@clonegod/ttd-bsc-common 3.1.22 → 3.1.24
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/bsc_dex_env_args.d.ts +5 -0
- package/dist/config/bsc_dex_env_args.js +59 -0
- package/dist/config/bsc_env_args.js +0 -67
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.js +1 -0
- package/dist/quote/pricing/index.d.ts +0 -1
- package/dist/quote/pricing/index.js +0 -1
- package/dist/quote/pricing/token_price_cache.d.ts +0 -2
- package/dist/quote/pricing/token_price_cache.js +7 -19
- package/package.json +2 -2
- package/dist/trade/check/base_tx_result_checker.d.ts +0 -28
- package/dist/trade/check/base_tx_result_checker.js +0 -169
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BscDexEnvArgs = void 0;
|
|
4
|
+
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
5
|
+
const bsc_env_args_1 = require("./bsc_env_args");
|
|
6
|
+
class BscDexEnvArgs extends bsc_env_args_1.BscEnvArgs {
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
const cfg = this._cfg;
|
|
10
|
+
this.app_name = (cfg.app_name || '').toLowerCase();
|
|
11
|
+
this.chain_id = (cfg.chain_id || '').toUpperCase();
|
|
12
|
+
this.dex_id = (cfg.dex_id || '').toUpperCase();
|
|
13
|
+
this.server_id = cfg.server_id ?? '';
|
|
14
|
+
this.redis_host = cfg.redis_host;
|
|
15
|
+
this.redis_port = String(cfg.redis_port);
|
|
16
|
+
this.rpc_endpoint = cfg.rpc_endpoint;
|
|
17
|
+
this.ws_endpoint = cfg.ws_endpoint;
|
|
18
|
+
this.group_id = cfg.group_id ?? '';
|
|
19
|
+
this.trade_group_id = cfg.trade_group_id;
|
|
20
|
+
this.quote_pair = cfg.quote_pair;
|
|
21
|
+
this.quote_pool_address = cfg.quote_pool_address;
|
|
22
|
+
this.quote_pool_name = cfg.quote_pool_name;
|
|
23
|
+
this.quote_pool_fee_rate = cfg.quote_pool_fee_rate;
|
|
24
|
+
this.quote_amount_usd = cfg.quote_amount_usd;
|
|
25
|
+
this.wallet_dir = cfg.wallet_dir;
|
|
26
|
+
this.encryption_key = cfg.encryption_key ?? '';
|
|
27
|
+
this.server_ip_list = cfg.server_ip_list ?? '';
|
|
28
|
+
this.ip_exclude_prefix = cfg.ip_exclude_prefix ?? '';
|
|
29
|
+
this.alert_analyze_host = cfg.alert_analyze_host ?? '';
|
|
30
|
+
this.alert_flush_size = cfg.alert_flush_size;
|
|
31
|
+
this.alert_flush_ms = cfg.alert_flush_ms;
|
|
32
|
+
this.alert_dedup_window_ms = cfg.alert_dedup_window_ms;
|
|
33
|
+
this.namespace = cfg.namespace ?? '';
|
|
34
|
+
this.trade_analyze_host = cfg.trade_analyze_host ?? '';
|
|
35
|
+
this.gas_price_gwei = cfg.gas_price_gwei;
|
|
36
|
+
this.gas_limit = cfg.gas_limit;
|
|
37
|
+
this.tip_amount_gwei = cfg.tip_amount_gwei;
|
|
38
|
+
this.pancake_executor_id = cfg.pancake_executor_id;
|
|
39
|
+
this.uniswap_executor_id = cfg.uniswap_executor_id;
|
|
40
|
+
this.caller_select_strategy = cfg.caller_select_strategy;
|
|
41
|
+
this.send_tx_blockrazor_bundle = cfg.send_tx_blockrazor_bundle;
|
|
42
|
+
this.send_tx_48club_bundle = cfg.send_tx_48club_bundle;
|
|
43
|
+
this.send_tx_48club_bundle_ws = cfg.send_tx_48club_bundle_ws;
|
|
44
|
+
this.send_tx_blox_bundle_ws = cfg.send_tx_blox_bundle_ws;
|
|
45
|
+
this.send_tx_ws_host = cfg.send_tx_ws_host;
|
|
46
|
+
this.stream_quote_ws_host = cfg.stream_quote_ws_host;
|
|
47
|
+
this.min_quote_interval_ms = cfg.min_quote_interval_ms;
|
|
48
|
+
this.skip_price_feed_yynode = cfg.skip_price_feed_yynode;
|
|
49
|
+
this.push_price_feed = cfg.push_price_feed;
|
|
50
|
+
this.trade_parse_fetch_block_time = cfg.trade_parse_fetch_block_time;
|
|
51
|
+
this.tick_cache_neighboring_words = cfg.tick_cache_neighboring_words;
|
|
52
|
+
this.tick_cache_ttl = cfg.tick_cache_ttl;
|
|
53
|
+
this.tick_cache_min_update_interval = cfg.tick_cache_min_update_interval;
|
|
54
|
+
}
|
|
55
|
+
print(moduleName) {
|
|
56
|
+
(0, dist_1.printEnvConfig)(moduleName || this.app_name || 'bsc-dex', this);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.BscDexEnvArgs = BscDexEnvArgs;
|
|
@@ -75,73 +75,6 @@ const constants_1 = require("../common/constants");
|
|
|
75
75
|
class BscEnvArgs extends ttd_core_1.EnvArgs {
|
|
76
76
|
constructor() {
|
|
77
77
|
super();
|
|
78
|
-
this.gas_price_gwei = this._cfg.gas_price_gwei;
|
|
79
|
-
this.gas_limit = this._cfg.gas_limit;
|
|
80
|
-
this.tip_amount_gwei = this._cfg.tip_amount_gwei;
|
|
81
|
-
this.pancake_executor_id = this._cfg.pancake_executor_id;
|
|
82
|
-
this.uniswap_executor_id = this._cfg.uniswap_executor_id;
|
|
83
|
-
this.caller_select_strategy = this._cfg.caller_select_strategy;
|
|
84
|
-
this.send_tx_blockrazor_bundle = this._cfg.send_tx_blockrazor_bundle;
|
|
85
|
-
this.send_tx_48club_bundle = this._cfg.send_tx_48club_bundle;
|
|
86
|
-
this.send_tx_48club_bundle_ws = this._cfg.send_tx_48club_bundle_ws;
|
|
87
|
-
this.send_tx_blox_bundle_ws = this._cfg.send_tx_blox_bundle_ws;
|
|
88
|
-
this.stream_quote_ws_host = this._cfg.stream_quote_ws_host;
|
|
89
|
-
this.min_quote_interval_ms = this._cfg.min_quote_interval_ms;
|
|
90
|
-
this.skip_price_feed_yynode = this._cfg.skip_price_feed_yynode;
|
|
91
|
-
this.push_price_feed = this._cfg.push_price_feed;
|
|
92
|
-
this.trade_parse_fetch_block_time = this._cfg.trade_parse_fetch_block_time;
|
|
93
|
-
this.tick_cache_neighboring_words = this._cfg.tick_cache_neighboring_words;
|
|
94
|
-
this.tick_cache_ttl = this._cfg.tick_cache_ttl;
|
|
95
|
-
this.tick_cache_min_update_interval = this._cfg.tick_cache_min_update_interval;
|
|
96
|
-
this.ws_push_enable = this._cfg.ws_push_enable;
|
|
97
|
-
this.print_event_data = this._cfg.print_event_data;
|
|
98
|
-
this.pool_sync_interval_ms = this._cfg.pool_sync_interval_ms;
|
|
99
|
-
this.redis_sync_pool_enable = this._cfg.redis_sync_pool_enable;
|
|
100
|
-
this.redis_url = this._cfg.redis_url;
|
|
101
|
-
this.skip_pool_list = this._cfg.skip_pool_list;
|
|
102
|
-
this.price_feed_skip_dup = this._cfg.price_feed_skip_dup;
|
|
103
|
-
this.trade_analyze_port = this._cfg.trade_analyze_port;
|
|
104
|
-
this.log_max_size_mb = this._cfg.log_max_size_mb;
|
|
105
|
-
this.log_check_interval_min = this._cfg.log_check_interval_min;
|
|
106
|
-
this.log_dir = this._cfg.log_dir;
|
|
107
|
-
this.chain_name = this._cfg.chain_name;
|
|
108
|
-
this.caller_balance_check_interval = this._cfg.caller_balance_check_interval;
|
|
109
|
-
this.caller_balance_low_threshold = this._cfg.caller_balance_low_threshold;
|
|
110
|
-
this.caller_balance_empty_threshold = this._cfg.caller_balance_empty_threshold;
|
|
111
|
-
this.send_tx_ws_host = this._cfg.send_tx_ws_host;
|
|
112
|
-
this.send_tx_48club_ws = this._cfg.send_tx_48club_ws;
|
|
113
|
-
this.send_tx_bloxroute_ws = this._cfg.send_tx_bloxroute_ws;
|
|
114
|
-
this.send_tx_default_rpc = this._cfg.send_tx_default_rpc;
|
|
115
|
-
this.send_tx_blockrazor_private = this._cfg.send_tx_blockrazor_private;
|
|
116
|
-
this.send_tx_48club_private = this._cfg.send_tx_48club_private;
|
|
117
|
-
this.bsc_rpc_endpoint = this._cfg.bsc_rpc_endpoint;
|
|
118
|
-
this.bloxroute_ws_url = this._cfg.bloxroute_ws_url;
|
|
119
|
-
this.blox_auth_key = this._cfg.blox_auth_key;
|
|
120
|
-
this._48club_ws_url = this._cfg._48club_ws_url;
|
|
121
|
-
this._48club_rpc_url = this._cfg._48club_rpc_url;
|
|
122
|
-
this._48club_sp_wallet_id = this._cfg._48club_sp_wallet_id;
|
|
123
|
-
this.blockrazor_rpc_url = this._cfg.blockrazor_rpc_url;
|
|
124
|
-
this.blockrazor_auth_token = this._cfg.blockrazor_auth_token;
|
|
125
|
-
this.gecko_network = (this._cfg.gecko_network || this.chain_id || 'bsc').toLowerCase();
|
|
126
|
-
this.chain_id_num = this._cfg.chain_id_num;
|
|
127
|
-
this.native_token_symbol = this._cfg.native_token_symbol;
|
|
128
|
-
this.native_token_address = this._cfg.native_token_address;
|
|
129
|
-
this.wrapped_native_address = this._cfg.wrapped_native_address;
|
|
130
|
-
this.sync_pool_interval_ms = this._cfg.sync_pool_interval_ms;
|
|
131
|
-
this.fetch_api_wait_ms = this._cfg.fetch_api_wait_ms;
|
|
132
|
-
this.fetch_min_tvl = this._cfg.fetch_min_tvl;
|
|
133
|
-
this.fetch_min_vol = this._cfg.fetch_min_vol;
|
|
134
|
-
this.pool_default_tvl = this._cfg.pool_default_tvl;
|
|
135
|
-
this.fetch_max_page_no = this._cfg.fetch_max_page_no;
|
|
136
|
-
this.token_batch_size = this._cfg.token_batch_size;
|
|
137
|
-
this.fetch_on_startup = this._cfg.fetch_on_startup;
|
|
138
|
-
this.vault_mgt_rpc_url = this._cfg.vault_mgt_rpc_url;
|
|
139
|
-
this.vault_mgt_chain_id = this._cfg.vault_mgt_chain_id;
|
|
140
|
-
this.vault_mgt_chain_name = this._cfg.vault_mgt_chain_name;
|
|
141
|
-
this.vault_mgt_vault_groups = this._cfg.vault_mgt_vault_groups;
|
|
142
|
-
this.vault_mgt_native_symbol = this._cfg.vault_mgt_native_symbol;
|
|
143
|
-
this.vault_mgt_wrapped_native_address = this._cfg.vault_mgt_wrapped_native_address;
|
|
144
|
-
this.vault_mgt_fund_caller_max = this._cfg.vault_mgt_fund_caller_max;
|
|
145
78
|
}
|
|
146
79
|
}
|
|
147
80
|
exports.BscEnvArgs = BscEnvArgs;
|
package/dist/config/index.d.ts
CHANGED
package/dist/config/index.js
CHANGED
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./bsc_env_args"), exports);
|
|
18
|
+
__exportStar(require("./bsc_dex_env_args"), exports);
|
|
18
19
|
__exportStar(require("./BscQuoteAppConfig"), exports);
|
|
@@ -14,7 +14,6 @@ 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("./token_price_cache"), exports);
|
|
18
17
|
__exportStar(require("./pool"), exports);
|
|
19
18
|
__exportStar(require("./sdk_token_factory"), exports);
|
|
20
19
|
__exportStar(require("./pool_state_initializer"), exports);
|
|
@@ -3,27 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TokenPriceCache = void 0;
|
|
4
4
|
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
5
5
|
class TokenPriceCache {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.tokenPriceCache = new Map();
|
|
8
|
-
this.PRICE_CACHE_TIMEOUT_MILLS = parseInt(process.env.PRICE_CACHE_TIMEOUT_MILLS || Number(1000 * 60 * 60 * 1).toString());
|
|
9
|
-
(0, ttd_core_1.log_info)(`代币价格缓存超时时间: ${this.PRICE_CACHE_TIMEOUT_MILLS} ms`);
|
|
10
|
-
}
|
|
6
|
+
constructor() { }
|
|
11
7
|
async getTokenPrice(tokenAddress) {
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
return cachedData;
|
|
18
|
-
}
|
|
19
|
-
const priceMap = await (0, ttd_core_1.get_bsc_token_price_info)([tokenAddress]);
|
|
20
|
-
const tokenPrice = priceMap.get(tokenAddress);
|
|
21
|
-
if (!tokenPrice || !tokenPrice.price || Number(tokenPrice.price) <= 0) {
|
|
22
|
-
throw new Error(`无法获取代币 ${tokenAddress} 的有效USD价格`);
|
|
8
|
+
const addr = tokenAddress.toLowerCase();
|
|
9
|
+
const priceMap = await (0, ttd_core_1.get_bsc_token_price_info)([addr]);
|
|
10
|
+
const tp = priceMap.get(addr);
|
|
11
|
+
if (!tp?.price || Number(tp.price) <= 0) {
|
|
12
|
+
throw new Error(`无法获取代币 ${addr} 的有效USD价格`);
|
|
23
13
|
}
|
|
24
|
-
|
|
25
|
-
this.tokenPriceCache.set(tokenAddress, newPrice);
|
|
26
|
-
return newPrice;
|
|
14
|
+
return { price: tp.price, timestamp: Date.now() };
|
|
27
15
|
}
|
|
28
16
|
}
|
|
29
17
|
exports.TokenPriceCache = TokenPriceCache;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clonegod/ttd-bsc-common",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.24",
|
|
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.
|
|
17
|
+
"@clonegod/ttd-core": "3.1.25",
|
|
18
18
|
"axios": "1.15.0",
|
|
19
19
|
"dotenv": "^16.4.7",
|
|
20
20
|
"ethers": "^5.8.0",
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { EnvArgs } from '@clonegod/ttd-core';
|
|
2
|
-
import { AbstractTransactionResultCheck } from "@clonegod/ttd-core/dist/trade";
|
|
3
|
-
import { EventEmitter } from 'events';
|
|
4
|
-
export declare class TradeResultSubscriber {
|
|
5
|
-
private static instance;
|
|
6
|
-
private ws;
|
|
7
|
-
private connected;
|
|
8
|
-
private listeners;
|
|
9
|
-
static getInstance(): TradeResultSubscriber;
|
|
10
|
-
listen(txHash: string, callback: (receipt: any) => void, timeoutMs?: number): void;
|
|
11
|
-
remove(txHash: string): void;
|
|
12
|
-
sendNonceWatch(caller: string, txHash: string): void;
|
|
13
|
-
private cachedSubscriptions;
|
|
14
|
-
private cachedClientName;
|
|
15
|
-
private getSubscriptions;
|
|
16
|
-
private getClientName;
|
|
17
|
-
private ensureConnected;
|
|
18
|
-
}
|
|
19
|
-
export declare abstract class BaseTxResultChecker extends AbstractTransactionResultCheck {
|
|
20
|
-
protected provider: any;
|
|
21
|
-
constructor(env_args: EnvArgs, event_emitter: EventEmitter);
|
|
22
|
-
protected abstract createParser(): {
|
|
23
|
-
parseTransaction(txReceipt: any, poolInfo: any): Promise<any>;
|
|
24
|
-
};
|
|
25
|
-
check_tx_result_interval(): Promise<void>;
|
|
26
|
-
on_subscibe_transaction(): Promise<void>;
|
|
27
|
-
private processTransactionResult;
|
|
28
|
-
}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseTxResultChecker = exports.TradeResultSubscriber = void 0;
|
|
4
|
-
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
5
|
-
const logger = (0, ttd_core_1.createLogger)(__filename);
|
|
6
|
-
const trade_1 = require("@clonegod/ttd-core/dist/trade");
|
|
7
|
-
const ethers_compat_1 = require("../../utils/ethers_compat");
|
|
8
|
-
class TradeResultSubscriber {
|
|
9
|
-
constructor() {
|
|
10
|
-
this.ws = null;
|
|
11
|
-
this.connected = false;
|
|
12
|
-
this.listeners = new Map();
|
|
13
|
-
this.cachedSubscriptions = null;
|
|
14
|
-
this.cachedClientName = null;
|
|
15
|
-
}
|
|
16
|
-
static getInstance() {
|
|
17
|
-
if (!TradeResultSubscriber.instance) {
|
|
18
|
-
TradeResultSubscriber.instance = new TradeResultSubscriber();
|
|
19
|
-
}
|
|
20
|
-
return TradeResultSubscriber.instance;
|
|
21
|
-
}
|
|
22
|
-
listen(txHash, callback, timeoutMs = 30000) {
|
|
23
|
-
const key = txHash.toLowerCase();
|
|
24
|
-
this.listeners.set(key, callback);
|
|
25
|
-
setTimeout(() => {
|
|
26
|
-
this.listeners.delete(key);
|
|
27
|
-
}, timeoutMs);
|
|
28
|
-
this.ensureConnected();
|
|
29
|
-
}
|
|
30
|
-
remove(txHash) {
|
|
31
|
-
this.listeners.delete(txHash.toLowerCase());
|
|
32
|
-
}
|
|
33
|
-
sendNonceWatch(caller, txHash) {
|
|
34
|
-
this.ensureConnected();
|
|
35
|
-
if (this.ws && this.connected) {
|
|
36
|
-
this.ws.send(JSON.stringify({ type: 'nonceWatch', caller, txHash }));
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
getSubscriptions() {
|
|
40
|
-
if (this.cachedSubscriptions)
|
|
41
|
-
return this.cachedSubscriptions;
|
|
42
|
-
const groupIds = ((0, ttd_core_1.getCoreEnv)()?.trade_group_id || '').split(',').map(s => s.trim()).filter(Boolean);
|
|
43
|
-
const subs = [];
|
|
44
|
-
for (const gid of groupIds) {
|
|
45
|
-
const w = (0, ttd_core_1.load_wallet)(gid, true);
|
|
46
|
-
if (w.public_key) {
|
|
47
|
-
subs.push({ address: w.public_key, groupId: gid });
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
this.cachedSubscriptions = subs;
|
|
51
|
-
return subs;
|
|
52
|
-
}
|
|
53
|
-
getClientName() {
|
|
54
|
-
if (this.cachedClientName)
|
|
55
|
-
return this.cachedClientName;
|
|
56
|
-
this.cachedClientName = process.env.APP_NAME
|
|
57
|
-
|| process.env.name
|
|
58
|
-
|| (process.env.pm_id ? `pm2-${process.env.pm_id}` : null)
|
|
59
|
-
|| `pid-${process.pid}`;
|
|
60
|
-
return this.cachedClientName;
|
|
61
|
-
}
|
|
62
|
-
ensureConnected() {
|
|
63
|
-
if (this.ws)
|
|
64
|
-
return;
|
|
65
|
-
const host = process.env.STREAM_TRADE_WS_HOST || '127.0.0.1';
|
|
66
|
-
const wsUrl = `ws://${host}:${ttd_core_1.SERVICE_PORT.STREAM_TRADE_WS}`;
|
|
67
|
-
this.ws = new ttd_core_1.WebSocketClient(wsUrl);
|
|
68
|
-
this.ws.onOpen(() => {
|
|
69
|
-
this.connected = true;
|
|
70
|
-
const subs = this.getSubscriptions();
|
|
71
|
-
const clientName = this.getClientName();
|
|
72
|
-
for (const { address, groupId } of subs) {
|
|
73
|
-
this.ws.send(JSON.stringify({ address, groupId, clientName }));
|
|
74
|
-
}
|
|
75
|
-
logger.info(`TradeResultSubscriber connected: ${wsUrl}, subscribed=${subs.length}`);
|
|
76
|
-
});
|
|
77
|
-
this.ws.onMessage((msg) => {
|
|
78
|
-
if (msg.type !== 'TradeResult' || !msg.data)
|
|
79
|
-
return;
|
|
80
|
-
const { txHash, receipt } = msg.data;
|
|
81
|
-
if (!txHash || !receipt)
|
|
82
|
-
return;
|
|
83
|
-
const key = txHash.toLowerCase();
|
|
84
|
-
const callback = this.listeners.get(key);
|
|
85
|
-
if (callback) {
|
|
86
|
-
this.listeners.delete(key);
|
|
87
|
-
callback(receipt);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
this.ws.connect();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
exports.TradeResultSubscriber = TradeResultSubscriber;
|
|
94
|
-
TradeResultSubscriber.instance = null;
|
|
95
|
-
class BaseTxResultChecker extends trade_1.AbstractTransactionResultCheck {
|
|
96
|
-
constructor(env_args, event_emitter) {
|
|
97
|
-
super(env_args, event_emitter);
|
|
98
|
-
this.provider = new ethers_compat_1.ethersCompat.JsonRpcProvider(this.env_args.rpc_endpoint);
|
|
99
|
-
}
|
|
100
|
-
async check_tx_result_interval() {
|
|
101
|
-
const check_start_time = Date.now();
|
|
102
|
-
const check_interval = parseInt(process.env.CHECK_TX_RESULT_INTERVAL_MILLS || '3000');
|
|
103
|
-
const check_timeout = parseInt(process.env.CHECK_TX_RESULT_TIMEOUT_MILLS || '15000');
|
|
104
|
-
if (check_interval >= check_timeout)
|
|
105
|
-
return;
|
|
106
|
-
const intervalId = setInterval(async () => {
|
|
107
|
-
this.check_count += 1;
|
|
108
|
-
logger.info(`check transaction start: seq=[${this.check_count}], txhash=${this.txid}, trace_id=${this.trace_id}`);
|
|
109
|
-
try {
|
|
110
|
-
if (Date.now() - check_start_time < check_timeout) {
|
|
111
|
-
let txReceipt = await this.provider.getTransactionReceipt(this.txid);
|
|
112
|
-
if (!txReceipt)
|
|
113
|
-
return;
|
|
114
|
-
logger.info(`Received transaction result via polling: ${this.txid}`);
|
|
115
|
-
clearInterval(intervalId);
|
|
116
|
-
await this.processTransactionResult(txReceipt, 'interval');
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
clearInterval(intervalId);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
catch (err) {
|
|
123
|
-
clearInterval(intervalId);
|
|
124
|
-
logger.error('parse transaction error!', err);
|
|
125
|
-
}
|
|
126
|
-
}, check_interval);
|
|
127
|
-
this.intervalId = intervalId;
|
|
128
|
-
}
|
|
129
|
-
async on_subscibe_transaction() {
|
|
130
|
-
logger.info(`Subscribing trade result, txid=${this.txid}`);
|
|
131
|
-
TradeResultSubscriber.getInstance().listen(this.txid, (receipt) => {
|
|
132
|
-
logger.info(`Received transaction result via stream-trade: ${this.txid}`);
|
|
133
|
-
this.processTransactionResult(receipt, 'websocket')
|
|
134
|
-
.catch(err => logger.error(`Error processing trade result: ${this.txid}`, err));
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
async processTransactionResult(txReceipt, source) {
|
|
138
|
-
if (ttd_core_1.LOG.debug) {
|
|
139
|
-
(0, ttd_core_1.writeFile)(`./dist/tx_receipt_${this.txid}_${source}.json`, JSON.stringify(txReceipt, null, 2));
|
|
140
|
-
}
|
|
141
|
-
if (this.trade_result_already_processed) {
|
|
142
|
-
logger.info(`trade_result_already_processed, ignore result from ${source}`);
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
const parser = this.createParser();
|
|
146
|
-
const swap_detail = await parser.parseTransaction(txReceipt, this.pool_info);
|
|
147
|
-
let trade_result = this.map_swap_result_to_tx_result(swap_detail);
|
|
148
|
-
this.trade_result_already_processed = true;
|
|
149
|
-
if (this.intervalId) {
|
|
150
|
-
clearInterval(this.intervalId);
|
|
151
|
-
this.intervalId = null;
|
|
152
|
-
}
|
|
153
|
-
if (trade_result.success) {
|
|
154
|
-
this.event_emitter.emit(ttd_core_1.TRANSACTION_STATE_SUCCESS, trade_result);
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
this.event_emitter.emit(ttd_core_1.TRANSACTION_STATE_FAILED, trade_result);
|
|
158
|
-
}
|
|
159
|
-
if (source === 'interval') {
|
|
160
|
-
console.log('--------------------- Transaction Result from Polling ---------------------');
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
console.log('===================== Transaction Result from stream-trade =====================');
|
|
164
|
-
}
|
|
165
|
-
console.log(JSON.stringify(trade_result, null, 2));
|
|
166
|
-
console.log('-----------------------------------------------------------------------------');
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
exports.BaseTxResultChecker = BaseTxResultChecker;
|