@clonegod/ttd-bsc-common 1.0.27 → 1.0.28
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,66 @@ 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(token_list) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
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)(`Starting pre-approval for ${this.group_wallets.length} wallets, token_list=`, 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
|
+
(0, dist_1.log_info)(`Pre-approving ${tokens.length} tokens for all wallets`);
|
|
85
|
+
for (const wallet of this.group_wallets) {
|
|
86
|
+
try {
|
|
87
|
+
(0, dist_1.log_info)(`Pre-approving tokens for wallet: ${wallet.address}`);
|
|
88
|
+
for (const tokenAddress of tokens) {
|
|
89
|
+
try {
|
|
90
|
+
yield this.approveTokenIfNeeded(wallet, tokenAddress);
|
|
91
|
+
(0, dist_1.log_info)(`Pre-approved token ${tokenAddress} for wallet ${wallet.address}`);
|
|
92
|
+
yield (0, dist_1.sleep)(1000);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.warn(`Failed to pre-approve token ${tokenAddress} for wallet ${wallet.address}:`, error);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
(0, dist_1.log_info)(`Completed pre-approval for wallet: ${wallet.address}`);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
console.warn(`Failed to pre-approve tokens for wallet ${wallet.address}:`, error);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
(0, dist_1.log_info)('Pre-approval completed for all wallets');
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
approveTokenIfNeeded(wallet, tokenAddress) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
try {
|
|
110
|
+
const tokenContract = this.getTokenContract(tokenAddress);
|
|
111
|
+
const routerAddress = this.dexConfig.routerAddress;
|
|
112
|
+
const currentAllowance = yield tokenContract.allowance(wallet.address, routerAddress);
|
|
113
|
+
if (currentAllowance.gt(0)) {
|
|
114
|
+
(0, dist_1.log_info)(`Token ${tokenAddress} already approved for wallet ${wallet.address}`);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const maxAllowance = ethers_1.ethers.constants.MaxUint256;
|
|
118
|
+
const approveTx = yield tokenContract.connect(wallet).approve(routerAddress, maxAllowance);
|
|
119
|
+
(0, dist_1.log_info)(`Approving token ${tokenAddress} for wallet ${wallet.address}, tx: ${approveTx.hash}`);
|
|
120
|
+
yield approveTx.wait();
|
|
121
|
+
(0, dist_1.log_info)(`Token ${tokenAddress} approved for wallet ${wallet.address}`);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
console.warn(`Failed to approve token ${tokenAddress} for wallet ${wallet.address}:`, error);
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
69
129
|
checkTradeTokenApprove(context, wallet, routerAddress) {
|
|
70
130
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
131
|
const { pool_info } = context;
|