@clonegod/ttd-bsc-common 1.0.27 → 1.0.29
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.
|
@@ -18,6 +18,8 @@ export declare abstract class AbstractEvmDexTradePlus extends AbastrcatTrade {
|
|
|
18
18
|
protected getTokenContractWithWallet(tokenAddress: string, wallet: ethers.Wallet): ethers.Contract;
|
|
19
19
|
protected getGasPriceGwei(context: TradeContext): string;
|
|
20
20
|
protected getBuilderTipAmoutGwei(context: TradeContext): string;
|
|
21
|
+
preApproveAllWallets(token_list?: string[]): Promise<void>;
|
|
22
|
+
private approveTokenIfNeeded;
|
|
21
23
|
protected checkTradeTokenApprove(context: TradeContext, wallet: ethers.Wallet, routerAddress?: string): Promise<void>;
|
|
22
24
|
protected checkTokenApprove(tokenAddress: string, tokenSymbol: string, tokenContract: ethers.Contract, spenderAddress: string, wallet: ethers.Wallet): Promise<boolean>;
|
|
23
25
|
protected isNonceRelatedError(error: any): boolean;
|
|
@@ -66,6 +66,63 @@ class AbstractEvmDexTradePlus extends dist_1.AbastrcatTrade {
|
|
|
66
66
|
(0, dist_1.log_info)(`getGasTipAmoutGwei: ${evm_tip_amount_gwei} Gwei`);
|
|
67
67
|
return evm_tip_amount_gwei.toString();
|
|
68
68
|
}
|
|
69
|
+
preApproveAllWallets() {
|
|
70
|
+
return __awaiter(this, arguments, void 0, function* (token_list = []) {
|
|
71
|
+
if (!this.group_wallets || this.group_wallets.length === 0) {
|
|
72
|
+
(0, dist_1.log_info)('No wallets available for pre-approval');
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (!token_list || token_list.length === 0) {
|
|
76
|
+
token_list = Array.from(this.tokenContracts.keys());
|
|
77
|
+
}
|
|
78
|
+
(0, dist_1.log_info)(`Pre-approve: ${this.group_wallets.length} wallets, ${token_list.length} tokens`, token_list);
|
|
79
|
+
const tokenAddresses = new Set();
|
|
80
|
+
for (const token_address of token_list) {
|
|
81
|
+
tokenAddresses.add(token_address.toLowerCase());
|
|
82
|
+
}
|
|
83
|
+
const tokens = Array.from(tokenAddresses);
|
|
84
|
+
for (const wallet of this.group_wallets) {
|
|
85
|
+
try {
|
|
86
|
+
(0, dist_1.log_info)(`Pre-approve: wallet ${wallet.address}`);
|
|
87
|
+
for (const tokenAddress of tokens) {
|
|
88
|
+
try {
|
|
89
|
+
yield this.approveTokenIfNeeded(wallet, tokenAddress);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
console.warn(`Failed to pre-approve token ${tokenAddress} for wallet ${wallet.address}:`, error);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
(0, dist_1.log_info)(`Pre-approve: wallet ${wallet.address} completed`);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
console.warn(`Failed to pre-approve tokens for wallet ${wallet.address}:`, error);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
(0, dist_1.log_info)('Pre-approve: all wallets completed');
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
approveTokenIfNeeded(wallet, tokenAddress) {
|
|
105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
try {
|
|
107
|
+
const tokenContract = this.getTokenContract(tokenAddress);
|
|
108
|
+
const routerAddress = this.dexConfig.routerAddress;
|
|
109
|
+
const currentAllowance = yield tokenContract.allowance(wallet.address, routerAddress);
|
|
110
|
+
if (currentAllowance.gt(0)) {
|
|
111
|
+
(0, dist_1.log_info)(`Pre-approve: token ${tokenAddress} already approved`);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const maxAllowance = ethers_1.ethers.constants.MaxUint256;
|
|
115
|
+
const approveTx = yield tokenContract.connect(wallet).approve(routerAddress, maxAllowance);
|
|
116
|
+
(0, dist_1.log_info)(`Pre-approve: token ${tokenAddress} approve success, tx: ${approveTx.hash}`);
|
|
117
|
+
yield approveTx.wait();
|
|
118
|
+
(0, dist_1.log_info)(`Pre-approve: token ${tokenAddress} approved successfully`);
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
console.warn(`Failed to approve token ${tokenAddress} for wallet ${wallet.address}:`, error);
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
69
126
|
checkTradeTokenApprove(context, wallet, routerAddress) {
|
|
70
127
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
128
|
const { pool_info } = context;
|