four-flap-meme-sdk 1.5.43 → 1.5.44

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.
@@ -1270,24 +1270,71 @@ export class BundleExecutor {
1270
1270
  const provider = this.aaManager.getProvider();
1271
1271
  const startNonce = params.payerStartNonce ?? await provider.getTransactionCount(payer.address, 'pending');
1272
1272
  const signedTransactions = [];
1273
+ const feeData = await provider.getFeeData();
1274
+ const gasPrice = feeData.gasPrice ?? 100000000n;
1275
+ const chainId = (await provider.getNetwork()).chainId;
1276
+ let currentNonce = startNonce;
1277
+ // === 1. 预存资金交易:payer -> 各个 AA sender ===
1278
+ // 计算每个 buyer sender 需要的 OKB(买入金额 + gas 余量)
1279
+ const GAS_BUFFER = parseOkb('0.001'); // 0.001 OKB 作为 gas 缓冲
1280
+ const prefundTargets = [];
1281
+ // Dev sender 需要 quoteAmt(发币时的首次购买金额)
1282
+ const devQuoteAmt = params.quoteAmt || 0n;
1283
+ if (useNativeToken && devQuoteAmt > 0n) {
1284
+ prefundTargets.push({ sender: devAccount.sender, amount: devQuoteAmt + GAS_BUFFER });
1285
+ }
1286
+ // Buyer senders 需要各自的买入金额
1287
+ for (let i = 0; i < buyerWallets.length; i++) {
1288
+ const amountStr = buyAmounts[i] || '0';
1289
+ const originalWei = useNativeToken ? parseOkb(amountStr) : ethers.parseUnits(amountStr, quoteDecimals);
1290
+ let buyWei = originalWei;
1291
+ if (profitSettings.extractProfit) {
1292
+ const res = calculateProfit(originalWei, profitSettings.profitBps);
1293
+ buyWei = res.remaining;
1294
+ }
1295
+ if (buyWei > 0n) {
1296
+ prefundTargets.push({ sender: buyerSenders[i], amount: buyWei + GAS_BUFFER });
1297
+ }
1298
+ }
1299
+ // 如果有需要预存资金的地址,生成批量转账交易
1300
+ if (prefundTargets.length > 0) {
1301
+ const totalPrefund = prefundTargets.reduce((sum, t) => sum + t.amount, 0n);
1302
+ console.log(`[预存资金] 共 ${prefundTargets.length} 个 AA sender,总计: ${formatOkb(totalPrefund)} OKB`);
1303
+ // 批量转账:使用多个单独交易(因为普通 EOA 无法一次转账到多个地址)
1304
+ for (const target of prefundTargets) {
1305
+ const prefundTx = {
1306
+ to: target.sender,
1307
+ value: target.amount,
1308
+ nonce: currentNonce,
1309
+ gasLimit: 21000n,
1310
+ gasPrice,
1311
+ chainId
1312
+ };
1313
+ const signedPrefundTx = await payer.signTransaction(prefundTx);
1314
+ signedTransactions.push(signedPrefundTx);
1315
+ currentNonce++;
1316
+ console.log(` - prefund ${target.sender.slice(0, 10)}... = ${formatOkb(target.amount)} OKB (nonce: ${currentNonce - 1})`);
1317
+ }
1318
+ }
1319
+ // === 2. AA handleOps 交易 ===
1273
1320
  const signedMainTx = await this.signHandleOpsTx({
1274
1321
  ops,
1275
1322
  payerWallet: payer,
1276
1323
  beneficiary: useBeneficiary,
1277
- nonce: startNonce
1324
+ nonce: currentNonce
1278
1325
  });
1279
1326
  signedTransactions.push(signedMainTx);
1327
+ currentNonce++;
1328
+ // === 3. 利润提取交易 ===
1280
1329
  if (nativeProfitAmount > 0n) {
1281
1330
  console.log(`[利润提取-签名] 非 AA 转账: ${useNativeToken ? formatOkb(nativeProfitAmount) : `${formatOkb(totalBuyProfitWei)} (ERC20) -> ${formatOkb(nativeProfitAmount)} (OKB)`} -> ${profitSettings.profitRecipient}`);
1282
- const feeData = await provider.getFeeData();
1283
- const gasPrice = feeData.gasPrice ?? 100000000n;
1284
1331
  const profitTxRequest = {
1285
1332
  to: profitSettings.profitRecipient,
1286
1333
  value: nativeProfitAmount,
1287
- nonce: startNonce + 1,
1334
+ nonce: currentNonce,
1288
1335
  gasLimit: 21000n,
1289
- gasPrice: gasPrice,
1290
- chainId: (await provider.getNetwork()).chainId
1336
+ gasPrice,
1337
+ chainId
1291
1338
  };
1292
1339
  const signedProfitTx = await payer.signTransaction(profitTxRequest);
1293
1340
  signedTransactions.push(signedProfitTx);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.5.43",
3
+ "version": "1.5.44",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",