four-flap-meme-sdk 1.3.93 → 1.3.95
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.
|
@@ -2,7 +2,7 @@ import { JsonRpcProvider } from 'ethers';
|
|
|
2
2
|
import type { AmountLike } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* 获取 ERC20 代币精度(带缓存)
|
|
5
|
-
* ✅ 优化:避免每次调用都获取 network
|
|
5
|
+
* ✅ 优化:避免每次调用都获取 network,直接使用传入的 chainId
|
|
6
6
|
*/
|
|
7
7
|
export declare function getErc20DecimalsMerkle(provider: JsonRpcProvider, token: string, chainId?: number): Promise<number>;
|
|
8
8
|
export declare function generateHopWallets(recipientCount: number, hopCount: number | number[]): string[][] | null;
|
|
@@ -3,11 +3,12 @@ import { ethers, Wallet } from 'ethers';
|
|
|
3
3
|
const decimalsCache = new Map();
|
|
4
4
|
/**
|
|
5
5
|
* 获取 ERC20 代币精度(带缓存)
|
|
6
|
-
* ✅ 优化:避免每次调用都获取 network
|
|
6
|
+
* ✅ 优化:避免每次调用都获取 network,直接使用传入的 chainId
|
|
7
7
|
*/
|
|
8
8
|
export async function getErc20DecimalsMerkle(provider, token, chainId) {
|
|
9
|
-
// ✅
|
|
10
|
-
|
|
9
|
+
// ✅ 修复:不访问 provider._network(ethers v6 可能未准备好导致 NETWORK_ERROR)
|
|
10
|
+
// 直接使用传入的 chainId,如果没传则默认 56 (BSC)
|
|
11
|
+
const resolvedChainId = chainId ?? 56;
|
|
11
12
|
const key = `${resolvedChainId}_${token.toLowerCase()}`;
|
|
12
13
|
if (decimalsCache.has(key))
|
|
13
14
|
return decimalsCache.get(key);
|
|
@@ -153,8 +153,8 @@ export async function disperseWithBundleMerkle(params) {
|
|
|
153
153
|
signedTxs.push(...(await Promise.all(txPromises)));
|
|
154
154
|
}
|
|
155
155
|
else {
|
|
156
|
-
// ✅ ERC20:并行获取 decimals
|
|
157
|
-
const decimals = tokenDecimals ?? (await _getErc20DecimalsMerkle(provider, tokenAddress));
|
|
156
|
+
// ✅ ERC20:并行获取 decimals(传入 chainIdNum 避免 NETWORK_ERROR)
|
|
157
|
+
const decimals = tokenDecimals ?? (await _getErc20DecimalsMerkle(provider, tokenAddress, chainIdNum));
|
|
158
158
|
const iface = new ethers.Interface(['function transfer(address,uint256) returns (bool)']);
|
|
159
159
|
// 先计算所有金额和利润(同步)- ERC20 利润以代币计
|
|
160
160
|
let totalTokenProfit = 0n;
|
|
@@ -207,7 +207,7 @@ export async function disperseWithBundleMerkle(params) {
|
|
|
207
207
|
// ✅ 优化:并行获取 gasPrice 和 decimals
|
|
208
208
|
const [gasPrice, decimals] = await Promise.all([
|
|
209
209
|
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
210
|
-
isNative ? Promise.resolve(18) : Promise.resolve(tokenDecimals ?? await _getErc20DecimalsMerkle(provider, tokenAddress))
|
|
210
|
+
isNative ? Promise.resolve(18) : Promise.resolve(tokenDecimals ?? await _getErc20DecimalsMerkle(provider, tokenAddress, chainIdNum))
|
|
211
211
|
]);
|
|
212
212
|
const iface = isNative ? null : new ethers.Interface(['function transfer(address,uint256) returns (bool)']);
|
|
213
213
|
const gasFeePerHop = finalGasLimit * gasPrice;
|
|
@@ -608,10 +608,10 @@ export async function sweepWithBundleMerkle(params) {
|
|
|
608
608
|
}
|
|
609
609
|
}
|
|
610
610
|
else {
|
|
611
|
-
// ✅ ERC20:并行获取 gasPrice、decimals
|
|
611
|
+
// ✅ ERC20:并行获取 gasPrice、decimals、余额(传入 chainIdNum 避免 NETWORK_ERROR)
|
|
612
612
|
const [gasPrice, decimals, balances, bnbBalances] = await Promise.all([
|
|
613
613
|
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
614
|
-
Promise.resolve(tokenDecimals ?? await _getErc20DecimalsMerkle(provider, tokenAddress)),
|
|
614
|
+
Promise.resolve(tokenDecimals ?? await _getErc20DecimalsMerkle(provider, tokenAddress, chainIdNum)),
|
|
615
615
|
_batchGetBalances(provider, addresses, tokenAddress),
|
|
616
616
|
config.checkBnbForErc20NoHop ? _batchGetBalances(provider, addresses) : Promise.resolve([])
|
|
617
617
|
]);
|
|
@@ -760,10 +760,10 @@ export async function sweepWithBundleMerkle(params) {
|
|
|
760
760
|
}
|
|
761
761
|
}
|
|
762
762
|
const sourceAddresses = sourceWallets.map(w => w.address);
|
|
763
|
-
// ✅ 优化:并行获取 gasPrice、decimals
|
|
763
|
+
// ✅ 优化:并行获取 gasPrice、decimals、余额(传入 chainIdNum 避免 NETWORK_ERROR)
|
|
764
764
|
const [gasPrice, decimals, balances, bnbBalances] = await Promise.all([
|
|
765
765
|
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
766
|
-
isNative ? Promise.resolve(18) : Promise.resolve(tokenDecimals ?? await _getErc20DecimalsMerkle(provider, tokenAddress)),
|
|
766
|
+
isNative ? Promise.resolve(18) : Promise.resolve(tokenDecimals ?? await _getErc20DecimalsMerkle(provider, tokenAddress, chainIdNum)),
|
|
767
767
|
_batchGetBalances(provider, sourceAddresses, tokenAddress),
|
|
768
768
|
isNative ? Promise.resolve([]) : _batchGetBalances(provider, sourceAddresses)
|
|
769
769
|
]);
|