v3-sdk icon indicating copy to clipboard operation
v3-sdk copied to clipboard

Difference outputAmount returned by Pool.getOutputAmount() in uniV3-SDK and SwapRouter.exactInputSingle() in uniV3-periphery for only one pool

Open Tien-Thao-NGUYEN opened this issue 3 years ago • 5 comments

Hello everyone, I tried to use Pool.getOutputAmount() in uniV3-SDK and SwapRouter.exactInputSingle() in uniV3-periphery to perform a swap within a given pool then compare the two results. I use hardhat for forking the mainnet and execute the script for Pool.getOutputAmount() at first (because it doesn't change the state of EVM) then the script for SwapRouter.exactInputSingle() at the seconds. I take 6 pools for the test:

  1. ZDEX - WETH: '0x46087cEeD975CFfC0074C5d4A7e8f1150E7CECf6'
  2. USDC - WETH: '0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8'
  3. YAY - WETH: '0xC3e4E5c19984BE13bB52F5D14FfBf6a13ea0838B'
  4. DFM - WETH: '0x919F58bc429c7cF96905EB79395F5B77D9b98b52'
  5. WETH - MRXe: '0x7eC0bE8aa9fBc1d8aB40Aa5b1fd0E46d66120eDf'
  6. WETH - R64X: '0xAb44Da6A8180D0f75d214d3616970E0C93BBFBAa'

In each test, I swap 1 WETH for another token in each pool. I have only one pair of outputAmount which has difference result for the pool DFM - WETH: '0x919F58bc429c7cF96905EB79395F5B77D9b98b52' . The results of the others pools are good. Here is my SDK scripts :

swap-sdk-01 swap-sdk-02

And here is my periphery script:

swap-periphery-01 swap-periphery-02

For example of the result:

  • Pool 2 (USDC - WETH): Input 1 WETH +) SDK output: 3243438919 +) Periphery output: 3243438919
  • Pool 4 (DFM - WETH): input 1 WETH (the problem is here) +) SDK output: 28785598159162986664347 +) Periphery output: 28785598159162986644716

I don't know why. Can you explain to me please? Thank you!

Tien-Thao-NGUYEN avatar Sep 10 '21 15:09 Tien-Thao-NGUYEN

Open

True1194 avatar Oct 07 '21 18:10 True1194

446477chancey # #

True1194 avatar Oct 07 '21 18:10 True1194

Hey @Tien-Thao-NGUYEN this is likely due to incomplete tick data in your SDK pool entity.I'd suggest you use the Quoter instead of pool in this case.

marktoda avatar Jul 13 '22 19:07 marktoda

Hello everyone, I tried to use Pool.getOutputAmount() in uniV3-SDK and SwapRouter.exactInputSingle() in uniV3-periphery to perform a swap within a given pool then compare the two results. I use hardhat for forking the mainnet and execute the script for Pool.getOutputAmount() at first (because it doesn't change the state of EVM) then the script for SwapRouter.exactInputSingle() at the seconds. I take 6 pools for the test:

  1. ZDEX - WETH: '0x46087cEeD975CFfC0074C5d4A7e8f1150E7CECf6'
  2. USDC - WETH: '0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8'
  3. YAY - WETH: '0xC3e4E5c19984BE13bB52F5D14FfBf6a13ea0838B'
  4. DFM - WETH: '0x919F58bc429c7cF96905EB79395F5B77D9b98b52'
  5. WETH - MRXe: '0x7eC0bE8aa9fBc1d8aB40Aa5b1fd0E46d66120eDf'
  6. WETH - R64X: '0xAb44Da6A8180D0f75d214d3616970E0C93BBFBAa'

In each test, I swap 1 WETH for another token in each pool. I have only one pair of outputAmount which has difference result for the pool DFM - WETH: '0x919F58bc429c7cF96905EB79395F5B77D9b98b52' . The results of the others pools are good. Here is my SDK scripts :

swap-sdk-01 swap-sdk-02

And here is my periphery script:

swap-periphery-01 swap-periphery-02

For example of the result:

  • Pool 2 (USDC - WETH): Input 1 WETH +) SDK output: 3243438919 +) Periphery output: 3243438919
  • Pool 4 (DFM - WETH): input 1 WETH (the problem is here) +) SDK output: 28785598159162986664347 +) Periphery output: 28785598159162986644716

I don't know why. Can you explain to me please? Thank you!

Hey @Tien-Thao-NGUYEN , I've seen your code and I was wondering why are you putting "inputAmount" as a parameter in the CurrencyAmount's fromRawAmount function. I can see that inputAmount is a JSBI variable, but the parameter must be a "BigIntIsh" type. How did you solve that? Sorry for the newbie question, I'm trying to understand that

crisramb665 avatar Jul 17 '22 08:07 crisramb665

Any solutions ?

JulioSarda avatar Aug 12 '22 01:08 JulioSarda