Skip to content

Commit

Permalink
feat: update minzapamount
Browse files Browse the repository at this point in the history
  • Loading branch information
viet-nv committed Nov 8, 2023
1 parent f842f98 commit e1d3bc9
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/hooks/elasticZap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,24 @@ export function useZapInAction() {
: abiEncoder.encode(['address', 'int24', 'int24', 'uint128'], [account, tickLower, tickUpper, minLiquidity])

const zeros = '0'.repeat(128)

// max(1, 0.00001% * amount)
const exp6 = JSBI.BigInt(1_000_000)
const minZapAmount0 = JSBI.divide(
JSBI.multiply(JSBI.BigInt(amountIn), JSBI.BigInt(slippage)),
JSBI.BigInt(10000),
JSBI.multiply(JSBI.greaterThan(JSBI.BigInt(amountIn), exp6) ? JSBI.BigInt(amountIn) : exp6, JSBI.BigInt(1)),
exp6,
).toString(2)

const minZapAmount1 = JSBI.divide(
JSBI.multiply(JSBI.BigInt(equivalentQuoteAmount), JSBI.BigInt(slippage)),
JSBI.BigInt(10000),
JSBI.multiply(
JSBI.greaterThan(JSBI.BigInt(equivalentQuoteAmount), exp6) ? JSBI.BigInt(equivalentQuoteAmount) : exp6,
JSBI.BigInt(1),
),
exp6,
).toString(2)

const minZapAmount = JSBI.BigInt(
parseInt((zeros + minZapAmount0).slice(-128) + (zeros + minZapAmount1).slice(-128), 2),
const minZapAmount = BigInt(
'0b' + (zeros + minZapAmount0).slice(-128) + (zeros + minZapAmount1).slice(-128),
).toString()

const zapExecutorData = abiEncoder.encode(
Expand Down

0 comments on commit e1d3bc9

Please sign in to comment.