@clonegod/ttd-bsc-common 1.0.90 → 2.0.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/config/BscQuoteAppConfig.d.ts +11 -0
- package/dist/config/BscQuoteAppConfig.js +62 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.js +1 -0
- package/dist/quote/event/index.d.ts +1 -0
- package/dist/quote/event/index.js +1 -0
- package/dist/quote/event/swap_debouncer.d.ts +22 -0
- package/dist/quote/event/swap_debouncer.js +92 -0
- package/dist/quote/index.d.ts +1 -0
- package/dist/quote/index.js +1 -0
- package/dist/quote/pricing/index.d.ts +2 -0
- package/dist/quote/pricing/index.js +2 -0
- package/dist/quote/pricing/pool_state_initializer.d.ts +8 -0
- package/dist/quote/pricing/pool_state_initializer.js +142 -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/tick/clmm_tick_cache.d.ts +40 -0
- package/dist/quote/tick/clmm_tick_cache.js +219 -0
- package/dist/quote/tick/index.d.ts +2 -0
- package/dist/{trade/send → quote/tick}/index.js +2 -8
- package/dist/quote/tick/tick_lens_loaders.d.ts +25 -0
- package/dist/quote/tick/tick_lens_loaders.js +170 -0
- package/dist/redis/redis_client.d.ts +1 -0
- package/dist/redis/redis_client.js +6 -0
- package/dist/trade/abstract_dex_trade.d.ts +30 -16
- package/dist/trade/abstract_dex_trade.js +223 -108
- package/dist/trade/caller_manager.d.ts +35 -0
- package/dist/trade/caller_manager.js +178 -0
- package/dist/trade/index.d.ts +1 -2
- package/dist/trade/index.js +1 -2
- package/dist/types/pool_state.d.ts +31 -0
- package/package.json +3 -2
- package/dist/trade/abstract_dex_trade_plus.d.ts +0 -44
- package/dist/trade/abstract_dex_trade_plus.js +0 -449
- package/dist/trade/send/48club.d.ts +0 -17
- package/dist/trade/send/48club.js +0 -123
- package/dist/trade/send/48club_member.d.ts +0 -1
- package/dist/trade/send/48club_member.js +0 -25
- package/dist/trade/send/48club_sp.d.ts +0 -9
- package/dist/trade/send/48club_sp.js +0 -137
- package/dist/trade/send/blockrazor.d.ts +0 -7
- package/dist/trade/send/blockrazor.js +0 -78
- package/dist/trade/send/blxr.d.ts +0 -0
- package/dist/trade/send/blxr.js +0 -0
- package/dist/trade/send/bsc_rpc.d.ts +0 -6
- package/dist/trade/send/bsc_rpc.js +0 -47
- package/dist/trade/send/index.d.ts +0 -6
- package/dist/trade/send/send_bundle_proxy.d.ts +0 -7
- package/dist/trade/send/send_bundle_proxy.js +0 -30
- package/dist/trade/send/send_bundle_ws.d.ts +0 -7
- package/dist/trade/send/send_bundle_ws.js +0 -30
- package/dist/trade/send/send_tx.d.ts +0 -9
- package/dist/trade/send/send_tx.js +0 -119
- package/dist/ws/bsc_stream_ws_client.d.ts +0 -10
- package/dist/ws/bsc_stream_ws_client.js +0 -95
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BscEnvArgs } from "./bsc_env_args";
|
|
2
|
+
import { AppConfig } from "@clonegod/ttd-core/dist";
|
|
3
|
+
export declare class BscQuoteAppConfig extends AppConfig {
|
|
4
|
+
private eventEmitter;
|
|
5
|
+
env_args: BscEnvArgs;
|
|
6
|
+
constructor();
|
|
7
|
+
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
|
8
|
+
emit(eventName: string | symbol, ...args: any[]): boolean;
|
|
9
|
+
init(): Promise<void>;
|
|
10
|
+
subscribe_config_change(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.BscQuoteAppConfig = void 0;
|
|
13
|
+
const bsc_env_args_1 = require("./bsc_env_args");
|
|
14
|
+
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
15
|
+
const events_1 = require("events");
|
|
16
|
+
class BscQuoteAppConfig extends dist_1.AppConfig {
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
this.eventEmitter = new events_1.EventEmitter();
|
|
20
|
+
this.env_args = new bsc_env_args_1.BscEnvArgs();
|
|
21
|
+
}
|
|
22
|
+
on(eventName, listener) {
|
|
23
|
+
this.eventEmitter.on(eventName, listener);
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
emit(eventName, ...args) {
|
|
27
|
+
return this.eventEmitter.emit(eventName, ...args);
|
|
28
|
+
}
|
|
29
|
+
init() {
|
|
30
|
+
const _super = Object.create(null, {
|
|
31
|
+
init: { get: () => super.init }
|
|
32
|
+
});
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
yield _super.init.call(this);
|
|
35
|
+
yield this.arb_cache.init();
|
|
36
|
+
if (!this.arb_event_subscriber) {
|
|
37
|
+
this.arb_event_subscriber = (0, dist_1.getArbEventSubscriber)(this.arb_cache);
|
|
38
|
+
}
|
|
39
|
+
(0, dist_1.log_info)('BscQuoteAppConfig initialized', {
|
|
40
|
+
chain_id: this.env_args.chain_id,
|
|
41
|
+
dex_id: this.env_args.dex_id,
|
|
42
|
+
quote_pair: this.env_args.quote_pair,
|
|
43
|
+
rpc_endpoint: this.env_args.rpc_endpoint,
|
|
44
|
+
ws_endpoint: this.env_args.ws_endpoint,
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
subscribe_config_change() {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
this.on('config_change', (config) => __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
(0, dist_1.log_info)('Config change received', config);
|
|
52
|
+
if (config.env_args) {
|
|
53
|
+
this.env_args = new bsc_env_args_1.BscEnvArgs();
|
|
54
|
+
}
|
|
55
|
+
if (config.arb_cache) {
|
|
56
|
+
yield this.arb_cache.init();
|
|
57
|
+
}
|
|
58
|
+
}));
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.BscQuoteAppConfig = BscQuoteAppConfig;
|
package/dist/config/index.d.ts
CHANGED
package/dist/config/index.js
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare class SwapDebouncer<TEvent extends {
|
|
2
|
+
pool_address: string;
|
|
3
|
+
type: string;
|
|
4
|
+
data: {
|
|
5
|
+
blockNumber: number;
|
|
6
|
+
};
|
|
7
|
+
}, TResult = void> {
|
|
8
|
+
private debounceMs;
|
|
9
|
+
private onCalculate;
|
|
10
|
+
private onPublish;
|
|
11
|
+
private debouncedTypes;
|
|
12
|
+
private windows;
|
|
13
|
+
private latestBlock;
|
|
14
|
+
constructor(config: {
|
|
15
|
+
onCalculate: (event: TEvent) => TResult | Promise<TResult>;
|
|
16
|
+
onPublish: (event: TEvent, result: TResult) => void;
|
|
17
|
+
debouncedEventTypes?: string[];
|
|
18
|
+
});
|
|
19
|
+
onEvent(event: TEvent): Promise<void>;
|
|
20
|
+
flush(): void;
|
|
21
|
+
private startWindow;
|
|
22
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.SwapDebouncer = void 0;
|
|
13
|
+
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
14
|
+
class SwapDebouncer {
|
|
15
|
+
constructor(config) {
|
|
16
|
+
this.windows = new Map();
|
|
17
|
+
this.latestBlock = new Map();
|
|
18
|
+
this.debounceMs = parseInt(process.env.SWAP_DEBOUNCE_MS || '3', 10);
|
|
19
|
+
this.onCalculate = config.onCalculate;
|
|
20
|
+
this.onPublish = config.onPublish;
|
|
21
|
+
this.debouncedTypes = new Set((config.debouncedEventTypes || ['swap']).map(t => t.toLowerCase()));
|
|
22
|
+
}
|
|
23
|
+
onEvent(event) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
const poolAddress = event.pool_address;
|
|
27
|
+
const blockNumber = ((_a = event.data) === null || _a === void 0 ? void 0 : _a.blockNumber) || 0;
|
|
28
|
+
if (blockNumber > 0) {
|
|
29
|
+
const lastBlock = this.latestBlock.get(poolAddress) || 0;
|
|
30
|
+
if (blockNumber < lastBlock) {
|
|
31
|
+
(0, dist_1.log_warn)(`SwapDebouncer: stale block dropped, pool=${poolAddress}, event block=${blockNumber}, latest=${lastBlock}`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
this.latestBlock.set(poolAddress, blockNumber);
|
|
35
|
+
}
|
|
36
|
+
const eventType = (_b = event.type) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
|
37
|
+
if (!this.debouncedTypes.has(eventType)) {
|
|
38
|
+
const result = yield this.onCalculate(event);
|
|
39
|
+
this.onPublish(event, result);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const window = this.windows.get(poolAddress);
|
|
43
|
+
const result = yield this.onCalculate(event);
|
|
44
|
+
if (window) {
|
|
45
|
+
if (blockNumber > window.blockNumber) {
|
|
46
|
+
if (!window.expired) {
|
|
47
|
+
clearTimeout(window.timer);
|
|
48
|
+
this.onPublish(window.latestEvent, window.latestResult);
|
|
49
|
+
}
|
|
50
|
+
this.windows.delete(poolAddress);
|
|
51
|
+
this.startWindow(poolAddress, event, result, blockNumber);
|
|
52
|
+
}
|
|
53
|
+
else if (window.expired) {
|
|
54
|
+
this.onPublish(event, result);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
window.latestEvent = event;
|
|
58
|
+
window.latestResult = result;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
this.startWindow(poolAddress, event, result, blockNumber);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
flush() {
|
|
67
|
+
for (const [_, window] of this.windows) {
|
|
68
|
+
if (!window.expired) {
|
|
69
|
+
clearTimeout(window.timer);
|
|
70
|
+
this.onPublish(window.latestEvent, window.latestResult);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
this.windows.clear();
|
|
74
|
+
}
|
|
75
|
+
startWindow(poolAddress, event, result, blockNumber) {
|
|
76
|
+
const timer = setTimeout(() => {
|
|
77
|
+
const w = this.windows.get(poolAddress);
|
|
78
|
+
if (w) {
|
|
79
|
+
w.expired = true;
|
|
80
|
+
this.onPublish(w.latestEvent, w.latestResult);
|
|
81
|
+
}
|
|
82
|
+
}, this.debounceMs);
|
|
83
|
+
this.windows.set(poolAddress, {
|
|
84
|
+
blockNumber,
|
|
85
|
+
latestEvent: event,
|
|
86
|
+
latestResult: result,
|
|
87
|
+
timer,
|
|
88
|
+
expired: false,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.SwapDebouncer = SwapDebouncer;
|
package/dist/quote/index.d.ts
CHANGED
package/dist/quote/index.js
CHANGED
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./event"), exports);
|
|
18
18
|
__exportStar(require("./pricing"), exports);
|
|
19
|
+
__exportStar(require("./tick"), exports);
|
|
@@ -16,3 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./token_price_cache"), exports);
|
|
18
18
|
__exportStar(require("./pool"), exports);
|
|
19
|
+
__exportStar(require("./sdk_token_factory"), exports);
|
|
20
|
+
__exportStar(require("./pool_state_initializer"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AmmPoolState, ClmmPoolState, InfinityPoolState } from "../../types/pool_state";
|
|
2
|
+
export declare class PoolStateInitializer {
|
|
3
|
+
static initAmmPool(provider: any, poolAddress: string, dexId: string, ethersLib: any): Promise<AmmPoolState>;
|
|
4
|
+
static initClmmPool(provider: any, poolAddress: string, ethersLib: any, poolAbi?: any[]): Promise<ClmmPoolState>;
|
|
5
|
+
static initInfinityPool(provider: any, poolKey: string, poolManagerAddress: string, poolManagerAbi: any, ethersLib: any, decodeParameters: (params: string) => {
|
|
6
|
+
tickSpacing: number;
|
|
7
|
+
}): Promise<InfinityPoolState>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PoolStateInitializer = void 0;
|
|
13
|
+
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
14
|
+
const V2_PAIR_ABI = [
|
|
15
|
+
'function token0() view returns (address)',
|
|
16
|
+
'function token1() view returns (address)',
|
|
17
|
+
'function getReserves() view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast)',
|
|
18
|
+
];
|
|
19
|
+
const V3_POOL_ABI = [
|
|
20
|
+
'function token0() view returns (address)',
|
|
21
|
+
'function token1() view returns (address)',
|
|
22
|
+
'function fee() view returns (uint24)',
|
|
23
|
+
'function tickSpacing() view returns (int24)',
|
|
24
|
+
'function slot0() view returns (uint160 sqrtPriceX96, int24 tick, uint16 observationIndex, uint16 observationCardinality, uint16 observationCardinalityNext, uint8 feeProtocol, bool unlocked)',
|
|
25
|
+
'function liquidity() view returns (uint128)',
|
|
26
|
+
];
|
|
27
|
+
const AMM_FEE_MAP = {
|
|
28
|
+
'PANCAKE-AMM': 25,
|
|
29
|
+
'PANCAKE_AMM': 25,
|
|
30
|
+
'UNISWAP-AMM': 30,
|
|
31
|
+
'UNISWAP_AMM': 30,
|
|
32
|
+
};
|
|
33
|
+
class PoolStateInitializer {
|
|
34
|
+
static initAmmPool(provider, poolAddress, dexId, ethersLib) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
try {
|
|
37
|
+
const poolContract = new ethersLib.Contract(poolAddress, V2_PAIR_ABI, provider);
|
|
38
|
+
const [reserves, token0, token1] = yield Promise.all([
|
|
39
|
+
poolContract.getReserves(),
|
|
40
|
+
poolContract.token0(),
|
|
41
|
+
poolContract.token1(),
|
|
42
|
+
]);
|
|
43
|
+
const fee = AMM_FEE_MAP[dexId] || AMM_FEE_MAP[dexId.replace('-', '_')] || 30;
|
|
44
|
+
const state = {
|
|
45
|
+
address: poolAddress,
|
|
46
|
+
token0: token0.toLowerCase(),
|
|
47
|
+
token1: token1.toLowerCase(),
|
|
48
|
+
fee,
|
|
49
|
+
reserve0: reserves[0].toString(),
|
|
50
|
+
reserve1: reserves[1].toString(),
|
|
51
|
+
};
|
|
52
|
+
(0, dist_1.log_info)(`[PoolStateInitializer] AMM pool initialized: ${poolAddress}`, {
|
|
53
|
+
token0: state.token0, token1: state.token1, fee: state.fee,
|
|
54
|
+
});
|
|
55
|
+
return state;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
(0, dist_1.log_error)(`[PoolStateInitializer] Failed to init AMM pool ${poolAddress}:`, error);
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
static initClmmPool(provider, poolAddress, ethersLib, poolAbi) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
try {
|
|
66
|
+
const abi = poolAbi || V3_POOL_ABI;
|
|
67
|
+
const poolContract = new ethersLib.Contract(poolAddress, abi, provider);
|
|
68
|
+
const [token0, token1, fee, tickSpacing, slot0, liquidity] = yield Promise.all([
|
|
69
|
+
poolContract.token0(),
|
|
70
|
+
poolContract.token1(),
|
|
71
|
+
poolContract.fee(),
|
|
72
|
+
poolContract.tickSpacing(),
|
|
73
|
+
poolContract.slot0(),
|
|
74
|
+
poolContract.liquidity(),
|
|
75
|
+
]);
|
|
76
|
+
const [sqrtPriceX96, tick] = slot0;
|
|
77
|
+
const state = {
|
|
78
|
+
address: poolAddress,
|
|
79
|
+
token0: token0.toLowerCase(),
|
|
80
|
+
token1: token1.toLowerCase(),
|
|
81
|
+
fee: Number(fee),
|
|
82
|
+
tickSpacing: Number(tickSpacing),
|
|
83
|
+
tick: Number(tick),
|
|
84
|
+
sqrtPriceX96: sqrtPriceX96.toString(),
|
|
85
|
+
liquidity: liquidity.toString(),
|
|
86
|
+
};
|
|
87
|
+
(0, dist_1.log_info)(`[PoolStateInitializer] CLMM pool initialized: ${poolAddress}`, {
|
|
88
|
+
token0: state.token0, token1: state.token1,
|
|
89
|
+
fee: state.fee, tickSpacing: state.tickSpacing, tick: state.tick,
|
|
90
|
+
});
|
|
91
|
+
return state;
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
(0, dist_1.log_error)(`[PoolStateInitializer] Failed to init CLMM pool ${poolAddress}:`, error);
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
static initInfinityPool(provider, poolKey, poolManagerAddress, poolManagerAbi, ethersLib, decodeParameters) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
try {
|
|
102
|
+
const poolManagerContract = new ethersLib.Contract(poolManagerAddress, poolManagerAbi, provider);
|
|
103
|
+
const [slot0Result, liquidity, poolKeyInfo] = yield Promise.all([
|
|
104
|
+
poolManagerContract.getSlot0(poolKey),
|
|
105
|
+
poolManagerContract.getLiquidity(poolKey),
|
|
106
|
+
poolManagerContract.poolIdToPoolKey(poolKey),
|
|
107
|
+
]);
|
|
108
|
+
const [sqrtPriceX96, tick, protocolFee, lpFee] = slot0Result;
|
|
109
|
+
const [currency0, currency1, hooks, poolManager, fee, parameters] = poolKeyInfo;
|
|
110
|
+
const { tickSpacing } = decodeParameters(parameters);
|
|
111
|
+
const state = {
|
|
112
|
+
address: poolKey,
|
|
113
|
+
token0: currency0.toLowerCase ? currency0.toLowerCase() : currency0,
|
|
114
|
+
token1: currency1.toLowerCase ? currency1.toLowerCase() : currency1,
|
|
115
|
+
fee: Number(fee),
|
|
116
|
+
tickSpacing,
|
|
117
|
+
tick: Number(tick),
|
|
118
|
+
sqrtPriceX96: sqrtPriceX96.toString(),
|
|
119
|
+
liquidity: liquidity.toString(),
|
|
120
|
+
hooks,
|
|
121
|
+
poolManager,
|
|
122
|
+
parameters,
|
|
123
|
+
currency0,
|
|
124
|
+
currency1,
|
|
125
|
+
lpFee: Number(lpFee),
|
|
126
|
+
protocolFee: Number(protocolFee),
|
|
127
|
+
};
|
|
128
|
+
(0, dist_1.log_info)(`[PoolStateInitializer] Infinity pool initialized: ${poolKey}`, {
|
|
129
|
+
currency0: state.currency0, currency1: state.currency1,
|
|
130
|
+
fee: state.fee, tickSpacing: state.tickSpacing, tick: state.tick,
|
|
131
|
+
lpFee: state.lpFee, protocolFee: state.protocolFee,
|
|
132
|
+
});
|
|
133
|
+
return state;
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
(0, dist_1.log_error)(`[PoolStateInitializer] Failed to init Infinity pool ${poolKey}:`, error);
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.PoolStateInitializer = PoolStateInitializer;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { StandardPoolInfoType } from "@clonegod/ttd-core";
|
|
2
|
+
export declare function buildSdkTokenMap<T>(chainId: number, poolInfoMap: Map<string, StandardPoolInfoType>, TokenClass: new (chainId: number, address: string, decimals: number, symbol?: string, name?: string) => T): Map<string, T>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildSdkTokenMap = buildSdkTokenMap;
|
|
4
|
+
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
5
|
+
function buildSdkTokenMap(chainId, poolInfoMap, TokenClass) {
|
|
6
|
+
const sdkTokens = new Map();
|
|
7
|
+
for (const poolInfo of poolInfoMap.values()) {
|
|
8
|
+
const tokens = [poolInfo.tokenA, poolInfo.tokenB];
|
|
9
|
+
for (const tokenInfo of tokens) {
|
|
10
|
+
const address = tokenInfo.address;
|
|
11
|
+
if (sdkTokens.has(address))
|
|
12
|
+
continue;
|
|
13
|
+
let symbol = tokenInfo.symbol || address.substring(0, 6);
|
|
14
|
+
let name = tokenInfo.name || `Token ${address.substring(0, 8)}`;
|
|
15
|
+
const token = new TokenClass(chainId, address, tokenInfo.decimals, symbol, name);
|
|
16
|
+
sdkTokens.set(address, token);
|
|
17
|
+
(0, dist_1.log_debug)(`Created SDK Token: ${address}, symbol: ${symbol}, decimals: ${tokenInfo.decimals}`, '');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return sdkTokens;
|
|
21
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface TickInfo {
|
|
2
|
+
liquidityNet: bigint;
|
|
3
|
+
liquidityGross: bigint;
|
|
4
|
+
}
|
|
5
|
+
export interface ClmmTickCacheConfig {
|
|
6
|
+
neighboringWords?: number;
|
|
7
|
+
refreshInterval?: number;
|
|
8
|
+
minUpdateInterval?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface TickLensLoader {
|
|
11
|
+
loadBitmapWords(poolAddress: string, bitmapIndexes: number[]): Promise<Map<number, TickInfo>>;
|
|
12
|
+
}
|
|
13
|
+
export declare class ClmmTickCache {
|
|
14
|
+
private pools;
|
|
15
|
+
private refreshTimers;
|
|
16
|
+
private loadPromises;
|
|
17
|
+
private loader;
|
|
18
|
+
private config;
|
|
19
|
+
constructor(loader: TickLensLoader, config?: ClmmTickCacheConfig);
|
|
20
|
+
initPool(poolAddress: string, currentTick: number, tickSpacing: number): Promise<void>;
|
|
21
|
+
onSwap(poolAddress: string, newTick: number): void;
|
|
22
|
+
onMint(poolAddress: string, tickLower: number, tickUpper: number, amount: bigint): void;
|
|
23
|
+
onBurn(poolAddress: string, tickLower: number, tickUpper: number, amount: bigint): void;
|
|
24
|
+
onModifyLiquidity(poolAddress: string, tickLower: number, tickUpper: number, liquidityDelta: bigint): void;
|
|
25
|
+
private applyLiquidityDelta;
|
|
26
|
+
private updateTickLiquidity;
|
|
27
|
+
getTickLiquidityNet(poolAddress: string, tickIndex: number): bigint | undefined;
|
|
28
|
+
getTickInfo(poolAddress: string, tickIndex: number): TickInfo | undefined;
|
|
29
|
+
getCachedTickIndices(poolAddress: string): number[];
|
|
30
|
+
getTickSpacing(poolAddress: string): number | undefined;
|
|
31
|
+
hasPool(poolAddress: string): boolean;
|
|
32
|
+
private scheduleFullRefresh;
|
|
33
|
+
private startPeriodicRefresh;
|
|
34
|
+
private doFullRefresh;
|
|
35
|
+
private getBitmapIndex;
|
|
36
|
+
private calcBitmapIndexes;
|
|
37
|
+
private isInCachedRange;
|
|
38
|
+
clearPool(poolAddress: string): void;
|
|
39
|
+
destroy(): void;
|
|
40
|
+
}
|