four-flap-meme-sdk 1.1.92 → 1.1.94
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.
- package/dist/contracts/tm-bundle-merkle/approve-tokenmanager.d.ts +8 -1
- package/dist/contracts/tm-bundle-merkle/approve-tokenmanager.js +48 -13
- package/dist/contracts/tm-bundle-merkle/core.js +2 -2
- package/dist/contracts/tm-bundle-merkle/pancake-proxy.js +44 -10
- package/dist/contracts/tm-bundle-merkle/private.js +2 -2
- package/dist/contracts/tm-bundle-merkle/types.d.ts +7 -2
- package/dist/flap/portal-bundle-merkle/pancake-proxy.js +44 -10
- package/dist/flap/portal-bundle-merkle/types.d.ts +7 -2
- package/package.json +1 -1
|
@@ -5,13 +5,20 @@ export type ApproveFourTokenManagerBatchParams = {
|
|
|
5
5
|
config: {
|
|
6
6
|
apiKey: string;
|
|
7
7
|
customRpcUrl?: string;
|
|
8
|
+
chainId?: number;
|
|
9
|
+
bundleBlockOffset?: number;
|
|
8
10
|
gasLimit?: number | bigint;
|
|
9
11
|
gasLimitMultiplier?: number;
|
|
12
|
+
gasPriceMultiplierPercent?: number;
|
|
13
|
+
minGasPriceGwei?: number;
|
|
10
14
|
txType?: 0 | 2;
|
|
11
15
|
};
|
|
12
16
|
};
|
|
13
17
|
export type ApproveFourTokenManagerBatchResult = {
|
|
14
|
-
|
|
18
|
+
success: boolean;
|
|
19
|
+
approvedCount: number;
|
|
20
|
+
bundleHash?: string;
|
|
21
|
+
message: string;
|
|
15
22
|
};
|
|
16
23
|
/**
|
|
17
24
|
* 批量授权代币给 TokenManager(用于 Private Buy/Sell)
|
|
@@ -21,9 +21,10 @@ export async function approveFourTokenManagerBatch(params) {
|
|
|
21
21
|
throw new Error('Private key count and amount count must match');
|
|
22
22
|
}
|
|
23
23
|
const tmAddr = ADDRESSES.BSC.TokenManagerOriginal;
|
|
24
|
+
const chainId = config.chainId ?? 56;
|
|
24
25
|
const merkle = new MerkleClient({
|
|
25
26
|
apiKey: config.apiKey,
|
|
26
|
-
chainId:
|
|
27
|
+
chainId: chainId,
|
|
27
28
|
customRpcUrl: config.customRpcUrl
|
|
28
29
|
});
|
|
29
30
|
const provider = merkle.getProvider();
|
|
@@ -44,19 +45,26 @@ export async function approveFourTokenManagerBatch(params) {
|
|
|
44
45
|
console.log(` - 需要授权: ${needApproval.length}`);
|
|
45
46
|
console.log(` - 已有授权: ${wallets.length - needApproval.length}`);
|
|
46
47
|
if (needApproval.length === 0) {
|
|
47
|
-
|
|
48
|
-
console.log(`✅ 所有钱包已授权给 TokenManager`);
|
|
48
|
+
console.log('✅ 所有钱包已授权,无需再次授权。');
|
|
49
49
|
return {
|
|
50
|
-
|
|
50
|
+
success: true,
|
|
51
|
+
approvedCount: 0,
|
|
52
|
+
message: '所有钱包已授权'
|
|
51
53
|
};
|
|
52
54
|
}
|
|
53
55
|
// 构建授权交易
|
|
54
56
|
const needApprovalTokens = needApproval.map(w => new ethers.Contract(tokenAddress, ERC20_ABI, w));
|
|
55
57
|
const unsignedApprovals = await Promise.all(needApprovalTokens.map((token, i) => token.approve.populateTransaction(tmAddr, needApprovalAmounts[i])));
|
|
56
|
-
//
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
// 使用前端传入的 gasLimit,否则使用默认值
|
|
59
|
+
const getGasLimit = (cfg) => {
|
|
60
|
+
if (cfg.gasLimit)
|
|
61
|
+
return BigInt(cfg.gasLimit);
|
|
62
|
+
if (cfg.gasLimitMultiplier)
|
|
63
|
+
return BigInt(Math.ceil(21000 * cfg.gasLimitMultiplier));
|
|
64
|
+
return 21000n; // 默认授权 gas limit
|
|
65
|
+
};
|
|
66
|
+
const finalGasLimit = getGasLimit(config);
|
|
67
|
+
// 签名授权交易
|
|
60
68
|
const nonceManager = new NonceManager(provider);
|
|
61
69
|
const nonces = await Promise.all(needApproval.map(w => nonceManager.getNextNonce(w)));
|
|
62
70
|
const signedTxs = await Promise.all(unsignedApprovals.map((unsigned, i) => needApproval[i].signTransaction({
|
|
@@ -65,13 +73,40 @@ export async function approveFourTokenManagerBatch(params) {
|
|
|
65
73
|
nonce: nonces[i],
|
|
66
74
|
gasLimit: finalGasLimit,
|
|
67
75
|
gasPrice,
|
|
68
|
-
chainId
|
|
76
|
+
chainId,
|
|
69
77
|
type: getTxType(config)
|
|
70
78
|
})));
|
|
71
79
|
nonceManager.clearTemp();
|
|
72
80
|
console.log(`✅ 已生成 ${signedTxs.length} 个授权交易签名`);
|
|
73
|
-
// ✅
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
81
|
+
// ✅ 内部提交到 Merkle
|
|
82
|
+
const currentBlock = await provider.getBlockNumber();
|
|
83
|
+
const targetBlock = currentBlock + (config.bundleBlockOffset ?? 2);
|
|
84
|
+
console.log(`📤 正在提交授权交易到 Merkle...`);
|
|
85
|
+
const bundleResult = await merkle.sendBundle({
|
|
86
|
+
transactions: signedTxs,
|
|
87
|
+
targetBlock: targetBlock
|
|
88
|
+
});
|
|
89
|
+
console.log(`✅ 授权交易已提交,bundleHash: ${bundleResult.bundleHash}`);
|
|
90
|
+
// ✅ 等待授权确认
|
|
91
|
+
console.log(`⏳ 等待授权交易确认(约5-10秒)...`);
|
|
92
|
+
const confirmResults = await merkle.waitForBundleConfirmation(bundleResult.txHashes, 1, 60000);
|
|
93
|
+
const successCount = confirmResults.filter(r => r.success).length;
|
|
94
|
+
if (successCount > 0) {
|
|
95
|
+
console.log(`✅ 授权已确认,共 ${successCount} 笔交易成功`);
|
|
96
|
+
return {
|
|
97
|
+
success: true,
|
|
98
|
+
approvedCount: successCount,
|
|
99
|
+
bundleHash: bundleResult.bundleHash,
|
|
100
|
+
message: `授权成功,共 ${successCount} 个钱包`
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
console.log(`⚠️ 授权交易未确认`);
|
|
105
|
+
return {
|
|
106
|
+
success: false,
|
|
107
|
+
approvedCount: 0,
|
|
108
|
+
bundleHash: bundleResult.bundleHash,
|
|
109
|
+
message: '授权交易未确认'
|
|
110
|
+
};
|
|
111
|
+
}
|
|
77
112
|
}
|
|
@@ -4,6 +4,7 @@ import { NonceManager, getOptimizedGasPrice } from '../../utils/bundle-helpers.j
|
|
|
4
4
|
import { ADDRESSES } from '../../utils/constants.js';
|
|
5
5
|
import { FourClient, buildLoginMessage } from '../../clients/four.js';
|
|
6
6
|
import { getErrorMessage, getTxType, getGasPriceConfig, shouldExtractProfit, calculateProfit } from './config.js';
|
|
7
|
+
import { batchCheckAllowances } from '../../utils/erc20.js';
|
|
7
8
|
// ==================== TokenManager2 ABI(仅需要的方法)====================
|
|
8
9
|
const TM2_ABI = [
|
|
9
10
|
'function createToken(bytes args, bytes signature) payable',
|
|
@@ -335,7 +336,6 @@ export async function batchSellWithBundleMerkle(params) {
|
|
|
335
336
|
'function allowance(address owner, address spender) view returns (uint256)'
|
|
336
337
|
];
|
|
337
338
|
console.log('🔍 使用 Multicall3 批量检查授权状态...');
|
|
338
|
-
const { batchCheckAllowances } = await import('../../utils/erc20.js');
|
|
339
339
|
const allowances = await batchCheckAllowances(provider, tokenAddress, sellers.map(w => w.address), tmAddr);
|
|
340
340
|
// 找出需要授权的钱包索引
|
|
341
341
|
// 使用 MaxUint256 的一半作为阈值,确保能处理超大供应量代币
|
|
@@ -352,7 +352,7 @@ export async function batchSellWithBundleMerkle(params) {
|
|
|
352
352
|
// ✅ Step 2: 批量授权(如果需要)
|
|
353
353
|
// ⚠️ 注意:授权需要单独提交,SDK只返回签名交易
|
|
354
354
|
if (needApprovalIndexes.length > 0) {
|
|
355
|
-
console.log(
|
|
355
|
+
console.log(`⚠️ 警告:检测到 ${needApprovalIndexes.length} 个钱包需要授权`);
|
|
356
356
|
console.log(' 请先使用这些钱包的私钥调用授权方法,授权完成后再调用卖出方法');
|
|
357
357
|
throw new Error(`需要授权: ${needApprovalIndexes.length} 个钱包尚未授权。请先完成授权后再卖出。`);
|
|
358
358
|
}
|
|
@@ -3,6 +3,7 @@ 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, getBundleOptions, getGasPriceConfig, shouldExtractProfit, calculateProfit, calculateBatchProfit } from './config.js';
|
|
6
|
+
import { batchCheckAllowances } from '../../utils/erc20.js';
|
|
6
7
|
// 常量
|
|
7
8
|
const WBNB_ADDRESS = '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c';
|
|
8
9
|
const FLAT_FEE = ethers.parseEther('0.0001'); // 合约固定手续费
|
|
@@ -215,18 +216,24 @@ export async function approveFourPancakeProxyBatch(params) {
|
|
|
215
216
|
// 只授权不足的
|
|
216
217
|
const needApproval = wallets.filter((_, i) => allowances[i] < amountsBigInt[i]);
|
|
217
218
|
const needApprovalAmounts = amountsBigInt.filter((amount, i) => allowances[i] < amount);
|
|
219
|
+
console.log(`🔍 PancakeProxy 授权检查:`);
|
|
220
|
+
console.log(` - 总钱包数: ${wallets.length}`);
|
|
221
|
+
console.log(` - 需要授权: ${needApproval.length}`);
|
|
222
|
+
console.log(` - 已有授权: ${wallets.length - needApproval.length}`);
|
|
218
223
|
if (needApproval.length === 0) {
|
|
219
|
-
|
|
224
|
+
console.log('✅ 所有钱包已授权,无需再次授权。');
|
|
220
225
|
return {
|
|
221
|
-
|
|
226
|
+
success: true,
|
|
227
|
+
approvedCount: 0,
|
|
228
|
+
message: '所有钱包已授权'
|
|
222
229
|
};
|
|
223
230
|
}
|
|
224
231
|
// 构建授权交易
|
|
225
232
|
const needApprovalTokens = needApproval.map(w => new Contract(tokenAddress, ERC20_ABI, w));
|
|
226
233
|
const unsignedApprovals = await Promise.all(needApprovalTokens.map((token, i) => token.approve.populateTransaction(pancakeProxyAddress, needApprovalAmounts[i])));
|
|
227
|
-
//
|
|
234
|
+
// 使用前端传入的 gasLimit,否则使用默认值
|
|
228
235
|
const finalGasLimit = getGasLimit(config);
|
|
229
|
-
//
|
|
236
|
+
// 签名授权交易
|
|
230
237
|
const nonceManager = new NonceManager(provider);
|
|
231
238
|
const nonces = await Promise.all(needApproval.map(w => nonceManager.getNextNonce(w)));
|
|
232
239
|
const signedTxs = await Promise.all(unsignedApprovals.map((unsigned, i) => needApproval[i].signTransaction({
|
|
@@ -239,10 +246,38 @@ export async function approveFourPancakeProxyBatch(params) {
|
|
|
239
246
|
type: getTxType(config)
|
|
240
247
|
})));
|
|
241
248
|
nonceManager.clearTemp();
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
249
|
+
console.log(`✅ 已生成 ${signedTxs.length} 个授权交易签名`);
|
|
250
|
+
// ✅ 内部提交到 Merkle
|
|
251
|
+
const currentBlock = await provider.getBlockNumber();
|
|
252
|
+
const targetBlock = currentBlock + blockOffset;
|
|
253
|
+
console.log(`📤 正在提交授权交易到 Merkle...`);
|
|
254
|
+
const bundleResult = await merkle.sendBundle({
|
|
255
|
+
transactions: signedTxs,
|
|
256
|
+
targetBlock: targetBlock
|
|
257
|
+
});
|
|
258
|
+
console.log(`✅ 授权交易已提交,bundleHash: ${bundleResult.bundleHash}`);
|
|
259
|
+
// ✅ 等待授权确认
|
|
260
|
+
console.log(`⏳ 等待授权交易确认(约5-10秒)...`);
|
|
261
|
+
const confirmResults = await merkle.waitForBundleConfirmation(bundleResult.txHashes, 1, 60000);
|
|
262
|
+
const successCount = confirmResults.filter(r => r.success).length;
|
|
263
|
+
if (successCount > 0) {
|
|
264
|
+
console.log(`✅ 授权已确认,共 ${successCount} 笔交易成功`);
|
|
265
|
+
return {
|
|
266
|
+
success: true,
|
|
267
|
+
approvedCount: successCount,
|
|
268
|
+
bundleHash: bundleResult.bundleHash,
|
|
269
|
+
message: `授权成功,共 ${successCount} 个钱包`
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
console.log(`⚠️ 授权交易未确认`);
|
|
274
|
+
return {
|
|
275
|
+
success: false,
|
|
276
|
+
approvedCount: 0,
|
|
277
|
+
bundleHash: bundleResult.bundleHash,
|
|
278
|
+
message: '授权交易未确认'
|
|
279
|
+
};
|
|
280
|
+
}
|
|
246
281
|
}
|
|
247
282
|
/**
|
|
248
283
|
* 使用 PancakeSwapProxy 批量购买代币(Merkle 版本)
|
|
@@ -364,7 +399,6 @@ export async function fourPancakeProxyBatchSellMerkle(params) {
|
|
|
364
399
|
const amountsWei = sellAmounts.map(a => ethers.parseUnits(a, tokenDecimals));
|
|
365
400
|
// ✅ Step 1: 使用 Multicall3 批量检查授权状态
|
|
366
401
|
console.log('🔍 使用 Multicall3 批量检查授权状态...');
|
|
367
|
-
const { batchCheckAllowances } = await import('../../utils/erc20.js');
|
|
368
402
|
const allowances = await batchCheckAllowances(provider, tokenAddress, sellers.map(w => w.address), pancakeProxyAddress);
|
|
369
403
|
// 找出需要授权的钱包索引
|
|
370
404
|
const needApprovalIndexes = [];
|
|
@@ -380,7 +414,7 @@ export async function fourPancakeProxyBatchSellMerkle(params) {
|
|
|
380
414
|
// ✅ Step 2: 如果需要授权,抛出错误提示
|
|
381
415
|
// ⚠️ SDK不再处理授权,需要前端先单独授权
|
|
382
416
|
if (needApprovalIndexes.length > 0) {
|
|
383
|
-
console.log(
|
|
417
|
+
console.log(`⚠️ 警告:检测到 ${needApprovalIndexes.length} 个钱包需要授权`);
|
|
384
418
|
console.log(' 请先使用这些钱包完成授权后再调用卖出方法');
|
|
385
419
|
throw new Error(`需要授权: ${needApprovalIndexes.length} 个钱包尚未授权。请先完成授权后再卖出。`);
|
|
386
420
|
}
|
|
@@ -3,6 +3,7 @@ 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, shouldExtractProfit, calculateProfit, calculateBatchProfit } from './config.js';
|
|
6
|
+
import { batchCheckAllowances } from '../../utils/erc20.js';
|
|
6
7
|
// ==================== TokenManager2 ABI(仅需要的方法)====================
|
|
7
8
|
const TM2_ABI = [
|
|
8
9
|
'function buyTokenAMAP(uint256 origin, address token, address to, uint256 funds, uint256 minAmount) payable',
|
|
@@ -244,7 +245,6 @@ export async function fourBatchPrivateSellMerkle(params) {
|
|
|
244
245
|
const amountsWei = amounts.map((a) => ethers.parseUnits(a, 18));
|
|
245
246
|
// ✅ Step 1: 使用 Multicall3 批量检查授权状态
|
|
246
247
|
console.log('🔍 使用 Multicall3 批量检查授权状态...');
|
|
247
|
-
const { batchCheckAllowances } = await import('../../utils/erc20.js');
|
|
248
248
|
const allowances = await batchCheckAllowances(provider, tokenAddress, wallets.map(w => w.address), tmAddr);
|
|
249
249
|
// 找出需要授权的钱包索引
|
|
250
250
|
// 使用 MaxUint256 的一半作为阈值,确保能处理超大供应量代币
|
|
@@ -261,7 +261,7 @@ export async function fourBatchPrivateSellMerkle(params) {
|
|
|
261
261
|
// ✅ Step 2: 如果需要授权,抛出错误提示
|
|
262
262
|
// ⚠️ SDK不再处理授权,需要前端先单独授权
|
|
263
263
|
if (needApprovalIndexes.length > 0) {
|
|
264
|
-
console.log(
|
|
264
|
+
console.log(`⚠️ 警告:检测到 ${needApprovalIndexes.length} 个钱包需要授权`);
|
|
265
265
|
console.log(' 请先使用这些钱包完成授权后再调用卖出方法');
|
|
266
266
|
throw new Error(`需要授权: ${needApprovalIndexes.length} 个钱包尚未授权。请先完成授权后再卖出。`);
|
|
267
267
|
}
|
|
@@ -215,5 +215,10 @@ export type FourPancakeProxyApprovalBatchParams = {
|
|
|
215
215
|
amounts: (string | 'max')[];
|
|
216
216
|
config: FourBundleMerkleConfig;
|
|
217
217
|
};
|
|
218
|
-
/** ✅ PancakeProxy
|
|
219
|
-
export type FourPancakeProxyApprovalBatchResult =
|
|
218
|
+
/** ✅ PancakeProxy 批量授权结果 */
|
|
219
|
+
export type FourPancakeProxyApprovalBatchResult = {
|
|
220
|
+
success: boolean;
|
|
221
|
+
approvedCount: number;
|
|
222
|
+
bundleHash?: string;
|
|
223
|
+
message: string;
|
|
224
|
+
};
|
|
@@ -3,6 +3,7 @@ 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 { CHAIN_ID_MAP, getTxType, getBundleOptions, getGasPriceConfig, shouldExtractProfit, calculateProfit, calculateBatchProfit } from './config.js';
|
|
6
|
+
import { batchCheckAllowances } from '../../utils/erc20.js';
|
|
6
7
|
// 常量
|
|
7
8
|
const WBNB_ADDRESS = '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c';
|
|
8
9
|
const FLAT_FEE = ethers.parseEther('0.0001'); // 合约固定手续费
|
|
@@ -216,18 +217,24 @@ export async function approvePancakeProxyBatch(params) {
|
|
|
216
217
|
// 只授权不足的
|
|
217
218
|
const needApproval = wallets.filter((_, i) => allowances[i] < amountsBigInt[i]);
|
|
218
219
|
const needApprovalAmounts = amountsBigInt.filter((amount, i) => allowances[i] < amount);
|
|
220
|
+
console.log(`🔍 PancakeProxy 授权检查:`);
|
|
221
|
+
console.log(` - 总钱包数: ${wallets.length}`);
|
|
222
|
+
console.log(` - 需要授权: ${needApproval.length}`);
|
|
223
|
+
console.log(` - 已有授权: ${wallets.length - needApproval.length}`);
|
|
219
224
|
if (needApproval.length === 0) {
|
|
220
|
-
|
|
225
|
+
console.log('✅ 所有钱包已授权,无需再次授权。');
|
|
221
226
|
return {
|
|
222
|
-
|
|
227
|
+
success: true,
|
|
228
|
+
approvedCount: 0,
|
|
229
|
+
message: '所有钱包已授权'
|
|
223
230
|
};
|
|
224
231
|
}
|
|
225
232
|
// 构建授权交易
|
|
226
233
|
const needApprovalTokens = needApproval.map(w => new Contract(tokenAddress, ERC20_ABI, w));
|
|
227
234
|
const unsignedApprovals = await Promise.all(needApprovalTokens.map((token, i) => token.approve.populateTransaction(pancakeProxyAddress, needApprovalAmounts[i])));
|
|
228
|
-
//
|
|
235
|
+
// 使用前端传入的 gasLimit,否则使用默认值
|
|
229
236
|
const finalGasLimit = getGasLimit(config);
|
|
230
|
-
//
|
|
237
|
+
// 签名授权交易
|
|
231
238
|
const nonceManager = new NonceManager(provider);
|
|
232
239
|
const nonces = await Promise.all(needApproval.map(w => nonceManager.getNextNonce(w)));
|
|
233
240
|
const signedTxs = await Promise.all(unsignedApprovals.map((unsigned, i) => needApproval[i].signTransaction({
|
|
@@ -240,10 +247,38 @@ export async function approvePancakeProxyBatch(params) {
|
|
|
240
247
|
type: getTxType(config)
|
|
241
248
|
})));
|
|
242
249
|
nonceManager.clearTemp();
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
250
|
+
console.log(`✅ 已生成 ${signedTxs.length} 个授权交易签名`);
|
|
251
|
+
// ✅ 内部提交到 Merkle
|
|
252
|
+
const currentBlock = await provider.getBlockNumber();
|
|
253
|
+
const targetBlock = currentBlock + blockOffset;
|
|
254
|
+
console.log(`📤 正在提交授权交易到 Merkle...`);
|
|
255
|
+
const bundleResult = await merkle.sendBundle({
|
|
256
|
+
transactions: signedTxs,
|
|
257
|
+
targetBlock: targetBlock
|
|
258
|
+
});
|
|
259
|
+
console.log(`✅ 授权交易已提交,bundleHash: ${bundleResult.bundleHash}`);
|
|
260
|
+
// ✅ 等待授权确认
|
|
261
|
+
console.log(`⏳ 等待授权交易确认(约5-10秒)...`);
|
|
262
|
+
const confirmResults = await merkle.waitForBundleConfirmation(bundleResult.txHashes, 1, 60000);
|
|
263
|
+
const successCount = confirmResults.filter(r => r.success).length;
|
|
264
|
+
if (successCount > 0) {
|
|
265
|
+
console.log(`✅ 授权已确认,共 ${successCount} 笔交易成功`);
|
|
266
|
+
return {
|
|
267
|
+
success: true,
|
|
268
|
+
approvedCount: successCount,
|
|
269
|
+
bundleHash: bundleResult.bundleHash,
|
|
270
|
+
message: `授权成功,共 ${successCount} 个钱包`
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
console.log(`⚠️ 授权交易未确认`);
|
|
275
|
+
return {
|
|
276
|
+
success: false,
|
|
277
|
+
approvedCount: 0,
|
|
278
|
+
bundleHash: bundleResult.bundleHash,
|
|
279
|
+
message: '授权交易未确认'
|
|
280
|
+
};
|
|
281
|
+
}
|
|
247
282
|
}
|
|
248
283
|
/**
|
|
249
284
|
* 使用 PancakeSwapProxy 批量购买代币(Merkle 版本)
|
|
@@ -367,7 +402,6 @@ export async function pancakeProxyBatchSellMerkle(params) {
|
|
|
367
402
|
const amountsWei = sellAmounts.map(a => ethers.parseUnits(a, tokenDecimals));
|
|
368
403
|
// ✅ Step 1: 使用 Multicall3 批量检查授权状态
|
|
369
404
|
console.log('🔍 使用 Multicall3 批量检查授权状态...');
|
|
370
|
-
const { batchCheckAllowances } = await import('../../utils/erc20.js');
|
|
371
405
|
const allowances = await batchCheckAllowances(provider, tokenAddress, sellers.map(w => w.address), pancakeProxyAddress);
|
|
372
406
|
// 找出需要授权的钱包索引
|
|
373
407
|
const needApprovalIndexes = [];
|
|
@@ -383,7 +417,7 @@ export async function pancakeProxyBatchSellMerkle(params) {
|
|
|
383
417
|
// ✅ Step 2: 如果需要授权,抛出错误提示
|
|
384
418
|
// ⚠️ SDK不再处理授权,需要前端先单独授权
|
|
385
419
|
if (needApprovalIndexes.length > 0) {
|
|
386
|
-
console.log(
|
|
420
|
+
console.log(`⚠️ 警告:检测到 ${needApprovalIndexes.length} 个钱包需要授权`);
|
|
387
421
|
console.log(' 请先使用这些钱包完成授权后再调用卖出方法');
|
|
388
422
|
throw new Error(`需要授权: ${needApprovalIndexes.length} 个钱包尚未授权。请先完成授权后再卖出。`);
|
|
389
423
|
}
|
|
@@ -187,5 +187,10 @@ export type PancakeProxyApprovalBatchParams = {
|
|
|
187
187
|
amounts: (string | 'max')[];
|
|
188
188
|
config: FlapBundleMerkleConfig;
|
|
189
189
|
};
|
|
190
|
-
/** ✅ PancakeProxy
|
|
191
|
-
export type PancakeProxyApprovalBatchResult =
|
|
190
|
+
/** ✅ PancakeProxy 批量授权结果 */
|
|
191
|
+
export type PancakeProxyApprovalBatchResult = {
|
|
192
|
+
success: boolean;
|
|
193
|
+
approvedCount: number;
|
|
194
|
+
bundleHash?: string;
|
|
195
|
+
message: string;
|
|
196
|
+
};
|