four-flap-meme-sdk 1.6.53 → 1.6.54

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.
@@ -10,7 +10,7 @@ import { generateWallets } from './wallet.js';
10
10
  import { NonceManager, getOptimizedGasPrice, buildProfitHopTransactions, PROFIT_HOP_COUNT, getDeadline } from './bundle-helpers.js';
11
11
  import { ADDRESSES, BLOCKRAZOR_BUILDER_EOA, PROFIT_CONFIG } from './constants.js';
12
12
  import { FLAP_PORTAL_ADDRESSES } from '../flap/constants.js';
13
- import { V2_ROUTER_ABI, V3_ROUTER02_ABI, ERC20_ABI } from '../abis/common.js';
13
+ import { V2_ROUTER_ABI, V3_ROUTER02_ABI, V3_ROUTER_LEGACY_ABI, ERC20_ABI } from '../abis/common.js';
14
14
  // Four 内盘 ABI
15
15
  const FOUR_TM2_ABI = [
16
16
  'function buyTokenAMAP(uint256 origin, address token, address to, uint256 funds, uint256 minAmount) payable'
@@ -423,32 +423,59 @@ async function buildV2BuyTx(wallet, tokenAddress, buyAmount, nonce, gasPrice, ga
423
423
  * 构建 V3 单跳买入交易
424
424
  * BNB/OKB → Token (使用 exactInputSingle + multicall)
425
425
  *
426
- * ✅ 修复:使用 ethers.Interface 手动编码 calldata,避免 multicall 重载问题
426
+ * ✅ 修复:根据链类型选择正确的 Router ABI 版本
427
+ * - XLayer/Monad: 旧版 Router(exactInputSingle 包含 deadline,multicall(bytes[]))
428
+ * - BSC: 新版 SwapRouter02(exactInputSingle 不含 deadline,multicall(uint256,bytes[]))
427
429
  */
428
430
  async function buildV3BuyTx(wallet, tokenAddress, buyAmount, nonce, gasPrice, gasLimit, chainId, txType, v3Fee = 2500, // 默认 0.25% 手续费
429
431
  chain) {
430
432
  const deadline = getDeadline();
431
- const v3RouterIface = new ethers.Interface(V3_ROUTER02_ABI);
432
433
  const wrappedNative = getWrappedNativeAddress(chain);
433
434
  const routerAddress = chain === 'XLAYER' ? XLAYER_V3_ROUTER_ADDRESS : PANCAKE_V3_ROUTER_ADDRESS;
434
- // 构建 exactInputSingle calldata
435
- const swapParams = {
436
- tokenIn: wrappedNative,
437
- tokenOut: tokenAddress,
438
- fee: v3Fee,
439
- recipient: wallet.address,
440
- amountIn: buyAmount,
441
- amountOutMinimum: 0n,
442
- sqrtPriceLimitX96: 0n
443
- };
444
- const exactInputSingleData = v3RouterIface.encodeFunctionData('exactInputSingle', [swapParams]);
445
- // ✅ 添加 refundETH,退还多余的 ETH/OKB
446
- const refundETHData = v3RouterIface.encodeFunctionData('refundETH', []);
447
- // ✅ 使用明确的函数签名编码 multicall,避免重载问题
448
- const multicallData = v3RouterIface.encodeFunctionData('multicall(uint256,bytes[])', [
449
- deadline,
450
- [exactInputSingleData, refundETHData]
451
- ]);
435
+ // 根据链类型选择正确的 ABI 版本
436
+ // XLayer/Monad 使用旧版 Router(exactInputSingle 包含 deadline)
437
+ // BSC 使用新版 SwapRouter02(exactInputSingle 不含 deadline)
438
+ const useLegacyRouter = chain === 'XLAYER' || chain === 'MONAD';
439
+ const v3RouterIface = new ethers.Interface(useLegacyRouter ? V3_ROUTER_LEGACY_ABI : V3_ROUTER02_ABI);
440
+ let multicallData;
441
+ if (useLegacyRouter) {
442
+ // ✅ 旧版 Router:swapParams 包含 deadline,multicall(bytes[])
443
+ const swapParams = {
444
+ tokenIn: wrappedNative,
445
+ tokenOut: tokenAddress,
446
+ fee: v3Fee,
447
+ recipient: wallet.address,
448
+ deadline, // ✅ 旧版包含 deadline
449
+ amountIn: buyAmount,
450
+ amountOutMinimum: 0n,
451
+ sqrtPriceLimitX96: 0n
452
+ };
453
+ const exactInputSingleData = v3RouterIface.encodeFunctionData('exactInputSingle', [swapParams]);
454
+ const refundETHData = v3RouterIface.encodeFunctionData('refundETH', []);
455
+ // ✅ 旧版 multicall:只有 bytes[] 参数
456
+ multicallData = v3RouterIface.encodeFunctionData('multicall(bytes[])', [
457
+ [exactInputSingleData, refundETHData]
458
+ ]);
459
+ }
460
+ else {
461
+ // ✅ 新版 SwapRouter02:swapParams 不含 deadline,multicall(uint256,bytes[])
462
+ const swapParams = {
463
+ tokenIn: wrappedNative,
464
+ tokenOut: tokenAddress,
465
+ fee: v3Fee,
466
+ recipient: wallet.address,
467
+ amountIn: buyAmount,
468
+ amountOutMinimum: 0n,
469
+ sqrtPriceLimitX96: 0n
470
+ };
471
+ const exactInputSingleData = v3RouterIface.encodeFunctionData('exactInputSingle', [swapParams]);
472
+ const refundETHData = v3RouterIface.encodeFunctionData('refundETH', []);
473
+ // ✅ 新版 multicall:deadline 作为第一个参数
474
+ multicallData = v3RouterIface.encodeFunctionData('multicall(uint256,bytes[])', [
475
+ deadline,
476
+ [exactInputSingleData, refundETHData]
477
+ ]);
478
+ }
452
479
  const tx = {
453
480
  to: routerAddress,
454
481
  data: multicallData,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.6.53",
3
+ "version": "1.6.54",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",