From 42bd3bd6e30cc2c85a71976bb6e32d5cdca1fb68 Mon Sep 17 00:00:00 2001 From: lilchizh Date: Tue, 14 May 2024 21:10:23 +0700 Subject: [PATCH] (fix) Trade fee --- src/hooks/swap/useAllRoutes.ts | 6 +++--- src/hooks/swap/useSwapCallback.ts | 3 ++- src/hooks/swap/useSwapPools.ts | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/hooks/swap/useAllRoutes.ts b/src/hooks/swap/useAllRoutes.ts index f2768ae..3eb7e0a 100644 --- a/src/hooks/swap/useAllRoutes.ts +++ b/src/hooks/swap/useAllRoutes.ts @@ -19,7 +19,7 @@ function poolEquals(poolA: Pool, poolB: Pool): boolean { function computeAllRoutes( currencyIn: Currency, currencyOut: Currency, - pools: { tokens: [Token, Token], pool: { address: Address, liquidity: string, price: string, tick: string } }[], + pools: { tokens: [Token, Token], pool: { address: Address, liquidity: string, price: string, tick: string, fee: string } }[], chainId: number, currentPath: Pool[] = [], allPaths: Route[] = [], @@ -35,9 +35,9 @@ function computeAllRoutes( const [tokenA, tokenB] = pool.tokens - const { liquidity, price, tick } = pool.pool + const { liquidity, price, tick, fee } = pool.pool - const newPool = new Pool(tokenA, tokenB, INITIAL_POOL_FEE, price, liquidity, Number(tick), DEFAULT_TICK_SPACING) + const newPool = new Pool(tokenA, tokenB, +fee as unknown as 100, price, liquidity, Number(tick), DEFAULT_TICK_SPACING) if (!newPool.involvesToken(tokenIn) || currentPath.find((pathPool) => poolEquals(newPool, pathPool))) continue diff --git a/src/hooks/swap/useSwapCallback.ts b/src/hooks/swap/useSwapCallback.ts index 0526a46..e756d01 100644 --- a/src/hooks/swap/useSwapCallback.ts +++ b/src/hooks/swap/useSwapCallback.ts @@ -108,7 +108,8 @@ export function useSwapCallback( const { config: swapConfig } = usePrepareAlgebraRouterMulticall({ args: bestCall && [bestCall.calldata], value: BigInt(bestCall?.value || 0), - enabled: Boolean(bestCall) + enabled: Boolean(bestCall), + gas: bestCall ? bestCall.gasEstimate * (10000n + 2000n) / 10000n : undefined }) const { data: swapData, writeAsync: swapCallback } = useContractWrite(swapConfig) diff --git a/src/hooks/swap/useSwapPools.ts b/src/hooks/swap/useSwapPools.ts index 03fcd0c..37ea793 100644 --- a/src/hooks/swap/useSwapPools.ts +++ b/src/hooks/swap/useSwapPools.ts @@ -14,7 +14,7 @@ export function useSwapPools( currencyIn?: Currency, currencyOut?: Currency ): { - pools: { tokens: [Token, Token], pool: { address: Address, liquidity: string, price: string, tick: string, token0: TokenFieldsFragment, token1: TokenFieldsFragment } }[] + pools: { tokens: [Token, Token], pool: { address: Address, liquidity: string, price: string, tick: string, fee: string, token0: TokenFieldsFragment, token1: TokenFieldsFragment } }[] loading: boolean } { @@ -47,7 +47,7 @@ export function useSwapPools( // address // }).read.globalState())) - const pools = poolsData.data && poolsData.data.pools.map(pool => ({ address: pool.id, liquidity: pool.liquidity, price: pool.sqrtPrice, tick: pool.tick, token0: pool.token0, token1: pool.token1 })) + const pools = poolsData.data && poolsData.data.pools.map(pool => ({ address: pool.id, liquidity: pool.liquidity, price: pool.sqrtPrice, tick: pool.tick, fee: pool.fee, token0: pool.token0, token1: pool.token1 })) setExistingPools(pools)