diff --git a/src/components/transactions/Swap/actions/CollateralSwap/CollateralSwapActionsViaCoWAdapters.tsx b/src/components/transactions/Swap/actions/CollateralSwap/CollateralSwapActionsViaCoWAdapters.tsx index 36509bf2ff..05cf50d702 100644 --- a/src/components/transactions/Swap/actions/CollateralSwap/CollateralSwapActionsViaCoWAdapters.tsx +++ b/src/components/transactions/Swap/actions/CollateralSwap/CollateralSwapActionsViaCoWAdapters.tsx @@ -19,6 +19,7 @@ import { addOrderTypeToAppData, getCowFlashLoanSdk, getCowTradingSdkByChainIdAndAppCode, + overrideSmartSlippageOnAppData, } from '../../helpers/cow'; import { calculateInstanceAddress, getHooksGasLimit } from '../../helpers/cow/adapters.helpers'; import { useCollateralsAmount } from '../../hooks/useCollateralsAmount'; @@ -234,6 +235,11 @@ export const CollateralSwapActionsViaCowAdapters = ({ orderPostParams.swapSettings.appData ); + orderPostParams.swapSettings.appData = overrideSmartSlippageOnAppData( + state, + orderPostParams.swapSettings.appData + ); + // Safe-check in case any param changed between approval and order posting const instanceAddress = orderPostParams.instanceAddress; if (instanceAddress !== approvedAddress) { diff --git a/src/components/transactions/Swap/actions/DebtSwap/DebtSwapActionsViaCoW.tsx b/src/components/transactions/Swap/actions/DebtSwap/DebtSwapActionsViaCoW.tsx index 4d1b9989e5..16a32e33a3 100644 --- a/src/components/transactions/Swap/actions/DebtSwap/DebtSwapActionsViaCoW.tsx +++ b/src/components/transactions/Swap/actions/DebtSwap/DebtSwapActionsViaCoW.tsx @@ -20,6 +20,7 @@ import { addOrderTypeToAppData, getCowFlashLoanSdk, getCowTradingSdkByChainIdAndAppCode, + overrideSmartSlippageOnAppData, } from '../../helpers/cow'; import { accountForDustProtection, @@ -275,6 +276,12 @@ export const DebtSwapActionsViaCoW = ({ state.orderType, orderPostParams.swapSettings.appData ); + + orderPostParams.swapSettings.appData = overrideSmartSlippageOnAppData( + state, + orderPostParams.swapSettings.appData + ); + const result = await tradingSdk.postLimitOrder(limitOrder, orderPostParams.swapSettings); trackingHandlers.trackSwap(); diff --git a/src/components/transactions/Swap/actions/RepayWithCollateral/RepayWithCollateralActionsViaCoW.tsx b/src/components/transactions/Swap/actions/RepayWithCollateral/RepayWithCollateralActionsViaCoW.tsx index 1fd6597f45..715e66d713 100644 --- a/src/components/transactions/Swap/actions/RepayWithCollateral/RepayWithCollateralActionsViaCoW.tsx +++ b/src/components/transactions/Swap/actions/RepayWithCollateral/RepayWithCollateralActionsViaCoW.tsx @@ -19,6 +19,7 @@ import { addOrderTypeToAppData, getCowFlashLoanSdk, getCowTradingSdkByChainIdAndAppCode, + overrideSmartSlippageOnAppData, } from '../../helpers/cow'; import { accountForDustProtection, @@ -254,6 +255,11 @@ export const RepayWithCollateralActionsViaCoW = ({ orderPostParams.swapSettings.appData ); + orderPostParams.swapSettings.appData = overrideSmartSlippageOnAppData( + state, + orderPostParams.swapSettings.appData + ); + // Safe-check in case any param changed between approval and order posting const instanceAddress = orderPostParams.instanceAddress; if (instanceAddress !== approvedAddress) { diff --git a/src/components/transactions/Swap/helpers/cow/orders.helpers.ts b/src/components/transactions/Swap/helpers/cow/orders.helpers.ts index 4d271d702a..a4dbbfd107 100644 --- a/src/components/transactions/Swap/helpers/cow/orders.helpers.ts +++ b/src/components/transactions/Swap/helpers/cow/orders.helpers.ts @@ -27,7 +27,7 @@ import { COW_PROTOCOL_ETH_FLOW_ADDRESS_BY_ENV, isChainIdSupportedByCoWProtocol, } from '../../constants/cow.constants'; -import { OrderType } from '../../types'; +import { OrderType, SwapState } from '../../types'; import { getCowTradingSdkByChainIdAndAppCode } from './env.helpers'; export const COW_ENV: CowEnv = 'prod'; @@ -539,3 +539,21 @@ export const addOrderTypeToAppData = ( }, }; }; + +export const overrideSmartSlippageOnAppData = (state: SwapState, appData: AppDataParams) => { + const slippageBips = + state.orderType === OrderType.LIMIT ? 0 : Math.round(Number(state.slippage) * 100); // percent to bps + const smartSlippage = state.swapRate?.suggestedSlippage == Number(state.slippage); + + return { + ...appData, + metadata: { + ...appData?.metadata, + quote: { + ...appData?.metadata?.quote, + slippageBips: appData?.metadata?.quote?.slippageBips ?? slippageBips, + smartSlippage, + }, + }, + }; +};