Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
addOrderTypeToAppData,
getCowFlashLoanSdk,
getCowTradingSdkByChainIdAndAppCode,
overrideSmartSlippageOnAppData,
} from '../../helpers/cow';
import {
accountForDustProtection,
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
addOrderTypeToAppData,
getCowFlashLoanSdk,
getCowTradingSdkByChainIdAndAppCode,
overrideSmartSlippageOnAppData,
} from '../../helpers/cow';
import {
accountForDustProtection,
Expand Down Expand Up @@ -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) {
Expand Down
20 changes: 19 additions & 1 deletion src/components/transactions/Swap/helpers/cow/orders.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
},
},
};
};
Loading