Skip to content

Commit

Permalink
solve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
aburkut committed Dec 9, 2024
2 parents e8336c6 + 02631c7 commit c574744
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/dex/bebop/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const BEBOP_API_URL = 'https://api.bebop.xyz';
export const BEBOP_WS_API_URL = 'wss://api.bebop.xyz';
export const BEBOP_GAS_COST = 120_000;
export const BEBOP_AUTH_NAME = 'paraswap';
export const BEBOP_QUOTE_TIMEOUT_MS = 2000;
export const BEBOP_QUOTE_TIMEOUT_MS = 3000;
export const BEBOP_ERRORS_CACHE_KEY = 'errors';
export const BEBOP_RESTRICTED_CACHE_KEY = 'restricted';
// Restrict for BEBOP_RESTRICT_TTL_S if an error occured >= BEBOP_RESTRICT_COUNT_THRESHOLD times within BEBOP_RESTRICT_CHECK_INTERVAL_S interval
Expand Down
30 changes: 30 additions & 0 deletions src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,36 @@ export class PancakeSwapV3EventPool extends StatefulEventSubscriber<PoolState> {
return TICK_BITMAP_TO_USE + TICK_BITMAP_BUFFER;
}

async getOrGenerateState(
blockNumber: number,
): Promise<DeepReadonly<PoolState> | 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<Readonly<PoolState>> {
const callData = this._getStateRequestCallData();

Expand Down
10 changes: 10 additions & 0 deletions src/dex/pancakeswap-v3/pancakeswap-v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,10 @@ 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);
Expand All @@ -632,6 +636,12 @@ 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,
Expand Down
30 changes: 30 additions & 0 deletions src/dex/uniswap-v3/uniswap-v3-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,36 @@ export class UniswapV3EventPool extends StatefulEventSubscriber<PoolState> {
return TICK_BITMAP_TO_USE + TICK_BITMAP_BUFFER;
}

async getOrGenerateState(
blockNumber: number,
): Promise<DeepReadonly<PoolState> | 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<Readonly<PoolState>> {
const callData = this._getStateRequestCallData();

Expand Down
11 changes: 11 additions & 0 deletions src/dex/uniswap-v3/uniswap-v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,13 +715,18 @@ 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);
if (state === null) {
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);
Expand All @@ -734,6 +739,12 @@ 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)!,
);
Expand Down

0 comments on commit c574744

Please sign in to comment.