four-flap-meme-sdk 1.4.80 → 1.4.81

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.
@@ -112,8 +112,8 @@ export class BlockRazorClient {
112
112
  */
113
113
  async buildIncentiveTransaction(params) {
114
114
  const { wallet, amount, nonce, gasPrice } = params;
115
- // 获取 nonce
116
- const txNonce = nonce ?? await this.provider.getTransactionCount(wallet.address, 'latest');
115
+ // 获取 nonce(使用 pending 确保包含待处理交易)
116
+ const txNonce = nonce ?? await this.provider.getTransactionCount(wallet.address, 'pending');
117
117
  // 获取 gas price
118
118
  let txGasPrice = gasPrice;
119
119
  if (!txGasPrice) {
@@ -291,8 +291,8 @@ export class BlockRazorClient {
291
291
  * @returns Bundle 结果
292
292
  */
293
293
  async sendBundleWithIncentive(options, incentive) {
294
- // 获取激励钱包的 nonce
295
- const nonce = await this.provider.getTransactionCount(incentive.wallet.address, 'latest');
294
+ // 获取激励钱包的 nonce(使用 pending 确保包含待处理交易)
295
+ const nonce = await this.provider.getTransactionCount(incentive.wallet.address, 'pending');
296
296
  // 构建激励交易(放在 Bundle 最后)
297
297
  const incentiveTx = await this.buildIncentiveTransaction({
298
298
  wallet: incentive.wallet,
@@ -365,10 +365,10 @@ export class BlockRazorClient {
365
365
  if (!transactions || transactions.length === 0) {
366
366
  throw new Error('Transactions array cannot be empty');
367
367
  }
368
- // 获取 nonce
368
+ // 获取 nonce(使用 pending 确保包含待处理交易)
369
369
  let nonce = options?.startNonce;
370
370
  if (nonce === undefined) {
371
- nonce = await this.provider.getTransactionCount(wallet.address, 'latest');
371
+ nonce = await this.provider.getTransactionCount(wallet.address, 'pending');
372
372
  }
373
373
  // 获取 Gas Price(确保不低于最低要求)
374
374
  let gasPrice = options?.gasPrice;
@@ -289,10 +289,10 @@ export class MerkleClient {
289
289
  if (!transactions || transactions.length === 0) {
290
290
  throw new Error('Transactions array cannot be empty');
291
291
  }
292
- // 获取起始 Nonce(使用 latest 避免 pending 状态问题)
292
+ // 获取起始 Nonce(使用 pending 确保包含待处理交易)
293
293
  let nonce = options?.startNonce;
294
294
  if (nonce === undefined) {
295
- nonce = await this.provider.getTransactionCount(wallet.address, 'latest');
295
+ nonce = await this.provider.getTransactionCount(wallet.address, 'pending');
296
296
  }
297
297
  // 获取 Gas Price
298
298
  let gasPrice = options?.gasPrice;
@@ -9,7 +9,7 @@ import { type GeneratedWallet } from './wallet.js';
9
9
  * 用于在 bundle 交易中管理多个钱包的 nonce
10
10
  *
11
11
  * 策略:
12
- * 1. 每次获取 nonce 时查询链上最新状态('latest' 不含 pending)
12
+ * 1. 每次获取 nonce 时查询链上状态(使用 'pending' 包含待处理交易)
13
13
  * 2. 仅在同一批次内维护临时递增缓存
14
14
  * 3. 不持久化缓存,避免因失败交易导致 nonce 过高
15
15
  */
@@ -9,7 +9,7 @@ import { generateWallets } from './wallet.js';
9
9
  * 用于在 bundle 交易中管理多个钱包的 nonce
10
10
  *
11
11
  * 策略:
12
- * 1. 每次获取 nonce 时查询链上最新状态('latest' 不含 pending)
12
+ * 1. 每次获取 nonce 时查询链上状态(使用 'pending' 包含待处理交易)
13
13
  * 2. 仅在同一批次内维护临时递增缓存
14
14
  * 3. 不持久化缓存,避免因失败交易导致 nonce 过高
15
15
  */
@@ -33,9 +33,9 @@ export class NonceManager {
33
33
  this.tempNonceCache.set(key, cachedNonce + 1);
34
34
  return cachedNonce;
35
35
  }
36
- // ✅ 使用 'latest' 获取 nonce(已确认的交易)
36
+ // ✅ 使用 'pending' 获取 nonce(包含待处理交易)
37
37
  // 由于前端已移除 nonce 缓存,SDK 每次都从链上获取最新状态
38
- const onchainNonce = await this.provider.getTransactionCount(address, 'latest');
38
+ const onchainNonce = await this.provider.getTransactionCount(address, 'pending');
39
39
  // 缓存下一个值(仅在当前批次内有效)
40
40
  this.tempNonceCache.set(key, onchainNonce + 1);
41
41
  return onchainNonce;
@@ -54,7 +54,7 @@ export class NonceManager {
54
54
  startNonce = this.tempNonceCache.get(key);
55
55
  }
56
56
  else {
57
- startNonce = await this.provider.getTransactionCount(address, 'latest');
57
+ startNonce = await this.provider.getTransactionCount(address, 'pending');
58
58
  }
59
59
  // 更新缓存
60
60
  this.tempNonceCache.set(key, startNonce + count);
@@ -101,9 +101,10 @@ export class NonceManager {
101
101
  let queryResults;
102
102
  try {
103
103
  // ✅ 使用 JSON-RPC 批量请求(单次网络往返)
104
+ // ✅ 使用 'pending' 状态获取 nonce,避免与待处理交易冲突
104
105
  const batchRequests = needQuery.map(({ address }, idx) => ({
105
106
  method: 'eth_getTransactionCount',
106
- params: [address, 'latest'],
107
+ params: [address, 'pending'],
107
108
  id: idx + 1,
108
109
  jsonrpc: '2.0'
109
110
  }));
@@ -119,7 +120,8 @@ export class NonceManager {
119
120
  }
120
121
  catch {
121
122
  // 如果批量请求失败,回退到 Promise.all
122
- const queryPromises = needQuery.map(({ address }) => this.provider.getTransactionCount(address, 'latest'));
123
+ // 同样使用 'pending' 状态
124
+ const queryPromises = needQuery.map(({ address }) => this.provider.getTransactionCount(address, 'pending'));
123
125
  queryResults = await Promise.all(queryPromises);
124
126
  }
125
127
  // 填充结果并更新缓存
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.4.80",
3
+ "version": "1.4.81",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",