From 1b553bf4e1a073e8f403204af83424561d4bd80a Mon Sep 17 00:00:00 2001 From: Danylo Kanievskyi Date: Tue, 10 Dec 2024 11:03:00 +0200 Subject: [PATCH] feat: only check pool state for univ3 on pricing --- src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts | 22 ++++-------------- src/dex/pancakeswap-v3/pancakeswap-v3.ts | 2 +- src/dex/uniswap-v3/uniswap-v3-pool.ts | 23 ++++--------------- src/dex/uniswap-v3/uniswap-v3.ts | 2 +- 4 files changed, 10 insertions(+), 39 deletions(-) diff --git a/src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts b/src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts index c80c08d54..0159fc798 100644 --- a/src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts +++ b/src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts @@ -250,7 +250,7 @@ export class PancakeSwapV3EventPool extends StatefulEventSubscriber { return TICK_BITMAP_TO_USE + TICK_BITMAP_BUFFER; } - async getOrGenerateState( + async checkState( blockNumber: number, ): Promise | null> { const state = this.getState(blockNumber); @@ -259,25 +259,11 @@ export class PancakeSwapV3EventPool extends StatefulEventSubscriber { } this.logger.error( - `PancakeV3: No state found for ${this.name} ${this.addressesSubscribed[0]}, generating new one`, + `PancakeV3: No state found for ${this.name} ${this.addressesSubscribed[0]} for bn: ${blockNumber}`, ); - try { - const newState = await this.generateState(blockNumber); + return null; + } - 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> { diff --git a/src/dex/pancakeswap-v3/pancakeswap-v3.ts b/src/dex/pancakeswap-v3/pancakeswap-v3.ts index 17248a00a..ccc3ddc26 100644 --- a/src/dex/pancakeswap-v3/pancakeswap-v3.ts +++ b/src/dex/pancakeswap-v3/pancakeswap-v3.ts @@ -614,7 +614,7 @@ export class PancakeswapV3 if (selectedPools.length === 0) return null; await Promise.all( - selectedPools.map(pool => pool.getOrGenerateState(blockNumber)), + selectedPools.map(pool => pool.checkState(blockNumber)), ); const poolsToUse = selectedPools.reduce( diff --git a/src/dex/uniswap-v3/uniswap-v3-pool.ts b/src/dex/uniswap-v3/uniswap-v3-pool.ts index b3b9d2143..b8a6725a7 100644 --- a/src/dex/uniswap-v3/uniswap-v3-pool.ts +++ b/src/dex/uniswap-v3/uniswap-v3-pool.ts @@ -254,7 +254,7 @@ export class UniswapV3EventPool extends StatefulEventSubscriber { return TICK_BITMAP_TO_USE + TICK_BITMAP_BUFFER; } - async getOrGenerateState( + async checkState( blockNumber: number, ): Promise | null> { const state = this.getState(blockNumber); @@ -263,25 +263,10 @@ export class UniswapV3EventPool extends StatefulEventSubscriber { } this.logger.error( - `UniV3: No state found for ${this.name} ${this.addressesSubscribed[0]}, generating new one`, + `UniV3: No state found for ${this.name} ${this.addressesSubscribed[0]} for bn: ${blockNumber}`, ); - 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; - } + return null; + } } async generateState(blockNumber: number): Promise> { diff --git a/src/dex/uniswap-v3/uniswap-v3.ts b/src/dex/uniswap-v3/uniswap-v3.ts index e9e05771c..91eeb74c0 100644 --- a/src/dex/uniswap-v3/uniswap-v3.ts +++ b/src/dex/uniswap-v3/uniswap-v3.ts @@ -716,7 +716,7 @@ export class UniswapV3 if (selectedPools.length === 0) return null; await Promise.all( - selectedPools.map(pool => pool.getOrGenerateState(blockNumber)), + selectedPools.map(pool => pool.checkState(blockNumber)), ); const poolsToUse = selectedPools.reduce(