four-flap-meme-sdk 1.5.67 → 1.5.69

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.
@@ -95,6 +95,20 @@ export type TokenStateV5 = {
95
95
  nativeToQuoteSwapEnabled: boolean;
96
96
  extensionID: `0x${string}`;
97
97
  };
98
+ /**
99
+ * TokenStateV7 - 包含毕业相关信息(pool, progress, lpFeeProfile)
100
+ * 用于 XLayer 等支持 V7 的链
101
+ */
102
+ export type TokenStateV7 = TokenStateV5 & {
103
+ taxRate: bigint;
104
+ pool: string;
105
+ progress: bigint;
106
+ lpFeeProfile: number;
107
+ };
108
+ /**
109
+ * 将 lpFeeProfile 转换为 V3 fee 值
110
+ */
111
+ export declare function lpFeeProfileToV3Fee(profile: number): number;
98
112
  /**
99
113
  * Flap Portal 支持的链
100
114
  */
@@ -176,6 +190,23 @@ export declare class FlapPortal {
176
190
  getTokenV3(token: string): Promise<TokenStateV3>;
177
191
  getTokenV4(token: string): Promise<TokenStateV4>;
178
192
  getTokenV5(token: string): Promise<TokenStateV5>;
193
+ /**
194
+ * 获取代币状态 V7(包含毕业相关信息)
195
+ * 注意:仅部分链支持 V7(如 XLayer v5.7+),不支持的链会 revert
196
+ */
197
+ getTokenV7(token: string): Promise<TokenStateV7>;
198
+ /**
199
+ * 计算距离毕业还需多少 OKB/ETH(含手续费)
200
+ * @param state TokenStateV5 或 TokenStateV7
201
+ * @returns 毕业相关信息
202
+ */
203
+ computeRemainingToGraduation(state: TokenStateV5 | TokenStateV7): {
204
+ remainingOkb: string;
205
+ graduationReserve: string;
206
+ currentReserve: string;
207
+ isGraduated: boolean;
208
+ progressPercent: string;
209
+ };
179
210
  computePriceAndProgress(state: TokenStateV5): {
180
211
  price: string;
181
212
  progress: string;
@@ -64,6 +64,8 @@ const PORTAL_ABI = [
64
64
  'function getTokenV3(address token) external view returns (uint8,uint256,uint256,uint256,uint8,uint256,uint256,address,bool)',
65
65
  'function getTokenV4(address token) external view returns ((uint8,uint256,uint256,uint256,uint8,uint256,uint256,address,bool,bytes32))',
66
66
  'function getTokenV5(address token) external view returns ((uint8,uint256,uint256,uint256,uint8,uint256,uint256,uint256,uint256,address,bool,bytes32))',
67
+ // V7: 包含 taxRate, pool, progress, lpFeeProfile
68
+ 'function getTokenV7(address token) external view returns ((uint8,uint256,uint256,uint256,uint8,uint256,uint256,uint256,uint256,address,bool,bytes32,uint256,address,uint256,uint8))',
67
69
  // 报价方法
68
70
  'function previewBuy(address token, uint256 ethAmount) external view returns (uint256)',
69
71
  'function previewSell(address token, uint256 tokenAmount) external view returns (uint256)',
@@ -88,6 +90,17 @@ const PORTAL_ABI = [
88
90
  'function version() external pure returns (string)',
89
91
  'function getLocks(address token) external view returns (uint256[])'
90
92
  ];
93
+ /**
94
+ * 将 lpFeeProfile 转换为 V3 fee 值
95
+ */
96
+ export function lpFeeProfileToV3Fee(profile) {
97
+ switch (profile) {
98
+ case V3LPFeeProfile.LP_FEE_PROFILE_STANDARD: return 2500;
99
+ case V3LPFeeProfile.LP_FEE_PROFILE_LOW: return 100;
100
+ case V3LPFeeProfile.LP_FEE_PROFILE_HIGH: return 10000;
101
+ default: return 2500; // 默认 STANDARD
102
+ }
103
+ }
91
104
  export class FlapPortal {
92
105
  constructor(cfg) {
93
106
  this.rpcUrl = cfg.rpcUrl;
@@ -144,6 +157,66 @@ export class FlapPortal {
144
157
  extensionID: raw[11],
145
158
  };
146
159
  }
160
+ /**
161
+ * 获取代币状态 V7(包含毕业相关信息)
162
+ * 注意:仅部分链支持 V7(如 XLayer v5.7+),不支持的链会 revert
163
+ */
164
+ async getTokenV7(token) {
165
+ const raw = await this.contract.getTokenV7(token);
166
+ return {
167
+ status: raw[0],
168
+ reserve: raw[1],
169
+ circulatingSupply: raw[2],
170
+ price: raw[3],
171
+ tokenVersion: raw[4],
172
+ r: raw[5],
173
+ h: raw[6],
174
+ k: raw[7],
175
+ dexSupplyThresh: raw[8],
176
+ quoteTokenAddress: raw[9],
177
+ nativeToQuoteSwapEnabled: raw[10],
178
+ extensionID: raw[11],
179
+ taxRate: raw[12],
180
+ pool: raw[13],
181
+ progress: raw[14],
182
+ lpFeeProfile: Number(raw[15]),
183
+ };
184
+ }
185
+ /**
186
+ * 计算距离毕业还需多少 OKB/ETH(含手续费)
187
+ * @param state TokenStateV5 或 TokenStateV7
188
+ * @returns 毕业相关信息
189
+ */
190
+ computeRemainingToGraduation(state) {
191
+ const r = Number(formatEther(state.r));
192
+ const h = Number(formatEther(state.h));
193
+ const k = Number(formatEther(state.k));
194
+ const curve = new CDPV2(r, h, k);
195
+ const currentReserve = formatEther(state.reserve);
196
+ const dexSupplyThresh = formatEther(state.dexSupplyThresh);
197
+ const circulatingSupply = formatEther(state.circulatingSupply);
198
+ // 计算毕业时的储备
199
+ const graduationReserve = curve.estimateReserve(dexSupplyThresh);
200
+ const graduationReserveNum = parseFloat(graduationReserve.toString());
201
+ const currentReserveNum = parseFloat(currentReserve);
202
+ // 是否已毕业 (status == 4 表示 DEX)
203
+ const isGraduated = state.status === 4;
204
+ // 还需多少(净值)
205
+ const remainingNet = Math.max(0, graduationReserveNum - currentReserveNum);
206
+ // 含手续费(1% buy fee)
207
+ const remainingWithFee = remainingNet / (1 - this.buyFeeRate);
208
+ // 计算进度
209
+ const progressPercent = isGraduated
210
+ ? '100.00'
211
+ : (currentReserveNum / graduationReserveNum * 100).toFixed(2);
212
+ return {
213
+ remainingOkb: remainingWithFee.toFixed(6),
214
+ graduationReserve: graduationReserveNum.toFixed(6),
215
+ currentReserve: currentReserveNum.toFixed(6),
216
+ isGraduated,
217
+ progressPercent,
218
+ };
219
+ }
147
220
  // 价格/进度
148
221
  computePriceAndProgress(state) {
149
222
  // 使用合约返回的实时价格,而不是重新计算
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, 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';
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, AAVolumeBuyFirstExecutor as XLayerAAVolumeBuyFirstExecutor, createAAVolumeBuyFirstExecutor as xlayerCreateAAVolumeBuyFirstExecutor, type VolumeBuyFirstParams as XLayerVolumeBuyFirstParams, type VolumeBuyFirstResult as XLayerVolumeBuyFirstResult, type VolumeContinuousParams as XLayerVolumeContinuousParams, type VolumeContinuousResult as XLayerVolumeContinuousResult, type VolumeProgress as XLayerVolumeProgress, 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
@@ -107,6 +107,8 @@ bundleBuy as xlayerBundleBuy, bundleSell as xlayerBundleSell, bundleBuySell as x
107
107
  makeVolume as xlayerMakeVolume, singleRoundVolume as xlayerSingleRoundVolume, createVolumeExecutor as xlayerCreateVolumeExecutor, VolumeExecutor as XLayerVolumeExecutor,
108
108
  // ✅ Buy-First 刷量(对齐 BSC buy-first)
109
109
  makeBuyFirstVolume as xlayerMakeBuyFirstVolume, BuyFirstVolumeExecutor as XLayerBuyFirstVolumeExecutor, AAPortalBuyFirstExecutor as XLayerAAPortalBuyFirstExecutor, AADexBuyFirstExecutor as XLayerAADexBuyFirstExecutor,
110
+ // ✅ Volume Buy-First(自动刷量)
111
+ AAVolumeBuyFirstExecutor as XLayerAAVolumeBuyFirstExecutor, createAAVolumeBuyFirstExecutor as xlayerCreateAAVolumeBuyFirstExecutor,
110
112
  // DEX 交易
111
113
  createDexExecutor as xlayerCreateDexExecutor, createDexQuery as xlayerCreateDexQuery, quoteOkbToToken as xlayerQuoteOkbToToken, quoteTokenToOkb as xlayerQuoteTokenToOkb, DexExecutor as XLayerDexExecutor, DexQuery as XLayerDexQuery,
112
114
  // AA 账户管理
@@ -1469,14 +1469,13 @@ export class BundleExecutor {
1469
1469
  // ✅ 并行构建和签名所有外盘买入 UserOps
1470
1470
  const signedDexBuyOps = await mapWithConcurrency(dexBuyData, 5, async (data) => {
1471
1471
  const { wallet, info, buyWei } = data;
1472
- // AA 模式外盘:使用 executeBatch Approve + Swap 合并为一个 UserOp
1473
- const approveData = encodeApproveCall(POTATOSWAP_V2_ROUTER);
1472
+ // 外盘买入:用 OKB 买代币,不需要 approve,直接调用 Router swap 方法
1474
1473
  const swapData = encodeSwapExactETHForTokensSupportingFee(0n, [WOKB, tokenAddress], info.sender, deadline);
1475
- const batchCallData = encodeExecuteBatch([tokenAddress, POTATOSWAP_V2_ROUTER], [0n, buyWei], [approveData, swapData]);
1474
+ const dexBuyCallData = encodeExecute(POTATOSWAP_V2_ROUTER, buyWei, swapData);
1476
1475
  const dexBuyOpRes = await aaManager.buildUserOpWithFixedGas({
1477
1476
  ownerWallet: wallet,
1478
1477
  sender: info.sender,
1479
- callData: batchCallData,
1478
+ callData: dexBuyCallData,
1480
1479
  nonce: nonceMap.next(info.sender),
1481
1480
  initCode: '0x', // HandleOps1 已部署
1482
1481
  deployed: true,
@@ -69,6 +69,7 @@ export { AADexSwapExecutor, } from './dex-bundle-swap.js';
69
69
  export { AAPortalBuyFirstExecutor, createAAPortalBuyFirstExecutor, } from './portal-buy-first.js';
70
70
  export { AADexBuyFirstExecutor, createAADexBuyFirstExecutor, } from './dex-buy-first.js';
71
71
  export { BuyFirstVolumeExecutor, createBuyFirstVolumeExecutor, makeBuyFirstVolume, } from './buy-first-volume.js';
72
+ export { AAVolumeBuyFirstExecutor, createAAVolumeBuyFirstExecutor, type VolumeMode, type VolumeTradeType, type VolumeBuyFirstParams, type VolumeBuyFirstResult, type VolumeContinuousParams, type VolumeContinuousResult, type VolumeProgress, } from './volume-buy-first.js';
72
73
  /**
73
74
  * XLayer AA 换手签名 (卖 -> 买)
74
75
  */
@@ -99,6 +99,10 @@ export { AADexSwapExecutor, } from './dex-bundle-swap.js';
99
99
  export { AAPortalBuyFirstExecutor, createAAPortalBuyFirstExecutor, } from './portal-buy-first.js';
100
100
  export { AADexBuyFirstExecutor, createAADexBuyFirstExecutor, } from './dex-buy-first.js';
101
101
  export { BuyFirstVolumeExecutor, createBuyFirstVolumeExecutor, makeBuyFirstVolume, } from './buy-first-volume.js';
102
+ // ============================================================================
103
+ // ✅ Volume Buy-First(自动刷量)
104
+ // ============================================================================
105
+ export { AAVolumeBuyFirstExecutor, createAAVolumeBuyFirstExecutor, } from './volume-buy-first.js';
102
106
  /**
103
107
  * XLayer AA 换手签名 (卖 -> 买)
104
108
  */
@@ -0,0 +1,102 @@
1
+ /**
2
+ * XLayer AA Volume Buy-First Executor
3
+ *
4
+ * 自动刷量执行器,支持 wash(一买一卖)和 bundle(多买多卖)模式
5
+ *
6
+ * 核心优化:
7
+ * - Nonce 预分配:减少 RPC 调用
8
+ * - 批量余额检查:提前验证钱包余额
9
+ * - 智能钱包轮换:避免同一钱包频繁交易
10
+ * - 并行构建 UserOps:提高执行效率
11
+ */
12
+ import type { XLayerConfig } from './types.js';
13
+ import type { BuyFirstResult } from './types.js';
14
+ export type VolumeMode = 'wash' | 'bundle';
15
+ export type VolumeTradeType = 'FLAP' | 'V2' | 'V3';
16
+ export interface VolumeBuyFirstParams {
17
+ mode: VolumeMode;
18
+ tradeType: VolumeTradeType;
19
+ tokenAddress: string;
20
+ buyerPrivateKeys: string[];
21
+ sellerPrivateKeys: string[];
22
+ buyerFunds: string;
23
+ buyCount?: number;
24
+ sellCount?: number;
25
+ config?: Partial<XLayerConfig>;
26
+ }
27
+ export interface VolumeBuyFirstResult {
28
+ mode: VolumeMode;
29
+ tradeType: VolumeTradeType;
30
+ buySellResult: BuyFirstResult['buySellResult'];
31
+ withdrawResult?: BuyFirstResult['withdrawResult'];
32
+ metadata: {
33
+ buyCount: number;
34
+ sellCount: number;
35
+ roundTimestamp: number;
36
+ [key: string]: any;
37
+ };
38
+ }
39
+ export interface VolumeContinuousParams {
40
+ mode: VolumeMode;
41
+ tradeType: VolumeTradeType;
42
+ tokenAddress: string;
43
+ wallets: Array<{
44
+ privateKey: string;
45
+ address: string;
46
+ }>;
47
+ minBuyAmt: number;
48
+ maxBuyAmt: number;
49
+ buyCount?: number;
50
+ sellCount?: number;
51
+ durationSec: number;
52
+ intervalSec: number;
53
+ washBatchWalletCount?: number;
54
+ config?: Partial<XLayerConfig>;
55
+ onProgress?: (progress: VolumeProgress) => void;
56
+ }
57
+ export interface VolumeProgress {
58
+ currentRound: number;
59
+ totalRounds: number;
60
+ successCount: number;
61
+ failureCount: number;
62
+ elapsedMs: number;
63
+ }
64
+ export interface VolumeContinuousResult {
65
+ totalRounds: number;
66
+ successRounds: number;
67
+ failureRounds: number;
68
+ rounds: VolumeBuyFirstResult[];
69
+ totalDuration: number;
70
+ metadata: {
71
+ mode: VolumeMode;
72
+ tradeType: VolumeTradeType;
73
+ avgRoundTime: number;
74
+ };
75
+ }
76
+ export declare class AAVolumeBuyFirstExecutor {
77
+ private portalExecutor;
78
+ private dexExecutor;
79
+ private walletRotation;
80
+ private config;
81
+ constructor(config?: XLayerConfig);
82
+ /**
83
+ * 执行单轮 Buy-First 刷量
84
+ */
85
+ executeRound(params: VolumeBuyFirstParams): Promise<VolumeBuyFirstResult>;
86
+ /**
87
+ * 执行多轮持续刷量
88
+ */
89
+ executeContinuous(params: VolumeContinuousParams): Promise<VolumeContinuousResult>;
90
+ /**
91
+ * 生成随机总买入金额
92
+ */
93
+ private generateRandomTotalAmount;
94
+ /**
95
+ * 延迟函数
96
+ */
97
+ private delay;
98
+ }
99
+ /**
100
+ * 创建 Volume Buy-First 执行器
101
+ */
102
+ export declare function createAAVolumeBuyFirstExecutor(config?: XLayerConfig): AAVolumeBuyFirstExecutor;
@@ -0,0 +1,258 @@
1
+ /**
2
+ * XLayer AA Volume Buy-First Executor
3
+ *
4
+ * 自动刷量执行器,支持 wash(一买一卖)和 bundle(多买多卖)模式
5
+ *
6
+ * 核心优化:
7
+ * - Nonce 预分配:减少 RPC 调用
8
+ * - 批量余额检查:提前验证钱包余额
9
+ * - 智能钱包轮换:避免同一钱包频繁交易
10
+ * - 并行构建 UserOps:提高执行效率
11
+ */
12
+ import { AAPortalBuyFirstExecutor } from './portal-buy-first.js';
13
+ import { AADexBuyFirstExecutor } from './dex-buy-first.js';
14
+ // ==================== 智能钱包轮换管理器 ====================
15
+ class WalletRotationManager {
16
+ constructor(cooldownMs = 60000) {
17
+ this.lastUsedTime = new Map();
18
+ this.cooldownMs = cooldownMs;
19
+ }
20
+ /**
21
+ * 选择可用的钱包(过滤冷却中的钱包)
22
+ */
23
+ selectWallets(candidates, count) {
24
+ const now = Date.now();
25
+ // 过滤掉冷却中的钱包
26
+ const available = candidates.filter((w) => {
27
+ const lastUsed = this.lastUsedTime.get(w.address.toLowerCase()) ?? 0;
28
+ return now - lastUsed >= this.cooldownMs;
29
+ });
30
+ if (available.length < count) {
31
+ throw new Error(`可用钱包不足:需要 ${count} 个,实际 ${available.length} 个(${candidates.length - available.length} 个冷却中)`);
32
+ }
33
+ // 随机选择
34
+ const selected = this.randomSelect(available, count);
35
+ // 记录使用时间
36
+ for (const wallet of selected) {
37
+ this.lastUsedTime.set(wallet.address.toLowerCase(), now);
38
+ }
39
+ return selected;
40
+ }
41
+ /**
42
+ * 重置所有钱包的冷却时间
43
+ */
44
+ reset() {
45
+ this.lastUsedTime.clear();
46
+ }
47
+ randomSelect(arr, count) {
48
+ const shuffled = [...arr].sort(() => Math.random() - 0.5);
49
+ return shuffled.slice(0, count);
50
+ }
51
+ }
52
+ // ==================== 核心执行器 ====================
53
+ export class AAVolumeBuyFirstExecutor {
54
+ constructor(config = {}) {
55
+ this.config = config;
56
+ this.portalExecutor = new AAPortalBuyFirstExecutor(config);
57
+ this.dexExecutor = new AADexBuyFirstExecutor(config);
58
+ this.walletRotation = new WalletRotationManager(60000); // 60 秒冷却
59
+ }
60
+ /**
61
+ * 执行单轮 Buy-First 刷量
62
+ */
63
+ async executeRound(params) {
64
+ const { mode, tradeType, tokenAddress, buyerPrivateKeys, sellerPrivateKeys, buyerFunds, buyCount, sellCount, config, } = params;
65
+ // 验证参数
66
+ if (buyerPrivateKeys.length === 0) {
67
+ throw new Error('buyerPrivateKeys 不能为空');
68
+ }
69
+ if (sellerPrivateKeys.length === 0) {
70
+ throw new Error('sellerPrivateKeys 不能为空');
71
+ }
72
+ // 合并配置
73
+ const effConfig = { ...this.config, ...config };
74
+ // 根据 tradeType 选择执行器
75
+ const executor = tradeType === 'FLAP' ? this.portalExecutor : this.dexExecutor;
76
+ // 构建 BuyFirstParams
77
+ const buyFirstParams = {
78
+ tradeType: tradeType === 'FLAP' ? 'FLAP' : 'V2',
79
+ routerVersion: tradeType === 'V3' ? 'V3' : 'V2',
80
+ tokenAddress,
81
+ buyerPrivateKeys,
82
+ sellerPrivateKeys,
83
+ buyerFunds,
84
+ buyCount: buyCount ?? buyerPrivateKeys.length,
85
+ sellCount: sellCount ?? sellerPrivateKeys.length,
86
+ withdrawToOwner: mode === 'wash', // wash 模式立即归集
87
+ config: effConfig,
88
+ };
89
+ // 执行 buy-first
90
+ const result = await executor.execute(buyFirstParams);
91
+ return {
92
+ mode,
93
+ tradeType,
94
+ buySellResult: result.buySellResult,
95
+ withdrawResult: result.withdrawResult,
96
+ metadata: {
97
+ ...result.metadata,
98
+ buyCount: buyCount ?? buyerPrivateKeys.length,
99
+ sellCount: sellCount ?? sellerPrivateKeys.length,
100
+ roundTimestamp: Date.now(),
101
+ },
102
+ };
103
+ }
104
+ /**
105
+ * 执行多轮持续刷量
106
+ */
107
+ async executeContinuous(params) {
108
+ const { mode, tradeType, tokenAddress, wallets, minBuyAmt, maxBuyAmt, buyCount = 1, sellCount = 1, durationSec, intervalSec, washBatchWalletCount = 23, config, onProgress, } = params;
109
+ const startTime = Date.now();
110
+ const endTime = startTime + durationSec * 1000;
111
+ const rounds = [];
112
+ let successCount = 0;
113
+ let failureCount = 0;
114
+ // 重置钱包轮换状态
115
+ this.walletRotation.reset();
116
+ console.log(`\n[AAVolumeBuyFirstExecutor] 开始持续刷量`);
117
+ console.log(` 模式: ${mode}`);
118
+ console.log(` 交易类型: ${tradeType}`);
119
+ console.log(` 钱包数: ${wallets.length}`);
120
+ console.log(` 持续时间: ${durationSec} 秒`);
121
+ console.log(` 间隔: ${intervalSec} 秒\n`);
122
+ while (Date.now() < endTime) {
123
+ try {
124
+ if (mode === 'wash') {
125
+ // ✅ Wash 模式:按批次轮询
126
+ for (let i = 0; i < wallets.length; i += washBatchWalletCount) {
127
+ if (Date.now() >= endTime)
128
+ break;
129
+ const batch = wallets.slice(i, i + washBatchWalletCount);
130
+ const totalBuyAmount = this.generateRandomTotalAmount(batch.length, minBuyAmt, maxBuyAmt);
131
+ console.log(`[Wash Round ${rounds.length + 1}] 钱包 ${i + 1}-${i + batch.length}/${wallets.length}, 总买入: ${totalBuyAmount} OKB`);
132
+ const result = await this.executeRound({
133
+ mode: 'wash',
134
+ tradeType,
135
+ tokenAddress,
136
+ buyerPrivateKeys: batch.map((w) => w.privateKey),
137
+ sellerPrivateKeys: batch.map((w) => w.privateKey),
138
+ buyerFunds: totalBuyAmount,
139
+ buyCount: batch.length,
140
+ sellCount: batch.length,
141
+ config,
142
+ });
143
+ rounds.push(result);
144
+ successCount++;
145
+ // 进度回调
146
+ if (onProgress) {
147
+ onProgress({
148
+ currentRound: rounds.length,
149
+ totalRounds: Math.ceil((durationSec * 1000) / (intervalSec * 1000)),
150
+ successCount,
151
+ failureCount,
152
+ elapsedMs: Date.now() - startTime,
153
+ });
154
+ }
155
+ // 等待间隔
156
+ if (Date.now() < endTime) {
157
+ await this.delay(intervalSec * 1000);
158
+ }
159
+ }
160
+ }
161
+ else {
162
+ // ✅ Bundle 模式:随机选择买方和卖方
163
+ const buyers = this.walletRotation.selectWallets(wallets, buyCount);
164
+ const sellers = this.walletRotation.selectWallets(wallets, sellCount);
165
+ const totalBuyAmount = this.generateRandomTotalAmount(buyCount, minBuyAmt, maxBuyAmt);
166
+ console.log(`[Bundle Round ${rounds.length + 1}] ${buyCount} 买 ${sellCount} 卖, 总买入: ${totalBuyAmount} OKB`);
167
+ const result = await this.executeRound({
168
+ mode: 'bundle',
169
+ tradeType,
170
+ tokenAddress,
171
+ buyerPrivateKeys: buyers.map((w) => w.privateKey),
172
+ sellerPrivateKeys: sellers.map((w) => w.privateKey),
173
+ buyerFunds: totalBuyAmount,
174
+ buyCount,
175
+ sellCount,
176
+ config,
177
+ });
178
+ rounds.push(result);
179
+ successCount++;
180
+ // 进度回调
181
+ if (onProgress) {
182
+ onProgress({
183
+ currentRound: rounds.length,
184
+ totalRounds: Math.ceil((durationSec * 1000) / (intervalSec * 1000)),
185
+ successCount,
186
+ failureCount,
187
+ elapsedMs: Date.now() - startTime,
188
+ });
189
+ }
190
+ // 等待间隔
191
+ if (Date.now() < endTime) {
192
+ await this.delay(intervalSec * 1000);
193
+ }
194
+ }
195
+ }
196
+ catch (error) {
197
+ console.error(`[Round ${rounds.length + 1}] 执行失败:`, error);
198
+ failureCount++;
199
+ // 进度回调
200
+ if (onProgress) {
201
+ onProgress({
202
+ currentRound: rounds.length,
203
+ totalRounds: Math.ceil((durationSec * 1000) / (intervalSec * 1000)),
204
+ successCount,
205
+ failureCount,
206
+ elapsedMs: Date.now() - startTime,
207
+ });
208
+ }
209
+ // 失败后等待间隔再继续
210
+ if (Date.now() < endTime) {
211
+ await this.delay(intervalSec * 1000);
212
+ }
213
+ }
214
+ }
215
+ const totalDuration = Date.now() - startTime;
216
+ const avgRoundTime = rounds.length > 0 ? totalDuration / rounds.length : 0;
217
+ console.log(`\n[AAVolumeBuyFirstExecutor] 刷量完成`);
218
+ console.log(` 总轮数: ${rounds.length}`);
219
+ console.log(` 成功: ${successCount}`);
220
+ console.log(` 失败: ${failureCount}`);
221
+ console.log(` 总耗时: ${(totalDuration / 1000).toFixed(2)} 秒`);
222
+ console.log(` 平均每轮: ${(avgRoundTime / 1000).toFixed(2)} 秒\n`);
223
+ return {
224
+ totalRounds: rounds.length,
225
+ successRounds: successCount,
226
+ failureRounds: failureCount,
227
+ rounds,
228
+ totalDuration,
229
+ metadata: {
230
+ mode,
231
+ tradeType,
232
+ avgRoundTime,
233
+ },
234
+ };
235
+ }
236
+ /**
237
+ * 生成随机总买入金额
238
+ */
239
+ generateRandomTotalAmount(count, min, max) {
240
+ const amounts = Array(count)
241
+ .fill(0)
242
+ .map(() => min + Math.random() * (max - min));
243
+ const total = amounts.reduce((a, b) => a + b, 0);
244
+ return total.toFixed(6);
245
+ }
246
+ /**
247
+ * 延迟函数
248
+ */
249
+ delay(ms) {
250
+ return new Promise((resolve) => setTimeout(resolve, ms));
251
+ }
252
+ }
253
+ /**
254
+ * 创建 Volume Buy-First 执行器
255
+ */
256
+ export function createAAVolumeBuyFirstExecutor(config) {
257
+ return new AAVolumeBuyFirstExecutor(config);
258
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.5.67",
3
+ "version": "1.5.69",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,16 +0,0 @@
1
- /**
2
- * ECDH + AES-GCM 加密工具(浏览器兼容)
3
- * 用于将签名交易用服务器公钥加密
4
- */
5
- /**
6
- * 用服务器公钥加密签名交易(ECDH + AES-GCM)
7
- *
8
- * @param signedTransactions 签名后的交易数组
9
- * @param publicKeyBase64 服务器提供的公钥(Base64 格式)
10
- * @returns JSON 字符串 {e: 临时公钥, i: IV, d: 密文}
11
- */
12
- export declare function encryptWithPublicKey(signedTransactions: string[], publicKeyBase64: string): Promise<string>;
13
- /**
14
- * 验证公钥格式(Base64)
15
- */
16
- export declare function validatePublicKey(publicKeyBase64: string): boolean;
@@ -1,146 +0,0 @@
1
- /**
2
- * ECDH + AES-GCM 加密工具(浏览器兼容)
3
- * 用于将签名交易用服务器公钥加密
4
- */
5
- /**
6
- * 获取全局 crypto 对象(最简单直接的方式)
7
- */
8
- function getCryptoAPI() {
9
- // 尝试所有可能的全局对象,优先浏览器环境
10
- const cryptoObj = (typeof window !== 'undefined' && window.crypto) ||
11
- (typeof self !== 'undefined' && self.crypto) ||
12
- (typeof global !== 'undefined' && global.crypto) ||
13
- (typeof globalThis !== 'undefined' && globalThis.crypto);
14
- if (!cryptoObj) {
15
- const env = typeof window !== 'undefined' ? 'Browser' : 'Node.js';
16
- const protocol = typeof location !== 'undefined' ? location.protocol : 'unknown';
17
- throw new Error(`❌ Crypto API 不可用。环境: ${env}, 协议: ${protocol}. ` +
18
- '请确保在 HTTPS 或 localhost 下运行');
19
- }
20
- return cryptoObj;
21
- }
22
- /**
23
- * 获取 SubtleCrypto(用于加密操作)
24
- */
25
- function getSubtleCrypto() {
26
- const crypto = getCryptoAPI();
27
- if (!crypto.subtle) {
28
- const protocol = typeof location !== 'undefined' ? location.protocol : 'unknown';
29
- const hostname = typeof location !== 'undefined' ? location.hostname : 'unknown';
30
- throw new Error(`❌ SubtleCrypto API 不可用。协议: ${protocol}, 主机: ${hostname}. ` +
31
- '请确保:1) 使用 HTTPS (或 localhost);2) 浏览器支持 Web Crypto API;' +
32
- '3) 不在无痕/隐私浏览模式下');
33
- }
34
- return crypto.subtle;
35
- }
36
- /**
37
- * Base64 转 ArrayBuffer(优先使用浏览器 API)
38
- */
39
- function base64ToArrayBuffer(base64) {
40
- // 浏览器环境(优先)
41
- if (typeof atob !== 'undefined') {
42
- const binaryString = atob(base64);
43
- const bytes = new Uint8Array(binaryString.length);
44
- for (let i = 0; i < binaryString.length; i++) {
45
- bytes[i] = binaryString.charCodeAt(i);
46
- }
47
- return bytes.buffer;
48
- }
49
- // Node.js 环境(fallback)
50
- if (typeof Buffer !== 'undefined') {
51
- return Buffer.from(base64, 'base64').buffer;
52
- }
53
- throw new Error('❌ Base64 解码不可用');
54
- }
55
- /**
56
- * ArrayBuffer 转 Base64(优先使用浏览器 API)
57
- */
58
- function arrayBufferToBase64(buffer) {
59
- // 浏览器环境(优先)
60
- if (typeof btoa !== 'undefined') {
61
- const bytes = new Uint8Array(buffer);
62
- let binary = '';
63
- for (let i = 0; i < bytes.length; i++) {
64
- binary += String.fromCharCode(bytes[i]);
65
- }
66
- return btoa(binary);
67
- }
68
- // Node.js 环境(fallback)
69
- if (typeof Buffer !== 'undefined') {
70
- return Buffer.from(buffer).toString('base64');
71
- }
72
- throw new Error('❌ Base64 编码不可用');
73
- }
74
- /**
75
- * 生成随机 Hex 字符串
76
- */
77
- function randomHex(length) {
78
- const crypto = getCryptoAPI();
79
- const array = new Uint8Array(length);
80
- crypto.getRandomValues(array);
81
- return Array.from(array)
82
- .map(b => b.toString(16).padStart(2, '0'))
83
- .join('');
84
- }
85
- /**
86
- * 用服务器公钥加密签名交易(ECDH + AES-GCM)
87
- *
88
- * @param signedTransactions 签名后的交易数组
89
- * @param publicKeyBase64 服务器提供的公钥(Base64 格式)
90
- * @returns JSON 字符串 {e: 临时公钥, i: IV, d: 密文}
91
- */
92
- export async function encryptWithPublicKey(signedTransactions, publicKeyBase64) {
93
- try {
94
- // 0. 获取 SubtleCrypto 和 Crypto API
95
- const subtle = getSubtleCrypto();
96
- const crypto = getCryptoAPI();
97
- // 1. 准备数据
98
- const payload = {
99
- signedTransactions,
100
- timestamp: Date.now(),
101
- nonce: randomHex(8)
102
- };
103
- const plaintext = JSON.stringify(payload);
104
- // 2. 生成临时 ECDH 密钥对
105
- const ephemeralKeyPair = await subtle.generateKey({ name: 'ECDH', namedCurve: 'P-256' }, true, ['deriveKey']);
106
- // 3. 导入服务器公钥
107
- const publicKeyBuffer = base64ToArrayBuffer(publicKeyBase64);
108
- const publicKey = await subtle.importKey('raw', publicKeyBuffer, { name: 'ECDH', namedCurve: 'P-256' }, false, []);
109
- // 4. 派生共享密钥(AES-256)
110
- const sharedKey = await subtle.deriveKey({ name: 'ECDH', public: publicKey }, ephemeralKeyPair.privateKey, { name: 'AES-GCM', length: 256 }, false, ['encrypt']);
111
- // 5. AES-GCM 加密
112
- const iv = crypto.getRandomValues(new Uint8Array(12));
113
- const encrypted = await subtle.encrypt({ name: 'AES-GCM', iv }, sharedKey, new TextEncoder().encode(plaintext));
114
- // 6. 导出临时公钥
115
- const ephemeralPublicKeyRaw = await subtle.exportKey('raw', ephemeralKeyPair.publicKey);
116
- // 7. 返回加密包(JSON 格式)
117
- return JSON.stringify({
118
- e: arrayBufferToBase64(ephemeralPublicKeyRaw), // 临时公钥
119
- i: arrayBufferToBase64(iv.buffer), // IV
120
- d: arrayBufferToBase64(encrypted) // 密文
121
- });
122
- }
123
- catch (error) {
124
- throw new Error(`加密失败: ${error?.message || String(error)}`);
125
- }
126
- }
127
- /**
128
- * 验证公钥格式(Base64)
129
- */
130
- export function validatePublicKey(publicKeyBase64) {
131
- try {
132
- if (!publicKeyBase64)
133
- return false;
134
- // Base64 字符集验证
135
- if (!/^[A-Za-z0-9+/=]+$/.test(publicKeyBase64))
136
- return false;
137
- // ECDH P-256 公钥固定长度 65 字节(未压缩)
138
- // Base64 编码后约 88 字符
139
- if (publicKeyBase64.length < 80 || publicKeyBase64.length > 100)
140
- return false;
141
- return true;
142
- }
143
- catch {
144
- return false;
145
- }
146
- }