four-flap-meme-sdk 1.2.23 → 1.2.25

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.
@@ -397,6 +397,13 @@ export async function sweepWithBundleMerkle(params) {
397
397
  }
398
398
  }
399
399
  // ✅ 第二步:生成归集交易(扣除利润后的金额)
400
+ // ✅ 先为支付者预留 nonce,确保 nonce 连续
401
+ let payerProfitNonce;
402
+ if (extractProfit && totalProfit > 0n && maxSweepIndex >= 0) {
403
+ const payerWallet = wallets[maxSweepIndex];
404
+ const nonces = await nonceManager.getNextNonceBatch(payerWallet, 2);
405
+ payerProfitNonce = nonces[1]; // 利润交易的 nonce
406
+ }
400
407
  const txPromises = wallets.map(async (w, i) => {
401
408
  const toSend = sweepAmounts[i];
402
409
  if (toSend <= 0n)
@@ -406,7 +413,10 @@ export async function sweepWithBundleMerkle(params) {
406
413
  const { remaining } = calculateProfit(toSend, config);
407
414
  actualToSend = remaining;
408
415
  }
409
- const nonce = await nonceManager.getNextNonce(w);
416
+ // 支付者使用预留的第一个 nonce,其他钱包正常获取
417
+ const nonce = (i === maxSweepIndex && payerProfitNonce !== undefined)
418
+ ? payerProfitNonce - 1 // 使用预留的第一个 nonce
419
+ : await nonceManager.getNextNonce(w);
410
420
  const mainTx = await w.signTransaction({
411
421
  to: target,
412
422
  value: actualToSend,
@@ -420,16 +430,15 @@ export async function sweepWithBundleMerkle(params) {
420
430
  });
421
431
  const allTxs = (await Promise.all(txPromises)).filter(tx => tx !== null);
422
432
  signedTxs.push(...allTxs);
423
- // ✅ 第三步:由归集金额最大的钱包统一支付所有利润
424
- if (extractProfit && totalProfit > 0n && maxSweepIndex >= 0) {
433
+ // ✅ 第三步:在所有归集交易之后,生成利润交易
434
+ if (extractProfit && totalProfit > 0n && maxSweepIndex >= 0 && payerProfitNonce !== undefined) {
425
435
  const payerWallet = wallets[maxSweepIndex];
426
- const profitNonce = await nonceManager.getNextNonce(payerWallet);
427
436
  const profitTx = await payerWallet.signTransaction({
428
437
  to: config.profitRecipient,
429
438
  value: totalProfit,
430
- nonce: profitNonce,
439
+ nonce: payerProfitNonce,
431
440
  gasPrice,
432
- gasLimit: nativeGasLimit, // ✅ 使用用户配置的 gasLimit
441
+ gasLimit: nativeGasLimit,
433
442
  chainId: chainIdNum,
434
443
  type: txType
435
444
  });
@@ -500,6 +509,13 @@ export async function sweepWithBundleMerkle(params) {
500
509
  }
501
510
  }
502
511
  // ✅ 第二步:生成归集交易(扣除利润后的金额)
512
+ // ✅ 先为支付者预留 nonce,确保 nonce 连续
513
+ let payerProfitNonce;
514
+ if (extractProfit && totalProfit > 0n && maxSweepIndex >= 0) {
515
+ const payerWallet = wallets[maxSweepIndex];
516
+ const nonces = await nonceManager.getNextNonceBatch(payerWallet, 2);
517
+ payerProfitNonce = nonces[1]; // 利润交易的 nonce
518
+ }
503
519
  const txPromises = wallets.map(async (w, i) => {
504
520
  const toSend = sweepAmounts[i];
505
521
  if (toSend <= 0n)
@@ -509,7 +525,10 @@ export async function sweepWithBundleMerkle(params) {
509
525
  const { remaining } = calculateProfit(toSend, config);
510
526
  actualToSend = remaining;
511
527
  }
512
- const nonce = await nonceManager.getNextNonce(w);
528
+ // 支付者使用预留的第一个 nonce,其他钱包正常获取
529
+ const nonce = (i === maxSweepIndex && payerProfitNonce !== undefined)
530
+ ? payerProfitNonce - 1 // 使用预留的第一个 nonce
531
+ : await nonceManager.getNextNonce(w);
513
532
  const data = iface.encodeFunctionData('transfer', [target, actualToSend]);
514
533
  const mainTx = await w.signTransaction({
515
534
  to: tokenAddress,
@@ -525,18 +544,17 @@ export async function sweepWithBundleMerkle(params) {
525
544
  });
526
545
  const allTxs = (await Promise.all(txPromises)).filter(tx => tx !== null);
527
546
  signedTxs.push(...allTxs);
528
- // ✅ 第三步:由归集金额最大的钱包统一支付所有利润
529
- if (extractProfit && totalProfit > 0n && maxSweepIndex >= 0) {
547
+ // ✅ 第三步:在所有归集交易之后,生成利润交易
548
+ if (extractProfit && totalProfit > 0n && maxSweepIndex >= 0 && payerProfitNonce !== undefined) {
530
549
  const payerWallet = wallets[maxSweepIndex];
531
- const profitNonce = await nonceManager.getNextNonce(payerWallet);
532
550
  const profitData = iface.encodeFunctionData('transfer', [config.profitRecipient, totalProfit]);
533
551
  const profitTx = await payerWallet.signTransaction({
534
552
  to: tokenAddress,
535
553
  data: profitData,
536
554
  value: 0n,
537
- nonce: profitNonce,
555
+ nonce: payerProfitNonce,
538
556
  gasPrice,
539
- gasLimit: finalGasLimit, // ✅ 使用用户配置的 gasLimit
557
+ gasLimit: finalGasLimit,
540
558
  chainId: chainIdNum,
541
559
  type: txType
542
560
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.2.23",
3
+ "version": "1.2.25",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",