four-flap-meme-sdk 1.6.69 → 1.6.70

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, 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,21 +266,30 @@ export async function buildWashOps(params) {
266
266
  });
267
267
  }
268
268
  else if (poolType === 'v3') {
269
- // ✅ V3 使用 slot0 现货价计算预期代币输出(与 dex-bundle-swap 保持一致)
269
+ // ✅ V3 报价:使用 V2 Router 的报价(因为卖出使用 V2 Router 聚合路由)
270
+ // V2 Router 会自动聚合路由到最优池子(包括 V3 池子)
271
+ const dexQuery = new DexQuery({ rpcUrl: config.rpcUrl, routerAddress: POTATOSWAP_V2_ROUTER, wokbAddress: wokb });
270
272
  expectedTokenAmounts = await mapWithConcurrency(buyWeiList, 4, async (buyWei) => {
271
273
  if (buyWei <= 0n)
272
274
  return 0n;
273
275
  try {
274
- const quoted = await quoteV3BuyViaSlot0({
275
- rpcUrl: config.rpcUrl,
276
- tokenAddress: params.tokenAddress,
277
- wokbAmount: buyWei,
278
- fee: v3Fee,
279
- });
280
- return quoted;
276
+ // 使用 V2 Router 的报价,反映实际聚合路由路径
277
+ return await dexQuery.quoteOkbToToken(buyWei, params.tokenAddress);
281
278
  }
282
279
  catch {
283
- return 0n;
280
+ // 降级:使用 slot0 现货价,应用 5% 安全边际
281
+ try {
282
+ const slotQuoted = await quoteV3BuyViaSlot0({
283
+ rpcUrl: config.rpcUrl,
284
+ tokenAddress: params.tokenAddress,
285
+ wokbAmount: buyWei,
286
+ fee: v3Fee,
287
+ });
288
+ return (slotQuoted * 95n) / 100n;
289
+ }
290
+ catch {
291
+ return 0n;
292
+ }
284
293
  }
285
294
  });
286
295
  }
@@ -326,31 +335,18 @@ export async function buildWashOps(params) {
326
335
  sellCallData = encodeExecute(portal, 0n, sellSwapData);
327
336
  }
328
337
  else if (poolType === 'v3') {
329
- const buySwapData = encodeSwapExactETHForTokensV3({
330
- tokenIn: wokb,
331
- tokenOut: params.tokenAddress,
332
- fee: v3Fee,
333
- recipient: sender, // ✅ 使用已验证的 sender 变量
334
- deadline,
335
- amountIn: buyWei,
336
- amountOutMinimum: 0n,
337
- sqrtPriceLimitX96: 0n,
338
- });
339
- buyCallData = encodeExecute(routerAddress, buyWei, buySwapData);
338
+ // V3 买入:改用 V2 Router(V2 Router 会自动聚合路由到 V3 池子)
339
+ // 这样买入和卖出都使用同一个路由器,报价也一致
340
+ const buySwapData = encodeSwapExactETHForTokensSupportingFee(0n, [wokb, params.tokenAddress], sender, // ✅ 使用已验证的 sender 变量
341
+ deadline);
342
+ buyCallData = encodeExecute(POTATOSWAP_V2_ROUTER, buyWei, buySwapData);
343
+ // ✅ V3 卖出:改用 V2 Router(V2 Router 会自动聚合路由到 V3 池子)
344
+ // 这样只需要授权给 V2 Router,不需要额外授权给 V3 Router
340
345
  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);
346
+ const sellSwapData = encodeSwapExactTokensForETHSupportingFee(expectedTokenAmount, 0n, [params.tokenAddress, wokb], sender, // ✅ 使用已验证的 sender 变量
347
+ deadline);
348
+ // 使用 V2 Router 地址进行卖出
349
+ sellCallData = encodeExecute(POTATOSWAP_V2_ROUTER, 0n, sellSwapData);
354
350
  }
355
351
  else {
356
352
  // 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.70",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",