four-flap-meme-sdk 1.3.44 → 1.3.46

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,30 +82,31 @@ const V2_ROUTER_ABI = [
82
82
  /**
83
83
  * SwapRouter02 的 V2 方法 ABI (PotatoSwap)
84
84
  *
85
- * 重要:SwapRouter02 V2 方法只有:
85
+ * 根据官方文档,SwapRouter02 支持完整的 V2 方法:
86
86
  * - swapExactTokensForTokens(amountIn, amountOutMin, path[], to)
87
+ * - swapExactETHForTokens(amountOutMin, path[], to) - ETH 换代币,自动 wrap
88
+ * - swapExactTokensForETH(amountIn, amountOutMin, path[], to) - 代币换 ETH,自动 unwrap
87
89
  * - swapTokensForExactTokens(amountOut, amountInMax, path[], to)
88
- *
89
- * 没有 swapExactETHForTokens / swapExactTokensForETH!
90
- * 需要手动处理 ETH/WETH 转换:
91
- * - 买入(ETH->Token): wrapETH + swapExactTokensForTokens
92
- * - 卖出(Token->ETH): swapExactTokensForTokens(to=ADDRESS_THIS) + unwrapWETH9
90
+ * - swapTokensForExactETH(amountOut, amountInMax, path[], to)
91
+ * - swapETHForExactTokens(amountOut, path[], to)
93
92
  */
94
93
  const SWAP_ROUTER02_V2_ABI = [
95
- // V2 交换方法(只有 token-to-token)
94
+ // V2 交换方法 - 精确输入
96
95
  'function swapExactTokensForTokens(uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to) external payable returns (uint256 amountOut)',
96
+ 'function swapExactETHForTokens(uint256 amountOutMin, address[] calldata path, address to) external payable returns (uint256 amountOut)',
97
+ 'function swapExactTokensForETH(uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to) external payable returns (uint256 amountOut)',
98
+ // V2 交换方法 - 精确输出
97
99
  'function swapTokensForExactTokens(uint256 amountOut, uint256 amountInMax, address[] calldata path, address to) external payable returns (uint256 amountIn)',
100
+ 'function swapTokensForExactETH(uint256 amountOut, uint256 amountInMax, address[] calldata path, address to) external payable returns (uint256 amountIn)',
101
+ 'function swapETHForExactTokens(uint256 amountOut, address[] calldata path, address to) external payable returns (uint256 amountIn)',
98
102
  // Multicall - 多种重载
99
103
  'function multicall(uint256 deadline, bytes[] calldata data) external payable returns (bytes[] memory results)',
100
104
  'function multicall(bytes[] calldata data) external payable returns (bytes[] memory results)',
101
- // 辅助方法 - ETH/WETH 转换
105
+ // 辅助方法
102
106
  'function wrapETH(uint256 value) external payable',
103
107
  'function unwrapWETH9(uint256 amountMinimum, address recipient) external payable',
104
108
  'function unwrapWETH9(uint256 amountMinimum) external payable',
105
109
  'function refundETH() external payable',
106
- // pull 方法 - 从用户拉取代币到 Router
107
- 'function pull(address token, uint256 value) external payable',
108
- // sweepToken - 将 Router 中的代币发送给用户
109
110
  'function sweepToken(address token, uint256 amountMinimum, address recipient) external payable',
110
111
  'function sweepToken(address token, uint256 amountMinimum) external payable',
111
112
  ];
@@ -326,25 +327,22 @@ export async function directV2BatchBuy(params) {
326
327
  let txData;
327
328
  let txValue;
328
329
  if (useSwapRouter02) {
329
- // ✅ SwapRouter02: 只有 swapExactTokensForTokens,需要手动处理 ETH wrap
330
- // 文档:没有 swapExactETHForTokens / swapExactTokensForETH
331
- const multicallData = [];
330
+ // ✅ SwapRouter02: 使用官方文档的 V2 方法
332
331
  if (useNative) {
333
- // ETH -> 代币:
334
- // 1. wrapETH(msg.value) - ETH 转为 WETH
335
- // 2. swapExactTokensForTokens(WETH -> Token)
336
- const wrapData = routerIface.encodeFunctionData('wrapETH', [amountWei]);
337
- multicallData.push(wrapData);
338
- const swapData = routerIface.encodeFunctionData('swapExactTokensForTokens', [
339
- amountWei,
332
+ // ETH -> 代币:使用 swapExactETHForTokens
333
+ // msg.value ETH 会自动包装为 WETH
334
+ // path 第一个元素必须是 WETH
335
+ const swapData = routerIface.encodeFunctionData('swapExactETHForTokens', [
340
336
  0n, // amountOutMin
341
337
  path, // path: [WETH, ..., tokenOut]
342
338
  wallet.address, // to
343
339
  ]);
344
- multicallData.push(swapData);
345
- // refundETH - 退回多余的 ETH(如果有)
346
- const refundData = routerIface.encodeFunctionData('refundETH', []);
347
- multicallData.push(refundData);
340
+ // 使用 multicall 包装,传递 deadline
341
+ txData = routerIface.encodeFunctionData('multicall(uint256,bytes[])', [
342
+ deadline,
343
+ [swapData],
344
+ ]);
345
+ txValue = amountWei;
348
346
  }
349
347
  else {
350
348
  // 代币 -> 代币:直接 swapExactTokensForTokens
@@ -354,14 +352,12 @@ export async function directV2BatchBuy(params) {
354
352
  path,
355
353
  wallet.address, // to
356
354
  ]);
357
- multicallData.push(swapData);
355
+ txData = routerIface.encodeFunctionData('multicall(uint256,bytes[])', [
356
+ deadline,
357
+ [swapData],
358
+ ]);
359
+ txValue = 0n;
358
360
  }
359
- // 使用 multicall 包装,传递 deadline
360
- txData = routerIface.encodeFunctionData('multicall(uint256,bytes[])', [
361
- deadline,
362
- multicallData,
363
- ]);
364
- txValue = useNative ? amountWei : 0n;
365
361
  }
366
362
  else if (useNative) {
367
363
  // 传统 V2 Router: 原生币 → Token
@@ -488,46 +484,36 @@ export async function directV2BatchSell(params) {
488
484
  // 卖出交易
489
485
  let txData;
490
486
  if (useSwapRouter02) {
491
- // ✅ SwapRouter02: 只有 swapExactTokensForTokens,需要手动处理 ETH unwrap
492
- const router02Iface = new ethers.Interface(SWAP_ROUTER02_V2_ABI);
493
- const multicallData = [];
494
- // SwapRouter02 特殊地址约定:
495
- // address(1) = ADDRESS_THIS = Router 合约自己
496
- // address(2) = MSG_SENDER = 调用者
497
- const ADDRESS_THIS = '0x0000000000000000000000000000000000000001'; // Router 自己
487
+ // ✅ SwapRouter02: 使用官方文档的 V2 方法
498
488
  if (useNativeOutput) {
499
- // 代币 -> ETH
500
- // 1. swapExactTokensForTokens(token -> WETH, to = ADDRESS_THIS)
501
- // 2. unwrapWETH9(WETH -> ETH, to = 用户)
502
- const swapData = router02Iface.encodeFunctionData('swapExactTokensForTokens', [
489
+ // 代币 -> ETH:使用 swapExactTokensForETH
490
+ // path 最后一个元素必须是 WETH
491
+ // 最终 WETH 会自动解包为 ETH 发送给 to
492
+ const swapData = routerIface.encodeFunctionData('swapExactTokensForETH', [
503
493
  sellAmount,
504
494
  0n, // amountOutMin
505
495
  path, // path: [token, ..., WETH]
506
- ADDRESS_THIS, // to = Router 自己,WETH 留在 Router 中
496
+ wallet.address, // to
507
497
  ]);
508
- multicallData.push(swapData);
509
- // unwrap WETH -> ETH 发送给用户
510
- const unwrapData = router02Iface.encodeFunctionData('unwrapWETH9(uint256,address)', [
511
- 0n, // amountMinimum
512
- wallet.address, // recipient = 用户
498
+ // 使用 multicall 包装,传递 deadline
499
+ txData = routerIface.encodeFunctionData('multicall(uint256,bytes[])', [
500
+ deadline,
501
+ [swapData],
513
502
  ]);
514
- multicallData.push(unwrapData);
515
503
  }
516
504
  else {
517
505
  // 代币 -> 代币:直接 swapExactTokensForTokens
518
- const swapData = router02Iface.encodeFunctionData('swapExactTokensForTokens', [
506
+ const swapData = routerIface.encodeFunctionData('swapExactTokensForTokens', [
519
507
  sellAmount,
520
508
  0n, // amountOutMin
521
509
  path,
522
510
  wallet.address, // to
523
511
  ]);
524
- multicallData.push(swapData);
512
+ txData = routerIface.encodeFunctionData('multicall(uint256,bytes[])', [
513
+ deadline,
514
+ [swapData],
515
+ ]);
525
516
  }
526
- // 使用 multicall 包装,传递 deadline
527
- txData = router02Iface.encodeFunctionData('multicall(uint256,bytes[])', [
528
- deadline,
529
- multicallData,
530
- ]);
531
517
  }
532
518
  else if (useNativeOutput) {
533
519
  txData = routerIface.encodeFunctionData('swapExactTokensForETHSupportingFeeOnTransferTokens', [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.3.44",
3
+ "version": "1.3.46",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",