four-flap-meme-sdk 1.3.56 → 1.3.58
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.
|
@@ -327,8 +327,9 @@ async function ensureSellerApproval({ tokenAddress, seller, provider, decimals,
|
|
|
327
327
|
}
|
|
328
328
|
const erc20Contract = new Contract(tokenAddress, ERC20_ALLOWANCE_ABI, provider);
|
|
329
329
|
const currentAllowance = await erc20Contract.allowance(seller.address, PANCAKE_PROXY_ADDRESS);
|
|
330
|
-
|
|
331
|
-
|
|
330
|
+
// ✅ 阈值:MaxUint256 / 2,如果授权额度超过这个值,认为是"无限授权"
|
|
331
|
+
const halfMaxUint = ethers.MaxUint256 / 2n;
|
|
332
|
+
if (currentAllowance >= halfMaxUint) {
|
|
332
333
|
return null;
|
|
333
334
|
}
|
|
334
335
|
const approvalNonce = await nonceManager.getNextNonce(seller);
|
|
@@ -7,20 +7,20 @@ function createPancakeContext(config) {
|
|
|
7
7
|
});
|
|
8
8
|
return { chainId, provider };
|
|
9
9
|
}
|
|
10
|
-
async function ensureSellerApproval({ tokenAddress, seller, provider, decimals, chainId, config }) {
|
|
10
|
+
async function ensureSellerApproval({ tokenAddress, seller, provider, decimals, chainId, config, nonceManager, gasPrice, txType }) {
|
|
11
11
|
if (config.skipApprovalCheck) {
|
|
12
12
|
return null;
|
|
13
13
|
}
|
|
14
14
|
const erc20 = new Contract(tokenAddress, ERC20_ALLOWANCE_ABI, provider);
|
|
15
15
|
const currentAllowance = await erc20.allowance(seller.address, PANCAKE_PROXY_ADDRESS);
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
// ✅ 阈值:MaxUint256 / 2,如果授权额度超过这个值,认为是"无限授权"
|
|
17
|
+
// 这样可以检测到用户之前的 MaxUint256 授权
|
|
18
|
+
const halfMaxUint = ethers.MaxUint256 / 2n;
|
|
19
|
+
if (currentAllowance >= halfMaxUint) {
|
|
18
20
|
return null;
|
|
19
21
|
}
|
|
20
|
-
|
|
22
|
+
// ✅ 使用共享的 NonceManager
|
|
21
23
|
const approvalNonce = await nonceManager.getNextNonce(seller);
|
|
22
|
-
const gasPrice = await getGasPrice(provider, config);
|
|
23
|
-
const txType = config.txType ?? 0;
|
|
24
24
|
return await seller.signTransaction({
|
|
25
25
|
to: tokenAddress,
|
|
26
26
|
data: APPROVE_INTERFACE.encodeFunctionData('approve', [PANCAKE_PROXY_ADDRESS, ethers.MaxUint256]),
|
|
@@ -332,14 +332,23 @@ export async function pancakeBundleSwapMerkle(params) {
|
|
|
332
332
|
const seller = new Wallet(sellerPrivateKey, context.provider);
|
|
333
333
|
const buyer = new Wallet(buyerPrivateKey, context.provider);
|
|
334
334
|
const sameAddress = seller.address.toLowerCase() === buyer.address.toLowerCase();
|
|
335
|
+
// ✅ 提前创建 NonceManager 和获取 gasPrice,供所有交易共享
|
|
336
|
+
const nonceManager = new NonceManager(context.provider);
|
|
337
|
+
const finalGasLimit = getGasLimit(config);
|
|
338
|
+
const gasPrice = await getGasPrice(context.provider, config);
|
|
339
|
+
const txType = config.txType ?? 0;
|
|
335
340
|
const { amount: sellAmountWei, decimals } = await calculateSellAmount(context.provider, tokenAddress, seller.address, sellAmount, sellPercentage);
|
|
341
|
+
// ✅ 先构建授权交易(会消耗 nonce)
|
|
336
342
|
const approvalTx = await ensureSellerApproval({
|
|
337
343
|
tokenAddress,
|
|
338
344
|
seller,
|
|
339
345
|
provider: context.provider,
|
|
340
346
|
decimals,
|
|
341
347
|
chainId: context.chainId,
|
|
342
|
-
config
|
|
348
|
+
config,
|
|
349
|
+
nonceManager, // ✅ 共享 NonceManager
|
|
350
|
+
gasPrice,
|
|
351
|
+
txType
|
|
343
352
|
});
|
|
344
353
|
const quoteResult = await quoteSellOutput({
|
|
345
354
|
routeParams,
|
|
@@ -365,11 +374,8 @@ export async function pancakeBundleSwapMerkle(params) {
|
|
|
365
374
|
tokenAddress,
|
|
366
375
|
useNativeToken
|
|
367
376
|
});
|
|
368
|
-
const finalGasLimit = getGasLimit(config);
|
|
369
|
-
const gasPrice = await getGasPrice(context.provider, config);
|
|
370
|
-
const txType = config.txType ?? 0;
|
|
371
377
|
const profitAmount = calculateProfitAmount(quoteResult.estimatedBNBOut);
|
|
372
|
-
|
|
378
|
+
// ✅ 使用共享的 NonceManager 规划 nonce(授权已消耗一个 nonce)
|
|
373
379
|
const noncePlan = await planNonces({
|
|
374
380
|
seller,
|
|
375
381
|
buyer,
|