four-flap-meme-sdk 1.2.17 → 1.2.19
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,27 +1,21 @@
|
|
|
1
|
+
import type { FourSignConfig } from './types.js';
|
|
2
|
+
/** ✅ 批量授权参数(仅签名版本 - 精简) */
|
|
1
3
|
export type ApproveFourTokenManagerBatchParams = {
|
|
2
4
|
privateKeys: string[];
|
|
3
5
|
tokenAddress: string;
|
|
4
6
|
amounts: string[];
|
|
5
|
-
config:
|
|
6
|
-
apiKey: string;
|
|
7
|
-
customRpcUrl?: string;
|
|
8
|
-
chainId?: number;
|
|
9
|
-
bundleBlockOffset?: number;
|
|
10
|
-
gasLimit?: number | bigint;
|
|
11
|
-
gasLimitMultiplier?: number;
|
|
12
|
-
gasPriceMultiplierPercent?: number;
|
|
13
|
-
minGasPriceGwei?: number;
|
|
14
|
-
txType?: 0 | 2;
|
|
15
|
-
};
|
|
7
|
+
config: FourSignConfig;
|
|
16
8
|
};
|
|
9
|
+
/** ✅ 批量授权结果(精简版 - 只返回签名交易) */
|
|
17
10
|
export type ApproveFourTokenManagerBatchResult = {
|
|
18
|
-
|
|
11
|
+
signedTransactions: string[];
|
|
19
12
|
approvedCount: number;
|
|
20
|
-
|
|
13
|
+
skippedCount: number;
|
|
21
14
|
message: string;
|
|
22
15
|
};
|
|
23
16
|
/**
|
|
24
17
|
* 批量授权代币给 TokenManager(用于 Private Buy/Sell)
|
|
18
|
+
* ✅ 精简版:只负责签名交易,不提交到 Merkle
|
|
25
19
|
* ✅ 专门用于授权给 TokenManagerOriginal 合约
|
|
26
20
|
* ✅ 用于 fourBatchPrivateSell 和 fourBatchSellWithBundleMerkle
|
|
27
21
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ethers, Wallet } from 'ethers';
|
|
2
|
-
import { MerkleClient } from '../../clients/merkle.js';
|
|
2
|
+
// import { MerkleClient } from '../../clients/merkle.js';
|
|
3
3
|
import { NonceManager, getOptimizedGasPrice } from '../../utils/bundle-helpers.js';
|
|
4
4
|
import { ADDRESSES } from '../../utils/constants.js';
|
|
5
5
|
import { getTxType, getGasPriceConfig } from './config.js';
|
|
@@ -12,6 +12,7 @@ const ERC20_ABI = [
|
|
|
12
12
|
];
|
|
13
13
|
/**
|
|
14
14
|
* 批量授权代币给 TokenManager(用于 Private Buy/Sell)
|
|
15
|
+
* ✅ 精简版:只负责签名交易,不提交到 Merkle
|
|
15
16
|
* ✅ 专门用于授权给 TokenManagerOriginal 合约
|
|
16
17
|
* ✅ 用于 fourBatchPrivateSell 和 fourBatchSellWithBundleMerkle
|
|
17
18
|
*/
|
|
@@ -22,16 +23,30 @@ export async function approveFourTokenManagerBatch(params) {
|
|
|
22
23
|
}
|
|
23
24
|
const tmAddr = ADDRESSES.BSC.TokenManagerOriginal;
|
|
24
25
|
const chainId = config.chainId ?? 56;
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
// ✅ 直接使用传入的 RPC URL 创建 provider(不依赖 Merkle)
|
|
27
|
+
const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
|
|
27
28
|
chainId: chainId,
|
|
28
|
-
|
|
29
|
+
name: 'BSC'
|
|
29
30
|
});
|
|
30
|
-
const provider = merkle.getProvider();
|
|
31
31
|
const gasPrice = await getOptimizedGasPrice(provider, getGasPriceConfig(config));
|
|
32
|
-
//
|
|
33
|
-
const
|
|
34
|
-
|
|
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' 的授权
|
|
@@ -48,10 +63,13 @@ export async function approveFourTokenManagerBatch(params) {
|
|
|
48
63
|
const APPROVAL_THRESHOLD = ethers.MaxUint256 / 2n;
|
|
49
64
|
const needApproval = wallets.filter((_, i) => allowances[i] < APPROVAL_THRESHOLD);
|
|
50
65
|
const needApprovalAmounts = amountsBigInt.filter((_, i) => allowances[i] < APPROVAL_THRESHOLD);
|
|
66
|
+
const skippedCount = wallets.length - needApproval.length;
|
|
51
67
|
if (needApproval.length === 0) {
|
|
68
|
+
console.log('✅ 所有钱包已授权');
|
|
52
69
|
return {
|
|
53
|
-
|
|
70
|
+
signedTransactions: [],
|
|
54
71
|
approvedCount: 0,
|
|
72
|
+
skippedCount: skippedCount,
|
|
55
73
|
message: '所有钱包已授权'
|
|
56
74
|
};
|
|
57
75
|
}
|
|
@@ -63,8 +81,8 @@ export async function approveFourTokenManagerBatch(params) {
|
|
|
63
81
|
if (cfg.gasLimit)
|
|
64
82
|
return BigInt(cfg.gasLimit);
|
|
65
83
|
if (cfg.gasLimitMultiplier)
|
|
66
|
-
return BigInt(Math.ceil(
|
|
67
|
-
return
|
|
84
|
+
return BigInt(Math.ceil(60000 * cfg.gasLimitMultiplier));
|
|
85
|
+
return 60000n; // 默认授权 gas limit
|
|
68
86
|
};
|
|
69
87
|
const finalGasLimit = getGasLimit(config);
|
|
70
88
|
// 签名授权交易
|
|
@@ -81,35 +99,11 @@ export async function approveFourTokenManagerBatch(params) {
|
|
|
81
99
|
})));
|
|
82
100
|
nonceManager.clearTemp();
|
|
83
101
|
console.log(`✅ 已生成 ${signedTxs.length} 个授权交易签名`);
|
|
84
|
-
// ✅
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
});
|
|
92
|
-
console.log(`✅ 授权交易已提交,bundleHash: ${bundleResult.bundleHash}`);
|
|
93
|
-
// ✅ 等待授权确认
|
|
94
|
-
console.log(`⏳ 等待授权交易确认(约5-10秒)...`);
|
|
95
|
-
const confirmResults = await merkle.waitForBundleConfirmation(bundleResult.txHashes, 1, 60000);
|
|
96
|
-
const successCount = confirmResults.filter(r => r.success).length;
|
|
97
|
-
if (successCount > 0) {
|
|
98
|
-
console.log(`✅ 授权已确认,共 ${successCount} 笔交易成功`);
|
|
99
|
-
return {
|
|
100
|
-
success: true,
|
|
101
|
-
approvedCount: successCount,
|
|
102
|
-
bundleHash: bundleResult.bundleHash,
|
|
103
|
-
message: `授权成功,共 ${successCount} 个钱包`
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
console.log(`⚠️ 授权交易未确认`);
|
|
108
|
-
return {
|
|
109
|
-
success: false,
|
|
110
|
-
approvedCount: 0,
|
|
111
|
-
bundleHash: bundleResult.bundleHash,
|
|
112
|
-
message: '授权交易未确认'
|
|
113
|
-
};
|
|
114
|
-
}
|
|
102
|
+
// ✅ 只返回签名交易,不提交到 Merkle
|
|
103
|
+
return {
|
|
104
|
+
signedTransactions: signedTxs,
|
|
105
|
+
approvedCount: signedTxs.length,
|
|
106
|
+
skippedCount: skippedCount,
|
|
107
|
+
message: `已生成 ${signedTxs.length} 个授权交易签名,跳过 ${skippedCount} 个已授权钱包`
|
|
108
|
+
};
|
|
115
109
|
}
|