Skip to content

Commit

Permalink
Merge pull request #41 from cryptoalgebra/fix/trade-fee
Browse files Browse the repository at this point in the history
Fix/trade fee
  • Loading branch information
lilchizh authored May 14, 2024
2 parents 64ad8ba + 42bd3bd commit b3c9966
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/hooks/swap/useAllRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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<Currency, Currency>[] = [],
Expand All @@ -36,9 +36,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

Expand Down
3 changes: 2 additions & 1 deletion src/hooks/swap/useSwapCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,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)
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/swap/useSwapPools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
} {

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit b3c9966

Please sign in to comment.