four-flap-meme-sdk 1.4.2 → 1.4.3

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.
@@ -1,4 +1,5 @@
1
1
  import { JsonRpcProvider } from 'ethers';
2
+ import { NonceManager } from './bundle-helpers.js';
2
3
  export type EnsureAllowanceResult = {
3
4
  alreadyApproved: boolean;
4
5
  currentAllowance: bigint;
@@ -190,6 +191,8 @@ export type ApproveTokenBatchRawParams = {
190
191
  gasLimit?: number;
191
192
  /** 链ID(可选,默认56=BSC,signOnly=true 时生效) */
192
193
  chainId?: number;
194
+ /** 外部 NonceManager(可选,用于同一钱包签多笔交易时共享 nonce 状态) */
195
+ nonceManager?: NonceManager;
193
196
  };
194
197
  /** signOnly=false 时的返回结果(直接发送交易) */
195
198
  export type ApproveTokenBatchResult = {
@@ -1,5 +1,6 @@
1
1
  import { Contract, Wallet, JsonRpcProvider, Interface, parseUnits } from 'ethers';
2
2
  import { ADDRESSES } from './constants.js';
3
+ import { NonceManager } from './bundle-helpers.js';
3
4
  const ERC20_ABI = [
4
5
  { "constant": false, "inputs": [{ "name": "spender", "type": "address" }, { "name": "value", "type": "uint256" }], "name": "approve", "outputs": [{ "name": "", "type": "bool" }], "type": "function" },
5
6
  { "constant": true, "inputs": [{ "name": "owner", "type": "address" }, { "name": "spender", "type": "address" }], "name": "allowance", "outputs": [{ "name": "", "type": "uint256" }], "type": "function" },
@@ -488,7 +489,7 @@ export async function approveTokenBatch(params) {
488
489
  return approveTokenBatchRaw({ rpcUrl, privateKeys, tokenAddress, spenderAddress, amounts, signOnly, gasPriceGwei, gasLimit, chainId });
489
490
  }
490
491
  export async function approveTokenBatchRaw(params) {
491
- const { rpcUrl, privateKeys, tokenAddress, spenderAddress, amounts, signOnly, gasPriceGwei, gasLimit, chainId = 56 } = params;
492
+ const { rpcUrl, privateKeys, tokenAddress, spenderAddress, amounts, signOnly, gasPriceGwei, gasLimit, chainId = 56, nonceManager: externalNonceManager } = params;
492
493
  if (privateKeys.length === 0 || amounts.length !== privateKeys.length) {
493
494
  throw new Error('❌ 私钥数量和授权数量必须匹配');
494
495
  }
@@ -507,10 +508,12 @@ export async function approveTokenBatchRaw(params) {
507
508
  : amount);
508
509
  // ==================== signOnly=true:只签名不提交 ====================
509
510
  if (signOnly) {
511
+ // ✅ 使用 NonceManager 管理 nonce(和买卖交易一样)
512
+ const nonceManager = externalNonceManager || new NonceManager(provider);
510
513
  // ✅ 并行获取:当前授权额度 + nonces + gasPrice
511
514
  const [currentAllowances, nonces, fetchedGasPrice] = await Promise.all([
512
515
  batchCheckAllowances(provider, normalizedToken, ownerAddresses, normalizedSpender),
513
- Promise.all(wallets.map(w => provider.getTransactionCount(w.address, 'latest'))),
516
+ nonceManager.getNextNoncesForWallets(wallets), // 使用 NonceManager 批量获取 nonce
514
517
  gasPriceGwei ? Promise.resolve(parseUnits(gasPriceGwei.toString(), 'gwei')) : provider.getFeeData().then(fee => fee.gasPrice || parseUnits('3', 'gwei'))
515
518
  ]);
516
519
  const finalGasPrice = fetchedGasPrice;
@@ -537,7 +540,7 @@ export async function approveTokenBatchRaw(params) {
537
540
  const signedTx = await wallet.signTransaction({
538
541
  to: normalizedToken,
539
542
  data: txData,
540
- nonce: nonces[i],
543
+ nonce: nonces[i], // ✅ NonceManager 已经处理好递增
541
544
  gasLimit: finalGasLimit,
542
545
  gasPrice: finalGasPrice,
543
546
  chainId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",