four-flap-meme-sdk 1.3.41 → 1.3.43

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.
@@ -82,15 +82,26 @@ const V2_ROUTER_ABI = [
82
82
  /**
83
83
  * SwapRouter02 的 V2 方法 ABI (PotatoSwap, PancakeSwap V3 Router)
84
84
  * SwapRouter02 同时支持 V2 和 V3,V2 方法通过 multicall 调用
85
+ *
86
+ * 注意:SwapRouter02 的 V2SwapRouter 方法签名:
87
+ * - swapExactTokensForTokens(amountIn, amountOutMin, path[], to) - 不含 deadline
88
+ * - 卖出时需要先 approve,Router 会自动 pull 代币
85
89
  */
86
90
  const SWAP_ROUTER02_V2_ABI = [
87
91
  // V2 交换方法 (SwapRouter02 内置)
88
92
  'function swapExactTokensForTokens(uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to) external payable returns (uint256 amountOut)',
89
- // Multicall
93
+ // Multicall - 多种重载
90
94
  'function multicall(uint256 deadline, bytes[] calldata data) external payable returns (bytes[] memory results)',
95
+ 'function multicall(bytes[] calldata data) external payable returns (bytes[] memory results)',
91
96
  // 辅助方法
92
97
  'function refundETH() external payable',
93
98
  'function unwrapWETH9(uint256 amountMinimum, address recipient) external payable',
99
+ 'function unwrapWETH9(uint256 amountMinimum) external payable',
100
+ // pull 方法 - 从用户拉取代币到 Router
101
+ 'function pull(address token, uint256 value) external payable',
102
+ // sweepToken - 将 Router 中的代币发送给用户
103
+ 'function sweepToken(address token, uint256 amountMinimum, address recipient) external payable',
104
+ 'function sweepToken(address token, uint256 amountMinimum) external payable',
94
105
  ];
95
106
  /**
96
107
  * V3 SwapRouter02 ABI (PancakeSwap V3, 新版 Uniswap)
@@ -439,16 +450,30 @@ export async function directV2BatchSell(params) {
439
450
  // 卖出交易
440
451
  let txData;
441
452
  if (useSwapRouter02) {
442
- // ✅ SwapRouter02 V2 方法:使用 multicall 包装
443
- const swapData = routerIface.encodeFunctionData('swapExactTokensForTokens', [
453
+ // ✅ SwapRouter02: 卖出代币换原生币
454
+ // 流程:swapExactTokensForTokens (token -> WETH) + unwrapWETH9 (WETH -> ETH)
455
+ const router02Iface = new ethers.Interface(SWAP_ROUTER02_V2_ABI);
456
+ // 1. swap: token -> WETH (recipient 设为 Router 地址 address(2) 表示 Router 自己)
457
+ const ADDRESS_THIS = '0x0000000000000000000000000000000000000002'; // SwapRouter02 特殊地址,表示 Router 自己
458
+ const swapData = router02Iface.encodeFunctionData('swapExactTokensForTokens', [
444
459
  sellAmount,
445
460
  0n, // amountOutMin
446
461
  path,
447
- wallet.address,
462
+ useNativeOutput ? ADDRESS_THIS : wallet.address, // 如果输出是原生币,先发到 Router
448
463
  ]);
449
- txData = routerIface.encodeFunctionData('multicall', [
464
+ const multicallData = [swapData];
465
+ // 2. 如果输出是原生币,需要 unwrapWETH9
466
+ if (useNativeOutput) {
467
+ const unwrapData = router02Iface.encodeFunctionData('unwrapWETH9(uint256,address)', [
468
+ 0n, // amountMinimum
469
+ wallet.address, // recipient
470
+ ]);
471
+ multicallData.push(unwrapData);
472
+ }
473
+ // 使用 multicall 包装,传递 deadline
474
+ txData = router02Iface.encodeFunctionData('multicall(uint256,bytes[])', [
450
475
  deadline,
451
- [swapData],
476
+ multicallData,
452
477
  ]);
453
478
  }
454
479
  else if (useNativeOutput) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.3.41",
3
+ "version": "1.3.43",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",