Skip to content

Commit 04e3f47

Browse files
Ivan Workclaude
andcommitted
feat(algebra-integral): add addMasterPool for master/slave sync
Without this method, the master service cannot spin up event pools on demand when slaves publish pool requests via the new_pools channel. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2d0311d commit 04e3f47

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/dex/algebra-integral/algebra-integral.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
import {
1616
SwapSide,
1717
Network,
18+
CACHE_PREFIX,
1819
DEST_TOKEN_DEX_TRANSFERS,
1920
SRC_TOKEN_DEX_TRANSFERS,
2021
SUBGRAPH_TIMEOUT,
@@ -60,6 +61,8 @@ import { uint256ToBigInt } from '../../lib/decoders';
6061
import AlgebraIntegralStateMulticallABI from '../../abi/algebra-integral/AlgebraIntegralStateMulticall.abi.json';
6162
import { buildFeeCallData } from './utils';
6263

64+
const PoolsRegistryHashKey = `${CACHE_PREFIX}_poolsRegistry`;
65+
6366
export class AlgebraIntegral
6467
extends SimpleExchange
6568
implements IDex<AlgebraIntegralData>
@@ -187,6 +190,40 @@ export class AlgebraIntegral
187190
);
188191
}
189192

193+
async addMasterPool(poolKey: string, blockNumber: number): Promise<boolean> {
194+
const _pairs = await this.dexHelper.cache.hget(
195+
PoolsRegistryHashKey,
196+
`${this.cacheStateKey}_${poolKey}`,
197+
);
198+
if (!_pairs) {
199+
this.logger.warn(
200+
`did not find poolConfig in for key ${PoolsRegistryHashKey} ${this.cacheStateKey}_${poolKey}`,
201+
);
202+
return false;
203+
}
204+
205+
const poolInfo: { token0: Address; token1: Address } = JSON.parse(_pairs);
206+
207+
const pools = this.factory.getAvailablePoolsForPair(
208+
poolInfo.token0,
209+
poolInfo.token1,
210+
);
211+
212+
if (pools.length === 0) return false;
213+
214+
try {
215+
await this.initializeEventPools(blockNumber, true, pools);
216+
} catch (e) {
217+
this.logger.error(
218+
`${this.dexKey}: failed to initialize master pools for ${poolInfo.token0}/${poolInfo.token1}`,
219+
e,
220+
);
221+
return false;
222+
}
223+
224+
return true;
225+
}
226+
190227
protected async updateAllPoolFees(): Promise<void> {
191228
try {
192229
const activePools = Object.values(this.eventPools).filter(

0 commit comments

Comments
 (0)