four-flap-meme-sdk 1.5.49 → 1.5.50
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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/xlayer/bundle.d.ts +25 -6
- package/dist/xlayer/bundle.js +191 -48
- package/dist/xlayer/index.d.ts +2 -2
- package/dist/xlayer/index.js +5 -5
- package/dist/xlayer/types.d.ts +69 -24
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -53,4 +53,4 @@ export { submitDirectToRpc, submitDirectToRpcSequential, // ✅ 新增:顺序
|
|
|
53
53
|
submitDirectToRpcParallel, type DirectSubmitConfig, type DirectSubmitResult, type DirectTxResult } from './contracts/tm-bundle-merkle/submit.js';
|
|
54
54
|
export { directV2BatchBuy, directV2BatchSell, directV3BatchBuy, directV3BatchSell, getRouterAddress, DIRECT_ROUTERS, type DirectV2BuyParams, type DirectV2SellParams, type DirectV3BuyParams, type DirectV3SellParams, type DirectRouterResult, type DirectRouterSignConfig, type DexKey, type RouterVersion, } from './dex/index.js';
|
|
55
55
|
export * as XLayer from './xlayer/index.js';
|
|
56
|
-
export { bundleBuy as xlayerBundleBuy, bundleSell as xlayerBundleSell, bundleBuySell as xlayerBundleBuySell,
|
|
56
|
+
export { bundleBuy as xlayerBundleBuy, bundleSell as xlayerBundleSell, bundleBuySell as xlayerBundleBuySell, bundleCreateBuySign as xlayerBundleCreateBuySign, bundleCreateToDexSign as xlayerBundleCreateToDexSign, bundleSwapSign as xlayerBundleSwapSign, bundleBatchSwapSign as xlayerBundleBatchSwapSign, createBundleExecutor as xlayerCreateBundleExecutor, BundleExecutor as XLayerBundleExecutor, makeVolume as xlayerMakeVolume, singleRoundVolume as xlayerSingleRoundVolume, createVolumeExecutor as xlayerCreateVolumeExecutor, VolumeExecutor as XLayerVolumeExecutor, makeBuyFirstVolume as xlayerMakeBuyFirstVolume, BuyFirstVolumeExecutor as XLayerBuyFirstVolumeExecutor, AAPortalBuyFirstExecutor as XLayerAAPortalBuyFirstExecutor, AADexBuyFirstExecutor as XLayerAADexBuyFirstExecutor, createDexExecutor as xlayerCreateDexExecutor, createDexQuery as xlayerCreateDexQuery, quoteOkbToToken as xlayerQuoteOkbToToken, quoteTokenToOkb as xlayerQuoteTokenToOkb, DexExecutor as XLayerDexExecutor, DexQuery as XLayerDexQuery, createAAAccountManager as xlayerCreateAAAccountManager, predictSender as xlayerPredictSender, createWallet as xlayerCreateWallet, AAAccountManager as XLayerAAAccountManager, generateAAWallets as xlayerGenerateAAWallets, generateAAWalletsFromMnemonic as xlayerGenerateAAWalletsFromMnemonic, predictSendersFromPrivateKeys as xlayerPredictSendersFromPrivateKeys, createBundlerClient as xlayerCreateBundlerClient, BundlerClient as XLayerBundlerClient, createPortalQuery as xlayerCreatePortalQuery, PortalQuery as XLayerPortalQuery, encodeBuyCall as xlayerEncodeBuyCall, encodeSellCall as xlayerEncodeSellCall, encodeApproveCall as xlayerEncodeApproveCall, parseOkb as xlayerParseOkb, formatOkb as xlayerFormatOkb, XLAYER_CHAIN_ID, FLAP_PORTAL as XLAYER_FLAP_PORTAL, ENTRYPOINT_V06 as XLAYER_ENTRYPOINT, SIMPLE_ACCOUNT_FACTORY as XLAYER_FACTORY, PARTICLE_BUNDLER_URL as XLAYER_BUNDLER_URL, WOKB as XLAYER_WOKB, POTATOSWAP_V2_ROUTER as XLAYER_POTATOSWAP_ROUTER, type XLayerConfig, type BundleBuyParams as XLayerBundleBuyParams, type BundleSellParams as XLayerBundleSellParams, type BundleBuySellParams as XLayerBundleBuySellParams, type BundleSwapParams as XLayerBundleSwapParams, type BundleSwapSignParams as XLayerBundleSwapSignParams, type BundleBatchSwapParams as XLayerBundleBatchSwapParams, type BundleBatchSwapSignParams as XLayerBundleBatchSwapSignParams, type VolumeParams as XLayerVolumeParams, type BundleBuyResult as XLayerBundleBuyResult, type BundleSellResult as XLayerBundleSellResult, type BundleBuySellResult as XLayerBundleBuySellResult, type BundleCreateBuySignParams as XLayerBundleCreateBuySignParams, type BundleCreateBuySignResult as XLayerBundleCreateBuySignResult, type BundleCreateToDexSignParams as XLayerBundleCreateToDexSignParams, type BundleCreateToDexSignResult as XLayerBundleCreateToDexSignResult, type BundleSwapResult as XLayerBundleSwapResult, type BundleSwapSignResult as XLayerBundleSwapSignResult, type BundleBatchSwapResult as XLayerBundleBatchSwapResult, type BundleBatchSwapSignResult as XLayerBundleBatchSwapSignResult, type VolumeResult as XLayerVolumeResult, type BuyFirstParams as XLayerBuyFirstParams, type BuyFirstResult as XLayerBuyFirstResult, type BuyFirstVolumeParams as XLayerBuyFirstVolumeParams, type BuyFirstVolumeResult as XLayerBuyFirstVolumeResult, type HandleOpsResult as XLayerHandleOpsResult, type AAAccount as XLayerAAAccount, type UserOperation as XLayerUserOperation, type GeneratedAAWallet as XLayerGeneratedAAWallet, type GenerateAAWalletsParams as XLayerGenerateAAWalletsParams, type GenerateAAWalletsResult as XLayerGenerateAAWalletsResult, } from './xlayer/index.js';
|
package/dist/index.js
CHANGED
|
@@ -102,7 +102,7 @@ DIRECT_ROUTERS, } from './dex/index.js';
|
|
|
102
102
|
export * as XLayer from './xlayer/index.js';
|
|
103
103
|
export {
|
|
104
104
|
// 捆绑交易
|
|
105
|
-
bundleBuy as xlayerBundleBuy, bundleSell as xlayerBundleSell, bundleBuySell as xlayerBundleBuySell,
|
|
105
|
+
bundleBuy as xlayerBundleBuy, bundleSell as xlayerBundleSell, bundleBuySell as xlayerBundleBuySell, bundleCreateBuySign as xlayerBundleCreateBuySign, bundleCreateToDexSign as xlayerBundleCreateToDexSign, bundleSwapSign as xlayerBundleSwapSign, bundleBatchSwapSign as xlayerBundleBatchSwapSign, createBundleExecutor as xlayerCreateBundleExecutor, BundleExecutor as XLayerBundleExecutor,
|
|
106
106
|
// 刷量
|
|
107
107
|
makeVolume as xlayerMakeVolume, singleRoundVolume as xlayerSingleRoundVolume, createVolumeExecutor as xlayerCreateVolumeExecutor, VolumeExecutor as XLayerVolumeExecutor,
|
|
108
108
|
// ✅ Buy-First 刷量(对齐 BSC buy-first)
|
package/dist/xlayer/bundle.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - 买卖一体化:买入 -> 授权 -> 卖出 -> 归集
|
|
8
8
|
* - OKB 归集:将 sender 的 OKB 转回 owner
|
|
9
9
|
*/
|
|
10
|
-
import type { XLayerConfig, BundleBuyParams, BundleBuyResult, BundleSellParams, BundleSellResult, BundleBuySellParams, BundleBuySellResult,
|
|
10
|
+
import type { XLayerConfig, BundleBuyParams, BundleBuyResult, BundleSellParams, BundleSellResult, BundleBuySellParams, BundleBuySellResult, BundleCreateBuySignParams, BundleCreateBuySignResult, BundleCreateToDexSignParams, BundleCreateToDexSignResult, BundlePreApproveParams, BundlePreApproveResult, ApprovalStatusResult } from './types.js';
|
|
11
11
|
import { AAAccountManager } from './aa-account.js';
|
|
12
12
|
import { PortalQuery } from './portal-ops.js';
|
|
13
13
|
/**
|
|
@@ -96,7 +96,26 @@ export declare class BundleExecutor {
|
|
|
96
96
|
* 捆绑发射代币 + 购买(签名版本)
|
|
97
97
|
*/
|
|
98
98
|
bundleCreateBuySign(params: BundleCreateBuySignParams): Promise<BundleCreateBuySignResult>;
|
|
99
|
-
|
|
99
|
+
/**
|
|
100
|
+
* 一键发射到外盘(Create-to-DEX)之签名逻辑(AA 模式)
|
|
101
|
+
*
|
|
102
|
+
* 目标:对齐 BSC `flapBundleCreateToDex` 的逻辑,但适配 XLayer AA (EIP-4337)
|
|
103
|
+
*
|
|
104
|
+
* 流程:
|
|
105
|
+
* 1. 准备阶段:Payer (Dev), Curve Buyers, Nonces, Profit Settings
|
|
106
|
+
* 2. HandleOps #1:
|
|
107
|
+
* - Op 1: `newTokenV4` (发币) - Payer 发起
|
|
108
|
+
* - Ops 2..N: `swapExactInput` (内盘买入) - 多个 Curve Buyer 发起
|
|
109
|
+
* - 注意:最后一笔内盘买入通常触发毕业,GasLimit 设为 8,000,000
|
|
110
|
+
* 3. HandleOps #2 (可选):
|
|
111
|
+
* - Ops 1..M: Approve + `swapExactETHForTokens` (外盘买入) - 多个 DEX Buyer 发起
|
|
112
|
+
* 4. 利润提取 (可选):
|
|
113
|
+
* - 从 Payer EOA 发起 direct transfer
|
|
114
|
+
*
|
|
115
|
+
* @param params - 签名参数
|
|
116
|
+
* @returns 签名后的交易列表及元数据
|
|
117
|
+
*/
|
|
118
|
+
bundleCreateToDexSign(params: BundleCreateToDexSignParams): Promise<BundleCreateToDexSignResult>;
|
|
100
119
|
/**
|
|
101
120
|
* 检查多个 AA 账户的授权状态
|
|
102
121
|
*
|
|
@@ -147,14 +166,14 @@ export declare function bundleSell(params: BundleSellParams): Promise<BundleSell
|
|
|
147
166
|
* 快速捆绑买卖
|
|
148
167
|
*/
|
|
149
168
|
export declare function bundleBuySell(params: BundleBuySellParams): Promise<BundleBuySellResult>;
|
|
150
|
-
/**
|
|
151
|
-
* 快速捆绑发射 + 购买
|
|
152
|
-
*/
|
|
153
|
-
export declare function bundleCreateBuy(params: BundleCreateBuyParams): Promise<BundleCreateBuyResult>;
|
|
154
169
|
/**
|
|
155
170
|
* 快速捆绑发射 + 购买(仅签名)
|
|
156
171
|
*/
|
|
157
172
|
export declare function bundleCreateBuySign(params: BundleCreateBuySignParams): Promise<BundleCreateBuySignResult>;
|
|
173
|
+
/**
|
|
174
|
+
* 快速一键发射到外盘(仅签名,AA 模式)
|
|
175
|
+
*/
|
|
176
|
+
export declare function bundleCreateToDexSign(params: BundleCreateToDexSignParams): Promise<BundleCreateToDexSignResult>;
|
|
158
177
|
/**
|
|
159
178
|
* 快速预授权
|
|
160
179
|
*
|
package/dist/xlayer/bundle.js
CHANGED
|
@@ -8,12 +8,13 @@
|
|
|
8
8
|
* - OKB 归集:将 sender 的 OKB 转回 owner
|
|
9
9
|
*/
|
|
10
10
|
import { Wallet, Interface, Contract, ethers } from 'ethers';
|
|
11
|
-
import { FLAP_PORTAL, ENTRYPOINT_ABI, PORTAL_ABI, DEFAULT_CALL_GAS_LIMIT_SELL, DEFAULT_WITHDRAW_RESERVE, } from './constants.js';
|
|
12
|
-
import { AAAccountManager, encodeExecute, encodeExecuteBatch } from './aa-account.js';
|
|
11
|
+
import { FLAP_PORTAL, ENTRYPOINT_ABI, PORTAL_ABI, DEFAULT_CALL_GAS_LIMIT_SELL, DEFAULT_WITHDRAW_RESERVE, WOKB, POTATOSWAP_V2_ROUTER, } from './constants.js';
|
|
12
|
+
import { AAAccountManager, encodeExecute, encodeExecuteBatch, createWallet } from './aa-account.js';
|
|
13
13
|
import { encodeBuyCall, encodeSellCall, encodeApproveCall, encodeTransferCall, encodeCreateCallV2, encodeCreateCallV3, encodeCreateCallV4, PortalQuery, parseOkb, formatOkb, } from './portal-ops.js';
|
|
14
14
|
import { mapWithConcurrency } from '../utils/concurrency.js';
|
|
15
15
|
import { PROFIT_CONFIG, ZERO_ADDRESS } from '../utils/constants.js';
|
|
16
16
|
import { DexQuery } from './dex.js';
|
|
17
|
+
import { encodeSwapExactETHForTokensSupportingFee, } from './dex.js';
|
|
17
18
|
// ============================================================================
|
|
18
19
|
// AA Nonce(EntryPoint nonce)本地分配器
|
|
19
20
|
// ============================================================================
|
|
@@ -1353,50 +1354,192 @@ export class BundleExecutor {
|
|
|
1353
1354
|
}
|
|
1354
1355
|
};
|
|
1355
1356
|
}
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1357
|
+
/**
|
|
1358
|
+
* 一键发射到外盘(Create-to-DEX)之签名逻辑(AA 模式)
|
|
1359
|
+
*
|
|
1360
|
+
* 目标:对齐 BSC `flapBundleCreateToDex` 的逻辑,但适配 XLayer AA (EIP-4337)
|
|
1361
|
+
*
|
|
1362
|
+
* 流程:
|
|
1363
|
+
* 1. 准备阶段:Payer (Dev), Curve Buyers, Nonces, Profit Settings
|
|
1364
|
+
* 2. HandleOps #1:
|
|
1365
|
+
* - Op 1: `newTokenV4` (发币) - Payer 发起
|
|
1366
|
+
* - Ops 2..N: `swapExactInput` (内盘买入) - 多个 Curve Buyer 发起
|
|
1367
|
+
* - 注意:最后一笔内盘买入通常触发毕业,GasLimit 设为 8,000,000
|
|
1368
|
+
* 3. HandleOps #2 (可选):
|
|
1369
|
+
* - Ops 1..M: Approve + `swapExactETHForTokens` (外盘买入) - 多个 DEX Buyer 发起
|
|
1370
|
+
* 4. 利润提取 (可选):
|
|
1371
|
+
* - 从 Payer EOA 发起 direct transfer
|
|
1372
|
+
*
|
|
1373
|
+
* @param params - 签名参数
|
|
1374
|
+
* @returns 签名后的交易列表及元数据
|
|
1375
|
+
*/
|
|
1376
|
+
async bundleCreateToDexSign(params) {
|
|
1377
|
+
const { tokenInfo, tokenAddress, payerPrivateKey, curveBuyerPrivateKeys, curveBuyAmounts, enableDexBuy = false, dexBuyerPrivateKeys = [], dexBuyAmounts = [], config = {} } = params;
|
|
1378
|
+
const aaManager = this.getAAManager();
|
|
1379
|
+
const provider = aaManager.getProvider();
|
|
1380
|
+
const feeData = await provider.getFeeData();
|
|
1381
|
+
const legacyGasPrice = feeData.gasPrice ?? 100000000n;
|
|
1382
|
+
const payerWallet = createWallet(payerPrivateKey, config);
|
|
1383
|
+
const payerAccount = await aaManager.getAccountInfo(payerWallet.address);
|
|
1384
|
+
const nonceMap = new AANonceMap();
|
|
1385
|
+
nonceMap.init(payerAccount.sender, payerAccount.nonce);
|
|
1386
|
+
const profitSettings = resolveProfitSettings(config);
|
|
1387
|
+
const signedTransactions = [];
|
|
1388
|
+
let totalCurveBuyWei = 0n;
|
|
1389
|
+
let totalDexBuyWei = 0n;
|
|
1390
|
+
// --- 1. 准备内盘买家 ---
|
|
1391
|
+
const curveBuyerWallets = curveBuyerPrivateKeys.map(pk => createWallet(pk, config));
|
|
1392
|
+
const curveBuyerInfos = await mapWithConcurrency(curveBuyerWallets, 5, async (w) => {
|
|
1393
|
+
const info = await aaManager.getAccountInfo(w.address);
|
|
1394
|
+
nonceMap.init(info.sender, info.nonce);
|
|
1395
|
+
return info;
|
|
1360
1396
|
});
|
|
1361
|
-
const
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1397
|
+
const ops1 = [];
|
|
1398
|
+
// --- 2. 构建发币 Op (Payer/Dev) ---
|
|
1399
|
+
const createData = encodeCreateCallV4({
|
|
1400
|
+
name: tokenInfo.name,
|
|
1401
|
+
symbol: tokenInfo.symbol,
|
|
1402
|
+
meta: tokenInfo.meta,
|
|
1403
|
+
dexThresh: params.dexThresh ?? 0,
|
|
1404
|
+
salt: params.salt ?? ethers.hexlify(ethers.randomBytes(32)),
|
|
1405
|
+
taxRate: params.taxRate ?? 0,
|
|
1406
|
+
migratorType: params.migratorType ?? 0,
|
|
1407
|
+
quoteToken: params.quoteToken ?? ZERO_ADDRESS,
|
|
1408
|
+
quoteAmt: params.quoteAmt ?? 0n,
|
|
1409
|
+
beneficiary: params.beneficiary ?? payerAccount.sender,
|
|
1410
|
+
permitData: params.permitData ?? '0x',
|
|
1411
|
+
extensionID: params.extensionID ?? ZERO_ADDRESS,
|
|
1412
|
+
extensionData: params.extensionData ?? '0x',
|
|
1413
|
+
dexId: params.dexId ?? 0,
|
|
1414
|
+
lpFeeProfile: params.lpFeeProfile ?? 0,
|
|
1415
|
+
});
|
|
1416
|
+
const createCallData = encodeExecute(FLAP_PORTAL, 0n, createData);
|
|
1417
|
+
const createOpRes = await aaManager.buildUserOpWithFixedGas({
|
|
1418
|
+
ownerWallet: payerWallet,
|
|
1419
|
+
sender: payerAccount.sender,
|
|
1420
|
+
callData: createCallData,
|
|
1421
|
+
nonce: nonceMap.next(payerAccount.sender),
|
|
1422
|
+
initCode: payerAccount.deployed ? '0x' : (await aaManager.generateInitCode(payerWallet.address)),
|
|
1423
|
+
deployed: payerAccount.deployed,
|
|
1424
|
+
fixedGas: { callGasLimit: 800000n } // 发币较重,给 80W
|
|
1425
|
+
});
|
|
1426
|
+
const signedCreateOp = await aaManager.signUserOp(createOpRes.userOp, payerWallet);
|
|
1427
|
+
ops1.push(signedCreateOp.userOp);
|
|
1428
|
+
// --- 3. 构建内盘买入 Ops ---
|
|
1429
|
+
for (let i = 0; i < curveBuyerWallets.length; i++) {
|
|
1430
|
+
const wallet = curveBuyerWallets[i];
|
|
1431
|
+
const info = curveBuyerInfos[i];
|
|
1432
|
+
const buyWei = parseOkb(curveBuyAmounts[i]);
|
|
1433
|
+
totalCurveBuyWei += buyWei;
|
|
1434
|
+
const buyData = encodeBuyCall(tokenAddress, buyWei, 0n);
|
|
1435
|
+
const buyCallData = encodeExecute(FLAP_PORTAL, buyWei, buyData);
|
|
1436
|
+
// 最后一笔买入通常触发毕业,GasLimit 给大一点 (8M)
|
|
1437
|
+
const isLast = i === curveBuyerWallets.length - 1;
|
|
1438
|
+
const gasLimit = isLast ? 8000000n : 800000n;
|
|
1439
|
+
const buyOpRes = await aaManager.buildUserOpWithFixedGas({
|
|
1440
|
+
ownerWallet: wallet,
|
|
1441
|
+
sender: info.sender,
|
|
1442
|
+
callData: buyCallData,
|
|
1443
|
+
nonce: nonceMap.next(info.sender),
|
|
1444
|
+
initCode: info.deployed ? '0x' : (await aaManager.generateInitCode(wallet.address)),
|
|
1445
|
+
deployed: info.deployed,
|
|
1446
|
+
fixedGas: { callGasLimit: gasLimit }
|
|
1447
|
+
});
|
|
1448
|
+
const signedBuyOp = await aaManager.signUserOp(buyOpRes.userOp, wallet);
|
|
1449
|
+
ops1.push(signedBuyOp.userOp);
|
|
1450
|
+
}
|
|
1451
|
+
// 签名第一个 handleOps
|
|
1452
|
+
const startNonce = params.payerStartNonce ?? (await provider.getTransactionCount(payerWallet.address, 'pending'));
|
|
1453
|
+
const signedMainTx = await this.signHandleOpsTx({
|
|
1454
|
+
ops: ops1,
|
|
1455
|
+
payerWallet: payerWallet,
|
|
1456
|
+
beneficiary: params.beneficiary ?? payerWallet.address,
|
|
1457
|
+
nonce: startNonce
|
|
1458
|
+
});
|
|
1459
|
+
signedTransactions.push(signedMainTx);
|
|
1460
|
+
// --- 4. 构建外盘买入 handleOps (如果启用) ---
|
|
1461
|
+
if (enableDexBuy && dexBuyerPrivateKeys.length > 0) {
|
|
1462
|
+
const dexBuyerWallets = dexBuyerPrivateKeys.map(pk => createWallet(pk, config));
|
|
1463
|
+
const dexBuyerInfos = await mapWithConcurrency(dexBuyerWallets, 5, async (w) => {
|
|
1464
|
+
const info = await aaManager.getAccountInfo(w.address);
|
|
1465
|
+
nonceMap.init(info.sender, info.nonce);
|
|
1466
|
+
return info;
|
|
1467
|
+
});
|
|
1468
|
+
const ops2 = [];
|
|
1469
|
+
const deadline = Math.floor(Date.now() / 1000) + 1200; // 20 min
|
|
1470
|
+
for (let i = 0; i < dexBuyerWallets.length; i++) {
|
|
1471
|
+
const wallet = dexBuyerWallets[i];
|
|
1472
|
+
const info = dexBuyerInfos[i];
|
|
1473
|
+
const buyWei = parseOkb(dexBuyAmounts[i]);
|
|
1474
|
+
totalDexBuyWei += buyWei;
|
|
1475
|
+
// AA 模式外盘:Approve + Swap
|
|
1476
|
+
// 1. Approve (PotatoSwap Router)
|
|
1477
|
+
const approveData = encodeApproveCall(POTATOSWAP_V2_ROUTER);
|
|
1478
|
+
const approveCallData = encodeExecute(tokenAddress, 0n, approveData);
|
|
1479
|
+
const approveOpRes = await aaManager.buildUserOpWithFixedGas({
|
|
1480
|
+
ownerWallet: wallet,
|
|
1481
|
+
sender: info.sender,
|
|
1482
|
+
callData: approveCallData,
|
|
1483
|
+
nonce: nonceMap.next(info.sender),
|
|
1484
|
+
initCode: '0x', // HandleOps1 已部署
|
|
1485
|
+
deployed: true,
|
|
1486
|
+
fixedGas: { callGasLimit: 100000n }
|
|
1487
|
+
});
|
|
1488
|
+
const signedApprove = await aaManager.signUserOp(approveOpRes.userOp, wallet);
|
|
1489
|
+
ops2.push(signedApprove.userOp);
|
|
1490
|
+
// 2. Swap (PotatoSwap V2)
|
|
1491
|
+
const swapData = encodeSwapExactETHForTokensSupportingFee(0n, [WOKB, tokenAddress], info.sender, deadline);
|
|
1492
|
+
const swapCallData = encodeExecute(POTATOSWAP_V2_ROUTER, buyWei, swapData);
|
|
1493
|
+
const swapOpRes = await aaManager.buildUserOpWithFixedGas({
|
|
1494
|
+
ownerWallet: wallet,
|
|
1495
|
+
sender: info.sender,
|
|
1496
|
+
callData: swapCallData,
|
|
1497
|
+
nonce: nonceMap.next(info.sender),
|
|
1498
|
+
deployed: true,
|
|
1499
|
+
fixedGas: { callGasLimit: 500000n }
|
|
1500
|
+
});
|
|
1501
|
+
const signedSwap = await aaManager.signUserOp(swapOpRes.userOp, wallet);
|
|
1502
|
+
ops2.push(signedSwap.userOp);
|
|
1503
|
+
}
|
|
1504
|
+
const signedDexTx = await this.signHandleOpsTx({
|
|
1505
|
+
ops: ops2,
|
|
1506
|
+
payerWallet: payerWallet,
|
|
1507
|
+
beneficiary: params.beneficiary ?? payerWallet.address,
|
|
1508
|
+
nonce: startNonce + 1
|
|
1509
|
+
});
|
|
1510
|
+
signedTransactions.push(signedDexTx);
|
|
1511
|
+
}
|
|
1512
|
+
// --- 5. 利润提取 (Direct EOA transfer) ---
|
|
1513
|
+
let totalProfitWei = 0n;
|
|
1514
|
+
if (profitSettings.extractProfit) {
|
|
1515
|
+
totalProfitWei += calculateProfitWei(totalCurveBuyWei, profitSettings.profitBps);
|
|
1516
|
+
if (enableDexBuy) {
|
|
1517
|
+
totalProfitWei += calculateProfitWei(totalDexBuyWei, profitSettings.profitBps);
|
|
1518
|
+
}
|
|
1519
|
+
if (totalProfitWei > 0n) {
|
|
1520
|
+
const profitTxNonce = startNonce + (enableDexBuy ? 2 : 1);
|
|
1521
|
+
const signedProfitTx = await this.signProfitTransaction({
|
|
1522
|
+
payerWallet,
|
|
1523
|
+
profitWei: totalProfitWei,
|
|
1524
|
+
recipient: profitSettings.profitRecipient,
|
|
1525
|
+
nonce: profitTxNonce
|
|
1526
|
+
});
|
|
1527
|
+
signedTransactions.push(signedProfitTx);
|
|
1390
1528
|
}
|
|
1391
1529
|
}
|
|
1392
1530
|
return {
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1531
|
+
signedTransactions,
|
|
1532
|
+
tokenAddress,
|
|
1533
|
+
metadata: {
|
|
1534
|
+
payerOwner: payerWallet.address,
|
|
1535
|
+
payerSender: payerAccount.sender,
|
|
1536
|
+
curveBuyerCount: curveBuyerWallets.length,
|
|
1537
|
+
curveTotalBuyWei: totalCurveBuyWei.toString(),
|
|
1538
|
+
enableDexBuy,
|
|
1539
|
+
dexBuyerCount: dexBuyerPrivateKeys.length,
|
|
1540
|
+
dexTotalBuyWei: totalDexBuyWei.toString(),
|
|
1541
|
+
profitAmount: formatOkb(totalProfitWei)
|
|
1542
|
+
}
|
|
1400
1543
|
};
|
|
1401
1544
|
}
|
|
1402
1545
|
// ============================================================================
|
|
@@ -1592,18 +1735,18 @@ export async function bundleBuySell(params) {
|
|
|
1592
1735
|
return executor.bundleBuySell(params);
|
|
1593
1736
|
}
|
|
1594
1737
|
/**
|
|
1595
|
-
* 快速捆绑发射 +
|
|
1738
|
+
* 快速捆绑发射 + 购买(仅签名)
|
|
1596
1739
|
*/
|
|
1597
|
-
export async function
|
|
1740
|
+
export async function bundleCreateBuySign(params) {
|
|
1598
1741
|
const executor = createBundleExecutor(params.config);
|
|
1599
|
-
return executor.
|
|
1742
|
+
return executor.bundleCreateBuySign(params);
|
|
1600
1743
|
}
|
|
1601
1744
|
/**
|
|
1602
|
-
*
|
|
1745
|
+
* 快速一键发射到外盘(仅签名,AA 模式)
|
|
1603
1746
|
*/
|
|
1604
|
-
export async function
|
|
1747
|
+
export async function bundleCreateToDexSign(params) {
|
|
1605
1748
|
const executor = createBundleExecutor(params.config);
|
|
1606
|
-
return executor.
|
|
1749
|
+
return executor.bundleCreateToDexSign(params);
|
|
1607
1750
|
}
|
|
1608
1751
|
/**
|
|
1609
1752
|
* 快速预授权
|
package/dist/xlayer/index.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ import type { BundleSwapSignParams, BundleSwapSignResult, BundleBatchSwapSignPar
|
|
|
62
62
|
export { BundlerClient, createBundlerClient, type BundlerConfig, type BundlerReceipt, } from './bundler.js';
|
|
63
63
|
export { AAAccountManager, createAAAccountManager, predictSender, createWallet, encodeExecute, encodeExecuteBatch, generateAAWallets, generateAAWalletsFromMnemonic, predictSendersFromPrivateKeys, type GeneratedAAWallet, type GenerateAAWalletsParams, type GenerateAAWalletsResult, } from './aa-account.js';
|
|
64
64
|
export { encodeBuyCall, encodeSellCall, encodeApproveCall, encodeTransferCall, PortalQuery, createPortalQuery, applySlippage, formatOkb, parseOkb, formatTokenAmount, parseTokenAmount, type PortalQueryConfig, } from './portal-ops.js';
|
|
65
|
-
export { BundleExecutor, createBundleExecutor, bundleBuy, bundleSell, bundleBuySell,
|
|
65
|
+
export { BundleExecutor, createBundleExecutor, bundleBuy, bundleSell, bundleBuySell, bundleCreateBuySign, bundleCreateToDexSign, bundlePreApprove, checkApprovalStatus, } from './bundle.js';
|
|
66
66
|
export { DexBundleExecutor, createDexBundleExecutor, dexBundleBuySell, type DexBundleConfig, type DexBundleBuySellParams, } from './dex-bundle.js';
|
|
67
67
|
export { AAPortalSwapExecutor, } from './portal-bundle-swap.js';
|
|
68
68
|
export { AADexSwapExecutor, } from './dex-bundle-swap.js';
|
|
@@ -88,8 +88,8 @@ export declare const xlayer: {
|
|
|
88
88
|
bundleBuy: (params: import("./types.js").BundleBuyParams) => Promise<import("./types.js").BundleBuyResult>;
|
|
89
89
|
bundleSell: (params: import("./types.js").BundleSellParams) => Promise<import("./types.js").BundleSellResult>;
|
|
90
90
|
bundleBuySell: (params: import("./types.js").BundleBuySellParams) => Promise<import("./types.js").BundleBuySellResult>;
|
|
91
|
-
bundleCreateBuy: (params: import("./types.js").BundleCreateBuyParams) => Promise<import("./types.js").BundleCreateBuyResult>;
|
|
92
91
|
bundleCreateBuySign: (params: import("./types.js").BundleCreateBuySignParams) => Promise<import("./types.js").BundleCreateBuySignResult>;
|
|
92
|
+
bundleCreateToDexSign: (params: import("./types.js").BundleCreateToDexSignParams) => Promise<import("./types.js").BundleCreateToDexSignResult>;
|
|
93
93
|
bundleSwapSign: (params: BundleSwapSignParams & {
|
|
94
94
|
skipApprovalCheck?: boolean;
|
|
95
95
|
}) => Promise<BundleSwapSignResult>;
|
package/dist/xlayer/index.js
CHANGED
|
@@ -81,7 +81,7 @@ export { encodeBuyCall, encodeSellCall, encodeApproveCall, encodeTransferCall, P
|
|
|
81
81
|
// ============================================================================
|
|
82
82
|
// 捆绑交易
|
|
83
83
|
// ============================================================================
|
|
84
|
-
export { BundleExecutor, createBundleExecutor, bundleBuy, bundleSell, bundleBuySell,
|
|
84
|
+
export { BundleExecutor, createBundleExecutor, bundleBuy, bundleSell, bundleBuySell, bundleCreateBuySign, bundleCreateToDexSign,
|
|
85
85
|
// 预授权(一键授权)
|
|
86
86
|
bundlePreApprove, checkApprovalStatus, } from './bundle.js';
|
|
87
87
|
// ============================================================================
|
|
@@ -157,14 +157,14 @@ export const xlayer = {
|
|
|
157
157
|
const { bundleBuySell } = await import('./bundle.js');
|
|
158
158
|
return bundleBuySell(...args);
|
|
159
159
|
},
|
|
160
|
-
bundleCreateBuy: async (...args) => {
|
|
161
|
-
const { bundleCreateBuy } = await import('./bundle.js');
|
|
162
|
-
return bundleCreateBuy(...args);
|
|
163
|
-
},
|
|
164
160
|
bundleCreateBuySign: async (...args) => {
|
|
165
161
|
const { bundleCreateBuySign } = await import('./bundle.js');
|
|
166
162
|
return bundleCreateBuySign(...args);
|
|
167
163
|
},
|
|
164
|
+
bundleCreateToDexSign: async (...args) => {
|
|
165
|
+
const { bundleCreateToDexSign } = await import('./bundle.js');
|
|
166
|
+
return bundleCreateToDexSign(...args);
|
|
167
|
+
},
|
|
168
168
|
// 捆绑换手(AA):仅签名(raw signed tx)
|
|
169
169
|
bundleSwapSign: async (...args) => bundleSwapSign(...args),
|
|
170
170
|
bundleBatchSwapSign: async (...args) => bundleBatchSwapSign(...args),
|
package/dist/xlayer/types.d.ts
CHANGED
|
@@ -215,9 +215,9 @@ export interface BundleBuySellParams {
|
|
|
215
215
|
config?: Partial<XLayerConfig>;
|
|
216
216
|
}
|
|
217
217
|
/**
|
|
218
|
-
*
|
|
218
|
+
* 捆绑发射签名参数
|
|
219
219
|
*/
|
|
220
|
-
export interface
|
|
220
|
+
export interface BundleCreateBuySignParams {
|
|
221
221
|
/** 代币信息 */
|
|
222
222
|
tokenInfo: {
|
|
223
223
|
name: string;
|
|
@@ -237,7 +237,6 @@ export interface BundleCreateBuyParams {
|
|
|
237
237
|
migratorType?: number;
|
|
238
238
|
quoteToken?: string;
|
|
239
239
|
quoteAmt?: bigint;
|
|
240
|
-
beneficiary?: string;
|
|
241
240
|
permitData?: string;
|
|
242
241
|
extensionID?: string;
|
|
243
242
|
extensionData?: string;
|
|
@@ -249,27 +248,6 @@ export interface BundleCreateBuyParams {
|
|
|
249
248
|
withdrawReserve?: string;
|
|
250
249
|
/** 配置覆盖 */
|
|
251
250
|
config?: Partial<XLayerConfig>;
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* 捆绑发射执行结果
|
|
255
|
-
*/
|
|
256
|
-
export interface BundleCreateBuyResult {
|
|
257
|
-
/** handleOps 交易结果 */
|
|
258
|
-
createBuyResult: HandleOpsResult;
|
|
259
|
-
/** 代币地址 */
|
|
260
|
-
tokenAddress: string;
|
|
261
|
-
/** 利润汇总 */
|
|
262
|
-
profit?: {
|
|
263
|
-
extractProfit: boolean;
|
|
264
|
-
profitBps: number;
|
|
265
|
-
profitRecipient: string;
|
|
266
|
-
totalProfitWei: string;
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* 捆绑发射签名参数
|
|
271
|
-
*/
|
|
272
|
-
export interface BundleCreateBuySignParams extends BundleCreateBuyParams {
|
|
273
251
|
/** Payer 私钥(用于签 handleOps 交易);默认 privateKeys[0] */
|
|
274
252
|
payerPrivateKey?: string;
|
|
275
253
|
/** beneficiary(默认 payer 地址) */
|
|
@@ -295,6 +273,73 @@ export interface BundleCreateBuySignResult {
|
|
|
295
273
|
totalBuyWei: string;
|
|
296
274
|
};
|
|
297
275
|
}
|
|
276
|
+
/**
|
|
277
|
+
* 一键发射到外盘签名参数(AA 模式)
|
|
278
|
+
*
|
|
279
|
+
* 交易顺序:
|
|
280
|
+
* 1. handleOps #1: 创建代币 + 内盘买入(买到毕业)
|
|
281
|
+
* 2. handleOps #2: 外盘买入(通过 PotatoSwap V2)
|
|
282
|
+
* 3. 利润提取(EOA 转账)
|
|
283
|
+
*/
|
|
284
|
+
export interface BundleCreateToDexSignParams {
|
|
285
|
+
/** 代币信息 */
|
|
286
|
+
tokenInfo: {
|
|
287
|
+
name: string;
|
|
288
|
+
symbol: string;
|
|
289
|
+
meta: string;
|
|
290
|
+
};
|
|
291
|
+
/** 预计算的代币地址 */
|
|
292
|
+
tokenAddress: string;
|
|
293
|
+
/** Payer 私钥(支付 Gas,同时作为发币者) */
|
|
294
|
+
payerPrivateKey: string;
|
|
295
|
+
/** 内盘买入钱包私钥列表 */
|
|
296
|
+
curveBuyerPrivateKeys: string[];
|
|
297
|
+
/** 内盘买入金额列表(OKB,按顺序对应) */
|
|
298
|
+
curveBuyAmounts: string[];
|
|
299
|
+
/** 是否启用外盘买入(默认 false) */
|
|
300
|
+
enableDexBuy?: boolean;
|
|
301
|
+
/** 外盘买入钱包私钥列表(可与内盘钱包相同或不同) */
|
|
302
|
+
dexBuyerPrivateKeys?: string[];
|
|
303
|
+
/** 外盘买入金额列表(OKB) */
|
|
304
|
+
dexBuyAmounts?: string[];
|
|
305
|
+
/** V4 发币参数 */
|
|
306
|
+
salt?: string;
|
|
307
|
+
dexThresh?: number;
|
|
308
|
+
taxRate?: number;
|
|
309
|
+
migratorType?: number;
|
|
310
|
+
quoteToken?: string;
|
|
311
|
+
quoteAmt?: bigint;
|
|
312
|
+
beneficiary?: string;
|
|
313
|
+
permitData?: string;
|
|
314
|
+
extensionID?: string;
|
|
315
|
+
extensionData?: string;
|
|
316
|
+
dexId?: number;
|
|
317
|
+
lpFeeProfile?: number;
|
|
318
|
+
/** Payer 起始 nonce(不传则用 pending nonce) */
|
|
319
|
+
payerStartNonce?: number;
|
|
320
|
+
/** 配置覆盖 */
|
|
321
|
+
config?: Partial<XLayerConfig>;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* 一键发射到外盘签名结果
|
|
325
|
+
*/
|
|
326
|
+
export interface BundleCreateToDexSignResult {
|
|
327
|
+
/** raw signed tx 列表 */
|
|
328
|
+
signedTransactions: string[];
|
|
329
|
+
/** 代币地址 */
|
|
330
|
+
tokenAddress: string;
|
|
331
|
+
/** 元数据 */
|
|
332
|
+
metadata?: {
|
|
333
|
+
payerOwner: string;
|
|
334
|
+
payerSender: string;
|
|
335
|
+
curveBuyerCount: number;
|
|
336
|
+
curveTotalBuyWei: string;
|
|
337
|
+
enableDexBuy: boolean;
|
|
338
|
+
dexBuyerCount: number;
|
|
339
|
+
dexTotalBuyWei: string;
|
|
340
|
+
profitAmount?: string;
|
|
341
|
+
};
|
|
342
|
+
}
|
|
298
343
|
/**
|
|
299
344
|
* 捆绑换手参数(AA 模式,单卖单买)
|
|
300
345
|
* - 卖方 AA 先卖出
|