four-flap-meme-sdk 2.2.0 → 2.2.2

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 (467) hide show
  1. package/README.en.md +6 -41
  2. package/README.md +0 -31
  3. package/README.zh-CN.md +6 -41
  4. package/dist/chains/bsc/four/approve-tokenmanager.d.ts +26 -1
  5. package/dist/chains/bsc/four/approve-tokenmanager.js +113 -1
  6. package/dist/chains/bsc/four/config.d.ts +67 -5
  7. package/dist/chains/bsc/four/config.js +114 -2
  8. package/dist/chains/bsc/four/core.d.ts +4 -1
  9. package/dist/chains/bsc/four/core.js +592 -1
  10. package/dist/chains/bsc/four/index.d.ts +6 -6
  11. package/dist/chains/bsc/four/index.js +6 -6
  12. package/dist/chains/bsc/four/internal.d.ts +46 -2
  13. package/dist/chains/bsc/four/internal.js +239 -2
  14. package/dist/chains/bsc/four/pancake-proxy.d.ts +28 -1
  15. package/dist/chains/bsc/four/pancake-proxy.js +687 -1
  16. package/dist/chains/bsc/four/private.d.ts +27 -1
  17. package/dist/chains/bsc/four/private.js +477 -1
  18. package/dist/chains/bsc/four/submit.d.ts +315 -2
  19. package/dist/chains/bsc/four/submit.js +752 -2
  20. package/dist/chains/bsc/four/swap-buy-first.d.ts +55 -2
  21. package/dist/chains/bsc/four/swap-buy-first.js +507 -2
  22. package/dist/chains/bsc/four/swap-internal.d.ts +3 -1
  23. package/dist/chains/bsc/four/swap-internal.js +18 -1
  24. package/dist/chains/bsc/four/swap.d.ts +144 -2
  25. package/dist/chains/bsc/four/swap.js +766 -2
  26. package/dist/chains/bsc/four/types.d.ts +476 -1
  27. package/dist/chains/bsc/four/utils.d.ts +18 -5
  28. package/dist/chains/bsc/four/utils.js +1552 -5
  29. package/dist/chains/bsc/pancake/bundle-buy-first.d.ts +91 -1
  30. package/dist/chains/bsc/pancake/bundle-buy-first.js +212 -97
  31. package/dist/chains/bsc/pancake/bundle-swap.d.ts +79 -1
  32. package/dist/chains/bsc/pancake/bundle-swap.js +726 -114
  33. package/dist/chains/bsc/pancake/index.d.ts +2 -4
  34. package/dist/chains/bsc/pancake/index.js +3 -1
  35. package/dist/chains/bsc/platforms/iro/factory.js +1 -3
  36. package/dist/chains/bsc/platforms/iro/index.d.ts +5 -5
  37. package/dist/chains/bsc/platforms/iro/index.js +3 -3
  38. package/dist/chains/bsc/platforms/iro/pool.js +10 -31
  39. package/dist/chains/bsc/platforms/iro/token.js +1 -4
  40. package/dist/chains/eni/batch-router/bundle-approve.js +3 -4
  41. package/dist/chains/eni/batch-router/transfer.js +25 -55
  42. package/dist/chains/eni/batch-router/utils.js +6 -32
  43. package/dist/chains/eni/bundler/sign.js +4 -4
  44. package/dist/chains/eni/bundler/submit.js +4 -1
  45. package/dist/chains/eni/constants.js +1 -1
  46. package/dist/chains/eni/index.d.ts +1 -2
  47. package/dist/chains/eni/index.js +0 -1
  48. package/dist/chains/eni/platforms/daoaas/create.js +2 -2
  49. package/dist/chains/eni/platforms/daoaas/index.d.ts +3 -3
  50. package/dist/chains/eni/platforms/daoaas/index.js +3 -3
  51. package/dist/chains/eni/platforms/daoaas/meta.js +4 -8
  52. package/dist/chains/eni/platforms/daoaas/portal-direct.js +44 -28
  53. package/dist/chains/eni/platforms/daoaas/portal.js +6 -10
  54. package/dist/chains/eni/platforms/dswap/liquidity.js +26 -58
  55. package/dist/chains/eni/platforms/fair-launch/index.d.ts +2 -2
  56. package/dist/chains/eni/platforms/fair-launch/index.js +1 -1
  57. package/dist/chains/eni/platforms/fair-launch/launcher.js +46 -87
  58. package/dist/chains/eni/platforms/fair-launch/pool.js +1 -4
  59. package/dist/chains/eni/platforms/fair-launch/presets.js +2 -2
  60. package/dist/chains/eni/platforms/iro/factory.js +1 -3
  61. package/dist/chains/eni/platforms/iro/index.d.ts +6 -6
  62. package/dist/chains/eni/platforms/iro/index.js +4 -4
  63. package/dist/chains/eni/platforms/iro/pool.js +26 -90
  64. package/dist/chains/eni/platforms/iro/token.js +31 -107
  65. package/dist/chains/eni/platforms/iro/whitelist.js +18 -6
  66. package/dist/chains/index.d.ts +0 -13
  67. package/dist/chains/index.js +0 -13
  68. package/dist/chains/xlayer/eip7702/bundle-approve.d.ts +26 -2
  69. package/dist/chains/xlayer/eip7702/bundle-approve.js +21 -11
  70. package/dist/chains/xlayer/eip7702/bundle-buy.d.ts +6 -2
  71. package/dist/chains/xlayer/eip7702/bundle-buy.js +51 -13
  72. package/dist/chains/xlayer/eip7702/bundle-create.js +59 -93
  73. package/dist/chains/xlayer/eip7702/bundle-sell.d.ts +6 -2
  74. package/dist/chains/xlayer/eip7702/bundle-sell.js +97 -26
  75. package/dist/chains/xlayer/eip7702/bundle-swap.d.ts +65 -3
  76. package/dist/chains/xlayer/eip7702/bundle-swap.js +245 -51
  77. package/dist/chains/xlayer/eip7702/constants.d.ts +16 -1
  78. package/dist/chains/xlayer/eip7702/constants.js +21 -3
  79. package/dist/chains/xlayer/eip7702/index.d.ts +46 -28
  80. package/dist/chains/xlayer/eip7702/index.js +81 -28
  81. package/dist/chains/xlayer/eip7702/multi-hop-transfer.d.ts +203 -2
  82. package/dist/chains/xlayer/eip7702/multi-hop-transfer.js +301 -58
  83. package/dist/chains/xlayer/eip7702/types.d.ts +0 -88
  84. package/dist/chains/xlayer/eip7702/utils.d.ts +3 -0
  85. package/dist/chains/xlayer/eip7702/utils.js +28 -23
  86. package/dist/chains/xlayer/eip7702/volume.d.ts +184 -6
  87. package/dist/chains/xlayer/eip7702/volume.js +158 -83
  88. package/dist/chains/xlayer/eoa/constants.js +1 -1
  89. package/dist/chains/xlayer/eoa/dex-helpers.js +5 -5
  90. package/dist/chains/xlayer/eoa/eoa-bundle-swap.d.ts +95 -1
  91. package/dist/chains/xlayer/eoa/eoa-bundle-swap.js +299 -66
  92. package/dist/chains/xlayer/eoa/eoa-wash-volume.d.ts +1 -1
  93. package/dist/chains/xlayer/eoa/eoa-wash-volume.js +23 -18
  94. package/dist/chains/xlayer/eoa/index.d.ts +6 -10
  95. package/dist/chains/xlayer/eoa/index.js +23 -8
  96. package/dist/chains/xlayer/eoa/portal-ops.js +2 -7
  97. package/dist/chains/xlayer/eoa/router-manager.js +3 -3
  98. package/dist/chains/xlayer/eoa/types.d.ts +2 -2
  99. package/dist/chains/xlayer/eoa/types.js +3 -1
  100. package/dist/chains/xlayer/index.d.ts +2 -3
  101. package/dist/chains/xlayer/index.js +7 -4
  102. package/dist/contracts/helper3.d.ts +5 -20
  103. package/dist/contracts/helper3.js +20 -56
  104. package/dist/contracts/tm-bundle-merkle/approve-tokenmanager.d.ts +26 -1
  105. package/dist/contracts/tm-bundle-merkle/approve-tokenmanager.js +113 -1
  106. package/dist/contracts/tm-bundle-merkle/config.d.ts +67 -5
  107. package/dist/contracts/tm-bundle-merkle/config.js +114 -2
  108. package/dist/contracts/tm-bundle-merkle/core.d.ts +4 -1
  109. package/dist/contracts/tm-bundle-merkle/core.js +591 -1
  110. package/dist/contracts/tm-bundle-merkle/index.d.ts +5 -5
  111. package/dist/contracts/tm-bundle-merkle/index.js +5 -5
  112. package/dist/contracts/tm-bundle-merkle/internal.d.ts +46 -2
  113. package/dist/contracts/tm-bundle-merkle/internal.js +238 -2
  114. package/dist/contracts/tm-bundle-merkle/pancake-proxy.d.ts +28 -1
  115. package/dist/contracts/tm-bundle-merkle/pancake-proxy.js +686 -1
  116. package/dist/contracts/tm-bundle-merkle/private.d.ts +27 -1
  117. package/dist/contracts/tm-bundle-merkle/private.js +476 -1
  118. package/dist/contracts/tm-bundle-merkle/submit.d.ts +314 -3
  119. package/dist/contracts/tm-bundle-merkle/submit.js +928 -3
  120. package/dist/contracts/tm-bundle-merkle/swap-buy-first.d.ts +55 -2
  121. package/dist/contracts/tm-bundle-merkle/swap-buy-first.js +506 -2
  122. package/dist/contracts/tm-bundle-merkle/swap-internal.d.ts +3 -1
  123. package/dist/contracts/tm-bundle-merkle/swap-internal.js +18 -1
  124. package/dist/contracts/tm-bundle-merkle/swap.d.ts +144 -2
  125. package/dist/contracts/tm-bundle-merkle/swap.js +764 -2
  126. package/dist/contracts/tm-bundle-merkle/types.d.ts +476 -1
  127. package/dist/contracts/tm-bundle-merkle/utils.d.ts +18 -6
  128. package/dist/contracts/tm-bundle-merkle/utils.js +1501 -6
  129. package/dist/contracts/tm-bundle.d.ts +51 -3
  130. package/dist/contracts/tm-bundle.js +177 -108
  131. package/dist/contracts/tm.d.ts +2 -3
  132. package/dist/contracts/tm.js +32 -37
  133. package/dist/contracts/tm1.js +4 -9
  134. package/dist/contracts/tm2.js +4 -9
  135. package/dist/dex/direct-router.d.ts +125 -3
  136. package/dist/dex/direct-router.js +666 -237
  137. package/dist/flows/create.d.ts +1 -2
  138. package/dist/flows/create.js +6 -6
  139. package/dist/index.d.ts +85 -20
  140. package/dist/index.js +215 -20
  141. package/dist/shared/abis/TaxToken.json +105 -0
  142. package/dist/shared/abis/TokenManager2.json +60 -0
  143. package/dist/shared/abis/common.d.ts +83 -2
  144. package/dist/shared/abis/common.js +252 -2
  145. package/dist/shared/abis/index.d.ts +6 -5
  146. package/dist/shared/abis/index.js +7 -5
  147. package/dist/shared/clients/blockrazor.js +25 -39
  148. package/dist/shared/clients/club48.d.ts +2 -2
  149. package/dist/shared/clients/club48.js +29 -34
  150. package/dist/shared/clients/emitservice.js +0 -2
  151. package/dist/shared/clients/four.d.ts +5 -5
  152. package/dist/shared/clients/four.js +17 -21
  153. package/dist/shared/clients/merkle.js +34 -27
  154. package/dist/shared/constants/addresses.d.ts +1 -1
  155. package/dist/shared/constants/addresses.js +2 -11
  156. package/dist/shared/constants/chains.d.ts +1 -1
  157. package/dist/shared/constants/chains.js +1 -1
  158. package/dist/shared/constants/gas.d.ts +1 -1
  159. package/dist/shared/constants/gas.js +6 -2
  160. package/dist/shared/constants/index.d.ts +0 -3
  161. package/dist/shared/constants/index.js +0 -1
  162. package/dist/shared/flap/abi.js +1 -1
  163. package/dist/shared/flap/constants.d.ts +2 -1
  164. package/dist/shared/flap/constants.js +3 -2
  165. package/dist/shared/flap/curve.js +0 -3
  166. package/dist/shared/flap/errors.d.ts +4 -1
  167. package/dist/shared/flap/errors.js +1 -20
  168. package/dist/shared/flap/index.d.ts +3 -3
  169. package/dist/shared/flap/index.js +3 -3
  170. package/dist/shared/flap/meta.d.ts +18 -16
  171. package/dist/shared/flap/meta.js +17 -12
  172. package/dist/shared/flap/permit.js +2 -5
  173. package/dist/shared/flap/pinata.d.ts +4 -11
  174. package/dist/shared/flap/pinata.js +16 -21
  175. package/dist/shared/flap/portal-bundle-merkle/config.d.ts +72 -3
  176. package/dist/shared/flap/portal-bundle-merkle/config.js +124 -4
  177. package/dist/shared/flap/portal-bundle-merkle/core.d.ts +4 -0
  178. package/dist/shared/flap/portal-bundle-merkle/core.js +172 -92
  179. package/dist/shared/flap/portal-bundle-merkle/create-to-dex.js +99 -106
  180. package/dist/shared/flap/portal-bundle-merkle/curve-to-dex.js +92 -100
  181. package/dist/shared/flap/portal-bundle-merkle/index.d.ts +7 -11
  182. package/dist/shared/flap/portal-bundle-merkle/index.js +7 -4
  183. package/dist/shared/flap/portal-bundle-merkle/pancake-proxy.js +68 -71
  184. package/dist/shared/flap/portal-bundle-merkle/private.js +114 -61
  185. package/dist/shared/flap/portal-bundle-merkle/swap-buy-first.d.ts +64 -1
  186. package/dist/shared/flap/portal-bundle-merkle/swap-buy-first.js +247 -66
  187. package/dist/shared/flap/portal-bundle-merkle/swap.d.ts +71 -2
  188. package/dist/shared/flap/portal-bundle-merkle/swap.js +410 -103
  189. package/dist/shared/flap/portal-bundle-merkle/types.d.ts +7 -73
  190. package/dist/shared/flap/portal-bundle-merkle/utils.d.ts +80 -1
  191. package/dist/shared/flap/portal-bundle-merkle/utils.js +265 -145
  192. package/dist/shared/flap/portal-bundle.js +56 -55
  193. package/dist/shared/flap/portal.d.ts +3 -1
  194. package/dist/shared/flap/portal.js +25 -32
  195. package/dist/shared/flap/vanity.d.ts +5 -1
  196. package/dist/shared/flap/vanity.js +17 -6
  197. package/dist/shared/flap/vault.d.ts +124 -17
  198. package/dist/shared/flap/vault.js +148 -67
  199. package/dist/shared/four/tax-token.d.ts +1 -1
  200. package/dist/shared/four/tax-token.js +7 -27
  201. package/dist/shared/index.d.ts +0 -6
  202. package/dist/shared/index.js +0 -4
  203. package/dist/utils/airdrop-sweep.d.ts +76 -4
  204. package/dist/utils/airdrop-sweep.js +54 -40
  205. package/dist/utils/bundle-helpers.d.ts +243 -9
  206. package/dist/utils/bundle-helpers.js +584 -10
  207. package/dist/utils/constants.d.ts +61 -5
  208. package/dist/utils/constants.js +80 -5
  209. package/dist/utils/contract-factory.d.ts +4 -2
  210. package/dist/utils/contract-factory.js +18 -25
  211. package/dist/utils/erc20.d.ts +89 -7
  212. package/dist/utils/erc20.js +125 -94
  213. package/dist/utils/errors.d.ts +1 -12
  214. package/dist/utils/errors.js +1 -60
  215. package/dist/utils/holders-maker.d.ts +138 -2
  216. package/dist/utils/holders-maker.js +661 -26
  217. package/dist/utils/lp-inspect.d.ts +112 -2
  218. package/dist/utils/lp-inspect.js +223 -73
  219. package/dist/utils/mpcExclusive.d.ts +5 -2
  220. package/dist/utils/mpcExclusive.js +3 -4
  221. package/dist/utils/private-sale.d.ts +58 -2
  222. package/dist/utils/private-sale.js +15 -4
  223. package/dist/utils/provider-factory.d.ts +0 -4
  224. package/dist/utils/provider-factory.js +0 -10
  225. package/dist/utils/quote-helpers.d.ts +45 -4
  226. package/dist/utils/quote-helpers.js +74 -17
  227. package/dist/utils/stealth-transfer.d.ts +28 -2
  228. package/dist/utils/stealth-transfer.js +15 -31
  229. package/dist/utils/swap-helpers.d.ts +15 -2
  230. package/dist/utils/swap-helpers.js +10 -5
  231. package/dist/utils/wallet.d.ts +25 -2
  232. package/dist/utils/wallet.js +8 -9
  233. package/package.json +4 -159
  234. package/dist/__tests__/subpath-exports.test.d.ts +0 -1
  235. package/dist/__tests__/subpath-exports.test.js +0 -64
  236. package/dist/abis/common.d.ts +0 -85
  237. package/dist/abis/common.js +0 -260
  238. package/dist/abis/contracts/TaxToken.json +0 -969
  239. package/dist/abis/contracts/TokenManager2.json +0 -136
  240. package/dist/abis/contracts/index.d.ts +0 -5
  241. package/dist/abis/contracts/index.js +0 -5
  242. package/dist/abis/flap/index.d.ts +0 -3
  243. package/dist/abis/flap/index.js +0 -3
  244. package/dist/abis/flap/portal-events.d.ts +0 -6
  245. package/dist/abis/flap/portal-events.js +0 -17
  246. package/dist/abis/flap/portal.d.ts +0 -6
  247. package/dist/abis/flap/portal.js +0 -37
  248. package/dist/abis/flap/vault.d.ts +0 -171
  249. package/dist/abis/flap/vault.js +0 -91
  250. package/dist/abis/index.d.ts +0 -8
  251. package/dist/abis/index.js +0 -11
  252. package/dist/bundle-core/__tests__/config-helpers.test.d.ts +0 -1
  253. package/dist/bundle-core/__tests__/config-helpers.test.js +0 -28
  254. package/dist/bundle-core/__tests__/facade-parity.test.d.ts +0 -1
  255. package/dist/bundle-core/__tests__/facade-parity.test.js +0 -33
  256. package/dist/bundle-core/__tests__/sign-context-helpers.test.d.ts +0 -1
  257. package/dist/bundle-core/__tests__/sign-context-helpers.test.js +0 -60
  258. package/dist/bundle-core/__tests__/sign-fixture.test.d.ts +0 -1
  259. package/dist/bundle-core/__tests__/sign-fixture.test.js +0 -220
  260. package/dist/bundle-core/__tests__/sign-fixtures.d.ts +0 -10
  261. package/dist/bundle-core/__tests__/sign-fixtures.js +0 -16
  262. package/dist/bundle-core/config-helpers.d.ts +0 -36
  263. package/dist/bundle-core/config-helpers.js +0 -57
  264. package/dist/bundle-core/errors.d.ts +0 -50
  265. package/dist/bundle-core/errors.js +0 -34
  266. package/dist/bundle-core/four-meme/approve-tokenmanager.d.ts +0 -7
  267. package/dist/bundle-core/four-meme/approve-tokenmanager.js +0 -99
  268. package/dist/bundle-core/four-meme/core-helpers.d.ts +0 -8
  269. package/dist/bundle-core/four-meme/core-helpers.js +0 -40
  270. package/dist/bundle-core/four-meme/core.d.ts +0 -4
  271. package/dist/bundle-core/four-meme/core.js +0 -515
  272. package/dist/bundle-core/four-meme/pancake-proxy.d.ts +0 -28
  273. package/dist/bundle-core/four-meme/pancake-proxy.js +0 -679
  274. package/dist/bundle-core/four-meme/private.d.ts +0 -27
  275. package/dist/bundle-core/four-meme/private.js +0 -465
  276. package/dist/bundle-core/four-meme/sign-context-helpers.d.ts +0 -2
  277. package/dist/bundle-core/four-meme/sign-context-helpers.js +0 -2
  278. package/dist/bundle-core/four-meme/swap-buy-first.d.ts +0 -8
  279. package/dist/bundle-core/four-meme/swap-buy-first.js +0 -493
  280. package/dist/bundle-core/four-meme/swap-hop-helpers.d.ts +0 -6
  281. package/dist/bundle-core/four-meme/swap-hop-helpers.js +0 -63
  282. package/dist/bundle-core/four-meme/swap-internal.d.ts +0 -3
  283. package/dist/bundle-core/four-meme/swap-internal.js +0 -18
  284. package/dist/bundle-core/four-meme/swap-sign-helpers.d.ts +0 -27
  285. package/dist/bundle-core/four-meme/swap-sign-helpers.js +0 -105
  286. package/dist/bundle-core/four-meme/swap.d.ts +0 -17
  287. package/dist/bundle-core/four-meme/swap.js +0 -505
  288. package/dist/bundle-core/four-meme/types/buy-first.d.ts +0 -50
  289. package/dist/bundle-core/four-meme/types/buy-first.js +0 -1
  290. package/dist/bundle-core/four-meme/types/core-flow.d.ts +0 -63
  291. package/dist/bundle-core/four-meme/types/core-flow.js +0 -1
  292. package/dist/bundle-core/four-meme/types/index.d.ts +0 -600
  293. package/dist/bundle-core/four-meme/types/index.js +0 -1
  294. package/dist/bundle-core/four-meme/types/swap-internal.d.ts +0 -19
  295. package/dist/bundle-core/four-meme/types/swap-internal.js +0 -1
  296. package/dist/bundle-core/four-meme/types.d.ts +0 -1
  297. package/dist/bundle-core/four-meme/types.js +0 -1
  298. package/dist/bundle-core/four-meme/utils-disperse.d.ts +0 -7
  299. package/dist/bundle-core/four-meme/utils-disperse.js +0 -396
  300. package/dist/bundle-core/four-meme/utils-pairwise.d.ts +0 -8
  301. package/dist/bundle-core/four-meme/utils-pairwise.js +0 -328
  302. package/dist/bundle-core/four-meme/utils-sweep.d.ts +0 -8
  303. package/dist/bundle-core/four-meme/utils-sweep.js +0 -744
  304. package/dist/bundle-core/index.d.ts +0 -8
  305. package/dist/bundle-core/index.js +0 -8
  306. package/dist/bundle-core/internal.d.ts +0 -21
  307. package/dist/bundle-core/internal.js +0 -182
  308. package/dist/bundle-core/sign-context-helpers.d.ts +0 -25
  309. package/dist/bundle-core/sign-context-helpers.js +0 -67
  310. package/dist/bundle-core/submit.d.ts +0 -293
  311. package/dist/bundle-core/submit.js +0 -727
  312. package/dist/bundle-core/types/index.d.ts +0 -8
  313. package/dist/bundle-core/types/index.js +0 -1
  314. package/dist/bundle-core/types.d.ts +0 -1
  315. package/dist/bundle-core/types.js +0 -1
  316. package/dist/chains/bsc/four/utils-disperse.d.ts +0 -1
  317. package/dist/chains/bsc/four/utils-disperse.js +0 -1
  318. package/dist/chains/bsc/four/utils-pairwise.d.ts +0 -1
  319. package/dist/chains/bsc/four/utils-pairwise.js +0 -1
  320. package/dist/chains/bsc/four/utils-sweep.d.ts +0 -1
  321. package/dist/chains/bsc/four/utils-sweep.js +0 -1
  322. package/dist/chains/bsc/iro.d.ts +0 -5
  323. package/dist/chains/bsc/iro.js +0 -4
  324. package/dist/chains/bsc/pancake/bundle-buy-first-helpers.d.ts +0 -159
  325. package/dist/chains/bsc/pancake/bundle-buy-first-helpers.js +0 -117
  326. package/dist/chains/bsc/pancake/bundle-swap-helpers.d.ts +0 -241
  327. package/dist/chains/bsc/pancake/bundle-swap-helpers.js +0 -565
  328. package/dist/chains/eni/flat-aliases.d.ts +0 -10
  329. package/dist/chains/eni/flat-aliases.js +0 -8
  330. package/dist/chains/eni/submit.d.ts +0 -43
  331. package/dist/chains/eni/submit.js +0 -286
  332. package/dist/chains/xlayer/eip7702/flat-aliases.d.ts +0 -13
  333. package/dist/chains/xlayer/eip7702/flat-aliases.js +0 -10
  334. package/dist/chains/xlayer/eip7702/multi-hop-transfer-helpers.d.ts +0 -79
  335. package/dist/chains/xlayer/eip7702/multi-hop-transfer-helpers.js +0 -1
  336. package/dist/chains/xlayer/eip7702/transfer-context-helpers.d.ts +0 -26
  337. package/dist/chains/xlayer/eip7702/transfer-context-helpers.js +0 -57
  338. package/dist/chains/xlayer/eip7702/volume-helpers.d.ts +0 -148
  339. package/dist/chains/xlayer/eip7702/volume-helpers.js +0 -48
  340. package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.d.ts +0 -126
  341. package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.js +0 -228
  342. package/dist/contracts/tm-bundle-helpers.d.ts +0 -88
  343. package/dist/contracts/tm-bundle-helpers.js +0 -72
  344. package/dist/contracts/tm-bundle-merkle/utils-disperse.d.ts +0 -1
  345. package/dist/contracts/tm-bundle-merkle/utils-disperse.js +0 -1
  346. package/dist/contracts/tm-bundle-merkle/utils-pairwise.d.ts +0 -1
  347. package/dist/contracts/tm-bundle-merkle/utils-pairwise.js +0 -1
  348. package/dist/contracts/tm-bundle-merkle/utils-sweep.d.ts +0 -1
  349. package/dist/contracts/tm-bundle-merkle/utils-sweep.js +0 -1
  350. package/dist/dex/direct-router-helpers.d.ts +0 -264
  351. package/dist/dex/direct-router-helpers.js +0 -539
  352. package/dist/dex/types.d.ts +0 -81
  353. package/dist/dex/types.js +0 -1
  354. package/dist/exports/root-bundle-and-tooling.d.ts +0 -27
  355. package/dist/exports/root-bundle-and-tooling.js +0 -30
  356. package/dist/exports/root-eni-and-bsc-iro.d.ts +0 -26
  357. package/dist/exports/root-eni-and-bsc-iro.js +0 -66
  358. package/dist/exports/root-foundations.d.ts +0 -35
  359. package/dist/exports/root-foundations.js +0 -70
  360. package/dist/exports/root-swap-dex-and-xlayer.d.ts +0 -30
  361. package/dist/exports/root-swap-dex-and-xlayer.js +0 -78
  362. package/dist/flap/index.d.ts +0 -10
  363. package/dist/flap/index.js +0 -8
  364. package/dist/flows/index.d.ts +0 -1
  365. package/dist/flows/index.js +0 -1
  366. package/dist/merkle/index.d.ts +0 -12
  367. package/dist/merkle/index.js +0 -11
  368. package/dist/shared/clients/index.d.ts +0 -8
  369. package/dist/shared/clients/index.js +0 -8
  370. package/dist/shared/constants/quote.d.ts +0 -30
  371. package/dist/shared/constants/quote.js +0 -37
  372. package/dist/shared/flap/portal-bundle-merkle/core-helpers.d.ts +0 -32
  373. package/dist/shared/flap/portal-bundle-merkle/core-helpers.js +0 -83
  374. package/dist/shared/flap/portal-bundle-merkle/swap-buy-first-helpers.d.ts +0 -125
  375. package/dist/shared/flap/portal-bundle-merkle/swap-buy-first-helpers.js +0 -113
  376. package/dist/shared/flap/portal-bundle-merkle/swap-helpers.d.ts +0 -149
  377. package/dist/shared/flap/portal-bundle-merkle/swap-helpers.js +0 -259
  378. package/dist/shared/foundation/dex/v3-path.d.ts +0 -6
  379. package/dist/shared/foundation/dex/v3-path.js +0 -35
  380. package/dist/shared/foundation/gas/bundle-gas.d.ts +0 -39
  381. package/dist/shared/foundation/gas/bundle-gas.js +0 -93
  382. package/dist/shared/foundation/gas/profit-hop.d.ts +0 -20
  383. package/dist/shared/foundation/gas/profit-hop.js +0 -72
  384. package/dist/shared/foundation/index.d.ts +0 -13
  385. package/dist/shared/foundation/index.js +0 -12
  386. package/dist/shared/foundation/nonce/nonce-manager.d.ts +0 -17
  387. package/dist/shared/foundation/nonce/nonce-manager.js +0 -180
  388. package/dist/shared/foundation/normalize-unknown.d.ts +0 -9
  389. package/dist/shared/foundation/normalize-unknown.js +0 -29
  390. package/dist/shared/foundation/sdk-logger.d.ts +0 -13
  391. package/dist/shared/foundation/sdk-logger.js +0 -12
  392. package/dist/shared/foundation/tx/build-request.d.ts +0 -17
  393. package/dist/shared/foundation/tx/build-request.js +0 -25
  394. package/dist/shared/foundation/tx/sign-batch.d.ts +0 -5
  395. package/dist/shared/foundation/tx/sign-batch.js +0 -26
  396. package/dist/shared/foundation/tx/wallet-sign-patch.d.ts +0 -1
  397. package/dist/shared/foundation/tx/wallet-sign-patch.js +0 -18
  398. package/dist/shared/foundation/types/airdrop-sweep.d.ts +0 -79
  399. package/dist/shared/foundation/types/airdrop-sweep.js +0 -1
  400. package/dist/shared/foundation/types/erc20.d.ts +0 -65
  401. package/dist/shared/foundation/types/erc20.js +0 -1
  402. package/dist/shared/foundation/types/holders-maker.d.ts +0 -64
  403. package/dist/shared/foundation/types/holders-maker.js +0 -1
  404. package/dist/shared/foundation/types/index.d.ts +0 -7
  405. package/dist/shared/foundation/types/index.js +0 -1
  406. package/dist/shared/foundation/types/lp-inspect.d.ts +0 -102
  407. package/dist/shared/foundation/types/lp-inspect.js +0 -1
  408. package/dist/shared/foundation/types/multicall.d.ts +0 -5
  409. package/dist/shared/foundation/types/multicall.js +0 -1
  410. package/dist/shared/foundation/types/private-sale.d.ts +0 -35
  411. package/dist/shared/foundation/types/private-sale.js +0 -1
  412. package/dist/shared/foundation/types/quote-helpers.d.ts +0 -17
  413. package/dist/shared/foundation/types/quote-helpers.js +0 -1
  414. package/dist/types/errors.d.ts +0 -27
  415. package/dist/types/errors.js +0 -34
  416. package/dist/utils/holders-maker/addresses.d.ts +0 -12
  417. package/dist/utils/holders-maker/addresses.js +0 -15
  418. package/dist/utils/holders-maker/buy-tx.d.ts +0 -44
  419. package/dist/utils/holders-maker/buy-tx.js +0 -278
  420. package/dist/utils/holders-maker/constants.d.ts +0 -6
  421. package/dist/utils/holders-maker/constants.js +0 -7
  422. package/dist/utils/holders-maker/disperse.d.ts +0 -18
  423. package/dist/utils/holders-maker/disperse.js +0 -90
  424. package/dist/utils/holders-maker/routing.d.ts +0 -4
  425. package/dist/utils/holders-maker/routing.js +0 -45
  426. package/dist/utils/holders-maker/transfer-tx.d.ts +0 -4
  427. package/dist/utils/holders-maker/transfer-tx.js +0 -67
  428. package/dist/utils/holders-maker-helpers.d.ts +0 -9
  429. package/dist/utils/holders-maker-helpers.js +0 -9
  430. package/dist/utils/hop-chains.d.ts +0 -35
  431. package/dist/utils/hop-chains.js +0 -215
  432. package/dist/utils/lp-inspect-helpers.d.ts +0 -9
  433. package/dist/utils/lp-inspect-helpers.js +0 -109
  434. package/dist/utils/types/airdrop-sweep.d.ts +0 -1
  435. package/dist/utils/types/airdrop-sweep.js +0 -1
  436. package/dist/utils/types/contract-factory.d.ts +0 -1
  437. package/dist/utils/types/contract-factory.js +0 -1
  438. package/dist/utils/types/erc20.d.ts +0 -1
  439. package/dist/utils/types/erc20.js +0 -1
  440. package/dist/utils/types/errors.d.ts +0 -1
  441. package/dist/utils/types/errors.js +0 -1
  442. package/dist/utils/types/holders-maker.d.ts +0 -1
  443. package/dist/utils/types/holders-maker.js +0 -1
  444. package/dist/utils/types/hop-chains.d.ts +0 -8
  445. package/dist/utils/types/hop-chains.js +0 -1
  446. package/dist/utils/types/index.d.ts +0 -13
  447. package/dist/utils/types/index.js +0 -1
  448. package/dist/utils/types/lp-inspect.d.ts +0 -1
  449. package/dist/utils/types/lp-inspect.js +0 -1
  450. package/dist/utils/types/mpc-exclusive.d.ts +0 -5
  451. package/dist/utils/types/mpc-exclusive.js +0 -1
  452. package/dist/utils/types/private-sale.d.ts +0 -1
  453. package/dist/utils/types/private-sale.js +0 -1
  454. package/dist/utils/types/quote-helpers.d.ts +0 -1
  455. package/dist/utils/types/quote-helpers.js +0 -1
  456. package/dist/utils/types/stealth-transfer.d.ts +0 -44
  457. package/dist/utils/types/stealth-transfer.js +0 -1
  458. package/dist/utils/types/wallet.d.ts +0 -25
  459. package/dist/utils/types/wallet.js +0 -1
  460. package/dist/vanity/index.d.ts +0 -5
  461. package/dist/vanity/index.js +0 -5
  462. package/src/abis/contracts/TaxToken.json +0 -969
  463. package/src/abis/contracts/TokenManager.json +0 -836
  464. package/src/abis/contracts/TokenManager2.json +0 -136
  465. package/src/abis/contracts/TokenManagerHelper3.json +0 -993
  466. /package/dist/{abis/contracts → shared/abis}/TokenManager.json +0 -0
  467. /package/dist/{abis/contracts → shared/abis}/TokenManagerHelper3.json +0 -0
@@ -1,4 +1,766 @@
1
1
  /**
2
- * TM-Merkle Four.meme 内盘捆绑换手 — 实现见 bundle-core/four-meme/
2
+ * Four.meme 内盘捆绑换手(Merkle Bundle)
3
+ *
4
+ * 功能:钱包A卖出代币 → 钱包B买入相同数量 → 原子执行
3
5
  */
4
- export { fourBundleSwapMerkle, fourBatchSwapMerkle, fourQuickBatchSwapMerkle, } from '../../bundle-core/four-meme/swap.js';
6
+ import { ethers, Contract, Wallet } from 'ethers';
7
+ import { calculateSellAmount } from '../../utils/swap-helpers.js';
8
+ import { NonceManager, getOptimizedGasPrice, getGasLimit, getGasPriceConfig, getTxType, buildProfitHopTransactions, PROFIT_HOP_COUNT } from '../../utils/bundle-helpers.js';
9
+ import { ADDRESSES, PROFIT_CONFIG, BLOCKRAZOR_BUILDER_EOA } from '../../utils/constants.js';
10
+ /**
11
+ * 根据 userType 计算利润率
12
+ */
13
+ function getProfitRateBps(userType) {
14
+ if (userType === 'v0') {
15
+ return PROFIT_CONFIG.RATE_BPS_V0; // 0.06%
16
+ }
17
+ else if (userType === 'v1') {
18
+ return PROFIT_CONFIG.RATE_BPS_V1; // 0.05%
19
+ }
20
+ return PROFIT_CONFIG.RATE_BPS_V0; // 默认 0.06%
21
+ }
22
+ import { TM_ABI, HELPER3_ABI, TM_ADDRESS } from './swap-internal.js';
23
+ import { getBribeAmount, getProfitRecipient } from './config.js';
24
+ import { generateWallets } from '../../utils/wallet.js';
25
+ // ==================== 多跳转账常量 ====================
26
+ const NATIVE_TRANSFER_GAS_LIMIT = 21055n;
27
+ /**
28
+ * 生成分发多跳路径
29
+ */
30
+ function generateDisperseHopPaths(targetAddresses, hopCount, provider) {
31
+ if (hopCount <= 0) {
32
+ return targetAddresses.map(addr => ({
33
+ targetAddress: addr,
34
+ hopWallets: [],
35
+ hopWalletsInfo: []
36
+ }));
37
+ }
38
+ return targetAddresses.map(targetAddress => {
39
+ const hopWalletsInfo = generateWallets(hopCount);
40
+ const hopWallets = hopWalletsInfo.map(w => new Wallet(w.privateKey, provider));
41
+ return { targetAddress, hopWallets, hopWalletsInfo };
42
+ });
43
+ }
44
+ /**
45
+ * 构建原生代币多跳转账链
46
+ */
47
+ async function buildNativeHopChain(payer, path, finalAmount, gasPrice, chainId, txType, payerNonce) {
48
+ const signedTxs = [];
49
+ const hopCount = path.hopWallets.length;
50
+ if (hopCount === 0) {
51
+ const tx = {
52
+ to: path.targetAddress,
53
+ value: finalAmount,
54
+ nonce: payerNonce,
55
+ gasLimit: NATIVE_TRANSFER_GAS_LIMIT,
56
+ gasPrice,
57
+ chainId,
58
+ type: txType
59
+ };
60
+ signedTxs.push(await payer.signTransaction(tx));
61
+ return signedTxs;
62
+ }
63
+ const hopGasCost = NATIVE_TRANSFER_GAS_LIMIT * gasPrice;
64
+ // 计算每跳需要的金额
65
+ const amountsPerHop = [];
66
+ for (let i = 0; i < hopCount; i++) {
67
+ const remainingHops = hopCount - i;
68
+ amountsPerHop.push(finalAmount + hopGasCost * BigInt(remainingHops));
69
+ }
70
+ // payer → hop1
71
+ signedTxs.push(await payer.signTransaction({
72
+ to: path.hopWallets[0].address,
73
+ value: amountsPerHop[0],
74
+ nonce: payerNonce,
75
+ gasLimit: NATIVE_TRANSFER_GAS_LIMIT,
76
+ gasPrice,
77
+ chainId,
78
+ type: txType
79
+ }));
80
+ // hop1 → hop2 → ... → target
81
+ for (let i = 0; i < hopCount; i++) {
82
+ const fromWallet = path.hopWallets[i];
83
+ const toAddress = i === hopCount - 1 ? path.targetAddress : path.hopWallets[i + 1].address;
84
+ const amount = i === hopCount - 1 ? finalAmount : amountsPerHop[i + 1];
85
+ signedTxs.push(await fromWallet.signTransaction({
86
+ to: toAddress,
87
+ value: amount,
88
+ nonce: 0,
89
+ gasLimit: NATIVE_TRANSFER_GAS_LIMIT,
90
+ gasPrice,
91
+ chainId,
92
+ type: txType
93
+ }));
94
+ }
95
+ return signedTxs;
96
+ }
97
+ /**
98
+ * Four内盘捆绑换手
99
+ */
100
+ export async function fourBundleSwapMerkle(params) {
101
+ const { sellerPrivateKey, sellAmount, sellPercentage, buyerPrivateKey, tokenAddress, config, startNonces // ✅ 可选:前端预获取的 nonces
102
+ } = params;
103
+ const chainIdNum = config.chainId ?? 56;
104
+ const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
105
+ chainId: chainIdNum,
106
+ name: 'BSC'
107
+ });
108
+ const seller = new Wallet(sellerPrivateKey, provider);
109
+ const buyer = new Wallet(buyerPrivateKey, provider);
110
+ const nonceManager = new NonceManager(provider);
111
+ // ✅ 创建适配的配置对象
112
+ const bundleConfig = {
113
+ minGasPriceGwei: config.minGasPriceGwei,
114
+ maxGasPriceGwei: config.maxGasPriceGwei,
115
+ gasLimit: typeof config.gasLimit === 'bigint' ? Number(config.gasLimit) : config.gasLimit,
116
+ gasLimitMultiplier: config.gasLimitMultiplier,
117
+ txType: config.txType,
118
+ chainId: config.chainId
119
+ };
120
+ const finalGasLimit = getGasLimit(bundleConfig);
121
+ const txType = getTxType(bundleConfig);
122
+ // ✅ 优化:第一批并行 - calculateSellAmount、gasPrice
123
+ const [sellAmountResult, gasPrice] = await Promise.all([
124
+ calculateSellAmount(provider, tokenAddress, seller.address, sellAmount, sellPercentage),
125
+ getOptimizedGasPrice(provider, getGasPriceConfig(bundleConfig))
126
+ ]);
127
+ const { amount: sellAmountWei, decimals } = sellAmountResult;
128
+ // ✅ 优化:第二批并行 - sellQuote、allowance、buyerBalance
129
+ const helper3 = new Contract(ADDRESSES.BSC.TokenManagerHelper3, HELPER3_ABI, provider);
130
+ const erc20Contract = new Contract(tokenAddress, ['function allowance(address,address) view returns (uint256)'], provider);
131
+ const [sellQuote, currentAllowance, buyerBalance] = await Promise.all([
132
+ helper3.trySell(tokenAddress, sellAmountWei),
133
+ erc20Contract.allowance(seller.address, TM_ADDRESS),
134
+ provider.getBalance(buyer.address)
135
+ ]);
136
+ const sellerWillGetBNB = sellQuote.funds;
137
+ const buyerFunds = sellerWillGetBNB;
138
+ // 验证买方余额
139
+ const reserveGas = ethers.parseEther((config.reserveGasBNB || 0.0005).toString());
140
+ const requiredBalance = buyerFunds + reserveGas;
141
+ if (buyerBalance < requiredBalance) {
142
+ throw new Error(`买方余额不足:\n` +
143
+ ` - 需要: ${ethers.formatEther(requiredBalance)} BNB\n` +
144
+ ` - 实际: ${ethers.formatEther(buyerBalance)} BNB`);
145
+ }
146
+ // 检查是否需要授权
147
+ const APPROVAL_THRESHOLD = ethers.parseUnits('1000000000', decimals);
148
+ const needApproval = currentAllowance < APPROVAL_THRESHOLD;
149
+ // 利润配置
150
+ const extractProfit = true;
151
+ const profitRateBps = getProfitRateBps(config.userType);
152
+ const profitAmount = extractProfit && sellerWillGetBNB > 0n
153
+ ? (sellerWillGetBNB * BigInt(profitRateBps)) / 10000n
154
+ : 0n;
155
+ // ✅ 获取贿赂金额
156
+ const bribeAmount = getBribeAmount(config);
157
+ const needBribeTx = bribeAmount > 0n;
158
+ // ✅ 优化:第三批并行 - 构建交易、获取 nonces
159
+ const tmSeller = new Contract(TM_ADDRESS, TM_ABI, seller);
160
+ const tmBuyer = new Contract(TM_ADDRESS, TM_ABI, buyer);
161
+ // 计算需要的 nonce 数量
162
+ let sellerNonceCount = 1; // 卖出交易
163
+ if (needBribeTx)
164
+ sellerNonceCount++; // 贿赂交易
165
+ if (needApproval)
166
+ sellerNonceCount++; // 授权交易
167
+ if (extractProfit)
168
+ sellerNonceCount++; // 利润交易
169
+ // ✅ 优化:使用批量 nonce 获取(JSON-RPC 批量请求)
170
+ // 如果前端传入了 startNonces,直接使用;否则从链上获取
171
+ const [sellUnsigned, buyUnsigned, noncesResult] = await Promise.all([
172
+ tmSeller.sellToken.populateTransaction(0n, tokenAddress, sellAmountWei, 0n),
173
+ tmBuyer.buyTokenAMAP.populateTransaction(0n, tokenAddress, buyer.address, buyerFunds, 0n, { value: buyerFunds }),
174
+ (async () => {
175
+ // ✅ 如果前端传入了 startNonces,直接使用(性能优化)
176
+ if (startNonces && startNonces.length >= 2) {
177
+ const sellerNonces = Array.from({ length: sellerNonceCount }, (_, i) => startNonces[0] + i);
178
+ const buyerNonce = startNonces[1];
179
+ return { sellerNonces, buyerNonce };
180
+ }
181
+ // 否则从链上获取
182
+ const initialNonces = await nonceManager.getNextNoncesForWallets([seller, buyer]);
183
+ const sellerNonces = Array.from({ length: sellerNonceCount }, (_, i) => initialNonces[0] + i);
184
+ const buyerNonce = initialNonces[1];
185
+ return { sellerNonces, buyerNonce };
186
+ })()
187
+ ]);
188
+ const { sellerNonces, buyerNonce } = noncesResult;
189
+ // 分配 nonces
190
+ let idx = 0;
191
+ let bribeNonce;
192
+ let approvalNonce;
193
+ if (needBribeTx)
194
+ bribeNonce = sellerNonces[idx++];
195
+ if (needApproval)
196
+ approvalNonce = sellerNonces[idx++];
197
+ const sellerNonce = sellerNonces[idx++];
198
+ const profitNonce = extractProfit ? sellerNonces[idx] : undefined;
199
+ // ✅ 并行签名所有交易
200
+ const signPromises = [];
201
+ // ✅ 贿赂交易放在首位
202
+ if (needBribeTx && bribeNonce !== undefined) {
203
+ signPromises.push(seller.signTransaction({
204
+ to: BLOCKRAZOR_BUILDER_EOA,
205
+ value: bribeAmount,
206
+ nonce: bribeNonce,
207
+ gasPrice,
208
+ gasLimit: 21000n,
209
+ chainId: chainIdNum,
210
+ type: txType
211
+ }));
212
+ }
213
+ // 授权交易
214
+ if (needApproval && approvalNonce !== undefined) {
215
+ const approveInterface = new ethers.Interface(['function approve(address,uint256) returns (bool)']);
216
+ const approveData = approveInterface.encodeFunctionData('approve', [TM_ADDRESS, ethers.MaxUint256]);
217
+ signPromises.push(seller.signTransaction({
218
+ to: tokenAddress,
219
+ data: approveData,
220
+ value: 0n,
221
+ nonce: approvalNonce,
222
+ gasLimit: 80000n,
223
+ gasPrice,
224
+ chainId: chainIdNum,
225
+ type: txType
226
+ }));
227
+ }
228
+ // 卖出和买入交易
229
+ signPromises.push(seller.signTransaction({
230
+ ...sellUnsigned,
231
+ from: seller.address,
232
+ nonce: sellerNonce,
233
+ gasLimit: finalGasLimit,
234
+ gasPrice,
235
+ chainId: chainIdNum,
236
+ type: txType
237
+ }), buyer.signTransaction({
238
+ ...buyUnsigned,
239
+ from: buyer.address,
240
+ nonce: buyerNonce,
241
+ gasLimit: finalGasLimit,
242
+ gasPrice,
243
+ chainId: chainIdNum,
244
+ type: txType,
245
+ value: buyerFunds
246
+ }));
247
+ const signedTxs = await Promise.all(signPromises);
248
+ // 解析签名结果
249
+ let signIdx = 0;
250
+ let bribeTx = null;
251
+ let approvalTx = null;
252
+ if (needBribeTx)
253
+ bribeTx = signedTxs[signIdx++];
254
+ if (needApproval)
255
+ approvalTx = signedTxs[signIdx++];
256
+ const signedSell = signedTxs[signIdx++];
257
+ const signedBuy = signedTxs[signIdx++];
258
+ nonceManager.clearTemp();
259
+ // ✅ 组装交易列表:贿赂 → 授权 → 卖出 → 买入
260
+ const allTransactions = [];
261
+ if (bribeTx)
262
+ allTransactions.push(bribeTx);
263
+ if (approvalTx)
264
+ allTransactions.push(approvalTx);
265
+ allTransactions.push(signedSell, signedBuy);
266
+ // ✅ 利润多跳转账(强制 2 跳中转)
267
+ let profitHopWallets;
268
+ if (extractProfit && profitAmount > 0n && profitNonce !== undefined) {
269
+ const profitHopResult = await buildProfitHopTransactions({
270
+ provider,
271
+ payerWallet: seller,
272
+ profitAmount: profitAmount,
273
+ profitRecipient: getProfitRecipient(),
274
+ hopCount: PROFIT_HOP_COUNT,
275
+ gasPrice,
276
+ chainId: chainIdNum,
277
+ txType,
278
+ startNonce: profitNonce
279
+ });
280
+ allTransactions.push(...profitHopResult.signedTransactions);
281
+ profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
282
+ }
283
+ return {
284
+ signedTransactions: allTransactions,
285
+ profitHopWallets, // ✅ 导出利润多跳钱包
286
+ metadata: {
287
+ sellerAddress: seller.address,
288
+ buyerAddress: buyer.address,
289
+ sellAmount: ethers.formatUnits(sellAmountWei, decimals),
290
+ buyAmount: ethers.formatEther(buyerFunds),
291
+ hasApproval: !!approvalTx,
292
+ profitAmount: extractProfit ? ethers.formatEther(profitAmount) : undefined
293
+ }
294
+ };
295
+ }
296
+ /**
297
+ * Four 内盘批量换手(一卖多买)
298
+ *
299
+ * 功能:主钱包一次卖出 → 多个子钱包同时买入 → 在同一个区块中完成
300
+ * 限制:最多 24 个买方(服务器限制 25 笔交易,包含 1 笔利润交易)
301
+ */
302
+ export async function fourBatchSwapMerkle(params) {
303
+ const { sellerPrivateKey, sellAmount, sellPercentage, buyerPrivateKeys, tokenAddress, config, startNonces // ✅ 可选:前端预获取的 nonces
304
+ } = params;
305
+ // ✅ 校验买方数量(最多 24 个)
306
+ const MAX_BUYERS = 24;
307
+ if (buyerPrivateKeys.length === 0) {
308
+ throw new Error('至少需要一个买方钱包');
309
+ }
310
+ if (buyerPrivateKeys.length > MAX_BUYERS) {
311
+ throw new Error(`买方钱包数量超过限制: ${buyerPrivateKeys.length} > ${MAX_BUYERS}`);
312
+ }
313
+ const chainIdNum = config.chainId ?? 56;
314
+ const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
315
+ chainId: chainIdNum,
316
+ name: 'BSC'
317
+ });
318
+ const seller = new Wallet(sellerPrivateKey, provider);
319
+ const buyers = buyerPrivateKeys.map(pk => new Wallet(pk, provider));
320
+ const nonceManager = new NonceManager(provider);
321
+ // 创建适配的配置对象
322
+ const bundleConfig = {
323
+ minGasPriceGwei: config.minGasPriceGwei,
324
+ maxGasPriceGwei: config.maxGasPriceGwei,
325
+ gasLimit: typeof config.gasLimit === 'bigint' ? Number(config.gasLimit) : config.gasLimit,
326
+ gasLimitMultiplier: config.gasLimitMultiplier,
327
+ txType: config.txType,
328
+ chainId: config.chainId
329
+ };
330
+ const finalGasLimit = getGasLimit(bundleConfig);
331
+ const txType = getTxType(bundleConfig);
332
+ // ✅ 并行获取:卖出数量、gasPrice
333
+ const [sellAmountResult, gasPrice] = await Promise.all([
334
+ calculateSellAmount(provider, tokenAddress, seller.address, sellAmount, sellPercentage),
335
+ getOptimizedGasPrice(provider, getGasPriceConfig(bundleConfig))
336
+ ]);
337
+ const { amount: sellAmountWei, decimals } = sellAmountResult;
338
+ // ✅ 并行获取:sellQuote、allowance、所有买方余额
339
+ const helper3 = new Contract(ADDRESSES.BSC.TokenManagerHelper3, HELPER3_ABI, provider);
340
+ const erc20Contract = new Contract(tokenAddress, ['function allowance(address,address) view returns (uint256)'], provider);
341
+ const [sellQuote, currentAllowance, ...buyerBalances] = await Promise.all([
342
+ helper3.trySell(tokenAddress, sellAmountWei),
343
+ erc20Contract.allowance(seller.address, TM_ADDRESS),
344
+ ...buyers.map(buyer => provider.getBalance(buyer.address))
345
+ ]);
346
+ const totalBuyerFunds = sellQuote.funds;
347
+ // ✅ 计算每个买方的买入金额(按比例分配)
348
+ let buyAmountsWei;
349
+ if (params.buyerRatios && params.buyerRatios.length === buyers.length) {
350
+ // 按比例分配
351
+ buyAmountsWei = params.buyerRatios.map((ratio, index) => {
352
+ const amount = (totalBuyerFunds * BigInt(Math.round(ratio * 10000))) / 10000n;
353
+ return amount;
354
+ });
355
+ }
356
+ else {
357
+ // 平均分配
358
+ const amountPerBuyer = totalBuyerFunds / BigInt(buyers.length);
359
+ buyAmountsWei = buyers.map(() => amountPerBuyer);
360
+ }
361
+ // ✅ 验证所有买方余额
362
+ const reserveGas = ethers.parseEther((config.reserveGasBNB || 0.0005).toString());
363
+ buyers.forEach((buyer, i) => {
364
+ const required = buyAmountsWei[i] + reserveGas;
365
+ if (buyerBalances[i] < required) {
366
+ throw new Error(`买方 ${i + 1} 余额不足: 需要 ${ethers.formatEther(required)} BNB, 实际 ${ethers.formatEther(buyerBalances[i])} BNB`);
367
+ }
368
+ });
369
+ // 检查是否需要授权
370
+ const APPROVAL_THRESHOLD = ethers.parseUnits('1000000000', decimals);
371
+ const needApproval = currentAllowance < APPROVAL_THRESHOLD;
372
+ // 利润配置
373
+ const profitRateBps = getProfitRateBps(config.userType);
374
+ const profitAmount = totalBuyerFunds > 0n
375
+ ? (totalBuyerFunds * BigInt(profitRateBps)) / 10000n
376
+ : 0n;
377
+ // ✅ 获取贿赂金额
378
+ const bribeAmount = getBribeAmount(config);
379
+ const needBribeTx = bribeAmount > 0n;
380
+ // ✅ 并行构建所有交易
381
+ const tmSeller = new Contract(TM_ADDRESS, TM_ABI, seller);
382
+ const [sellUnsigned, ...buyUnsignedList] = await Promise.all([
383
+ // 卖出交易
384
+ tmSeller.sellToken.populateTransaction(0n, tokenAddress, sellAmountWei, 0n),
385
+ // 所有买入交易
386
+ ...buyers.map((buyer, i) => {
387
+ const tmBuyer = new Contract(TM_ADDRESS, TM_ABI, buyer);
388
+ const buyAmount = buyAmountsWei[i];
389
+ return tmBuyer.buyTokenAMAP.populateTransaction(0n, tokenAddress, buyer.address, buyAmount, 0n, { value: buyAmount });
390
+ })
391
+ ]);
392
+ // ✅ 计算 nonce
393
+ // seller 需要的 nonce 数量
394
+ let sellerNonceCount = 1; // 卖出交易
395
+ if (needBribeTx)
396
+ sellerNonceCount++; // 贿赂交易
397
+ if (needApproval)
398
+ sellerNonceCount++; // 授权交易
399
+ sellerNonceCount++; // 利润交易
400
+ // ✅ 如果前端传入了 startNonces,直接使用(性能优化)
401
+ // 否则从链上获取
402
+ const allWallets = [seller, ...buyers];
403
+ const initialNonces = startNonces && startNonces.length >= allWallets.length
404
+ ? startNonces
405
+ : await nonceManager.getNextNoncesForWallets(allWallets);
406
+ // 分配 seller nonces
407
+ const sellerNonces = Array.from({ length: sellerNonceCount }, (_, i) => initialNonces[0] + i);
408
+ let idx = 0;
409
+ let bribeNonce;
410
+ let approvalNonce;
411
+ if (needBribeTx)
412
+ bribeNonce = sellerNonces[idx++];
413
+ if (needApproval)
414
+ approvalNonce = sellerNonces[idx++];
415
+ const sellerNonce = sellerNonces[idx++];
416
+ const profitNonce = sellerNonces[idx];
417
+ // buyer nonces
418
+ const buyerNonces = initialNonces.slice(1);
419
+ // ✅ 并行签名所有交易
420
+ const signPromises = [];
421
+ // ✅ 贿赂交易放在首位
422
+ if (needBribeTx && bribeNonce !== undefined) {
423
+ signPromises.push(seller.signTransaction({
424
+ to: BLOCKRAZOR_BUILDER_EOA,
425
+ value: bribeAmount,
426
+ nonce: bribeNonce,
427
+ gasPrice,
428
+ gasLimit: 21000n,
429
+ chainId: chainIdNum,
430
+ type: txType
431
+ }));
432
+ }
433
+ // 授权交易
434
+ if (needApproval && approvalNonce !== undefined) {
435
+ const approveInterface = new ethers.Interface(['function approve(address,uint256) returns (bool)']);
436
+ const approveData = approveInterface.encodeFunctionData('approve', [TM_ADDRESS, ethers.MaxUint256]);
437
+ signPromises.push(seller.signTransaction({
438
+ to: tokenAddress,
439
+ data: approveData,
440
+ value: 0n,
441
+ nonce: approvalNonce,
442
+ gasLimit: 80000n,
443
+ gasPrice,
444
+ chainId: chainIdNum,
445
+ type: txType
446
+ }));
447
+ }
448
+ // 卖出交易
449
+ signPromises.push(seller.signTransaction({
450
+ ...sellUnsigned,
451
+ from: seller.address,
452
+ nonce: sellerNonce,
453
+ gasLimit: finalGasLimit,
454
+ gasPrice,
455
+ chainId: chainIdNum,
456
+ type: txType
457
+ }));
458
+ // 所有买入交易
459
+ buyers.forEach((buyer, i) => {
460
+ signPromises.push(buyer.signTransaction({
461
+ ...buyUnsignedList[i],
462
+ from: buyer.address,
463
+ nonce: buyerNonces[i],
464
+ gasLimit: finalGasLimit,
465
+ gasPrice,
466
+ chainId: chainIdNum,
467
+ type: txType,
468
+ value: buyAmountsWei[i]
469
+ }));
470
+ });
471
+ const signedTxs = await Promise.all(signPromises);
472
+ // 解析签名结果
473
+ let signIdx = 0;
474
+ let bribeTx = null;
475
+ let approvalTx = null;
476
+ if (needBribeTx)
477
+ bribeTx = signedTxs[signIdx++];
478
+ if (needApproval)
479
+ approvalTx = signedTxs[signIdx++];
480
+ const signedSell = signedTxs[signIdx++];
481
+ const signedBuys = signedTxs.slice(signIdx, signIdx + buyers.length);
482
+ nonceManager.clearTemp();
483
+ // ✅ 按顺序组装交易数组:贿赂 → 授权 → 卖出 → 买入
484
+ const signedTransactions = [];
485
+ if (bribeTx)
486
+ signedTransactions.push(bribeTx);
487
+ if (approvalTx)
488
+ signedTransactions.push(approvalTx);
489
+ signedTransactions.push(signedSell);
490
+ signedTransactions.push(...signedBuys);
491
+ // ✅ 利润多跳转账(强制 2 跳中转)
492
+ let profitHopWallets;
493
+ if (profitAmount > 0n) {
494
+ const profitHopResult = await buildProfitHopTransactions({
495
+ provider,
496
+ payerWallet: seller,
497
+ profitAmount: profitAmount,
498
+ profitRecipient: getProfitRecipient(),
499
+ hopCount: PROFIT_HOP_COUNT,
500
+ gasPrice,
501
+ chainId: chainIdNum,
502
+ txType,
503
+ startNonce: profitNonce
504
+ });
505
+ signedTransactions.push(...profitHopResult.signedTransactions);
506
+ profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
507
+ }
508
+ return {
509
+ signedTransactions,
510
+ profitHopWallets, // ✅ 导出利润多跳钱包
511
+ metadata: {
512
+ sellerAddress: seller.address,
513
+ buyerAddresses: buyers.map(b => b.address),
514
+ sellAmount: ethers.formatUnits(sellAmountWei, decimals),
515
+ buyAmounts: buyAmountsWei.map(amt => ethers.formatEther(amt)),
516
+ hasApproval: !!approvalTx,
517
+ profitAmount: ethers.formatEther(profitAmount)
518
+ }
519
+ };
520
+ }
521
+ /**
522
+ * Four 内盘快捷批量换手(资金利用率模式)
523
+ *
524
+ * 流程:[贿赂] → [卖出] → [转账多跳...] → [买入1, 买入2, ...] → [利润]
525
+ *
526
+ * 特点:
527
+ * - 子钱包不需要预先有 BNB
528
+ * - 资金来自主钱包卖出代币所得
529
+ * - 提升资金利用率
530
+ * - ✅ 支持转账多跳,隐藏资金流向
531
+ *
532
+ * 限制:根据多跳数动态计算最大买方数量
533
+ */
534
+ export async function fourQuickBatchSwapMerkle(params) {
535
+ const { sellerPrivateKey, sellAmount, sellPercentage, buyerPrivateKeys, buyerRatios, buyerAmounts, tokenAddress, config, disperseHopCount = 0, // ✅ 转账多跳数(默认0=直接转账)
536
+ startNonces // ✅ 可选:前端预获取的 nonces
537
+ } = params;
538
+ // ✅ 动态计算最大买方数量(根据多跳数)
539
+ // 固定开销: 贿赂(1) + 卖出(1) + 利润多跳(PROFIT_HOP_COUNT + 1)
540
+ // 转账(N*(H+1)) + 买入(N) = N*(H+2)
541
+ const fixedOverhead = 1 + 1 + PROFIT_HOP_COUNT + 1;
542
+ const maxTxs = 50 - fixedOverhead;
543
+ let MAX_BUYERS = Math.floor(maxTxs / (disperseHopCount + 2));
544
+ MAX_BUYERS = Math.max(1, MAX_BUYERS);
545
+ console.log(`[fourQuickBatchSwapMerkle] 多跳数: ${disperseHopCount}, 最大买方数: ${MAX_BUYERS}`);
546
+ if (buyerPrivateKeys.length === 0) {
547
+ throw new Error('至少需要一个买方钱包');
548
+ }
549
+ if (buyerPrivateKeys.length > MAX_BUYERS) {
550
+ throw new Error(`资金利用率模式(${disperseHopCount}跳)买方钱包数量超过限制: ${buyerPrivateKeys.length} > ${MAX_BUYERS}`);
551
+ }
552
+ // ✅ 校验分配模式
553
+ if (!buyerRatios && !buyerAmounts) {
554
+ throw new Error('必须提供 buyerRatios 或 buyerAmounts');
555
+ }
556
+ if (buyerRatios && buyerRatios.length !== buyerPrivateKeys.length) {
557
+ throw new Error(`buyerRatios 长度 (${buyerRatios.length}) 与 buyerPrivateKeys 长度 (${buyerPrivateKeys.length}) 不匹配`);
558
+ }
559
+ if (buyerAmounts && buyerAmounts.length !== buyerPrivateKeys.length) {
560
+ throw new Error(`buyerAmounts 长度 (${buyerAmounts.length}) 与 buyerPrivateKeys 长度 (${buyerPrivateKeys.length}) 不匹配`);
561
+ }
562
+ const chainIdNum = config.chainId ?? 56;
563
+ const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
564
+ chainId: chainIdNum,
565
+ name: 'BSC'
566
+ });
567
+ const seller = new Wallet(sellerPrivateKey, provider);
568
+ const buyers = buyerPrivateKeys.map(pk => new Wallet(pk, provider));
569
+ const nonceManager = new NonceManager(provider);
570
+ // 创建适配的配置对象
571
+ const bundleConfig = {
572
+ minGasPriceGwei: config.minGasPriceGwei,
573
+ maxGasPriceGwei: config.maxGasPriceGwei,
574
+ gasLimit: typeof config.gasLimit === 'bigint' ? Number(config.gasLimit) : config.gasLimit,
575
+ gasLimitMultiplier: config.gasLimitMultiplier,
576
+ txType: config.txType,
577
+ chainId: config.chainId
578
+ };
579
+ const finalGasLimit = getGasLimit(bundleConfig);
580
+ const txType = getTxType(bundleConfig);
581
+ // ✅ 并行获取:卖出数量、gasPrice
582
+ const [sellAmountResult, gasPrice] = await Promise.all([
583
+ calculateSellAmount(provider, tokenAddress, seller.address, sellAmount, sellPercentage),
584
+ getOptimizedGasPrice(provider, getGasPriceConfig(bundleConfig))
585
+ ]);
586
+ const { amount: sellAmountWei, decimals } = sellAmountResult;
587
+ // ✅ 获取卖出报价
588
+ const helper3 = new Contract(ADDRESSES.BSC.TokenManagerHelper3, HELPER3_ABI, provider);
589
+ const sellQuote = await helper3.trySell(tokenAddress, sellAmountWei);
590
+ const estimatedBNBOut = sellQuote.funds;
591
+ console.log(`[fourQuickBatchSwapMerkle] 卖出数量: ${ethers.formatUnits(sellAmountWei, decimals)}`);
592
+ console.log(`[fourQuickBatchSwapMerkle] 预估卖出所得: ${ethers.formatEther(estimatedBNBOut)} BNB`);
593
+ // ✅ 计算利润(根据 userType 动态调整)
594
+ const profitRateBps = getProfitRateBps(config.userType);
595
+ const profitAmount = estimatedBNBOut > 0n
596
+ ? (estimatedBNBOut * BigInt(profitRateBps)) / 10000n
597
+ : 0n;
598
+ const distributableAmount = estimatedBNBOut - profitAmount;
599
+ // ✅ 计算每个买方分到的金额
600
+ let transferAmountsWei;
601
+ if (buyerAmounts && buyerAmounts.length === buyers.length) {
602
+ // 数量模式
603
+ transferAmountsWei = buyerAmounts.map(amt => ethers.parseEther(amt));
604
+ const totalTransfer = transferAmountsWei.reduce((a, b) => a + b, 0n);
605
+ if (totalTransfer > distributableAmount) {
606
+ throw new Error(`指定的买入总金额超过可分配金额 (${ethers.formatEther(distributableAmount)} BNB)`);
607
+ }
608
+ }
609
+ else if (buyerRatios && buyerRatios.length === buyers.length) {
610
+ // 比例模式
611
+ transferAmountsWei = buyerRatios.map(ratio => {
612
+ return (distributableAmount * BigInt(Math.round(ratio * 10000))) / 10000n;
613
+ });
614
+ }
615
+ else {
616
+ throw new Error('必须提供 buyerRatios 或 buyerAmounts');
617
+ }
618
+ // ✅ 获取贿赂金额
619
+ const bribeAmount = getBribeAmount(config);
620
+ // ✅ 验证主钱包余额
621
+ const sellerBalance = await seller.provider.getBalance(seller.address);
622
+ // 主钱包只需要支付:贿赂 + Gas(卖出后有 BNB 可用于转账和利润)
623
+ const sellerGasCost = gasPrice * (21000n + finalGasLimit + 21000n * BigInt(buyers.length) + 21000n);
624
+ const sellerRequired = bribeAmount + sellerGasCost;
625
+ if (sellerBalance < sellerRequired) {
626
+ throw new Error(`主钱包 BNB 余额不足: 需要约 ${ethers.formatEther(sellerRequired)} BNB (贿赂: ${ethers.formatEther(bribeAmount)}, Gas: ${ethers.formatEther(sellerGasCost)}), 实际 ${ethers.formatEther(sellerBalance)} BNB`);
627
+ }
628
+ // ==================== 规划 Nonce ====================
629
+ // ✅ 如果前端传入了 startNonces,直接使用(性能优化)
630
+ let sellerNonce = startNonces && startNonces.length > 0
631
+ ? startNonces[0]
632
+ : await nonceManager.getNextNonce(seller);
633
+ // ==================== 1. 贿赂交易 ====================
634
+ let bribeTx = null;
635
+ if (bribeAmount > 0n) {
636
+ bribeTx = await seller.signTransaction({
637
+ to: BLOCKRAZOR_BUILDER_EOA,
638
+ value: bribeAmount,
639
+ nonce: sellerNonce++,
640
+ gasPrice,
641
+ gasLimit: 21000n,
642
+ chainId: chainIdNum,
643
+ type: txType
644
+ });
645
+ console.log(`[fourQuickBatchSwapMerkle] 贿赂交易已签名`);
646
+ }
647
+ // ==================== 2. 卖出交易 ====================
648
+ const tmSeller = new Contract(TM_ADDRESS, TM_ABI, seller);
649
+ const sellUnsigned = await tmSeller.sellToken.populateTransaction(0n, tokenAddress, sellAmountWei, 0n);
650
+ const signedSell = await seller.signTransaction({
651
+ ...sellUnsigned,
652
+ from: seller.address,
653
+ nonce: sellerNonce++,
654
+ gasLimit: finalGasLimit,
655
+ gasPrice,
656
+ chainId: chainIdNum,
657
+ type: txType
658
+ });
659
+ console.log(`[fourQuickBatchSwapMerkle] 卖出交易已签名`);
660
+ // ==================== 3. 转账交易(支持多跳)====================
661
+ const reserveGas = ethers.parseEther((config.reserveGasBNB || 0.0005).toString());
662
+ const buyerGasCost = gasPrice * finalGasLimit;
663
+ // ✅ 生成多跳路径
664
+ const hopPaths = generateDisperseHopPaths(buyers.map(b => b.address), disperseHopCount, provider);
665
+ // 收集所有中间钱包信息
666
+ const allHopWallets = [];
667
+ hopPaths.forEach(path => {
668
+ allHopWallets.push(...path.hopWalletsInfo);
669
+ });
670
+ let transferTxs = [];
671
+ if (disperseHopCount === 0) {
672
+ // ✅ 无多跳:直接转账
673
+ const transferNonces = buyers.map((_, i) => sellerNonce + i);
674
+ sellerNonce += buyers.length;
675
+ transferTxs = await Promise.all(buyers.map((buyer, i) => {
676
+ const transferValue = transferAmountsWei[i] + reserveGas + buyerGasCost;
677
+ return seller.signTransaction({
678
+ to: buyer.address,
679
+ value: transferValue,
680
+ nonce: transferNonces[i],
681
+ gasPrice,
682
+ gasLimit: NATIVE_TRANSFER_GAS_LIMIT,
683
+ chainId: chainIdNum,
684
+ type: txType
685
+ });
686
+ }));
687
+ }
688
+ else {
689
+ // ✅ 有多跳:构建多跳转账链
690
+ // ✅ 修复:payer 每次只发送 1 笔交易(到第一个hop钱包),hop钱包用自己的nonce=0
691
+ const hopChains = await Promise.all(hopPaths.map((path, i) => {
692
+ const finalAmount = transferAmountsWei[i] + reserveGas + buyerGasCost;
693
+ const payerNonce = sellerNonce + i; // ✅ payer 每个 buyer 只用 1 个 nonce
694
+ return buildNativeHopChain(seller, path, finalAmount, gasPrice, chainIdNum, txType, payerNonce);
695
+ }));
696
+ transferTxs = hopChains.flat();
697
+ sellerNonce += buyers.length; // ✅ payer 只增加 buyers.length 个 nonce
698
+ }
699
+ console.log(`[fourQuickBatchSwapMerkle] ${transferTxs.length} 笔转账交易已签名 (多跳数=${disperseHopCount})`);
700
+ // ==================== 4. 买入交易 ====================
701
+ // ✅ 如果前端传入了 startNonces,使用 buyer 部分(从索引 1 开始)
702
+ const buyerNonces = startNonces && startNonces.length > 1
703
+ ? startNonces.slice(1)
704
+ : await Promise.all(buyers.map(buyer => nonceManager.getNextNonce(buyer)));
705
+ const signedBuys = await Promise.all(buyers.map(async (buyer, i) => {
706
+ const buyAmount = transferAmountsWei[i];
707
+ const tmBuyer = new Contract(TM_ADDRESS, TM_ABI, buyer);
708
+ const buyUnsigned = await tmBuyer.buyTokenAMAP.populateTransaction(0n, tokenAddress, buyer.address, buyAmount, 0n, { value: buyAmount });
709
+ return buyer.signTransaction({
710
+ ...buyUnsigned,
711
+ from: buyer.address,
712
+ nonce: buyerNonces[i],
713
+ gasLimit: finalGasLimit,
714
+ gasPrice,
715
+ chainId: chainIdNum,
716
+ type: txType,
717
+ value: buyAmount
718
+ });
719
+ }));
720
+ console.log(`[fourQuickBatchSwapMerkle] ${signedBuys.length} 笔买入交易已签名`);
721
+ nonceManager.clearTemp();
722
+ // ==================== 组装交易数组 ====================
723
+ const signedTransactions = [];
724
+ if (bribeTx)
725
+ signedTransactions.push(bribeTx);
726
+ signedTransactions.push(signedSell);
727
+ signedTransactions.push(...transferTxs);
728
+ signedTransactions.push(...signedBuys);
729
+ // ==================== 5. 利润多跳转账(强制 2 跳中转)====================
730
+ let profitHopWallets;
731
+ if (profitAmount > 0n) {
732
+ const profitHopResult = await buildProfitHopTransactions({
733
+ provider,
734
+ payerWallet: seller,
735
+ profitAmount: profitAmount,
736
+ profitRecipient: getProfitRecipient(),
737
+ hopCount: PROFIT_HOP_COUNT,
738
+ gasPrice,
739
+ chainId: chainIdNum,
740
+ txType,
741
+ startNonce: sellerNonce++
742
+ });
743
+ signedTransactions.push(...profitHopResult.signedTransactions);
744
+ profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
745
+ // 多跳交易已签名
746
+ }
747
+ console.log(`[fourQuickBatchSwapMerkle] 交易组装完成: ${signedTransactions.length} 笔`);
748
+ console.log(` - 贿赂: ${bribeTx ? 1 : 0}`);
749
+ console.log(` - 卖出: 1`);
750
+ console.log(` - 转账: ${transferTxs.length}`);
751
+ console.log(` - 买入: ${signedBuys.length}`);
752
+ return {
753
+ signedTransactions,
754
+ disperseHopWallets: allHopWallets.length > 0 ? allHopWallets : undefined, // ✅ 返回转账多跳钱包
755
+ profitHopWallets, // ✅ 返回利润多跳钱包
756
+ metadata: {
757
+ sellerAddress: seller.address,
758
+ buyerAddresses: buyers.map(b => b.address),
759
+ sellAmount: ethers.formatUnits(sellAmountWei, decimals),
760
+ estimatedBNBOut: ethers.formatEther(estimatedBNBOut),
761
+ transferAmounts: transferAmountsWei.map(amt => ethers.formatEther(amt)),
762
+ profitAmount: profitAmount > 0n ? ethers.formatEther(profitAmount) : undefined,
763
+ disperseHopCount: disperseHopCount > 0 ? disperseHopCount : undefined // ✅ 返回多跳数
764
+ }
765
+ };
766
+ }