@clonegod/ttd-base-common 1.0.25 → 1.1.1
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.
- package/dist/appconfig/BaseQuoteAppConfig.d.ts +10 -0
- package/dist/appconfig/BaseQuoteAppConfig.js +36 -0
- package/dist/appconfig/BaseTradeAppConfig.d.ts +7 -0
- package/dist/appconfig/BaseTradeAppConfig.js +13 -0
- package/dist/appconfig/base_dex_env_args.d.ts +5 -0
- package/dist/appconfig/base_dex_env_args.js +68 -0
- package/dist/appconfig/base_env_args.d.ts +82 -0
- package/dist/appconfig/base_env_args.js +91 -0
- package/dist/appconfig/ensure_core_env.d.ts +1 -0
- package/dist/appconfig/ensure_core_env.js +18 -0
- package/dist/appconfig/index.d.ts +5 -0
- package/dist/appconfig/index.js +21 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/quote/depth/amm_depth_calculator.d.ts +19 -0
- package/dist/quote/depth/amm_depth_calculator.js +55 -0
- package/dist/quote/depth/clmm_depth_calculator.d.ts +28 -0
- package/dist/quote/depth/clmm_depth_calculator.js +176 -0
- package/dist/quote/depth/index.d.ts +51 -0
- package/dist/quote/depth/index.js +264 -0
- package/dist/quote/depth/tick_liquidity_snapshot.d.ts +58 -0
- package/dist/quote/depth/tick_liquidity_snapshot.js +143 -0
- package/dist/quote/event/index.d.ts +1 -0
- package/dist/quote/event/index.js +1 -0
- package/dist/quote/event/pool_event_listener.d.ts +5 -3
- package/dist/quote/event/pool_event_listener.js +128 -150
- package/dist/quote/event/swap_debouncer.d.ts +22 -0
- package/dist/quote/event/swap_debouncer.js +80 -0
- package/dist/quote/get_base_token_price.d.ts +6 -0
- package/dist/quote/get_base_token_price.js +90 -0
- package/dist/quote/index.d.ts +7 -0
- package/dist/quote/index.js +7 -0
- package/dist/quote/preload_token_prices.d.ts +2 -0
- package/dist/quote/preload_token_prices.js +37 -0
- package/dist/quote/price_feed_handler.d.ts +15 -0
- package/dist/quote/price_feed_handler.js +56 -0
- package/dist/quote/pricing/fee_helpers.d.ts +13 -0
- package/dist/quote/pricing/fee_helpers.js +68 -0
- package/dist/quote/pricing/index.d.ts +3 -1
- package/dist/quote/pricing/index.js +3 -1
- package/dist/quote/pricing/pool_state_initializer.d.ts +12 -0
- package/dist/quote/pricing/pool_state_initializer.js +191 -0
- package/dist/quote/pricing/sdk_token_factory.d.ts +2 -0
- package/dist/quote/pricing/sdk_token_factory.js +21 -0
- package/dist/quote/quote_amount.d.ts +4 -0
- package/dist/quote/quote_amount.js +24 -0
- package/dist/quote/tick/cached_tick_data_provider.d.ts +12 -0
- package/dist/quote/tick/cached_tick_data_provider.js +45 -0
- package/dist/quote/tick/clmm_tick_cache.d.ts +42 -0
- package/dist/quote/tick/clmm_tick_cache.js +236 -0
- package/dist/quote/tick/index.d.ts +4 -0
- package/dist/{ws → quote/tick}/index.js +4 -2
- package/dist/quote/tick/state_view_tick_loader.d.ts +17 -0
- package/dist/quote/tick/state_view_tick_loader.js +136 -0
- package/dist/quote/tick/tick_lens_loaders.d.ts +24 -0
- package/dist/quote/tick/tick_lens_loaders.js +158 -0
- package/dist/quote/verify/index.d.ts +2 -0
- package/dist/quote/verify/index.js +5 -0
- package/dist/quote/verify/quote_price_verify.d.ts +30 -0
- package/dist/quote/verify/quote_price_verify.js +240 -0
- package/dist/redis/redis_client.d.ts +3 -2
- package/dist/redis/redis_client.js +86 -116
- package/dist/send-tx/constants.d.ts +2 -0
- package/dist/send-tx/constants.js +6 -0
- package/dist/send-tx/index.d.ts +2 -0
- package/dist/{config → send-tx}/index.js +2 -1
- package/dist/send-tx/types.d.ts +4 -0
- package/dist/send-tx/types.js +2 -0
- package/dist/trade/abstract_dex_trade.d.ts +43 -21
- package/dist/trade/abstract_dex_trade.js +347 -133
- package/dist/trade/caller_manager.d.ts +31 -0
- package/dist/trade/caller_manager.js +202 -0
- package/dist/trade/check/abstract_tx_result_checker.d.ts +28 -0
- package/dist/trade/check/abstract_tx_result_checker.js +192 -0
- package/dist/trade/check/index.d.ts +1 -1
- package/dist/trade/check/index.js +1 -1
- package/dist/trade/index.d.ts +2 -2
- package/dist/trade/index.js +2 -2
- package/dist/trade/parse/base_parser.d.ts +1 -2
- package/dist/trade/parse/base_parser.js +36 -36
- package/dist/trade/trade_trace.d.ts +17 -0
- package/dist/trade/trade_trace.js +65 -0
- package/dist/types/config_types.d.ts +3 -3
- package/dist/types/event_types.d.ts +3 -3
- package/dist/types/pool_state.d.ts +140 -13
- package/dist/utils/ethers_compat.d.ts +13 -0
- package/dist/utils/ethers_compat.js +18 -0
- package/dist/utils/fast_signer.d.ts +1 -0
- package/dist/utils/fast_signer.js +87 -0
- package/dist/utils/gas_helper.d.ts +2 -2
- package/dist/utils/gas_helper.js +48 -60
- package/dist/utils/index.d.ts +5 -2
- package/dist/utils/index.js +6 -2
- package/dist/utils/pool_filter.d.ts +8 -0
- package/dist/utils/pool_filter.js +38 -0
- package/dist/utils/trade_direction.d.ts +14 -0
- package/dist/utils/trade_direction.js +23 -0
- package/package.json +2 -2
- package/dist/config/base_env_args.d.ts +0 -11
- package/dist/config/base_env_args.js +0 -19
- package/dist/config/index.d.ts +0 -1
- package/dist/quote/event/verify_clmm_swap_event.d.ts +0 -1
- package/dist/quote/event/verify_clmm_swap_event.js +0 -178
- package/dist/quote/pricing/token_price_cache.d.ts +0 -10
- package/dist/quote/pricing/token_price_cache.js +0 -40
- package/dist/trade/abstract_dex_trade_plus.d.ts +0 -43
- package/dist/trade/abstract_dex_trade_plus.js +0 -421
- package/dist/trade/check/tx_websocket_manager.d.ts +0 -23
- package/dist/trade/check/tx_websocket_manager.js +0 -119
- package/dist/trade/send/alchemy_base.d.ts +0 -5
- package/dist/trade/send/alchemy_base.js +0 -48
- package/dist/trade/send/ankr_base.d.ts +0 -5
- package/dist/trade/send/ankr_base.js +0 -48
- package/dist/trade/send/base_rpc.d.ts +0 -5
- package/dist/trade/send/base_rpc.js +0 -48
- package/dist/trade/send/blockpi_base.d.ts +0 -5
- package/dist/trade/send/blockpi_base.js +0 -48
- package/dist/trade/send/bloxroute_base.d.ts +0 -11
- package/dist/trade/send/bloxroute_base.js +0 -115
- package/dist/trade/send/chainstack_base.d.ts +0 -5
- package/dist/trade/send/chainstack_base.js +0 -48
- package/dist/trade/send/drpc_base.d.ts +0 -5
- package/dist/trade/send/drpc_base.js +0 -48
- package/dist/trade/send/getblock_base.d.ts +0 -5
- package/dist/trade/send/getblock_base.js +0 -48
- package/dist/trade/send/index.d.ts +0 -15
- package/dist/trade/send/index.js +0 -33
- package/dist/trade/send/infura_base.d.ts +0 -5
- package/dist/trade/send/infura_base.js +0 -48
- package/dist/trade/send/moralis_base.d.ts +0 -5
- package/dist/trade/send/moralis_base.js +0 -48
- package/dist/trade/send/onerpc_base.d.ts +0 -5
- package/dist/trade/send/onerpc_base.js +0 -48
- package/dist/trade/send/quicknode_base.d.ts +0 -5
- package/dist/trade/send/quicknode_base.js +0 -48
- package/dist/trade/send/send_tx.d.ts +0 -17
- package/dist/trade/send/send_tx.js +0 -163
- package/dist/ws/event_filter.d.ts +0 -8
- package/dist/ws/event_filter.js +0 -36
- package/dist/ws/index.d.ts +0 -2
- package/dist/ws/subscribe_v2_events.d.ts +0 -14
- package/dist/ws/subscribe_v2_events.js +0 -174
- package/dist/ws/subscribe_v3_events.d.ts +0 -14
- package/dist/ws/subscribe_v3_events.js +0 -174
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export declare const TICK_REFRESH_INTERVAL_MS: number;
|
|
2
|
+
export interface TickInfo {
|
|
3
|
+
liquidityNet: bigint;
|
|
4
|
+
liquidityGross: bigint;
|
|
5
|
+
}
|
|
6
|
+
export interface ClmmTickCacheConfig {
|
|
7
|
+
neighboringWords?: number;
|
|
8
|
+
refreshInterval?: number;
|
|
9
|
+
minUpdateInterval?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface TickLensLoader {
|
|
12
|
+
loadBitmapWords(poolAddress: string, bitmapIndexes: number[]): Promise<Map<number, TickInfo>>;
|
|
13
|
+
}
|
|
14
|
+
export declare class ClmmTickCache {
|
|
15
|
+
private pools;
|
|
16
|
+
private refreshTimers;
|
|
17
|
+
private loadPromises;
|
|
18
|
+
private loader;
|
|
19
|
+
private config;
|
|
20
|
+
constructor(loader: TickLensLoader, config?: ClmmTickCacheConfig);
|
|
21
|
+
initPool(poolAddress: string, currentTick: number, tickSpacing: number): Promise<void>;
|
|
22
|
+
onSwap(poolAddress: string, newTick: number): Promise<void>;
|
|
23
|
+
onMint(poolAddress: string, tickLower: number, tickUpper: number, amount: bigint): void;
|
|
24
|
+
onBurn(poolAddress: string, tickLower: number, tickUpper: number, amount: bigint): void;
|
|
25
|
+
onModifyLiquidity(poolAddress: string, tickLower: number, tickUpper: number, liquidityDelta: bigint): void;
|
|
26
|
+
private applyLiquidityDelta;
|
|
27
|
+
private updateTickLiquidity;
|
|
28
|
+
getTickLiquidityNet(poolAddress: string, tickIndex: number): bigint | undefined;
|
|
29
|
+
getTickInfo(poolAddress: string, tickIndex: number): TickInfo | undefined;
|
|
30
|
+
getCachedTickIndices(poolAddress: string): number[];
|
|
31
|
+
getTickSpacing(poolAddress: string): number | undefined;
|
|
32
|
+
hasPool(poolAddress: string): boolean;
|
|
33
|
+
private scheduleFullRefresh;
|
|
34
|
+
private startPeriodicRefresh;
|
|
35
|
+
private doFullRefresh;
|
|
36
|
+
private getBitmapIndex;
|
|
37
|
+
private calcBitmapIndexes;
|
|
38
|
+
private isInCachedRange;
|
|
39
|
+
getNextInitializedTickWithinOneWord(poolAddress: string, tick: number, tickSpacing: number, zeroForOne: boolean): [number, boolean] | null;
|
|
40
|
+
clearPool(poolAddress: string): void;
|
|
41
|
+
destroy(): void;
|
|
42
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClmmTickCache = exports.TICK_REFRESH_INTERVAL_MS = void 0;
|
|
4
|
+
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
5
|
+
exports.TICK_REFRESH_INTERVAL_MS = Number(process.env.TICK_CACHE_FORCE_FULL_REFRESH_INTERVAL) || 60000;
|
|
6
|
+
class ClmmTickCache {
|
|
7
|
+
constructor(loader, config = {}) {
|
|
8
|
+
this.pools = new Map();
|
|
9
|
+
this.refreshTimers = new Map();
|
|
10
|
+
this.loadPromises = new Map();
|
|
11
|
+
this.loader = loader;
|
|
12
|
+
this.config = {
|
|
13
|
+
neighboringWords: config.neighboringWords ?? (Number(process.env.TICK_CACHE_NEIGHBORING_WORDS) || 2),
|
|
14
|
+
refreshInterval: config.refreshInterval ?? exports.TICK_REFRESH_INTERVAL_MS,
|
|
15
|
+
minUpdateInterval: config.minUpdateInterval ?? (Number(process.env.TICK_CACHE_MIN_UPDATE_INTERVAL) || 3000),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
async initPool(poolAddress, currentTick, tickSpacing) {
|
|
19
|
+
const bitmapIndexes = this.calcBitmapIndexes(currentTick, tickSpacing);
|
|
20
|
+
(0, ttd_core_1.log_info)(`[TickCache] Init pool ${poolAddress}: tick=${currentTick}, tickSpacing=${tickSpacing}, loading ${bitmapIndexes.length} bitmap words`);
|
|
21
|
+
const ticks = await this.loader.loadBitmapWords(poolAddress, bitmapIndexes);
|
|
22
|
+
this.pools.set(poolAddress, {
|
|
23
|
+
ticks,
|
|
24
|
+
bitmapIndexes,
|
|
25
|
+
currentTick,
|
|
26
|
+
tickSpacing,
|
|
27
|
+
lastFullLoadTime: Date.now(),
|
|
28
|
+
pendingForceRefresh: false,
|
|
29
|
+
loading: false,
|
|
30
|
+
});
|
|
31
|
+
this.startPeriodicRefresh(poolAddress);
|
|
32
|
+
(0, ttd_core_1.log_info)(`[TickCache] Pool ${poolAddress} initialized: ${ticks.size} ticks loaded`);
|
|
33
|
+
}
|
|
34
|
+
async onSwap(poolAddress, newTick) {
|
|
35
|
+
const state = this.pools.get(poolAddress);
|
|
36
|
+
if (!state)
|
|
37
|
+
return;
|
|
38
|
+
state.currentTick = newTick;
|
|
39
|
+
const currentBitmapIndex = this.getBitmapIndex(newTick, state.tickSpacing);
|
|
40
|
+
if (!state.bitmapIndexes.includes(currentBitmapIndex)) {
|
|
41
|
+
const cachedRange = `[${Math.min(...state.bitmapIndexes)}..${Math.max(...state.bitmapIndexes)}]`;
|
|
42
|
+
(0, ttd_core_1.log_info)(`[TickCache] 本地缓存 tick 缺失,开始同步 RPC 刷新: pool=${poolAddress.slice(0, 10)}..., tick=${newTick}, bitmapIndex=${currentBitmapIndex}, cachedWords=${cachedRange}`);
|
|
43
|
+
await this.scheduleFullRefresh(poolAddress);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
onMint(poolAddress, tickLower, tickUpper, amount) {
|
|
47
|
+
this.applyLiquidityDelta(poolAddress, tickLower, tickUpper, amount);
|
|
48
|
+
}
|
|
49
|
+
onBurn(poolAddress, tickLower, tickUpper, amount) {
|
|
50
|
+
this.applyLiquidityDelta(poolAddress, tickLower, tickUpper, -amount);
|
|
51
|
+
}
|
|
52
|
+
onModifyLiquidity(poolAddress, tickLower, tickUpper, liquidityDelta) {
|
|
53
|
+
this.applyLiquidityDelta(poolAddress, tickLower, tickUpper, liquidityDelta);
|
|
54
|
+
}
|
|
55
|
+
applyLiquidityDelta(poolAddress, tickLower, tickUpper, delta) {
|
|
56
|
+
const state = this.pools.get(poolAddress);
|
|
57
|
+
if (!state) {
|
|
58
|
+
(0, ttd_core_1.log_warn)(`[TickCache] Pool ${poolAddress} not initialized, ignoring liquidity event`);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const absDelta = delta < BigInt(0) ? -delta : delta;
|
|
62
|
+
let needAsyncRefresh = false;
|
|
63
|
+
needAsyncRefresh = this.updateTickLiquidity(state, tickLower, delta, absDelta, true) || needAsyncRefresh;
|
|
64
|
+
needAsyncRefresh = this.updateTickLiquidity(state, tickUpper, -delta, absDelta, false) || needAsyncRefresh;
|
|
65
|
+
if (needAsyncRefresh) {
|
|
66
|
+
this.scheduleFullRefresh(poolAddress);
|
|
67
|
+
}
|
|
68
|
+
(0, ttd_core_1.log_debug)(`[TickCache] Pool ${poolAddress}: liquidity delta applied, tickLower=${tickLower}, tickUpper=${tickUpper}, delta=${delta}`);
|
|
69
|
+
}
|
|
70
|
+
updateTickLiquidity(state, tickIndex, netDelta, grossDelta, isLower) {
|
|
71
|
+
const existing = state.ticks.get(tickIndex);
|
|
72
|
+
if (existing) {
|
|
73
|
+
existing.liquidityNet += netDelta;
|
|
74
|
+
existing.liquidityGross += (netDelta > BigInt(0) ? grossDelta : -grossDelta);
|
|
75
|
+
if (existing.liquidityGross <= BigInt(0)) {
|
|
76
|
+
state.ticks.delete(tickIndex);
|
|
77
|
+
(0, ttd_core_1.log_debug)(`[TickCache] Tick ${tickIndex} de-initialized (liquidityGross <= 0)`);
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
if (netDelta > BigInt(0) || grossDelta > BigInt(0)) {
|
|
82
|
+
if (this.isInCachedRange(state, tickIndex)) {
|
|
83
|
+
state.ticks.set(tickIndex, {
|
|
84
|
+
liquidityNet: netDelta,
|
|
85
|
+
liquidityGross: grossDelta,
|
|
86
|
+
});
|
|
87
|
+
(0, ttd_core_1.log_debug)(`[TickCache] New tick ${tickIndex} initialized in cached range`);
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
(0, ttd_core_1.log_debug)(`[TickCache] New tick ${tickIndex} outside cached range, will refresh async`);
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
getTickLiquidityNet(poolAddress, tickIndex) {
|
|
98
|
+
const state = this.pools.get(poolAddress);
|
|
99
|
+
if (!state)
|
|
100
|
+
return undefined;
|
|
101
|
+
return state.ticks.get(tickIndex)?.liquidityNet;
|
|
102
|
+
}
|
|
103
|
+
getTickInfo(poolAddress, tickIndex) {
|
|
104
|
+
const state = this.pools.get(poolAddress);
|
|
105
|
+
if (!state)
|
|
106
|
+
return undefined;
|
|
107
|
+
return state.ticks.get(tickIndex);
|
|
108
|
+
}
|
|
109
|
+
getCachedTickIndices(poolAddress) {
|
|
110
|
+
const state = this.pools.get(poolAddress);
|
|
111
|
+
if (!state)
|
|
112
|
+
return [];
|
|
113
|
+
return Array.from(state.ticks.keys()).sort((a, b) => a - b);
|
|
114
|
+
}
|
|
115
|
+
getTickSpacing(poolAddress) {
|
|
116
|
+
return this.pools.get(poolAddress)?.tickSpacing;
|
|
117
|
+
}
|
|
118
|
+
hasPool(poolAddress) {
|
|
119
|
+
return this.pools.has(poolAddress);
|
|
120
|
+
}
|
|
121
|
+
async scheduleFullRefresh(poolAddress) {
|
|
122
|
+
const state = this.pools.get(poolAddress);
|
|
123
|
+
if (!state)
|
|
124
|
+
return;
|
|
125
|
+
const existing = this.loadPromises.get(poolAddress);
|
|
126
|
+
if (existing) {
|
|
127
|
+
return existing;
|
|
128
|
+
}
|
|
129
|
+
const elapsed = Date.now() - state.lastFullLoadTime;
|
|
130
|
+
if (elapsed < this.config.minUpdateInterval) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const promise = this.doFullRefresh(poolAddress).finally(() => {
|
|
134
|
+
this.loadPromises.delete(poolAddress);
|
|
135
|
+
});
|
|
136
|
+
this.loadPromises.set(poolAddress, promise);
|
|
137
|
+
return promise;
|
|
138
|
+
}
|
|
139
|
+
startPeriodicRefresh(poolAddress) {
|
|
140
|
+
const old = this.refreshTimers.get(poolAddress);
|
|
141
|
+
if (old)
|
|
142
|
+
clearInterval(old);
|
|
143
|
+
const timer = setInterval(async () => {
|
|
144
|
+
try {
|
|
145
|
+
await this.doFullRefresh(poolAddress);
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
(0, ttd_core_1.log_warn)(`[TickCache] Periodic refresh failed for ${poolAddress}: ${err.message}`);
|
|
149
|
+
}
|
|
150
|
+
}, this.config.refreshInterval);
|
|
151
|
+
this.refreshTimers.set(poolAddress, timer);
|
|
152
|
+
}
|
|
153
|
+
async doFullRefresh(poolAddress) {
|
|
154
|
+
const state = this.pools.get(poolAddress);
|
|
155
|
+
if (!state)
|
|
156
|
+
return;
|
|
157
|
+
if (state.loading) {
|
|
158
|
+
state.pendingForceRefresh = true;
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
state.loading = true;
|
|
162
|
+
try {
|
|
163
|
+
const bitmapIndexes = this.calcBitmapIndexes(state.currentTick, state.tickSpacing);
|
|
164
|
+
const ticks = await this.loader.loadBitmapWords(poolAddress, bitmapIndexes);
|
|
165
|
+
state.ticks = ticks;
|
|
166
|
+
state.bitmapIndexes = bitmapIndexes;
|
|
167
|
+
state.lastFullLoadTime = Date.now();
|
|
168
|
+
state.pendingForceRefresh = false;
|
|
169
|
+
(0, ttd_core_1.log_debug)(`[TickCache] Full refresh for ${poolAddress}: ${ticks.size} ticks, ${bitmapIndexes.length} words`);
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
state.loading = false;
|
|
173
|
+
if (state.pendingForceRefresh) {
|
|
174
|
+
state.pendingForceRefresh = false;
|
|
175
|
+
this.doFullRefresh(poolAddress).catch(() => { });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
getBitmapIndex(tick, tickSpacing) {
|
|
180
|
+
return Math.floor(tick / tickSpacing / 256);
|
|
181
|
+
}
|
|
182
|
+
calcBitmapIndexes(currentTick, tickSpacing) {
|
|
183
|
+
const center = this.getBitmapIndex(currentTick, tickSpacing);
|
|
184
|
+
const n = this.config.neighboringWords;
|
|
185
|
+
const indexes = [];
|
|
186
|
+
for (let i = -n; i <= n; i++) {
|
|
187
|
+
indexes.push(center + i);
|
|
188
|
+
}
|
|
189
|
+
return indexes;
|
|
190
|
+
}
|
|
191
|
+
isInCachedRange(state, tickIndex) {
|
|
192
|
+
const bitmapIndex = this.getBitmapIndex(tickIndex, state.tickSpacing);
|
|
193
|
+
return state.bitmapIndexes.includes(bitmapIndex);
|
|
194
|
+
}
|
|
195
|
+
getNextInitializedTickWithinOneWord(poolAddress, tick, tickSpacing, zeroForOne) {
|
|
196
|
+
const state = this.pools.get(poolAddress);
|
|
197
|
+
if (!state)
|
|
198
|
+
return null;
|
|
199
|
+
const compressed = Math.floor(tick / tickSpacing);
|
|
200
|
+
const wordPos = compressed >> 8;
|
|
201
|
+
const wordStartTick = (wordPos << 8) * tickSpacing;
|
|
202
|
+
const wordEndTick = ((wordPos + 1) << 8) * tickSpacing;
|
|
203
|
+
const ticksInWord = Array.from(state.ticks.keys())
|
|
204
|
+
.filter(t => t >= wordStartTick && t < wordEndTick)
|
|
205
|
+
.sort((a, b) => a - b);
|
|
206
|
+
if (ticksInWord.length === 0)
|
|
207
|
+
return null;
|
|
208
|
+
if (zeroForOne) {
|
|
209
|
+
const nextTick = ticksInWord.find(t => t > tick);
|
|
210
|
+
if (nextTick !== undefined)
|
|
211
|
+
return [nextTick, true];
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
for (let i = ticksInWord.length - 1; i >= 0; i--) {
|
|
215
|
+
if (ticksInWord[i] < tick)
|
|
216
|
+
return [ticksInWord[i], true];
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
clearPool(poolAddress) {
|
|
222
|
+
this.pools.delete(poolAddress);
|
|
223
|
+
const timer = this.refreshTimers.get(poolAddress);
|
|
224
|
+
if (timer) {
|
|
225
|
+
clearInterval(timer);
|
|
226
|
+
this.refreshTimers.delete(poolAddress);
|
|
227
|
+
}
|
|
228
|
+
this.loadPromises.delete(poolAddress);
|
|
229
|
+
}
|
|
230
|
+
destroy() {
|
|
231
|
+
for (const [addr] of this.pools) {
|
|
232
|
+
this.clearPool(addr);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
exports.ClmmTickCache = ClmmTickCache;
|
|
@@ -14,5 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./clmm_tick_cache"), exports);
|
|
18
|
+
__exportStar(require("./tick_lens_loaders"), exports);
|
|
19
|
+
__exportStar(require("./cached_tick_data_provider"), exports);
|
|
20
|
+
__exportStar(require("./state_view_tick_loader"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TickInfo, TickLensLoader } from './clmm_tick_cache';
|
|
2
|
+
export declare class StateViewTickLensLoader implements TickLensLoader {
|
|
3
|
+
private ethersLib;
|
|
4
|
+
private provider;
|
|
5
|
+
private stateViewAddress;
|
|
6
|
+
private stateViewIface;
|
|
7
|
+
private multicallContract;
|
|
8
|
+
private tickSpacingMap;
|
|
9
|
+
constructor(params: {
|
|
10
|
+
ethersLib: any;
|
|
11
|
+
provider: any;
|
|
12
|
+
stateViewAddress: string;
|
|
13
|
+
multicallAddress?: string;
|
|
14
|
+
});
|
|
15
|
+
setTickSpacing(poolAddress: string, tickSpacing: number): void;
|
|
16
|
+
loadBitmapWords(poolAddress: string, bitmapIndexes: number[]): Promise<Map<number, TickInfo>>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StateViewTickLensLoader = void 0;
|
|
4
|
+
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
5
|
+
const tick_lens_loaders_1 = require("./tick_lens_loaders");
|
|
6
|
+
const STATE_VIEW_ABI = [
|
|
7
|
+
{
|
|
8
|
+
type: 'function',
|
|
9
|
+
name: 'getTickBitmap',
|
|
10
|
+
inputs: [
|
|
11
|
+
{ name: 'poolId', type: 'bytes32' },
|
|
12
|
+
{ name: 'tick', type: 'int16' },
|
|
13
|
+
],
|
|
14
|
+
outputs: [
|
|
15
|
+
{ name: 'tickBitmap', type: 'uint256' },
|
|
16
|
+
],
|
|
17
|
+
stateMutability: 'view',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
type: 'function',
|
|
21
|
+
name: 'getTickLiquidity',
|
|
22
|
+
inputs: [
|
|
23
|
+
{ name: 'poolId', type: 'bytes32' },
|
|
24
|
+
{ name: 'tick', type: 'int24' },
|
|
25
|
+
],
|
|
26
|
+
outputs: [
|
|
27
|
+
{ name: 'liquidityGross', type: 'uint128' },
|
|
28
|
+
{ name: 'liquidityNet', type: 'int128' },
|
|
29
|
+
],
|
|
30
|
+
stateMutability: 'view',
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
const MULTICALL3_ABI = [
|
|
34
|
+
{
|
|
35
|
+
type: 'function',
|
|
36
|
+
name: 'aggregate',
|
|
37
|
+
inputs: [
|
|
38
|
+
{
|
|
39
|
+
name: 'calls',
|
|
40
|
+
type: 'tuple[]',
|
|
41
|
+
components: [
|
|
42
|
+
{ name: 'target', type: 'address' },
|
|
43
|
+
{ name: 'callData', type: 'bytes' },
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
outputs: [
|
|
48
|
+
{ name: 'blockNumber', type: 'uint256' },
|
|
49
|
+
{ name: 'returnData', type: 'bytes[]' },
|
|
50
|
+
],
|
|
51
|
+
stateMutability: 'nonpayable',
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
function getInitializedTicksFromBitmap(bitmapIndex, bitmap, tickSpacing) {
|
|
55
|
+
const ticks = [];
|
|
56
|
+
for (let bit = 0; bit < 256; bit++) {
|
|
57
|
+
if ((bitmap >> BigInt(bit)) & BigInt(1)) {
|
|
58
|
+
const tickIndex = (bitmapIndex * 256 + bit) * tickSpacing;
|
|
59
|
+
ticks.push(tickIndex);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return ticks;
|
|
63
|
+
}
|
|
64
|
+
class StateViewTickLensLoader {
|
|
65
|
+
constructor(params) {
|
|
66
|
+
this.tickSpacingMap = new Map();
|
|
67
|
+
this.ethersLib = params.ethersLib;
|
|
68
|
+
this.provider = params.provider;
|
|
69
|
+
this.stateViewAddress = params.stateViewAddress;
|
|
70
|
+
const InterfaceClass = params.ethersLib.Interface || params.ethersLib.utils?.Interface;
|
|
71
|
+
if (!InterfaceClass) {
|
|
72
|
+
throw new Error('ethersLib.Interface not found');
|
|
73
|
+
}
|
|
74
|
+
this.stateViewIface = new InterfaceClass(STATE_VIEW_ABI);
|
|
75
|
+
this.multicallContract = new params.ethersLib.Contract(params.multicallAddress || tick_lens_loaders_1.MULTICALL3_ADDRESS, MULTICALL3_ABI, this.provider);
|
|
76
|
+
}
|
|
77
|
+
setTickSpacing(poolAddress, tickSpacing) {
|
|
78
|
+
this.tickSpacingMap.set(poolAddress.toLowerCase(), tickSpacing);
|
|
79
|
+
}
|
|
80
|
+
async loadBitmapWords(poolAddress, bitmapIndexes) {
|
|
81
|
+
const result = new Map();
|
|
82
|
+
if (bitmapIndexes.length === 0)
|
|
83
|
+
return result;
|
|
84
|
+
const tickSpacing = this.tickSpacingMap.get(poolAddress.toLowerCase());
|
|
85
|
+
if (!tickSpacing) {
|
|
86
|
+
(0, ttd_core_1.log_warn)(`[StateViewLoader] tickSpacing not set for ${poolAddress}, defaulting to 1`);
|
|
87
|
+
}
|
|
88
|
+
const spacing = tickSpacing || 1;
|
|
89
|
+
try {
|
|
90
|
+
const bitmapCalls = bitmapIndexes.map(bitmapIndex => ({
|
|
91
|
+
target: this.stateViewAddress,
|
|
92
|
+
callData: this.stateViewIface.encodeFunctionData('getTickBitmap', [poolAddress, bitmapIndex]),
|
|
93
|
+
}));
|
|
94
|
+
const callMethod = this.multicallContract.aggregate.staticCall || this.multicallContract.callStatic?.aggregate;
|
|
95
|
+
const [, bitmapReturnData] = await callMethod(bitmapCalls);
|
|
96
|
+
const initializedTicks = [];
|
|
97
|
+
for (let i = 0; i < bitmapReturnData.length; i++) {
|
|
98
|
+
try {
|
|
99
|
+
const decoded = this.stateViewIface.decodeFunctionResult('getTickBitmap', bitmapReturnData[i]);
|
|
100
|
+
const bitmap = typeof decoded[0] === 'bigint' ? decoded[0] : BigInt(decoded[0].toString());
|
|
101
|
+
const ticks = getInitializedTicksFromBitmap(bitmapIndexes[i], bitmap, spacing);
|
|
102
|
+
initializedTicks.push(...ticks);
|
|
103
|
+
}
|
|
104
|
+
catch (e) {
|
|
105
|
+
(0, ttd_core_1.log_warn)(`[StateViewLoader] Failed to decode bitmap ${bitmapIndexes[i]}: ${e.message}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (initializedTicks.length === 0) {
|
|
109
|
+
(0, ttd_core_1.log_debug)(`[StateViewLoader] No initialized ticks in ${bitmapIndexes.length} bitmap words`);
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
const liquidityCalls = initializedTicks.map(tick => ({
|
|
113
|
+
target: this.stateViewAddress,
|
|
114
|
+
callData: this.stateViewIface.encodeFunctionData('getTickLiquidity', [poolAddress, tick]),
|
|
115
|
+
}));
|
|
116
|
+
const [, liquidityReturnData] = await callMethod(liquidityCalls);
|
|
117
|
+
for (let i = 0; i < liquidityReturnData.length; i++) {
|
|
118
|
+
try {
|
|
119
|
+
const decoded = this.stateViewIface.decodeFunctionResult('getTickLiquidity', liquidityReturnData[i]);
|
|
120
|
+
const liquidityGross = typeof decoded[0] === 'bigint' ? decoded[0] : BigInt(decoded[0].toString());
|
|
121
|
+
const liquidityNet = typeof decoded[1] === 'bigint' ? decoded[1] : BigInt(decoded[1].toString());
|
|
122
|
+
result.set(initializedTicks[i], { liquidityNet, liquidityGross });
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
(0, ttd_core_1.log_warn)(`[StateViewLoader] Failed to decode tick ${initializedTicks[i]}: ${e.message}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
(0, ttd_core_1.log_debug)(`[StateViewLoader] Loaded ${result.size} ticks from ${bitmapIndexes.length} bitmap words (2 Multicall3 calls)`);
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
(0, ttd_core_1.log_warn)(`[StateViewLoader] Multicall failed: ${error.message}`);
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.StateViewTickLensLoader = StateViewTickLensLoader;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TickInfo, TickLensLoader } from "./clmm_tick_cache";
|
|
2
|
+
export declare const MULTICALL3_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11";
|
|
3
|
+
export declare const BASE_TICK_LENS_ADDRESSES: {
|
|
4
|
+
readonly UNISWAP_V3: "0x0CdeE061c75D43c82520eD998C23ac2991c9ac6d";
|
|
5
|
+
readonly UNISWAP_V4: "0xA3c0c9b65baD0b08107Aa264b0f3dB444b867A71";
|
|
6
|
+
};
|
|
7
|
+
export declare class MulticallTickLensLoader implements TickLensLoader {
|
|
8
|
+
private ethersLib;
|
|
9
|
+
private provider;
|
|
10
|
+
private tickLensAddress;
|
|
11
|
+
private tickLensAbi;
|
|
12
|
+
private multicallAddress;
|
|
13
|
+
private tickLensIface;
|
|
14
|
+
private multicallContract;
|
|
15
|
+
constructor(params: {
|
|
16
|
+
ethersLib: any;
|
|
17
|
+
provider: any;
|
|
18
|
+
tickLensAddress: string;
|
|
19
|
+
version: 'V3' | 'V4';
|
|
20
|
+
multicallAddress?: string;
|
|
21
|
+
});
|
|
22
|
+
loadBitmapWords(poolAddress: string, bitmapIndexes: number[]): Promise<Map<number, TickInfo>>;
|
|
23
|
+
private loadBitmapWordsIndividually;
|
|
24
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MulticallTickLensLoader = exports.BASE_TICK_LENS_ADDRESSES = exports.MULTICALL3_ADDRESS = void 0;
|
|
4
|
+
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
5
|
+
exports.MULTICALL3_ADDRESS = '0xcA11bde05977b3631167028862bE2a173976CA11';
|
|
6
|
+
exports.BASE_TICK_LENS_ADDRESSES = {
|
|
7
|
+
UNISWAP_V3: '0x0CdeE061c75D43c82520eD998C23ac2991c9ac6d',
|
|
8
|
+
UNISWAP_V4: '0xA3c0c9b65baD0b08107Aa264b0f3dB444b867A71',
|
|
9
|
+
};
|
|
10
|
+
const V3_TICK_LENS_ABI = [
|
|
11
|
+
{
|
|
12
|
+
type: 'function',
|
|
13
|
+
name: 'getPopulatedTicksInWord',
|
|
14
|
+
inputs: [
|
|
15
|
+
{ name: 'pool', type: 'address' },
|
|
16
|
+
{ name: 'tickBitmapIndex', type: 'int16' },
|
|
17
|
+
],
|
|
18
|
+
outputs: [
|
|
19
|
+
{
|
|
20
|
+
name: 'populatedTicks',
|
|
21
|
+
type: 'tuple[]',
|
|
22
|
+
components: [
|
|
23
|
+
{ name: 'tick', type: 'int24' },
|
|
24
|
+
{ name: 'liquidityNet', type: 'int128' },
|
|
25
|
+
{ name: 'liquidityGross', type: 'uint128' },
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
stateMutability: 'view',
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
const V4_TICK_LENS_ABI = [
|
|
33
|
+
{
|
|
34
|
+
type: 'function',
|
|
35
|
+
name: 'getPopulatedTicksInWord',
|
|
36
|
+
inputs: [
|
|
37
|
+
{ name: 'id', type: 'bytes32' },
|
|
38
|
+
{ name: 'tickBitmapIndex', type: 'int16' },
|
|
39
|
+
],
|
|
40
|
+
outputs: [
|
|
41
|
+
{
|
|
42
|
+
name: 'populatedTicks',
|
|
43
|
+
type: 'tuple[]',
|
|
44
|
+
components: [
|
|
45
|
+
{ name: 'tick', type: 'int24' },
|
|
46
|
+
{ name: 'liquidityNet', type: 'int128' },
|
|
47
|
+
{ name: 'liquidityGross', type: 'uint128' },
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
stateMutability: 'view',
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
const MULTICALL3_ABI = [
|
|
55
|
+
{
|
|
56
|
+
type: 'function',
|
|
57
|
+
name: 'aggregate',
|
|
58
|
+
inputs: [
|
|
59
|
+
{
|
|
60
|
+
name: 'calls',
|
|
61
|
+
type: 'tuple[]',
|
|
62
|
+
components: [
|
|
63
|
+
{ name: 'target', type: 'address' },
|
|
64
|
+
{ name: 'callData', type: 'bytes' },
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
outputs: [
|
|
69
|
+
{ name: 'blockNumber', type: 'uint256' },
|
|
70
|
+
{ name: 'returnData', type: 'bytes[]' },
|
|
71
|
+
],
|
|
72
|
+
stateMutability: 'nonpayable',
|
|
73
|
+
},
|
|
74
|
+
];
|
|
75
|
+
class MulticallTickLensLoader {
|
|
76
|
+
constructor(params) {
|
|
77
|
+
this.ethersLib = params.ethersLib;
|
|
78
|
+
this.provider = params.provider;
|
|
79
|
+
this.tickLensAddress = params.tickLensAddress;
|
|
80
|
+
this.tickLensAbi = params.version === 'V4' ? V4_TICK_LENS_ABI : V3_TICK_LENS_ABI;
|
|
81
|
+
this.multicallAddress = params.multicallAddress || exports.MULTICALL3_ADDRESS;
|
|
82
|
+
const InterfaceClass = params.ethersLib.Interface || params.ethersLib.utils?.Interface;
|
|
83
|
+
if (!InterfaceClass) {
|
|
84
|
+
throw new Error('ethersLib.Interface not found, ensure ethers v5 or v6 is passed');
|
|
85
|
+
}
|
|
86
|
+
this.tickLensIface = new InterfaceClass(this.tickLensAbi);
|
|
87
|
+
this.multicallContract = new params.ethersLib.Contract(this.multicallAddress, MULTICALL3_ABI, this.provider);
|
|
88
|
+
}
|
|
89
|
+
async loadBitmapWords(poolAddress, bitmapIndexes) {
|
|
90
|
+
const result = new Map();
|
|
91
|
+
if (bitmapIndexes.length === 0)
|
|
92
|
+
return result;
|
|
93
|
+
try {
|
|
94
|
+
const calls = bitmapIndexes.map(bitmapIndex => {
|
|
95
|
+
const callData = this.tickLensIface.encodeFunctionData('getPopulatedTicksInWord', [
|
|
96
|
+
poolAddress,
|
|
97
|
+
bitmapIndex,
|
|
98
|
+
]);
|
|
99
|
+
return {
|
|
100
|
+
target: this.tickLensAddress,
|
|
101
|
+
callData,
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
const callMethod = this.multicallContract.aggregate.staticCall || this.multicallContract.callStatic?.aggregate;
|
|
105
|
+
const [, returnData] = await callMethod(calls);
|
|
106
|
+
for (let i = 0; i < returnData.length; i++) {
|
|
107
|
+
try {
|
|
108
|
+
const decoded = this.tickLensIface.decodeFunctionResult('getPopulatedTicksInWord', returnData[i]);
|
|
109
|
+
const populatedTicks = decoded[0];
|
|
110
|
+
if (!populatedTicks || populatedTicks.length === 0)
|
|
111
|
+
continue;
|
|
112
|
+
for (const tick of populatedTicks) {
|
|
113
|
+
const tickIndex = typeof tick.tick === 'bigint' ? Number(tick.tick) : tick.tick;
|
|
114
|
+
result.set(tickIndex, {
|
|
115
|
+
liquidityNet: typeof tick.liquidityNet === 'bigint'
|
|
116
|
+
? tick.liquidityNet
|
|
117
|
+
: BigInt(String(tick.liquidityNet)),
|
|
118
|
+
liquidityGross: typeof tick.liquidityGross === 'bigint'
|
|
119
|
+
? tick.liquidityGross
|
|
120
|
+
: BigInt(String(tick.liquidityGross)),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
(0, ttd_core_1.log_warn)(`[TickLensLoader] Failed to decode bitmap index ${bitmapIndexes[i]}: ${e.message}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
(0, ttd_core_1.log_debug)(`[TickLensLoader] Loaded ${result.size} ticks from ${bitmapIndexes.length} bitmap words (1 RPC call)`);
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
(0, ttd_core_1.log_warn)(`[TickLensLoader] Multicall failed, falling back to individual queries: ${error.message}`);
|
|
132
|
+
await this.loadBitmapWordsIndividually(poolAddress, bitmapIndexes, result);
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
async loadBitmapWordsIndividually(poolAddress, bitmapIndexes, result) {
|
|
137
|
+
const tickLensContract = new this.ethersLib.Contract(this.tickLensAddress, this.tickLensAbi, this.provider);
|
|
138
|
+
const promises = bitmapIndexes.map(async (bitmapIndex) => {
|
|
139
|
+
try {
|
|
140
|
+
const callMethod = tickLensContract.getPopulatedTicksInWord.staticCall
|
|
141
|
+
|| tickLensContract.callStatic?.getPopulatedTicksInWord;
|
|
142
|
+
const populatedTicks = await callMethod(poolAddress, bitmapIndex);
|
|
143
|
+
for (const tick of populatedTicks) {
|
|
144
|
+
const tickIndex = Number(tick.tick);
|
|
145
|
+
result.set(tickIndex, {
|
|
146
|
+
liquidityNet: BigInt(tick.liquidityNet.toString()),
|
|
147
|
+
liquidityGross: BigInt(tick.liquidityGross.toString()),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch (e) {
|
|
152
|
+
(0, ttd_core_1.log_warn)(`[TickLensLoader] Bitmap index ${bitmapIndex} query failed for ${poolAddress}`);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
await Promise.all(promises);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.MulticallTickLensLoader = MulticallTickLensLoader;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QuotePriceVerify = void 0;
|
|
4
|
+
var quote_price_verify_1 = require("./quote_price_verify");
|
|
5
|
+
Object.defineProperty(exports, "QuotePriceVerify", { enumerable: true, get: function () { return quote_price_verify_1.QuotePriceVerify; } });
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { QuoteTier } from '@clonegod/ttd-core';
|
|
2
|
+
export interface CheckSwapParams {
|
|
3
|
+
poolAddress: string;
|
|
4
|
+
poolName: string;
|
|
5
|
+
blockNumber: number;
|
|
6
|
+
txHash: string;
|
|
7
|
+
amount0: string;
|
|
8
|
+
amount1: string;
|
|
9
|
+
token0Address: string;
|
|
10
|
+
token1Address: string;
|
|
11
|
+
token0Decimals: number;
|
|
12
|
+
token1Decimals: number;
|
|
13
|
+
poolInfo: {
|
|
14
|
+
tokenA: any;
|
|
15
|
+
tokenB: any;
|
|
16
|
+
quote_token: string;
|
|
17
|
+
};
|
|
18
|
+
swapperDeltaConvention?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare class QuotePriceVerify {
|
|
21
|
+
private quoteCache;
|
|
22
|
+
private get enabled();
|
|
23
|
+
cacheQuote(poolAddress: string, priceId: string, source: string, askPrice: number, bidPrice: number, blockNumber: number, quoteAmountUsd: number, token0PriceUsd?: number, token1PriceUsd?: number, tiers?: {
|
|
24
|
+
askTiers?: QuoteTier[];
|
|
25
|
+
bidTiers?: QuoteTier[];
|
|
26
|
+
}): void;
|
|
27
|
+
checkSwap(params: CheckSwapParams): void;
|
|
28
|
+
private deriveSwapDirection;
|
|
29
|
+
private compareAndLog;
|
|
30
|
+
}
|