four-flap-meme-sdk 1.5.63 → 1.5.65
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 +14 -13
- package/dist/xlayer/bundle.js +170 -108
- package/dist/xlayer/index.d.ts +2 -1
- package/dist/xlayer/index.js +5 -1
- package/dist/xlayer/types.d.ts +43 -0
- 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, 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';
|
|
56
|
+
export { bundleBuy as xlayerBundleBuy, bundleSell as xlayerBundleSell, bundleBuySell as xlayerBundleBuySell, bundleCreateBuySign as xlayerBundleCreateBuySign, bundleCreateToDexSign as xlayerBundleCreateToDexSign, bundleGraduateBuy as xlayerBundleGraduateBuy, 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 BundleGraduateBuyParams as XLayerBundleGraduateBuyParams, type BundleGraduateBuyResult as XLayerBundleGraduateBuyResult, 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, bundleCreateBuySign as xlayerBundleCreateBuySign, bundleCreateToDexSign as xlayerBundleCreateToDexSign, bundleSwapSign as xlayerBundleSwapSign, bundleBatchSwapSign as xlayerBundleBatchSwapSign, createBundleExecutor as xlayerCreateBundleExecutor, BundleExecutor as XLayerBundleExecutor,
|
|
105
|
+
bundleBuy as xlayerBundleBuy, bundleSell as xlayerBundleSell, bundleBuySell as xlayerBundleBuySell, bundleCreateBuySign as xlayerBundleCreateBuySign, bundleCreateToDexSign as xlayerBundleCreateToDexSign, bundleGraduateBuy as xlayerBundleGraduateBuy, 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, BundleCreateBuySignParams, BundleCreateBuySignResult, BundleCreateToDexSignParams, BundleCreateToDexSignResult, BundlePreApproveParams, BundlePreApproveResult, ApprovalStatusResult } from './types.js';
|
|
10
|
+
import type { XLayerConfig, BundleBuyParams, BundleBuyResult, BundleSellParams, BundleSellResult, BundleBuySellParams, BundleBuySellResult, BundleCreateBuySignParams, BundleCreateBuySignResult, BundleCreateToDexSignParams, BundleCreateToDexSignResult, BundlePreApproveParams, BundlePreApproveResult, ApprovalStatusResult, BundleGraduateBuyParams, BundleGraduateBuyResult } from './types.js';
|
|
11
11
|
import { AAAccountManager } from './aa-account.js';
|
|
12
12
|
import { PortalQuery } from './portal-ops.js';
|
|
13
13
|
/**
|
|
@@ -46,11 +46,6 @@ export declare class BundleExecutor {
|
|
|
46
46
|
* - 用于 AA 交易的尾部,将利润转账给指定地址
|
|
47
47
|
*/
|
|
48
48
|
private signProfitTransaction;
|
|
49
|
-
private getErc20Decimals;
|
|
50
|
-
/**
|
|
51
|
-
* 构建买入 UserOp
|
|
52
|
-
*/
|
|
53
|
-
private buildBuyUserOp;
|
|
54
49
|
/**
|
|
55
50
|
* 构建授权 UserOp
|
|
56
51
|
*/
|
|
@@ -59,19 +54,15 @@ export declare class BundleExecutor {
|
|
|
59
54
|
* 构建卖出 UserOp
|
|
60
55
|
*/
|
|
61
56
|
private buildSellUserOp;
|
|
62
|
-
/**
|
|
63
|
-
* 构建归集 UserOp(将 OKB 从 sender 转回 owner)
|
|
64
|
-
*/
|
|
65
|
-
private buildWithdrawUserOp;
|
|
66
57
|
/**
|
|
67
58
|
* 构建归集 UserOp(已知 sender/nonce/balance 的快速版本)
|
|
68
59
|
* - 用于批量流程:避免重复 getAccountInfo / getOkbBalance
|
|
69
60
|
*/
|
|
70
61
|
private buildWithdrawUserOpWithState;
|
|
71
62
|
/**
|
|
72
|
-
*
|
|
63
|
+
* 获取代币精度 (用于内部逻辑)
|
|
73
64
|
*/
|
|
74
|
-
|
|
65
|
+
getErc20Decimals(tokenAddress: string): Promise<number>;
|
|
75
66
|
/**
|
|
76
67
|
* 捆绑买入
|
|
77
68
|
*
|
|
@@ -116,6 +107,12 @@ export declare class BundleExecutor {
|
|
|
116
107
|
* @returns 签名后的交易列表及元数据
|
|
117
108
|
*/
|
|
118
109
|
bundleCreateToDexSign(params: BundleCreateToDexSignParams): Promise<BundleCreateToDexSignResult>;
|
|
110
|
+
/**
|
|
111
|
+
* 捆绑买到毕业(签名版本)
|
|
112
|
+
*
|
|
113
|
+
* 自动计算剩余毕业容量,将钱包分为内盘和外盘组,生成签名的交易列表
|
|
114
|
+
*/
|
|
115
|
+
bundleGraduateBuy(params: BundleGraduateBuyParams): Promise<BundleGraduateBuyResult>;
|
|
119
116
|
/**
|
|
120
117
|
* 检查多个 AA 账户的授权状态
|
|
121
118
|
*
|
|
@@ -171,9 +168,13 @@ export declare function bundleBuySell(params: BundleBuySellParams): Promise<Bund
|
|
|
171
168
|
*/
|
|
172
169
|
export declare function bundleCreateBuySign(params: BundleCreateBuySignParams): Promise<BundleCreateBuySignResult>;
|
|
173
170
|
/**
|
|
174
|
-
*
|
|
171
|
+
* 快速捆绑发射到外盘(仅签名,AA 模式)
|
|
175
172
|
*/
|
|
176
173
|
export declare function bundleCreateToDexSign(params: BundleCreateToDexSignParams): Promise<BundleCreateToDexSignResult>;
|
|
174
|
+
/**
|
|
175
|
+
* 快速买到毕业(仅签名,AA 模式)
|
|
176
|
+
*/
|
|
177
|
+
export declare function bundleGraduateBuy(params: BundleGraduateBuyParams): Promise<BundleGraduateBuyResult>;
|
|
177
178
|
/**
|
|
178
179
|
* 快速预授权
|
|
179
180
|
*
|
package/dist/xlayer/bundle.js
CHANGED
|
@@ -253,62 +253,6 @@ export class BundleExecutor {
|
|
|
253
253
|
type: 0,
|
|
254
254
|
});
|
|
255
255
|
}
|
|
256
|
-
async getErc20Decimals(tokenAddress) {
|
|
257
|
-
const provider = this.aaManager.getProvider();
|
|
258
|
-
const token = new Contract(tokenAddress, ['function decimals() view returns (uint8)'], provider);
|
|
259
|
-
try {
|
|
260
|
-
const d = await token.decimals();
|
|
261
|
-
const n = Number(d);
|
|
262
|
-
return Number.isFinite(n) ? n : 18;
|
|
263
|
-
}
|
|
264
|
-
catch {
|
|
265
|
-
return 18;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* 构建买入 UserOp
|
|
270
|
-
*/
|
|
271
|
-
async buildBuyUserOp(ownerWallet, tokenAddress, buyAmountWei, ownerName) {
|
|
272
|
-
const accountInfo = await this.aaManager.getAccountInfo(ownerWallet.address);
|
|
273
|
-
const initCode = accountInfo.deployed
|
|
274
|
-
? '0x'
|
|
275
|
-
: this.aaManager.generateInitCode(ownerWallet.address);
|
|
276
|
-
// 构建 callData: execute(portal, value=buyAmountWei, swapExactInput)
|
|
277
|
-
const swapData = encodeBuyCall(tokenAddress, buyAmountWei, 0n);
|
|
278
|
-
const callData = encodeExecute(this.portalAddress, buyAmountWei, swapData);
|
|
279
|
-
// 估算前确保 sender 有足够余额(用于模拟)
|
|
280
|
-
await this.aaManager.ensureSenderBalance(ownerWallet, accountInfo.sender, buyAmountWei + parseOkb('0.0003'), `${ownerName ?? 'owner'}/buy-prefund-before-estimate`);
|
|
281
|
-
const gasPolicy = this.config.gasPolicy ?? 'bundlerEstimate';
|
|
282
|
-
const { userOp, prefundWei } = gasPolicy === 'fixed'
|
|
283
|
-
? await this.aaManager.buildUserOpWithFixedGas({
|
|
284
|
-
ownerWallet,
|
|
285
|
-
sender: accountInfo.sender,
|
|
286
|
-
callData,
|
|
287
|
-
nonce: accountInfo.nonce,
|
|
288
|
-
initCode,
|
|
289
|
-
deployed: accountInfo.deployed,
|
|
290
|
-
fixedGas: {
|
|
291
|
-
...(this.config.fixedGas ?? {}),
|
|
292
|
-
callGasLimit: this.config.fixedGas?.callGasLimit ?? DEFAULT_CALL_GAS_LIMIT_BUY,
|
|
293
|
-
},
|
|
294
|
-
})
|
|
295
|
-
: await this.aaManager.buildUserOpWithBundlerEstimate({
|
|
296
|
-
ownerWallet,
|
|
297
|
-
sender: accountInfo.sender,
|
|
298
|
-
callData,
|
|
299
|
-
nonce: accountInfo.nonce,
|
|
300
|
-
initCode,
|
|
301
|
-
});
|
|
302
|
-
// 补足 prefund + 买入金额
|
|
303
|
-
await this.aaManager.ensureSenderBalance(ownerWallet, accountInfo.sender, buyAmountWei + prefundWei + parseOkb('0.0002'), `${ownerName ?? 'owner'}/buy-fund`);
|
|
304
|
-
// 签名
|
|
305
|
-
const signed = await this.aaManager.signUserOp(userOp, ownerWallet);
|
|
306
|
-
return {
|
|
307
|
-
...signed,
|
|
308
|
-
prefundWei,
|
|
309
|
-
ownerName,
|
|
310
|
-
};
|
|
311
|
-
}
|
|
312
256
|
/**
|
|
313
257
|
* 构建授权 UserOp
|
|
314
258
|
*/
|
|
@@ -409,23 +353,6 @@ export class BundleExecutor {
|
|
|
409
353
|
const signed = await this.aaManager.signUserOp(userOp, ownerWallet);
|
|
410
354
|
return { ...signed, prefundWei, ownerName };
|
|
411
355
|
}
|
|
412
|
-
/**
|
|
413
|
-
* 构建归集 UserOp(将 OKB 从 sender 转回 owner)
|
|
414
|
-
*/
|
|
415
|
-
async buildWithdrawUserOp(ownerWallet, reserveWei, ownerName) {
|
|
416
|
-
const accountInfo = await this.aaManager.getAccountInfo(ownerWallet.address);
|
|
417
|
-
const senderBalance = await this.portalQuery.getOkbBalance(accountInfo.sender);
|
|
418
|
-
const initCode = accountInfo.deployed ? '0x' : this.aaManager.generateInitCode(ownerWallet.address);
|
|
419
|
-
return await this.buildWithdrawUserOpWithState({
|
|
420
|
-
ownerWallet,
|
|
421
|
-
sender: accountInfo.sender,
|
|
422
|
-
nonce: accountInfo.nonce,
|
|
423
|
-
initCode,
|
|
424
|
-
senderBalance,
|
|
425
|
-
reserveWei,
|
|
426
|
-
ownerName,
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
356
|
/**
|
|
430
357
|
* 构建归集 UserOp(已知 sender/nonce/balance 的快速版本)
|
|
431
358
|
* - 用于批量流程:避免重复 getAccountInfo / getOkbBalance
|
|
@@ -527,42 +454,16 @@ export class BundleExecutor {
|
|
|
527
454
|
return { ...signed, prefundWei, ownerName: params.ownerName };
|
|
528
455
|
}
|
|
529
456
|
/**
|
|
530
|
-
*
|
|
457
|
+
* 获取代币精度 (用于内部逻辑)
|
|
531
458
|
*/
|
|
532
|
-
async
|
|
533
|
-
const
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
459
|
+
async getErc20Decimals(tokenAddress) {
|
|
460
|
+
const token = new Contract(tokenAddress, ['function decimals() view returns (uint8)'], this.aaManager.getProvider());
|
|
461
|
+
try {
|
|
462
|
+
return Number(await token.decimals());
|
|
463
|
+
}
|
|
464
|
+
catch {
|
|
465
|
+
return 18;
|
|
538
466
|
}
|
|
539
|
-
const transferData = encodeTransferCall(ownerWallet.address, tokenBalance);
|
|
540
|
-
const callData = encodeExecute(tokenAddress, 0n, transferData);
|
|
541
|
-
await this.aaManager.ensureSenderBalance(ownerWallet, accountInfo.sender, parseOkb('0.0002'), `${ownerName ?? 'owner'}/transfer-prefund`);
|
|
542
|
-
const gasPolicy = this.config.gasPolicy ?? 'bundlerEstimate';
|
|
543
|
-
const { userOp, prefundWei } = gasPolicy === 'fixed'
|
|
544
|
-
? await this.aaManager.buildUserOpWithFixedGas({
|
|
545
|
-
ownerWallet,
|
|
546
|
-
sender: accountInfo.sender,
|
|
547
|
-
callData,
|
|
548
|
-
nonce: accountInfo.nonce,
|
|
549
|
-
initCode: accountInfo.deployed ? '0x' : this.aaManager.generateInitCode(ownerWallet.address),
|
|
550
|
-
deployed: accountInfo.deployed,
|
|
551
|
-
fixedGas: {
|
|
552
|
-
...(this.config.fixedGas ?? {}),
|
|
553
|
-
callGasLimit: this.config.fixedGas?.callGasLimit ?? DEFAULT_CALL_GAS_LIMIT_TRANSFER,
|
|
554
|
-
},
|
|
555
|
-
})
|
|
556
|
-
: await this.aaManager.buildUserOpWithBundlerEstimate({
|
|
557
|
-
ownerWallet,
|
|
558
|
-
sender: accountInfo.sender,
|
|
559
|
-
callData,
|
|
560
|
-
nonce: accountInfo.nonce,
|
|
561
|
-
});
|
|
562
|
-
await this.aaManager.ensureSenderBalance(ownerWallet, accountInfo.sender, prefundWei + parseOkb('0.00005'), `${ownerName ?? 'owner'}/transfer-fund`);
|
|
563
|
-
console.log(`\n[${ownerName ?? 'owner'}] transfer token: ${tokenBalance.toString()}`);
|
|
564
|
-
const signed = await this.aaManager.signUserOp(userOp, ownerWallet);
|
|
565
|
-
return { ...signed, prefundWei, ownerName };
|
|
566
467
|
}
|
|
567
468
|
// ============================================================================
|
|
568
469
|
// 公开 API
|
|
@@ -1628,6 +1529,160 @@ export class BundleExecutor {
|
|
|
1628
1529
|
}
|
|
1629
1530
|
};
|
|
1630
1531
|
}
|
|
1532
|
+
/**
|
|
1533
|
+
* 捆绑买到毕业(签名版本)
|
|
1534
|
+
*
|
|
1535
|
+
* 自动计算剩余毕业容量,将钱包分为内盘和外盘组,生成签名的交易列表
|
|
1536
|
+
*/
|
|
1537
|
+
async bundleGraduateBuy(params) {
|
|
1538
|
+
const { tokenAddress, privateKeys, payerPrivateKey, amountMode, totalBuyAmount, minAmount, maxAmount, walletAmounts, enableDexBuy = false, config = {} } = params;
|
|
1539
|
+
const aaManager = this.getAAManager();
|
|
1540
|
+
const provider = aaManager.getProvider();
|
|
1541
|
+
// 1. 获取代币状态,计算剩余毕业容量
|
|
1542
|
+
const tokenState = await this.portalQuery.getTokenV5(tokenAddress);
|
|
1543
|
+
const poolReserveOkb = ethers.formatEther(tokenState.reserve);
|
|
1544
|
+
const graduateCapacity = 73.38; // 毕业阈值
|
|
1545
|
+
const remainingToGraduate = Math.max(0, graduateCapacity - parseFloat(poolReserveOkb));
|
|
1546
|
+
const remainingToGraduateWei = ethers.parseEther(remainingToGraduate.toFixed(18));
|
|
1547
|
+
console.log(`[GraduateBuy] Pool Reserve: ${poolReserveOkb} OKB, Remaining: ${remainingToGraduate} OKB`);
|
|
1548
|
+
// 2. 准备钱包
|
|
1549
|
+
const sharedProvider = this.aaManager.getProvider();
|
|
1550
|
+
const wallets = privateKeys.map(pk => new Wallet(pk, sharedProvider));
|
|
1551
|
+
const payerWallet = new Wallet(payerPrivateKey, sharedProvider);
|
|
1552
|
+
const payerAccount = await aaManager.getAccountInfo(payerWallet.address);
|
|
1553
|
+
const nonceMap = new AANonceMap();
|
|
1554
|
+
nonceMap.init(payerAccount.sender, payerAccount.nonce);
|
|
1555
|
+
// 3. 计算每个钱包的金额
|
|
1556
|
+
let finalAmounts = [];
|
|
1557
|
+
if (amountMode === 'average') {
|
|
1558
|
+
const avg = (totalBuyAmount || 0) / wallets.length;
|
|
1559
|
+
finalAmounts = wallets.map(() => avg);
|
|
1560
|
+
}
|
|
1561
|
+
else if (amountMode === 'random') {
|
|
1562
|
+
let total = 0;
|
|
1563
|
+
finalAmounts = wallets.map(() => {
|
|
1564
|
+
const amt = (minAmount || 0) + Math.random() * ((maxAmount || 0) - (minAmount || 0));
|
|
1565
|
+
total += amt;
|
|
1566
|
+
return amt;
|
|
1567
|
+
});
|
|
1568
|
+
}
|
|
1569
|
+
else if (amountMode === 'custom') {
|
|
1570
|
+
finalAmounts = wallets.map(w => walletAmounts?.[w.address] || 0);
|
|
1571
|
+
}
|
|
1572
|
+
// 4. 钱包分组
|
|
1573
|
+
const curveBuyers = [];
|
|
1574
|
+
const dexBuyers = [];
|
|
1575
|
+
let currentCurveTotal = 0n;
|
|
1576
|
+
for (let i = 0; i < wallets.length; i++) {
|
|
1577
|
+
const wallet = wallets[i];
|
|
1578
|
+
const amountWei = ethers.parseEther(finalAmounts[i].toFixed(18));
|
|
1579
|
+
if (currentCurveTotal < remainingToGraduateWei) {
|
|
1580
|
+
const needed = remainingToGraduateWei - currentCurveTotal;
|
|
1581
|
+
if (amountWei <= needed) {
|
|
1582
|
+
curveBuyers.push({ wallet, amount: amountWei });
|
|
1583
|
+
currentCurveTotal += amountWei;
|
|
1584
|
+
}
|
|
1585
|
+
else {
|
|
1586
|
+
// 当前钱包金额超过了剩余容量,将其限制为 needed
|
|
1587
|
+
curveBuyers.push({ wallet, amount: needed });
|
|
1588
|
+
currentCurveTotal = remainingToGraduateWei;
|
|
1589
|
+
// 超出部分暂不处理(遵循单钱包单属性逻辑)
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
else if (enableDexBuy) {
|
|
1593
|
+
dexBuyers.push({ wallet, amount: amountWei });
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
// 5. 构建 UserOps
|
|
1597
|
+
const effConfig = { ...(this.config ?? {}), ...(config ?? {}) };
|
|
1598
|
+
const signedTransactions = [];
|
|
1599
|
+
const ops1 = [];
|
|
1600
|
+
// --- 内盘 Ops ---
|
|
1601
|
+
const curveBuyerInfos = await mapWithConcurrency(curveBuyers.map(b => b.wallet), 5, async (w) => {
|
|
1602
|
+
const info = await aaManager.getAccountInfo(w.address);
|
|
1603
|
+
nonceMap.init(info.sender, info.nonce);
|
|
1604
|
+
return info;
|
|
1605
|
+
});
|
|
1606
|
+
const signedCurveBuyOps = await mapWithConcurrency(curveBuyers, 5, async (data, i) => {
|
|
1607
|
+
const { wallet, amount } = data;
|
|
1608
|
+
const info = curveBuyerInfos[i];
|
|
1609
|
+
const buyData = encodeBuyCall(tokenAddress, amount, 0n);
|
|
1610
|
+
const buyCallData = encodeExecute(FLAP_PORTAL, amount, buyData);
|
|
1611
|
+
const buyOpRes = await aaManager.buildUserOpWithFixedGas({
|
|
1612
|
+
ownerWallet: wallet,
|
|
1613
|
+
sender: info.sender,
|
|
1614
|
+
callData: buyCallData,
|
|
1615
|
+
nonce: nonceMap.next(info.sender),
|
|
1616
|
+
initCode: info.deployed ? '0x' : (await aaManager.generateInitCode(wallet.address)),
|
|
1617
|
+
deployed: info.deployed,
|
|
1618
|
+
fixedGas: { callGasLimit: 8000000n } // 毕业买入给高 Gas
|
|
1619
|
+
});
|
|
1620
|
+
const signedBuyOp = await aaManager.signUserOp(buyOpRes.userOp, wallet);
|
|
1621
|
+
return signedBuyOp.userOp;
|
|
1622
|
+
});
|
|
1623
|
+
ops1.push(...signedCurveBuyOps);
|
|
1624
|
+
// 签名第一个 handleOps (内盘)
|
|
1625
|
+
const startNonce = params.payerStartNonce ?? (await provider.getTransactionCount(payerWallet.address, 'pending'));
|
|
1626
|
+
const signedMainTx = await this.signHandleOpsTx({
|
|
1627
|
+
ops: ops1,
|
|
1628
|
+
payerWallet: payerWallet,
|
|
1629
|
+
beneficiary: params.beneficiary ?? payerWallet.address,
|
|
1630
|
+
nonce: startNonce,
|
|
1631
|
+
gasLimit: effConfig.gasLimit,
|
|
1632
|
+
gasPrice: effConfig.minGasPriceGwei ? ethers.parseUnits(effConfig.minGasPriceGwei.toString(), 'gwei') : undefined
|
|
1633
|
+
});
|
|
1634
|
+
signedTransactions.push(signedMainTx);
|
|
1635
|
+
// --- 外盘 Ops ---
|
|
1636
|
+
let totalDexBuyWei = 0n;
|
|
1637
|
+
if (enableDexBuy && dexBuyers.length > 0) {
|
|
1638
|
+
const dexBuyerInfos = await mapWithConcurrency(dexBuyers.map(b => b.wallet), 5, async (w) => {
|
|
1639
|
+
const info = await aaManager.getAccountInfo(w.address);
|
|
1640
|
+
nonceMap.init(info.sender, info.nonce);
|
|
1641
|
+
return info;
|
|
1642
|
+
});
|
|
1643
|
+
const ops2 = [];
|
|
1644
|
+
const deadline = Math.floor(Date.now() / 1000) + 1200;
|
|
1645
|
+
const signedDexBuyOps = await mapWithConcurrency(dexBuyers, 5, async (data, i) => {
|
|
1646
|
+
const { wallet, amount } = data;
|
|
1647
|
+
const info = dexBuyerInfos[i];
|
|
1648
|
+
totalDexBuyWei += amount;
|
|
1649
|
+
const approveData = encodeApproveCall(POTATOSWAP_V2_ROUTER);
|
|
1650
|
+
const swapData = encodeSwapExactETHForTokensSupportingFee(0n, [WOKB, tokenAddress], info.sender, deadline);
|
|
1651
|
+
const batchCallData = encodeExecuteBatch([tokenAddress, POTATOSWAP_V2_ROUTER], [0n, amount], [approveData, swapData]);
|
|
1652
|
+
const dexBuyOpRes = await aaManager.buildUserOpWithFixedGas({
|
|
1653
|
+
ownerWallet: wallet,
|
|
1654
|
+
sender: info.sender,
|
|
1655
|
+
callData: batchCallData,
|
|
1656
|
+
nonce: nonceMap.next(info.sender),
|
|
1657
|
+
initCode: info.deployed ? '0x' : (await aaManager.generateInitCode(wallet.address)),
|
|
1658
|
+
deployed: info.deployed,
|
|
1659
|
+
fixedGas: { callGasLimit: 600000n }
|
|
1660
|
+
});
|
|
1661
|
+
const signedDexBuyOp = await aaManager.signUserOp(dexBuyOpRes.userOp, wallet);
|
|
1662
|
+
return signedDexBuyOp.userOp;
|
|
1663
|
+
});
|
|
1664
|
+
ops2.push(...signedDexBuyOps);
|
|
1665
|
+
const signedDexTx = await this.signHandleOpsTx({
|
|
1666
|
+
ops: ops2,
|
|
1667
|
+
payerWallet: payerWallet,
|
|
1668
|
+
beneficiary: params.beneficiary ?? payerWallet.address,
|
|
1669
|
+
nonce: startNonce + 1,
|
|
1670
|
+
gasLimit: effConfig.gasLimit,
|
|
1671
|
+
gasPrice: effConfig.minGasPriceGwei ? ethers.parseUnits(effConfig.minGasPriceGwei.toString(), 'gwei') : undefined
|
|
1672
|
+
});
|
|
1673
|
+
signedTransactions.push(signedDexTx);
|
|
1674
|
+
}
|
|
1675
|
+
return {
|
|
1676
|
+
signedTransactions,
|
|
1677
|
+
metadata: {
|
|
1678
|
+
curveCount: curveBuyers.length,
|
|
1679
|
+
dexCount: dexBuyers.length,
|
|
1680
|
+
curveTotalAmount: ethers.formatEther(currentCurveTotal),
|
|
1681
|
+
dexTotalAmount: ethers.formatEther(totalDexBuyWei),
|
|
1682
|
+
tokenAddress
|
|
1683
|
+
}
|
|
1684
|
+
};
|
|
1685
|
+
}
|
|
1631
1686
|
// ============================================================================
|
|
1632
1687
|
// 预授权 API(一键授权,提升交易速度)
|
|
1633
1688
|
// ============================================================================
|
|
@@ -1832,12 +1887,19 @@ export async function bundleCreateBuySign(params) {
|
|
|
1832
1887
|
return executor.bundleCreateBuySign(params);
|
|
1833
1888
|
}
|
|
1834
1889
|
/**
|
|
1835
|
-
*
|
|
1890
|
+
* 快速捆绑发射到外盘(仅签名,AA 模式)
|
|
1836
1891
|
*/
|
|
1837
1892
|
export async function bundleCreateToDexSign(params) {
|
|
1838
1893
|
const executor = createBundleExecutor(params.config);
|
|
1839
1894
|
return executor.bundleCreateToDexSign(params);
|
|
1840
1895
|
}
|
|
1896
|
+
/**
|
|
1897
|
+
* 快速买到毕业(仅签名,AA 模式)
|
|
1898
|
+
*/
|
|
1899
|
+
export async function bundleGraduateBuy(params) {
|
|
1900
|
+
const executor = createBundleExecutor(params.config);
|
|
1901
|
+
return executor.bundleGraduateBuy(params);
|
|
1902
|
+
}
|
|
1841
1903
|
/**
|
|
1842
1904
|
* 快速预授权
|
|
1843
1905
|
*
|
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, bundleCreateBuySign, bundleCreateToDexSign, bundlePreApprove, checkApprovalStatus, } from './bundle.js';
|
|
65
|
+
export { BundleExecutor, createBundleExecutor, bundleBuy, bundleSell, bundleBuySell, bundleCreateBuySign, bundleCreateToDexSign, bundleGraduateBuy, 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';
|
|
@@ -90,6 +90,7 @@ export declare const xlayer: {
|
|
|
90
90
|
bundleBuySell: (params: import("./types.js").BundleBuySellParams) => Promise<import("./types.js").BundleBuySellResult>;
|
|
91
91
|
bundleCreateBuySign: (params: import("./types.js").BundleCreateBuySignParams) => Promise<import("./types.js").BundleCreateBuySignResult>;
|
|
92
92
|
bundleCreateToDexSign: (params: import("./types.js").BundleCreateToDexSignParams) => Promise<import("./types.js").BundleCreateToDexSignResult>;
|
|
93
|
+
bundleGraduateBuy: (params: import("./types.js").BundleGraduateBuyParams) => Promise<import("./types.js").BundleGraduateBuyResult>;
|
|
93
94
|
bundleSwapSign: (params: BundleSwapSignParams & {
|
|
94
95
|
skipApprovalCheck?: boolean;
|
|
95
96
|
}) => 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, bundleCreateBuySign, bundleCreateToDexSign,
|
|
84
|
+
export { BundleExecutor, createBundleExecutor, bundleBuy, bundleSell, bundleBuySell, bundleCreateBuySign, bundleCreateToDexSign, bundleGraduateBuy,
|
|
85
85
|
// 预授权(一键授权)
|
|
86
86
|
bundlePreApprove, checkApprovalStatus, } from './bundle.js';
|
|
87
87
|
// ============================================================================
|
|
@@ -165,6 +165,10 @@ export const xlayer = {
|
|
|
165
165
|
const { bundleCreateToDexSign } = await import('./bundle.js');
|
|
166
166
|
return bundleCreateToDexSign(...args);
|
|
167
167
|
},
|
|
168
|
+
bundleGraduateBuy: async (...args) => {
|
|
169
|
+
const { bundleGraduateBuy } = await import('./bundle.js');
|
|
170
|
+
return bundleGraduateBuy(...args);
|
|
171
|
+
},
|
|
168
172
|
// 捆绑换手(AA):仅签名(raw signed tx)
|
|
169
173
|
bundleSwapSign: async (...args) => bundleSwapSign(...args),
|
|
170
174
|
bundleBatchSwapSign: async (...args) => bundleBatchSwapSign(...args),
|
package/dist/xlayer/types.d.ts
CHANGED
|
@@ -835,3 +835,46 @@ export declare class AANonceMap {
|
|
|
835
835
|
* 必需的配置字段
|
|
836
836
|
*/
|
|
837
837
|
export type RequiredConfig = Required<Pick<XLayerConfig, 'rpcUrl' | 'bundlerUrl' | 'chainId' | 'entryPoint' | 'factory'>>;
|
|
838
|
+
/**
|
|
839
|
+
* 捆绑买到毕业签名参数
|
|
840
|
+
*/
|
|
841
|
+
export interface BundleGraduateBuyParams {
|
|
842
|
+
/** 代位地址 */
|
|
843
|
+
tokenAddress: string;
|
|
844
|
+
/** 买入钱包私钥数组 */
|
|
845
|
+
privateKeys: string[];
|
|
846
|
+
/** AA Payer 私钥 */
|
|
847
|
+
payerPrivateKey: string;
|
|
848
|
+
/** 分配模式 */
|
|
849
|
+
amountMode: 'average' | 'random' | 'custom';
|
|
850
|
+
/** 平均模式:总买入金额 */
|
|
851
|
+
totalBuyAmount?: number;
|
|
852
|
+
/** 随机模式:最小金额 / 最大金额 */
|
|
853
|
+
minAmount?: number;
|
|
854
|
+
maxAmount?: number;
|
|
855
|
+
/** 自定义模式:地址 -> 金额 */
|
|
856
|
+
walletAmounts?: Record<string, number>;
|
|
857
|
+
/** 是否启用外盘买入(默认 false) */
|
|
858
|
+
enableDexBuy?: boolean;
|
|
859
|
+
/** 配置覆盖 */
|
|
860
|
+
config?: Partial<XLayerConfig>;
|
|
861
|
+
/** Payer 起始 nonce */
|
|
862
|
+
payerStartNonce?: number;
|
|
863
|
+
/** beneficiary(默认 payer 地址) */
|
|
864
|
+
beneficiary?: string;
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* 捆绑买到毕业签名结果
|
|
868
|
+
*/
|
|
869
|
+
export interface BundleGraduateBuyResult {
|
|
870
|
+
/** raw signed tx 列表 */
|
|
871
|
+
signedTransactions: string[];
|
|
872
|
+
/** 元数据 */
|
|
873
|
+
metadata: {
|
|
874
|
+
curveCount: number;
|
|
875
|
+
dexCount: number;
|
|
876
|
+
curveTotalAmount: string;
|
|
877
|
+
dexTotalAmount: string;
|
|
878
|
+
tokenAddress: string;
|
|
879
|
+
};
|
|
880
|
+
}
|