@clonegod/ttd-bsc-common 3.1.65 → 3.1.66
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/bsc_env_args.d.ts +1 -0
- package/dist/appconfig/bsc_env_args.js +1 -0
- package/package.json +1 -1
- 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/index.js +0 -18
- package/dist/ws/subscribe_v2_events.d.ts +0 -14
- package/dist/ws/subscribe_v2_events.js +0 -160
- package/dist/ws/subscribe_v3_events.d.ts +0 -16
- package/dist/ws/subscribe_v3_events.js +0 -163
|
@@ -36,6 +36,7 @@ const constants_1 = require("../common/constants");
|
|
|
36
36
|
redis_url: { env: 'REDIS_URL', type: 'string', default: 'redis://127.0.0.1:6379', desc: 'Redis 连接 URL' },
|
|
37
37
|
skip_pool_list: { env: 'SKIP_POOL_LIST', type: 'string', default: '', desc: '跳过的池子名称列表(逗号分隔)' },
|
|
38
38
|
price_feed_skip_dup: { env: 'PRICE_FEED_SKIP_DUP', type: 'boolean', default: false, desc: 'PriceFeed 去重过滤' },
|
|
39
|
+
price_feed_client_id: { env: 'PRICE_FEED_CLIENT_ID', type: 'string', default: 'BSC_DC', desc: 'PriceFeed 订阅消息里的 client 标识(如 yyNode 区分客户端)' },
|
|
39
40
|
trade_analyze_port: { env: 'TRADE_ANALYZE_PORT', type: 'number', default: 8004, desc: '上报 analyze 的 HTTP 端口' },
|
|
40
41
|
log_max_size_mb: { env: 'LOG_MAX_SIZE_MB', type: 'number', default: 20, desc: '日志文件大小上限(MB)' },
|
|
41
42
|
log_check_interval_min: { env: 'LOG_CHECK_INTERVAL_MIN', type: 'number', default: 10, desc: '日志检查间隔(分钟)' },
|
package/package.json
CHANGED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export declare class EventFilter {
|
|
2
|
-
private static poolEventMap;
|
|
3
|
-
private static readonly CLEANUP_INTERVAL_MS;
|
|
4
|
-
private static readonly EVENT_EXPIRE_MS;
|
|
5
|
-
private static cleanupInitialized;
|
|
6
|
-
private static initializeCleanup;
|
|
7
|
-
static filterEvent<T>(poolAddress: string, blockNumber: number, eventType: string, callback: (data: T) => void, eventData: T): boolean;
|
|
8
|
-
}
|
package/dist/ws/event_filter.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EventFilter = void 0;
|
|
4
|
-
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
5
|
-
class EventFilter {
|
|
6
|
-
static initializeCleanup() {
|
|
7
|
-
if (this.cleanupInitialized) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
setInterval(() => {
|
|
11
|
-
const now = Date.now();
|
|
12
|
-
this.poolEventMap.forEach((timestamp, key) => {
|
|
13
|
-
if (now - timestamp > this.EVENT_EXPIRE_MS) {
|
|
14
|
-
this.poolEventMap.delete(key);
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
}, this.CLEANUP_INTERVAL_MS);
|
|
18
|
-
this.cleanupInitialized = true;
|
|
19
|
-
}
|
|
20
|
-
static filterEvent(poolAddress, blockNumber, eventType, callback, eventData) {
|
|
21
|
-
this.initializeCleanup();
|
|
22
|
-
const key = `${poolAddress}-${blockNumber}-${eventType.toUpperCase()}`;
|
|
23
|
-
if (this.poolEventMap.has(key)) {
|
|
24
|
-
(0, ttd_core_1.log_warn)(`Event ${eventType} already occurred on pool: ${poolAddress}, block: ${blockNumber}`);
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
this.poolEventMap.set(key, Date.now());
|
|
28
|
-
callback(eventData);
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.EventFilter = EventFilter;
|
|
33
|
-
EventFilter.poolEventMap = new Map();
|
|
34
|
-
EventFilter.CLEANUP_INTERVAL_MS = 10 * 1000;
|
|
35
|
-
EventFilter.EVENT_EXPIRE_MS = 10 * 60 * 1000;
|
|
36
|
-
EventFilter.cleanupInitialized = false;
|
package/dist/ws/index.d.ts
DELETED
package/dist/ws/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./subscribe_v2_events"), exports);
|
|
18
|
-
__exportStar(require("./subscribe_v3_events"), exports);
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare class PancakeV2AmmPoolEventsSubscriber {
|
|
2
|
-
private wsUrl;
|
|
3
|
-
private poolAddress;
|
|
4
|
-
private provider;
|
|
5
|
-
private poolContract;
|
|
6
|
-
private eventCallbacks;
|
|
7
|
-
private isConnected;
|
|
8
|
-
constructor(wsUrl: string, poolAddress: string);
|
|
9
|
-
initialize(): Promise<void>;
|
|
10
|
-
subscribe(eventType: string, callback: any): void;
|
|
11
|
-
unsubscribe(eventType: string): Promise<void>;
|
|
12
|
-
disconnect(): Promise<void>;
|
|
13
|
-
_reconnect(): void;
|
|
14
|
-
}
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PancakeV2AmmPoolEventsSubscriber = void 0;
|
|
4
|
-
const ethers_1 = require("ethers");
|
|
5
|
-
const ethers_compat_1 = require("../utils/ethers_compat");
|
|
6
|
-
const event_filter_1 = require("./event_filter");
|
|
7
|
-
const PANCAKE_V2_POOL_ABI = [
|
|
8
|
-
'event Sync(uint112 reserve0, uint112 reserve1)',
|
|
9
|
-
'event Mint(address indexed sender, uint amount0, uint amount1)',
|
|
10
|
-
'event Burn(address indexed sender, uint amount0, uint amount1, address indexed to)'
|
|
11
|
-
];
|
|
12
|
-
class PancakeV2AmmPoolEventsSubscriber {
|
|
13
|
-
constructor(wsUrl, poolAddress) {
|
|
14
|
-
this.wsUrl = wsUrl;
|
|
15
|
-
this.poolAddress = poolAddress;
|
|
16
|
-
this.provider = null;
|
|
17
|
-
this.poolContract = null;
|
|
18
|
-
this.eventCallbacks = {
|
|
19
|
-
sync: null,
|
|
20
|
-
mint: null,
|
|
21
|
-
burn: null
|
|
22
|
-
};
|
|
23
|
-
this.isConnected = false;
|
|
24
|
-
}
|
|
25
|
-
async initialize() {
|
|
26
|
-
try {
|
|
27
|
-
if (!this.wsUrl || !this.poolAddress) {
|
|
28
|
-
throw new Error(`wsUrl and poolAddress are required! wsUrl=${this.wsUrl} poolAddress=${this.poolAddress}`);
|
|
29
|
-
}
|
|
30
|
-
this.provider = new ethers_compat_1.ethersCompat.WebSocketProvider(this.wsUrl);
|
|
31
|
-
this.poolContract = new ethers_1.ethers.Contract(this.poolAddress, PANCAKE_V2_POOL_ABI, this.provider);
|
|
32
|
-
this.isConnected = true;
|
|
33
|
-
console.log(`Connected to WebSocket: ${this.wsUrl} for pool: ${this.poolAddress}`);
|
|
34
|
-
this.provider._websocket.on('error', (error) => {
|
|
35
|
-
console.error('WebSocket Error:', error);
|
|
36
|
-
this.isConnected = false;
|
|
37
|
-
this._reconnect();
|
|
38
|
-
});
|
|
39
|
-
this.provider._websocket.on('close', (code, reason) => {
|
|
40
|
-
console.error('WebSocket Closed:', code, reason);
|
|
41
|
-
this.isConnected = false;
|
|
42
|
-
this._reconnect();
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
console.error('Initialization Error:', error);
|
|
47
|
-
this.isConnected = false;
|
|
48
|
-
this._reconnect();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
subscribe(eventType, callback) {
|
|
52
|
-
if (!this.poolContract) {
|
|
53
|
-
throw new Error('Contract not initialized. Call initialize() first.');
|
|
54
|
-
}
|
|
55
|
-
if (!['sync', 'mint', 'burn'].includes(eventType.toLowerCase())) {
|
|
56
|
-
throw new Error('Invalid event type. Use "sync", "mint", or "burn".');
|
|
57
|
-
}
|
|
58
|
-
this.eventCallbacks[eventType.toLowerCase()] = callback;
|
|
59
|
-
if (eventType.toLowerCase() === 'sync') {
|
|
60
|
-
this.poolContract.on('Sync', (reserve0, reserve1, event) => {
|
|
61
|
-
const data = {
|
|
62
|
-
pool_address: this.poolAddress,
|
|
63
|
-
type: 'sync',
|
|
64
|
-
event_time: Date.now(),
|
|
65
|
-
data: {
|
|
66
|
-
blockNumber: event.blockNumber,
|
|
67
|
-
transactionIndex: event.transactionIndex,
|
|
68
|
-
transactionHash: event.transactionHash,
|
|
69
|
-
amount0: '0',
|
|
70
|
-
amount1: '0',
|
|
71
|
-
reserve0: BigInt(reserve0.toString()),
|
|
72
|
-
reserve1: BigInt(reserve1.toString()),
|
|
73
|
-
tick: 0,
|
|
74
|
-
sqrtPriceX96: BigInt(0),
|
|
75
|
-
liquidity: BigInt(0),
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
callback(data);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
else if (eventType.toLowerCase() === 'mint') {
|
|
82
|
-
this.poolContract.on('Mint', (sender, amount0, amount1, event) => {
|
|
83
|
-
const data = {
|
|
84
|
-
pool_address: this.poolAddress,
|
|
85
|
-
type: 'mint',
|
|
86
|
-
event_time: Date.now(),
|
|
87
|
-
data: {
|
|
88
|
-
blockNumber: event.blockNumber,
|
|
89
|
-
transactionIndex: event.transactionIndex,
|
|
90
|
-
transactionHash: event.transactionHash,
|
|
91
|
-
amount0: amount0.toString(),
|
|
92
|
-
amount1: amount1.toString(),
|
|
93
|
-
reserve0: BigInt(0),
|
|
94
|
-
reserve1: BigInt(0),
|
|
95
|
-
tick: 0,
|
|
96
|
-
sqrtPriceX96: BigInt(0),
|
|
97
|
-
liquidity: BigInt(0),
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
event_filter_1.EventFilter.filterEvent(this.poolAddress, event.blockNumber, 'mint', callback, data);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
else if (eventType.toLowerCase() === 'burn') {
|
|
104
|
-
this.poolContract.on('Burn', (sender, amount0, amount1, to, event) => {
|
|
105
|
-
const data = {
|
|
106
|
-
pool_address: this.poolAddress,
|
|
107
|
-
type: 'burn',
|
|
108
|
-
event_time: Date.now(),
|
|
109
|
-
data: {
|
|
110
|
-
blockNumber: event.blockNumber,
|
|
111
|
-
transactionIndex: event.transactionIndex,
|
|
112
|
-
transactionHash: event.transactionHash,
|
|
113
|
-
amount0: amount0.toString(),
|
|
114
|
-
amount1: amount1.toString(),
|
|
115
|
-
reserve0: BigInt(0),
|
|
116
|
-
reserve1: BigInt(0),
|
|
117
|
-
tick: 0,
|
|
118
|
-
sqrtPriceX96: BigInt(0),
|
|
119
|
-
liquidity: BigInt(0),
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
event_filter_1.EventFilter.filterEvent(this.poolAddress, event.blockNumber, 'burn', callback, data);
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
async unsubscribe(eventType) {
|
|
127
|
-
if (!this.poolContract) {
|
|
128
|
-
throw new Error('Contract not initialized.');
|
|
129
|
-
}
|
|
130
|
-
if (!['sync', 'mint', 'burn'].includes(eventType.toLowerCase())) {
|
|
131
|
-
throw new Error('Invalid event type. Use "sync", "mint", or "burn".');
|
|
132
|
-
}
|
|
133
|
-
this.poolContract.removeAllListeners(eventType);
|
|
134
|
-
this.eventCallbacks[eventType.toLowerCase()] = null;
|
|
135
|
-
console.log(`Unsubscribed from ${eventType} events`);
|
|
136
|
-
}
|
|
137
|
-
async disconnect() {
|
|
138
|
-
if (this.provider) {
|
|
139
|
-
await this.provider.destroy();
|
|
140
|
-
this.provider = null;
|
|
141
|
-
this.poolContract = null;
|
|
142
|
-
this.isConnected = false;
|
|
143
|
-
console.log('Disconnected from WebSocket');
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
_reconnect() {
|
|
147
|
-
if (!this.isConnected) {
|
|
148
|
-
console.log('Attempting to reconnect...');
|
|
149
|
-
setTimeout(async () => {
|
|
150
|
-
await this.initialize();
|
|
151
|
-
for (const [eventType, callback] of Object.entries(this.eventCallbacks)) {
|
|
152
|
-
if (callback) {
|
|
153
|
-
this.subscribe(eventType, callback);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}, 2000);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
exports.PancakeV2AmmPoolEventsSubscriber = PancakeV2AmmPoolEventsSubscriber;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export declare class PancakeV3PoolEventsSubscriber {
|
|
2
|
-
private wsUrl;
|
|
3
|
-
private poolAddress;
|
|
4
|
-
private provider;
|
|
5
|
-
private poolContract;
|
|
6
|
-
private eventCallbacks;
|
|
7
|
-
private isConnected;
|
|
8
|
-
constructor(wsUrl: string, poolAddress: string);
|
|
9
|
-
initialize(): Promise<void>;
|
|
10
|
-
subscribe(eventType: string, callback: any): void;
|
|
11
|
-
unsubscribe(eventType: string): Promise<void>;
|
|
12
|
-
disconnect(): Promise<void>;
|
|
13
|
-
_reconnect(): void;
|
|
14
|
-
}
|
|
15
|
-
export declare class UniswapV3PoolEventsSubscriber extends PancakeV3PoolEventsSubscriber {
|
|
16
|
-
}
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UniswapV3PoolEventsSubscriber = exports.PancakeV3PoolEventsSubscriber = void 0;
|
|
4
|
-
const ethers_1 = require("ethers");
|
|
5
|
-
const ethers_compat_1 = require("../utils/ethers_compat");
|
|
6
|
-
const event_filter_1 = require("./event_filter");
|
|
7
|
-
const PANCAKE_V3_POOL_ABI = [
|
|
8
|
-
'event Swap(address indexed sender, address indexed recipient, int256 amount0, int256 amount1, uint160 sqrtPriceX96, uint128 liquidity, int24 tick, uint128 protocolFeesToken0, uint128 protocolFeesToken1)',
|
|
9
|
-
'event Mint(address sender, address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1)',
|
|
10
|
-
'event Burn(address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1)'
|
|
11
|
-
];
|
|
12
|
-
class PancakeV3PoolEventsSubscriber {
|
|
13
|
-
constructor(wsUrl, poolAddress) {
|
|
14
|
-
this.wsUrl = wsUrl;
|
|
15
|
-
this.poolAddress = poolAddress;
|
|
16
|
-
this.provider = null;
|
|
17
|
-
this.poolContract = null;
|
|
18
|
-
this.eventCallbacks = {
|
|
19
|
-
swap: null,
|
|
20
|
-
mint: null,
|
|
21
|
-
burn: null
|
|
22
|
-
};
|
|
23
|
-
this.isConnected = false;
|
|
24
|
-
}
|
|
25
|
-
async initialize() {
|
|
26
|
-
try {
|
|
27
|
-
if (!this.wsUrl || !this.poolAddress) {
|
|
28
|
-
throw new Error(`wsUrl and poolAddress are required! wsUrl=${this.wsUrl} poolAddress=${this.poolAddress}`);
|
|
29
|
-
}
|
|
30
|
-
this.provider = new ethers_compat_1.ethersCompat.WebSocketProvider(this.wsUrl);
|
|
31
|
-
this.poolContract = new ethers_1.ethers.Contract(this.poolAddress, PANCAKE_V3_POOL_ABI, this.provider);
|
|
32
|
-
this.isConnected = true;
|
|
33
|
-
console.log(`Connected to WebSocket: ${this.wsUrl} for pool: ${this.poolAddress}`);
|
|
34
|
-
this.provider._websocket.on('error', (error) => {
|
|
35
|
-
console.error('WebSocket Error:', error);
|
|
36
|
-
this.isConnected = false;
|
|
37
|
-
this._reconnect();
|
|
38
|
-
});
|
|
39
|
-
this.provider._websocket.on('close', (code, reason) => {
|
|
40
|
-
console.error('WebSocket Closed:', code, reason);
|
|
41
|
-
this.isConnected = false;
|
|
42
|
-
this._reconnect();
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
console.error('Initialization Error:', error);
|
|
47
|
-
this.isConnected = false;
|
|
48
|
-
this._reconnect();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
subscribe(eventType, callback) {
|
|
52
|
-
if (!this.poolContract) {
|
|
53
|
-
throw new Error('Contract not initialized. Call initialize() first.');
|
|
54
|
-
}
|
|
55
|
-
if (!['swap', 'mint', 'burn'].includes(eventType.toLowerCase())) {
|
|
56
|
-
throw new Error('Invalid event type. Use "swap", "mint", or "burn".');
|
|
57
|
-
}
|
|
58
|
-
this.eventCallbacks[eventType.toLowerCase()] = callback;
|
|
59
|
-
if (eventType.toLowerCase() === 'swap') {
|
|
60
|
-
this.poolContract.on('Swap', (sender, recipient, amount0, amount1, sqrtPriceX96, liquidity, tick, protocolFeesToken0, protocolFeesToken1, event) => {
|
|
61
|
-
const data = {
|
|
62
|
-
pool_address: this.poolAddress,
|
|
63
|
-
type: 'swap',
|
|
64
|
-
event_time: Date.now(),
|
|
65
|
-
data: {
|
|
66
|
-
blockNumber: event.blockNumber,
|
|
67
|
-
transactionIndex: event.transactionIndex,
|
|
68
|
-
transactionHash: event.transactionHash,
|
|
69
|
-
amount0: amount0.toString(),
|
|
70
|
-
amount1: amount1.toString(),
|
|
71
|
-
reserve0: BigInt(0),
|
|
72
|
-
reserve1: BigInt(0),
|
|
73
|
-
tick,
|
|
74
|
-
sqrtPriceX96: sqrtPriceX96.toString(),
|
|
75
|
-
liquidity: liquidity.toString(),
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
callback(data);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
else if (eventType.toLowerCase() === 'mint') {
|
|
82
|
-
this.poolContract.on('Mint', (sender, owner, tickLower, tickUpper, amount, amount0, amount1, event) => {
|
|
83
|
-
const data = {
|
|
84
|
-
pool_address: this.poolAddress,
|
|
85
|
-
type: 'mint',
|
|
86
|
-
event_time: Date.now(),
|
|
87
|
-
data: {
|
|
88
|
-
blockNumber: event.blockNumber,
|
|
89
|
-
transactionIndex: event.transactionIndex,
|
|
90
|
-
transactionHash: event.transactionHash,
|
|
91
|
-
amount0: amount0.toString(),
|
|
92
|
-
amount1: amount1.toString(),
|
|
93
|
-
reserve0: BigInt(0),
|
|
94
|
-
reserve1: BigInt(0),
|
|
95
|
-
tick: 0,
|
|
96
|
-
sqrtPriceX96: BigInt(0),
|
|
97
|
-
liquidity: BigInt(0),
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
event_filter_1.EventFilter.filterEvent(this.poolAddress, event.blockNumber, 'mint', callback, data);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
else if (eventType.toLowerCase() === 'burn') {
|
|
104
|
-
this.poolContract.on('Burn', (owner, tickLower, tickUpper, amount, amount0, amount1, event) => {
|
|
105
|
-
const data = {
|
|
106
|
-
pool_address: this.poolAddress,
|
|
107
|
-
type: 'burn',
|
|
108
|
-
event_time: Date.now(),
|
|
109
|
-
data: {
|
|
110
|
-
blockNumber: event.blockNumber,
|
|
111
|
-
transactionIndex: event.transactionIndex,
|
|
112
|
-
transactionHash: event.transactionHash,
|
|
113
|
-
amount0: amount0.toString(),
|
|
114
|
-
amount1: amount1.toString(),
|
|
115
|
-
reserve0: BigInt(0),
|
|
116
|
-
reserve1: BigInt(0),
|
|
117
|
-
tick: 0,
|
|
118
|
-
sqrtPriceX96: BigInt(0),
|
|
119
|
-
liquidity: BigInt(0),
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
event_filter_1.EventFilter.filterEvent(this.poolAddress, event.blockNumber, 'burn', callback, data);
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
async unsubscribe(eventType) {
|
|
127
|
-
if (!this.poolContract) {
|
|
128
|
-
throw new Error('Contract not initialized.');
|
|
129
|
-
}
|
|
130
|
-
if (!['swap', 'mint', 'burn'].includes(eventType.toLowerCase())) {
|
|
131
|
-
throw new Error('Invalid event type. Use "swap", "mint", or "burn".');
|
|
132
|
-
}
|
|
133
|
-
this.poolContract.removeAllListeners(eventType);
|
|
134
|
-
this.eventCallbacks[eventType.toLowerCase()] = null;
|
|
135
|
-
console.log(`Unsubscribed from ${eventType} events`);
|
|
136
|
-
}
|
|
137
|
-
async disconnect() {
|
|
138
|
-
if (this.provider) {
|
|
139
|
-
await this.provider.destroy();
|
|
140
|
-
this.provider = null;
|
|
141
|
-
this.poolContract = null;
|
|
142
|
-
this.isConnected = false;
|
|
143
|
-
console.log('Disconnected from WebSocket');
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
_reconnect() {
|
|
147
|
-
if (!this.isConnected) {
|
|
148
|
-
console.log('Attempting to reconnect...');
|
|
149
|
-
setTimeout(async () => {
|
|
150
|
-
await this.initialize();
|
|
151
|
-
for (const [eventType, callback] of Object.entries(this.eventCallbacks)) {
|
|
152
|
-
if (callback) {
|
|
153
|
-
this.subscribe(eventType, callback);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}, 2000);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
exports.PancakeV3PoolEventsSubscriber = PancakeV3PoolEventsSubscriber;
|
|
161
|
-
class UniswapV3PoolEventsSubscriber extends PancakeV3PoolEventsSubscriber {
|
|
162
|
-
}
|
|
163
|
-
exports.UniswapV3PoolEventsSubscriber = UniswapV3PoolEventsSubscriber;
|