From 2367230895e6815c774bda38d8a2b44898e745a6 Mon Sep 17 00:00:00 2001 From: Danylo Kanievskyi Date: Tue, 10 Dec 2024 10:39:56 +0200 Subject: [PATCH 1/2] Revert "feat: lazy generate state on uni-v3 & pancake-swap-v3 pools" This reverts commit 33cd9dbae00896d373a236669ffa58bc94362c71. --- src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts | 30 ------------------- src/dex/pancakeswap-v3/pancakeswap-v3.ts | 10 ------- src/dex/uniswap-v3/uniswap-v3-pool.ts | 30 ------------------- src/dex/uniswap-v3/uniswap-v3.ts | 11 ------- 4 files changed, 81 deletions(-) diff --git a/src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts b/src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts index c80c08d54..fc2fdb9f1 100644 --- a/src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts +++ b/src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts @@ -250,36 +250,6 @@ export class PancakeSwapV3EventPool extends StatefulEventSubscriber { return TICK_BITMAP_TO_USE + TICK_BITMAP_BUFFER; } - async getOrGenerateState( - blockNumber: number, - ): Promise | null> { - const state = this.getState(blockNumber); - if (state) { - return state; - } - - this.logger.error( - `PancakeV3: No state found for ${this.name} ${this.addressesSubscribed[0]}, generating new one`, - ); - try { - const newState = await this.generateState(blockNumber); - - if (!newState) { - this.logger.error( - `PancakeV3: Could not generate state for ${this.name} ${this.addressesSubscribed[0]}`, - ); - return null; - } - this.setState(newState, blockNumber); - return newState; - } catch (error) { - this.logger.error( - `PancakeV3: Failed to generate state for ${this.name} ${this.addressesSubscribed[0]}`, - ); - return null; - } - } - async generateState(blockNumber: number): Promise> { const callData = this._getStateRequestCallData(); diff --git a/src/dex/pancakeswap-v3/pancakeswap-v3.ts b/src/dex/pancakeswap-v3/pancakeswap-v3.ts index 17248a00a..fc267ad0f 100644 --- a/src/dex/pancakeswap-v3/pancakeswap-v3.ts +++ b/src/dex/pancakeswap-v3/pancakeswap-v3.ts @@ -613,10 +613,6 @@ export class PancakeswapV3 if (selectedPools.length === 0) return null; - await Promise.all( - selectedPools.map(pool => pool.getOrGenerateState(blockNumber)), - ); - const poolsToUse = selectedPools.reduce( (acc, pool) => { let state = pool.getState(blockNumber); @@ -636,12 +632,6 @@ export class PancakeswapV3 }, ); - poolsToUse.poolWithoutState.forEach(pool => { - this.logger.warn( - `PancakeV3: Pool ${pool.name} on ${this.dexKey} has no state. Fallback to rpc`, - ); - }); - const rpcResultsPromise = this.getPricingFromRpc( _srcToken, _destToken, diff --git a/src/dex/uniswap-v3/uniswap-v3-pool.ts b/src/dex/uniswap-v3/uniswap-v3-pool.ts index b3b9d2143..2110470b2 100644 --- a/src/dex/uniswap-v3/uniswap-v3-pool.ts +++ b/src/dex/uniswap-v3/uniswap-v3-pool.ts @@ -254,36 +254,6 @@ export class UniswapV3EventPool extends StatefulEventSubscriber { return TICK_BITMAP_TO_USE + TICK_BITMAP_BUFFER; } - async getOrGenerateState( - blockNumber: number, - ): Promise | null> { - const state = this.getState(blockNumber); - if (state) { - return state; - } - - this.logger.error( - `UniV3: No state found for ${this.name} ${this.addressesSubscribed[0]}, generating new one`, - ); - try { - const newState = await this.generateState(blockNumber); - - if (!newState) { - this.logger.error( - `UniV3: Could not generate state for ${this.name} ${this.addressesSubscribed[0]}`, - ); - return null; - } - this.setState(newState, blockNumber); - return newState; - } catch (error) { - this.logger.error( - `UniV3: Failed to generate state for ${this.name} ${this.addressesSubscribed[0]}`, - ); - return null; - } - } - async generateState(blockNumber: number): Promise> { const callData = this._getStateRequestCallData(); diff --git a/src/dex/uniswap-v3/uniswap-v3.ts b/src/dex/uniswap-v3/uniswap-v3.ts index e9e05771c..40defeeae 100644 --- a/src/dex/uniswap-v3/uniswap-v3.ts +++ b/src/dex/uniswap-v3/uniswap-v3.ts @@ -715,10 +715,6 @@ export class UniswapV3 if (selectedPools.length === 0) return null; - await Promise.all( - selectedPools.map(pool => pool.getOrGenerateState(blockNumber)), - ); - const poolsToUse = selectedPools.reduce( (acc, pool) => { let state = pool.getState(blockNumber); @@ -726,7 +722,6 @@ export class UniswapV3 this.logger.trace( `${this.dexKey}: State === null. Fallback to rpc ${pool.name}`, ); - // as we generate state (if nullified) in previous Promise.all, here should only be pools with failed initialization acc.poolWithoutState.push(pool); } else { acc.poolWithState.push(pool); @@ -739,12 +734,6 @@ export class UniswapV3 }, ); - poolsToUse.poolWithoutState.forEach(pool => { - this.logger.warn( - `UniV3: Pool ${pool.name} on ${this.dexKey} has no state. Fallback to rpc`, - ); - }); - const states = poolsToUse.poolWithState.map( p => p.getState(blockNumber)!, ); From c4c2de007f3174c643901a8b8a080d3faace1101 Mon Sep 17 00:00:00 2001 From: Danylo Kanievskyi Date: Tue, 10 Dec 2024 10:40:18 +0200 Subject: [PATCH 2/2] 3.11.9 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 62a435b8d..3284f0870 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paraswap/dex-lib", - "version": "3.11.8", + "version": "3.11.9", "main": "build/index.js", "types": "build/index.d.ts", "repository": "https://github.com/paraswap/paraswap-dex-lib",