Skip to content

Commit

Permalink
feat: only check pool state for univ3 on pricing
Browse files Browse the repository at this point in the history
  • Loading branch information
KanievskyiDanylo committed Dec 10, 2024
1 parent 95ba87e commit 1b553bf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 39 deletions.
22 changes: 4 additions & 18 deletions src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export class PancakeSwapV3EventPool extends StatefulEventSubscriber<PoolState> {
return TICK_BITMAP_TO_USE + TICK_BITMAP_BUFFER;
}

async getOrGenerateState(
async checkState(
blockNumber: number,
): Promise<DeepReadonly<PoolState> | null> {
const state = this.getState(blockNumber);
Expand All @@ -259,25 +259,11 @@ export class PancakeSwapV3EventPool extends StatefulEventSubscriber<PoolState> {
}

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<Readonly<PoolState>> {
Expand Down
2 changes: 1 addition & 1 deletion src/dex/pancakeswap-v3/pancakeswap-v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
23 changes: 4 additions & 19 deletions src/dex/uniswap-v3/uniswap-v3-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export class UniswapV3EventPool extends StatefulEventSubscriber<PoolState> {
return TICK_BITMAP_TO_USE + TICK_BITMAP_BUFFER;
}

async getOrGenerateState(
async checkState(
blockNumber: number,
): Promise<DeepReadonly<PoolState> | null> {
const state = this.getState(blockNumber);
Expand All @@ -263,25 +263,10 @@ export class UniswapV3EventPool extends StatefulEventSubscriber<PoolState> {
}

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<Readonly<PoolState>> {
Expand Down
2 changes: 1 addition & 1 deletion src/dex/uniswap-v3/uniswap-v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 1b553bf

Please sign in to comment.