four-flap-meme-sdk 1.6.40 → 1.6.41

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.
@@ -688,9 +688,12 @@ export class AADexSwapExecutor {
688
688
  if (prefundedHopWallets.length < totalHopsNeeded) {
689
689
  throw new Error(`预充值 hop 钱包数量不足: 需要 ${totalHopsNeeded} 个,实际 ${prefundedHopWallets.length} 个`);
690
690
  }
691
- // ✅ 关键修复:从链上获取所有 hop 钱包的真实 nonce(用户可能重复使用同一批 hop 钱包)
691
+ // ✅ 关键修复:从链上获取所有 hop 钱包的真实 nonce 和部署状态
692
692
  const hopSenders = prefundedHopWallets.slice(0, totalHopsNeeded).map(h => h.senderAddress);
693
693
  const hopNonces = await this.aaManager.batchGetNonces(hopSenders);
694
+ // ✅ 直接检查链上 code 判断是否已部署(比 nonce 更可靠)
695
+ const hopCodes = await Promise.all(hopSenders.map(s => provider.getCode(s)));
696
+ const hopDeployed = hopCodes.map(code => code !== null && code !== '0x' && code.length > 2);
694
697
  // ✅ 检查 hop 钱包余额是否足够(之前的失败交易可能已消耗 prefund)
695
698
  const hopBalances = await Promise.all(hopSenders.map(s => provider.getBalance(s)));
696
699
  const minPrefundNeeded = estimatePrefund(HOP_CALL_GAS_LIMIT, true); // 已部署钱包的 prefund
@@ -704,17 +707,25 @@ export class AADexSwapExecutor {
704
707
  console.error('[AA DEX 多跳] ❌ 以下 hop 钱包余额不足:', insufficientHops);
705
708
  throw new Error(`Hop 钱包余额不足(可能之前交易失败消耗了 prefund),请点击"退回资金"后重新预充值。不足的钱包: ${insufficientHops.length} 个`);
706
709
  }
710
+ // 打印调试信息
711
+ console.log('[AA DEX 多跳] Hop 钱包状态:', hopSenders.map((s, i) => ({
712
+ sender: s,
713
+ nonce: hopNonces[i]?.toString(),
714
+ deployed: hopDeployed[i],
715
+ balance: ethers.formatEther(hopBalances[i]),
716
+ })));
707
717
  let hopIdx = 0;
708
718
  for (let buyerIdx = 0; buyerIdx < buyerSenders.length; buyerIdx++) {
709
719
  const chainHops = [];
710
720
  for (let h = 0; h < effectiveHopCount; h++) {
711
721
  const prefundedHop = prefundedHopWallets[hopIdx];
712
722
  const wallet = new ethers.Wallet(prefundedHop.privateKey, provider);
713
- // ✅ 关键修复:根据真实 nonce 判断是否已部署
714
- // 如果 nonce > 0,说明钱包已经被使用过,肯定已部署,initCode 必须为 '0x'
723
+ // ✅ 关键修复:直接检查链上 code 判断是否已部署
715
724
  const realNonce = hopNonces[hopIdx] ?? 0n;
716
- const isDeployed = realNonce > 0n || prefundedHop.deployed;
725
+ const isDeployedOnChain = hopDeployed[hopIdx] ?? false;
726
+ const isDeployed = realNonce > 0n || isDeployedOnChain || prefundedHop.deployed;
717
727
  const effectiveInitCode = isDeployed ? '0x' : prefundedHop.initCode;
728
+ console.log(`[AA DEX 多跳] Hop ${hopIdx}: sender=${prefundedHop.senderAddress}, nonce=${realNonce}, deployedOnChain=${isDeployedOnChain}, finalDeployed=${isDeployed}, initCode=${effectiveInitCode === '0x' ? '0x' : 'has-initCode'}`);
718
729
  chainHops.push({
719
730
  wallet,
720
731
  sender: prefundedHop.senderAddress,
@@ -329,20 +329,31 @@ export class HopWalletManager {
329
329
  // 构建所有退款 UserOps
330
330
  const userOps = [];
331
331
  const hopWalletsToRefund = [];
332
- // ✅ 关键修复:从链上批量获取所有 hop 钱包的真实 nonce
332
+ // ✅ 关键修复:从链上批量获取所有 hop 钱包的真实 nonce 和部署状态
333
333
  const hopSenders = hopWallets.map(h => h.senderAddress);
334
334
  const hopNonces = await this.aaManager.batchGetNonces(hopSenders);
335
+ // ✅ 直接检查链上 code 判断是否已部署
336
+ const hopCodes = await Promise.all(hopSenders.map(s => this.provider.getCode(s)));
337
+ const hopDeployedOnChain = hopCodes.map(code => code !== null && code !== '0x' && code.length > 2);
338
+ // ✅ 批量获取余额
339
+ const hopBalances = await Promise.all(hopSenders.map(s => this.provider.getBalance(s)));
340
+ console.log('[HopWalletManager] 退款前 Hop 钱包状态:', hopSenders.map((s, i) => ({
341
+ sender: s,
342
+ nonce: hopNonces[i]?.toString(),
343
+ deployed: hopDeployedOnChain[i],
344
+ balance: ethers.formatEther(hopBalances[i]),
345
+ })));
335
346
  for (let i = 0; i < hopWallets.length; i++) {
336
347
  const hop = hopWallets[i];
337
348
  try {
338
- const balance = await this.provider.getBalance(hop.senderAddress);
349
+ const balance = hopBalances[i];
339
350
  // 估算 UserOp 执行需要的 gas
340
351
  const estimatedGas = 150000n * gasPrice;
341
352
  if (balance <= estimatedGas) {
342
353
  hopRefunds.push({
343
354
  hopIndex: hop.index,
344
355
  refundWei: 0n,
345
- error: '余额不足',
356
+ error: `余额不足 (${ethers.formatEther(balance)} OKB)`,
346
357
  });
347
358
  continue;
348
359
  }
@@ -351,9 +362,11 @@ export class HopWalletManager {
351
362
  const hopWallet = new Wallet(hop.privateKey, this.provider);
352
363
  // ✅ 使用从链上获取的真实 nonce
353
364
  const realNonce = hopNonces[i] ?? 0n;
354
- // ✅ 检查 hop 钱包是否已部署(根据 nonce 判断,nonce > 0 说明已用过,肯定已部署)
355
- const isDeployed = realNonce > 0n || hop.deployed;
365
+ // ✅ 三重检查是否已部署:nonce > 0 OR 链上有 code OR 预充值时记录为已部署
366
+ const isDeployedOnChain = hopDeployedOnChain[i] ?? false;
367
+ const isDeployed = realNonce > 0n || isDeployedOnChain || hop.deployed;
356
368
  const initCode = isDeployed ? '0x' : hop.initCode;
369
+ console.log(`[HopWalletManager] 退款 Hop ${i}: sender=${hop.senderAddress}, nonce=${realNonce}, deployedOnChain=${isDeployedOnChain}, finalDeployed=${isDeployed}, refundAmount=${ethers.formatEther(refundAmount)} OKB`);
357
370
  const { userOp } = await this.aaManager.buildUserOpWithFixedGas({
358
371
  ownerWallet: hopWallet,
359
372
  sender: hop.senderAddress,
@@ -373,6 +386,7 @@ export class HopWalletManager {
373
386
  });
374
387
  }
375
388
  catch (error) {
389
+ console.error(`[HopWalletManager] 退款 Hop ${i} 失败:`, error);
376
390
  hopRefunds.push({
377
391
  hopIndex: hop.index,
378
392
  refundWei: 0n,
@@ -495,9 +495,12 @@ export class AAPortalSwapExecutor {
495
495
  if (prefundedHopWallets.length < totalHopsNeeded) {
496
496
  throw new Error(`预充值 hop 钱包数量不足: 需要 ${totalHopsNeeded} 个,实际 ${prefundedHopWallets.length} 个`);
497
497
  }
498
- // ✅ 关键修复:从链上获取所有 hop 钱包的真实 nonce(用户可能重复使用同一批 hop 钱包)
498
+ // ✅ 关键修复:从链上获取所有 hop 钱包的真实 nonce 和部署状态
499
499
  const hopSenders = prefundedHopWallets.slice(0, totalHopsNeeded).map(h => h.senderAddress);
500
500
  const hopNonces = await this.aaManager.batchGetNonces(hopSenders);
501
+ // ✅ 直接检查链上 code 判断是否已部署(比 nonce 更可靠)
502
+ const hopCodes = await Promise.all(hopSenders.map(s => provider.getCode(s)));
503
+ const hopDeployed = hopCodes.map(code => code !== null && code !== '0x' && code.length > 2);
501
504
  // ✅ 检查 hop 钱包余额是否足够(之前的失败交易可能已消耗 prefund)
502
505
  const hopBalances = await Promise.all(hopSenders.map(s => provider.getBalance(s)));
503
506
  // 预估已部署钱包的最小 prefund
@@ -512,17 +515,25 @@ export class AAPortalSwapExecutor {
512
515
  console.error('[AA Portal 多跳] ❌ 以下 hop 钱包余额不足:', insufficientHops);
513
516
  throw new Error(`Hop 钱包余额不足(可能之前交易失败消耗了 prefund),请点击"退回资金"后重新预充值。不足的钱包: ${insufficientHops.length} 个`);
514
517
  }
518
+ // 打印调试信息
519
+ console.log('[AA Portal 多跳] Hop 钱包状态:', hopSenders.map((s, i) => ({
520
+ sender: s,
521
+ nonce: hopNonces[i]?.toString(),
522
+ deployed: hopDeployed[i],
523
+ balance: ethers.formatEther(hopBalances[i]),
524
+ })));
515
525
  let hopIdx = 0;
516
526
  for (let buyerIdx = 0; buyerIdx < buyerSenders.length; buyerIdx++) {
517
527
  const chainHops = [];
518
528
  for (let h = 0; h < effectiveHopCount; h++) {
519
529
  const prefundedHop = prefundedHopWallets[hopIdx];
520
530
  const wallet = new ethers.Wallet(prefundedHop.privateKey, provider);
521
- // ✅ 关键修复:根据真实 nonce 判断是否已部署
522
- // 如果 nonce > 0,说明钱包已经被使用过,肯定已部署,initCode 必须为 '0x'
531
+ // ✅ 关键修复:直接检查链上 code 判断是否已部署
523
532
  const realNonce = hopNonces[hopIdx] ?? 0n;
524
- const isDeployed = realNonce > 0n || prefundedHop.deployed;
533
+ const isDeployedOnChain = hopDeployed[hopIdx] ?? false;
534
+ const isDeployed = realNonce > 0n || isDeployedOnChain || prefundedHop.deployed;
525
535
  const effectiveInitCode = isDeployed ? '0x' : prefundedHop.initCode;
536
+ console.log(`[AA Portal 多跳] Hop ${hopIdx}: sender=${prefundedHop.senderAddress}, nonce=${realNonce}, deployedOnChain=${isDeployedOnChain}, finalDeployed=${isDeployed}, initCode=${effectiveInitCode === '0x' ? '0x' : 'has-initCode'}`);
526
537
  chainHops.push({
527
538
  wallet,
528
539
  sender: prefundedHop.senderAddress,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.6.40",
3
+ "version": "1.6.41",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",