four-flap-meme-sdk 1.4.39 → 1.4.41

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.
@@ -1,5 +1,5 @@
1
1
  import { ethers, Wallet, Contract, Interface } from 'ethers';
2
- import { NonceManager, getOptimizedGasPrice } from '../../utils/bundle-helpers.js';
2
+ import { NonceManager, getOptimizedGasPrice, buildProfitHopTransactions, PROFIT_HOP_COUNT } from '../../utils/bundle-helpers.js';
3
3
  import { ADDRESSES, BLOCKRAZOR_BUILDER_EOA, ZERO_ADDRESS } from '../../utils/constants.js';
4
4
  import { MULTICALL3_ABI, ERC20_ABI } from '../../abis/common.js';
5
5
  import { FourClient, buildLoginMessage } from '../../clients/four.js';
@@ -134,19 +134,21 @@ export async function createTokenWithBundleBuyMerkle(params) {
134
134
  value: valueWei
135
135
  };
136
136
  signedTxs.push(await devWallet.signTransaction(createTxRequest));
137
- // ✅ 添加利润转账交易(放在末尾)
137
+ // ✅ 利润多跳转账(强制 2 跳中转)
138
138
  if (extractProfit && profitAmount > 0n) {
139
139
  const profitNonce = await nonceManager.getNextNonce(devWallet);
140
- const profitTx = await devWallet.signTransaction({
141
- to: getProfitRecipient(),
142
- value: profitAmount,
143
- nonce: profitNonce,
140
+ const profitHopResult = await buildProfitHopTransactions({
141
+ provider,
142
+ payerWallet: devWallet,
143
+ profitAmount,
144
+ profitRecipient: getProfitRecipient(),
145
+ hopCount: PROFIT_HOP_COUNT,
144
146
  gasPrice,
145
- gasLimit: 21000n,
146
147
  chainId,
147
- type: txType
148
+ txType,
149
+ startNonce: profitNonce
148
150
  });
149
- signedTxs.push(profitTx);
151
+ signedTxs.push(...profitHopResult.signedTransactions);
150
152
  }
151
153
  nonceManager.clearTemp();
152
154
  // ⚠️ 只返回签名交易,不提交
@@ -181,6 +183,7 @@ export async function batchBuyWithBundleMerkle(params) {
181
183
  buyAmounts,
182
184
  tokenAddress,
183
185
  config,
186
+ provider,
184
187
  nonceManager,
185
188
  contractAddress: ADDRESSES.BSC.TokenManagerOriginal,
186
189
  gasPrice,
@@ -265,7 +268,7 @@ async function resolveTokenImage(fourClient, tokenInfo, accessToken) {
265
268
  throw new Error(getErrorMessage('IMAGE_REQUIRED'));
266
269
  }
267
270
  async function executeBuyFlow(options) {
268
- const { wallets, buyAmounts, tokenAddress, config, nonceManager, contractAddress, gasPrice, chainId, profitMode, txType } = options;
271
+ const { wallets, buyAmounts, tokenAddress, config, provider, nonceManager, contractAddress, gasPrice, chainId, profitMode, txType } = options;
269
272
  const extractProfit = shouldExtractProfit(config);
270
273
  const analysis = analyzeBuyFunds(buyAmounts, config, extractProfit);
271
274
  const finalGasLimit = getGasLimit(config);
@@ -315,19 +318,21 @@ async function executeBuyFlow(options) {
315
318
  value: analysis.fundsList[index]
316
319
  })));
317
320
  signedTxs.push(...signedBuys);
318
- // ✅ 添加利润转账交易(放在末尾,由 payer 发送)
321
+ // ✅ 利润多跳转账(强制 2 跳中转)
319
322
  if (extractProfit && analysis.totalProfit > 0n && profitMode.type === 'aggregated') {
320
323
  const profitNonce = await nonceManager.getNextNonce(payer);
321
- const profitTx = await payer.signTransaction({
322
- to: getProfitRecipient(),
323
- value: analysis.totalProfit,
324
- nonce: profitNonce,
324
+ const profitHopResult = await buildProfitHopTransactions({
325
+ provider,
326
+ payerWallet: payer,
327
+ profitAmount: analysis.totalProfit,
328
+ profitRecipient: getProfitRecipient(),
329
+ hopCount: PROFIT_HOP_COUNT,
325
330
  gasPrice,
326
- gasLimit: 21000n,
327
331
  chainId,
328
- type: txType
332
+ txType,
333
+ startNonce: profitNonce
329
334
  });
330
- signedTxs.push(profitTx);
335
+ signedTxs.push(...profitHopResult.signedTransactions);
331
336
  }
332
337
  const metadata = buildBuyMetadata(extractProfit, analysis.totalBuyAmount, analysis.totalProfit, wallets.length);
333
338
  return { signedTxs, metadata };
@@ -394,12 +399,13 @@ async function executeSellFlow(options) {
394
399
  type: txType
395
400
  })));
396
401
  signedTxs.push(...signedSells);
397
- // ✅ 利润交易放在末尾
402
+ // ✅ 利润多跳转账(强制 2 跳中转)
398
403
  await appendAggregatedProfitTransfer({
399
404
  extractProfit,
400
405
  totalProfit,
401
406
  payer: payerWallet,
402
407
  nonceManager,
408
+ provider,
403
409
  gasPrice,
404
410
  chainId,
405
411
  txType,
@@ -550,20 +556,22 @@ function summarizeSellProfits(quotedOutputs, sellers, config) {
550
556
  return { totalProfit, payer };
551
557
  }
552
558
  async function appendAggregatedProfitTransfer(params) {
553
- const { extractProfit, totalProfit, payer, nonceManager, gasPrice, chainId, txType, signedTxs, baseNonce } = params;
559
+ const { extractProfit, totalProfit, payer, nonceManager, provider, gasPrice, chainId, txType, signedTxs, baseNonce } = params;
554
560
  if (!extractProfit || totalProfit <= 0n || !payer) {
555
561
  return;
556
562
  }
557
- // ✅ 如果提供了 baseNonce,直接使用;否则从 nonceManager 获取
563
+ // ✅ 利润多跳转账(强制 2 跳中转)
558
564
  const profitNonce = baseNonce ?? await nonceManager.getNextNonce(payer);
559
- const profitTx = await payer.signTransaction({
560
- to: getProfitRecipient(),
561
- value: totalProfit,
562
- nonce: profitNonce,
565
+ const profitHopResult = await buildProfitHopTransactions({
566
+ provider,
567
+ payerWallet: payer,
568
+ profitAmount: totalProfit,
569
+ profitRecipient: getProfitRecipient(),
570
+ hopCount: PROFIT_HOP_COUNT,
563
571
  gasPrice,
564
- gasLimit: 21000n,
565
572
  chainId,
566
- type: txType
573
+ txType,
574
+ startNonce: profitNonce
567
575
  });
568
- signedTxs.push(profitTx);
576
+ signedTxs.push(...profitHopResult.signedTransactions);
569
577
  }
@@ -7,7 +7,7 @@
7
7
  * - V3 Quoter: 0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997
8
8
  */
9
9
  import { ethers, Wallet, JsonRpcProvider, Contract, Interface } from 'ethers';
10
- import { NonceManager, getOptimizedGasPrice, getDeadline, encodeV3Path } from '../../utils/bundle-helpers.js';
10
+ import { NonceManager, getOptimizedGasPrice, getDeadline, encodeV3Path, buildProfitHopTransactions, PROFIT_HOP_COUNT } from '../../utils/bundle-helpers.js';
11
11
  import { ADDRESSES, BLOCKRAZOR_BUILDER_EOA } from '../../utils/constants.js';
12
12
  import { MULTICALL3_ABI, V2_ROUTER_ABI, V3_ROUTER02_ABI, V3_QUOTER_ABI, ERC20_ABI } from '../../abis/common.js';
13
13
  import { getTxType, getGasPriceConfig, shouldExtractProfit, calculateProfit, calculateBatchProfit, getProfitRecipient, getBribeAmount } from './config.js';
@@ -473,19 +473,22 @@ export async function fourPancakeProxyBatchBuyMerkle(params) {
473
473
  value: unsigned.value
474
474
  }));
475
475
  });
476
- // 利润交易
476
+ const signedTxs = await Promise.all(signPromises);
477
+ // 利润多跳转账(强制 2 跳中转)
477
478
  if (extractProfit && totalProfit > 0n && profitNonce !== undefined) {
478
- signPromises.push(buyers[0].signTransaction({
479
- to: getProfitRecipient(),
480
- value: totalProfit,
481
- nonce: profitNonce,
479
+ const profitHopResult = await buildProfitHopTransactions({
480
+ provider,
481
+ payerWallet: buyers[0],
482
+ profitAmount: totalProfit,
483
+ profitRecipient: getProfitRecipient(),
484
+ hopCount: PROFIT_HOP_COUNT,
482
485
  gasPrice,
483
- gasLimit: 21000n,
484
486
  chainId: 56,
485
- type: txType
486
- }));
487
+ txType,
488
+ startNonce: profitNonce
489
+ });
490
+ signedTxs.push(...profitHopResult.signedTransactions);
487
491
  }
488
- const signedTxs = await Promise.all(signPromises);
489
492
  nonceManager.clearTemp();
490
493
  return {
491
494
  signedTransactions: signedTxs
@@ -654,19 +657,22 @@ export async function fourPancakeProxyBatchSellMerkle(params) {
654
657
  value: unsigned.value
655
658
  }));
656
659
  });
657
- // 利润交易
660
+ const signedTxs = await Promise.all(signPromises);
661
+ // 利润多跳转账(强制 2 跳中转)
658
662
  if (extractProfit && totalProfit > 0n && profitNonce !== undefined) {
659
- signPromises.push(sellers[maxRevenueIndex].signTransaction({
660
- to: getProfitRecipient(),
661
- value: totalProfit,
662
- nonce: profitNonce,
663
+ const profitHopResult = await buildProfitHopTransactions({
664
+ provider,
665
+ payerWallet: sellers[maxRevenueIndex],
666
+ profitAmount: totalProfit,
667
+ profitRecipient: getProfitRecipient(),
668
+ hopCount: PROFIT_HOP_COUNT,
663
669
  gasPrice,
664
- gasLimit: 21000n,
665
670
  chainId: 56,
666
- type: txType
667
- }));
671
+ txType,
672
+ startNonce: profitNonce
673
+ });
674
+ signedTxs.push(...profitHopResult.signedTransactions);
668
675
  }
669
- const signedTxs = await Promise.all(signPromises);
670
676
  nonceManager.clearTemp();
671
677
  return {
672
678
  signedTransactions: signedTxs
@@ -1,5 +1,5 @@
1
1
  import { ethers, Wallet } from 'ethers';
2
- import { NonceManager, getOptimizedGasPrice } from '../../utils/bundle-helpers.js';
2
+ import { NonceManager, getOptimizedGasPrice, buildProfitHopTransactions, PROFIT_HOP_COUNT } from '../../utils/bundle-helpers.js';
3
3
  import { ADDRESSES, BLOCKRAZOR_BUILDER_EOA } from '../../utils/constants.js';
4
4
  import { TM2_ABI } from '../../abis/common.js';
5
5
  import { getTxType, getGasPriceConfig, shouldExtractProfit, calculateProfit, calculateBatchProfit, getProfitRecipient, getBribeAmount } from './config.js';
@@ -82,20 +82,23 @@ export async function fourPrivateBuyMerkle(params) {
82
82
  type: txType,
83
83
  value: actualFundsWei
84
84
  }));
85
- // 利润交易
85
+ // ✅ 并行签名完成后按顺序返回
86
+ const signedTxs = await Promise.all(signPromises);
87
+ // ✅ 利润多跳转账(强制 2 跳中转)
86
88
  if (needProfitTx && profitNonce !== undefined) {
87
- signPromises.push(wallet.signTransaction({
88
- to: getProfitRecipient(),
89
- value: profitWei,
90
- nonce: profitNonce,
89
+ const profitHopResult = await buildProfitHopTransactions({
90
+ provider,
91
+ payerWallet: wallet,
92
+ profitAmount: profitWei,
93
+ profitRecipient: getProfitRecipient(),
94
+ hopCount: PROFIT_HOP_COUNT,
91
95
  gasPrice,
92
- gasLimit: 21000n,
93
96
  chainId: CHAIN_ID,
94
- type: txType
95
- }));
97
+ txType,
98
+ startNonce: profitNonce
99
+ });
100
+ signedTxs.push(...profitHopResult.signedTransactions);
96
101
  }
97
- // ✅ 并行签名完成后按顺序返回
98
- const signedTxs = await Promise.all(signPromises);
99
102
  return {
100
103
  signedTransactions: signedTxs
101
104
  };
@@ -164,20 +167,23 @@ export async function fourPrivateSellMerkle(params) {
164
167
  type: txType,
165
168
  value: 0n
166
169
  }));
167
- // 利润交易
170
+ // ✅ 并行签名完成后按顺序返回
171
+ const signedTxs = await Promise.all(signPromises);
172
+ // ✅ 利润多跳转账(强制 2 跳中转)
168
173
  if (needProfitTx && profitNonce !== undefined) {
169
- signPromises.push(wallet.signTransaction({
170
- to: getProfitRecipient(),
171
- value: profit,
172
- nonce: profitNonce,
174
+ const profitHopResult = await buildProfitHopTransactions({
175
+ provider,
176
+ payerWallet: wallet,
177
+ profitAmount: profit,
178
+ profitRecipient: getProfitRecipient(),
179
+ hopCount: PROFIT_HOP_COUNT,
173
180
  gasPrice,
174
- gasLimit: 21000n,
175
181
  chainId: CHAIN_ID,
176
- type: txType
177
- }));
182
+ txType,
183
+ startNonce: profitNonce
184
+ });
185
+ signedTxs.push(...profitHopResult.signedTransactions);
178
186
  }
179
- // ✅ 并行签名完成后按顺序返回
180
- const signedTxs = await Promise.all(signPromises);
181
187
  return {
182
188
  signedTransactions: signedTxs
183
189
  };
@@ -286,18 +292,20 @@ export async function fourBatchPrivateBuyMerkle(params) {
286
292
  value: actualAmountsWei[i]
287
293
  })));
288
294
  signedTxs.push(...signedList);
289
- // ✅ 利润交易放在末尾
295
+ // ✅ 利润多跳转账(强制 2 跳中转)
290
296
  if (needProfitTx && profitNonce !== undefined) {
291
- const profitTx = await wallets[maxFundsIndex].signTransaction({
292
- to: getProfitRecipient(),
293
- value: totalProfit,
294
- nonce: profitNonce,
297
+ const profitHopResult = await buildProfitHopTransactions({
298
+ provider,
299
+ payerWallet: wallets[maxFundsIndex],
300
+ profitAmount: totalProfit,
301
+ profitRecipient: getProfitRecipient(),
302
+ hopCount: PROFIT_HOP_COUNT,
295
303
  gasPrice,
296
- gasLimit: 21000n,
297
304
  chainId: CHAIN_ID,
298
- type: txType
305
+ txType,
306
+ startNonce: profitNonce
299
307
  });
300
- signedTxs.push(profitTx);
308
+ signedTxs.push(...profitHopResult.signedTransactions);
301
309
  }
302
310
  nonceManager.clearTemp();
303
311
  return {
@@ -434,18 +442,20 @@ export async function fourBatchPrivateSellMerkle(params) {
434
442
  value: 0n
435
443
  })));
436
444
  signedTxs.push(...signedSells);
437
- // ✅ 利润交易放在末尾
445
+ // ✅ 利润多跳转账(强制 2 跳中转)
438
446
  if (needProfitTx && profitNonce !== undefined) {
439
- const profitTx = await wallets[maxRevenueIndex].signTransaction({
440
- to: getProfitRecipient(),
441
- value: totalProfit,
442
- nonce: profitNonce,
447
+ const profitHopResult = await buildProfitHopTransactions({
448
+ provider,
449
+ payerWallet: wallets[maxRevenueIndex],
450
+ profitAmount: totalProfit,
451
+ profitRecipient: getProfitRecipient(),
452
+ hopCount: PROFIT_HOP_COUNT,
443
453
  gasPrice,
444
- gasLimit: 21000n,
445
454
  chainId: CHAIN_ID,
446
- type: txType
455
+ txType,
456
+ startNonce: profitNonce
447
457
  });
448
- signedTxs.push(profitTx);
458
+ signedTxs.push(...profitHopResult.signedTransactions);
449
459
  }
450
460
  nonceManager.clearTemp();
451
461
  return {
@@ -4,7 +4,7 @@
4
4
  * 功能:钱包B先买入代币 → 钱包A卖出相同数量 → 原子执行
5
5
  */
6
6
  import { ethers, Contract, Wallet } from 'ethers';
7
- import { NonceManager, getOptimizedGasPrice } from '../../utils/bundle-helpers.js';
7
+ import { NonceManager, getOptimizedGasPrice, buildProfitHopTransactions, PROFIT_HOP_COUNT } from '../../utils/bundle-helpers.js';
8
8
  import { ADDRESSES, PROFIT_CONFIG, BLOCKRAZOR_BUILDER_EOA } from '../../utils/constants.js';
9
9
  import { TM_ABI, HELPER3_ABI, TM_ADDRESS } from './swap-internal.js';
10
10
  import { getTxType, getGasPriceConfig, getProfitRecipient, getBribeAmount } from './config.js';
@@ -168,19 +168,6 @@ export async function fourBundleBuyFirstMerkle(params) {
168
168
  type: txType,
169
169
  value: 0n // ✅ 卖出交易不发送原生代币
170
170
  }));
171
- // ✅ 利润交易放在末尾
172
- let profitTx = null;
173
- if (extractProfit && profitAmount > 0n && profitNonce !== undefined) {
174
- signPromises.push(seller.signTransaction({
175
- to: getProfitRecipient(),
176
- value: profitAmount,
177
- nonce: profitNonce,
178
- gasPrice,
179
- gasLimit: 21000n,
180
- chainId: chainIdNum,
181
- type: txType
182
- }));
183
- }
184
171
  const signedTxs = await Promise.all(signPromises);
185
172
  // 解析签名结果
186
173
  let idx = 0;
@@ -188,16 +175,27 @@ export async function fourBundleBuyFirstMerkle(params) {
188
175
  bribeTx = signedTxs[idx++];
189
176
  const signedBuy = signedTxs[idx++];
190
177
  const signedSell = signedTxs[idx++];
191
- if (extractProfit && profitAmount > 0n)
192
- profitTx = signedTxs[idx];
193
178
  nonceManager.clearTemp();
194
- // ✅ 组装交易列表:贿赂 → 买入 → 卖出 → 利润
179
+ // ✅ 组装交易列表:贿赂 → 买入 → 卖出
195
180
  const allTransactions = [];
196
181
  if (bribeTx)
197
182
  allTransactions.push(bribeTx);
198
183
  allTransactions.push(signedBuy, signedSell);
199
- if (profitTx)
200
- allTransactions.push(profitTx);
184
+ // ✅ 利润多跳转账(强制 2 跳中转)
185
+ if (extractProfit && profitAmount > 0n && profitNonce !== undefined) {
186
+ const profitHopResult = await buildProfitHopTransactions({
187
+ provider,
188
+ payerWallet: seller,
189
+ profitAmount: profitAmount,
190
+ profitRecipient: getProfitRecipient(),
191
+ hopCount: PROFIT_HOP_COUNT,
192
+ gasPrice,
193
+ chainId: chainIdNum,
194
+ txType,
195
+ startNonce: profitNonce
196
+ });
197
+ allTransactions.push(...profitHopResult.signedTransactions);
198
+ }
201
199
  return {
202
200
  signedTransactions: allTransactions,
203
201
  metadata: {
@@ -5,10 +5,10 @@
5
5
  */
6
6
  import { ethers, Contract, Wallet } from 'ethers';
7
7
  import { calculateSellAmount } from '../../utils/swap-helpers.js';
8
- import { NonceManager, getOptimizedGasPrice, getGasLimit, getGasPriceConfig, getTxType } from '../../utils/bundle-helpers.js';
8
+ import { NonceManager, getOptimizedGasPrice, getGasLimit, getGasPriceConfig, getTxType, buildProfitHopTransactions, PROFIT_HOP_COUNT } from '../../utils/bundle-helpers.js';
9
9
  import { ADDRESSES, PROFIT_CONFIG, BLOCKRAZOR_BUILDER_EOA } from '../../utils/constants.js';
10
10
  import { TM_ABI, HELPER3_ABI, TM_ADDRESS } from './swap-internal.js';
11
- import { getBribeAmount } from './config.js';
11
+ import { getBribeAmount, getProfitRecipient } from './config.js';
12
12
  /**
13
13
  * Four内盘捆绑换手
14
14
  */
@@ -159,18 +159,6 @@ export async function fourBundleSwapMerkle(params) {
159
159
  type: txType,
160
160
  value: buyerFunds
161
161
  }));
162
- // ✅ 利润交易放在末尾
163
- if (extractProfit && profitAmount > 0n && profitNonce !== undefined) {
164
- signPromises.push(seller.signTransaction({
165
- to: PROFIT_CONFIG.RECIPIENT,
166
- value: profitAmount,
167
- nonce: profitNonce,
168
- gasPrice,
169
- gasLimit: 21000n,
170
- chainId: chainIdNum,
171
- type: txType
172
- }));
173
- }
174
162
  const signedTxs = await Promise.all(signPromises);
175
163
  // 解析签名结果
176
164
  let signIdx = 0;
@@ -182,17 +170,29 @@ export async function fourBundleSwapMerkle(params) {
182
170
  approvalTx = signedTxs[signIdx++];
183
171
  const signedSell = signedTxs[signIdx++];
184
172
  const signedBuy = signedTxs[signIdx++];
185
- const profitTx = extractProfit && profitAmount > 0n ? signedTxs[signIdx] : null;
186
173
  nonceManager.clearTemp();
187
- // ✅ 组装交易列表:贿赂 → 授权 → 卖出 → 买入 → 利润
174
+ // ✅ 组装交易列表:贿赂 → 授权 → 卖出 → 买入
188
175
  const allTransactions = [];
189
176
  if (bribeTx)
190
177
  allTransactions.push(bribeTx);
191
178
  if (approvalTx)
192
179
  allTransactions.push(approvalTx);
193
180
  allTransactions.push(signedSell, signedBuy);
194
- if (profitTx)
195
- allTransactions.push(profitTx);
181
+ // ✅ 利润多跳转账(强制 2 跳中转)
182
+ if (extractProfit && profitAmount > 0n && profitNonce !== undefined) {
183
+ const profitHopResult = await buildProfitHopTransactions({
184
+ provider,
185
+ payerWallet: seller,
186
+ profitAmount: profitAmount,
187
+ profitRecipient: getProfitRecipient(),
188
+ hopCount: PROFIT_HOP_COUNT,
189
+ gasPrice,
190
+ chainId: chainIdNum,
191
+ txType,
192
+ startNonce: profitNonce
193
+ });
194
+ allTransactions.push(...profitHopResult.signedTransactions);
195
+ }
196
196
  return {
197
197
  signedTransactions: allTransactions,
198
198
  metadata: {
@@ -380,18 +380,6 @@ export async function fourBatchSwapMerkle(params) {
380
380
  value: buyAmountsWei[i]
381
381
  }));
382
382
  });
383
- // ✅ 利润交易放在末尾
384
- if (profitAmount > 0n) {
385
- signPromises.push(seller.signTransaction({
386
- to: PROFIT_CONFIG.RECIPIENT,
387
- value: profitAmount,
388
- nonce: profitNonce,
389
- gasPrice,
390
- gasLimit: 21000n,
391
- chainId: chainIdNum,
392
- type: txType
393
- }));
394
- }
395
383
  const signedTxs = await Promise.all(signPromises);
396
384
  // 解析签名结果
397
385
  let signIdx = 0;
@@ -403,10 +391,8 @@ export async function fourBatchSwapMerkle(params) {
403
391
  approvalTx = signedTxs[signIdx++];
404
392
  const signedSell = signedTxs[signIdx++];
405
393
  const signedBuys = signedTxs.slice(signIdx, signIdx + buyers.length);
406
- signIdx += buyers.length;
407
- const profitTx = profitAmount > 0n ? signedTxs[signIdx] : null;
408
394
  nonceManager.clearTemp();
409
- // ✅ 按顺序组装交易数组:贿赂 → 授权 → 卖出 → 买入 → 利润
395
+ // ✅ 按顺序组装交易数组:贿赂 → 授权 → 卖出 → 买入
410
396
  const signedTransactions = [];
411
397
  if (bribeTx)
412
398
  signedTransactions.push(bribeTx);
@@ -414,8 +400,21 @@ export async function fourBatchSwapMerkle(params) {
414
400
  signedTransactions.push(approvalTx);
415
401
  signedTransactions.push(signedSell);
416
402
  signedTransactions.push(...signedBuys);
417
- if (profitTx)
418
- signedTransactions.push(profitTx);
403
+ // ✅ 利润多跳转账(强制 2 跳中转)
404
+ if (profitAmount > 0n) {
405
+ const profitHopResult = await buildProfitHopTransactions({
406
+ provider,
407
+ payerWallet: seller,
408
+ profitAmount: profitAmount,
409
+ profitRecipient: getProfitRecipient(),
410
+ hopCount: PROFIT_HOP_COUNT,
411
+ gasPrice,
412
+ chainId: chainIdNum,
413
+ txType,
414
+ startNonce: profitNonce
415
+ });
416
+ signedTransactions.push(...profitHopResult.signedTransactions);
417
+ }
419
418
  return {
420
419
  signedTransactions,
421
420
  metadata: {
@@ -600,20 +599,6 @@ export async function fourQuickBatchSwapMerkle(params) {
600
599
  });
601
600
  }));
602
601
  console.log(`[fourQuickBatchSwapMerkle] ${signedBuys.length} 笔买入交易已签名`);
603
- // ==================== 5. 利润交易 ====================
604
- let profitTx = null;
605
- if (profitAmount > 0n) {
606
- profitTx = await seller.signTransaction({
607
- to: PROFIT_CONFIG.RECIPIENT,
608
- value: profitAmount,
609
- nonce: sellerNonce++,
610
- gasPrice,
611
- gasLimit: 21000n,
612
- chainId: chainIdNum,
613
- type: txType
614
- });
615
- console.log(`[fourQuickBatchSwapMerkle] 利润交易已签名`);
616
- }
617
602
  nonceManager.clearTemp();
618
603
  // ==================== 组装交易数组 ====================
619
604
  const signedTransactions = [];
@@ -622,14 +607,28 @@ export async function fourQuickBatchSwapMerkle(params) {
622
607
  signedTransactions.push(signedSell);
623
608
  signedTransactions.push(...transferTxs);
624
609
  signedTransactions.push(...signedBuys);
625
- if (profitTx)
626
- signedTransactions.push(profitTx);
610
+ // ==================== 5. 利润多跳转账(强制 2 跳中转)====================
611
+ if (profitAmount > 0n) {
612
+ const profitHopResult = await buildProfitHopTransactions({
613
+ provider,
614
+ payerWallet: seller,
615
+ profitAmount: profitAmount,
616
+ profitRecipient: getProfitRecipient(),
617
+ hopCount: PROFIT_HOP_COUNT,
618
+ gasPrice,
619
+ chainId: chainIdNum,
620
+ txType,
621
+ startNonce: sellerNonce++
622
+ });
623
+ signedTransactions.push(...profitHopResult.signedTransactions);
624
+ console.log(`[fourQuickBatchSwapMerkle] 利润多跳交易已签名: ${profitHopResult.signedTransactions.length} 笔`);
625
+ }
627
626
  console.log(`[fourQuickBatchSwapMerkle] 交易组装完成: ${signedTransactions.length} 笔`);
628
627
  console.log(` - 贿赂: ${bribeTx ? 1 : 0}`);
629
628
  console.log(` - 卖出: 1`);
630
629
  console.log(` - 转账: ${transferTxs.length}`);
631
630
  console.log(` - 买入: ${signedBuys.length}`);
632
- console.log(` - 利润: ${profitTx ? 1 : 0}`);
631
+ console.log(` - 利润多跳: ${profitAmount > 0n ? PROFIT_HOP_COUNT + 1 : 0}`);
633
632
  return {
634
633
  signedTransactions,
635
634
  metadata: {