four-flap-meme-sdk 1.6.97 → 1.6.98

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 CHANGED
@@ -40,8 +40,8 @@ export { privateSaleMerkle, batchPrivateSaleMerkle, type PrivateSaleSignConfig,
40
40
  export { inspectTokenLP, getFactoryFromRouter, registerDYORSwap, registerDex, getChainConfig, type LPInfo, type LPPlatform, type InspectOptions, type DexConfig, type ChainDexConfig, } from './utils/lp-inspect.js';
41
41
  export { disperseWithBundle, sweepWithBundle, type DisperseSignParams, type SweepSignParams, type SignedTransactionsResult, type DisperseParams, type SweepParams, type BundleSubmitResult } from './utils/airdrop-sweep.js';
42
42
  export { fourBundleSwapMerkle, fourBatchSwapMerkle, fourQuickBatchSwapMerkle, type FourSwapSignConfig, type FourSwapConfig, type FourBundleSwapSignParams, type FourBundleSwapParams, type FourSwapResult, type FourBatchSwapSignParams, type FourBatchSwapResult, type FourQuickBatchSwapSignParams, type FourQuickBatchSwapResult } from './contracts/tm-bundle-merkle/swap.js';
43
- export { flapBundleSwapMerkle, flapBatchSwapMerkle, flapQuickBatchSwapMerkle, type FlapSwapSignConfig, type FlapSwapConfig, type FlapBundleSwapSignParams, type FlapBundleSwapParams, type FlapSwapResult, type FlapBatchSwapSignParams, type FlapBatchSwapResult, type FlapQuickBatchSwapSignParams, type FlapQuickBatchSwapResult } from './flap/portal-bundle-merkle/swap.js';
44
- export { pancakeBundleSwapMerkle, pancakeBatchSwapMerkle, pancakeQuickBatchSwapMerkle, type PancakeSwapSignConfig, type PancakeBundleSwapSignParams, type PancakeSwapConfig, type PancakeBundleSwapParams, type PancakeSwapResult, type PancakeBatchSwapSignParams, type PancakeBatchSwapResult, type PancakeQuickBatchSwapParams, type PancakeQuickBatchSwapResult, type SwapRouteType, type V2RouteParams, type V3SingleRouteParams, type V3MultiRouteParams, type RouteParams } from './pancake/bundle-swap.js';
43
+ export { flapBundleSwapMerkle, flapBatchSwapMerkle, flapQuickBatchSwapMerkle, flapCrossSwapMerkle, type FlapSwapSignConfig, type FlapSwapConfig, type FlapBundleSwapSignParams, type FlapBundleSwapParams, type FlapSwapResult, type FlapBatchSwapSignParams, type FlapBatchSwapResult, type FlapQuickBatchSwapSignParams, type FlapQuickBatchSwapResult, type FlapCrossSwapParams, type FlapCrossSwapResult } from './flap/portal-bundle-merkle/swap.js';
44
+ export { pancakeBundleSwapMerkle, pancakeBatchSwapMerkle, pancakeQuickBatchSwapMerkle, pancakeCrossSwapMerkle, type PancakeSwapSignConfig, type PancakeBundleSwapSignParams, type PancakeSwapConfig, type PancakeBundleSwapParams, type PancakeSwapResult, type PancakeBatchSwapSignParams, type PancakeBatchSwapResult, type PancakeQuickBatchSwapParams, type PancakeQuickBatchSwapResult, type PancakeCrossSwapParams, type PancakeCrossSwapResult, type SwapRouteType, type V2RouteParams, type V3SingleRouteParams, type V3MultiRouteParams, type RouteParams } from './pancake/bundle-swap.js';
45
45
  export { fourBundleBuyFirstMerkle, type FourBuyFirstConfig, type FourBundleBuyFirstParams, type FourBuyFirstSignConfig, type FourBundleBuyFirstSignParams, type FourBuyFirstResult } from './contracts/tm-bundle-merkle/swap-buy-first.js';
46
46
  export { flapBundleBuyFirstMerkle, type FlapBuyFirstSignConfig, type FlapBuyFirstConfig, type FlapBundleBuyFirstSignParams, type FlapBundleBuyFirstParams, type FlapBuyFirstResult } from './flap/portal-bundle-merkle/swap-buy-first.js';
47
47
  export { pancakeBundleBuyFirstMerkle, type PancakeBuyFirstSignConfig, type PancakeBuyFirstConfig, type PancakeBundleBuyFirstSignParams, type PancakeBundleBuyFirstParams, type PancakeBuyFirstResult } from './pancake/bundle-buy-first.js';
package/dist/index.js CHANGED
@@ -66,9 +66,9 @@ export { disperseWithBundle, sweepWithBundle } from './utils/airdrop-sweep.js';
66
66
  // Four内盘换手
67
67
  export { fourBundleSwapMerkle, fourBatchSwapMerkle, fourQuickBatchSwapMerkle } from './contracts/tm-bundle-merkle/swap.js';
68
68
  // Flap内盘换手
69
- export { flapBundleSwapMerkle, flapBatchSwapMerkle, flapQuickBatchSwapMerkle } from './flap/portal-bundle-merkle/swap.js';
69
+ export { flapBundleSwapMerkle, flapBatchSwapMerkle, flapQuickBatchSwapMerkle, flapCrossSwapMerkle } from './flap/portal-bundle-merkle/swap.js';
70
70
  // PancakeSwap V2/V3通用换手
71
- export { pancakeBundleSwapMerkle, pancakeBatchSwapMerkle, pancakeQuickBatchSwapMerkle } from './pancake/bundle-swap.js';
71
+ export { pancakeBundleSwapMerkle, pancakeBatchSwapMerkle, pancakeQuickBatchSwapMerkle, pancakeCrossSwapMerkle } from './pancake/bundle-swap.js';
72
72
  // 先买后卖(Buy-First)入口
73
73
  export { fourBundleBuyFirstMerkle } from './contracts/tm-bundle-merkle/swap-buy-first.js';
74
74
  export { flapBundleBuyFirstMerkle } from './flap/portal-bundle-merkle/swap-buy-first.js';
@@ -170,3 +170,43 @@ export interface PancakeQuickBatchSwapResult {
170
170
  * 限制:根据多跳数动态计算最大买方数量
171
171
  */
172
172
  export declare function pancakeQuickBatchSwapMerkle(params: PancakeQuickBatchSwapParams): Promise<PancakeQuickBatchSwapResult>;
173
+ /** 交叉换手参数(PancakeSwap V2/V3) */
174
+ export interface PancakeCrossSwapParams {
175
+ /** 卖方私钥列表(按顺序轮流卖出) */
176
+ sellerPrivateKeys: string[];
177
+ /** 每个卖方的卖出数量(与 sellerPrivateKeys 长度一致) */
178
+ sellAmounts: string[];
179
+ /** 买方私钥列表(按顺序轮流分配,每笔平分) */
180
+ buyerPrivateKeys: string[];
181
+ tokenAddress: string;
182
+ routeParams: RouteParams;
183
+ config: PancakeSwapSignConfig;
184
+ quoteToken?: string;
185
+ quoteTokenDecimals?: number;
186
+ /** 每次卖出分配给多少个买方(默认使用全部买方平分) */
187
+ buyersPerSell?: number;
188
+ /** 转账多跳数(可选) */
189
+ disperseHopCount?: number;
190
+ }
191
+ /** 交叉换手结果(PancakeSwap V2/V3) */
192
+ export interface PancakeCrossSwapResult {
193
+ signedTransactions: string[];
194
+ /** 每轮的元数据列表 */
195
+ rounds: Array<{
196
+ sellerAddress: string;
197
+ buyerAddresses: string[];
198
+ sellAmount: string;
199
+ bundleHash?: string;
200
+ }>;
201
+ /** 汇总的中间钱包信息(转账/利润) */
202
+ disperseHopWallets?: GeneratedWallet[];
203
+ profitHopWallets?: GeneratedWallet[];
204
+ }
205
+ /**
206
+ * PancakeSwap 交叉换手(多卖多买,循环执行)
207
+ * - 每个卖方单独卖出,买入金额由卖出所得等分分配给当轮买方
208
+ * - 利润刮取、转账多跳逻辑继承 pancakeQuickBatchSwapMerkle
209
+ * - 结果按顺序拼接 signedTransactions(可交由前端/后端顺序广播)
210
+ * - ✅ 正确处理 nonce:同一钱包在多轮中使用时 nonce 自动递增
211
+ */
212
+ export declare function pancakeCrossSwapMerkle(params: PancakeCrossSwapParams): Promise<PancakeCrossSwapResult>;
@@ -1477,3 +1477,141 @@ export async function pancakeQuickBatchSwapMerkle(params) {
1477
1477
  }
1478
1478
  };
1479
1479
  }
1480
+ /**
1481
+ * PancakeSwap 交叉换手(多卖多买,循环执行)
1482
+ * - 每个卖方单独卖出,买入金额由卖出所得等分分配给当轮买方
1483
+ * - 利润刮取、转账多跳逻辑继承 pancakeQuickBatchSwapMerkle
1484
+ * - 结果按顺序拼接 signedTransactions(可交由前端/后端顺序广播)
1485
+ * - ✅ 正确处理 nonce:同一钱包在多轮中使用时 nonce 自动递增
1486
+ */
1487
+ export async function pancakeCrossSwapMerkle(params) {
1488
+ const { sellerPrivateKeys, sellAmounts, buyerPrivateKeys, tokenAddress, routeParams, config, quoteToken, quoteTokenDecimals = 18, buyersPerSell, disperseHopCount = 0 } = params;
1489
+ if (sellerPrivateKeys.length === 0) {
1490
+ throw new Error('至少需要一个卖方');
1491
+ }
1492
+ if (sellerPrivateKeys.length !== sellAmounts.length) {
1493
+ throw new Error(`sellAmounts 长度 (${sellAmounts.length}) 必须与卖方数量 (${sellerPrivateKeys.length}) 一致`);
1494
+ }
1495
+ if (buyerPrivateKeys.length === 0) {
1496
+ throw new Error('至少需要一个买方');
1497
+ }
1498
+ // ✅ 创建 Provider 和 NonceManager
1499
+ const context = createPancakeContext(config);
1500
+ const nonceManager = new NonceManager(context.provider);
1501
+ // ✅ 预先获取所有钱包的初始 nonce
1502
+ const allSellerWallets = sellerPrivateKeys.map(pk => new Wallet(pk, context.provider));
1503
+ const allBuyerWallets = buyerPrivateKeys.map(pk => new Wallet(pk, context.provider));
1504
+ // 使用 Map 去重(同一私钥可能出现多次)
1505
+ const addressToNonce = new Map();
1506
+ // 获取所有卖方 nonce
1507
+ for (const wallet of allSellerWallets) {
1508
+ if (!addressToNonce.has(wallet.address)) {
1509
+ const nonce = await nonceManager.getNextNonce(wallet);
1510
+ addressToNonce.set(wallet.address, nonce);
1511
+ }
1512
+ }
1513
+ // 获取所有买方 nonce
1514
+ for (const wallet of allBuyerWallets) {
1515
+ if (!addressToNonce.has(wallet.address)) {
1516
+ const nonce = await nonceManager.getNextNonce(wallet);
1517
+ addressToNonce.set(wallet.address, nonce);
1518
+ }
1519
+ }
1520
+ console.log(`[pancakeCrossSwapMerkle] 初始化完成: ${sellerPrivateKeys.length} 卖方, ${buyerPrivateKeys.length} 买方`);
1521
+ const allSigned = [];
1522
+ const allDisperse = [];
1523
+ const allProfit = [];
1524
+ const rounds = [];
1525
+ // 轮流分配买方:每轮取 buyersPerSell 个(默认所有买方),不足则从头继续
1526
+ let buyerCursor = 0;
1527
+ const buyerBatchSize = Math.max(1, buyersPerSell ?? buyerPrivateKeys.length);
1528
+ // 判断是否使用原生代币
1529
+ const useNativeToken = !quoteToken || quoteToken === ZERO_ADDRESS;
1530
+ // 获取贿赂金额
1531
+ const bribeAmount = config.bribeAmount && config.bribeAmount > 0
1532
+ ? ethers.parseEther(String(config.bribeAmount))
1533
+ : 0n;
1534
+ const hasBribe = bribeAmount > 0n;
1535
+ for (let i = 0; i < sellerPrivateKeys.length; i++) {
1536
+ const sellerPk = sellerPrivateKeys[i];
1537
+ const sellAmount = sellAmounts[i];
1538
+ const sellerWallet = allSellerWallets[i];
1539
+ // 选取本轮买方私钥和钱包
1540
+ const roundBuyerPks = [];
1541
+ const roundBuyerWallets = [];
1542
+ for (let k = 0; k < buyerBatchSize; k++) {
1543
+ const idx = buyerCursor % buyerPrivateKeys.length;
1544
+ roundBuyerPks.push(buyerPrivateKeys[idx]);
1545
+ roundBuyerWallets.push(allBuyerWallets[idx]);
1546
+ buyerCursor++;
1547
+ }
1548
+ // ✅ 获取卖方当前 nonce
1549
+ const sellerNonce = addressToNonce.get(sellerWallet.address);
1550
+ // ✅ 获取并更新买方 nonces(每个买方本轮需要 1 个 nonce)
1551
+ const roundBuyerNonces = roundBuyerWallets.map(w => {
1552
+ const nonce = addressToNonce.get(w.address);
1553
+ addressToNonce.set(w.address, nonce + 1); // 每个买方用 1 个 nonce
1554
+ return nonce;
1555
+ });
1556
+ // 平分买入金额(使用比例模式,避免固定金额超出可分配金额)
1557
+ const ratio = 1 / roundBuyerPks.length;
1558
+ const buyerRatios = roundBuyerPks.map(() => ratio);
1559
+ // ✅ 构建 startNonces: [sellerNonce, buyer1Nonce, buyer2Nonce, ...]
1560
+ const startNonces = [sellerNonce, ...roundBuyerNonces];
1561
+ // ✅ 预先计算卖方 nonce 消耗(精确计算)
1562
+ // 卖方 nonce 消耗 = 贿赂(0/1) + 卖出(1) + 转账(N 或 N*2) + 利润(1)
1563
+ const hasProfit = true; // 默认有利润刮取
1564
+ let sellerNonceConsumed = 0;
1565
+ if (hasBribe)
1566
+ sellerNonceConsumed += 1; // 贿赂
1567
+ sellerNonceConsumed += 1; // 卖出
1568
+ if (disperseHopCount === 0) {
1569
+ sellerNonceConsumed += roundBuyerPks.length; // 直接转账
1570
+ }
1571
+ else if (useNativeToken) {
1572
+ sellerNonceConsumed += roundBuyerPks.length; // 原生多跳:seller→hop1
1573
+ }
1574
+ else {
1575
+ sellerNonceConsumed += roundBuyerPks.length * 2; // ERC20 多跳:BNB + ERC20 两批
1576
+ }
1577
+ if (hasProfit)
1578
+ sellerNonceConsumed += 1; // 利润
1579
+ // 调用单卖多买的签名函数
1580
+ const res = await pancakeQuickBatchSwapMerkle({
1581
+ sellerPrivateKey: sellerPk,
1582
+ sellAmount,
1583
+ buyerPrivateKeys: roundBuyerPks,
1584
+ buyerRatios,
1585
+ tokenAddress,
1586
+ routeParams,
1587
+ config,
1588
+ quoteToken,
1589
+ quoteTokenDecimals,
1590
+ disperseHopCount,
1591
+ startNonces // ✅ 传入预计算的 nonces
1592
+ });
1593
+ // ✅ 更新卖方 nonce(使用精确计算的值)
1594
+ addressToNonce.set(sellerWallet.address, sellerNonce + sellerNonceConsumed);
1595
+ console.log(`[pancakeCrossSwapMerkle] 轮次 ${i + 1}: 卖方=${sellerWallet.address.slice(0, 10)}..., 买方=${roundBuyerPks.length}, 交易=${res.signedTransactions.length}`);
1596
+ // 累积签名与中间钱包
1597
+ allSigned.push(...res.signedTransactions);
1598
+ if (res.disperseHopWallets)
1599
+ allDisperse.push(...res.disperseHopWallets);
1600
+ if (res.profitHopWallets)
1601
+ allProfit.push(...res.profitHopWallets);
1602
+ rounds.push({
1603
+ sellerAddress: res.metadata?.sellerAddress || '',
1604
+ buyerAddresses: res.metadata?.buyerAddresses || roundBuyerPks.map(() => ''),
1605
+ sellAmount,
1606
+ bundleHash: undefined
1607
+ });
1608
+ }
1609
+ nonceManager.clearTemp();
1610
+ console.log(`[pancakeCrossSwapMerkle] 完成: ${rounds.length} 轮, ${allSigned.length} 笔交易`);
1611
+ return {
1612
+ signedTransactions: allSigned,
1613
+ rounds,
1614
+ disperseHopWallets: allDisperse.length > 0 ? allDisperse : undefined,
1615
+ profitHopWallets: allProfit.length > 0 ? allProfit : undefined
1616
+ };
1617
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.6.97",
3
+ "version": "1.6.98",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",