four-flap-meme-sdk 1.2.77 → 1.2.78
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.
|
@@ -256,10 +256,13 @@ export async function batchSellWithBundleMerkle(params) {
|
|
|
256
256
|
throw new Error(getErrorMessage('SELL_KEY_AMOUNT_MISMATCH'));
|
|
257
257
|
}
|
|
258
258
|
const { provider, chainId } = createChainContext(config.rpcUrl);
|
|
259
|
-
const gasPrice = await getOptimizedGasPrice(provider, getGasPriceConfig(config));
|
|
260
|
-
const nonceManager = new NonceManager(provider);
|
|
261
|
-
const sellers = createWallets(privateKeys, provider);
|
|
262
259
|
const txType = getTxType(config);
|
|
260
|
+
const sellers = createWallets(privateKeys, provider);
|
|
261
|
+
// ✅ 优化:并行初始化 nonceManager 和获取 gasPrice
|
|
262
|
+
const [nonceManager, gasPrice] = await Promise.all([
|
|
263
|
+
Promise.resolve(new NonceManager(provider)),
|
|
264
|
+
getOptimizedGasPrice(provider, getGasPriceConfig(config))
|
|
265
|
+
]);
|
|
263
266
|
const sellFlow = await executeSellFlow({
|
|
264
267
|
wallets: sellers,
|
|
265
268
|
sellAmounts,
|
|
@@ -179,14 +179,18 @@ export async function batchSellWithBundleMerkle(params) {
|
|
|
179
179
|
throw new Error(getErrorMessage('SELL_KEY_AMOUNT_MISMATCH'));
|
|
180
180
|
}
|
|
181
181
|
const { provider, chainId } = createChainContext(chain, config.rpcUrl);
|
|
182
|
-
const gasPrice = await resolveGasPrice(provider, config);
|
|
183
182
|
const nonceManager = new NonceManager(provider);
|
|
184
183
|
const signedTxs = [];
|
|
185
184
|
const wallets = createWallets(privateKeys, provider);
|
|
186
185
|
const amountsWei = sellAmounts.map(a => ethers.parseUnits(a, 18));
|
|
187
186
|
const portalAddr = FLAP_PORTAL_ADDRESSES[chain];
|
|
188
187
|
const readOnlyPortal = new ethers.Contract(portalAddr, PORTAL_ABI, provider);
|
|
189
|
-
const
|
|
188
|
+
const gasLimits = buildGasLimitList(wallets.length, config);
|
|
189
|
+
// ✅ 优化:并行执行 gasPrice 和 quoteSellOutputs(最耗时的两个操作)
|
|
190
|
+
const [gasPrice, quotedOutputs] = await Promise.all([
|
|
191
|
+
resolveGasPrice(provider, config),
|
|
192
|
+
quoteSellOutputs(readOnlyPortal, tokenAddress, amountsWei)
|
|
193
|
+
]);
|
|
190
194
|
const minOuts = resolveMinOutputs(minOutputAmounts, wallets.length, quotedOutputs);
|
|
191
195
|
const portals = wallets.map(w => new ethers.Contract(portalAddr, PORTAL_ABI, w));
|
|
192
196
|
const unsignedList = await Promise.all(portals.map((portal, i) => portal.swapExactInput.populateTransaction({
|
|
@@ -196,7 +200,6 @@ export async function batchSellWithBundleMerkle(params) {
|
|
|
196
200
|
minOutputAmount: minOuts[i],
|
|
197
201
|
permitData: '0x'
|
|
198
202
|
})));
|
|
199
|
-
const gasLimits = buildGasLimitList(wallets.length, config);
|
|
200
203
|
const nonces = await Promise.all(wallets.map(w => nonceManager.getNextNonce(w)));
|
|
201
204
|
const signedList = await Promise.all(unsignedList.map((unsigned, i) => wallets[i].signTransaction({
|
|
202
205
|
...unsigned,
|
package/dist/utils/erc20.js
CHANGED
|
@@ -502,51 +502,56 @@ export async function approveTokenBatchRaw(params) {
|
|
|
502
502
|
// 验证地址
|
|
503
503
|
await validateContractAddress(provider, normalizedToken, 'Token');
|
|
504
504
|
await validateContractAddress(provider, normalizedSpender, 'Spender');
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
505
|
+
// ✅ 优化:批量创建钱包和合约实例
|
|
506
|
+
const wallets = privateKeys.map(key => new Wallet(key, provider));
|
|
507
|
+
const ownerAddresses = wallets.map(w => w.address);
|
|
508
|
+
const requiredAmounts = amounts.map(amount => amount === 'max'
|
|
509
|
+
? BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff')
|
|
510
|
+
: amount);
|
|
511
|
+
// ✅ 优化:并行检查所有钱包的授权额度
|
|
512
|
+
const currentAllowances = await batchCheckAllowances(provider, normalizedToken, ownerAddresses, normalizedSpender);
|
|
513
|
+
// ✅ 优化:并行发送所有需要授权的交易
|
|
514
|
+
const approvalPromises = wallets.map(async (wallet, i) => {
|
|
515
|
+
const ownerAddress = ownerAddresses[i];
|
|
516
|
+
const currentAllowance = currentAllowances[i];
|
|
517
|
+
const requiredAmount = requiredAmounts[i];
|
|
514
518
|
try {
|
|
515
|
-
|
|
516
|
-
// 检查当前授权
|
|
517
|
-
const currentAllowance = await erc20.allowance(ownerAddress, normalizedSpender);
|
|
519
|
+
// 如果已经授权足够,跳过
|
|
518
520
|
if (currentAllowance >= requiredAmount) {
|
|
519
|
-
|
|
521
|
+
return {
|
|
520
522
|
owner: ownerAddress,
|
|
521
523
|
alreadyApproved: true,
|
|
522
524
|
currentAllowance,
|
|
523
525
|
requiredAllowance: requiredAmount
|
|
524
|
-
}
|
|
525
|
-
continue;
|
|
526
|
+
};
|
|
526
527
|
}
|
|
527
528
|
// 发送授权交易
|
|
529
|
+
const erc20 = new Contract(normalizedToken, ERC20_ABI, wallet);
|
|
528
530
|
const tx = await erc20.approve(normalizedSpender, requiredAmount);
|
|
529
531
|
const receipt = await tx.wait();
|
|
530
|
-
|
|
532
|
+
return {
|
|
531
533
|
owner: ownerAddress,
|
|
532
534
|
alreadyApproved: false,
|
|
533
535
|
currentAllowance,
|
|
534
536
|
requiredAllowance: requiredAmount,
|
|
535
537
|
txHash: receipt.hash
|
|
536
|
-
}
|
|
537
|
-
approvedCount++;
|
|
538
|
+
};
|
|
538
539
|
}
|
|
539
540
|
catch (error) {
|
|
540
|
-
|
|
541
|
+
return {
|
|
541
542
|
owner: ownerAddress,
|
|
542
543
|
alreadyApproved: false,
|
|
543
|
-
currentAllowance
|
|
544
|
+
currentAllowance,
|
|
544
545
|
requiredAllowance: requiredAmount,
|
|
545
546
|
error: error.message
|
|
546
|
-
}
|
|
547
|
-
errorCount++;
|
|
547
|
+
};
|
|
548
548
|
}
|
|
549
|
-
}
|
|
549
|
+
});
|
|
550
|
+
// ✅ 优化:并行等待所有授权交易完成
|
|
551
|
+
const results = await Promise.all(approvalPromises);
|
|
552
|
+
// 统计结果
|
|
553
|
+
const approvedCount = results.filter(r => !r.alreadyApproved && !r.error).length;
|
|
554
|
+
const errorCount = results.filter(r => r.error).length;
|
|
550
555
|
// ✅ 只要没有错误,就算成功(包括所有钱包都已授权的情况)
|
|
551
556
|
return {
|
|
552
557
|
success: errorCount === 0,
|