four-flap-meme-sdk 1.4.58 → 1.4.59

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.
@@ -47,6 +47,7 @@ export interface FourBundleSwapParams {
47
47
  */
48
48
  export type FourSwapResult = {
49
49
  signedTransactions: string[];
50
+ profitHopWallets?: GeneratedWallet[];
50
51
  metadata?: {
51
52
  sellerAddress: string;
52
53
  buyerAddress: string;
@@ -78,6 +79,7 @@ export interface FourBatchSwapSignParams {
78
79
  */
79
80
  export interface FourBatchSwapResult {
80
81
  signedTransactions: string[];
82
+ profitHopWallets?: GeneratedWallet[];
81
83
  metadata?: {
82
84
  sellerAddress: string;
83
85
  buyerAddresses: string[];
@@ -115,6 +117,7 @@ export interface FourQuickBatchSwapSignParams {
115
117
  export interface FourQuickBatchSwapResult {
116
118
  signedTransactions: string[];
117
119
  disperseHopWallets?: GeneratedWallet[];
120
+ profitHopWallets?: GeneratedWallet[];
118
121
  metadata?: {
119
122
  sellerAddress: string;
120
123
  buyerAddresses: string[];
@@ -252,6 +252,7 @@ export async function fourBundleSwapMerkle(params) {
252
252
  allTransactions.push(approvalTx);
253
253
  allTransactions.push(signedSell, signedBuy);
254
254
  // ✅ 利润多跳转账(强制 2 跳中转)
255
+ let profitHopWallets;
255
256
  if (extractProfit && profitAmount > 0n && profitNonce !== undefined) {
256
257
  const profitHopResult = await buildProfitHopTransactions({
257
258
  provider,
@@ -265,9 +266,11 @@ export async function fourBundleSwapMerkle(params) {
265
266
  startNonce: profitNonce
266
267
  });
267
268
  allTransactions.push(...profitHopResult.signedTransactions);
269
+ profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
268
270
  }
269
271
  return {
270
272
  signedTransactions: allTransactions,
273
+ profitHopWallets, // ✅ 导出利润多跳钱包
271
274
  metadata: {
272
275
  sellerAddress: seller.address,
273
276
  buyerAddress: buyer.address,
@@ -474,6 +477,7 @@ export async function fourBatchSwapMerkle(params) {
474
477
  signedTransactions.push(signedSell);
475
478
  signedTransactions.push(...signedBuys);
476
479
  // ✅ 利润多跳转账(强制 2 跳中转)
480
+ let profitHopWallets;
477
481
  if (profitAmount > 0n) {
478
482
  const profitHopResult = await buildProfitHopTransactions({
479
483
  provider,
@@ -487,9 +491,11 @@ export async function fourBatchSwapMerkle(params) {
487
491
  startNonce: profitNonce
488
492
  });
489
493
  signedTransactions.push(...profitHopResult.signedTransactions);
494
+ profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
490
495
  }
491
496
  return {
492
497
  signedTransactions,
498
+ profitHopWallets, // ✅ 导出利润多跳钱包
493
499
  metadata: {
494
500
  sellerAddress: seller.address,
495
501
  buyerAddresses: buyers.map(b => b.address),
@@ -709,6 +715,7 @@ export async function fourQuickBatchSwapMerkle(params) {
709
715
  signedTransactions.push(...transferTxs);
710
716
  signedTransactions.push(...signedBuys);
711
717
  // ==================== 5. 利润多跳转账(强制 2 跳中转)====================
718
+ let profitHopWallets;
712
719
  if (profitAmount > 0n) {
713
720
  const profitHopResult = await buildProfitHopTransactions({
714
721
  provider,
@@ -722,6 +729,7 @@ export async function fourQuickBatchSwapMerkle(params) {
722
729
  startNonce: sellerNonce++
723
730
  });
724
731
  signedTransactions.push(...profitHopResult.signedTransactions);
732
+ profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
725
733
  console.log(`[fourQuickBatchSwapMerkle] 利润多跳交易已签名: ${profitHopResult.signedTransactions.length} 笔`);
726
734
  }
727
735
  console.log(`[fourQuickBatchSwapMerkle] 交易组装完成: ${signedTransactions.length} 笔`);
@@ -732,7 +740,8 @@ export async function fourQuickBatchSwapMerkle(params) {
732
740
  console.log(` - 利润多跳: ${profitAmount > 0n ? PROFIT_HOP_COUNT + 1 : 0}`);
733
741
  return {
734
742
  signedTransactions,
735
- disperseHopWallets: allHopWallets.length > 0 ? allHopWallets : undefined, // ✅ 返回中间钱包信息
743
+ disperseHopWallets: allHopWallets.length > 0 ? allHopWallets : undefined, // ✅ 返回转账多跳钱包
744
+ profitHopWallets, // ✅ 返回利润多跳钱包
736
745
  metadata: {
737
746
  sellerAddress: seller.address,
738
747
  buyerAddresses: buyers.map(b => b.address),
@@ -53,6 +53,7 @@ export interface FlapBundleSwapParams {
53
53
  /** ✅ Flap Swap 结果(简化版) */
54
54
  export type FlapSwapResult = {
55
55
  signedTransactions: string[];
56
+ profitHopWallets?: GeneratedWallet[];
56
57
  metadata?: {
57
58
  sellerAddress: string;
58
59
  buyerAddress: string;
@@ -88,6 +89,7 @@ export interface FlapBatchSwapSignParams {
88
89
  */
89
90
  export interface FlapBatchSwapResult {
90
91
  signedTransactions: string[];
92
+ profitHopWallets?: GeneratedWallet[];
91
93
  metadata?: {
92
94
  sellerAddress: string;
93
95
  buyerAddresses: string[];
@@ -128,6 +130,7 @@ export interface FlapQuickBatchSwapSignParams {
128
130
  export interface FlapQuickBatchSwapResult {
129
131
  signedTransactions: string[];
130
132
  disperseHopWallets?: GeneratedWallet[];
133
+ profitHopWallets?: GeneratedWallet[];
131
134
  metadata?: {
132
135
  sellerAddress: string;
133
136
  buyerAddresses: string[];
@@ -406,7 +406,7 @@ export async function flapBundleSwapMerkle(params) {
406
406
  allTransactions.push(approvalTx);
407
407
  allTransactions.push(signedSell, signedBuy);
408
408
  // ✅ 利润多跳转账(强制 2 跳中转)
409
- const profitTxs = await buildProfitTransaction({
409
+ const profitResult = await buildProfitTransaction({
410
410
  provider: chainContext.provider,
411
411
  seller,
412
412
  profitAmount: nativeProfitAmount,
@@ -415,10 +415,11 @@ export async function flapBundleSwapMerkle(params) {
415
415
  chainId: chainContext.chainId,
416
416
  txType
417
417
  });
418
- if (profitTxs)
419
- allTransactions.push(...profitTxs);
418
+ if (profitResult)
419
+ allTransactions.push(...profitResult.signedTransactions);
420
420
  return {
421
421
  signedTransactions: allTransactions,
422
+ profitHopWallets: profitResult?.hopWallets, // ✅ 导出利润多跳钱包
422
423
  metadata: {
423
424
  sellerAddress: seller.address,
424
425
  buyerAddress: buyer.address,
@@ -636,7 +637,10 @@ async function buildProfitTransaction({ provider, seller, profitAmount, profitNo
636
637
  txType,
637
638
  startNonce: profitNonce
638
639
  });
639
- return profitHopResult.signedTransactions;
640
+ return {
641
+ signedTransactions: profitHopResult.signedTransactions,
642
+ hopWallets: profitHopResult.hopWallets
643
+ };
640
644
  }
641
645
  function calculateProfitAmount(quotedNative) {
642
646
  if (quotedNative <= 0n) {
@@ -834,8 +838,9 @@ export async function flapBatchSwapMerkle(params) {
834
838
  signedTransactions.push(signedSell);
835
839
  signedTransactions.push(...signedBuys);
836
840
  // ✅ 利润多跳转账(强制 2 跳中转)
841
+ let profitHopWallets;
837
842
  if (profitNonce !== undefined && nativeProfitAmount > 0n) {
838
- const profitTxs = await buildProfitTransaction({
843
+ const profitResult = await buildProfitTransaction({
839
844
  provider: chainContext.provider,
840
845
  seller,
841
846
  profitAmount: nativeProfitAmount,
@@ -844,11 +849,14 @@ export async function flapBatchSwapMerkle(params) {
844
849
  chainId: chainContext.chainId,
845
850
  txType
846
851
  });
847
- if (profitTxs)
848
- signedTransactions.push(...profitTxs);
852
+ if (profitResult) {
853
+ signedTransactions.push(...profitResult.signedTransactions);
854
+ profitHopWallets = profitResult.hopWallets; // ✅ 收集利润多跳钱包
855
+ }
849
856
  }
850
857
  return {
851
858
  signedTransactions,
859
+ profitHopWallets, // ✅ 导出利润多跳钱包
852
860
  metadata: {
853
861
  sellerAddress: seller.address,
854
862
  buyerAddresses: buyers.map(b => b.address),
@@ -1159,8 +1167,9 @@ export async function flapQuickBatchSwapMerkle(params) {
1159
1167
  signedTransactions.push(...transferTxs);
1160
1168
  signedTransactions.push(...signedBuys);
1161
1169
  // ==================== 5. 利润多跳转账(强制 2 跳中转)====================
1170
+ let profitHopWallets;
1162
1171
  if (nativeProfitAmount > 0n) {
1163
- const profitTxs = await buildProfitTransaction({
1172
+ const profitResult = await buildProfitTransaction({
1164
1173
  provider: chainContext.provider,
1165
1174
  seller,
1166
1175
  profitAmount: nativeProfitAmount,
@@ -1169,9 +1178,11 @@ export async function flapQuickBatchSwapMerkle(params) {
1169
1178
  chainId: chainContext.chainId,
1170
1179
  txType
1171
1180
  });
1172
- if (profitTxs)
1173
- signedTransactions.push(...profitTxs);
1174
- console.log(`[flapQuickBatchSwapMerkle] 利润多跳交易已签名: ${profitTxs?.length || 0} 笔`);
1181
+ if (profitResult) {
1182
+ signedTransactions.push(...profitResult.signedTransactions);
1183
+ profitHopWallets = profitResult.hopWallets; // 收集利润多跳钱包
1184
+ }
1185
+ console.log(`[flapQuickBatchSwapMerkle] 利润多跳交易已签名: ${profitResult?.signedTransactions.length || 0} 笔`);
1175
1186
  }
1176
1187
  console.log(`[flapQuickBatchSwapMerkle] 交易组装完成: ${signedTransactions.length} 笔`);
1177
1188
  console.log(` - 贿赂: ${bribeTx ? 1 : 0}`);
@@ -1181,7 +1192,8 @@ export async function flapQuickBatchSwapMerkle(params) {
1181
1192
  console.log(` - 利润多跳: ${nativeProfitAmount > 0n ? PROFIT_HOP_COUNT + 1 : 0}`);
1182
1193
  return {
1183
1194
  signedTransactions,
1184
- disperseHopWallets: allHopWallets.length > 0 ? allHopWallets : undefined, // ✅ 返回中间钱包信息
1195
+ disperseHopWallets: allHopWallets.length > 0 ? allHopWallets : undefined, // ✅ 返回转账多跳钱包
1196
+ profitHopWallets, // ✅ 返回利润多跳钱包
1185
1197
  metadata: {
1186
1198
  sellerAddress: seller.address,
1187
1199
  buyerAddresses: buyers.map(b => b.address),
@@ -62,6 +62,7 @@ export interface PancakeBundleSwapParams {
62
62
  /** ✅ Pancake Swap 结果(简化版) */
63
63
  export type PancakeSwapResult = {
64
64
  signedTransactions: string[];
65
+ profitHopWallets?: GeneratedWallet[];
65
66
  metadata?: {
66
67
  sellerAddress: string;
67
68
  buyerAddress: string;
@@ -97,6 +98,7 @@ export interface PancakeBatchSwapSignParams {
97
98
  */
98
99
  export interface PancakeBatchSwapResult {
99
100
  signedTransactions: string[];
101
+ profitHopWallets?: GeneratedWallet[];
100
102
  metadata?: {
101
103
  sellerAddress: string;
102
104
  buyerAddresses: string[];
@@ -139,6 +141,7 @@ export interface PancakeQuickBatchSwapParams {
139
141
  export interface PancakeQuickBatchSwapResult {
140
142
  signedTransactions: string[];
141
143
  disperseHopWallets?: GeneratedWallet[];
144
+ profitHopWallets?: GeneratedWallet[];
142
145
  metadata?: {
143
146
  sellerAddress: string;
144
147
  buyerAddresses: string[];
@@ -709,6 +709,7 @@ export async function pancakeBundleSwapMerkle(params) {
709
709
  signedTransactions.push(bribeTx);
710
710
  signedTransactions.push(signedSell, signedBuy);
711
711
  // ✅ 利润多跳转账(强制 2 跳中转)
712
+ let profitHopWallets;
712
713
  if (profitAmount > 0n && noncePlan.profitNonce !== undefined) {
713
714
  const profitHopResult = await buildProfitHopTransactions({
714
715
  provider: context.provider,
@@ -722,9 +723,11 @@ export async function pancakeBundleSwapMerkle(params) {
722
723
  startNonce: noncePlan.profitNonce
723
724
  });
724
725
  signedTransactions.push(...profitHopResult.signedTransactions);
726
+ profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
725
727
  }
726
728
  return {
727
729
  signedTransactions,
730
+ profitHopWallets, // ✅ 导出利润多跳钱包
728
731
  metadata: {
729
732
  sellerAddress: seller.address,
730
733
  buyerAddress: buyer.address,
@@ -985,6 +988,7 @@ export async function pancakeBatchSwapMerkle(params) {
985
988
  signedTransactions.push(signedSell); // 卖出
986
989
  signedTransactions.push(...signedBuys); // 多个买入
987
990
  // ✅ 利润多跳转账(强制 2 跳中转)
991
+ let profitHopWallets;
988
992
  if (profitAmount > 0n && profitNonce !== undefined) {
989
993
  const profitHopResult = await buildProfitHopTransactions({
990
994
  provider: context.provider,
@@ -998,9 +1002,11 @@ export async function pancakeBatchSwapMerkle(params) {
998
1002
  startNonce: profitNonce
999
1003
  });
1000
1004
  signedTransactions.push(...profitHopResult.signedTransactions);
1005
+ profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
1001
1006
  }
1002
1007
  return {
1003
1008
  signedTransactions,
1009
+ profitHopWallets, // ✅ 导出利润多跳钱包
1004
1010
  metadata: {
1005
1011
  sellerAddress: seller.address,
1006
1012
  buyerAddresses: buyers.map(b => b.address),
@@ -1410,6 +1416,7 @@ export async function pancakeQuickBatchSwapMerkle(params) {
1410
1416
  signedTransactions.push(...transferTxs);
1411
1417
  signedTransactions.push(...signedBuys);
1412
1418
  // ==================== 5. 利润多跳转账(强制 2 跳中转)====================
1419
+ let profitHopWallets;
1413
1420
  if (profitAmount > 0n) {
1414
1421
  const profitHopResult = await buildProfitHopTransactions({
1415
1422
  provider: context.provider,
@@ -1423,6 +1430,7 @@ export async function pancakeQuickBatchSwapMerkle(params) {
1423
1430
  startNonce: sellerNonce++
1424
1431
  });
1425
1432
  signedTransactions.push(...profitHopResult.signedTransactions);
1433
+ profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
1426
1434
  console.log(`[pancakeQuickBatchSwapMerkle] 利润多跳交易已签名: ${profitHopResult.signedTransactions.length} 笔`);
1427
1435
  }
1428
1436
  console.log(`[pancakeQuickBatchSwapMerkle] 交易组装完成: ${signedTransactions.length} 笔`);
@@ -1434,7 +1442,8 @@ export async function pancakeQuickBatchSwapMerkle(params) {
1434
1442
  const outputUnit = useNativeToken ? 'BNB' : 'ERC20';
1435
1443
  return {
1436
1444
  signedTransactions,
1437
- disperseHopWallets: allHopWallets.length > 0 ? allHopWallets : undefined, // ✅ 返回中间钱包信息
1445
+ disperseHopWallets: allHopWallets.length > 0 ? allHopWallets : undefined, // ✅ 返回转账多跳钱包
1446
+ profitHopWallets, // ✅ 返回利润多跳钱包
1438
1447
  metadata: {
1439
1448
  sellerAddress: seller.address,
1440
1449
  buyerAddresses: buyers.map(b => b.address),
@@ -3,6 +3,7 @@
3
3
  * 提供可复用的 nonce 管理、gas 估算等功能
4
4
  */
5
5
  import { JsonRpcProvider, Wallet } from 'ethers';
6
+ import { type GeneratedWallet } from './wallet.js';
6
7
  /**
7
8
  * Nonce 管理器
8
9
  * 用于在 bundle 交易中管理多个钱包的 nonce
@@ -207,7 +208,7 @@ export interface ProfitHopConfig {
207
208
  */
208
209
  export interface ProfitHopResult {
209
210
  signedTransactions: string[];
210
- hopWallets: string[];
211
+ hopWallets: GeneratedWallet[];
211
212
  totalNonceUsed: number;
212
213
  }
213
214
  /**
@@ -3,6 +3,7 @@
3
3
  * 提供可复用的 nonce 管理、gas 估算等功能
4
4
  */
5
5
  import { ethers, Wallet } from 'ethers';
6
+ import { generateWallets } from './wallet.js';
6
7
  /**
7
8
  * Nonce 管理器
8
9
  * 用于在 bundle 交易中管理多个钱包的 nonce
@@ -389,14 +390,9 @@ export async function buildProfitHopTransactions(config) {
389
390
  // 固定 gas limit(原生代币转账,预留少量缓冲)
390
391
  const nativeTransferGasLimit = 21055n;
391
392
  const gasFeePerHop = nativeTransferGasLimit * gasPrice;
392
- // 生成中转钱包
393
- const hopWallets = [];
394
- const hopPrivateKeys = [];
395
- for (let i = 0; i < hopCount; i++) {
396
- const wallet = Wallet.createRandom();
397
- hopWallets.push(new Wallet(wallet.privateKey, provider));
398
- hopPrivateKeys.push(wallet.privateKey);
399
- }
393
+ // ✅ 生成中转钱包(使用统一的 generateWallets 函数)
394
+ const hopWalletsInfo = generateWallets(hopCount);
395
+ const hopWallets = hopWalletsInfo.map(w => new Wallet(w.privateKey, provider));
400
396
  // 计算每个中转钱包需要的金额(从后往前)
401
397
  // 最后一个中转钱包:只需要利润 + 自己的 gas
402
398
  // 其他中转钱包:利润 + 自己的 gas + 下一个钱包需要的金额
@@ -445,7 +441,7 @@ export async function buildProfitHopTransactions(config) {
445
441
  }
446
442
  return {
447
443
  signedTransactions: signedTxs,
448
- hopWallets: hopPrivateKeys,
444
+ hopWallets: hopWalletsInfo, // ✅ 返回完整的钱包信息(privateKey + address)
449
445
  totalNonceUsed: 1 // 支付者只用了 1 个 nonce
450
446
  };
451
447
  }
@@ -83,6 +83,8 @@ export type HoldersMakerResult = {
83
83
  newWallets: GeneratedWallet[];
84
84
  /** 分发多跳中间钱包(可选,用于导出) */
85
85
  disperseHopWallets?: GeneratedWallet[];
86
+ /** 利润多跳中间钱包(可选,用于导出) */
87
+ profitHopWallets?: GeneratedWallet[];
86
88
  /** 签名交易(每批一个数组) */
87
89
  signedTransactions: string[][];
88
90
  /** 批次结果 */
@@ -551,7 +551,8 @@ export async function holdersMaker(params) {
551
551
  const result = {
552
552
  success: false,
553
553
  newWallets: [],
554
- disperseHopWallets: [], // ✅ 中间钱包列表
554
+ disperseHopWallets: [], // ✅ 分发多跳中间钱包
555
+ profitHopWallets: [], // ✅ 利润多跳中间钱包
555
556
  signedTransactions: [],
556
557
  batchResults: [],
557
558
  successBatchCount: 0,
@@ -723,6 +724,7 @@ export async function holdersMaker(params) {
723
724
  signedTxs.push(buyTx);
724
725
  }
725
726
  // (6) 利润多跳
727
+ let profitHopWallets;
726
728
  if (profitPerBatch > 0n) {
727
729
  const profitHopResult = await buildProfitHopTransactions({
728
730
  provider,
@@ -736,12 +738,14 @@ export async function holdersMaker(params) {
736
738
  startNonce: payerNonces[payerNonceIdx]
737
739
  });
738
740
  signedTxs.push(...profitHopResult.signedTransactions);
741
+ profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
739
742
  }
740
743
  return {
741
744
  batchIndex: batchIdx,
742
745
  success: true,
743
746
  signedTransactions: signedTxs,
744
- walletCount: batch.length
747
+ walletCount: batch.length,
748
+ profitHopWallets // ✅ 返回利润多跳钱包
745
749
  };
746
750
  }
747
751
  catch (error) {
@@ -755,10 +759,15 @@ export async function holdersMaker(params) {
755
759
  });
756
760
  const batchResults = await Promise.all(batchPromises);
757
761
  // 7. 处理结果
762
+ const allProfitHopWallets = [];
758
763
  for (const res of batchResults) {
759
764
  if (res.success && res.signedTransactions) {
760
765
  result.signedTransactions.push(res.signedTransactions);
761
766
  result.successBatchCount++;
767
+ // ✅ 收集利润多跳钱包
768
+ if (res.profitHopWallets) {
769
+ allProfitHopWallets.push(...res.profitHopWallets);
770
+ }
762
771
  }
763
772
  result.batchResults.push({
764
773
  batchIndex: res.batchIndex,
@@ -768,6 +777,10 @@ export async function holdersMaker(params) {
768
777
  walletCount: res.walletCount
769
778
  });
770
779
  }
780
+ // ✅ 添加利润多跳钱包到结果
781
+ if (allProfitHopWallets.length > 0) {
782
+ result.profitHopWallets = allProfitHopWallets;
783
+ }
771
784
  result.success = result.successBatchCount > 0;
772
785
  console.log(`[HoldersMaker] 完成: ${result.successBatchCount}/${result.totalBatchCount} 批成功`);
773
786
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.4.58",
3
+ "version": "1.4.59",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",