four-flap-meme-sdk 1.2.19 → 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
|
-
* ✅
|
|
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
|
-
* ✅
|
|
14
|
+
* ✅ 直接通过 RPC 提交到链上并等待确认
|
|
15
|
+
* ✅ 不需要 Merkle API Key,使用普通 RPC 即可
|
|
16
16
|
* ✅ 专门用于授权给 TokenManagerOriginal 合约
|
|
17
17
|
* ✅ 用于 fourBatchPrivateSell 和 fourBatchSellWithBundleMerkle
|
|
18
18
|
*/
|
|
@@ -67,10 +67,11 @@ export async function approveFourTokenManagerBatch(params) {
|
|
|
67
67
|
if (needApproval.length === 0) {
|
|
68
68
|
console.log('✅ 所有钱包已授权');
|
|
69
69
|
return {
|
|
70
|
+
success: true,
|
|
70
71
|
signedTransactions: [],
|
|
71
72
|
approvedCount: 0,
|
|
72
73
|
skippedCount: skippedCount,
|
|
73
|
-
message: '
|
|
74
|
+
message: '所有钱包已授权,无需重复授权'
|
|
74
75
|
};
|
|
75
76
|
}
|
|
76
77
|
// 构建授权交易
|
|
@@ -99,11 +100,37 @@ export async function approveFourTokenManagerBatch(params) {
|
|
|
99
100
|
})));
|
|
100
101
|
nonceManager.clearTemp();
|
|
101
102
|
console.log(`✅ 已生成 ${signedTxs.length} 个授权交易签名`);
|
|
102
|
-
// ✅
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
+
}
|
|
109
136
|
}
|