four-flap-meme-sdk 1.2.18 → 1.2.20

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,21 +1,24 @@
1
1
  import type { FourSignConfig } from './types.js';
2
- /** ✅ 批量授权参数(仅签名版本 - 精简) */
2
+ /** ✅ 批量授权参数(直接提交到链上) */
3
3
  export type ApproveFourTokenManagerBatchParams = {
4
4
  privateKeys: string[];
5
5
  tokenAddress: string;
6
6
  amounts: string[];
7
7
  config: FourSignConfig;
8
8
  };
9
- /** ✅ 批量授权结果(精简版 - 只返回签名交易) */
9
+ /** ✅ 批量授权结果(包含提交状态) */
10
10
  export type ApproveFourTokenManagerBatchResult = {
11
+ success: boolean;
11
12
  signedTransactions: string[];
12
13
  approvedCount: number;
13
14
  skippedCount: number;
15
+ txHashes?: string[];
14
16
  message: string;
15
17
  };
16
18
  /**
17
19
  * 批量授权代币给 TokenManager(用于 Private Buy/Sell)
18
- * ✅ 精简版:只负责签名交易,不提交到 Merkle
20
+ * ✅ 直接通过 RPC 提交到链上并等待确认
21
+ * ✅ 不需要 Merkle API Key,使用普通 RPC 即可
19
22
  * ✅ 专门用于授权给 TokenManagerOriginal 合约
20
23
  * ✅ 用于 fourBatchPrivateSell 和 fourBatchSellWithBundleMerkle
21
24
  */
@@ -1,5 +1,4 @@
1
1
  import { ethers, Wallet } from 'ethers';
2
- // import { MerkleClient } from '../../clients/merkle.js';
3
2
  import { NonceManager, getOptimizedGasPrice } from '../../utils/bundle-helpers.js';
4
3
  import { ADDRESSES } from '../../utils/constants.js';
5
4
  import { getTxType, getGasPriceConfig } from './config.js';
@@ -12,7 +11,8 @@ const ERC20_ABI = [
12
11
  ];
13
12
  /**
14
13
  * 批量授权代币给 TokenManager(用于 Private Buy/Sell)
15
- * ✅ 精简版:只负责签名交易,不提交到 Merkle
14
+ * ✅ 直接通过 RPC 提交到链上并等待确认
15
+ * ✅ 不需要 Merkle API Key,使用普通 RPC 即可
16
16
  * ✅ 专门用于授权给 TokenManagerOriginal 合约
17
17
  * ✅ 用于 fourBatchPrivateSell 和 fourBatchSellWithBundleMerkle
18
18
  */
@@ -29,9 +29,24 @@ export async function approveFourTokenManagerBatch(params) {
29
29
  name: 'BSC'
30
30
  });
31
31
  const gasPrice = await getOptimizedGasPrice(provider, getGasPriceConfig(config));
32
- // 查询 decimals
33
- const tokenContract = new ethers.Contract(tokenAddress, ERC20_ABI, provider);
34
- const decimals = await tokenContract.decimals();
32
+ // 优化:如果所有金额都是 'max',则不需要查询 decimals
33
+ const allMax = amounts.every(a => a === 'max');
34
+ let decimals = 18; // 默认值
35
+ if (!allMax) {
36
+ try {
37
+ const tokenContract = new ethers.Contract(tokenAddress, ERC20_ABI, provider);
38
+ decimals = await tokenContract.decimals();
39
+ }
40
+ catch (error) {
41
+ console.error('⚠️ 查询代币 decimals 失败:', error.message);
42
+ console.error(' 代币地址:', tokenAddress);
43
+ console.error(' 请确认:');
44
+ console.error(' 1. 代币地址是否正确');
45
+ console.error(' 2. 代币是否已部署在 BSC 主网');
46
+ console.error(' 3. RPC URL 是否可用');
47
+ throw new Error(`查询代币 decimals 失败: ${error.message}`);
48
+ }
49
+ }
35
50
  const wallets = privateKeys.map(k => new Wallet(k, provider));
36
51
  const amountsBigInt = amounts.map(a => a === 'max' ? ethers.MaxUint256 : ethers.parseUnits(a, decimals));
37
52
  // ✅ 检查是否有非 'max' 的授权
@@ -52,10 +67,11 @@ export async function approveFourTokenManagerBatch(params) {
52
67
  if (needApproval.length === 0) {
53
68
  console.log('✅ 所有钱包已授权');
54
69
  return {
70
+ success: true,
55
71
  signedTransactions: [],
56
72
  approvedCount: 0,
57
73
  skippedCount: skippedCount,
58
- message: '所有钱包已授权'
74
+ message: '所有钱包已授权,无需重复授权'
59
75
  };
60
76
  }
61
77
  // 构建授权交易
@@ -84,11 +100,37 @@ export async function approveFourTokenManagerBatch(params) {
84
100
  })));
85
101
  nonceManager.clearTemp();
86
102
  console.log(`✅ 已生成 ${signedTxs.length} 个授权交易签名`);
87
- // ✅ 只返回签名交易,不提交到 Merkle
88
- return {
89
- signedTransactions: signedTxs,
90
- approvedCount: signedTxs.length,
91
- skippedCount: skippedCount,
92
- message: `已生成 ${signedTxs.length} 个授权交易签名,跳过 ${skippedCount} 个已授权钱包`
93
- };
103
+ // ✅ 直接通过传入的 RPC 提交授权交易到链上
104
+ console.log(`📤 正在提交授权交易到链上...`);
105
+ try {
106
+ // 广播所有授权交易
107
+ const txResponses = await Promise.all(signedTxs.map(tx => provider.broadcastTransaction(tx)));
108
+ const txHashes = txResponses.map(r => r.hash);
109
+ console.log(`✅ 授权交易已提交,共 ${txHashes.length} 笔`);
110
+ txHashes.forEach((hash, i) => {
111
+ console.log(` 交易 ${i + 1}: ${hash}`);
112
+ });
113
+ // 等待所有授权交易确认(至少1个确认)
114
+ console.log(`⏳ 等待授权确认(约3-5秒)...`);
115
+ await Promise.all(txResponses.map(tx => tx.wait(1)));
116
+ console.log(`✅ 所有授权交易已确认!`);
117
+ return {
118
+ success: true,
119
+ signedTransactions: signedTxs,
120
+ approvedCount: signedTxs.length,
121
+ skippedCount: skippedCount,
122
+ txHashes: txHashes,
123
+ message: `授权成功!共 ${signedTxs.length} 个钱包已授权,跳过 ${skippedCount} 个已授权钱包`
124
+ };
125
+ }
126
+ catch (error) {
127
+ console.error('❌ 授权交易提交失败:', error.message);
128
+ return {
129
+ success: false,
130
+ signedTransactions: signedTxs,
131
+ approvedCount: 0,
132
+ skippedCount: skippedCount,
133
+ message: `授权提交失败: ${error.message}`
134
+ };
135
+ }
94
136
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.2.18",
3
+ "version": "1.2.20",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",