Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Pool getOutputAmount calculation incorrect for some cases #159

Open
z-hao-wang opened this issue Dec 5, 2022 · 1 comment
Open

Pool getOutputAmount calculation incorrect for some cases #159

z-hao-wang opened this issue Dec 5, 2022 · 1 comment

Comments

@z-hao-wang
Copy link

I've noticed for some pools, the getOutputAmount produces different results than quoter v2

z-hao-wang/v3-core-debug#1
this branch can reproduce the error I found
The quote results are same for config like this

{
    description: 'high fee, 1:1 price, default config',
    feeAmount: FeeAmount.HIGH,
    tickSpacing: TICK_SPACINGS[FeeAmount.HIGH],
    startingPrice: encodePriceSqrt(1, 1),
    positions: [
      {
        tickLower: getMinTick(TICK_SPACINGS[FeeAmount.HIGH]),
        tickUpper: getMaxTick(TICK_SPACINGS[FeeAmount.HIGH]),
        liquidity: expandTo18Decimals(2),
      },
    ],
    swapTests: [{
      zeroForOne: true,
      exactOut: false,
      amount0: expandTo18Decimals(1),
    }],
  }

but it doesn't work for config like this

{
    description: 'high fee, 1:1 price, buggy swap calculation',
    feeAmount: FeeAmount.HIGH,
    tickSpacing: TICK_SPACINGS[FeeAmount.HIGH],
    startingPrice: BigNumber.from('3905891053926514387903925684'), // tick at -60200
    positions: [
      {
        tickLower: -60200,
        tickUpper: 138200,
        liquidity: '1505426792435356595487',
      },
    ],
    swapTests: [{
      zeroForOne: true,
      exactOut: false,
      amount0: expandTo18Decimals(1),
    }],
  }
@z-hao-wang
Copy link
Author

I found this is due to amount remaining isn't returned.
The pool doesn't get enough liquidity.
see below pr that fixes it.

https://github.com/QuantSatoshi/v3-sdk/pull/1/files

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant