four-flap-meme-sdk 1.2.87 → 1.2.89

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.
@@ -251,6 +251,8 @@ export type DisperseSignParams = {
251
251
  hopPrivateKeys?: string[];
252
252
  }>;
253
253
  config: FourSignConfig;
254
+ /** ✅ 起始 Nonce(用于并行调用时控制 nonce 顺序) */
255
+ startNonce?: number;
254
256
  };
255
257
  /**
256
258
  * ✅ 分发结果(简化版)
@@ -300,6 +302,8 @@ export type SweepSignParams = {
300
302
  hopPrivateKeys?: string[];
301
303
  }>;
302
304
  config: FourSignConfig;
305
+ /** ✅ 起始 Nonce(用于并行调用时控制 nonce 顺序 - 仅当有多个源钱包且使用同一私钥时有效,通常归集不需要) */
306
+ startNonce?: number;
303
307
  };
304
308
  /**
305
309
  * ✅ 归集结果(简化版)
@@ -8,7 +8,7 @@ import { getErc20DecimalsMerkle as _getErc20DecimalsMerkle, generateHopWallets a
8
8
  * ✅ 精简版:只负责签名交易,不提交到 Merkle
9
9
  */
10
10
  export async function disperseWithBundleMerkle(params) {
11
- const { fromPrivateKey, recipients, amount, amounts, tokenAddress, tokenDecimals, hopCount = 0, hopPrivateKeys, items, config } = params;
11
+ const { fromPrivateKey, recipients, amount, amounts, tokenAddress, tokenDecimals, hopCount = 0, hopPrivateKeys, items, config, startNonce } = params;
12
12
  // 快速返回空结果
13
13
  if (!recipients || recipients.length === 0) {
14
14
  return {
@@ -69,6 +69,9 @@ export async function disperseWithBundleMerkle(params) {
69
69
  if (!preparedHops) {
70
70
  // ========== 无多跳:直接批量转账 ==========
71
71
  const nonceManager = new NonceManager(provider);
72
+ if (startNonce !== undefined) {
73
+ nonceManager.setNonce(mainWallet.address, startNonce);
74
+ }
72
75
  const extraTxCount = extractProfit ? 1 : 0; // ✅ 利润转账需要额外1个nonce
73
76
  const nonces = await nonceManager.getNextNonceBatch(mainWallet, recipients.length + extraTxCount);
74
77
  if (isNative) {
@@ -158,6 +161,9 @@ export async function disperseWithBundleMerkle(params) {
158
161
  const iface = isNative ? null : new ethers.Interface(['function transfer(address,uint256) returns (bool)']);
159
162
  const gasFeePerHop = finalGasLimit * gasPrice;
160
163
  const nonceManager = new NonceManager(provider);
164
+ if (startNonce !== undefined) {
165
+ nonceManager.setNonce(mainWallet.address, startNonce);
166
+ }
161
167
  for (let i = 0; i < recipients.length; i++) {
162
168
  const finalRecipient = recipients[i];
163
169
  const originalAmountWei = isNative
@@ -315,7 +321,7 @@ export async function disperseWithBundleMerkle(params) {
315
321
  * ✅ 精简版:只负责签名交易,不提交到 Merkle
316
322
  */
317
323
  export async function sweepWithBundleMerkle(params) {
318
- const { sourcePrivateKeys, target, ratioPct, ratios, amount, amounts, tokenAddress, tokenDecimals, skipIfInsufficient = true, hopCount = 0, hopPrivateKeys, sources, config } = params;
324
+ const { sourcePrivateKeys, target, ratioPct, ratios, amount, amounts, tokenAddress, tokenDecimals, skipIfInsufficient = true, hopCount = 0, hopPrivateKeys, sources, config, startNonce } = params;
319
325
  // 快速返回空结果
320
326
  if (!sourcePrivateKeys || sourcePrivateKeys.length === 0) {
321
327
  return {
@@ -383,6 +389,10 @@ export async function sweepWithBundleMerkle(params) {
383
389
  const wallets = actualKeys.map(pk => new Wallet(pk, provider));
384
390
  const addresses = wallets.map(w => w.address);
385
391
  const nonceManager = new NonceManager(provider);
392
+ // ✅ 如果提供了 startNonce,设置给第一个钱包(主要用于测试场景下单一源钱包的并发调用)
393
+ if (startNonce !== undefined && wallets.length > 0) {
394
+ nonceManager.setNonce(wallets[0].address, startNonce);
395
+ }
386
396
  if (isNative) {
387
397
  // ✅ 原生币:批量查询余额,统一扣除利润
388
398
  const balances = await _batchGetBalances(provider, addresses);
@@ -661,6 +671,11 @@ export async function sweepWithBundleMerkle(params) {
661
671
  const iface = isNative ? null : new ethers.Interface(['function transfer(address,uint256) returns (bool)']);
662
672
  const gasFeePerHop = finalGasLimit * gasPrice;
663
673
  const nonceManager = new NonceManager(provider);
674
+ // ✅ 如果提供了 startNonce,设置给第一个钱包(主要用于测试场景下单一源钱包的并发调用)
675
+ if (startNonce !== undefined && actualKeys.length > 0) {
676
+ const firstWallet = new Wallet(actualKeys[0], provider);
677
+ nonceManager.setNonce(firstWallet.address, startNonce);
678
+ }
664
679
  // 分离有跳转和无跳转的地址
665
680
  const sourceWallets = actualKeys.map(pk => new Wallet(pk, provider));
666
681
  const withHopIndexes = [];
@@ -16,6 +16,12 @@ export declare class NonceManager {
16
16
  private provider;
17
17
  private tempNonceCache;
18
18
  constructor(provider: JsonRpcProvider);
19
+ /**
20
+ * 手动设置缓存的 nonce(用于外部控制起始 nonce)
21
+ * @param wallet 钱包对象或地址
22
+ * @param nonce 起始 nonce(getNextNonce 将返回此值)
23
+ */
24
+ setNonce(wallet: Wallet | string, nonce: number): void;
19
25
  /**
20
26
  * 获取下一个可用的 nonce
21
27
  * @param wallet 钱包对象或地址
@@ -18,6 +18,15 @@ export class NonceManager {
18
18
  this.tempNonceCache = new Map();
19
19
  this.provider = provider;
20
20
  }
21
+ /**
22
+ * 手动设置缓存的 nonce(用于外部控制起始 nonce)
23
+ * @param wallet 钱包对象或地址
24
+ * @param nonce 起始 nonce(getNextNonce 将返回此值)
25
+ */
26
+ setNonce(wallet, nonce) {
27
+ const address = typeof wallet === 'string' ? wallet : wallet.address;
28
+ this.tempNonceCache.set(address.toLowerCase(), nonce);
29
+ }
21
30
  /**
22
31
  * 获取下一个可用的 nonce
23
32
  * @param wallet 钱包对象或地址
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.2.87",
3
+ "version": "1.2.89",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",