four-flap-meme-sdk 1.5.42 → 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.
@@ -91,9 +91,6 @@ export declare class BundleExecutor {
91
91
  * 捆绑发射代币 + 购买(签名版本)
92
92
  */
93
93
  bundleCreateBuySign(params: BundleCreateBuySignParams): Promise<BundleCreateBuySignResult>;
94
- /**
95
- * 捆绑发射代币 + 购买(执行版本)
96
- */
97
94
  bundleCreateBuy(params: BundleCreateBuyParams): Promise<BundleCreateBuyResult>;
98
95
  /**
99
96
  * 检查多个 AA 账户的授权状态
@@ -1131,13 +1131,10 @@ export class BundleExecutor {
1131
1131
  console.log('token:', tokenInfo.symbol);
1132
1132
  console.log('dev:', devWallet.address);
1133
1133
  console.log('buyers:', buyerWallets.length);
1134
- // 1. 准备代币地址
1135
1134
  const tokenAddress = params.tokenAddress || ZERO_ADDRESS;
1136
- // 2. 构造 UserOperations
1137
- const mainOps = [];
1138
- const profitOps = [];
1135
+ // 2. 构造 UserOperations (主要涵盖发币和购买)
1136
+ const ops = [];
1139
1137
  const nonceMap = new AANonceMap();
1140
- // 2a. Dev 发射代币
1141
1138
  const devAccount = await this.aaManager.getAccountInfo(devWallet.address);
1142
1139
  nonceMap.init(devAccount.sender, devAccount.nonce);
1143
1140
  const useV4 = params.dexId !== undefined || params.lpFeeProfile !== undefined;
@@ -1206,8 +1203,7 @@ export class BundleExecutor {
1206
1203
  deployed: devAccount.deployed
1207
1204
  });
1208
1205
  const signedDevOp = await this.aaManager.signUserOp(devCreateOp.userOp, devWallet);
1209
- mainOps.push(signedDevOp.userOp);
1210
- // 2b. Buyers 买入
1206
+ ops.push(signedDevOp.userOp);
1211
1207
  const profitSettings = resolveProfitSettings(effConfig);
1212
1208
  const inputToken = params.quoteToken && params.quoteToken !== ZERO_ADDRESS ? params.quoteToken : ZERO_ADDRESS;
1213
1209
  const useNativeToken = inputToken === ZERO_ADDRESS;
@@ -1215,7 +1211,6 @@ export class BundleExecutor {
1215
1211
  let totalBuyWei = 0n;
1216
1212
  let totalBuyProfitWei = 0n;
1217
1213
  const buyerSenders = [];
1218
- const profitWeis = [];
1219
1214
  const portalIface = new Interface(PORTAL_ABI);
1220
1215
  for (let i = 0; i < buyerWallets.length; i++) {
1221
1216
  const buyer = buyerWallets[i];
@@ -1230,7 +1225,6 @@ export class BundleExecutor {
1230
1225
  }
1231
1226
  totalBuyWei += buyWei;
1232
1227
  totalBuyProfitWei += profitWei;
1233
- profitWeis.push(profitWei);
1234
1228
  const buyerAccount = await this.aaManager.getAccountInfo(buyer.address);
1235
1229
  buyerSenders.push(buyerAccount.sender);
1236
1230
  nonceMap.init(buyerAccount.sender, buyerAccount.nonce);
@@ -1252,11 +1246,11 @@ export class BundleExecutor {
1252
1246
  deployed: buyerAccount.deployed
1253
1247
  });
1254
1248
  const signedBuyOp = await this.aaManager.signUserOp(buyOp.userOp, buyer);
1255
- mainOps.push(signedBuyOp.userOp);
1249
+ ops.push(signedBuyOp.userOp);
1256
1250
  }
1257
- // 刮取利润:单独作为一个交易签名
1251
+ let nativeProfitAmount = 0n;
1258
1252
  if (profitSettings.extractProfit && totalBuyProfitWei > 0n) {
1259
- let nativeProfitAmount = totalBuyProfitWei;
1253
+ nativeProfitAmount = totalBuyProfitWei;
1260
1254
  if (!useNativeToken) {
1261
1255
  try {
1262
1256
  const dq = new DexQuery(effConfig);
@@ -1272,47 +1266,77 @@ export class BundleExecutor {
1272
1266
  }
1273
1267
  }
1274
1268
  }
1275
- if (nativeProfitAmount > 0n) {
1276
- const maxProfitIndex = profitWeis.reduce((maxIdx, p, idx) => p > (profitWeis[maxIdx] ?? 0n) ? idx : maxIdx, 0);
1277
- const pOwner = buyerWallets[maxProfitIndex];
1278
- const pSender = buyerSenders[maxProfitIndex];
1279
- const profitCallData = encodeExecute(profitSettings.profitRecipient, nativeProfitAmount, '0x');
1280
- const profitOp = await this.aaManager.buildUserOpWithFixedGas({
1281
- ownerWallet: pOwner,
1282
- sender: pSender,
1283
- callData: profitCallData,
1284
- nonce: nonceMap.next(pSender),
1285
- initCode: '0x',
1286
- deployed: true,
1287
- fixedGas: {
1288
- ...(effConfig.fixedGas ?? {}),
1289
- callGasLimit: effConfig.fixedGas?.callGasLimit ?? DEFAULT_CALL_GAS_LIMIT_WITHDRAW,
1290
- }
1291
- });
1292
- const signedProfitOp = await this.aaManager.signUserOp(profitOp.userOp, pOwner);
1293
- profitOps.push(signedProfitOp.userOp);
1294
- }
1295
1269
  }
1296
- // 3. 签名 handleOps 交易
1297
1270
  const provider = this.aaManager.getProvider();
1298
1271
  const startNonce = params.payerStartNonce ?? await provider.getTransactionCount(payer.address, 'pending');
1299
1272
  const signedTransactions = [];
1300
- // 3a. 签名主交易
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 交易 ===
1301
1320
  const signedMainTx = await this.signHandleOpsTx({
1302
- ops: mainOps,
1321
+ ops,
1303
1322
  payerWallet: payer,
1304
1323
  beneficiary: useBeneficiary,
1305
- nonce: startNonce
1324
+ nonce: currentNonce
1306
1325
  });
1307
1326
  signedTransactions.push(signedMainTx);
1308
- // 3b. 签名利润交易
1309
- if (profitOps.length > 0) {
1310
- const signedProfitTx = await this.signHandleOpsTx({
1311
- ops: profitOps,
1312
- payerWallet: payer,
1313
- beneficiary: useBeneficiary,
1314
- nonce: startNonce + 1
1315
- });
1327
+ currentNonce++;
1328
+ // === 3. 利润提取交易 ===
1329
+ if (nativeProfitAmount > 0n) {
1330
+ console.log(`[利润提取-签名] 非 AA 转账: ${useNativeToken ? formatOkb(nativeProfitAmount) : `${formatOkb(totalBuyProfitWei)} (ERC20) -> ${formatOkb(nativeProfitAmount)} (OKB)`} -> ${profitSettings.profitRecipient}`);
1331
+ const profitTxRequest = {
1332
+ to: profitSettings.profitRecipient,
1333
+ value: nativeProfitAmount,
1334
+ nonce: currentNonce,
1335
+ gasLimit: 21000n,
1336
+ gasPrice,
1337
+ chainId
1338
+ };
1339
+ const signedProfitTx = await payer.signTransaction(profitTxRequest);
1316
1340
  signedTransactions.push(signedProfitTx);
1317
1341
  }
1318
1342
  return {
@@ -1328,9 +1352,6 @@ export class BundleExecutor {
1328
1352
  }
1329
1353
  };
1330
1354
  }
1331
- /**
1332
- * 捆绑发射代币 + 购买(执行版本)
1333
- */
1334
1355
  async bundleCreateBuy(params) {
1335
1356
  const signResult = await this.bundleCreateBuySign({
1336
1357
  ...params,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.5.42",
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",