@clonegod/ttd-bsc-common 3.1.83 → 3.1.88

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.
Files changed (39) hide show
  1. package/dist/appconfig/bsc_env_args.d.ts +1 -0
  2. package/dist/appconfig/bsc_env_args.js +1 -0
  3. package/dist/config/bsc_env_args.d.ts +11 -0
  4. package/dist/config/bsc_env_args.js +19 -0
  5. package/dist/config/index.d.ts +1 -0
  6. package/dist/config/index.js +17 -0
  7. package/dist/quote/event/verify_clmm_swap_event.d.ts +1 -0
  8. package/dist/quote/event/verify_clmm_swap_event.js +178 -0
  9. package/dist/quote/pricing/token_price_cache.d.ts +9 -0
  10. package/dist/quote/pricing/token_price_cache.js +40 -0
  11. package/dist/redis/index.d.ts +1 -0
  12. package/dist/redis/index.js +17 -0
  13. package/dist/redis/redis_client.d.ts +21 -0
  14. package/dist/redis/redis_client.js +155 -0
  15. package/dist/trade/abstract_dex_trade_plus.d.ts +30 -0
  16. package/dist/trade/abstract_dex_trade_plus.js +227 -0
  17. package/dist/trade/check/tx_websocket_manager.d.ts +23 -0
  18. package/dist/trade/check/tx_websocket_manager.js +119 -0
  19. package/dist/trade/send/48club.d.ts +18 -0
  20. package/dist/trade/send/48club.js +97 -0
  21. package/dist/trade/send/blockrazor.d.ts +7 -0
  22. package/dist/trade/send/blockrazor.js +79 -0
  23. package/dist/trade/send/bsc_rpc.d.ts +6 -0
  24. package/dist/trade/send/bsc_rpc.js +43 -0
  25. package/dist/trade/send/index.d.ts +5 -0
  26. package/dist/trade/send/index.js +23 -0
  27. package/dist/trade/send/send_tx.d.ts +8 -0
  28. package/dist/trade/send/send_tx.js +91 -0
  29. package/dist/ws/event_filter.d.ts +8 -0
  30. package/dist/ws/event_filter.js +36 -0
  31. package/dist/ws/index.d.ts +2 -0
  32. package/dist/ws/index.js +18 -0
  33. package/dist/ws/subscribe_v2_events.d.ts +14 -0
  34. package/dist/ws/subscribe_v2_events.js +174 -0
  35. package/dist/ws/subscribe_v3_events.d.ts +16 -0
  36. package/dist/ws/subscribe_v3_events.js +177 -0
  37. package/package.json +2 -2
  38. package/dist/quote/hook_fee_monitor.d.ts +0 -10
  39. package/dist/quote/hook_fee_monitor.js +0 -32
@@ -0,0 +1,91 @@
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.TransactionSender = void 0;
13
+ const dist_1 = require("@clonegod/ttd-core/dist");
14
+ const blockrazor_1 = require("./blockrazor");
15
+ const bsc_rpc_1 = require("./bsc_rpc");
16
+ const _48club_1 = require("./48club");
17
+ const _1 = require(".");
18
+ class TransactionSender {
19
+ constructor(appConfig) {
20
+ this.rpc = new bsc_rpc_1.BscRpc(appConfig.env_args.rpc_endpoint);
21
+ this.blockRazor = new blockrazor_1.BlockRazorTrade();
22
+ this._48Club = new _48club_1._48ClubTrade();
23
+ }
24
+ sendTransaction(signedMainTx, eoa_tip_transaction, order_trace_id) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const rpcProviders = [
27
+ {
28
+ name: 'Default (QuickNode / Merkle)',
29
+ enable: process.env.SEND_TX_DEFAULT_RPC_PRIVATE === 'true',
30
+ send: () => __awaiter(this, void 0, void 0, function* () {
31
+ return yield this.rpc.eth_sendRawTransaction(signedMainTx);
32
+ })
33
+ },
34
+ {
35
+ name: 'BlockRazor - Private Transaction',
36
+ enable: process.env.SEND_TX_BLOCKRAZOR_PRIVATE === 'true',
37
+ send: () => __awaiter(this, void 0, void 0, function* () {
38
+ return yield this.blockRazor.sendPrivateTransaction(signedMainTx);
39
+ })
40
+ },
41
+ {
42
+ name: 'BlockRazor - sendBundle',
43
+ enable: process.env.SEND_TX_BLOCKRAZOR_BUNDLE === 'true',
44
+ send: () => __awaiter(this, void 0, void 0, function* () {
45
+ let bundle = [signedMainTx, yield eoa_tip_transaction(_1.BSC_EOA_ADDRESS.BLOCKRAZOR)];
46
+ return yield this.blockRazor.sendBundle(bundle);
47
+ })
48
+ },
49
+ {
50
+ name: '48Club - Private Transaction',
51
+ enable: process.env.SEND_TX_48CLUB_PRIVATE === 'true',
52
+ send: () => __awaiter(this, void 0, void 0, function* () {
53
+ return yield this._48Club.sendPrivateTransaction(signedMainTx);
54
+ })
55
+ },
56
+ {
57
+ name: '48Club - sendBundle',
58
+ enable: process.env.SEND_TX_48CLUB_BUNDLE === 'true',
59
+ send: () => __awaiter(this, void 0, void 0, function* () {
60
+ let bundle = [signedMainTx, yield eoa_tip_transaction(_1.BSC_EOA_ADDRESS._48CLUB)];
61
+ return yield this._48Club.sendBundle({ txs: bundle });
62
+ })
63
+ }
64
+ ];
65
+ const results = [];
66
+ const errors = [];
67
+ yield Promise.all(rpcProviders.filter(provider => provider.enable).map((provider) => __awaiter(this, void 0, void 0, function* () {
68
+ try {
69
+ const txHash = yield provider.send();
70
+ results.push(txHash);
71
+ (0, dist_1.log_info)(`Transaction sent successfully`, { provider: provider.name, order_trace_id, txHash });
72
+ }
73
+ catch (error) {
74
+ errors.push(`${provider.name}: ${error.message}`);
75
+ (0, dist_1.log_info)(`Transaction sending failed`, { provider: provider.name, order_trace_id, error: error.message });
76
+ }
77
+ })));
78
+ if (errors.some(error => error.includes('nonce'))) {
79
+ throw new Error(`!!!!!! Some RPC providers returned nonce error: ${JSON.stringify(errors)}`);
80
+ }
81
+ if (errors.some(error => error.includes('bundle already exist') || error.includes('already known'))) {
82
+ return results;
83
+ }
84
+ if (results.length === 0 || errors.length > 0) {
85
+ throw new Error(`!!!!!! Some RPC providers failed to send transactions: ${JSON.stringify(errors)}`);
86
+ }
87
+ return results;
88
+ });
89
+ }
90
+ }
91
+ exports.TransactionSender = TransactionSender;
@@ -0,0 +1,8 @@
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
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventFilter = void 0;
4
+ const dist_1 = require("@clonegod/ttd-core/dist");
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, dist_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;
@@ -0,0 +1,2 @@
1
+ export * from './subscribe_v2_events';
2
+ export * from './subscribe_v3_events';
@@ -0,0 +1,18 @@
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);
@@ -0,0 +1,14 @@
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
+ }
@@ -0,0 +1,174 @@
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.PancakeV2AmmPoolEventsSubscriber = void 0;
13
+ const ethers_1 = require("ethers");
14
+ const event_filter_1 = require("./event_filter");
15
+ const PANCAKE_V2_POOL_ABI = [
16
+ 'event Sync(uint112 reserve0, uint112 reserve1)',
17
+ 'event Mint(address indexed sender, uint amount0, uint amount1)',
18
+ 'event Burn(address indexed sender, uint amount0, uint amount1, address indexed to)'
19
+ ];
20
+ class PancakeV2AmmPoolEventsSubscriber {
21
+ constructor(wsUrl, poolAddress) {
22
+ this.wsUrl = wsUrl;
23
+ this.poolAddress = poolAddress;
24
+ this.provider = null;
25
+ this.poolContract = null;
26
+ this.eventCallbacks = {
27
+ sync: null,
28
+ mint: null,
29
+ burn: null
30
+ };
31
+ this.isConnected = false;
32
+ }
33
+ initialize() {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ try {
36
+ if (!this.wsUrl || !this.poolAddress) {
37
+ throw new Error(`wsUrl and poolAddress are required! wsUrl=${this.wsUrl} poolAddress=${this.poolAddress}`);
38
+ }
39
+ this.provider = new ethers_1.ethers.providers.WebSocketProvider(this.wsUrl);
40
+ this.poolContract = new ethers_1.ethers.Contract(this.poolAddress, PANCAKE_V2_POOL_ABI, this.provider);
41
+ this.isConnected = true;
42
+ console.log(`Connected to WebSocket: ${this.wsUrl} for pool: ${this.poolAddress}`);
43
+ this.provider._websocket.on('error', (error) => {
44
+ console.error('WebSocket Error:', error);
45
+ this.isConnected = false;
46
+ this._reconnect();
47
+ });
48
+ this.provider._websocket.on('close', (code, reason) => {
49
+ console.error('WebSocket Closed:', code, reason);
50
+ this.isConnected = false;
51
+ this._reconnect();
52
+ });
53
+ }
54
+ catch (error) {
55
+ console.error('Initialization Error:', error);
56
+ this.isConnected = false;
57
+ this._reconnect();
58
+ }
59
+ });
60
+ }
61
+ subscribe(eventType, callback) {
62
+ if (!this.poolContract) {
63
+ throw new Error('Contract not initialized. Call initialize() first.');
64
+ }
65
+ if (!['sync', 'mint', 'burn'].includes(eventType.toLowerCase())) {
66
+ throw new Error('Invalid event type. Use "sync", "mint", or "burn".');
67
+ }
68
+ this.eventCallbacks[eventType.toLowerCase()] = callback;
69
+ if (eventType.toLowerCase() === 'sync') {
70
+ this.poolContract.on('Sync', (reserve0, reserve1, event) => {
71
+ const data = {
72
+ pool_address: this.poolAddress,
73
+ type: 'sync',
74
+ event_time: Date.now(),
75
+ data: {
76
+ blockNumber: event.blockNumber,
77
+ transactionIndex: event.transactionIndex,
78
+ transactionHash: event.transactionHash,
79
+ amount0: '0',
80
+ amount1: '0',
81
+ reserve0: BigInt(reserve0.toString()),
82
+ reserve1: BigInt(reserve1.toString()),
83
+ tick: 0,
84
+ sqrtPriceX96: BigInt(0),
85
+ liquidity: BigInt(0),
86
+ }
87
+ };
88
+ callback(data);
89
+ });
90
+ }
91
+ else if (eventType.toLowerCase() === 'mint') {
92
+ this.poolContract.on('Mint', (sender, amount0, amount1, event) => {
93
+ const data = {
94
+ pool_address: this.poolAddress,
95
+ type: 'mint',
96
+ event_time: Date.now(),
97
+ data: {
98
+ blockNumber: event.blockNumber,
99
+ transactionIndex: event.transactionIndex,
100
+ transactionHash: event.transactionHash,
101
+ amount0: amount0.toString(),
102
+ amount1: amount1.toString(),
103
+ reserve0: BigInt(0),
104
+ reserve1: BigInt(0),
105
+ tick: 0,
106
+ sqrtPriceX96: BigInt(0),
107
+ liquidity: BigInt(0),
108
+ }
109
+ };
110
+ event_filter_1.EventFilter.filterEvent(this.poolAddress, event.blockNumber, 'mint', callback, data);
111
+ });
112
+ }
113
+ else if (eventType.toLowerCase() === 'burn') {
114
+ this.poolContract.on('Burn', (sender, amount0, amount1, to, event) => {
115
+ const data = {
116
+ pool_address: this.poolAddress,
117
+ type: 'burn',
118
+ event_time: Date.now(),
119
+ data: {
120
+ blockNumber: event.blockNumber,
121
+ transactionIndex: event.transactionIndex,
122
+ transactionHash: event.transactionHash,
123
+ amount0: amount0.toString(),
124
+ amount1: amount1.toString(),
125
+ reserve0: BigInt(0),
126
+ reserve1: BigInt(0),
127
+ tick: 0,
128
+ sqrtPriceX96: BigInt(0),
129
+ liquidity: BigInt(0),
130
+ }
131
+ };
132
+ event_filter_1.EventFilter.filterEvent(this.poolAddress, event.blockNumber, 'burn', callback, data);
133
+ });
134
+ }
135
+ }
136
+ unsubscribe(eventType) {
137
+ return __awaiter(this, void 0, void 0, function* () {
138
+ if (!this.poolContract) {
139
+ throw new Error('Contract not initialized.');
140
+ }
141
+ if (!['sync', 'mint', 'burn'].includes(eventType.toLowerCase())) {
142
+ throw new Error('Invalid event type. Use "sync", "mint", or "burn".');
143
+ }
144
+ this.poolContract.removeAllListeners(eventType);
145
+ this.eventCallbacks[eventType.toLowerCase()] = null;
146
+ console.log(`Unsubscribed from ${eventType} events`);
147
+ });
148
+ }
149
+ disconnect() {
150
+ return __awaiter(this, void 0, void 0, function* () {
151
+ if (this.provider) {
152
+ yield this.provider.destroy();
153
+ this.provider = null;
154
+ this.poolContract = null;
155
+ this.isConnected = false;
156
+ console.log('Disconnected from WebSocket');
157
+ }
158
+ });
159
+ }
160
+ _reconnect() {
161
+ if (!this.isConnected) {
162
+ console.log('Attempting to reconnect...');
163
+ setTimeout(() => __awaiter(this, void 0, void 0, function* () {
164
+ yield this.initialize();
165
+ for (const [eventType, callback] of Object.entries(this.eventCallbacks)) {
166
+ if (callback) {
167
+ this.subscribe(eventType, callback);
168
+ }
169
+ }
170
+ }), 2000);
171
+ }
172
+ }
173
+ }
174
+ exports.PancakeV2AmmPoolEventsSubscriber = PancakeV2AmmPoolEventsSubscriber;
@@ -0,0 +1,16 @@
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
+ }
@@ -0,0 +1,177 @@
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.UniswapV3PoolEventsSubscriber = exports.PancakeV3PoolEventsSubscriber = void 0;
13
+ const ethers_1 = require("ethers");
14
+ const event_filter_1 = require("./event_filter");
15
+ const PANCAKE_V3_POOL_ABI = [
16
+ 'event Swap(address indexed sender, address indexed recipient, int256 amount0, int256 amount1, uint160 sqrtPriceX96, uint128 liquidity, int24 tick, uint128 protocolFeesToken0, uint128 protocolFeesToken1)',
17
+ 'event Mint(address sender, address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1)',
18
+ 'event Burn(address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1)'
19
+ ];
20
+ class PancakeV3PoolEventsSubscriber {
21
+ constructor(wsUrl, poolAddress) {
22
+ this.wsUrl = wsUrl;
23
+ this.poolAddress = poolAddress;
24
+ this.provider = null;
25
+ this.poolContract = null;
26
+ this.eventCallbacks = {
27
+ swap: null,
28
+ mint: null,
29
+ burn: null
30
+ };
31
+ this.isConnected = false;
32
+ }
33
+ initialize() {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ try {
36
+ if (!this.wsUrl || !this.poolAddress) {
37
+ throw new Error(`wsUrl and poolAddress are required! wsUrl=${this.wsUrl} poolAddress=${this.poolAddress}`);
38
+ }
39
+ this.provider = new ethers_1.ethers.providers.WebSocketProvider(this.wsUrl);
40
+ this.poolContract = new ethers_1.ethers.Contract(this.poolAddress, PANCAKE_V3_POOL_ABI, this.provider);
41
+ this.isConnected = true;
42
+ console.log(`Connected to WebSocket: ${this.wsUrl} for pool: ${this.poolAddress}`);
43
+ this.provider._websocket.on('error', (error) => {
44
+ console.error('WebSocket Error:', error);
45
+ this.isConnected = false;
46
+ this._reconnect();
47
+ });
48
+ this.provider._websocket.on('close', (code, reason) => {
49
+ console.error('WebSocket Closed:', code, reason);
50
+ this.isConnected = false;
51
+ this._reconnect();
52
+ });
53
+ }
54
+ catch (error) {
55
+ console.error('Initialization Error:', error);
56
+ this.isConnected = false;
57
+ this._reconnect();
58
+ }
59
+ });
60
+ }
61
+ subscribe(eventType, callback) {
62
+ if (!this.poolContract) {
63
+ throw new Error('Contract not initialized. Call initialize() first.');
64
+ }
65
+ if (!['swap', 'mint', 'burn'].includes(eventType.toLowerCase())) {
66
+ throw new Error('Invalid event type. Use "swap", "mint", or "burn".');
67
+ }
68
+ this.eventCallbacks[eventType.toLowerCase()] = callback;
69
+ if (eventType.toLowerCase() === 'swap') {
70
+ this.poolContract.on('Swap', (sender, recipient, amount0, amount1, sqrtPriceX96, liquidity, tick, protocolFeesToken0, protocolFeesToken1, event) => {
71
+ const data = {
72
+ pool_address: this.poolAddress,
73
+ type: 'swap',
74
+ event_time: Date.now(),
75
+ data: {
76
+ blockNumber: event.blockNumber,
77
+ transactionIndex: event.transactionIndex,
78
+ transactionHash: event.transactionHash,
79
+ amount0: amount0.toString(),
80
+ amount1: amount1.toString(),
81
+ reserve0: BigInt(0),
82
+ reserve1: BigInt(0),
83
+ tick,
84
+ sqrtPriceX96: sqrtPriceX96.toString(),
85
+ liquidity: liquidity.toString(),
86
+ }
87
+ };
88
+ callback(data);
89
+ });
90
+ }
91
+ else if (eventType.toLowerCase() === 'mint') {
92
+ this.poolContract.on('Mint', (sender, owner, tickLower, tickUpper, amount, amount0, amount1, event) => {
93
+ const data = {
94
+ pool_address: this.poolAddress,
95
+ type: 'mint',
96
+ event_time: Date.now(),
97
+ data: {
98
+ blockNumber: event.blockNumber,
99
+ transactionIndex: event.transactionIndex,
100
+ transactionHash: event.transactionHash,
101
+ amount0: amount0.toString(),
102
+ amount1: amount1.toString(),
103
+ reserve0: BigInt(0),
104
+ reserve1: BigInt(0),
105
+ tick: 0,
106
+ sqrtPriceX96: BigInt(0),
107
+ liquidity: BigInt(0),
108
+ }
109
+ };
110
+ event_filter_1.EventFilter.filterEvent(this.poolAddress, event.blockNumber, 'mint', callback, data);
111
+ });
112
+ }
113
+ else if (eventType.toLowerCase() === 'burn') {
114
+ this.poolContract.on('Burn', (owner, tickLower, tickUpper, amount, amount0, amount1, event) => {
115
+ const data = {
116
+ pool_address: this.poolAddress,
117
+ type: 'burn',
118
+ event_time: Date.now(),
119
+ data: {
120
+ blockNumber: event.blockNumber,
121
+ transactionIndex: event.transactionIndex,
122
+ transactionHash: event.transactionHash,
123
+ amount0: amount0.toString(),
124
+ amount1: amount1.toString(),
125
+ reserve0: BigInt(0),
126
+ reserve1: BigInt(0),
127
+ tick: 0,
128
+ sqrtPriceX96: BigInt(0),
129
+ liquidity: BigInt(0),
130
+ }
131
+ };
132
+ event_filter_1.EventFilter.filterEvent(this.poolAddress, event.blockNumber, 'burn', callback, data);
133
+ });
134
+ }
135
+ }
136
+ unsubscribe(eventType) {
137
+ return __awaiter(this, void 0, void 0, function* () {
138
+ if (!this.poolContract) {
139
+ throw new Error('Contract not initialized.');
140
+ }
141
+ if (!['swap', 'mint', 'burn'].includes(eventType.toLowerCase())) {
142
+ throw new Error('Invalid event type. Use "swap", "mint", or "burn".');
143
+ }
144
+ this.poolContract.removeAllListeners(eventType);
145
+ this.eventCallbacks[eventType.toLowerCase()] = null;
146
+ console.log(`Unsubscribed from ${eventType} events`);
147
+ });
148
+ }
149
+ disconnect() {
150
+ return __awaiter(this, void 0, void 0, function* () {
151
+ if (this.provider) {
152
+ yield this.provider.destroy();
153
+ this.provider = null;
154
+ this.poolContract = null;
155
+ this.isConnected = false;
156
+ console.log('Disconnected from WebSocket');
157
+ }
158
+ });
159
+ }
160
+ _reconnect() {
161
+ if (!this.isConnected) {
162
+ console.log('Attempting to reconnect...');
163
+ setTimeout(() => __awaiter(this, void 0, void 0, function* () {
164
+ yield this.initialize();
165
+ for (const [eventType, callback] of Object.entries(this.eventCallbacks)) {
166
+ if (callback) {
167
+ this.subscribe(eventType, callback);
168
+ }
169
+ }
170
+ }), 2000);
171
+ }
172
+ }
173
+ }
174
+ exports.PancakeV3PoolEventsSubscriber = PancakeV3PoolEventsSubscriber;
175
+ class UniswapV3PoolEventsSubscriber extends PancakeV3PoolEventsSubscriber {
176
+ }
177
+ exports.UniswapV3PoolEventsSubscriber = UniswapV3PoolEventsSubscriber;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-bsc-common",
3
- "version": "3.1.83",
3
+ "version": "3.1.88",
4
4
  "description": "BSC common library",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",
@@ -14,7 +14,7 @@
14
14
  "push": "npm run build && npm publish"
15
15
  },
16
16
  "dependencies": {
17
- "@clonegod/ttd-core": "3.1.87",
17
+ "@clonegod/ttd-core": "3.1.92",
18
18
  "axios": "1.17.0",
19
19
  "dotenv": "^16.4.7",
20
20
  "ethers": "^5.8.0",
@@ -1,10 +0,0 @@
1
- export declare function reportHookFeeChangeIfChanged(opts: {
2
- pool_address: string;
3
- dex_id: string;
4
- pool_name?: string;
5
- block_number: number;
6
- prevLpFee: number | undefined;
7
- prevProtocolFee: number | undefined;
8
- newLpFee: number;
9
- newProtocolFee: number;
10
- }): void;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.reportHookFeeChangeIfChanged = reportHookFeeChangeIfChanged;
4
- const ttd_core_1 = require("@clonegod/ttd-core");
5
- function reportHookFeeChangeIfChanged(opts) {
6
- const { pool_address, dex_id, pool_name, block_number, prevLpFee, prevProtocolFee, newLpFee, newProtocolFee } = opts;
7
- if (prevLpFee == null)
8
- return;
9
- const prevTotal = prevLpFee + (prevProtocolFee ?? 0);
10
- const newTotal = newLpFee + newProtocolFee;
11
- if (prevTotal === newTotal)
12
- return;
13
- const addr = pool_address.toLowerCase();
14
- const prevBps = (prevTotal / 100).toFixed(2);
15
- const newBps = (newTotal / 100).toFixed(2);
16
- ttd_core_1.ALERT_TYPES.QUOTE_HOOK_FEE_CHANGE.reportIfChanged(addr, true, () => ({
17
- identity: addr,
18
- scope: { dex_id, pool_address: addr },
19
- title: `${pool_name || addr.slice(0, 10)} hook fee ${prevBps}bps → ${newBps}bps`,
20
- detail: {
21
- pool_name: pool_name || '',
22
- block_number,
23
- prev_lp_fee_ppm: prevLpFee,
24
- prev_protocol_fee_ppm: prevProtocolFee ?? 0,
25
- prev_total_ppm: prevTotal,
26
- new_lp_fee_ppm: newLpFee,
27
- new_protocol_fee_ppm: newProtocolFee,
28
- new_total_ppm: newTotal,
29
- delta_ppm: newTotal - prevTotal,
30
- },
31
- }));
32
- }