four-flap-meme-sdk 1.6.69 → 1.6.71

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.
@@ -15,7 +15,7 @@
15
15
  import { ethers } from 'ethers';
16
16
  import { createAAAccountManager, encodeExecute, createWallet } from './aa-account.js';
17
17
  import { encodeBuyCall, encodeSellCall, PortalQuery, lpFeeProfileToV3Fee } from './portal-ops.js';
18
- import { encodeSwapExactETHForTokensSupportingFee, encodeSwapExactTokensForETHSupportingFee, encodeSwapExactETHForTokensV3, encodeSwapExactTokensForETHV3, DexQuery, } from './dex.js';
18
+ import { encodeSwapExactETHForTokensSupportingFee, encodeSwapExactTokensForETHSupportingFee, encodeSwapExactETHForTokensV3, DexQuery, } from './dex.js';
19
19
  import { FLAP_PORTAL, WOKB, XLAYER_CHAIN_ID, DEFAULT_RPC_URL, ENTRYPOINT_V06, SIMPLE_ACCOUNT_FACTORY, PARTICLE_BUNDLER_URL, POTATOSWAP_V2_ROUTER, POTATOSWAP_V3_ROUTER, POTATOSWAP_V3_FACTORY, } from './constants.js';
20
20
  import { PROFIT_CONFIG, ZERO_ADDRESS } from '../utils/constants.js';
21
21
  import { mapWithConcurrency } from '../utils/concurrency.js';
@@ -266,18 +266,19 @@ export async function buildWashOps(params) {
266
266
  });
267
267
  }
268
268
  else if (poolType === 'v3') {
269
- // ✅ V3 使用 slot0 现货价计算预期代币输出(与 dex-bundle-swap 保持一致)
269
+ // ✅ V3 报价:使用 slot0 现货价(因为买入使用 V3 Router)
270
270
  expectedTokenAmounts = await mapWithConcurrency(buyWeiList, 4, async (buyWei) => {
271
271
  if (buyWei <= 0n)
272
272
  return 0n;
273
273
  try {
274
- const quoted = await quoteV3BuyViaSlot0({
274
+ // 使用 slot0 现货价,应用 5% 安全边际(考虑价格影响)
275
+ const slotQuoted = await quoteV3BuyViaSlot0({
275
276
  rpcUrl: config.rpcUrl,
276
277
  tokenAddress: params.tokenAddress,
277
278
  wokbAmount: buyWei,
278
279
  fee: v3Fee,
279
280
  });
280
- return quoted;
281
+ return (slotQuoted * 95n) / 100n;
281
282
  }
282
283
  catch {
283
284
  return 0n;
@@ -326,31 +327,23 @@ export async function buildWashOps(params) {
326
327
  sellCallData = encodeExecute(portal, 0n, sellSwapData);
327
328
  }
328
329
  else if (poolType === 'v3') {
330
+ // ✅ V3 买入:使用 V3 Router 直接调用(买入不需要代币授权)
329
331
  const buySwapData = encodeSwapExactETHForTokensV3({
330
332
  tokenIn: wokb,
331
333
  tokenOut: params.tokenAddress,
332
334
  fee: v3Fee,
333
- recipient: sender, // ✅ 使用已验证的 sender 变量
335
+ recipient: sender,
334
336
  deadline,
335
337
  amountIn: buyWei,
336
338
  amountOutMinimum: 0n,
337
339
  sqrtPriceLimitX96: 0n,
338
340
  });
339
341
  buyCallData = encodeExecute(routerAddress, buyWei, buySwapData);
342
+ // ✅ V3 卖出:使用 V2 Router(V2 Router 会聚合路由到 V3 池子,和正常卖出一样)
343
+ // 这样只需要授权给 V2 Router,不需要额外授权给 V3 Router
340
344
  const expectedTokenAmount = expectedTokenAmounts[i] || 0n;
341
- const sellSwapData = encodeSwapExactTokensForETHV3({
342
- tokenIn: params.tokenAddress,
343
- tokenOut: wokb,
344
- fee: v3Fee,
345
- recipient: sender, // ✅ 使用已验证的 sender 变量
346
- unwrapRecipient: sender, // ✅ 使用已验证的 sender 变量
347
- routerAddress, // ✅ 传递正确的 Router 地址
348
- deadline,
349
- amountIn: expectedTokenAmount,
350
- amountOutMinimum: 0n,
351
- sqrtPriceLimitX96: 0n,
352
- });
353
- sellCallData = encodeExecute(routerAddress, 0n, sellSwapData);
345
+ const sellSwapData = encodeSwapExactTokensForETHSupportingFee(expectedTokenAmount, 0n, [params.tokenAddress, wokb], sender, deadline);
346
+ sellCallData = encodeExecute(POTATOSWAP_V2_ROUTER, 0n, sellSwapData);
354
347
  }
355
348
  else {
356
349
  // V2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.6.69",
3
+ "version": "1.6.71",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",