four-flap-meme-sdk 1.5.95 → 1.5.96

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.
@@ -1418,28 +1418,58 @@ export class BundleExecutor {
1418
1418
  }
1419
1419
  }
1420
1420
  const provider = this.aaManager.getProvider();
1421
- const startNonce = params.payerStartNonce ?? await provider.getTransactionCount(payer.address, 'pending');
1421
+ let currentNonce = params.payerStartNonce ?? await provider.getTransactionCount(payer.address, 'pending');
1422
1422
  const signedTransactions = [];
1423
1423
  const feeData = await provider.getFeeData();
1424
1424
  const gasPrice = feeData.gasPrice ?? 100000000n;
1425
1425
  const chainId = (await provider.getNetwork()).chainId;
1426
+ // === 0. 向买家 AA 账户转入 OKB(prefund + 买入金额)===
1427
+ // ✅ 修复 AA21 didn't pay prefund 错误:确保每个买家的 AA 账户有足够的 OKB
1428
+ const DEFAULT_PREFUND_ESTIMATE = parseOkb('0.002'); // 预估每个 UserOp 的 prefund (gas 费用)
1429
+ const BUFFER_WEI = parseOkb('0.0005'); // 缓冲金额
1430
+ for (let i = 0; i < buyerWallets.length; i++) {
1431
+ const buyerSender = buyerSenders[i];
1432
+ const buyWei = buyerData[i].buyWei;
1433
+ // 计算需要转入的金额:买入金额 + prefund + 缓冲
1434
+ const requiredAmount = useNativeToken
1435
+ ? buyWei + DEFAULT_PREFUND_ESTIMATE + BUFFER_WEI // 原生代币:需要买入金额 + gas
1436
+ : DEFAULT_PREFUND_ESTIMATE + BUFFER_WEI; // ERC20 代币:只需要 gas
1437
+ // 检查买家 AA 账户当前余额
1438
+ const currentBalance = await provider.getBalance(buyerSender);
1439
+ if (currentBalance < requiredAmount) {
1440
+ const transferAmount = requiredAmount - currentBalance;
1441
+ console.log(`[买家${i + 1}] 向 AA 账户 ${buyerSender} 转入 ${formatOkb(transferAmount)} OKB`);
1442
+ const fundTxRequest = {
1443
+ to: buyerSender,
1444
+ value: transferAmount,
1445
+ nonce: currentNonce,
1446
+ gasLimit: 21000n,
1447
+ gasPrice,
1448
+ chainId
1449
+ };
1450
+ const signedFundTx = await payer.signTransaction(fundTxRequest);
1451
+ signedTransactions.push(signedFundTx);
1452
+ currentNonce++;
1453
+ }
1454
+ }
1426
1455
  // === 1. AA handleOps 交易(包含所有 UserOps:创建 + 买入)===
1427
1456
  const signedMainTx = await this.signHandleOpsTx({
1428
1457
  ops,
1429
1458
  payerWallet: payer,
1430
1459
  beneficiary: useBeneficiary,
1431
- nonce: startNonce,
1460
+ nonce: currentNonce,
1432
1461
  gasLimit: effConfig.gasLimit,
1433
1462
  gasPrice: effConfig.minGasPriceGwei ? ethers.parseUnits(effConfig.minGasPriceGwei.toString(), 'gwei') : undefined
1434
1463
  });
1435
1464
  signedTransactions.push(signedMainTx);
1465
+ currentNonce++;
1436
1466
  // === 2. 利润提取交易(独立的 EOA 转账)===
1437
1467
  if (nativeProfitAmount > 0n) {
1438
1468
  console.log(`[利润提取-签名] 非 AA 转账: ${useNativeToken ? formatOkb(nativeProfitAmount) : `${formatOkb(totalBuyProfitWei)} (ERC20) -> ${formatOkb(nativeProfitAmount)} (OKB)`} -> ${profitSettings.profitRecipient}`);
1439
1469
  const profitTxRequest = {
1440
1470
  to: profitSettings.profitRecipient,
1441
1471
  value: nativeProfitAmount,
1442
- nonce: startNonce + 1,
1472
+ nonce: currentNonce,
1443
1473
  gasLimit: 21000n,
1444
1474
  gasPrice,
1445
1475
  chainId
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.5.95",
3
+ "version": "1.5.96",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",