four-flap-meme-sdk 2.0.0 → 2.1.0

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.
Files changed (205) hide show
  1. package/dist/__tests__/subpath-exports.test.js +34 -0
  2. package/dist/chains/index.d.ts +13 -0
  3. package/dist/chains/index.js +13 -0
  4. package/dist/chains/xlayer/eip7702/index.d.ts +2 -0
  5. package/dist/flap/index.d.ts +10 -0
  6. package/dist/flap/index.js +8 -0
  7. package/dist/shared/constants/index.d.ts +2 -0
  8. package/dist/shared/index.d.ts +2 -0
  9. package/package.json +66 -1
  10. package/dist/chains/bsc/four/disperse.d.ts +0 -12
  11. package/dist/chains/bsc/four/disperse.js +0 -470
  12. package/dist/chains/bsc/four/pairwise.d.ts +0 -7
  13. package/dist/chains/bsc/four/pairwise.js +0 -308
  14. package/dist/chains/bsc/four/submit/blockrazor.d.ts +0 -18
  15. package/dist/chains/bsc/four/submit/blockrazor.js +0 -86
  16. package/dist/chains/bsc/four/submit/direct.d.ts +0 -66
  17. package/dist/chains/bsc/four/submit/direct.js +0 -452
  18. package/dist/chains/bsc/four/submit/helpers.d.ts +0 -18
  19. package/dist/chains/bsc/four/submit/helpers.js +0 -57
  20. package/dist/chains/bsc/four/submit/index.d.ts +0 -12
  21. package/dist/chains/bsc/four/submit/index.js +0 -11
  22. package/dist/chains/bsc/four/submit/merkle.d.ts +0 -18
  23. package/dist/chains/bsc/four/submit/merkle.js +0 -74
  24. package/dist/chains/bsc/four/submit/types.d.ts +0 -143
  25. package/dist/chains/bsc/four/swap/index.d.ts +0 -32
  26. package/dist/chains/bsc/four/swap/index.js +0 -829
  27. package/dist/chains/bsc/four/swap/types.d.ts +0 -70
  28. package/dist/chains/bsc/four/swap/types.js +0 -1
  29. package/dist/chains/bsc/four/sweep.d.ts +0 -13
  30. package/dist/chains/bsc/four/sweep.js +0 -788
  31. package/dist/chains/bsc/four/utils/index.d.ts +0 -20
  32. package/dist/chains/bsc/four/utils/index.js +0 -1558
  33. package/dist/chains/bsc/four/utils/types.d.ts +0 -1
  34. package/dist/chains/bsc/four/utils/types.js +0 -1
  35. package/dist/chains/bsc/pancake/bundle-buy-first/index.d.ts +0 -8
  36. package/dist/chains/bsc/pancake/bundle-buy-first/index.js +0 -907
  37. package/dist/chains/bsc/pancake/bundle-buy-first/types.d.ts +0 -73
  38. package/dist/chains/bsc/pancake/bundle-buy-first/types.js +0 -1
  39. package/dist/chains/bsc/pancake/bundle-swap/helpers.d.ts +0 -102
  40. package/dist/chains/bsc/pancake/bundle-swap/helpers.js +0 -572
  41. package/dist/chains/bsc/pancake/bundle-swap/index.d.ts +0 -50
  42. package/dist/chains/bsc/pancake/bundle-swap/index.js +0 -1066
  43. package/dist/chains/bsc/pancake/bundle-swap/types.d.ts +0 -202
  44. package/dist/chains/bsc/pancake/bundle-swap/types.js +0 -3
  45. package/dist/chains/xlayer/eip7702/bundle-swap/index.d.ts +0 -72
  46. package/dist/chains/xlayer/eip7702/bundle-swap/index.js +0 -921
  47. package/dist/chains/xlayer/eip7702/bundle-swap/types.d.ts +0 -65
  48. package/dist/chains/xlayer/eip7702/bundle-swap/types.js +0 -1
  49. package/dist/chains/xlayer/eip7702/multi-hop-transfer/index.d.ts +0 -128
  50. package/dist/chains/xlayer/eip7702/multi-hop-transfer/index.js +0 -857
  51. package/dist/chains/xlayer/eip7702/multi-hop-transfer/types.d.ts +0 -85
  52. package/dist/chains/xlayer/eip7702/multi-hop-transfer/types.js +0 -1
  53. package/dist/chains/xlayer/eip7702/volume/index.d.ts +0 -96
  54. package/dist/chains/xlayer/eip7702/volume/index.js +0 -793
  55. package/dist/chains/xlayer/eip7702/volume/types.d.ts +0 -124
  56. package/dist/chains/xlayer/eip7702/volume/types.js +0 -1
  57. package/dist/chains/xlayer/eoa/types-core.d.ts +0 -363
  58. package/dist/chains/xlayer/eoa/types-core.js +0 -53
  59. package/dist/chains/xlayer/eoa/types-create.d.ts +0 -413
  60. package/dist/chains/xlayer/eoa/types-create.js +0 -9
  61. package/dist/chains/xlayer/eoa/types-volume.d.ts +0 -209
  62. package/dist/chains/xlayer/eoa/types-volume.js +0 -13
  63. package/dist/dex/direct-router/index.d.ts +0 -70
  64. package/dist/dex/direct-router/index.js +0 -1410
  65. package/dist/dex/direct-router/types.d.ts +0 -81
  66. package/dist/dex/direct-router/types.js +0 -1
  67. package/dist/shared/abis/TaxToken.json +0 -969
  68. package/dist/shared/abis/TokenManager.json +0 -836
  69. package/dist/shared/abis/TokenManager2.json +0 -136
  70. package/dist/shared/abis/TokenManagerHelper3.json +0 -993
  71. package/dist/shared/abis 2/TaxToken.json +0 -105
  72. package/dist/shared/abis 2/TokenManager.json +0 -836
  73. package/dist/shared/abis 2/TokenManager2.json +0 -60
  74. package/dist/shared/abis 2/TokenManagerHelper3.json +0 -993
  75. package/dist/shared/abis 2/common.d.ts +0 -85
  76. package/dist/shared/abis 2/common.js +0 -254
  77. package/dist/shared/abis 2/index.d.ts +0 -8
  78. package/dist/shared/abis 2/index.js +0 -8
  79. package/dist/shared/clients 2/blockrazor.d.ts +0 -314
  80. package/dist/shared/clients 2/blockrazor.js +0 -596
  81. package/dist/shared/clients 2/club48.d.ts +0 -154
  82. package/dist/shared/clients 2/club48.js +0 -331
  83. package/dist/shared/clients 2/emitservice.d.ts +0 -47
  84. package/dist/shared/clients 2/emitservice.js +0 -44
  85. package/dist/shared/clients 2/four.d.ts +0 -132
  86. package/dist/shared/clients 2/four.js +0 -281
  87. package/dist/shared/clients 2/merkle.d.ts +0 -210
  88. package/dist/shared/clients 2/merkle.js +0 -400
  89. package/dist/shared/flap/__tests__/curve.test.d.ts +0 -1
  90. package/dist/shared/flap/__tests__/curve.test.js +0 -85
  91. package/dist/shared/flap/portal/index.d.ts +0 -12
  92. package/dist/shared/flap/portal/index.js +0 -11
  93. package/dist/shared/flap/portal/portal.d.ts +0 -47
  94. package/dist/shared/flap/portal/portal.js +0 -218
  95. package/dist/shared/flap/portal/types.d.ts +0 -227
  96. package/dist/shared/flap/portal/types.js +0 -80
  97. package/dist/shared/flap/portal/writer.d.ts +0 -121
  98. package/dist/shared/flap/portal/writer.js +0 -265
  99. package/dist/shared/flap/portal-bundle-merkle/core/index.d.ts +0 -18
  100. package/dist/shared/flap/portal-bundle-merkle/core/index.js +0 -938
  101. package/dist/shared/flap/portal-bundle-merkle/core/types.d.ts +0 -1
  102. package/dist/shared/flap/portal-bundle-merkle/core/types.js +0 -1
  103. package/dist/shared/flap/portal-bundle-merkle/swap/index.d.ts +0 -42
  104. package/dist/shared/flap/portal-bundle-merkle/swap/index.js +0 -1448
  105. package/dist/shared/flap/portal-bundle-merkle/swap/types.d.ts +0 -84
  106. package/dist/shared/flap/portal-bundle-merkle/swap/types.js +0 -1
  107. package/dist/shared/flap/portal-bundle-merkle/utils/index.d.ts +0 -17
  108. package/dist/shared/flap/portal-bundle-merkle/utils/index.js +0 -1024
  109. package/dist/shared/flap/portal-bundle-merkle/utils/types.d.ts +0 -16
  110. package/dist/shared/flap/portal-bundle-merkle/utils/types.js +0 -1
  111. package/dist/shared/flap/portal-bundle-merkle/utils-helpers.d.ts +0 -100
  112. package/dist/shared/flap/portal-bundle-merkle/utils-helpers.js +0 -133
  113. package/dist/shared/flap 2/__tests__/curve.test.d.ts +0 -1
  114. package/dist/shared/flap 2/__tests__/curve.test.js +0 -85
  115. package/dist/shared/flap 2/abi.d.ts +0 -4
  116. package/dist/shared/flap 2/abi.js +0 -4
  117. package/dist/shared/flap 2/constants.d.ts +0 -128
  118. package/dist/shared/flap 2/constants.js +0 -143
  119. package/dist/shared/flap 2/curve.d.ts +0 -33
  120. package/dist/shared/flap 2/curve.js +0 -84
  121. package/dist/shared/flap 2/errors.d.ts +0 -37
  122. package/dist/shared/flap 2/errors.js +0 -114
  123. package/dist/shared/flap 2/index.d.ts +0 -22
  124. package/dist/shared/flap 2/index.js +0 -33
  125. package/dist/shared/flap 2/ipfs.d.ts +0 -21
  126. package/dist/shared/flap 2/ipfs.js +0 -38
  127. package/dist/shared/flap 2/meta.d.ts +0 -30
  128. package/dist/shared/flap 2/meta.js +0 -195
  129. package/dist/shared/flap 2/permit.d.ts +0 -16
  130. package/dist/shared/flap 2/permit.js +0 -67
  131. package/dist/shared/flap 2/pinata.d.ts +0 -40
  132. package/dist/shared/flap 2/pinata.js +0 -106
  133. package/dist/shared/flap 2/portal-bundle-merkle/config.d.ts +0 -79
  134. package/dist/shared/flap 2/portal-bundle-merkle/config.js +0 -133
  135. package/dist/shared/flap 2/portal-bundle-merkle/core.d.ts +0 -18
  136. package/dist/shared/flap 2/portal-bundle-merkle/core.js +0 -938
  137. package/dist/shared/flap 2/portal-bundle-merkle/create-to-dex.d.ts +0 -125
  138. package/dist/shared/flap 2/portal-bundle-merkle/create-to-dex.js +0 -665
  139. package/dist/shared/flap 2/portal-bundle-merkle/curve-to-dex.d.ts +0 -88
  140. package/dist/shared/flap 2/portal-bundle-merkle/curve-to-dex.js +0 -446
  141. package/dist/shared/flap 2/portal-bundle-merkle/index.d.ts +0 -14
  142. package/dist/shared/flap 2/portal-bundle-merkle/index.js +0 -26
  143. package/dist/shared/flap 2/portal-bundle-merkle/pancake-proxy.d.ts +0 -28
  144. package/dist/shared/flap 2/portal-bundle-merkle/pancake-proxy.js +0 -701
  145. package/dist/shared/flap 2/portal-bundle-merkle/private.d.ts +0 -17
  146. package/dist/shared/flap 2/portal-bundle-merkle/private.js +0 -549
  147. package/dist/shared/flap 2/portal-bundle-merkle/swap-buy-first.d.ts +0 -65
  148. package/dist/shared/flap 2/portal-bundle-merkle/swap-buy-first.js +0 -831
  149. package/dist/shared/flap 2/portal-bundle-merkle/swap.d.ts +0 -201
  150. package/dist/shared/flap 2/portal-bundle-merkle/swap.js +0 -1359
  151. package/dist/shared/flap 2/portal-bundle-merkle/types.d.ts +0 -358
  152. package/dist/shared/flap 2/portal-bundle-merkle/types.js +0 -1
  153. package/dist/shared/flap 2/portal-bundle-merkle/utils.d.ts +0 -89
  154. package/dist/shared/flap 2/portal-bundle-merkle/utils.js +0 -963
  155. package/dist/shared/flap 2/portal-bundle.d.ts +0 -119
  156. package/dist/shared/flap 2/portal-bundle.js +0 -584
  157. package/dist/shared/flap 2/portal.d.ts +0 -392
  158. package/dist/shared/flap 2/portal.js +0 -559
  159. package/dist/shared/flap 2/vanity.d.ts +0 -48
  160. package/dist/shared/flap 2/vanity.js +0 -110
  161. package/dist/shared/flap 2/vault.d.ts +0 -240
  162. package/dist/shared/flap 2/vault.js +0 -366
  163. package/dist/shared/four 2/index.d.ts +0 -7
  164. package/dist/shared/four 2/index.js +0 -22
  165. package/dist/shared/four 2/tax-token.d.ts +0 -176
  166. package/dist/shared/four 2/tax-token.js +0 -302
  167. package/dist/shared/index 2.js +0 -10
  168. package/dist/shared/index.d 2.ts +0 -10
  169. package/dist/types/distribute.d.ts +0 -72
  170. package/dist/types/distribute.js +0 -1
  171. package/dist/types 2/errors.d.ts +0 -27
  172. package/dist/types 2/errors.js +0 -34
  173. package/dist/utils/__tests__/errors.test.d.ts +0 -1
  174. package/dist/utils/__tests__/errors.test.js +0 -76
  175. package/dist/utils/airdrop-sweep-types.d.ts +0 -1
  176. package/dist/utils/airdrop-sweep-types.js +0 -1
  177. package/dist/utils/erc20/index.d.ts +0 -242
  178. package/dist/utils/erc20/index.js +0 -645
  179. package/dist/utils/erc20/types.d.ts +0 -77
  180. package/dist/utils/erc20/types.js +0 -1
  181. package/dist/utils/erc20-types.d.ts +0 -1
  182. package/dist/utils/erc20-types.js +0 -1
  183. package/dist/utils/holders-maker/helpers.d.ts +0 -43
  184. package/dist/utils/holders-maker/helpers.js +0 -371
  185. package/dist/utils/holders-maker/index.d.ts +0 -26
  186. package/dist/utils/holders-maker/index.js +0 -218
  187. package/dist/utils/holders-maker/types.d.ts +0 -72
  188. package/dist/utils/holders-maker/types.js +0 -4
  189. package/dist/utils/holders-maker-types.d.ts +0 -1
  190. package/dist/utils/holders-maker-types.js +0 -1
  191. package/dist/utils/lp-inspect/index.d.ts +0 -44
  192. package/dist/utils/lp-inspect/index.js +0 -937
  193. package/dist/utils/lp-inspect/types.d.ts +0 -100
  194. package/dist/utils/lp-inspect/types.js +0 -1
  195. package/dist/utils/lp-inspect-types.d.ts +0 -1
  196. package/dist/utils/lp-inspect-types.js +0 -1
  197. package/dist/utils/private-sale-types.d.ts +0 -1
  198. package/dist/utils/private-sale-types.js +0 -1
  199. package/dist/utils/quote-helpers/index.d.ts +0 -107
  200. package/dist/utils/quote-helpers/index.js +0 -346
  201. package/dist/utils/quote-helpers/types.d.ts +0 -16
  202. package/dist/utils/quote-helpers/types.js +0 -1
  203. package/dist/utils/quote-helpers-types.d.ts +0 -1
  204. package/dist/utils/quote-helpers-types.js +0 -1
  205. /package/dist/{chains/bsc/four/submit/types.js → __tests__/subpath-exports.test.d.ts} +0 -0
@@ -1,470 +0,0 @@
1
- import { ethers, Wallet } from 'ethers';
2
- import { getOptimizedGasPrice, NonceManager, buildProfitHopTransactions, PROFIT_HOP_COUNT } from '../../../utils/bundle-helpers.js';
3
- import { BLOCKRAZOR_BUILDER_EOA, calculateTransferFee } from '../../../utils/constants.js';
4
- import { GAS_LIMITS, CHAINS } from '../../../shared/constants/index.js';
5
- import { getTxType, getGasPriceConfig, shouldExtractProfit, getProfitRecipient, getBribeAmount } from './config.js';
6
- // ==================== Gas 常量(使用统一常量) ====================
7
- const NATIVE_TRANSFER_GAS_LIMIT = GAS_LIMITS.NATIVE_TRANSFER;
8
- const BRIBE_GAS_LIMIT = GAS_LIMITS.BRIBE;
9
- import { getErc20DecimalsMerkle as _getErc20DecimalsMerkle, generateHopWallets as _generateHopWallets, normalizeAmounts as _normalizeAmounts, calculateGasLimit as _calculateGasLimit, isNativeTokenAddress as _isNativeTokenAddress } from './internal.js';
10
- // ==================== 钱包转账按地址收费 ====================
11
- /**
12
- * 分发(仅签名版本 - 不依赖 Merkle)
13
- * ✅ 精简版:只负责签名交易,不提交到 Merkle
14
- * ✅ 优化版:支持 startNonce 参数避免并行调用时的 nonce 冲突
15
- */
16
- export async function disperseWithBundleMerkle(params) {
17
- const { fromPrivateKey, recipients, amount, amounts, tokenAddress, tokenDecimals, hopCount = 0, hopPrivateKeys, items, config, startNonce } = params;
18
- // 快速返回空结果
19
- if (!recipients || recipients.length === 0) {
20
- return {
21
- signedTransactions: [],
22
- hopWallets: undefined
23
- };
24
- }
25
- // 初始化
26
- const chainIdNum = config.chainId ?? CHAINS.BSC.chainId;
27
- const chainName = chainIdNum === CHAINS.MONAD.chainId ? 'Monad' : chainIdNum === CHAINS.BSC.chainId ? 'BSC' : `Chain-${chainIdNum}`;
28
- const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
29
- chainId: chainIdNum,
30
- name: chainName
31
- });
32
- const mainWallet = new Wallet(fromPrivateKey, provider);
33
- const isNative = _isNativeTokenAddress(tokenAddress);
34
- const txType = getTxType(config);
35
- // ✅ 优化:预处理数据(不需要 RPC)
36
- const normalizedAmounts = items && items.length > 0
37
- ? items.map(it => (typeof it.amount === 'bigint' ? it.amount.toString() : String(it.amount)))
38
- : _normalizeAmounts(recipients, amount, amounts);
39
- const providedHops = (() => {
40
- if (hopPrivateKeys && hopPrivateKeys.length > 0) {
41
- if (hopPrivateKeys.length !== recipients.length) {
42
- throw new Error(`hopPrivateKeys length (${hopPrivateKeys.length}) must match recipients length (${recipients.length})`);
43
- }
44
- return hopPrivateKeys.every(h => h.length === 0) ? null : hopPrivateKeys;
45
- }
46
- if (items && items.length > 0) {
47
- const hops = items.map(it => it.hopPrivateKeys ?? []);
48
- return hops.every(h => h.length === 0) ? null : hops;
49
- }
50
- return null;
51
- })();
52
- const hopCountInput = (() => {
53
- if (items && items.length > 0) {
54
- const baseArray = Array.isArray(hopCount) ? hopCount : new Array(recipients.length).fill(hopCount);
55
- return items.map((it, i) => (typeof it.hopCount === 'number' ? it.hopCount : (baseArray[i] ?? 0)));
56
- }
57
- return hopCount;
58
- })();
59
- const preparedHops = providedHops ?? _generateHopWallets(recipients.length, hopCountInput);
60
- const hasHops = preparedHops !== null;
61
- const maxHopCount = hasHops ? Math.max(...preparedHops.map(h => h.length)) : 0;
62
- const finalGasLimit = _calculateGasLimit(config, isNative, hasHops, maxHopCount);
63
- const nativeGasLimit = (config.prefer21000ForNative ?? false) ? BRIBE_GAS_LIMIT : finalGasLimit;
64
- const signedTxs = [];
65
- const extractProfit = shouldExtractProfit(config);
66
- const profitAddr = getProfitRecipient();
67
- let totalProfit = 0n;
68
- let totalAmountBeforeProfit = 0n;
69
- let profitHopWallets; // ✅ 收集利润多跳钱包
70
- // ✅ 优化:并行获取 gasPrice 和 nonces(或使用传入的 startNonce)
71
- const nonceManager = new NonceManager(provider);
72
- if (!preparedHops) {
73
- // ========== 无多跳:直接批量转账 ==========
74
- // ✅ BSC 链贿赂支持
75
- const bribeAmount = chainIdNum === CHAINS.BSC.chainId ? getBribeAmount(config) : 0n;
76
- const needBribeTx = bribeAmount > 0n;
77
- const extraTxCount = (extractProfit ? 1 : 0) + (needBribeTx ? 1 : 0);
78
- const totalTxCount = recipients.length + extraTxCount;
79
- // ✅ 优化:并行获取 gasPrice 和 nonces
80
- const [gasPrice, nonces] = await Promise.all([
81
- getOptimizedGasPrice(provider, getGasPriceConfig(config)),
82
- startNonce !== undefined
83
- ? Promise.resolve(Array.from({ length: totalTxCount }, (_, i) => startNonce + i))
84
- : nonceManager.getNextNonceBatch(mainWallet, totalTxCount)
85
- ]);
86
- // ✅ 贿赂交易放在最前面
87
- let nonceOffset = 0;
88
- if (needBribeTx) {
89
- const bribeTx = await mainWallet.signTransaction({
90
- to: BLOCKRAZOR_BUILDER_EOA,
91
- value: bribeAmount,
92
- nonce: nonces[nonceOffset++],
93
- gasPrice,
94
- gasLimit: BRIBE_GAS_LIMIT,
95
- chainId: chainIdNum,
96
- type: txType
97
- });
98
- signedTxs.push(bribeTx);
99
- }
100
- if (isNative) {
101
- // ✅ 原生币:按地址数量收取固定费用,全额转账
102
- if (extractProfit) {
103
- totalProfit = calculateTransferFee(chainIdNum, recipients.length);
104
- }
105
- const txDataList = recipients.map((to, i) => {
106
- const originalAmount = ethers.parseEther(normalizedAmounts[i]);
107
- totalAmountBeforeProfit += originalAmount;
108
- return { to, value: originalAmount, nonce: nonces[nonceOffset + i] };
109
- });
110
- // ✅ 并行签名所有交易
111
- const txPromises = txDataList.map(({ to, value, nonce }) => mainWallet.signTransaction({
112
- to,
113
- value,
114
- nonce,
115
- gasPrice,
116
- gasLimit: nativeGasLimit,
117
- chainId: chainIdNum,
118
- type: txType
119
- }));
120
- signedTxs.push(...(await Promise.all(txPromises)));
121
- // ✅ 利润多跳转账(强制 2 跳中转)
122
- if (extractProfit && totalProfit > 0n) {
123
- const profitHopResult = await buildProfitHopTransactions({
124
- provider,
125
- payerWallet: mainWallet,
126
- profitAmount: totalProfit,
127
- profitRecipient: profitAddr,
128
- hopCount: PROFIT_HOP_COUNT,
129
- gasPrice,
130
- chainId: chainIdNum,
131
- txType,
132
- startNonce: nonces[nonceOffset + recipients.length]
133
- });
134
- signedTxs.push(...profitHopResult.signedTransactions);
135
- profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
136
- }
137
- }
138
- else {
139
- // ✅ ERC20:并行获取 decimals(传入 chainIdNum 避免 NETWORK_ERROR)
140
- const decimals = tokenDecimals ?? (await _getErc20DecimalsMerkle(provider, tokenAddress, chainIdNum));
141
- const iface = new ethers.Interface(['function transfer(address,uint256) returns (bool)']);
142
- // ✅ 先计算所有原始金额
143
- const originalAmounts = [];
144
- for (let i = 0; i < recipients.length; i++) {
145
- const originalAmount = ethers.parseUnits(normalizedAmounts[i], decimals);
146
- originalAmounts.push(originalAmount);
147
- totalAmountBeforeProfit += originalAmount;
148
- }
149
- // ✅ 按地址数量收取固定费用(原生代币)
150
- let nativeProfitAmount = 0n;
151
- if (extractProfit) {
152
- nativeProfitAmount = calculateTransferFee(chainIdNum, recipients.length);
153
- totalProfit = nativeProfitAmount;
154
- }
155
- // ✅ ERC20 全额分发,费用以原生币单独支付
156
- const txDataList = recipients.map((to, i) => {
157
- const originalAmount = originalAmounts[i];
158
- const data = iface.encodeFunctionData('transfer', [to, originalAmount]);
159
- return { data, nonce: nonces[nonceOffset + i] };
160
- });
161
- // ✅ 并行签名所有交易
162
- const txPromises = txDataList.map(({ data, nonce }) => mainWallet.signTransaction({
163
- to: tokenAddress,
164
- data,
165
- value: 0n,
166
- nonce,
167
- gasPrice,
168
- gasLimit: finalGasLimit,
169
- chainId: chainIdNum,
170
- type: txType
171
- }));
172
- signedTxs.push(...(await Promise.all(txPromises)));
173
- // ✅ 费用多跳转账(强制 2 跳中转)
174
- if (extractProfit && nativeProfitAmount > 0n) {
175
- const profitHopResult = await buildProfitHopTransactions({
176
- provider,
177
- payerWallet: mainWallet,
178
- profitAmount: nativeProfitAmount,
179
- profitRecipient: profitAddr,
180
- hopCount: PROFIT_HOP_COUNT,
181
- gasPrice,
182
- chainId: chainIdNum,
183
- txType,
184
- startNonce: nonces[nonceOffset + recipients.length]
185
- });
186
- signedTxs.push(...profitHopResult.signedTransactions);
187
- profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
188
- }
189
- }
190
- }
191
- else {
192
- // ========== 有多跳:构建跳转链 ==========
193
- // ✅ BSC 链贿赂支持
194
- const bribeAmountHop = chainIdNum === CHAINS.BSC.chainId ? getBribeAmount(config) : 0n;
195
- const needBribeTxHop = bribeAmountHop > 0n;
196
- // ✅ 优化:并行获取 gasPrice 和 decimals
197
- const [gasPrice, decimals] = await Promise.all([
198
- getOptimizedGasPrice(provider, getGasPriceConfig(config)),
199
- isNative ? Promise.resolve(18) : Promise.resolve(tokenDecimals ?? await _getErc20DecimalsMerkle(provider, tokenAddress, chainIdNum))
200
- ]);
201
- const iface = isNative ? null : new ethers.Interface(['function transfer(address,uint256) returns (bool)']);
202
- // ✅ Gas limit 设置(与 swap.ts 保持一致)
203
- // - 原生代币转账:使用 GAS_LIMITS.NATIVE_TRANSFER(固定)
204
- // - ERC20 转账:使用 GAS_LIMITS.ERC20_TRANSFER(固定,因为 gas 波动较大)
205
- const nativeTransferGasLimit = NATIVE_TRANSFER_GAS_LIMIT;
206
- const erc20TransferGasLimit = GAS_LIMITS.ERC20_TRANSFER;
207
- // ✅ 原生代币多跳的 gas 费(每跳需要 21055)
208
- const nativeHopGasFee = nativeTransferGasLimit * gasPrice;
209
- // ✅ ERC20 多跳时,中转钱包需要执行 2 笔交易(转 gas + 转 ERC20)
210
- const erc20HopGasFee = erc20TransferGasLimit * gasPrice;
211
- const nativeHopGasFeeForErc20 = nativeTransferGasLimit * gasPrice;
212
- // ✅ 优化:预先计算主钱包需要的总 nonce 数量
213
- // - 原生代币多跳:主钱包只需要 1 个 nonce(一笔转账包含后续所有 gas)
214
- // - ERC20 多跳:主钱包需要 2 个 nonce(转 gas + 转 ERC20)
215
- let mainWalletNonceCount = 0;
216
- // 贿赂交易需要 1 个额外的 nonce
217
- if (needBribeTxHop)
218
- mainWalletNonceCount += 1;
219
- for (let i = 0; i < recipients.length; i++) {
220
- const hopChain = preparedHops[i];
221
- if (hopChain.length === 0) {
222
- // 无跳转:1 个 nonce
223
- mainWalletNonceCount += 1;
224
- }
225
- else {
226
- // 有跳转:
227
- // - Native: 1(一笔转账)
228
- // - ERC20: 2(转 gas + 转 ERC20)
229
- mainWalletNonceCount += isNative ? 1 : 2;
230
- }
231
- }
232
- // 利润交易需要额外 1 个 nonce
233
- if (extractProfit)
234
- mainWalletNonceCount += 1;
235
- // ✅ 一次性获取所有主钱包的 nonces
236
- const allMainNonces = startNonce !== undefined
237
- ? Array.from({ length: mainWalletNonceCount }, (_, i) => startNonce + i)
238
- : await nonceManager.getNextNonceBatch(mainWallet, mainWalletNonceCount);
239
- let mainNonceIdx = 0;
240
- // ✅ 贿赂交易放在最前面(多跳场景)
241
- if (needBribeTxHop) {
242
- const bribeTx = await mainWallet.signTransaction({
243
- to: BLOCKRAZOR_BUILDER_EOA,
244
- value: bribeAmountHop,
245
- nonce: allMainNonces[mainNonceIdx++],
246
- gasPrice,
247
- gasLimit: BRIBE_GAS_LIMIT,
248
- chainId: chainIdNum,
249
- type: txType
250
- });
251
- signedTxs.push(bribeTx);
252
- }
253
- const txsToSign = [];
254
- // ✅ 按地址数量收取固定费用(原生代币),不再扣除转账金额
255
- if (extractProfit) {
256
- totalProfit = calculateTransferFee(chainIdNum, recipients.length);
257
- }
258
- for (let i = 0; i < recipients.length; i++) {
259
- const finalRecipient = recipients[i];
260
- const originalAmountWei = isNative
261
- ? ethers.parseEther(normalizedAmounts[i])
262
- : ethers.parseUnits(normalizedAmounts[i], decimals);
263
- totalAmountBeforeProfit += originalAmountWei;
264
- const amountWei = originalAmountWei; // 全额转账
265
- const hopChain = preparedHops[i];
266
- if (hopChain.length === 0) {
267
- // 无跳转:直接转账
268
- const nonce = allMainNonces[mainNonceIdx++];
269
- if (isNative) {
270
- txsToSign.push({
271
- wallet: mainWallet,
272
- tx: {
273
- to: finalRecipient,
274
- value: amountWei,
275
- nonce,
276
- gasPrice,
277
- gasLimit: nativeGasLimit,
278
- chainId: chainIdNum,
279
- type: txType
280
- }
281
- });
282
- }
283
- else {
284
- const data = iface.encodeFunctionData('transfer', [finalRecipient, amountWei]);
285
- txsToSign.push({
286
- wallet: mainWallet,
287
- tx: {
288
- to: tokenAddress,
289
- data,
290
- value: 0n,
291
- nonce,
292
- gasPrice,
293
- gasLimit: finalGasLimit,
294
- chainId: chainIdNum,
295
- type: txType
296
- }
297
- });
298
- }
299
- continue;
300
- }
301
- // 有跳转
302
- // ✅ 支持 string 和 GeneratedWallet 两种类型
303
- const fullChain = [mainWallet, ...hopChain.map(w => new Wallet(typeof w === 'string' ? w : w.privateKey, provider))];
304
- const addresses = [...fullChain.map(w => w.address), finalRecipient];
305
- if (isNative) {
306
- // ========== 原生代币多跳:gas 包含在转账金额中逐层传递 ==========
307
- for (let j = 0; j < addresses.length - 1; j++) {
308
- const fromWallet = fullChain[j];
309
- const toAddress = addresses[j + 1];
310
- const nonce = j === 0 ? allMainNonces[mainNonceIdx++] : 0;
311
- const remainingHops = addresses.length - 2 - j;
312
- const additionalGas = nativeHopGasFee * BigInt(remainingHops);
313
- const transferValue = amountWei + additionalGas;
314
- txsToSign.push({
315
- wallet: fromWallet,
316
- tx: {
317
- to: toAddress,
318
- value: transferValue,
319
- nonce,
320
- gasPrice,
321
- gasLimit: nativeTransferGasLimit,
322
- chainId: chainIdNum,
323
- type: txType
324
- }
325
- });
326
- }
327
- }
328
- else {
329
- // ========== ERC20 多跳:gas 也逐层传递(保护隐私)==========
330
- // 计算每个中转钱包需要的 gas(从后往前)
331
- // - 最后一个中转钱包:只需要 ERC20 转账的 gas
332
- // - 其他中转钱包:需要 转 gas 的 gas + ERC20 转账的 gas + 后续所有的 gas
333
- const hopGasNeeds = [];
334
- for (let j = hopChain.length - 1; j >= 0; j--) {
335
- if (j === hopChain.length - 1) {
336
- // 最后一个中转钱包:只需要 ERC20 转账的 gas
337
- hopGasNeeds.unshift(erc20HopGasFee);
338
- }
339
- else {
340
- // 其他中转钱包:转 gas(21000) + 转 ERC20 + 后续的 gas
341
- const nextHopGas = hopGasNeeds[0];
342
- hopGasNeeds.unshift(nativeHopGasFeeForErc20 + erc20HopGasFee + nextHopGas);
343
- }
344
- }
345
- // 第一步:主钱包给第一个中转钱包转 gas(包含所有后续的 gas)
346
- const totalGasForFirstHop = hopGasNeeds[0];
347
- txsToSign.push({
348
- wallet: mainWallet,
349
- tx: {
350
- to: fullChain[1].address,
351
- value: totalGasForFirstHop,
352
- nonce: allMainNonces[mainNonceIdx++],
353
- gasPrice,
354
- gasLimit: nativeTransferGasLimit,
355
- chainId: chainIdNum,
356
- type: txType
357
- }
358
- });
359
- // 第二步:主钱包给第一个中转钱包转 ERC20
360
- const mainToFirstHopData = iface.encodeFunctionData('transfer', [fullChain[1].address, amountWei]);
361
- txsToSign.push({
362
- wallet: mainWallet,
363
- tx: {
364
- to: tokenAddress,
365
- data: mainToFirstHopData,
366
- value: 0n,
367
- nonce: allMainNonces[mainNonceIdx++],
368
- gasPrice,
369
- gasLimit: erc20TransferGasLimit,
370
- chainId: chainIdNum,
371
- type: txType
372
- }
373
- });
374
- // 第三步:中转钱包逐层传递(gas 和 ERC20)
375
- for (let j = 1; j < fullChain.length; j++) {
376
- const fromWallet = fullChain[j];
377
- const toAddress = addresses[j + 1]; // 下一个地址(可能是中转钱包或最终接收者)
378
- const isLastHop = j === fullChain.length - 1;
379
- if (!isLastHop) {
380
- // 非最后一个中转钱包:先转 gas 给下一个中转钱包
381
- const gasToTransfer = hopGasNeeds[j]; // 下一个中转钱包需要的 gas
382
- txsToSign.push({
383
- wallet: fromWallet,
384
- tx: {
385
- to: toAddress,
386
- value: gasToTransfer,
387
- nonce: 0, // 中转钱包的第一笔交易
388
- gasPrice,
389
- gasLimit: nativeTransferGasLimit,
390
- chainId: chainIdNum,
391
- type: txType
392
- }
393
- });
394
- // 再转 ERC20
395
- const erc20Data = iface.encodeFunctionData('transfer', [toAddress, amountWei]);
396
- txsToSign.push({
397
- wallet: fromWallet,
398
- tx: {
399
- to: tokenAddress,
400
- data: erc20Data,
401
- value: 0n,
402
- nonce: 1, // 中转钱包的第二笔交易
403
- gasPrice,
404
- gasLimit: erc20TransferGasLimit,
405
- chainId: chainIdNum,
406
- type: txType
407
- }
408
- });
409
- }
410
- else {
411
- // 最后一个中转钱包:只转 ERC20 给最终接收者
412
- const erc20Data = iface.encodeFunctionData('transfer', [toAddress, amountWei]);
413
- txsToSign.push({
414
- wallet: fromWallet,
415
- tx: {
416
- to: tokenAddress,
417
- data: erc20Data,
418
- value: 0n,
419
- nonce: 0, // 最后一个中转钱包只有一笔交易
420
- gasPrice,
421
- gasLimit: erc20TransferGasLimit,
422
- chainId: chainIdNum,
423
- type: txType
424
- }
425
- });
426
- }
427
- }
428
- }
429
- }
430
- // ✅ 并行签名所有交易
431
- const signedTxsResult = await Promise.all(txsToSign.map(({ wallet, tx }) => wallet.signTransaction(tx)));
432
- signedTxs.push(...signedTxsResult);
433
- // ✅ 利润多跳转账(强制 2 跳中转)
434
- if (extractProfit && totalProfit > 0n) {
435
- const profitNonce = allMainNonces[mainNonceIdx];
436
- const profitHopResult = await buildProfitHopTransactions({
437
- provider,
438
- payerWallet: mainWallet,
439
- profitAmount: totalProfit,
440
- profitRecipient: profitAddr,
441
- hopCount: PROFIT_HOP_COUNT,
442
- gasPrice,
443
- chainId: chainIdNum,
444
- txType,
445
- startNonce: profitNonce
446
- });
447
- signedTxs.push(...profitHopResult.signedTransactions);
448
- profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
449
- }
450
- }
451
- // ✅ 简化返回:只返回签名交易、多跳钱包和元数据
452
- return {
453
- signedTransactions: signedTxs,
454
- hopWallets: preparedHops || undefined,
455
- profitHopWallets, // ✅ 返回利润多跳钱包
456
- metadata: extractProfit ? {
457
- totalAmount: ethers.formatEther(totalAmountBeforeProfit),
458
- profitAmount: ethers.formatEther(totalProfit),
459
- profitRecipient: profitAddr,
460
- recipientCount: recipients.length,
461
- isNative,
462
- tokenAddress: isNative ? undefined : tokenAddress
463
- } : undefined
464
- };
465
- }
466
- /**
467
- * 归集(仅签名版本 - 不依赖 Merkle)
468
- * ✅ 精简版:只负责签名交易,不提交到 Merkle
469
- * ✅ 优化版:支持 startNonce 参数避免并行调用时的 nonce 冲突
470
- */
@@ -1,7 +0,0 @@
1
- import { PairwiseTransferSignParams, PairwiseTransferMerkleResult } from './types.js';
2
- /**
3
- * 分发(仅签名版本 - 不依赖 Merkle)
4
- * ✅ 精简版:只负责签名交易,不提交到 Merkle
5
- * ✅ 优化版:支持 startNonce 参数避免并行调用时的 nonce 冲突
6
- */
7
- export declare function pairwiseTransferWithBundleMerkle(params: PairwiseTransferSignParams): Promise<PairwiseTransferMerkleResult>;