0

I have a question regarding the SDK, I am using subgraph to pull data for each pool and using to create a pool class in JS, when I pass the Tick[] or create a TickListDataProvider I keep getting this Error: Invariant failed: ZERO_NET, it is at the validate list function in the SDK but I an't seem to understand what is causing the issue. I could not find any info on the web for this error. Any help would be appreciated!

let query: string
    let pools = [] as UPool[]

    let poolSize = 1000

    let chunks = _.chunk(ids, poolSize)
    for (let i = 0; i * poolSize < ids.length; i++) {
        query = `
            {
            pools(first: ${poolSize}, orderBy: volumeUSD, orderDirection: desc, where: { id_in: ${JSON.stringify(
            chunks[i]
        )}}) {
              id
              volumeUSD
              token0 {
                id
                symbol
                decimals
                name
              }
              token1 {
                id
                symbol
                decimals
                name
              }
              liquidity
              tick
              ticks(first: 1000) {
                poolAddress
                tickIdx
                liquidityGross
                liquidityNet
              }
              feeTier
              sqrtPrice
              createdAtTimestamp
            }
          }`
        try {
            if (pools.length % poolSize === 0) {
                let res = await axios.post(v3SubgraphUrl, { query })
                let tickAmount = 0
                res.data.data.pools.forEach(async (pool: V3Pool) => {
                    if (pool.ticks && pool.ticks.length > 1) {
                        const token0 = new Token(
                            1,
                            pool.token0.id,
                            parseInt(pool.token0.decimals),
                            pool.token0.symbol,
                            pool.token0.name
                        )

                        const token1 = new Token(
                            1,
                            pool.token1.id,
                            parseInt(pool.token1.decimals),
                            pool.token1.symbol,
                            pool.token1.name
                        )

                        let newTicks: Tick[] = []
                        
                            newTicks = pool.ticks.map((tick) => {
                                return new Tick({
                                    index: Number(tick.tickIdx),
                                    liquidityGross: tick.liquidityGross,
                                    liquidityNet: tick.liquidityNet,
                                })
                            }
                            
                        

                        tickAmount += newTicks.length

                        const uPool = new UPool(
                            pool.id,
                            token0,
                            token1,
                            Number(pool.feeTier),
                            pool.sqrtPrice,
                            pool.liquidity,
                            Number(pool.tick),
                            pool.createdAtTimestamp,
                            pool.volumeUSD,
                            newTicks
                        )
                        pools.push(uPool)
                    }
                })
                console.log("tickAmount", tickAmount)
            }
        } catch (e) {
            console.log(e)
        }
    }
    return pools
Error: Invariant failed: ZERO_NET
    at invariant (/Users/lukelongo/Desktop/js-eth-course/moneyMaker/node_modules/tiny-invariant/dist/tiny-invariant.cjs.js:14:11)
    at Function.validateList (/Users/lukelongo/Desktop/js-eth-course/moneyMaker/node_modules/@uniswap/v3-sdk/src/utils/tickList.ts:29:5)
    at new TickListDataProvider (/Users/lukelongo/Desktop/js-eth-course/moneyMaker/node_modules/@uniswap/v3-sdk/src/entities/tickListDataProvider.ts:14:14)
    at /Users/lukelongo/Desktop/js-eth-course/moneyMaker/src/utils.ts:406:54
    at Array.forEach (<anonymous>)
    at getV3Pricing (/Users/lukelongo/Desktop/js-eth-course/moneyMaker/src/utils.ts:376:37)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async JsonRpcProvider.<anonymous> (/Users/lukelongo/Desktop/js-eth-course/moneyMaker/src/V3Arbitrage.ts:67:21)

1 Answer 1

0

I faced a similar issue. Check if the pool has more than 1000 ticks. If yes you have to fetch all of them to construct the pool.

Since the subgraph can give only 1000 entries, you should run in a loop to fetch all the tick data

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.