From f8cba7cec34e50df41804f6c1b42ae738194f486 Mon Sep 17 00:00:00 2001 From: Leifu Chen Date: Tue, 17 May 2022 18:48:22 +0300 Subject: [PATCH] Added hardcoded slippage and sUSD into atomic exchange --- sections/exchange/hooks/useExchange.tsx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/sections/exchange/hooks/useExchange.tsx b/sections/exchange/hooks/useExchange.tsx index 4ce9479bdc..864f1045af 100644 --- a/sections/exchange/hooks/useExchange.tsx +++ b/sections/exchange/hooks/useExchange.tsx @@ -141,6 +141,7 @@ const useExchange = ({ const [selectQuoteTokenModalOpen, setSelectQuoteTokenModalOpen] = useState(false); const [selectBaseTokenModalOpen, setSelectBaseTokenModalOpen] = useState(false); const [txApproveModalOpen, setTxApproveModalOpen] = useState(false); + const [atomicExchangeSlippage] = useState('0.01'); const setOrders = useSetRecoilState(ordersState); const setHasOrdersNotification = useSetRecoilState(hasOrdersNotificationState); const { selectPriceCurrencyRate, selectedPriceCurrency } = useSelectedPriceCurrency(); @@ -580,7 +581,7 @@ const useExchange = ({ const destinationCurrencyKey = ethers.utils.formatBytes32String(quoteCurrencyKey!); const sourceCurrencyKey = ethers.utils.formatBytes32String(baseCurrencyKey!); const sourceAmount = quoteCurrencyAmountBN.toBN(); - const minAmount = baseCurrencyAmountBN.toBN(); + const minAmount = baseCurrencyAmountBN.mul(wei(1).sub(atomicExchangeSlippage)).toBN(); if (isAtomic) { return [ @@ -600,7 +601,14 @@ const useExchange = ({ ]; } }, - [baseCurrencyKey, quoteCurrencyAmountBN, quoteCurrencyKey, walletAddress, baseCurrencyAmountBN] + [ + baseCurrencyKey, + quoteCurrencyAmountBN, + quoteCurrencyKey, + walletAddress, + baseCurrencyAmountBN, + atomicExchangeSlippage, + ] ); const getGasEstimateForExchange = useCallback( @@ -615,7 +623,8 @@ const useExchange = ({ !isL2 && (destinationCurrencyKey === 'sBTC' || destinationCurrencyKey === 'sETH' || - destinationCurrencyKey === 'sEUR'); + destinationCurrencyKey === 'sEUR' || + destinationCurrencyKey === 'sUSD'); const exchangeParams = getExchangeParams(isAtomic); let gasEstimate, gasLimitNum, metaTx; @@ -787,7 +796,8 @@ const useExchange = ({ !isL2 && (destinationCurrencyKey === 'sBTC' || destinationCurrencyKey === 'sETH' || - destinationCurrencyKey === 'sEUR'); + destinationCurrencyKey === 'sEUR' || + destinationCurrencyKey === 'sUSD'); const exchangeParams = getExchangeParams(isAtomic);