four-flap-meme-sdk 1.6.41 → 1.6.43

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.
@@ -696,11 +696,15 @@ export class AADexSwapExecutor {
696
696
  const hopDeployed = hopCodes.map(code => code !== null && code !== '0x' && code.length > 2);
697
697
  // ✅ 检查 hop 钱包余额是否足够(之前的失败交易可能已消耗 prefund)
698
698
  const hopBalances = await Promise.all(hopSenders.map(s => provider.getBalance(s)));
699
- const minPrefundNeeded = estimatePrefund(HOP_CALL_GAS_LIMIT, true); // 已部署钱包的 prefund
699
+ // 关键修复:使用每个 hop 的实际部署状态来估算 minPrefund
700
+ // 未部署钱包需要 VERIFICATION_GAS_LIMIT_DEPLOY (800,000)
701
+ // 已部署钱包只需要 VERIFICATION_GAS_LIMIT_NORMAL (250,000)
700
702
  const insufficientHops = [];
701
703
  for (let i = 0; i < hopSenders.length; i++) {
704
+ const isDeployed = hopDeployed[i] ?? false;
705
+ const minPrefundNeeded = estimatePrefund(HOP_CALL_GAS_LIMIT, isDeployed);
702
706
  if (hopBalances[i] < minPrefundNeeded) {
703
- insufficientHops.push(`${hopSenders[i]} (余额: ${ethers.formatEther(hopBalances[i])} OKB, 需要: ${ethers.formatEther(minPrefundNeeded)} OKB)`);
707
+ insufficientHops.push(`${hopSenders[i]} (余额: ${ethers.formatEther(hopBalances[i])} OKB, 需要: ${ethers.formatEther(minPrefundNeeded)} OKB, 已部署: ${isDeployed})`);
704
708
  }
705
709
  }
706
710
  if (insufficientHops.length > 0) {
@@ -828,14 +832,21 @@ export class AADexSwapExecutor {
828
832
  const transferData = erc20Iface.encodeFunctionData('transfer', [nextHop.sender, buyAmount]);
829
833
  callData = encodeExecute(quoteToken, 0n, transferData);
830
834
  }
831
- const signedHop = await this.aaManager.buildUserOpWithState({
835
+ // 关键修复:使用 buildUserOpWithFixedGas,确保 callGasLimit 与预充值时一致
836
+ // 预充值时使用 HOP_CALL_GAS_LIMIT (150,000),这里也必须使用相同的值
837
+ // 否则 buildUserOpWithState 会动态估算,可能得到 500,000,导致 prefund 不足
838
+ const { userOp: hopUserOp } = await this.aaManager.buildUserOpWithFixedGas({
832
839
  ownerWallet: currentHop.wallet,
833
840
  sender: currentHop.sender,
834
841
  nonce: nonceMap.next(currentHop.sender),
835
842
  initCode: currentHop.initCode,
836
843
  callData,
837
- signOnly: true,
844
+ deployed: currentHop.deployed,
845
+ fixedGas: {
846
+ callGasLimit: HOP_CALL_GAS_LIMIT,
847
+ },
838
848
  });
849
+ const signedHop = await this.aaManager.signUserOp(hopUserOp, currentHop.wallet);
839
850
  outOps.push(signedHop.userOp);
840
851
  }
841
852
  // 3) lastHop → buyer
@@ -849,14 +860,19 @@ export class AADexSwapExecutor {
849
860
  const transferData = erc20Iface.encodeFunctionData('transfer', [buyerSender, buyAmount]);
850
861
  callDataLast = encodeExecute(quoteToken, 0n, transferData);
851
862
  }
852
- const signedLastHop = await this.aaManager.buildUserOpWithState({
863
+ // 关键修复:同样使用 buildUserOpWithFixedGas
864
+ const { userOp: lastHopUserOp } = await this.aaManager.buildUserOpWithFixedGas({
853
865
  ownerWallet: lastHop.wallet,
854
866
  sender: lastHop.sender,
855
867
  nonce: nonceMap.next(lastHop.sender),
856
868
  initCode: lastHop.initCode,
857
869
  callData: callDataLast,
858
- signOnly: true,
870
+ deployed: lastHop.deployed,
871
+ fixedGas: {
872
+ callGasLimit: HOP_CALL_GAS_LIMIT,
873
+ },
859
874
  });
875
+ const signedLastHop = await this.aaManager.signUserOp(lastHopUserOp, lastHop.wallet);
860
876
  outOps.push(signedLastHop.userOp);
861
877
  }
862
878
  // ✅ 保存所有动态生成的多跳钱包信息,用于后续导出
@@ -503,12 +503,16 @@ export class AAPortalSwapExecutor {
503
503
  const hopDeployed = hopCodes.map(code => code !== null && code !== '0x' && code.length > 2);
504
504
  // ✅ 检查 hop 钱包余额是否足够(之前的失败交易可能已消耗 prefund)
505
505
  const hopBalances = await Promise.all(hopSenders.map(s => provider.getBalance(s)));
506
- // 预估已部署钱包的最小 prefund
507
- const minPrefundNeeded = (HOP_CALL_GAS_LIMIT + VERIFICATION_GAS_LIMIT_NORMAL + PRE_VERIFICATION_GAS) * gasPrice * PREFUND_BUFFER_PERCENT / 100n;
506
+ // 关键修复:使用每个 hop 的实际部署状态来估算 minPrefund
507
+ // 未部署钱包需要 VERIFICATION_GAS_LIMIT_DEPLOY (800,000)
508
+ // 已部署钱包只需要 VERIFICATION_GAS_LIMIT_NORMAL (250,000)
508
509
  const insufficientHops = [];
509
510
  for (let i = 0; i < hopSenders.length; i++) {
511
+ const isDeployed = hopDeployed[i] ?? false;
512
+ const verifyGas = isDeployed ? VERIFICATION_GAS_LIMIT_NORMAL : VERIFICATION_GAS_LIMIT_DEPLOY;
513
+ const minPrefundNeeded = (HOP_CALL_GAS_LIMIT + verifyGas + PRE_VERIFICATION_GAS) * gasPrice * PREFUND_BUFFER_PERCENT / 100n;
510
514
  if (hopBalances[i] < minPrefundNeeded) {
511
- insufficientHops.push(`${hopSenders[i]} (余额: ${ethers.formatEther(hopBalances[i])} OKB, 需要: ${ethers.formatEther(minPrefundNeeded)} OKB)`);
515
+ insufficientHops.push(`${hopSenders[i]} (余额: ${ethers.formatEther(hopBalances[i])} OKB, 需要: ${ethers.formatEther(minPrefundNeeded)} OKB, 已部署: ${isDeployed})`);
512
516
  }
513
517
  }
514
518
  if (insufficientHops.length > 0) {
@@ -639,14 +643,21 @@ export class AAPortalSwapExecutor {
639
643
  const transferData = erc20Iface.encodeFunctionData('transfer', [nextHop.sender, buyAmount]);
640
644
  callData = encodeExecute(quoteToken, 0n, transferData);
641
645
  }
642
- const signedHop = await this.aaManager.buildUserOpWithState({
646
+ // 关键修复:使用 buildUserOpWithFixedGas,确保 callGasLimit 与预充值时一致
647
+ // 预充值时使用 HOP_CALL_GAS_LIMIT (150,000),这里也必须使用相同的值
648
+ // 否则 buildUserOpWithState 会动态估算,可能得到 500,000,导致 prefund 不足
649
+ const { userOp: hopUserOp } = await this.aaManager.buildUserOpWithFixedGas({
643
650
  ownerWallet: currentHop.wallet,
644
651
  sender: currentHop.sender,
645
652
  nonce: nonceMap.next(currentHop.sender),
646
653
  initCode: currentHop.initCode,
647
654
  callData,
648
- signOnly: true,
655
+ deployed: currentHop.deployed,
656
+ fixedGas: {
657
+ callGasLimit: HOP_CALL_GAS_LIMIT,
658
+ },
649
659
  });
660
+ const signedHop = await this.aaManager.signUserOp(hopUserOp, currentHop.wallet);
650
661
  outOps.push(signedHop.userOp);
651
662
  }
652
663
  // 3) lastHop → buyer
@@ -660,14 +671,19 @@ export class AAPortalSwapExecutor {
660
671
  const transferData = erc20Iface.encodeFunctionData('transfer', [buyerSender, buyAmount]);
661
672
  callDataLast = encodeExecute(quoteToken, 0n, transferData);
662
673
  }
663
- const signedLastHop = await this.aaManager.buildUserOpWithState({
674
+ // 关键修复:同样使用 buildUserOpWithFixedGas
675
+ const { userOp: lastHopUserOp } = await this.aaManager.buildUserOpWithFixedGas({
664
676
  ownerWallet: lastHop.wallet,
665
677
  sender: lastHop.sender,
666
678
  nonce: nonceMap.next(lastHop.sender),
667
679
  initCode: lastHop.initCode,
668
680
  callData: callDataLast,
669
- signOnly: true,
681
+ deployed: lastHop.deployed,
682
+ fixedGas: {
683
+ callGasLimit: HOP_CALL_GAS_LIMIT,
684
+ },
670
685
  });
686
+ const signedLastHop = await this.aaManager.signUserOp(lastHopUserOp, lastHop.wallet);
671
687
  outOps.push(signedLastHop.userOp);
672
688
  }
673
689
  // ✅ 保存所有动态生成的多跳钱包信息,用于后续导出
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.6.41",
3
+ "version": "1.6.43",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",