four-flap-meme-sdk 1.2.78 → 1.2.80
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.
|
@@ -296,7 +296,6 @@ export async function fourPancakeProxyBatchBuyMerkle(params) {
|
|
|
296
296
|
chainId: 56,
|
|
297
297
|
name: 'BSC'
|
|
298
298
|
});
|
|
299
|
-
const gasPrice = await getOptimizedGasPrice(provider, getGasPriceConfig(config));
|
|
300
299
|
const txType = getTxType(config);
|
|
301
300
|
const buyers = privateKeys.map(k => new Wallet(k, provider));
|
|
302
301
|
const originalAmountsWei = buyAmounts.map(a => ethers.parseEther(a)); // BNB 固定 18 位
|
|
@@ -304,8 +303,11 @@ export async function fourPancakeProxyBatchBuyMerkle(params) {
|
|
|
304
303
|
const extractProfit = shouldExtractProfit(config);
|
|
305
304
|
const { totalProfit, remainingAmounts } = calculateBatchProfit(originalAmountsWei, config);
|
|
306
305
|
const actualAmountsWei = remainingAmounts; // 扣除利润后用于购买的金额
|
|
307
|
-
//
|
|
308
|
-
const tokenDecimals = await
|
|
306
|
+
// ✅ 优化:并行获取 gasPrice 和 tokenDecimals
|
|
307
|
+
const [gasPrice, tokenDecimals] = await Promise.all([
|
|
308
|
+
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
309
|
+
getTokenDecimals(tokenAddress, provider)
|
|
310
|
+
]);
|
|
309
311
|
// 计算 minOutputAmounts
|
|
310
312
|
let minOuts;
|
|
311
313
|
if (params.minOutputAmounts && params.minOutputAmounts.length === buyers.length) {
|
|
@@ -342,7 +344,7 @@ export async function fourPancakeProxyBatchBuyMerkle(params) {
|
|
|
342
344
|
}
|
|
343
345
|
// ✅ 使用前端传入的 gasLimit,否则使用默认值
|
|
344
346
|
const finalGasLimit = getGasLimit(config);
|
|
345
|
-
// ✅
|
|
347
|
+
// ✅ 优化:并行获取 nonces(直接签名和提交以支持利润转账)
|
|
346
348
|
const nonceManager = new NonceManager(provider);
|
|
347
349
|
const nonces = await Promise.all(buyers.map(w => nonceManager.getNextNonce(w)));
|
|
348
350
|
const signedTxs = await Promise.all(unsignedBuys.map((unsigned, i) => buyers[i].signTransaction({
|
|
@@ -393,11 +395,13 @@ export async function fourPancakeProxyBatchSellMerkle(params) {
|
|
|
393
395
|
chainId: 56,
|
|
394
396
|
name: 'BSC'
|
|
395
397
|
});
|
|
396
|
-
const gasPrice = await getOptimizedGasPrice(provider, getGasPriceConfig(config));
|
|
397
398
|
const txType = getTxType(config);
|
|
398
399
|
const sellers = privateKeys.map(k => new Wallet(k, provider));
|
|
399
|
-
//
|
|
400
|
-
const tokenDecimals = await
|
|
400
|
+
// ✅ 优化:并行获取 gasPrice 和 tokenDecimals
|
|
401
|
+
const [gasPrice, tokenDecimals] = await Promise.all([
|
|
402
|
+
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
403
|
+
getTokenDecimals(tokenAddress, provider)
|
|
404
|
+
]);
|
|
401
405
|
const amountsWei = sellAmounts.map(a => ethers.parseUnits(a, tokenDecimals));
|
|
402
406
|
// ✅ Step 1: 使用 Multicall3 批量检查授权状态
|
|
403
407
|
const allowances = await batchCheckAllowances(provider, tokenAddress, sellers.map(w => w.address), pancakeProxyAddress);
|
|
@@ -291,28 +291,34 @@ export async function pancakeProxyBatchBuyMerkle(params) {
|
|
|
291
291
|
throw new Error('Private key count and buy amount count must match');
|
|
292
292
|
}
|
|
293
293
|
const { provider, chainId } = createChainContext(chain, config.rpcUrl);
|
|
294
|
-
const gasPrice = await getOptimizedGasPrice(provider, getGasPriceConfig(config));
|
|
295
294
|
const buyers = createWallets(privateKeys, provider);
|
|
296
295
|
const extractProfit = shouldExtractProfit(config);
|
|
297
296
|
const originalAmountsWei = buyAmounts.map(amount => ethers.parseEther(amount));
|
|
298
297
|
const { totalProfit, remainingAmounts } = calculateBatchProfit(originalAmountsWei, config);
|
|
299
298
|
const maxFundsIndex = findMaxAmountIndex(originalAmountsWei);
|
|
300
|
-
|
|
299
|
+
// ✅ 优化:并行获取 gasPrice 和 tokenDecimals
|
|
300
|
+
const [gasPrice, tokenDecimals] = await Promise.all([
|
|
301
|
+
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
302
|
+
getTokenDecimals(tokenAddress, provider)
|
|
303
|
+
]);
|
|
301
304
|
const minOuts = resolveBuyMinOutputs(params, buyers.length, tokenDecimals);
|
|
302
305
|
const needBNB = needSendBNB(routeType, params);
|
|
303
306
|
const proxies = createPancakeProxies(buyers, ADDRESSES.BSC.PancakeProxy);
|
|
304
|
-
|
|
305
|
-
routeType,
|
|
306
|
-
params,
|
|
307
|
-
proxies,
|
|
308
|
-
wallets: buyers,
|
|
309
|
-
tokenAddress,
|
|
310
|
-
actualAmountsWei: remainingAmounts,
|
|
311
|
-
minOuts,
|
|
312
|
-
needBNB
|
|
313
|
-
});
|
|
307
|
+
// ✅ 优化:并行构建交易和获取 nonces
|
|
314
308
|
const nonceManager = new NonceManager(provider);
|
|
315
|
-
const nonces = await
|
|
309
|
+
const [unsignedBuys, nonces] = await Promise.all([
|
|
310
|
+
buildBuyTransactions({
|
|
311
|
+
routeType,
|
|
312
|
+
params,
|
|
313
|
+
proxies,
|
|
314
|
+
wallets: buyers,
|
|
315
|
+
tokenAddress,
|
|
316
|
+
actualAmountsWei: remainingAmounts,
|
|
317
|
+
minOuts,
|
|
318
|
+
needBNB
|
|
319
|
+
}),
|
|
320
|
+
allocateProfitAwareNonces(buyers, extractProfit, maxFundsIndex, totalProfit, nonceManager)
|
|
321
|
+
]);
|
|
316
322
|
const signedTxs = await signPancakeTransactions({
|
|
317
323
|
unsignedTxs: unsignedBuys,
|
|
318
324
|
wallets: buyers,
|
|
@@ -352,16 +358,26 @@ export async function pancakeProxyBatchSellMerkle(params) {
|
|
|
352
358
|
throw new Error('Private key count and sell amount count must match');
|
|
353
359
|
}
|
|
354
360
|
const { provider, chainId } = createChainContext(chain, config.rpcUrl);
|
|
355
|
-
const gasPrice = await getOptimizedGasPrice(provider, getGasPriceConfig(config));
|
|
356
361
|
const sellers = createWallets(privateKeys, provider);
|
|
357
|
-
const
|
|
362
|
+
const finalGasLimit = getGasLimit(config);
|
|
363
|
+
const extractProfit = shouldExtractProfit(config);
|
|
364
|
+
// ✅ 优化:并行获取 gasPrice 和 tokenDecimals
|
|
365
|
+
const [gasPrice, tokenDecimals] = await Promise.all([
|
|
366
|
+
getOptimizedGasPrice(provider, getGasPriceConfig(config)),
|
|
367
|
+
getTokenDecimals(tokenAddress, provider)
|
|
368
|
+
]);
|
|
358
369
|
const amountsWei = sellAmounts.map(amount => ethers.parseUnits(amount, tokenDecimals));
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
370
|
+
// ✅ 优化:并行检查授权和获取卖出输出
|
|
371
|
+
await Promise.all([
|
|
372
|
+
ensureAllowances({
|
|
373
|
+
provider,
|
|
374
|
+
tokenAddress,
|
|
375
|
+
owners: sellers.map(w => w.address),
|
|
376
|
+
spender: ADDRESSES.BSC.PancakeProxy
|
|
377
|
+
}),
|
|
378
|
+
// 预热:提前检查 BNB 余额
|
|
379
|
+
ensureFeeBalances(provider, sellers, gasPrice, finalGasLimit, extractProfit)
|
|
380
|
+
]);
|
|
365
381
|
const { minOuts, quotedOutputs } = await resolveSellOutputs({
|
|
366
382
|
params,
|
|
367
383
|
provider,
|
|
@@ -369,22 +385,21 @@ export async function pancakeProxyBatchSellMerkle(params) {
|
|
|
369
385
|
routeType,
|
|
370
386
|
amountsWei
|
|
371
387
|
});
|
|
372
|
-
const finalGasLimit = getGasLimit(config);
|
|
373
|
-
const extractProfit = shouldExtractProfit(config);
|
|
374
|
-
// 检查 BNB 余额是否足够支付 gas 费(包括可能的利润转账 gas)
|
|
375
|
-
await ensureFeeBalances(provider, sellers, gasPrice, finalGasLimit, extractProfit);
|
|
376
388
|
const proxies = createPancakeProxies(sellers, ADDRESSES.BSC.PancakeProxy);
|
|
377
|
-
|
|
378
|
-
routeType,
|
|
379
|
-
params,
|
|
380
|
-
proxies,
|
|
381
|
-
wallets: sellers,
|
|
382
|
-
tokenAddress,
|
|
383
|
-
amountsWei,
|
|
384
|
-
minOuts
|
|
385
|
-
});
|
|
389
|
+
// ✅ 优化:并行构建交易和获取 nonces
|
|
386
390
|
const nonceManager = new NonceManager(provider);
|
|
387
|
-
const nonces = await Promise.all(
|
|
391
|
+
const [unsignedSells, nonces] = await Promise.all([
|
|
392
|
+
buildSellTransactions({
|
|
393
|
+
routeType,
|
|
394
|
+
params,
|
|
395
|
+
proxies,
|
|
396
|
+
wallets: sellers,
|
|
397
|
+
tokenAddress,
|
|
398
|
+
amountsWei,
|
|
399
|
+
minOuts
|
|
400
|
+
}),
|
|
401
|
+
Promise.all(sellers.map(wallet => nonceManager.getNextNonce(wallet)))
|
|
402
|
+
]);
|
|
388
403
|
const signedTxs = await signPancakeTransactions({
|
|
389
404
|
unsignedTxs: unsignedSells,
|
|
390
405
|
wallets: sellers,
|
|
@@ -395,7 +410,7 @@ export async function pancakeProxyBatchSellMerkle(params) {
|
|
|
395
410
|
config
|
|
396
411
|
});
|
|
397
412
|
await appendSellProfitTransfer({
|
|
398
|
-
extractProfit
|
|
413
|
+
extractProfit,
|
|
399
414
|
quotedOutputs,
|
|
400
415
|
wallets: sellers,
|
|
401
416
|
nonceManager,
|