four-flap-meme-sdk 1.5.94 → 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.
@@ -73,7 +73,6 @@ class AANonceMap {
73
73
  // 固定 gas(用于大规模减少 RPC);具体值允许通过 config.fixedGas 覆盖
74
74
  const DEFAULT_CALL_GAS_LIMIT_BUY = DEFAULT_CALL_GAS_LIMIT_SELL; // buy 与 sell 共享一个保守值
75
75
  const DEFAULT_CALL_GAS_LIMIT_APPROVE = 200000n;
76
- const DEFAULT_CALL_GAS_LIMIT_TRANSFER = 150000n;
77
76
  const DEFAULT_CALL_GAS_LIMIT_WITHDRAW = 120000n;
78
77
  function resolveProfitSettings(config) {
79
78
  const extractProfit = config?.extractProfit !== false; // 默认 true
@@ -1350,17 +1349,31 @@ export class BundleExecutor {
1350
1349
  const totalBuyWei = buyerData.reduce((sum, d) => sum + d.buyWei, 0n);
1351
1350
  const totalBuyProfitWei = buyerData.reduce((sum, d) => sum + d.profitWei, 0n);
1352
1351
  // ✅ 并行构建和签名所有买家的 UserOps
1352
+ // ✅ V3/V4 代币使用 swapExactInputV3(支持 extensionData),与 bundleGraduateBuy 保持一致
1353
+ const extensionData = params.extensionData ?? '0x';
1353
1354
  const signedBuyOps = await mapWithConcurrency(buyerData, 5, async (data) => {
1354
1355
  const { buyer, buyWei, accountInfo } = data;
1355
- const swapData = portalIface.encodeFunctionData('swapExactInput', [
1356
- {
1357
- inputToken,
1358
- outputToken: tokenAddress,
1359
- inputAmount: buyWei,
1360
- minOutputAmount: 0n,
1361
- permitData: '0x',
1362
- },
1363
- ]);
1356
+ // V3/V4 代币使用 swapExactInputV3,否则使用旧版 swapExactInput
1357
+ const swapData = (useV3 || useV4)
1358
+ ? portalIface.encodeFunctionData('swapExactInputV3', [
1359
+ {
1360
+ inputToken,
1361
+ outputToken: tokenAddress,
1362
+ inputAmount: buyWei,
1363
+ minOutputAmount: 0n,
1364
+ permitData: '0x',
1365
+ extensionData,
1366
+ },
1367
+ ])
1368
+ : portalIface.encodeFunctionData('swapExactInput', [
1369
+ {
1370
+ inputToken,
1371
+ outputToken: tokenAddress,
1372
+ inputAmount: buyWei,
1373
+ minOutputAmount: 0n,
1374
+ permitData: '0x',
1375
+ },
1376
+ ]);
1364
1377
  // ✅ ERC20 代币需要先 approve,使用 executeBatch 将 approve + swap 合并为一个 UserOp
1365
1378
  let buyCallData;
1366
1379
  if (useNativeToken) {
@@ -1405,28 +1418,58 @@ export class BundleExecutor {
1405
1418
  }
1406
1419
  }
1407
1420
  const provider = this.aaManager.getProvider();
1408
- const startNonce = params.payerStartNonce ?? await provider.getTransactionCount(payer.address, 'pending');
1421
+ let currentNonce = params.payerStartNonce ?? await provider.getTransactionCount(payer.address, 'pending');
1409
1422
  const signedTransactions = [];
1410
1423
  const feeData = await provider.getFeeData();
1411
1424
  const gasPrice = feeData.gasPrice ?? 100000000n;
1412
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
+ }
1413
1455
  // === 1. AA handleOps 交易(包含所有 UserOps:创建 + 买入)===
1414
1456
  const signedMainTx = await this.signHandleOpsTx({
1415
1457
  ops,
1416
1458
  payerWallet: payer,
1417
1459
  beneficiary: useBeneficiary,
1418
- nonce: startNonce,
1460
+ nonce: currentNonce,
1419
1461
  gasLimit: effConfig.gasLimit,
1420
1462
  gasPrice: effConfig.minGasPriceGwei ? ethers.parseUnits(effConfig.minGasPriceGwei.toString(), 'gwei') : undefined
1421
1463
  });
1422
1464
  signedTransactions.push(signedMainTx);
1465
+ currentNonce++;
1423
1466
  // === 2. 利润提取交易(独立的 EOA 转账)===
1424
1467
  if (nativeProfitAmount > 0n) {
1425
1468
  console.log(`[利润提取-签名] 非 AA 转账: ${useNativeToken ? formatOkb(nativeProfitAmount) : `${formatOkb(totalBuyProfitWei)} (ERC20) -> ${formatOkb(nativeProfitAmount)} (OKB)`} -> ${profitSettings.profitRecipient}`);
1426
1469
  const profitTxRequest = {
1427
1470
  to: profitSettings.profitRecipient,
1428
1471
  value: nativeProfitAmount,
1429
- nonce: startNonce + 1,
1472
+ nonce: currentNonce,
1430
1473
  gasLimit: 21000n,
1431
1474
  gasPrice,
1432
1475
  chainId
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.5.94",
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",