@clonegod/ttd-base-common 1.0.26 → 1.1.2
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 +3 -3
- 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
|
@@ -1,421 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.AbstractEvmDexTradePlus = void 0;
|
|
16
|
-
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
17
|
-
const ethers_1 = require("ethers");
|
|
18
|
-
const common_1 = require("../common");
|
|
19
|
-
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
20
|
-
const redis_1 = require("../redis");
|
|
21
|
-
class AbstractEvmDexTradePlus extends dist_1.AbastrcatTrade {
|
|
22
|
-
constructor(appConfig) {
|
|
23
|
-
super();
|
|
24
|
-
this.appConfig = appConfig;
|
|
25
|
-
this.walletMode = 'multi';
|
|
26
|
-
this.approvedTokens = new Map();
|
|
27
|
-
this.pairContracts = new Map();
|
|
28
|
-
this.tokenContracts = new Map();
|
|
29
|
-
this.approvedTokens = new Map();
|
|
30
|
-
this.pairContracts = new Map();
|
|
31
|
-
this.tokenContracts = new Map();
|
|
32
|
-
this.initConfigs();
|
|
33
|
-
this.chainNameLower = this.appConfig.env_args.chain_id.toLowerCase();
|
|
34
|
-
this.redisClient = new redis_1.SimpleRedisClient(`${this.chainNameLower}:tx`);
|
|
35
|
-
}
|
|
36
|
-
init() {
|
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
this.provider = new ethers_1.ethers.providers.JsonRpcProvider(this.chainConfig.rpcEndpoint);
|
|
39
|
-
const walletGroupIds = process.env.WALLET_GROUP_IDS || '';
|
|
40
|
-
this.walletMode = walletGroupIds && walletGroupIds.trim().split(',').length > 0 ? 'multi' : 'single';
|
|
41
|
-
if (this.walletMode === 'multi') {
|
|
42
|
-
let wallet_infos = (0, dist_1.load_wallet_multi)(walletGroupIds.split(','), false);
|
|
43
|
-
this.group_wallets = wallet_infos.map(info => new ethers_1.ethers.Wallet(info.private_key, this.provider));
|
|
44
|
-
(0, dist_1.log_info)(`组钱包已初始化,数量: ${this.group_wallets.length}`, this.group_wallets.map(e => e.address));
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
this.wallet = new ethers_1.ethers.Wallet(this.appConfig.trade_runtime.wallet.private_key, this.provider);
|
|
48
|
-
(0, dist_1.log_info)(`单钱包已初始化,walletAddress= ${this.wallet.address}`);
|
|
49
|
-
}
|
|
50
|
-
this.routerContract = new ethers_1.ethers.Contract(this.dexConfig.routerAddress, this.dexConfig.routerAbi, this.provider);
|
|
51
|
-
(0, dist_1.log_info)(`${this.dexConfig.dexName} Router已初始化, routerAddress= ${this.dexConfig.routerAddress}`);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
getWalletMode() {
|
|
55
|
-
return this.walletMode;
|
|
56
|
-
}
|
|
57
|
-
getSingleWallet() {
|
|
58
|
-
if (this.walletMode !== 'single' || !this.wallet) {
|
|
59
|
-
throw new Error('Single wallet not available in multi-wallet mode or not initialized');
|
|
60
|
-
}
|
|
61
|
-
return this.wallet;
|
|
62
|
-
}
|
|
63
|
-
getGroupWallets() {
|
|
64
|
-
if (this.walletMode !== 'multi' || !this.group_wallets) {
|
|
65
|
-
throw new Error('Group wallets not available in single-wallet mode or not initialized');
|
|
66
|
-
}
|
|
67
|
-
return this.group_wallets;
|
|
68
|
-
}
|
|
69
|
-
getTokenContract(tokenAddress) {
|
|
70
|
-
if (!this.tokenContracts.has(tokenAddress)) {
|
|
71
|
-
const tokenContract = new ethers_1.ethers.Contract(tokenAddress, common_1.ERC20_ABI, this.provider);
|
|
72
|
-
this.tokenContracts.set(tokenAddress, tokenContract);
|
|
73
|
-
}
|
|
74
|
-
return this.tokenContracts.get(tokenAddress);
|
|
75
|
-
}
|
|
76
|
-
getTokenContractWithWallet(tokenAddress, wallet) {
|
|
77
|
-
const tokenContract = this.getTokenContract(tokenAddress);
|
|
78
|
-
return tokenContract.connect(wallet);
|
|
79
|
-
}
|
|
80
|
-
getGasPriceGwei(context) {
|
|
81
|
-
let { evm_gas_limit, evm_gas_price_gwei, evm_tip_amount_gwei } = context.trade_runtime.settings.strategy;
|
|
82
|
-
if (evm_gas_price_gwei === undefined || evm_gas_price_gwei === null || evm_gas_price_gwei <= 0) {
|
|
83
|
-
evm_gas_price_gwei = this.chainConfig.gasOptions.defaultGasPriceGwei;
|
|
84
|
-
}
|
|
85
|
-
(0, dist_1.log_info)(`getGasPriceGwei: ${evm_gas_price_gwei} Gwei`);
|
|
86
|
-
return evm_gas_price_gwei.toString();
|
|
87
|
-
}
|
|
88
|
-
getBuilderTipAmoutGwei(context) {
|
|
89
|
-
let { evm_gas_limit, evm_gas_price_gwei, evm_tip_amount_gwei } = context.trade_runtime.settings.strategy;
|
|
90
|
-
if (evm_tip_amount_gwei === undefined || evm_tip_amount_gwei === null || evm_tip_amount_gwei <= 0) {
|
|
91
|
-
evm_tip_amount_gwei = this.chainConfig.gasOptions.defaultTipAmountGwei;
|
|
92
|
-
}
|
|
93
|
-
(0, dist_1.log_info)(`getGasTipAmoutGwei: ${evm_tip_amount_gwei} Gwei`);
|
|
94
|
-
return evm_tip_amount_gwei.toString();
|
|
95
|
-
}
|
|
96
|
-
preApproveAllWallets() {
|
|
97
|
-
return __awaiter(this, arguments, void 0, function* (token_list = []) {
|
|
98
|
-
if (this.walletMode === 'single') {
|
|
99
|
-
if (!this.wallet) {
|
|
100
|
-
(0, dist_1.log_info)('Single wallet not available for pre-approval');
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
if (!token_list || token_list.length === 0) {
|
|
104
|
-
token_list = Array.from(this.tokenContracts.keys());
|
|
105
|
-
}
|
|
106
|
-
(0, dist_1.log_info)(`Pre-approve: single wallet ${this.wallet.address}, ${token_list.length} tokens`, token_list);
|
|
107
|
-
const tokenAddresses = new Set();
|
|
108
|
-
for (const token_address of token_list) {
|
|
109
|
-
tokenAddresses.add(token_address.toLowerCase());
|
|
110
|
-
}
|
|
111
|
-
const tokens = Array.from(tokenAddresses);
|
|
112
|
-
try {
|
|
113
|
-
(0, dist_1.log_info)(`Pre-approve: wallet ${this.wallet.address}`);
|
|
114
|
-
for (const tokenAddress of tokens) {
|
|
115
|
-
try {
|
|
116
|
-
yield this.approveTokenIfNeeded(this.wallet, tokenAddress);
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
console.warn(`Failed to pre-approve token ${tokenAddress} for wallet ${this.wallet.address}:`, error);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
(0, dist_1.log_info)(`Pre-approve: wallet ${this.wallet.address} completed`);
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
console.warn(`Failed to pre-approve tokens for wallet ${this.wallet.address}:`, error);
|
|
126
|
-
}
|
|
127
|
-
(0, dist_1.log_info)('Pre-approve: single wallet completed');
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
if (!this.group_wallets || this.group_wallets.length === 0) {
|
|
131
|
-
(0, dist_1.log_info)('No wallets available for pre-approval');
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
if (!token_list || token_list.length === 0) {
|
|
135
|
-
token_list = Array.from(this.tokenContracts.keys());
|
|
136
|
-
}
|
|
137
|
-
(0, dist_1.log_info)(`Pre-approve: ${this.group_wallets.length} wallets, ${token_list.length} tokens`, token_list);
|
|
138
|
-
const tokenAddresses = new Set();
|
|
139
|
-
for (const token_address of token_list) {
|
|
140
|
-
tokenAddresses.add(token_address.toLowerCase());
|
|
141
|
-
}
|
|
142
|
-
const tokens = Array.from(tokenAddresses);
|
|
143
|
-
for (const wallet of this.group_wallets) {
|
|
144
|
-
try {
|
|
145
|
-
(0, dist_1.log_info)(`Pre-approve: wallet ${wallet.address}`);
|
|
146
|
-
for (const tokenAddress of tokens) {
|
|
147
|
-
try {
|
|
148
|
-
yield this.approveTokenIfNeeded(wallet, tokenAddress);
|
|
149
|
-
}
|
|
150
|
-
catch (error) {
|
|
151
|
-
console.warn(`Failed to pre-approve token ${tokenAddress} for wallet ${wallet.address}:`, error);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
(0, dist_1.log_info)(`Pre-approve: wallet ${wallet.address} completed`);
|
|
155
|
-
}
|
|
156
|
-
catch (error) {
|
|
157
|
-
console.warn(`Failed to pre-approve tokens for wallet ${wallet.address}:`, error);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
(0, dist_1.log_info)('Pre-approve: all wallets completed');
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
approveTokenIfNeeded(wallet, tokenAddress) {
|
|
165
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
-
try {
|
|
167
|
-
const tokenContract = this.getTokenContract(tokenAddress);
|
|
168
|
-
const routerAddress = this.dexConfig.routerAddress;
|
|
169
|
-
const currentAllowance = yield tokenContract.allowance(wallet.address, routerAddress);
|
|
170
|
-
if (currentAllowance.gt(0)) {
|
|
171
|
-
(0, dist_1.log_info)(`Pre-approve: token ${tokenAddress} already approved`);
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
const maxAllowance = ethers_1.ethers.constants.MaxUint256;
|
|
175
|
-
const approveTx = yield tokenContract.connect(wallet).approve(routerAddress, maxAllowance);
|
|
176
|
-
(0, dist_1.log_info)(`Pre-approve: token ${tokenAddress} approve success, tx: ${approveTx.hash}`);
|
|
177
|
-
yield approveTx.wait();
|
|
178
|
-
(0, dist_1.log_info)(`Pre-approve: token ${tokenAddress} approved successfully`);
|
|
179
|
-
}
|
|
180
|
-
catch (error) {
|
|
181
|
-
console.warn(`Failed to approve token ${tokenAddress} for wallet ${wallet.address}:`, error);
|
|
182
|
-
throw error;
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
checkTradeTokenApprove(context, wallet, routerAddress) {
|
|
187
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
-
const { pool_info } = context;
|
|
189
|
-
const { tokenA, tokenB } = pool_info;
|
|
190
|
-
const router = routerAddress || this.dexConfig.routerAddress;
|
|
191
|
-
if (!this.approvedTokens.has(wallet.address)) {
|
|
192
|
-
this.approvedTokens.set(wallet.address, new Map());
|
|
193
|
-
}
|
|
194
|
-
yield Promise.all([tokenA, tokenB].map((_a) => __awaiter(this, [_a], void 0, function* ({ symbol, address }) {
|
|
195
|
-
const tokenContract = this.getTokenContractWithWallet(address, wallet);
|
|
196
|
-
yield this.checkTokenApprove(address, symbol, tokenContract, router, wallet);
|
|
197
|
-
})));
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
checkTokenApprove(tokenAddress, tokenSymbol, tokenContract, spenderAddress, wallet) {
|
|
201
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
202
|
-
if (!this.approvedTokens.has(wallet.address)) {
|
|
203
|
-
this.approvedTokens.set(wallet.address, new Map());
|
|
204
|
-
}
|
|
205
|
-
if (this.approvedTokens.get(wallet.address).get(tokenAddress)) {
|
|
206
|
-
(0, dist_1.log_info)(`钱包 ${wallet.address} 的代币 ${tokenSymbol} 已授权,跳过授权检查`);
|
|
207
|
-
return true;
|
|
208
|
-
}
|
|
209
|
-
const allowance = yield tokenContract.allowance(wallet.address, spenderAddress);
|
|
210
|
-
const maxAllowance = ethers_1.ethers.constants.MaxUint256.div(2);
|
|
211
|
-
(0, dist_1.log_info)(`代币授权检查:`, {
|
|
212
|
-
walletAddress: wallet.address,
|
|
213
|
-
tokenSymbol,
|
|
214
|
-
currentAllowance: allowance.toString(),
|
|
215
|
-
maxAllowance: maxAllowance.toString(),
|
|
216
|
-
isSufficient: allowance.gte(maxAllowance)
|
|
217
|
-
});
|
|
218
|
-
if (allowance.lt(maxAllowance)) {
|
|
219
|
-
const maxApprovalAmount = ethers_1.ethers.utils.formatUnits(ethers_1.ethers.constants.MaxUint256, yield tokenContract.decimals());
|
|
220
|
-
const tokenSymbolDisplay = tokenSymbol || `${tokenAddress.substring(0, 6)}...`;
|
|
221
|
-
(0, dist_1.log_info)(`正在为钱包 ${wallet.address} 授权代币 ${tokenSymbolDisplay}`, {
|
|
222
|
-
walletAddress: wallet.address,
|
|
223
|
-
tokenAddress,
|
|
224
|
-
tokenSymbol: tokenSymbolDisplay,
|
|
225
|
-
currentAllowance: ethers_1.ethers.utils.formatUnits(allowance, yield tokenContract.decimals()),
|
|
226
|
-
newAllowance: maxApprovalAmount
|
|
227
|
-
});
|
|
228
|
-
const tx = yield tokenContract.approve(spenderAddress, ethers_1.ethers.constants.MaxUint256, {
|
|
229
|
-
gasLimit: this.chainConfig.gasOptions.gasLimit
|
|
230
|
-
});
|
|
231
|
-
yield tx.wait();
|
|
232
|
-
this.approvedTokens.get(wallet.address).set(tokenAddress, true);
|
|
233
|
-
(0, dist_1.log_info)(`钱包 ${wallet.address} 的代币 ${tokenSymbolDisplay} 授权完成,数量: ${maxApprovalAmount} ${tokenSymbolDisplay}, 交易哈希: ${tx.hash}`);
|
|
234
|
-
return true;
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
|
-
this.approvedTokens.get(wallet.address).set(tokenAddress, true);
|
|
238
|
-
return true;
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
isNonceRelatedError(error) {
|
|
243
|
-
if (!error)
|
|
244
|
-
return false;
|
|
245
|
-
const errorMessage = error.message ? error.message.toLowerCase() : '';
|
|
246
|
-
const nonceErrorKeywords = [
|
|
247
|
-
'nonce',
|
|
248
|
-
'nonce too low',
|
|
249
|
-
'nonce too high',
|
|
250
|
-
'nonce has already been used',
|
|
251
|
-
'already known',
|
|
252
|
-
'replacement transaction underpriced',
|
|
253
|
-
'transaction with same nonce',
|
|
254
|
-
'transaction nonce is too low',
|
|
255
|
-
'invalid transaction nonce',
|
|
256
|
-
'insufficient funds',
|
|
257
|
-
'sign bundle to get failure details',
|
|
258
|
-
];
|
|
259
|
-
return nonceErrorKeywords.some(keyword => errorMessage.includes(keyword));
|
|
260
|
-
}
|
|
261
|
-
isNativeCurrency(symbol) {
|
|
262
|
-
return symbol.toUpperCase() === this.chainConfig.nativeCurrency;
|
|
263
|
-
}
|
|
264
|
-
getWrappedNativeAddress() {
|
|
265
|
-
return this.chainConfig.wrappedNativeCurrencyAddress;
|
|
266
|
-
}
|
|
267
|
-
buildTipTransferTx(to, transfer_amount_gwei, gas_price_gwei, transfer_nonce, wallet) {
|
|
268
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
269
|
-
let real_transfer_amount_gwei = Math.min(Number(transfer_amount_gwei), this.chainConfig.gasOptions.maxTipAmountGwei).toString();
|
|
270
|
-
let real_gas_price_gwei = Math.min(Number(gas_price_gwei), this.chainConfig.gasOptions.maxGasPriceGwei).toString();
|
|
271
|
-
let tx_data = {
|
|
272
|
-
from: wallet.address,
|
|
273
|
-
to,
|
|
274
|
-
value: ethers_1.ethers.utils.parseUnits(real_transfer_amount_gwei, 'gwei'),
|
|
275
|
-
gasLimit: 21000,
|
|
276
|
-
gasPrice: ethers_1.ethers.utils.parseUnits(real_gas_price_gwei, 'gwei'),
|
|
277
|
-
nonce: transfer_nonce,
|
|
278
|
-
chainId: this.chainConfig.chainId
|
|
279
|
-
};
|
|
280
|
-
let signedTx = yield wallet.signTransaction(tx_data);
|
|
281
|
-
(0, dist_1.log_info)(`构建转账交易: `, Object.assign(Object.assign({}, tx_data), { real_transfer_amount_gwei,
|
|
282
|
-
real_gas_price_gwei, txhash: ethers_1.ethers.utils.keccak256(signedTx) }));
|
|
283
|
-
return signedTx;
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
chooseWallet(context) {
|
|
287
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
288
|
-
var _a, _b;
|
|
289
|
-
if (this.getWalletMode() === 'single') {
|
|
290
|
-
return this.getSingleWallet();
|
|
291
|
-
}
|
|
292
|
-
const { inputToken } = this.determineInputOutputTokens(context.order_msg, context.pool_info);
|
|
293
|
-
console.log('inputToken', inputToken);
|
|
294
|
-
const requiredAmount = new decimal_js_1.default(context.order_msg.amount);
|
|
295
|
-
const wallet_assets = yield this.redisClient.hgetall(`${this.chainNameLower}:wallet:assets`);
|
|
296
|
-
if (!wallet_assets || Object.keys(wallet_assets).length === 0) {
|
|
297
|
-
throw new Error('没有找到钱包资产信息,请确保钱包监控服务正在运行');
|
|
298
|
-
}
|
|
299
|
-
const wallet_assets_map = {};
|
|
300
|
-
for (const [walletAddress, assetsJson] of Object.entries(wallet_assets)) {
|
|
301
|
-
try {
|
|
302
|
-
wallet_assets_map[walletAddress] = JSON.parse(assetsJson);
|
|
303
|
-
}
|
|
304
|
-
catch (error) {
|
|
305
|
-
console.warn(`解析钱包资产数据失败: ${walletAddress}`, error);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
const availableWallets = [];
|
|
309
|
-
const allWallets = [];
|
|
310
|
-
for (const [walletAddress, assets] of Object.entries(wallet_assets_map)) {
|
|
311
|
-
try {
|
|
312
|
-
const wallet = (_a = this.group_wallets) === null || _a === void 0 ? void 0 : _a.find(w => w.address.toLowerCase() === walletAddress.toLowerCase());
|
|
313
|
-
if (!wallet) {
|
|
314
|
-
continue;
|
|
315
|
-
}
|
|
316
|
-
const tokenAsset = (_b = assets.tokens) === null || _b === void 0 ? void 0 : _b.find((token) => token.tokenaddr.toLowerCase() === inputToken.address.toLowerCase());
|
|
317
|
-
let tokenBalance = (tokenAsset === null || tokenAsset === void 0 ? void 0 : tokenAsset.balance) || '0';
|
|
318
|
-
const balanceDecimal = new decimal_js_1.default(tokenBalance);
|
|
319
|
-
if (balanceDecimal.gte(requiredAmount)) {
|
|
320
|
-
availableWallets.push({
|
|
321
|
-
wallet,
|
|
322
|
-
balance: tokenBalance
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
else {
|
|
326
|
-
console.log(`钱包 ${walletAddress} 余额不足: ${tokenBalance} ${inputToken.symbol} < ${requiredAmount} ${inputToken.symbol}`);
|
|
327
|
-
}
|
|
328
|
-
allWallets.push({
|
|
329
|
-
wallet,
|
|
330
|
-
balance: tokenBalance
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
catch (error) {
|
|
334
|
-
console.warn(`处理钱包资产时出错: ${walletAddress}`, error);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
if (availableWallets.length === 0) {
|
|
338
|
-
let error_msg = `all wallets are insufficient, required: ${requiredAmount} ${inputToken.symbol}`;
|
|
339
|
-
(0, dist_1.log_warn)(error_msg);
|
|
340
|
-
allWallets.forEach((walletInfo, index) => {
|
|
341
|
-
const shortAddress = walletInfo.wallet.address.substring(0, 6) + '...' + walletInfo.wallet.address.substring(walletInfo.wallet.address.length - 4);
|
|
342
|
-
console.log(`${index + 1}. ${shortAddress}: ${walletInfo.balance} ${inputToken.symbol}`);
|
|
343
|
-
});
|
|
344
|
-
throw new Error(error_msg);
|
|
345
|
-
}
|
|
346
|
-
console.log('availableWallets', availableWallets.map(w => w.wallet.address));
|
|
347
|
-
const wallet_last_used = yield this.redisClient.hgetall(`${this.chainNameLower}:wallet:last_used`);
|
|
348
|
-
for (const availableWallet of availableWallets) {
|
|
349
|
-
const lastUsedData = wallet_last_used === null || wallet_last_used === void 0 ? void 0 : wallet_last_used[availableWallet.wallet.address];
|
|
350
|
-
if (lastUsedData) {
|
|
351
|
-
try {
|
|
352
|
-
const lastUsedInfo = JSON.parse(lastUsedData);
|
|
353
|
-
availableWallet.lastUsedAt = lastUsedInfo.lastUsedAt;
|
|
354
|
-
}
|
|
355
|
-
catch (error) {
|
|
356
|
-
console.warn(`解析钱包最后使用时间失败: ${availableWallet.wallet.address}`, error);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
else {
|
|
360
|
-
yield this.redisClient.hsetValue(`${this.chainNameLower}:wallet:last_used`, availableWallet.wallet.address, JSON.stringify({
|
|
361
|
-
lastUsedAt: 0,
|
|
362
|
-
lastUsedTime: new Date(0).toISOString()
|
|
363
|
-
}), 24 * 60 * 60);
|
|
364
|
-
availableWallet.lastUsedAt = 0;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
let selectedWallet;
|
|
368
|
-
let selectionStrategy;
|
|
369
|
-
if (availableWallets.length === 1) {
|
|
370
|
-
selectedWallet = availableWallets[0].wallet;
|
|
371
|
-
selectionStrategy = 'OnlyOne';
|
|
372
|
-
}
|
|
373
|
-
else {
|
|
374
|
-
const hasUsageHistory = wallet_last_used && Object.keys(wallet_last_used).length > 0;
|
|
375
|
-
if (hasUsageHistory) {
|
|
376
|
-
availableWallets.sort((a, b) => {
|
|
377
|
-
const aTime = a.lastUsedAt || 0;
|
|
378
|
-
const bTime = b.lastUsedAt || 0;
|
|
379
|
-
return aTime - bTime;
|
|
380
|
-
});
|
|
381
|
-
selectedWallet = availableWallets[0].wallet;
|
|
382
|
-
selectionStrategy = 'MaxLastUsed';
|
|
383
|
-
}
|
|
384
|
-
else {
|
|
385
|
-
availableWallets.sort((a, b) => {
|
|
386
|
-
const aBalance = new decimal_js_1.default(a.balance);
|
|
387
|
-
const bBalance = new decimal_js_1.default(b.balance);
|
|
388
|
-
return bBalance.cmp(aBalance);
|
|
389
|
-
});
|
|
390
|
-
selectedWallet = availableWallets[0].wallet;
|
|
391
|
-
selectionStrategy = 'MaxBalance';
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
yield this.redisClient.hsetValue(`${this.chainNameLower}:wallet:last_used`, selectedWallet.address, JSON.stringify({
|
|
395
|
-
lastUsedAt: Date.now(),
|
|
396
|
-
lastUsedTime: new Date().toISOString()
|
|
397
|
-
}), 24 * 60 * 60);
|
|
398
|
-
const selectedWalletInfo = availableWallets.find(w => w.wallet.address === selectedWallet.address);
|
|
399
|
-
(0, dist_1.log_info)(`Choose wallet: ${selectionStrategy} -> ${selectedWallet.address}, balance: ${selectedWalletInfo === null || selectedWalletInfo === void 0 ? void 0 : selectedWalletInfo.balance} ${inputToken.symbol}, required: ${requiredAmount} ${inputToken.symbol}`);
|
|
400
|
-
return selectedWallet;
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
determineInputOutputTokens(order_msg, pool_info) {
|
|
404
|
-
const { aToB } = order_msg;
|
|
405
|
-
const { tokenA, tokenB, quote_token } = pool_info;
|
|
406
|
-
const quoteToken = [tokenA, tokenB].find(token => token.symbol === quote_token);
|
|
407
|
-
const nonQuoteToken = [tokenA, tokenB].find(token => token.symbol !== quote_token);
|
|
408
|
-
const inputToken = aToB ? nonQuoteToken : quoteToken;
|
|
409
|
-
const outputToken = aToB ? quoteToken : nonQuoteToken;
|
|
410
|
-
if (!inputToken || !outputToken) {
|
|
411
|
-
throw new Error(`无法确定输入/输出代币: ${JSON.stringify({
|
|
412
|
-
tokenA: tokenA.symbol,
|
|
413
|
-
tokenB: tokenB.symbol,
|
|
414
|
-
quote: quote_token,
|
|
415
|
-
aToB
|
|
416
|
-
})}`);
|
|
417
|
-
}
|
|
418
|
-
return { inputToken, outputToken };
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
exports.AbstractEvmDexTradePlus = AbstractEvmDexTradePlus;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
|
-
export declare class WebSocketManager {
|
|
3
|
-
private static instance;
|
|
4
|
-
private wsProvider;
|
|
5
|
-
private wsConnections;
|
|
6
|
-
private reconnectAttempts;
|
|
7
|
-
private readonly MAX_RECONNECT_ATTEMPTS;
|
|
8
|
-
private readonly RECONNECT_DELAY;
|
|
9
|
-
private reconnecting;
|
|
10
|
-
private eventListeners;
|
|
11
|
-
private constructor();
|
|
12
|
-
static getInstance(): WebSocketManager;
|
|
13
|
-
getWsProvider(wsEndpoint: string, network: {
|
|
14
|
-
name: string;
|
|
15
|
-
chainId: number;
|
|
16
|
-
}): ethers.providers.WebSocketProvider | null;
|
|
17
|
-
private handleWsError;
|
|
18
|
-
private handleWsDisconnection;
|
|
19
|
-
incrementConnections(): void;
|
|
20
|
-
decrementConnections(): void;
|
|
21
|
-
listenToEvent(eventName: string, handler: Function): void;
|
|
22
|
-
removeEventListener(eventName: string, handler: Function): void;
|
|
23
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WebSocketManager = void 0;
|
|
4
|
-
const ethers_1 = require("ethers");
|
|
5
|
-
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
6
|
-
class WebSocketManager {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.wsProvider = null;
|
|
9
|
-
this.wsConnections = 0;
|
|
10
|
-
this.reconnectAttempts = 0;
|
|
11
|
-
this.MAX_RECONNECT_ATTEMPTS = 5;
|
|
12
|
-
this.RECONNECT_DELAY = 2000;
|
|
13
|
-
this.reconnecting = false;
|
|
14
|
-
this.eventListeners = new Map();
|
|
15
|
-
}
|
|
16
|
-
static getInstance() {
|
|
17
|
-
if (!WebSocketManager.instance) {
|
|
18
|
-
WebSocketManager.instance = new WebSocketManager();
|
|
19
|
-
}
|
|
20
|
-
return WebSocketManager.instance;
|
|
21
|
-
}
|
|
22
|
-
getWsProvider(wsEndpoint, network) {
|
|
23
|
-
if (!wsEndpoint) {
|
|
24
|
-
(0, dist_1.log_warn)('WebSocket endpoint not configured');
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
if (!this.wsProvider && !this.reconnecting) {
|
|
28
|
-
(0, dist_1.log_info)('Creating new WebSocket provider');
|
|
29
|
-
try {
|
|
30
|
-
this.wsProvider = new ethers_1.ethers.providers.WebSocketProvider(wsEndpoint, network);
|
|
31
|
-
this.wsProvider.on('error', (error) => {
|
|
32
|
-
this.handleWsError(error, wsEndpoint, network);
|
|
33
|
-
});
|
|
34
|
-
this.wsProvider._websocket.on('close', () => {
|
|
35
|
-
(0, dist_1.log_warn)('WebSocket connection closed');
|
|
36
|
-
this.handleWsDisconnection(wsEndpoint, network);
|
|
37
|
-
});
|
|
38
|
-
this.reconnectAttempts = 0;
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
(0, dist_1.log_error)('Failed to create WebSocket provider', error);
|
|
42
|
-
this.wsProvider = null;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return this.wsProvider;
|
|
46
|
-
}
|
|
47
|
-
handleWsError(error, wsEndpoint, network) {
|
|
48
|
-
(0, dist_1.log_error)('WebSocket provider error', error);
|
|
49
|
-
this.handleWsDisconnection(wsEndpoint, network);
|
|
50
|
-
}
|
|
51
|
-
handleWsDisconnection(wsEndpoint, network) {
|
|
52
|
-
if (this.reconnecting)
|
|
53
|
-
return;
|
|
54
|
-
if (this.wsProvider) {
|
|
55
|
-
this.wsProvider.removeAllListeners();
|
|
56
|
-
this.wsProvider = null;
|
|
57
|
-
}
|
|
58
|
-
if (this.wsConnections > 0 &&
|
|
59
|
-
this.reconnectAttempts < this.MAX_RECONNECT_ATTEMPTS) {
|
|
60
|
-
this.reconnecting = true;
|
|
61
|
-
this.reconnectAttempts++;
|
|
62
|
-
(0, dist_1.log_info)(`Attempting to reconnect WebSocket (${this.reconnectAttempts}/${this.MAX_RECONNECT_ATTEMPTS})`);
|
|
63
|
-
setTimeout(() => {
|
|
64
|
-
this.reconnecting = false;
|
|
65
|
-
this.getWsProvider(wsEndpoint, network);
|
|
66
|
-
}, this.RECONNECT_DELAY * this.reconnectAttempts);
|
|
67
|
-
}
|
|
68
|
-
else if (this.reconnectAttempts >= this.MAX_RECONNECT_ATTEMPTS) {
|
|
69
|
-
(0, dist_1.log_error)(`Maximum WebSocket reconnection attempts (${this.MAX_RECONNECT_ATTEMPTS}) reached`, new Error('Max reconnect attempts'));
|
|
70
|
-
this.wsConnections = 0;
|
|
71
|
-
this.reconnectAttempts = 0;
|
|
72
|
-
this.reconnecting = false;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
incrementConnections() {
|
|
76
|
-
this.wsConnections++;
|
|
77
|
-
(0, dist_1.log_info)(`WebSocket active connections: ${this.wsConnections}`);
|
|
78
|
-
}
|
|
79
|
-
decrementConnections() {
|
|
80
|
-
if (this.wsConnections > 0) {
|
|
81
|
-
this.wsConnections--;
|
|
82
|
-
}
|
|
83
|
-
(0, dist_1.log_info)(`WebSocket active connections: ${this.wsConnections}`);
|
|
84
|
-
if (this.wsConnections === 0 && this.wsProvider) {
|
|
85
|
-
(0, dist_1.log_info)('No active connections, closing WebSocket');
|
|
86
|
-
this.wsProvider.removeAllListeners();
|
|
87
|
-
this.wsProvider = null;
|
|
88
|
-
this.reconnectAttempts = 0;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
listenToEvent(eventName, handler) {
|
|
92
|
-
var _a;
|
|
93
|
-
if (!this.wsProvider) {
|
|
94
|
-
(0, dist_1.log_warn)('WebSocket provider not available for event listener');
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (!this.eventListeners.has(eventName)) {
|
|
98
|
-
this.eventListeners.set(eventName, new Set());
|
|
99
|
-
}
|
|
100
|
-
(_a = this.eventListeners.get(eventName)) === null || _a === void 0 ? void 0 : _a.add(handler);
|
|
101
|
-
this.wsProvider.once(eventName, handler);
|
|
102
|
-
this.incrementConnections();
|
|
103
|
-
}
|
|
104
|
-
removeEventListener(eventName, handler) {
|
|
105
|
-
if (!this.wsProvider)
|
|
106
|
-
return;
|
|
107
|
-
this.wsProvider.removeListener(eventName, handler);
|
|
108
|
-
const handlers = this.eventListeners.get(eventName);
|
|
109
|
-
if (handlers) {
|
|
110
|
-
handlers.delete(handler);
|
|
111
|
-
if (handlers.size === 0) {
|
|
112
|
-
this.eventListeners.delete(eventName);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
this.decrementConnections();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
exports.WebSocketManager = WebSocketManager;
|
|
119
|
-
WebSocketManager.instance = null;
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.AlchemyBase = void 0;
|
|
16
|
-
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
17
|
-
const axios_1 = __importDefault(require("axios"));
|
|
18
|
-
class AlchemyBase {
|
|
19
|
-
constructor() {
|
|
20
|
-
this.endpoint = process.env.BASE_ALCHEMY_RPC_ENDPOINT || '';
|
|
21
|
-
}
|
|
22
|
-
sendTransaction(signedTx) {
|
|
23
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
try {
|
|
25
|
-
const response = yield axios_1.default.post(this.endpoint, {
|
|
26
|
-
jsonrpc: '2.0',
|
|
27
|
-
method: 'eth_sendRawTransaction',
|
|
28
|
-
params: [signedTx],
|
|
29
|
-
id: 1
|
|
30
|
-
}, {
|
|
31
|
-
headers: {
|
|
32
|
-
'Content-Type': 'application/json'
|
|
33
|
-
},
|
|
34
|
-
timeout: 3000
|
|
35
|
-
});
|
|
36
|
-
if (response.data.error) {
|
|
37
|
-
throw new Error(`Alchemy RPC error: ${response.data.error.message}`);
|
|
38
|
-
}
|
|
39
|
-
return response.data.result;
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
(0, dist_1.log_info)(`Alchemy transaction sending failed`, { error: error.message });
|
|
43
|
-
throw error;
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
exports.AlchemyBase = AlchemyBase;
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.AnkrBase = void 0;
|
|
16
|
-
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
17
|
-
const axios_1 = __importDefault(require("axios"));
|
|
18
|
-
class AnkrBase {
|
|
19
|
-
constructor() {
|
|
20
|
-
this.endpoint = process.env.BASE_ANKR_RPC_ENDPOINT || '';
|
|
21
|
-
}
|
|
22
|
-
sendTransaction(signedTx) {
|
|
23
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
try {
|
|
25
|
-
const response = yield axios_1.default.post(this.endpoint, {
|
|
26
|
-
jsonrpc: '2.0',
|
|
27
|
-
method: 'eth_sendRawTransaction',
|
|
28
|
-
params: [signedTx],
|
|
29
|
-
id: 1
|
|
30
|
-
}, {
|
|
31
|
-
headers: {
|
|
32
|
-
'Content-Type': 'application/json'
|
|
33
|
-
},
|
|
34
|
-
timeout: 3000
|
|
35
|
-
});
|
|
36
|
-
if (response.data.error) {
|
|
37
|
-
throw new Error(`Ankr RPC error: ${response.data.error.message}`);
|
|
38
|
-
}
|
|
39
|
-
return response.data.result;
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
(0, dist_1.log_info)(`Ankr transaction sending failed`, { error: error.message });
|
|
43
|
-
throw error;
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
exports.AnkrBase = AnkrBase;
|