four-flap-meme-sdk 1.6.70 → 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, 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,30 +266,22 @@ export async function buildWashOps(params) {
266
266
  });
267
267
  }
268
268
  else if (poolType === 'v3') {
269
- // ✅ V3 报价:使用 V2 Router 的报价(因为卖出使用 V2 Router 聚合路由)
270
- // V2 Router 会自动聚合路由到最优池子(包括 V3 池子)
271
- const dexQuery = new DexQuery({ rpcUrl: config.rpcUrl, routerAddress: POTATOSWAP_V2_ROUTER, wokbAddress: wokb });
269
+ // ✅ V3 报价:使用 slot0 现货价(因为买入使用 V3 Router
272
270
  expectedTokenAmounts = await mapWithConcurrency(buyWeiList, 4, async (buyWei) => {
273
271
  if (buyWei <= 0n)
274
272
  return 0n;
275
273
  try {
276
- // 使用 V2 Router 的报价,反映实际聚合路由路径
277
- return await dexQuery.quoteOkbToToken(buyWei, params.tokenAddress);
274
+ // 使用 slot0 现货价,应用 5% 安全边际(考虑价格影响)
275
+ const slotQuoted = await quoteV3BuyViaSlot0({
276
+ rpcUrl: config.rpcUrl,
277
+ tokenAddress: params.tokenAddress,
278
+ wokbAmount: buyWei,
279
+ fee: v3Fee,
280
+ });
281
+ return (slotQuoted * 95n) / 100n;
278
282
  }
279
283
  catch {
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
+ return 0n;
293
285
  }
294
286
  });
295
287
  }
@@ -335,17 +327,22 @@ export async function buildWashOps(params) {
335
327
  sellCallData = encodeExecute(portal, 0n, sellSwapData);
336
328
  }
337
329
  else if (poolType === 'v3') {
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 池子)
330
+ // ✅ V3 买入:使用 V3 Router 直接调用(买入不需要代币授权)
331
+ const buySwapData = encodeSwapExactETHForTokensV3({
332
+ tokenIn: wokb,
333
+ tokenOut: params.tokenAddress,
334
+ fee: v3Fee,
335
+ recipient: sender,
336
+ deadline,
337
+ amountIn: buyWei,
338
+ amountOutMinimum: 0n,
339
+ sqrtPriceLimitX96: 0n,
340
+ });
341
+ buyCallData = encodeExecute(routerAddress, buyWei, buySwapData);
342
+ // ✅ V3 卖出:使用 V2 Router(V2 Router 会聚合路由到 V3 池子,和正常卖出一样)
344
343
  // 这样只需要授权给 V2 Router,不需要额外授权给 V3 Router
345
344
  const expectedTokenAmount = expectedTokenAmounts[i] || 0n;
346
- const sellSwapData = encodeSwapExactTokensForETHSupportingFee(expectedTokenAmount, 0n, [params.tokenAddress, wokb], sender, // ✅ 使用已验证的 sender 变量
347
- deadline);
348
- // 使用 V2 Router 地址进行卖出
345
+ const sellSwapData = encodeSwapExactTokensForETHSupportingFee(expectedTokenAmount, 0n, [params.tokenAddress, wokb], sender, deadline);
349
346
  sellCallData = encodeExecute(POTATOSWAP_V2_ROUTER, 0n, sellSwapData);
350
347
  }
351
348
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.6.70",
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",