daoleno / uniswapv3-sdk

🛠 A Go SDK for building applications on top of Uniswap V3
MIT License
195 stars 142 forks source link

ConstructV3Pool failing for a live pool #17

Open cryptohazard opened 2 years ago

cryptohazard commented 2 years ago

Hey, I was trying to use your package to interact with a pool on maiinet but I get an error when using ConstructV3Pool

        unipool = "0x82c427AdFDf2d245Ec51D8046b41c4ee87F0d29C"
        weth    = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
        osqth   = "0xf1B99e3E573A1a9C5E6B2Ce818b617F0E664E86B"
        chainID, _ := client.ChainID(context.Background())
    c := uint(chainID.Uint64())
    token0 := coreEntities.NewToken(c, common.HexToAddress(weth), 18, "WETH", "weth")
    token1 := coreEntities.NewToken(c, common.HexToAddress(osqth), 18, "oSQTH", "opyn squeeth")
    //amountIn := helper.FloatStringToBigInt("1.00", 18)
    pool, err := ConstructV3Pool(client, token0, token1, uint64(constants.FeeMedium))
    if err != nil {
        log.Fatal(err)
    }

I get the following error tick net delta must be zero , which as I understand is something about validating the ticks in ValidateList. But I don't know enough of the details of uniswap to understand how to fix this or why this pool fails.

Do you have an idea? etherscan link of the pool: https://etherscan.io/address/0x82c427adfdf2d245ec51d8046b41c4ee87f0d29c#readContract

cryptohazard commented 1 year ago

any idea what is this issue?

cryptohazard commented 1 year ago

So I figured out the issue. Here is the dump values for that pool using the default ConstructV3Pool :

(int) -887220
(struct { LiquidityGross *big.Int; LiquidityNet *big.Int; FeeGrowthOutside0X128 *big.Int; FeeGrowthOutside1X128 *big.Int; TickCumulativeOutside *big.Int; SecondsPerLiquidityOutsideX128 *big.Int; SecondsOutside uint32; Initialized bool }) {
 LiquidityGross: (*big.Int)(0xc0002284e0)(188409859849374781670),
 LiquidityNet: (*big.Int)(0xc000228500)(188409859849374781670),
 FeeGrowthOutside0X128: (*big.Int)(0xc000228520)(0),
 FeeGrowthOutside1X128: (*big.Int)(0xc000228540)(0),
 TickCumulativeOutside: (*big.Int)(0xc000228560)(28670743),
 SecondsPerLiquidityOutsideX128: (*big.Int)(0xc000228580)(877588224289100297272043112566530217345024),
 SecondsOutside: (uint32) 1641883915,
 Initialized: (bool) true
}
(int) 887220
(struct { LiquidityGross *big.Int; LiquidityNet *big.Int; FeeGrowthOutside0X128 *big.Int; FeeGrowthOutside1X128 *big.Int; TickCumulativeOutside *big.Int; SecondsPerLiquidityOutsideX128 *big.Int; SecondsOutside uint32; Initialized bool }) {
 LiquidityGross: (*big.Int)(0xc0001a4f60)(185649691152534902627),
 LiquidityNet: (*big.Int)(0xc0001a4f80)(-185649691152534902627),
 FeeGrowthOutside0X128: (*big.Int)(0xc0001a4fa0)(0),
 FeeGrowthOutside1X128: (*big.Int)(0xc0001a4fc0)(0),
 TickCumulativeOutside: (*big.Int)(0xc0001a4fe0)(0),
 SecondsPerLiquidityOutsideX128: (*big.Int)(0xc0001a5000)(0),
 SecondsOutside: (uint32) 0,
 Initialized: (bool) true
}
2023/02/16 11:48:59 tick net delta must be zero
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x10039db04]

I also the function from @lmanini fix. I tried other pools, USDC/DAI, WBTC/WETH, USDC/WETH, and all worked fine. In the end, all I wanted was to check the value of LP tokens. now my fix was to follow the example code to create two ticks with opposites LiquidityNet in my own ConstructV3Pool. And this fixed my issue and give a propre amount of tokens.