four-flap-meme-sdk 1.4.38 → 1.4.39
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 { ethers, Wallet } from 'ethers';
|
|
|
2
2
|
import { getOptimizedGasPrice, NonceManager } from '../../utils/bundle-helpers.js';
|
|
3
3
|
import { PROFIT_CONFIG, ZERO_ADDRESS } from '../../utils/constants.js';
|
|
4
4
|
import { getTxType, getGasPriceConfig, shouldExtractProfit, getProfitRecipient } from './config.js';
|
|
5
|
-
import { getErc20DecimalsMerkle as _getErc20DecimalsMerkle, generateHopWallets as _generateHopWallets, normalizeAmounts as _normalizeAmounts, batchGetBalances as _batchGetBalances, calculateGasLimit as _calculateGasLimit, isNativeTokenAddress as _isNativeTokenAddress
|
|
5
|
+
import { getErc20DecimalsMerkle as _getErc20DecimalsMerkle, generateHopWallets as _generateHopWallets, normalizeAmounts as _normalizeAmounts, batchGetBalances as _batchGetBalances, calculateGasLimit as _calculateGasLimit, isNativeTokenAddress as _isNativeTokenAddress } from './internal.js';
|
|
6
6
|
// ==================== 本地利润计算(万分之三)====================
|
|
7
7
|
/**
|
|
8
8
|
* 计算利润金额(万分之三)
|
|
@@ -357,25 +357,9 @@ export async function disperseWithBundleMerkle(params) {
|
|
|
357
357
|
const iface = isNative ? null : new ethers.Interface(['function transfer(address,uint256) returns (bool)']);
|
|
358
358
|
// ✅ Gas limit 设置
|
|
359
359
|
// - 原生代币转账:21000(固定)
|
|
360
|
-
// - ERC20
|
|
360
|
+
// - ERC20 转账:65000(固定,因为 gas 波动较大,不再使用模拟预估)
|
|
361
361
|
const nativeTransferGasLimit = 21000n;
|
|
362
|
-
|
|
363
|
-
// ⚠️ 注意:多跳时中转钱包是新生成的地址,第一次发送 ERC20 的 gas 消耗可能高于主钱包
|
|
364
|
-
// 因此需要添加 10% 缓冲以确保交易成功
|
|
365
|
-
let erc20TransferGasLimit = finalGasLimit;
|
|
366
|
-
if (!isNative && config.estimateGas !== false) {
|
|
367
|
-
try {
|
|
368
|
-
// 使用第一个接收者模拟一笔转账,获取精确的 gas limit
|
|
369
|
-
const sampleAmount = ethers.parseUnits(normalizedAmounts[0], decimals);
|
|
370
|
-
const estimatedGas = await _estimateErc20TransferGas(provider, tokenAddress, mainWallet.address, recipients[0], sampleAmount, 10 // ✅ 添加 10% 缓冲,因为中转钱包首次发送 ERC20 gas 消耗可能更高
|
|
371
|
-
);
|
|
372
|
-
erc20TransferGasLimit = estimatedGas;
|
|
373
|
-
console.log(`[disperseWithBundleMerkle] 使用模拟估算的 ERC20 gas limit: ${erc20TransferGasLimit} (+10% buffer)`);
|
|
374
|
-
}
|
|
375
|
-
catch (error) {
|
|
376
|
-
console.warn(`[disperseWithBundleMerkle] 模拟估算失败,使用默认值:`, error);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
362
|
+
const erc20TransferGasLimit = 65000n;
|
|
379
363
|
// ✅ 原生代币多跳的 gas 费(每跳只需要 21000)
|
|
380
364
|
const nativeHopGasFee = nativeTransferGasLimit * gasPrice;
|
|
381
365
|
// ✅ ERC20 多跳时,中转钱包需要执行 2 笔交易(转 gas + 转 ERC20)
|
|
@@ -1004,27 +988,10 @@ export async function sweepWithBundleMerkle(params) {
|
|
|
1004
988
|
]);
|
|
1005
989
|
const iface = isNative ? null : new ethers.Interface(['function transfer(address,uint256) returns (bool)']);
|
|
1006
990
|
// ✅ Gas limit 设置(与分散函数保持一致)
|
|
991
|
+
// - 原生代币转账:21000(固定)
|
|
992
|
+
// - ERC20 转账:65000(固定,因为 gas 波动较大,不再使用模拟预估)
|
|
1007
993
|
const nativeTransferGasLimit = 21000n;
|
|
1008
|
-
|
|
1009
|
-
// ⚠️ 注意:多跳时中转钱包是新生成的地址,第一次发送 ERC20 的 gas 消耗可能高于已有余额的钱包
|
|
1010
|
-
// 因此需要添加 10% 缓冲以确保交易成功
|
|
1011
|
-
let erc20TransferGasLimit = finalGasLimit;
|
|
1012
|
-
if (!isNative && config.estimateGas !== false) {
|
|
1013
|
-
try {
|
|
1014
|
-
// 找到第一个有余额的钱包来模拟转账
|
|
1015
|
-
const firstWithBalance = balances.findIndex(b => b > 0n);
|
|
1016
|
-
if (firstWithBalance >= 0) {
|
|
1017
|
-
const sampleAmount = balances[firstWithBalance] > 0n ? balances[firstWithBalance] / 2n : 1n;
|
|
1018
|
-
const estimatedGas = await _estimateErc20TransferGas(provider, tokenAddress, sourceAddresses[firstWithBalance], target, sampleAmount, 10 // ✅ 添加 10% 缓冲,因为中转钱包首次发送 ERC20 gas 消耗可能更高
|
|
1019
|
-
);
|
|
1020
|
-
erc20TransferGasLimit = estimatedGas;
|
|
1021
|
-
console.log(`[sweepWithBundleMerkle] 使用模拟估算的 ERC20 gas limit: ${erc20TransferGasLimit} (+10% buffer)`);
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
catch (error) {
|
|
1025
|
-
console.warn(`[sweepWithBundleMerkle] 模拟估算失败,使用默认值:`, error);
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
994
|
+
const erc20TransferGasLimit = 65000n;
|
|
1028
995
|
// ✅ 原生代币多跳的 gas 费(每跳只需要 21000)
|
|
1029
996
|
const nativeHopGasFee = nativeTransferGasLimit * gasPrice;
|
|
1030
997
|
// ✅ ERC20 多跳时,中转钱包需要执行 2 笔交易(转 gas + 转 ERC20)
|