four-flap-meme-sdk 1.7.72 → 1.7.74

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.
@@ -338,31 +338,84 @@ export async function batchBuyWithBundleMerkle(params) {
338
338
  fundsList: adjustedFundsList, // ✅ 使用调整后的金额
339
339
  useNativeToken // ✅ USDT 购买时 value=0,BNB 购买时 value=金额
340
340
  });
341
- // ✅ 利润多跳转账(强制 2 跳中转)
341
+ // ✅ 利润多跳转账
342
342
  const profitTxs = [];
343
343
  let profitHopWallets;
344
- if (extractProfit && nativeProfitAmount > 0n && maxFundsIndex >= 0) {
345
- const profitNonce = buyerNonces[maxFundsIndex] + 1;
346
- const profitHopResult = await buildProfitHopTransactions({
347
- provider,
348
- payerWallet: buyers[maxFundsIndex],
349
- profitAmount: nativeProfitAmount,
350
- profitRecipient: getProfitRecipient(),
351
- hopCount: PROFIT_HOP_COUNT,
352
- gasPrice,
353
- chainId,
354
- txType: getTxType(config),
355
- startNonce: profitNonce
356
- });
357
- profitTxs.push(...profitHopResult.signedTransactions);
358
- profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
344
+ // 检查是否使用分布式利润模式
345
+ const profitMode = config.profitMode || 'single';
346
+ console.log('🔧 [SDK batchBuyWithBundleMerkle] config.profitMode:', config.profitMode, '-> resolved:', profitMode, 'wallets:', buyers.length);
347
+ if (extractProfit && nativeProfitAmount > 0n) {
348
+ if (profitMode === 'distributed') {
349
+ // ✅ 分布式模式:每个钱包独立扣除自己的利润,每个都有独立的多跳
350
+ // 最多支持 12 个钱包(12 交易 + 36 多跳 + 1 贿赂 = 49 笔)
351
+ const MAX_DISTRIBUTED_WALLETS = 12;
352
+ console.log('🔧 [SDK] 使用分布式利润模式,钱包数:', buyers.length);
353
+ if (buyers.length > MAX_DISTRIBUTED_WALLETS) {
354
+ throw new Error(`分布式利润模式最多支持 ${MAX_DISTRIBUTED_WALLETS} 个钱包,当前 ${buyers.length} 个`);
355
+ }
356
+ profitHopWallets = [];
357
+ // 计算每个钱包的利润(按比例分配)
358
+ const perWalletProfits = [];
359
+ for (let i = 0; i < buyers.length; i++) {
360
+ const walletOriginalAmount = originalAmounts[i];
361
+ // 按比例计算该钱包应承担的利润
362
+ const walletProfit = totalBuyAmount > 0n
363
+ ? (nativeProfitAmount * walletOriginalAmount) / totalBuyAmount
364
+ : 0n;
365
+ perWalletProfits.push(walletProfit);
366
+ }
367
+ // 为每个钱包生成独立的利润多跳交易
368
+ for (let i = 0; i < buyers.length; i++) {
369
+ const walletProfit = perWalletProfits[i];
370
+ if (walletProfit > 0n) {
371
+ const profitNonce = buyerNonces[i] + 1; // 每个钱包买入后 +1
372
+ const profitHopResult = await buildProfitHopTransactions({
373
+ provider,
374
+ payerWallet: buyers[i],
375
+ profitAmount: walletProfit,
376
+ profitRecipient: getProfitRecipient(),
377
+ hopCount: PROFIT_HOP_COUNT,
378
+ gasPrice,
379
+ chainId,
380
+ txType: getTxType(config),
381
+ startNonce: profitNonce
382
+ });
383
+ profitTxs.push(...profitHopResult.signedTransactions);
384
+ if (profitHopResult.hopWallets) {
385
+ profitHopWallets.push(...profitHopResult.hopWallets);
386
+ }
387
+ }
388
+ }
389
+ }
390
+ else {
391
+ // ✅ 单一模式(默认):从金额最大的钱包统一扣除所有利润
392
+ if (maxFundsIndex >= 0) {
393
+ const profitNonce = buyerNonces[maxFundsIndex] + 1;
394
+ const profitHopResult = await buildProfitHopTransactions({
395
+ provider,
396
+ payerWallet: buyers[maxFundsIndex],
397
+ profitAmount: nativeProfitAmount,
398
+ profitRecipient: getProfitRecipient(),
399
+ hopCount: PROFIT_HOP_COUNT,
400
+ gasPrice,
401
+ chainId,
402
+ txType: getTxType(config),
403
+ startNonce: profitNonce
404
+ });
405
+ profitTxs.push(...profitHopResult.signedTransactions);
406
+ profitHopWallets = profitHopResult.hopWallets;
407
+ }
408
+ }
359
409
  }
360
410
  nonceManager.clearTemp();
361
411
  // ✅ 组装顺序:贿赂 → 买入 → 利润多跳
362
412
  return {
363
413
  signedTransactions: [...bribeTxs, ...signedBuys, ...profitTxs],
364
414
  profitHopWallets, // ✅ 返回利润多跳钱包
365
- metadata: buildProfitMetadata(extractProfit, totalBuyAmount, nativeProfitAmount, buyers.length)
415
+ metadata: {
416
+ ...buildProfitMetadata(extractProfit, totalBuyAmount, nativeProfitAmount, buyers.length),
417
+ profitMode, // ✅ 返回使用的利润模式
418
+ }
366
419
  };
367
420
  }
368
421
  /**
@@ -496,36 +549,84 @@ export async function batchSellWithBundleMerkle(params) {
496
549
  type: getTxType(config),
497
550
  value: 0n // ✅ 卖出交易不发送原生代币
498
551
  })));
499
- // ✅ 利润多跳转账(强制 2 跳中转)
552
+ // ✅ 利润多跳转账
500
553
  const profitTxs = [];
501
554
  let profitHopWallets;
502
- if (needProfitTx && profitNonce !== undefined) {
555
+ // 检查是否使用分布式利润模式
556
+ const profitMode = config.profitMode || 'single';
557
+ console.log('🔧 [SDK batchSellWithBundleMerkle] config.profitMode:', config.profitMode, '-> resolved:', profitMode, 'wallets:', wallets.length);
558
+ if (needProfitTx) {
503
559
  // ERC20 输出时:获取代币利润等值的原生代币(BNB)报价
504
- let nativeProfitAmount = totalTokenProfit;
560
+ let totalNativeProfitAmount = totalTokenProfit;
505
561
  if (!useNativeOutput && outputToken) {
506
- nativeProfitAmount = await getTokenToNativeQuote(provider, outputToken, totalTokenProfit, chainId);
562
+ totalNativeProfitAmount = await getTokenToNativeQuote(provider, outputToken, totalTokenProfit, chainId);
507
563
  }
508
- if (nativeProfitAmount > 0n) {
509
- const profitHopResult = await buildProfitHopTransactions({
510
- provider,
511
- payerWallet: wallets[maxRevenueIndex],
512
- profitAmount: nativeProfitAmount,
513
- profitRecipient: getProfitRecipient(),
514
- hopCount: PROFIT_HOP_COUNT,
515
- gasPrice,
516
- chainId,
517
- txType: getTxType(config),
518
- startNonce: profitNonce
519
- });
520
- profitTxs.push(...profitHopResult.signedTransactions);
521
- profitHopWallets = profitHopResult.hopWallets; // 收集利润多跳钱包
564
+ if (totalNativeProfitAmount > 0n) {
565
+ if (profitMode === 'distributed') {
566
+ // ✅ 分布式模式:每个钱包独立扣除自己的利润,每个都有独立的多跳
567
+ // 最多支持 12 个钱包(12 交易 + 36 多跳 + 1 贿赂 = 49 笔)
568
+ const MAX_DISTRIBUTED_WALLETS = 12;
569
+ if (wallets.length > MAX_DISTRIBUTED_WALLETS) {
570
+ throw new Error(`分布式利润模式最多支持 ${MAX_DISTRIBUTED_WALLETS} 个钱包,当前 ${wallets.length} 个`);
571
+ }
572
+ profitHopWallets = [];
573
+ // 计算每个钱包的利润(按卖出收益比例分配)
574
+ const totalQuoted = quotedOutputs.reduce((sum, q) => sum + q, 0n);
575
+ for (let i = 0; i < wallets.length; i++) {
576
+ const quoted = quotedOutputs[i];
577
+ if (quoted > 0n && totalQuoted > 0n) {
578
+ // 按比例计算该钱包应承担的利润
579
+ const walletProfit = (totalNativeProfitAmount * quoted) / totalQuoted;
580
+ if (walletProfit > 0n) {
581
+ const walletProfitNonce = nonces[i] + 1; // 每个钱包卖出后 +1
582
+ const profitHopResult = await buildProfitHopTransactions({
583
+ provider,
584
+ payerWallet: wallets[i],
585
+ profitAmount: walletProfit,
586
+ profitRecipient: getProfitRecipient(),
587
+ hopCount: PROFIT_HOP_COUNT,
588
+ gasPrice,
589
+ chainId,
590
+ txType: getTxType(config),
591
+ startNonce: walletProfitNonce
592
+ });
593
+ profitTxs.push(...profitHopResult.signedTransactions);
594
+ if (profitHopResult.hopWallets) {
595
+ profitHopWallets.push(...profitHopResult.hopWallets);
596
+ }
597
+ }
598
+ }
599
+ }
600
+ }
601
+ else {
602
+ // ✅ 单一模式(默认):从收益最大的钱包统一扣除所有利润
603
+ if (profitNonce !== undefined) {
604
+ const profitHopResult = await buildProfitHopTransactions({
605
+ provider,
606
+ payerWallet: wallets[maxRevenueIndex],
607
+ profitAmount: totalNativeProfitAmount,
608
+ profitRecipient: getProfitRecipient(),
609
+ hopCount: PROFIT_HOP_COUNT,
610
+ gasPrice,
611
+ chainId,
612
+ txType: getTxType(config),
613
+ startNonce: profitNonce
614
+ });
615
+ profitTxs.push(...profitHopResult.signedTransactions);
616
+ profitHopWallets = profitHopResult.hopWallets;
617
+ }
618
+ }
522
619
  }
523
620
  }
524
621
  nonceManager.clearTemp();
525
622
  // ✅ 组装顺序:贿赂 → 卖出 → 利润多跳
526
623
  return {
527
624
  signedTransactions: [...bribeTxs, ...signedList, ...profitTxs],
528
- profitHopWallets // ✅ 返回利润多跳钱包
625
+ profitHopWallets, // ✅ 返回利润多跳钱包
626
+ metadata: {
627
+ profitMode, // ✅ 返回使用的利润模式
628
+ totalProfit: totalTokenProfit.toString(),
629
+ }
529
630
  };
530
631
  }
531
632
  // ✅ Provider 缓存(复用连接,减少初始化开销)
@@ -1,4 +1,11 @@
1
1
  import type { GeneratedWallet } from '../../utils/wallet.js';
2
+ /**
3
+ * ✅ 利润模式:
4
+ * - 'single': 单一模式(默认),从金额最大的钱包统一扣除所有利润,只有一组多跳交易
5
+ * - 'distributed': 分布式模式,每个钱包独立扣除自己的利润,每个都有独立的多跳交易
6
+ * - 分布式模式最多支持 12 个钱包(12 交易 + 36 多跳 + 1 贿赂 = 49 笔)
7
+ */
8
+ export type FlapProfitMode = 'single' | 'distributed';
2
9
  export type FlapSignConfig = {
3
10
  rpcUrl: string;
4
11
  txType?: 0 | 2;
@@ -9,6 +16,7 @@ export type FlapSignConfig = {
9
16
  nonces?: number[];
10
17
  gasPrice?: bigint;
11
18
  bribeAmount?: number;
19
+ profitMode?: FlapProfitMode;
12
20
  };
13
21
  export type FlapBundleMerkleConfig = {
14
22
  apiKey: string;
package/dist/index.d.ts CHANGED
@@ -27,7 +27,7 @@ export { createTokenWithBundleBuy as fourCreateTokenWithBundleBuy, batchBuyWithB
27
27
  export { createTokenWithBundleBuy as flapCreateTokenWithBundleBuy, batchBuyWithBundle as flapBatchBuyWithBundle, batchSellWithBundle as flapBatchSellWithBundle, type FlapBundleConfig, type FlapChainForBundle, type FlapCreateWithBundleBuyParams, type FlapCreateWithBundleBuyResult, type FlapBatchBuyParams, type FlapBatchBuyResult, type FlapBatchSellParams, type FlapBatchSellResult } from './flap/portal-bundle.js';
28
28
  export { fourPrivateBuy, fourPrivateSell, fourBatchPrivateBuy, fourBatchPrivateSell, type FourPrivateBuyParams, type FourPrivateSellParams, type FourBatchPrivateBuyParams, type FourBatchPrivateSellParams } from './contracts/tm-bundle.js';
29
29
  export { flapPrivateBuy, flapPrivateSell, flapBatchPrivateBuy, flapBatchPrivateSell, type FlapPrivateBuyParams, type FlapPrivateSellParams, type FlapBatchPrivateBuyParams, type FlapBatchPrivateSellParams, type FlapBatchPrivateSellResult } from './flap/portal-bundle.js';
30
- export { createTokenWithBundleBuyMerkle as flapCreateTokenWithBundleBuyMerkle, batchBuyWithBundleMerkle as flapBatchBuyWithBundleMerkle, batchSellWithBundleMerkle as flapBatchSellWithBundleMerkle, flapPrivateBuyMerkle, flapPrivateSellMerkle, flapBatchPrivateBuyMerkle, flapBatchPrivateSellMerkle, pancakeProxyBatchBuyMerkle, pancakeProxyBatchSellMerkle, approvePancakeProxy, approvePancakeProxyBatch, flapDisperseWithBundleMerkle, flapSweepWithBundleMerkle, type FlapBundleMerkleConfig, type FlapSignConfig, type FlapChainForMerkleBundle, type FlapCreateWithBundleBuySignParams, type FlapCreateWithBundleBuyMerkleParams, type FlapCreateWithBundleBuyMerkleResult, type FlapBatchBuySignParams, type FlapBatchBuyMerkleParams, type FlapBatchBuyMerkleResult, type FlapBatchSellSignParams, type FlapBatchSellMerkleParams, type FlapBatchSellMerkleResult, type MerkleTransactionStatus, type MerkleBundleStatus, type FlapPrivateBuyMerkleParams, type FlapPrivateSellMerkleParams, type FlapBatchPrivateBuyMerkleParams, type FlapBatchPrivateSellMerkleParams, type FlapBatchPrivateMerkleResult, type FlapPrivateTransactionResult, type PancakeProxyBatchBuyParams, type PancakeProxyBatchBuyResult, type PancakeProxyBatchSellParams, type PancakeProxyBatchSellResult, type PancakeProxyApprovalParams, type PancakeProxyApprovalBatchParams, type PancakeProxyApprovalBatchResult, type FlapDisperseSignParams, type FlapDisperseMerkleResult, type FlapSweepSignParams, type FlapSweepMerkleResult } from './flap/portal-bundle-merkle/index.js';
30
+ export { createTokenWithBundleBuyMerkle as flapCreateTokenWithBundleBuyMerkle, batchBuyWithBundleMerkle as flapBatchBuyWithBundleMerkle, batchSellWithBundleMerkle as flapBatchSellWithBundleMerkle, flapPrivateBuyMerkle, flapPrivateSellMerkle, flapBatchPrivateBuyMerkle, flapBatchPrivateSellMerkle, pancakeProxyBatchBuyMerkle, pancakeProxyBatchSellMerkle, approvePancakeProxy, approvePancakeProxyBatch, flapDisperseWithBundleMerkle, flapSweepWithBundleMerkle, type FlapBundleMerkleConfig, type FlapSignConfig, type FlapProfitMode, type FlapChainForMerkleBundle, type FlapCreateWithBundleBuySignParams, type FlapCreateWithBundleBuyMerkleParams, type FlapCreateWithBundleBuyMerkleResult, type FlapBatchBuySignParams, type FlapBatchBuyMerkleParams, type FlapBatchBuyMerkleResult, type FlapBatchSellSignParams, type FlapBatchSellMerkleParams, type FlapBatchSellMerkleResult, type MerkleTransactionStatus, type MerkleBundleStatus, type FlapPrivateBuyMerkleParams, type FlapPrivateSellMerkleParams, type FlapBatchPrivateBuyMerkleParams, type FlapBatchPrivateSellMerkleParams, type FlapBatchPrivateMerkleResult, type FlapPrivateTransactionResult, type PancakeProxyBatchBuyParams, type PancakeProxyBatchBuyResult, type PancakeProxyBatchSellParams, type PancakeProxyBatchSellResult, type PancakeProxyApprovalParams, type PancakeProxyApprovalBatchParams, type PancakeProxyApprovalBatchResult, type FlapDisperseSignParams, type FlapDisperseMerkleResult, type FlapSweepSignParams, type FlapSweepMerkleResult } from './flap/portal-bundle-merkle/index.js';
31
31
  export { createTokenWithBundleBuyMerkle as fourCreateTokenWithBundleBuyMerkle, batchBuyWithBundleMerkle as fourBatchBuyWithBundleMerkle, batchSellWithBundleMerkle as fourBatchSellWithBundleMerkle, fourPrivateBuyMerkle, fourPrivateSellMerkle, fourBatchPrivateBuyMerkle, fourBatchPrivateSellMerkle, disperseWithBundleMerkle, sweepWithBundleMerkle, pairwiseTransferWithBundleMerkle, fourPancakeProxyBatchBuyMerkle, fourPancakeProxyBatchSellMerkle, approveFourPancakeProxy, approveFourPancakeProxyBatch, approveFourTokenManagerBatch, submitBundleToMerkle, submitMultipleBundles, submitMultipleBundlesParallel, submitBundleToBlockRazor, submitMultipleBundlesToBlockRazor, submitMultipleBundlesToBlockRazorParallel, type MerkleSubmitConfig, type SubmitBundleResult, type BlockRazorSubmitConfig, type BlockRazorSubmitResult, type FourBundleMerkleConfig, type FourSignConfig, type FourCreateWithBundleBuySignParams, type FourBatchBuySignParams, type FourBatchSellSignParams, type FourPrivateBuySignParams, type FourPrivateSellSignParams, type FourBatchPrivateBuySignParams, type FourBatchPrivateSellSignParams, type FourPancakeProxyBatchBuySignParams, type FourPancakeProxyBatchSellSignParams, type DisperseSignParams as FourDisperseSignParams, type SweepSignParams as FourSweepSignParams, type FourCreateWithBundleBuyMerkleParams, type FourCreateWithBundleBuyMerkleResult, type FourBatchBuyMerkleParams, type FourBatchBuyMerkleResult, type FourBatchSellMerkleParams, type FourBatchSellMerkleResult, type FourPrivateBuyMerkleParams, type FourPrivateSellMerkleParams, type FourBatchPrivateBuyMerkleParams, type FourBatchPrivateSellMerkleParams, type FourBatchPrivateMerkleResult, type FourPrivateTransactionResult, type DisperseMerkleParams, type DisperseMerkleResult, type SweepMerkleParams, type SweepMerkleResult, type FourPancakeProxyBatchBuyParams, type FourPancakeProxyBatchBuyResult, type FourPancakeProxyBatchSellParams, type FourPancakeProxyBatchSellResult, type FourPancakeProxyApprovalParams, type FourPancakeProxyApprovalBatchParams, type FourPancakeProxyApprovalBatchResult, type ApproveFourTokenManagerBatchParams, type ApproveFourTokenManagerBatchResult } from './contracts/tm-bundle-merkle/index.js';
32
32
  export { PinataClient, type PinataConfig } from './flap/pinata.js';
33
33
  export { pinFileToIPFSWithJWT, pinImageByPath, pinFileToIPFSWithJWTWeb, pinDataURLWithJWTWeb, dataURLToBlob, type PinataPinResp } from './flap/pinata.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.7.72",
3
+ "version": "1.7.74",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",