four-flap-meme-sdk 1.6.38 → 1.6.40
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.
|
@@ -691,20 +691,36 @@ export class AADexSwapExecutor {
|
|
|
691
691
|
// ✅ 关键修复:从链上获取所有 hop 钱包的真实 nonce(用户可能重复使用同一批 hop 钱包)
|
|
692
692
|
const hopSenders = prefundedHopWallets.slice(0, totalHopsNeeded).map(h => h.senderAddress);
|
|
693
693
|
const hopNonces = await this.aaManager.batchGetNonces(hopSenders);
|
|
694
|
+
// ✅ 检查 hop 钱包余额是否足够(之前的失败交易可能已消耗 prefund)
|
|
695
|
+
const hopBalances = await Promise.all(hopSenders.map(s => provider.getBalance(s)));
|
|
696
|
+
const minPrefundNeeded = estimatePrefund(HOP_CALL_GAS_LIMIT, true); // 已部署钱包的 prefund
|
|
697
|
+
const insufficientHops = [];
|
|
698
|
+
for (let i = 0; i < hopSenders.length; i++) {
|
|
699
|
+
if (hopBalances[i] < minPrefundNeeded) {
|
|
700
|
+
insufficientHops.push(`${hopSenders[i]} (余额: ${ethers.formatEther(hopBalances[i])} OKB, 需要: ${ethers.formatEther(minPrefundNeeded)} OKB)`);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
if (insufficientHops.length > 0) {
|
|
704
|
+
console.error('[AA DEX 多跳] ❌ 以下 hop 钱包余额不足:', insufficientHops);
|
|
705
|
+
throw new Error(`Hop 钱包余额不足(可能之前交易失败消耗了 prefund),请点击"退回资金"后重新预充值。不足的钱包: ${insufficientHops.length} 个`);
|
|
706
|
+
}
|
|
694
707
|
let hopIdx = 0;
|
|
695
708
|
for (let buyerIdx = 0; buyerIdx < buyerSenders.length; buyerIdx++) {
|
|
696
709
|
const chainHops = [];
|
|
697
710
|
for (let h = 0; h < effectiveHopCount; h++) {
|
|
698
711
|
const prefundedHop = prefundedHopWallets[hopIdx];
|
|
699
712
|
const wallet = new ethers.Wallet(prefundedHop.privateKey, provider);
|
|
713
|
+
// ✅ 关键修复:根据真实 nonce 判断是否已部署
|
|
714
|
+
// 如果 nonce > 0,说明钱包已经被使用过,肯定已部署,initCode 必须为 '0x'
|
|
715
|
+
const realNonce = hopNonces[hopIdx] ?? 0n;
|
|
716
|
+
const isDeployed = realNonce > 0n || prefundedHop.deployed;
|
|
717
|
+
const effectiveInitCode = isDeployed ? '0x' : prefundedHop.initCode;
|
|
700
718
|
chainHops.push({
|
|
701
719
|
wallet,
|
|
702
720
|
sender: prefundedHop.senderAddress,
|
|
703
|
-
deployed:
|
|
704
|
-
initCode:
|
|
721
|
+
deployed: isDeployed,
|
|
722
|
+
initCode: effectiveInitCode,
|
|
705
723
|
});
|
|
706
|
-
// ✅ 使用从链上获取的真实 nonce(而非硬编码 0)
|
|
707
|
-
const realNonce = hopNonces[hopIdx] ?? 0n;
|
|
708
724
|
nonceMap.init(prefundedHop.senderAddress, realNonce);
|
|
709
725
|
hopIdx++;
|
|
710
726
|
}
|
|
@@ -498,20 +498,37 @@ export class AAPortalSwapExecutor {
|
|
|
498
498
|
// ✅ 关键修复:从链上获取所有 hop 钱包的真实 nonce(用户可能重复使用同一批 hop 钱包)
|
|
499
499
|
const hopSenders = prefundedHopWallets.slice(0, totalHopsNeeded).map(h => h.senderAddress);
|
|
500
500
|
const hopNonces = await this.aaManager.batchGetNonces(hopSenders);
|
|
501
|
+
// ✅ 检查 hop 钱包余额是否足够(之前的失败交易可能已消耗 prefund)
|
|
502
|
+
const hopBalances = await Promise.all(hopSenders.map(s => provider.getBalance(s)));
|
|
503
|
+
// 预估已部署钱包的最小 prefund
|
|
504
|
+
const minPrefundNeeded = (HOP_CALL_GAS_LIMIT + VERIFICATION_GAS_LIMIT_NORMAL + PRE_VERIFICATION_GAS) * gasPrice * PREFUND_BUFFER_PERCENT / 100n;
|
|
505
|
+
const insufficientHops = [];
|
|
506
|
+
for (let i = 0; i < hopSenders.length; i++) {
|
|
507
|
+
if (hopBalances[i] < minPrefundNeeded) {
|
|
508
|
+
insufficientHops.push(`${hopSenders[i]} (余额: ${ethers.formatEther(hopBalances[i])} OKB, 需要: ${ethers.formatEther(minPrefundNeeded)} OKB)`);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
if (insufficientHops.length > 0) {
|
|
512
|
+
console.error('[AA Portal 多跳] ❌ 以下 hop 钱包余额不足:', insufficientHops);
|
|
513
|
+
throw new Error(`Hop 钱包余额不足(可能之前交易失败消耗了 prefund),请点击"退回资金"后重新预充值。不足的钱包: ${insufficientHops.length} 个`);
|
|
514
|
+
}
|
|
501
515
|
let hopIdx = 0;
|
|
502
516
|
for (let buyerIdx = 0; buyerIdx < buyerSenders.length; buyerIdx++) {
|
|
503
517
|
const chainHops = [];
|
|
504
518
|
for (let h = 0; h < effectiveHopCount; h++) {
|
|
505
519
|
const prefundedHop = prefundedHopWallets[hopIdx];
|
|
506
520
|
const wallet = new ethers.Wallet(prefundedHop.privateKey, provider);
|
|
521
|
+
// ✅ 关键修复:根据真实 nonce 判断是否已部署
|
|
522
|
+
// 如果 nonce > 0,说明钱包已经被使用过,肯定已部署,initCode 必须为 '0x'
|
|
523
|
+
const realNonce = hopNonces[hopIdx] ?? 0n;
|
|
524
|
+
const isDeployed = realNonce > 0n || prefundedHop.deployed;
|
|
525
|
+
const effectiveInitCode = isDeployed ? '0x' : prefundedHop.initCode;
|
|
507
526
|
chainHops.push({
|
|
508
527
|
wallet,
|
|
509
528
|
sender: prefundedHop.senderAddress,
|
|
510
|
-
deployed:
|
|
511
|
-
initCode:
|
|
529
|
+
deployed: isDeployed,
|
|
530
|
+
initCode: effectiveInitCode,
|
|
512
531
|
});
|
|
513
|
-
// ✅ 使用从链上获取的真实 nonce(而非硬编码 0)
|
|
514
|
-
const realNonce = hopNonces[hopIdx] ?? 0n;
|
|
515
532
|
nonceMap.init(prefundedHop.senderAddress, realNonce);
|
|
516
533
|
hopIdx++;
|
|
517
534
|
}
|