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.
- package/dist/xlayer/wash-ops.js +30 -34
- package/package.json +1 -1
package/dist/xlayer/wash-ops.js
CHANGED
|
@@ -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,
|
|
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
|
|
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
|
-
|
|
275
|
-
|
|
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
|
-
|
|
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
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
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 =
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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
|