@clonegod/ttd-bsc-common 3.0.38 → 3.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -18,7 +18,7 @@ export declare class ClmmTickCache {
|
|
|
18
18
|
private config;
|
|
19
19
|
constructor(loader: TickLensLoader, config?: ClmmTickCacheConfig);
|
|
20
20
|
initPool(poolAddress: string, currentTick: number, tickSpacing: number): Promise<void>;
|
|
21
|
-
onSwap(poolAddress: string, newTick: number): void
|
|
21
|
+
onSwap(poolAddress: string, newTick: number): Promise<void>;
|
|
22
22
|
onMint(poolAddress: string, tickLower: number, tickUpper: number, amount: bigint): void;
|
|
23
23
|
onBurn(poolAddress: string, tickLower: number, tickUpper: number, amount: bigint): void;
|
|
24
24
|
onModifyLiquidity(poolAddress: string, tickLower: number, tickUpper: number, liquidityDelta: bigint): void;
|
|
@@ -19,9 +19,9 @@ class ClmmTickCache {
|
|
|
19
19
|
this.loadPromises = new Map();
|
|
20
20
|
this.loader = loader;
|
|
21
21
|
this.config = {
|
|
22
|
-
neighboringWords: (_a = config.neighboringWords) !== null && _a !== void 0 ? _a : 2,
|
|
23
|
-
refreshInterval: (_b = config.refreshInterval) !== null && _b !== void 0 ? _b : 60000,
|
|
24
|
-
minUpdateInterval: (_c = config.minUpdateInterval) !== null && _c !== void 0 ? _c : 3000,
|
|
22
|
+
neighboringWords: (_a = config.neighboringWords) !== null && _a !== void 0 ? _a : (Number(process.env.TICK_CACHE_NEIGHBORING_WORDS) || 2),
|
|
23
|
+
refreshInterval: (_b = config.refreshInterval) !== null && _b !== void 0 ? _b : (Number(process.env.TICK_CACHE_FORCE_FULL_REFRESH_INTERVAL) || 60000),
|
|
24
|
+
minUpdateInterval: (_c = config.minUpdateInterval) !== null && _c !== void 0 ? _c : (Number(process.env.TICK_CACHE_MIN_UPDATE_INTERVAL) || 3000),
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
initPool(poolAddress, currentTick, tickSpacing) {
|
|
@@ -43,15 +43,18 @@ class ClmmTickCache {
|
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
onSwap(poolAddress, newTick) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
(
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const state = this.pools.get(poolAddress);
|
|
48
|
+
if (!state)
|
|
49
|
+
return;
|
|
50
|
+
state.currentTick = newTick;
|
|
51
|
+
const currentBitmapIndex = this.getBitmapIndex(newTick, state.tickSpacing);
|
|
52
|
+
if (!state.bitmapIndexes.includes(currentBitmapIndex)) {
|
|
53
|
+
const cachedRange = `[${Math.min(...state.bitmapIndexes)}..${Math.max(...state.bitmapIndexes)}]`;
|
|
54
|
+
(0, ttd_core_1.log_info)(`[TickCache] 本地缓存 tick 缺失,开始同步 RPC 刷新: pool=${poolAddress.slice(0, 10)}..., tick=${newTick}, bitmapIndex=${currentBitmapIndex}, cachedWords=${cachedRange}`);
|
|
55
|
+
yield this.scheduleFullRefresh(poolAddress);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
55
58
|
}
|
|
56
59
|
onMint(poolAddress, tickLower, tickUpper, amount) {
|
|
57
60
|
this.applyLiquidityDelta(poolAddress, tickLower, tickUpper, amount);
|
|
@@ -131,16 +134,23 @@ class ClmmTickCache {
|
|
|
131
134
|
return this.pools.has(poolAddress);
|
|
132
135
|
}
|
|
133
136
|
scheduleFullRefresh(poolAddress) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
(
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
const state = this.pools.get(poolAddress);
|
|
139
|
+
if (!state)
|
|
140
|
+
return;
|
|
141
|
+
const existing = this.loadPromises.get(poolAddress);
|
|
142
|
+
if (existing) {
|
|
143
|
+
return existing;
|
|
144
|
+
}
|
|
145
|
+
const elapsed = Date.now() - state.lastFullLoadTime;
|
|
146
|
+
if (elapsed < this.config.minUpdateInterval) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const promise = this.doFullRefresh(poolAddress).finally(() => {
|
|
150
|
+
this.loadPromises.delete(poolAddress);
|
|
151
|
+
});
|
|
152
|
+
this.loadPromises.set(poolAddress, promise);
|
|
153
|
+
return promise;
|
|
144
154
|
});
|
|
145
155
|
}
|
|
146
156
|
startPeriodicRefresh(poolAddress) {
|