@@ -10,7 +10,6 @@ import { useCallback, useEffect, useState } from 'react';
1010import { ComputedReserveData } from './app-data-provider/useAppDataProvider' ;
1111import { ChainId } from '@aave/contract-helpers' ;
1212import { BigNumberZeroDecimal , normalize , normalizeBN , valueToBigNumber } from '@aave/math-utils' ;
13- import BigNumber from 'bignumber.js' ;
1413
1514const ParaSwap = ( chainId : number ) => {
1615 const fetcher = constructFetchFetcher ( fetch ) ; // alternatively constructFetchFetcher
@@ -45,23 +44,13 @@ type UseSwapProps = {
4544 userId ?: string ;
4645 chainId : ChainId ;
4746 skip ?: boolean ;
48- maxSlippage ?: string ;
4947} ;
5048
5149const MESSAGE_MAP = {
5250 ESTIMATED_LOSS_GREATER_THAN_MAX_IMPACT : 'Price impact to high' ,
5351} ;
5452
55- export const useSwap = ( {
56- swapIn,
57- swapOut,
58- variant,
59- userId,
60- max,
61- chainId,
62- skip,
63- maxSlippage,
64- } : UseSwapProps ) => {
53+ export const useSwap = ( { swapIn, swapOut, variant, userId, max, chainId, skip } : UseSwapProps ) => {
6554 const paraSwap = getParaswap ( chainId ) ;
6655 const [ loading , setLoading ] = useState ( false ) ;
6756 const [ error , setError ] = useState ( '' ) ;
@@ -76,11 +65,6 @@ export const useSwap = ({
7665 if ( variant === 'exactIn' && max && swapIn . supplyAPY !== '0' ) {
7766 _amount = _amount . plus ( _amount . multipliedBy ( swapIn . supplyAPY ) . dividedBy ( 360 * 24 ) ) ;
7867 }
79- if ( variant === 'exactOut' ) {
80- _amount = new BigNumber ( _amount ) . multipliedBy (
81- new BigNumber ( 100 ) . plus ( maxSlippage || 0 ) . dividedBy ( 100 )
82- ) ;
83- }
8468 if ( variant === 'exactOut' && max ) {
8569 // variableBorrowAPY in most cases should be higher than stableRate so while this is slightly inaccurate it should be enough
8670 _amount = _amount . plus ( _amount . multipliedBy ( swapIn . variableBorrowAPY ) . dividedBy ( 360 * 24 ) ) ;
@@ -103,9 +87,12 @@ export const useSwap = ({
10387 side : variant === 'exactIn' ? SwapSide . SELL : SwapSide . BUY ,
10488 options : {
10589 partner : 'aave' ,
90+ excludeDEXS :
91+ 'ParaSwapPool,ParaSwapPool2,ParaSwapPool3,ParaSwapPool4,ParaSwapPool5,ParaSwapPool6,ParaSwapPool7,ParaSwapPool8,ParaSwapPool9,ParaSwapPool10' ,
10692 ...( max
10793 ? {
108- excludeDEXS : 'Balancer' ,
94+ excludeDEXS :
95+ 'Balancer,ParaSwapPool,ParaSwapPool2,ParaSwapPool3,ParaSwapPool4,ParaSwapPool5,ParaSwapPool6,ParaSwapPool7,ParaSwapPool8,ParaSwapPool9,ParaSwapPool10' ,
10996 excludeContractMethods : [ excludedMethod ] ,
11097 }
11198 : { } ) ,
@@ -131,7 +118,6 @@ export const useSwap = ({
131118 variant ,
132119 max ,
133120 chainId ,
134- maxSlippage ,
135121 ] ) ;
136122
137123 // updates the route on input change
@@ -199,7 +185,7 @@ type GetSwapAndRepayCallDataProps = {
199185 route : OptimalRate ;
200186 max ?: boolean ;
201187 chainId : ChainId ;
202- repayWithAmount : string ;
188+ maxSlippage : number ;
203189} ;
204190
205191export const getSwapCallData = async ( {
@@ -251,15 +237,20 @@ export const getRepayCallData = async ({
251237 user,
252238 route,
253239 chainId,
240+ maxSlippage,
254241} : GetSwapAndRepayCallDataProps ) => {
255242 const paraSwap = getParaswap ( chainId ) ;
243+ const srcAmountWithSlippage = new BigNumberZeroDecimal ( route . srcAmount )
244+ . multipliedBy ( 100 + maxSlippage )
245+ . dividedBy ( 100 )
246+ . toFixed ( 0 ) ;
256247
257248 try {
258249 const params = await paraSwap . buildTx (
259250 {
260251 srcToken,
261252 destToken,
262- srcAmount : route . srcAmount ,
253+ srcAmount : srcAmountWithSlippage ,
263254 destAmount : route . destAmount ,
264255 priceRoute : route ,
265256 userAddress : user ,
@@ -273,6 +264,7 @@ export const getRepayCallData = async ({
273264 return {
274265 swapCallData : ( params as TransactionParams ) . data ,
275266 augustus : ( params as TransactionParams ) . to ,
267+ srcAmountWithSlippage,
276268 } ;
277269 } catch ( e ) {
278270 console . log ( e ) ;
0 commit comments