four-flap-meme-sdk 2.2.2 → 2.2.3

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 (472) hide show
  1. package/README.en.md +41 -6
  2. package/README.md +31 -0
  3. package/README.zh-CN.md +41 -6
  4. package/dist/__tests__/subpath-exports.test.d.ts +1 -0
  5. package/dist/__tests__/subpath-exports.test.js +64 -0
  6. package/dist/abis/common.d.ts +85 -0
  7. package/dist/abis/common.js +264 -0
  8. package/dist/abis/contracts/TaxToken.json +969 -0
  9. package/dist/abis/contracts/TokenManager2.json +136 -0
  10. package/dist/abis/contracts/index.d.ts +5 -0
  11. package/dist/abis/contracts/index.js +5 -0
  12. package/dist/abis/flap/index.d.ts +3 -0
  13. package/dist/abis/flap/index.js +3 -0
  14. package/dist/abis/flap/portal-events.d.ts +6 -0
  15. package/dist/abis/flap/portal-events.js +17 -0
  16. package/dist/abis/flap/portal.d.ts +6 -0
  17. package/dist/abis/flap/portal.js +37 -0
  18. package/dist/abis/flap/vault.d.ts +171 -0
  19. package/dist/abis/flap/vault.js +91 -0
  20. package/dist/abis/index.d.ts +8 -0
  21. package/dist/abis/index.js +11 -0
  22. package/dist/bundle-core/__tests__/config-helpers.test.d.ts +1 -0
  23. package/dist/bundle-core/__tests__/config-helpers.test.js +28 -0
  24. package/dist/bundle-core/__tests__/facade-parity.test.d.ts +1 -0
  25. package/dist/bundle-core/__tests__/facade-parity.test.js +33 -0
  26. package/dist/bundle-core/__tests__/sign-context-helpers.test.d.ts +1 -0
  27. package/dist/bundle-core/__tests__/sign-context-helpers.test.js +60 -0
  28. package/dist/bundle-core/__tests__/sign-fixture.test.d.ts +1 -0
  29. package/dist/bundle-core/__tests__/sign-fixture.test.js +220 -0
  30. package/dist/bundle-core/__tests__/sign-fixtures.d.ts +10 -0
  31. package/dist/bundle-core/__tests__/sign-fixtures.js +16 -0
  32. package/dist/bundle-core/config-helpers.d.ts +36 -0
  33. package/dist/bundle-core/config-helpers.js +57 -0
  34. package/dist/bundle-core/errors.d.ts +50 -0
  35. package/dist/bundle-core/errors.js +35 -0
  36. package/dist/bundle-core/four-meme/approve-tokenmanager.d.ts +7 -0
  37. package/dist/bundle-core/four-meme/approve-tokenmanager.js +99 -0
  38. package/dist/bundle-core/four-meme/core-helpers.d.ts +8 -0
  39. package/dist/bundle-core/four-meme/core-helpers.js +40 -0
  40. package/dist/bundle-core/four-meme/core.d.ts +4 -0
  41. package/dist/bundle-core/four-meme/core.js +515 -0
  42. package/dist/bundle-core/four-meme/pancake-proxy.d.ts +28 -0
  43. package/dist/bundle-core/four-meme/pancake-proxy.js +679 -0
  44. package/dist/bundle-core/four-meme/private.d.ts +27 -0
  45. package/dist/bundle-core/four-meme/private.js +465 -0
  46. package/dist/bundle-core/four-meme/sign-context-helpers.d.ts +2 -0
  47. package/dist/bundle-core/four-meme/sign-context-helpers.js +2 -0
  48. package/dist/bundle-core/four-meme/swap-buy-first.d.ts +8 -0
  49. package/dist/bundle-core/four-meme/swap-buy-first.js +493 -0
  50. package/dist/bundle-core/four-meme/swap-hop-helpers.d.ts +6 -0
  51. package/dist/bundle-core/four-meme/swap-hop-helpers.js +63 -0
  52. package/dist/bundle-core/four-meme/swap-internal.d.ts +3 -0
  53. package/dist/bundle-core/four-meme/swap-internal.js +18 -0
  54. package/dist/bundle-core/four-meme/swap-sign-helpers.d.ts +27 -0
  55. package/dist/bundle-core/four-meme/swap-sign-helpers.js +105 -0
  56. package/dist/bundle-core/four-meme/swap.d.ts +17 -0
  57. package/dist/bundle-core/four-meme/swap.js +505 -0
  58. package/dist/bundle-core/four-meme/types/buy-first.d.ts +50 -0
  59. package/dist/bundle-core/four-meme/types/buy-first.js +1 -0
  60. package/dist/bundle-core/four-meme/types/core-flow.d.ts +63 -0
  61. package/dist/bundle-core/four-meme/types/core-flow.js +1 -0
  62. package/dist/bundle-core/four-meme/types/index.d.ts +600 -0
  63. package/dist/bundle-core/four-meme/types/index.js +1 -0
  64. package/dist/bundle-core/four-meme/types/swap-internal.d.ts +19 -0
  65. package/dist/bundle-core/four-meme/types/swap-internal.js +1 -0
  66. package/dist/bundle-core/four-meme/types.d.ts +1 -0
  67. package/dist/bundle-core/four-meme/types.js +1 -0
  68. package/dist/bundle-core/four-meme/utils-disperse.d.ts +7 -0
  69. package/dist/bundle-core/four-meme/utils-disperse.js +396 -0
  70. package/dist/bundle-core/four-meme/utils-pairwise.d.ts +8 -0
  71. package/dist/bundle-core/four-meme/utils-pairwise.js +328 -0
  72. package/dist/bundle-core/four-meme/utils-sweep.d.ts +8 -0
  73. package/dist/bundle-core/four-meme/utils-sweep.js +744 -0
  74. package/dist/bundle-core/index.d.ts +8 -0
  75. package/dist/bundle-core/index.js +8 -0
  76. package/dist/bundle-core/internal.d.ts +21 -0
  77. package/dist/bundle-core/internal.js +182 -0
  78. package/dist/bundle-core/sign-context-helpers.d.ts +25 -0
  79. package/dist/bundle-core/sign-context-helpers.js +67 -0
  80. package/dist/bundle-core/submit.d.ts +293 -0
  81. package/dist/bundle-core/submit.js +727 -0
  82. package/dist/bundle-core/types/index.d.ts +8 -0
  83. package/dist/bundle-core/types/index.js +1 -0
  84. package/dist/bundle-core/types.d.ts +1 -0
  85. package/dist/bundle-core/types.js +1 -0
  86. package/dist/chains/bsc/four/approve-tokenmanager.d.ts +1 -26
  87. package/dist/chains/bsc/four/approve-tokenmanager.js +1 -113
  88. package/dist/chains/bsc/four/config.d.ts +5 -67
  89. package/dist/chains/bsc/four/config.js +2 -114
  90. package/dist/chains/bsc/four/core.d.ts +1 -4
  91. package/dist/chains/bsc/four/core.js +1 -592
  92. package/dist/chains/bsc/four/index.d.ts +6 -6
  93. package/dist/chains/bsc/four/index.js +6 -6
  94. package/dist/chains/bsc/four/internal.d.ts +2 -46
  95. package/dist/chains/bsc/four/internal.js +2 -239
  96. package/dist/chains/bsc/four/pancake-proxy.d.ts +1 -28
  97. package/dist/chains/bsc/four/pancake-proxy.js +1 -687
  98. package/dist/chains/bsc/four/private.d.ts +1 -27
  99. package/dist/chains/bsc/four/private.js +1 -477
  100. package/dist/chains/bsc/four/submit.d.ts +2 -315
  101. package/dist/chains/bsc/four/submit.js +2 -752
  102. package/dist/chains/bsc/four/swap-buy-first.d.ts +2 -55
  103. package/dist/chains/bsc/four/swap-buy-first.js +2 -507
  104. package/dist/chains/bsc/four/swap-internal.d.ts +1 -3
  105. package/dist/chains/bsc/four/swap-internal.js +1 -18
  106. package/dist/chains/bsc/four/swap.d.ts +2 -144
  107. package/dist/chains/bsc/four/swap.js +2 -766
  108. package/dist/chains/bsc/four/types.d.ts +1 -476
  109. package/dist/chains/bsc/four/utils-disperse.d.ts +1 -0
  110. package/dist/chains/bsc/four/utils-disperse.js +1 -0
  111. package/dist/chains/bsc/four/utils-pairwise.d.ts +1 -0
  112. package/dist/chains/bsc/four/utils-pairwise.js +1 -0
  113. package/dist/chains/bsc/four/utils-sweep.d.ts +1 -0
  114. package/dist/chains/bsc/four/utils-sweep.js +1 -0
  115. package/dist/chains/bsc/four/utils.d.ts +5 -18
  116. package/dist/chains/bsc/four/utils.js +5 -1552
  117. package/dist/chains/bsc/iro.d.ts +5 -0
  118. package/dist/chains/bsc/iro.js +4 -0
  119. package/dist/chains/bsc/pancake/bundle-buy-first-helpers.d.ts +159 -0
  120. package/dist/chains/bsc/pancake/bundle-buy-first-helpers.js +117 -0
  121. package/dist/chains/bsc/pancake/bundle-buy-first.d.ts +1 -91
  122. package/dist/chains/bsc/pancake/bundle-buy-first.js +97 -212
  123. package/dist/chains/bsc/pancake/bundle-swap-helpers.d.ts +241 -0
  124. package/dist/chains/bsc/pancake/bundle-swap-helpers.js +565 -0
  125. package/dist/chains/bsc/pancake/bundle-swap.d.ts +1 -79
  126. package/dist/chains/bsc/pancake/bundle-swap.js +114 -726
  127. package/dist/chains/bsc/pancake/index.d.ts +4 -2
  128. package/dist/chains/bsc/pancake/index.js +1 -3
  129. package/dist/chains/bsc/platforms/iro/factory.d.ts +2 -2
  130. package/dist/chains/bsc/platforms/iro/factory.js +3 -1
  131. package/dist/chains/bsc/platforms/iro/index.d.ts +5 -5
  132. package/dist/chains/bsc/platforms/iro/index.js +3 -3
  133. package/dist/chains/bsc/platforms/iro/pool.js +31 -10
  134. package/dist/chains/bsc/platforms/iro/token.js +4 -1
  135. package/dist/chains/eni/batch-router/bundle-approve.js +4 -3
  136. package/dist/chains/eni/batch-router/transfer.js +55 -25
  137. package/dist/chains/eni/batch-router/utils.js +32 -6
  138. package/dist/chains/eni/bundler/sign.js +5 -6
  139. package/dist/chains/eni/bundler/submit.js +1 -4
  140. package/dist/chains/eni/constants.js +1 -1
  141. package/dist/chains/eni/flat-aliases.d.ts +10 -0
  142. package/dist/chains/eni/flat-aliases.js +8 -0
  143. package/dist/chains/eni/index.d.ts +2 -1
  144. package/dist/chains/eni/index.js +1 -0
  145. package/dist/chains/eni/platforms/daoaas/create.js +2 -2
  146. package/dist/chains/eni/platforms/daoaas/index.d.ts +3 -3
  147. package/dist/chains/eni/platforms/daoaas/index.js +3 -3
  148. package/dist/chains/eni/platforms/daoaas/meta.js +9 -6
  149. package/dist/chains/eni/platforms/daoaas/portal-direct.js +28 -44
  150. package/dist/chains/eni/platforms/daoaas/portal.js +10 -6
  151. package/dist/chains/eni/platforms/dswap/liquidity.js +58 -26
  152. package/dist/chains/eni/platforms/fair-launch/index.d.ts +2 -2
  153. package/dist/chains/eni/platforms/fair-launch/index.js +1 -1
  154. package/dist/chains/eni/platforms/fair-launch/launcher.js +87 -46
  155. package/dist/chains/eni/platforms/fair-launch/pool.js +4 -1
  156. package/dist/chains/eni/platforms/fair-launch/presets.js +2 -2
  157. package/dist/chains/eni/platforms/iro/factory.d.ts +2 -2
  158. package/dist/chains/eni/platforms/iro/factory.js +3 -1
  159. package/dist/chains/eni/platforms/iro/index.d.ts +6 -6
  160. package/dist/chains/eni/platforms/iro/index.js +4 -4
  161. package/dist/chains/eni/platforms/iro/pool.js +90 -26
  162. package/dist/chains/eni/platforms/iro/token.js +107 -31
  163. package/dist/chains/eni/platforms/iro/whitelist.js +6 -18
  164. package/dist/chains/eni/submit.d.ts +43 -0
  165. package/dist/chains/eni/submit.js +286 -0
  166. package/dist/chains/index.d.ts +13 -0
  167. package/dist/chains/index.js +13 -0
  168. package/dist/chains/xlayer/eip7702/bundle-approve.d.ts +2 -26
  169. package/dist/chains/xlayer/eip7702/bundle-approve.js +11 -21
  170. package/dist/chains/xlayer/eip7702/bundle-buy.d.ts +2 -6
  171. package/dist/chains/xlayer/eip7702/bundle-buy.js +13 -51
  172. package/dist/chains/xlayer/eip7702/bundle-create.js +93 -59
  173. package/dist/chains/xlayer/eip7702/bundle-sell.d.ts +2 -6
  174. package/dist/chains/xlayer/eip7702/bundle-sell.js +29 -111
  175. package/dist/chains/xlayer/eip7702/bundle-swap.d.ts +3 -65
  176. package/dist/chains/xlayer/eip7702/bundle-swap.js +51 -245
  177. package/dist/chains/xlayer/eip7702/constants.d.ts +1 -16
  178. package/dist/chains/xlayer/eip7702/constants.js +3 -21
  179. package/dist/chains/xlayer/eip7702/flat-aliases.d.ts +13 -0
  180. package/dist/chains/xlayer/eip7702/flat-aliases.js +10 -0
  181. package/dist/chains/xlayer/eip7702/index.d.ts +28 -46
  182. package/dist/chains/xlayer/eip7702/index.js +28 -81
  183. package/dist/chains/xlayer/eip7702/multi-hop-transfer-helpers.d.ts +79 -0
  184. package/dist/chains/xlayer/eip7702/multi-hop-transfer-helpers.js +1 -0
  185. package/dist/chains/xlayer/eip7702/multi-hop-transfer.d.ts +2 -203
  186. package/dist/chains/xlayer/eip7702/multi-hop-transfer.js +63 -307
  187. package/dist/chains/xlayer/eip7702/transfer-context-helpers.d.ts +26 -0
  188. package/dist/chains/xlayer/eip7702/transfer-context-helpers.js +57 -0
  189. package/dist/chains/xlayer/eip7702/types.d.ts +88 -0
  190. package/dist/chains/xlayer/eip7702/utils.d.ts +0 -3
  191. package/dist/chains/xlayer/eip7702/utils.js +23 -28
  192. package/dist/chains/xlayer/eip7702/volume-helpers.d.ts +148 -0
  193. package/dist/chains/xlayer/eip7702/volume-helpers.js +48 -0
  194. package/dist/chains/xlayer/eip7702/volume.d.ts +6 -184
  195. package/dist/chains/xlayer/eip7702/volume.js +89 -164
  196. package/dist/chains/xlayer/eoa/constants.js +1 -1
  197. package/dist/chains/xlayer/eoa/dex-helpers.js +5 -5
  198. package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.d.ts +126 -0
  199. package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.js +228 -0
  200. package/dist/chains/xlayer/eoa/eoa-bundle-swap.d.ts +1 -95
  201. package/dist/chains/xlayer/eoa/eoa-bundle-swap.js +66 -299
  202. package/dist/chains/xlayer/eoa/eoa-wash-volume.d.ts +1 -1
  203. package/dist/chains/xlayer/eoa/eoa-wash-volume.js +18 -23
  204. package/dist/chains/xlayer/eoa/index.d.ts +10 -6
  205. package/dist/chains/xlayer/eoa/index.js +8 -23
  206. package/dist/chains/xlayer/eoa/portal-ops.js +7 -2
  207. package/dist/chains/xlayer/eoa/router-manager.js +3 -3
  208. package/dist/chains/xlayer/eoa/types.d.ts +2 -2
  209. package/dist/chains/xlayer/eoa/types.js +1 -3
  210. package/dist/chains/xlayer/index.d.ts +3 -2
  211. package/dist/chains/xlayer/index.js +4 -7
  212. package/dist/contracts/helper3.d.ts +20 -5
  213. package/dist/contracts/helper3.js +56 -20
  214. package/dist/contracts/tm-bundle-helpers.d.ts +88 -0
  215. package/dist/contracts/tm-bundle-helpers.js +72 -0
  216. package/dist/contracts/tm-bundle-merkle/approve-tokenmanager.d.ts +1 -26
  217. package/dist/contracts/tm-bundle-merkle/approve-tokenmanager.js +1 -113
  218. package/dist/contracts/tm-bundle-merkle/config.d.ts +5 -67
  219. package/dist/contracts/tm-bundle-merkle/config.js +2 -114
  220. package/dist/contracts/tm-bundle-merkle/core.d.ts +1 -4
  221. package/dist/contracts/tm-bundle-merkle/core.js +1 -591
  222. package/dist/contracts/tm-bundle-merkle/index.d.ts +5 -5
  223. package/dist/contracts/tm-bundle-merkle/index.js +5 -5
  224. package/dist/contracts/tm-bundle-merkle/internal.d.ts +2 -46
  225. package/dist/contracts/tm-bundle-merkle/internal.js +2 -238
  226. package/dist/contracts/tm-bundle-merkle/pancake-proxy.d.ts +1 -28
  227. package/dist/contracts/tm-bundle-merkle/pancake-proxy.js +1 -686
  228. package/dist/contracts/tm-bundle-merkle/private.d.ts +1 -27
  229. package/dist/contracts/tm-bundle-merkle/private.js +1 -476
  230. package/dist/contracts/tm-bundle-merkle/submit.d.ts +3 -314
  231. package/dist/contracts/tm-bundle-merkle/submit.js +3 -928
  232. package/dist/contracts/tm-bundle-merkle/swap-buy-first.d.ts +2 -55
  233. package/dist/contracts/tm-bundle-merkle/swap-buy-first.js +2 -506
  234. package/dist/contracts/tm-bundle-merkle/swap-internal.d.ts +1 -3
  235. package/dist/contracts/tm-bundle-merkle/swap-internal.js +1 -18
  236. package/dist/contracts/tm-bundle-merkle/swap.d.ts +2 -144
  237. package/dist/contracts/tm-bundle-merkle/swap.js +2 -764
  238. package/dist/contracts/tm-bundle-merkle/types.d.ts +1 -476
  239. package/dist/contracts/tm-bundle-merkle/utils-disperse.d.ts +1 -0
  240. package/dist/contracts/tm-bundle-merkle/utils-disperse.js +1 -0
  241. package/dist/contracts/tm-bundle-merkle/utils-pairwise.d.ts +1 -0
  242. package/dist/contracts/tm-bundle-merkle/utils-pairwise.js +1 -0
  243. package/dist/contracts/tm-bundle-merkle/utils-sweep.d.ts +1 -0
  244. package/dist/contracts/tm-bundle-merkle/utils-sweep.js +1 -0
  245. package/dist/contracts/tm-bundle-merkle/utils.d.ts +6 -18
  246. package/dist/contracts/tm-bundle-merkle/utils.js +6 -1501
  247. package/dist/contracts/tm-bundle.d.ts +3 -51
  248. package/dist/contracts/tm-bundle.js +108 -177
  249. package/dist/contracts/tm.d.ts +3 -2
  250. package/dist/contracts/tm.js +37 -32
  251. package/dist/contracts/tm1.js +9 -4
  252. package/dist/contracts/tm2.js +9 -4
  253. package/dist/dex/direct-router-helpers.d.ts +264 -0
  254. package/dist/dex/direct-router-helpers.js +539 -0
  255. package/dist/dex/direct-router.d.ts +3 -125
  256. package/dist/dex/direct-router.js +237 -666
  257. package/dist/dex/types.d.ts +81 -0
  258. package/dist/dex/types.js +1 -0
  259. package/dist/exports/root-bundle-and-tooling.d.ts +27 -0
  260. package/dist/exports/root-bundle-and-tooling.js +30 -0
  261. package/dist/exports/root-eni-and-bsc-iro.d.ts +26 -0
  262. package/dist/exports/root-eni-and-bsc-iro.js +66 -0
  263. package/dist/exports/root-foundations.d.ts +35 -0
  264. package/dist/exports/root-foundations.js +70 -0
  265. package/dist/exports/root-swap-dex-and-xlayer.d.ts +30 -0
  266. package/dist/exports/root-swap-dex-and-xlayer.js +78 -0
  267. package/dist/flap/index.d.ts +10 -0
  268. package/dist/flap/index.js +8 -0
  269. package/dist/flows/create.d.ts +2 -1
  270. package/dist/flows/create.js +6 -6
  271. package/dist/flows/index.d.ts +1 -0
  272. package/dist/flows/index.js +1 -0
  273. package/dist/index.d.ts +20 -85
  274. package/dist/index.js +20 -215
  275. package/dist/merkle/index.d.ts +12 -0
  276. package/dist/merkle/index.js +11 -0
  277. package/dist/shared/abis/common.d.ts +2 -83
  278. package/dist/shared/abis/common.js +2 -252
  279. package/dist/shared/abis/index.d.ts +5 -6
  280. package/dist/shared/abis/index.js +5 -7
  281. package/dist/shared/clients/blockrazor.js +39 -25
  282. package/dist/shared/clients/club48.d.ts +2 -2
  283. package/dist/shared/clients/club48.js +34 -29
  284. package/dist/shared/clients/emitservice.js +2 -0
  285. package/dist/shared/clients/four.d.ts +21 -6
  286. package/dist/shared/clients/four.js +29 -24
  287. package/dist/shared/clients/index.d.ts +8 -0
  288. package/dist/shared/clients/index.js +8 -0
  289. package/dist/shared/clients/merkle.js +27 -34
  290. package/dist/shared/constants/addresses.d.ts +1 -1
  291. package/dist/shared/constants/addresses.js +11 -2
  292. package/dist/shared/constants/chains.d.ts +1 -1
  293. package/dist/shared/constants/chains.js +1 -1
  294. package/dist/shared/constants/gas.d.ts +1 -1
  295. package/dist/shared/constants/gas.js +2 -6
  296. package/dist/shared/constants/index.d.ts +3 -0
  297. package/dist/shared/constants/index.js +1 -0
  298. package/dist/shared/constants/quote.d.ts +30 -0
  299. package/dist/shared/constants/quote.js +37 -0
  300. package/dist/shared/flap/abi.js +1 -1
  301. package/dist/shared/flap/constants.d.ts +1 -2
  302. package/dist/shared/flap/constants.js +2 -3
  303. package/dist/shared/flap/curve.js +3 -0
  304. package/dist/shared/flap/errors.d.ts +1 -4
  305. package/dist/shared/flap/errors.js +20 -1
  306. package/dist/shared/flap/index.d.ts +5 -4
  307. package/dist/shared/flap/index.js +5 -4
  308. package/dist/shared/flap/meta.d.ts +22 -18
  309. package/dist/shared/flap/meta.js +12 -17
  310. package/dist/shared/flap/permit.js +5 -2
  311. package/dist/shared/flap/pinata.d.ts +22 -6
  312. package/dist/shared/flap/pinata.js +21 -26
  313. package/dist/shared/flap/portal-bundle-merkle/config.d.ts +3 -72
  314. package/dist/shared/flap/portal-bundle-merkle/config.js +4 -124
  315. package/dist/shared/flap/portal-bundle-merkle/core-helpers.d.ts +32 -0
  316. package/dist/shared/flap/portal-bundle-merkle/core-helpers.js +83 -0
  317. package/dist/shared/flap/portal-bundle-merkle/core.d.ts +0 -4
  318. package/dist/shared/flap/portal-bundle-merkle/core.js +86 -278
  319. package/dist/shared/flap/portal-bundle-merkle/create-to-dex.d.ts +7 -2
  320. package/dist/shared/flap/portal-bundle-merkle/create-to-dex.js +101 -206
  321. package/dist/shared/flap/portal-bundle-merkle/curve-to-dex.js +100 -92
  322. package/dist/shared/flap/portal-bundle-merkle/index.d.ts +11 -7
  323. package/dist/shared/flap/portal-bundle-merkle/index.js +4 -7
  324. package/dist/shared/flap/portal-bundle-merkle/pancake-proxy.js +71 -68
  325. package/dist/shared/flap/portal-bundle-merkle/private.js +61 -114
  326. package/dist/shared/flap/portal-bundle-merkle/swap-buy-first-helpers.d.ts +125 -0
  327. package/dist/shared/flap/portal-bundle-merkle/swap-buy-first-helpers.js +113 -0
  328. package/dist/shared/flap/portal-bundle-merkle/swap-buy-first.d.ts +1 -64
  329. package/dist/shared/flap/portal-bundle-merkle/swap-buy-first.js +66 -247
  330. package/dist/shared/flap/portal-bundle-merkle/swap-helpers.d.ts +149 -0
  331. package/dist/shared/flap/portal-bundle-merkle/swap-helpers.js +259 -0
  332. package/dist/shared/flap/portal-bundle-merkle/swap.d.ts +2 -71
  333. package/dist/shared/flap/portal-bundle-merkle/swap.js +103 -410
  334. package/dist/shared/flap/portal-bundle-merkle/types.d.ts +83 -9
  335. package/dist/shared/flap/portal-bundle-merkle/utils.d.ts +1 -80
  336. package/dist/shared/flap/portal-bundle-merkle/utils.js +145 -265
  337. package/dist/shared/flap/portal-bundle.js +55 -56
  338. package/dist/shared/flap/portal-create-token.d.ts +77 -0
  339. package/dist/shared/flap/portal-create-token.js +214 -0
  340. package/dist/shared/flap/portal.d.ts +14 -3
  341. package/dist/shared/flap/portal.js +50 -25
  342. package/dist/shared/flap/vanity.d.ts +1 -5
  343. package/dist/shared/flap/vanity.js +6 -17
  344. package/dist/shared/flap/vault.d.ts +17 -124
  345. package/dist/shared/flap/vault.js +67 -148
  346. package/dist/shared/foundation/dex/v3-path.d.ts +6 -0
  347. package/dist/shared/foundation/dex/v3-path.js +35 -0
  348. package/dist/shared/foundation/gas/bundle-gas.d.ts +49 -0
  349. package/dist/shared/foundation/gas/bundle-gas.js +93 -0
  350. package/dist/shared/foundation/gas/profit-hop.d.ts +20 -0
  351. package/dist/shared/foundation/gas/profit-hop.js +72 -0
  352. package/dist/shared/foundation/index.d.ts +13 -0
  353. package/dist/shared/foundation/index.js +12 -0
  354. package/dist/shared/foundation/nonce/nonce-manager.d.ts +17 -0
  355. package/dist/shared/foundation/nonce/nonce-manager.js +183 -0
  356. package/dist/shared/foundation/normalize-unknown.d.ts +9 -0
  357. package/dist/shared/foundation/normalize-unknown.js +29 -0
  358. package/dist/shared/foundation/sdk-logger.d.ts +13 -0
  359. package/dist/shared/foundation/sdk-logger.js +12 -0
  360. package/dist/shared/foundation/tx/build-request.d.ts +17 -0
  361. package/dist/shared/foundation/tx/build-request.js +25 -0
  362. package/dist/shared/foundation/tx/sign-batch.d.ts +5 -0
  363. package/dist/shared/foundation/tx/sign-batch.js +26 -0
  364. package/dist/shared/foundation/tx/wallet-sign-patch.d.ts +1 -0
  365. package/dist/shared/foundation/tx/wallet-sign-patch.js +18 -0
  366. package/dist/shared/foundation/types/airdrop-sweep.d.ts +79 -0
  367. package/dist/shared/foundation/types/airdrop-sweep.js +1 -0
  368. package/dist/shared/foundation/types/erc20.d.ts +65 -0
  369. package/dist/shared/foundation/types/erc20.js +1 -0
  370. package/dist/shared/foundation/types/holders-maker.d.ts +64 -0
  371. package/dist/shared/foundation/types/holders-maker.js +1 -0
  372. package/dist/shared/foundation/types/index.d.ts +7 -0
  373. package/dist/shared/foundation/types/index.js +1 -0
  374. package/dist/shared/foundation/types/lp-inspect.d.ts +102 -0
  375. package/dist/shared/foundation/types/lp-inspect.js +1 -0
  376. package/dist/shared/foundation/types/multicall.d.ts +5 -0
  377. package/dist/shared/foundation/types/multicall.js +1 -0
  378. package/dist/shared/foundation/types/private-sale.d.ts +35 -0
  379. package/dist/shared/foundation/types/private-sale.js +1 -0
  380. package/dist/shared/foundation/types/quote-helpers.d.ts +17 -0
  381. package/dist/shared/foundation/types/quote-helpers.js +1 -0
  382. package/dist/shared/four/tax-token.d.ts +1 -1
  383. package/dist/shared/four/tax-token.js +27 -7
  384. package/dist/shared/index.d.ts +6 -0
  385. package/dist/shared/index.js +4 -0
  386. package/dist/types/errors.d.ts +27 -0
  387. package/dist/types/errors.js +34 -0
  388. package/dist/utils/airdrop-sweep.d.ts +4 -76
  389. package/dist/utils/airdrop-sweep.js +42 -55
  390. package/dist/utils/bundle-helpers.d.ts +9 -243
  391. package/dist/utils/bundle-helpers.js +10 -584
  392. package/dist/utils/constants.d.ts +5 -61
  393. package/dist/utils/constants.js +5 -80
  394. package/dist/utils/contract-factory.d.ts +2 -4
  395. package/dist/utils/contract-factory.js +25 -18
  396. package/dist/utils/erc20.d.ts +7 -89
  397. package/dist/utils/erc20.js +94 -125
  398. package/dist/utils/errors.d.ts +12 -1
  399. package/dist/utils/errors.js +60 -1
  400. package/dist/utils/holders-maker/addresses.d.ts +12 -0
  401. package/dist/utils/holders-maker/addresses.js +15 -0
  402. package/dist/utils/holders-maker/buy-tx.d.ts +44 -0
  403. package/dist/utils/holders-maker/buy-tx.js +278 -0
  404. package/dist/utils/holders-maker/constants.d.ts +6 -0
  405. package/dist/utils/holders-maker/constants.js +7 -0
  406. package/dist/utils/holders-maker/disperse.d.ts +18 -0
  407. package/dist/utils/holders-maker/disperse.js +90 -0
  408. package/dist/utils/holders-maker/routing.d.ts +4 -0
  409. package/dist/utils/holders-maker/routing.js +45 -0
  410. package/dist/utils/holders-maker/transfer-tx.d.ts +4 -0
  411. package/dist/utils/holders-maker/transfer-tx.js +67 -0
  412. package/dist/utils/holders-maker-helpers.d.ts +9 -0
  413. package/dist/utils/holders-maker-helpers.js +9 -0
  414. package/dist/utils/holders-maker.d.ts +2 -138
  415. package/dist/utils/holders-maker.js +26 -661
  416. package/dist/utils/hop-chains.d.ts +35 -0
  417. package/dist/utils/hop-chains.js +215 -0
  418. package/dist/utils/lp-inspect-helpers.d.ts +9 -0
  419. package/dist/utils/lp-inspect-helpers.js +109 -0
  420. package/dist/utils/lp-inspect.d.ts +2 -112
  421. package/dist/utils/lp-inspect.js +73 -223
  422. package/dist/utils/mpcExclusive.d.ts +2 -5
  423. package/dist/utils/mpcExclusive.js +4 -3
  424. package/dist/utils/private-sale.d.ts +2 -58
  425. package/dist/utils/private-sale.js +4 -15
  426. package/dist/utils/provider-factory.d.ts +4 -0
  427. package/dist/utils/provider-factory.js +10 -0
  428. package/dist/utils/quote-helpers.d.ts +4 -45
  429. package/dist/utils/quote-helpers.js +17 -74
  430. package/dist/utils/stealth-transfer.d.ts +2 -28
  431. package/dist/utils/stealth-transfer.js +31 -15
  432. package/dist/utils/swap-helpers.d.ts +2 -15
  433. package/dist/utils/swap-helpers.js +6 -11
  434. package/dist/utils/types/airdrop-sweep.d.ts +1 -0
  435. package/dist/utils/types/airdrop-sweep.js +1 -0
  436. package/dist/utils/types/contract-factory.d.ts +1 -0
  437. package/dist/utils/types/contract-factory.js +1 -0
  438. package/dist/utils/types/erc20.d.ts +1 -0
  439. package/dist/utils/types/erc20.js +1 -0
  440. package/dist/utils/types/errors.d.ts +1 -0
  441. package/dist/utils/types/errors.js +1 -0
  442. package/dist/utils/types/holders-maker.d.ts +1 -0
  443. package/dist/utils/types/holders-maker.js +1 -0
  444. package/dist/utils/types/hop-chains.d.ts +8 -0
  445. package/dist/utils/types/hop-chains.js +1 -0
  446. package/dist/utils/types/index.d.ts +13 -0
  447. package/dist/utils/types/index.js +1 -0
  448. package/dist/utils/types/lp-inspect.d.ts +1 -0
  449. package/dist/utils/types/lp-inspect.js +1 -0
  450. package/dist/utils/types/mpc-exclusive.d.ts +5 -0
  451. package/dist/utils/types/mpc-exclusive.js +1 -0
  452. package/dist/utils/types/private-sale.d.ts +1 -0
  453. package/dist/utils/types/private-sale.js +1 -0
  454. package/dist/utils/types/quote-helpers.d.ts +1 -0
  455. package/dist/utils/types/quote-helpers.js +1 -0
  456. package/dist/utils/types/stealth-transfer.d.ts +44 -0
  457. package/dist/utils/types/stealth-transfer.js +1 -0
  458. package/dist/utils/types/wallet.d.ts +25 -0
  459. package/dist/utils/types/wallet.js +1 -0
  460. package/dist/utils/wallet.d.ts +2 -25
  461. package/dist/utils/wallet.js +13 -10
  462. package/dist/vanity/index.d.ts +5 -0
  463. package/dist/vanity/index.js +5 -0
  464. package/package.json +160 -4
  465. package/src/abis/contracts/TaxToken.json +969 -0
  466. package/src/abis/contracts/TokenManager.json +836 -0
  467. package/src/abis/contracts/TokenManager2.json +136 -0
  468. package/src/abis/contracts/TokenManagerHelper3.json +993 -0
  469. package/dist/shared/abis/TaxToken.json +0 -105
  470. package/dist/shared/abis/TokenManager2.json +0 -60
  471. /package/dist/{shared/abis → abis/contracts}/TokenManager.json +0 -0
  472. /package/dist/{shared/abis → abis/contracts}/TokenManagerHelper3.json +0 -0
@@ -0,0 +1,105 @@
1
+ import { ethers, Contract } from 'ethers';
2
+ import { getGasLimit } from '../../utils/bundle-helpers.js';
3
+ import { ADDRESSES } from '../../shared/constants/index.js';
4
+ import { getProfitRateBps as getSharedProfitRateBps } from '../../shared/constants/index.js';
5
+ import { getTxType } from '../config-helpers.js';
6
+ import { createSignProvider } from '../sign-context-helpers.js';
7
+ import { HELPER3_ABI, TM_ADDRESS } from './swap-internal.js';
8
+ const APPROVE_INTERFACE = new ethers.Interface(['function approve(address,uint256) returns (bool)']);
9
+ const ERC20_ALLOWANCE_ABI = ['function allowance(address,address) view returns (uint256)'];
10
+ export function getFourSwapProfitRateBps(userType) {
11
+ if (userType === 'v0')
12
+ return getSharedProfitRateBps('v0Single');
13
+ if (userType === 'v1')
14
+ return getSharedProfitRateBps('v1Single');
15
+ return getSharedProfitRateBps('v0Single');
16
+ }
17
+ export function needsTmTokenApproval(currentAllowance, decimals) {
18
+ const threshold = ethers.parseUnits('1000000000', decimals);
19
+ return currentAllowance < threshold;
20
+ }
21
+ export function countSellerNonceSlots(needBribeTx, needApproval, includeProfit) {
22
+ let count = 1;
23
+ if (needBribeTx)
24
+ count++;
25
+ if (needApproval)
26
+ count++;
27
+ if (includeProfit)
28
+ count++;
29
+ return count;
30
+ }
31
+ export function planSellerNonces(sellerNonces, needBribeTx, needApproval, extractProfit) {
32
+ let idx = 0;
33
+ const plan = { sellerNonce: sellerNonces[0] };
34
+ if (needBribeTx)
35
+ plan.bribeNonce = sellerNonces[idx++];
36
+ if (needApproval)
37
+ plan.approvalNonce = sellerNonces[idx++];
38
+ plan.sellerNonce = sellerNonces[idx++];
39
+ if (extractProfit)
40
+ plan.profitNonce = sellerNonces[idx];
41
+ return plan;
42
+ }
43
+ export async function signTmMaxApprovalTx(seller, tokenAddress, approvalNonce, gasPrice, chainIdNum, txType) {
44
+ const approveData = APPROVE_INTERFACE.encodeFunctionData('approve', [TM_ADDRESS, ethers.MaxUint256]);
45
+ return seller.signTransaction({
46
+ to: tokenAddress,
47
+ data: approveData,
48
+ value: 0n,
49
+ nonce: approvalNonce,
50
+ gasLimit: 80000n,
51
+ gasPrice,
52
+ chainId: chainIdNum,
53
+ type: txType,
54
+ });
55
+ }
56
+ export async function quoteFourSwapSellFunds(provider, tokenAddress, sellAmountWei) {
57
+ const helper3 = new Contract(ADDRESSES.BSC.TokenManagerHelper3, HELPER3_ABI, provider);
58
+ const sellQuote = await helper3.trySell(tokenAddress, sellAmountWei);
59
+ return sellQuote.funds;
60
+ }
61
+ export async function fetchFourSwapSellQuoteAndAllowance(provider, tokenAddress, sellerAddress, sellAmountWei) {
62
+ const helper3 = new Contract(ADDRESSES.BSC.TokenManagerHelper3, HELPER3_ABI, provider);
63
+ const erc20 = new Contract(tokenAddress, ERC20_ALLOWANCE_ABI, provider);
64
+ const [sellQuote, allowance] = await Promise.all([
65
+ helper3.trySell(tokenAddress, sellAmountWei),
66
+ erc20.allowance(sellerAddress, TM_ADDRESS),
67
+ ]);
68
+ return { sellFunds: sellQuote.funds, allowance };
69
+ }
70
+ export async function fetchFourSwapSellQuoteAllowanceAndBalances(provider, tokenAddress, sellerAddress, sellAmountWei, buyerAddresses) {
71
+ const helper3 = new Contract(ADDRESSES.BSC.TokenManagerHelper3, HELPER3_ABI, provider);
72
+ const erc20 = new Contract(tokenAddress, ERC20_ALLOWANCE_ABI, provider);
73
+ const [sellQuote, allowance, ...buyerBalances] = await Promise.all([
74
+ helper3.trySell(tokenAddress, sellAmountWei),
75
+ erc20.allowance(sellerAddress, TM_ADDRESS),
76
+ ...buyerAddresses.map((addr) => provider.getBalance(addr)),
77
+ ]);
78
+ return {
79
+ sellFunds: sellQuote.funds,
80
+ allowance,
81
+ buyerBalances,
82
+ };
83
+ }
84
+ export function toCommonBundleConfig(config) {
85
+ return {
86
+ minGasPriceGwei: config.minGasPriceGwei,
87
+ maxGasPriceGwei: config.maxGasPriceGwei,
88
+ gasLimit: typeof config.gasLimit === 'bigint' ? Number(config.gasLimit) : config.gasLimit,
89
+ gasLimitMultiplier: config.gasLimitMultiplier,
90
+ txType: config.txType,
91
+ chainId: config.chainId,
92
+ };
93
+ }
94
+ export function createFourSwapGasContext(config) {
95
+ const chainIdNum = config.chainId ?? 56;
96
+ const provider = createSignProvider(config.rpcUrl, chainIdNum, 'BSC');
97
+ const bundleConfig = toCommonBundleConfig(config);
98
+ return {
99
+ chainIdNum,
100
+ provider,
101
+ bundleConfig,
102
+ finalGasLimit: getGasLimit(bundleConfig),
103
+ txType: getTxType(bundleConfig),
104
+ };
105
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Four.meme 内盘捆绑换手(Merkle Bundle)
3
+ */
4
+ import type { FourBatchSwapResult, FourBatchSwapSignParams, FourBundleSwapSignParams, FourQuickBatchSwapResult, FourQuickBatchSwapSignParams, FourSwapResult } from './types.js';
5
+ export type { UserType, FourSwapSignConfig, FourSwapConfig, FourBundleSwapSignParams, FourBundleSwapParams, FourSwapResult, FourBatchSwapSignParams, FourBatchSwapResult, FourQuickBatchSwapSignParams, FourQuickBatchSwapResult, } from './types.js';
6
+ /**
7
+ * Four内盘捆绑换手
8
+ */
9
+ export declare function fourBundleSwapMerkle(params: FourBundleSwapSignParams): Promise<FourSwapResult>;
10
+ /**
11
+ * Four 内盘批量换手(一卖多买)
12
+ */
13
+ export declare function fourBatchSwapMerkle(params: FourBatchSwapSignParams): Promise<FourBatchSwapResult>;
14
+ /**
15
+ * Four 内盘快捷批量换手(资金利用率模式)
16
+ */
17
+ export declare function fourQuickBatchSwapMerkle(params: FourQuickBatchSwapSignParams): Promise<FourQuickBatchSwapResult>;
@@ -0,0 +1,505 @@
1
+ /**
2
+ * Four.meme 内盘捆绑换手(Merkle Bundle)
3
+ */
4
+ import { ethers, Contract, Wallet } from 'ethers';
5
+ import { countSellerNonceSlots, createFourSwapGasContext, fetchFourSwapSellQuoteAndAllowance, fetchFourSwapSellQuoteAllowanceAndBalances, getFourSwapProfitRateBps, needsTmTokenApproval, planSellerNonces, quoteFourSwapSellFunds, signTmMaxApprovalTx, } from './swap-sign-helpers.js';
6
+ import { generateDisperseHopPaths, buildNativeHopChain, NATIVE_TRANSFER_GAS_LIMIT } from './swap-hop-helpers.js';
7
+ import { signBribeTransaction } from '../sign-context-helpers.js';
8
+ import { calculateSellAmount } from '../../utils/swap-helpers.js';
9
+ import { NonceManager, getOptimizedGasPrice, getGasPriceConfig, buildProfitHopTransactions, PROFIT_HOP_COUNT, } from '../../utils/bundle-helpers.js';
10
+ import { getBribeAmount, getProfitRecipient } from '../config-helpers.js';
11
+ import { TM_ABI, TM_ADDRESS } from './swap-internal.js';
12
+ /**
13
+ * Four内盘捆绑换手
14
+ */
15
+ export async function fourBundleSwapMerkle(params) {
16
+ const { sellerPrivateKey, sellAmount, sellPercentage, buyerPrivateKey, tokenAddress, config, startNonces, // ✅ 可选:前端预获取的 nonces
17
+ } = params;
18
+ const { chainIdNum, provider, bundleConfig, finalGasLimit, txType } = createFourSwapGasContext(config);
19
+ const seller = new Wallet(sellerPrivateKey, provider);
20
+ const buyer = new Wallet(buyerPrivateKey, provider);
21
+ const nonceManager = new NonceManager(provider);
22
+ // ✅ 优化:第一批并行 - calculateSellAmount、gasPrice
23
+ const [sellAmountResult, gasPrice] = await Promise.all([
24
+ calculateSellAmount(provider, tokenAddress, seller.address, sellAmount, sellPercentage),
25
+ getOptimizedGasPrice(provider, getGasPriceConfig(bundleConfig)),
26
+ ]);
27
+ const { amount: sellAmountWei, decimals } = sellAmountResult;
28
+ const [{ sellFunds: sellerWillGetBNB, allowance: currentAllowance }, buyerBalance] = await Promise.all([
29
+ fetchFourSwapSellQuoteAndAllowance(provider, tokenAddress, seller.address, sellAmountWei),
30
+ provider.getBalance(buyer.address),
31
+ ]);
32
+ const buyerFunds = sellerWillGetBNB;
33
+ // 验证买方余额
34
+ const reserveGas = ethers.parseEther((config.reserveGasBNB || 0.0005).toString());
35
+ const requiredBalance = buyerFunds + reserveGas;
36
+ if (buyerBalance < requiredBalance) {
37
+ throw new Error(`买方余额不足:\n` +
38
+ ` - 需要: ${ethers.formatEther(requiredBalance)} BNB\n` +
39
+ ` - 实际: ${ethers.formatEther(buyerBalance)} BNB`);
40
+ }
41
+ // 检查是否需要授权
42
+ const needApproval = needsTmTokenApproval(currentAllowance, decimals);
43
+ // 利润配置
44
+ const extractProfit = true;
45
+ const profitRateBps = getFourSwapProfitRateBps(config.userType);
46
+ const profitAmount = extractProfit && sellerWillGetBNB > 0n ? (sellerWillGetBNB * BigInt(profitRateBps)) / 10000n : 0n;
47
+ // ✅ 获取贿赂金额
48
+ const bribeAmount = getBribeAmount(config);
49
+ const needBribeTx = bribeAmount > 0n;
50
+ // ✅ 优化:第三批并行 - 构建交易、获取 nonces
51
+ const tmSeller = new Contract(TM_ADDRESS, TM_ABI, seller);
52
+ const tmBuyer = new Contract(TM_ADDRESS, TM_ABI, buyer);
53
+ const sellerNonceCount = countSellerNonceSlots(needBribeTx, needApproval, extractProfit);
54
+ // ✅ 优化:使用批量 nonce 获取(JSON-RPC 批量请求)
55
+ // 如果前端传入了 startNonces,直接使用;否则从链上获取
56
+ const [sellUnsigned, buyUnsigned, noncesResult] = await Promise.all([
57
+ tmSeller.sellToken.populateTransaction(0n, tokenAddress, sellAmountWei, 0n),
58
+ tmBuyer.buyTokenAMAP.populateTransaction(0n, tokenAddress, buyer.address, buyerFunds, 0n, { value: buyerFunds }),
59
+ (async () => {
60
+ // ✅ 如果前端传入了 startNonces,直接使用(性能优化)
61
+ if (startNonces && startNonces.length >= 2) {
62
+ const sellerNonces = Array.from({ length: sellerNonceCount }, (_, i) => startNonces[0] + i);
63
+ const buyerNonce = startNonces[1];
64
+ return { sellerNonces, buyerNonce };
65
+ }
66
+ // 否则从链上获取
67
+ const initialNonces = await nonceManager.getNextNoncesForWallets([seller, buyer]);
68
+ const sellerNonces = Array.from({ length: sellerNonceCount }, (_, i) => initialNonces[0] + i);
69
+ const buyerNonce = initialNonces[1];
70
+ return { sellerNonces, buyerNonce };
71
+ })(),
72
+ ]);
73
+ const { sellerNonces, buyerNonce } = noncesResult;
74
+ const noncePlan = planSellerNonces(sellerNonces, needBribeTx, needApproval, extractProfit);
75
+ const signPromises = [];
76
+ if (needBribeTx && noncePlan.bribeNonce !== undefined) {
77
+ signPromises.push(signBribeTransaction(seller, bribeAmount, noncePlan.bribeNonce, gasPrice, chainIdNum, txType));
78
+ }
79
+ if (needApproval && noncePlan.approvalNonce !== undefined) {
80
+ signPromises.push(signTmMaxApprovalTx(seller, tokenAddress, noncePlan.approvalNonce, gasPrice, chainIdNum, txType));
81
+ }
82
+ signPromises.push(seller.signTransaction({
83
+ ...sellUnsigned,
84
+ from: seller.address,
85
+ nonce: noncePlan.sellerNonce,
86
+ gasLimit: finalGasLimit,
87
+ gasPrice,
88
+ chainId: chainIdNum,
89
+ type: txType,
90
+ }), buyer.signTransaction({
91
+ ...buyUnsigned,
92
+ from: buyer.address,
93
+ nonce: buyerNonce,
94
+ gasLimit: finalGasLimit,
95
+ gasPrice,
96
+ chainId: chainIdNum,
97
+ type: txType,
98
+ value: buyerFunds,
99
+ }));
100
+ const signedTxs = await Promise.all(signPromises);
101
+ let signIdx = 0;
102
+ let bribeTx = null;
103
+ let approvalTx = null;
104
+ if (needBribeTx)
105
+ bribeTx = signedTxs[signIdx++];
106
+ if (needApproval)
107
+ approvalTx = signedTxs[signIdx++];
108
+ const signedSell = signedTxs[signIdx++];
109
+ const signedBuy = signedTxs[signIdx];
110
+ const profitNonce = noncePlan.profitNonce;
111
+ nonceManager.clearTemp();
112
+ // ✅ 组装交易列表:贿赂 → 授权 → 卖出 → 买入
113
+ const allTransactions = [];
114
+ if (bribeTx)
115
+ allTransactions.push(bribeTx);
116
+ if (approvalTx)
117
+ allTransactions.push(approvalTx);
118
+ allTransactions.push(signedSell, signedBuy);
119
+ // ✅ 利润多跳转账(强制 2 跳中转)
120
+ let profitHopWallets;
121
+ if (extractProfit && profitAmount > 0n && profitNonce !== undefined) {
122
+ const profitHopResult = await buildProfitHopTransactions({
123
+ provider,
124
+ payerWallet: seller,
125
+ profitAmount: profitAmount,
126
+ profitRecipient: getProfitRecipient(),
127
+ hopCount: PROFIT_HOP_COUNT,
128
+ gasPrice,
129
+ chainId: chainIdNum,
130
+ txType,
131
+ startNonce: profitNonce,
132
+ });
133
+ allTransactions.push(...profitHopResult.signedTransactions);
134
+ profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
135
+ }
136
+ return {
137
+ signedTransactions: allTransactions,
138
+ profitHopWallets, // ✅ 导出利润多跳钱包
139
+ metadata: {
140
+ sellerAddress: seller.address,
141
+ buyerAddress: buyer.address,
142
+ sellAmount: ethers.formatUnits(sellAmountWei, decimals),
143
+ buyAmount: ethers.formatEther(buyerFunds),
144
+ hasApproval: !!approvalTx,
145
+ profitAmount: extractProfit ? ethers.formatEther(profitAmount) : undefined,
146
+ },
147
+ };
148
+ }
149
+ // ==================== 批量换手(一卖多买)====================
150
+ /**
151
+ * Four 内盘批量换手(一卖多买)
152
+ */
153
+ export async function fourBatchSwapMerkle(params) {
154
+ const { sellerPrivateKey, sellAmount, sellPercentage, buyerPrivateKeys, tokenAddress, config, startNonces, // ✅ 可选:前端预获取的 nonces
155
+ } = params;
156
+ // ✅ 校验买方数量(最多 24 个)
157
+ const MAX_BUYERS = 24;
158
+ if (buyerPrivateKeys.length === 0) {
159
+ throw new Error('至少需要一个买方钱包');
160
+ }
161
+ if (buyerPrivateKeys.length > MAX_BUYERS) {
162
+ throw new Error(`买方钱包数量超过限制: ${buyerPrivateKeys.length} > ${MAX_BUYERS}`);
163
+ }
164
+ const { chainIdNum, provider, bundleConfig, finalGasLimit, txType } = createFourSwapGasContext(config);
165
+ const seller = new Wallet(sellerPrivateKey, provider);
166
+ const buyers = buyerPrivateKeys.map((pk) => new Wallet(pk, provider));
167
+ const nonceManager = new NonceManager(provider);
168
+ // ✅ 并行获取:卖出数量、gasPrice
169
+ const [sellAmountResult, gasPrice] = await Promise.all([
170
+ calculateSellAmount(provider, tokenAddress, seller.address, sellAmount, sellPercentage),
171
+ getOptimizedGasPrice(provider, getGasPriceConfig(bundleConfig)),
172
+ ]);
173
+ const { amount: sellAmountWei, decimals } = sellAmountResult;
174
+ const { sellFunds: totalBuyerFunds, allowance: currentAllowance, buyerBalances, } = await fetchFourSwapSellQuoteAllowanceAndBalances(provider, tokenAddress, seller.address, sellAmountWei, buyers.map((b) => b.address));
175
+ // ✅ 计算每个买方的买入金额(按比例分配)
176
+ let buyAmountsWei;
177
+ if (params.buyerRatios && params.buyerRatios.length === buyers.length) {
178
+ // 按比例分配
179
+ buyAmountsWei = params.buyerRatios.map((ratio) => {
180
+ const amount = (totalBuyerFunds * BigInt(Math.round(ratio * 10000))) / 10000n;
181
+ return amount;
182
+ });
183
+ }
184
+ else {
185
+ // 平均分配
186
+ const amountPerBuyer = totalBuyerFunds / BigInt(buyers.length);
187
+ buyAmountsWei = buyers.map(() => amountPerBuyer);
188
+ }
189
+ // ✅ 验证所有买方余额
190
+ const reserveGas = ethers.parseEther((config.reserveGasBNB || 0.0005).toString());
191
+ buyers.forEach((buyer, i) => {
192
+ const required = buyAmountsWei[i] + reserveGas;
193
+ if (buyerBalances[i] < required) {
194
+ throw new Error(`买方 ${i + 1} 余额不足: 需要 ${ethers.formatEther(required)} BNB, 实际 ${ethers.formatEther(buyerBalances[i])} BNB`);
195
+ }
196
+ });
197
+ // 检查是否需要授权
198
+ const needApproval = needsTmTokenApproval(currentAllowance, decimals);
199
+ // 利润配置
200
+ const profitRateBps = getFourSwapProfitRateBps(config.userType);
201
+ const profitAmount = totalBuyerFunds > 0n ? (totalBuyerFunds * BigInt(profitRateBps)) / 10000n : 0n;
202
+ // ✅ 获取贿赂金额
203
+ const bribeAmount = getBribeAmount(config);
204
+ const needBribeTx = bribeAmount > 0n;
205
+ // ✅ 并行构建所有交易
206
+ const tmSeller = new Contract(TM_ADDRESS, TM_ABI, seller);
207
+ const [sellUnsigned, ...buyUnsignedList] = await Promise.all([
208
+ // 卖出交易
209
+ tmSeller.sellToken.populateTransaction(0n, tokenAddress, sellAmountWei, 0n),
210
+ // 所有买入交易
211
+ ...buyers.map((buyer, i) => {
212
+ const tmBuyer = new Contract(TM_ADDRESS, TM_ABI, buyer);
213
+ const buyAmount = buyAmountsWei[i];
214
+ return tmBuyer.buyTokenAMAP.populateTransaction(0n, tokenAddress, buyer.address, buyAmount, 0n, {
215
+ value: buyAmount,
216
+ });
217
+ }),
218
+ ]);
219
+ const sellerNonceCount = countSellerNonceSlots(needBribeTx, needApproval, true);
220
+ // ✅ 如果前端传入了 startNonces,直接使用(性能优化)
221
+ // 否则从链上获取
222
+ const allWallets = [seller, ...buyers];
223
+ const initialNonces = startNonces && startNonces.length >= allWallets.length
224
+ ? startNonces
225
+ : await nonceManager.getNextNoncesForWallets(allWallets);
226
+ // 分配 seller nonces
227
+ const sellerNonces = Array.from({ length: sellerNonceCount }, (_, i) => initialNonces[0] + i);
228
+ const noncePlan = planSellerNonces(sellerNonces, needBribeTx, needApproval, true);
229
+ const profitNonce = noncePlan.profitNonce;
230
+ const buyerNonces = initialNonces.slice(1);
231
+ const signPromises = [];
232
+ if (needBribeTx && noncePlan.bribeNonce !== undefined) {
233
+ signPromises.push(signBribeTransaction(seller, bribeAmount, noncePlan.bribeNonce, gasPrice, chainIdNum, txType));
234
+ }
235
+ if (needApproval && noncePlan.approvalNonce !== undefined) {
236
+ signPromises.push(signTmMaxApprovalTx(seller, tokenAddress, noncePlan.approvalNonce, gasPrice, chainIdNum, txType));
237
+ }
238
+ signPromises.push(seller.signTransaction({
239
+ ...sellUnsigned,
240
+ from: seller.address,
241
+ nonce: noncePlan.sellerNonce,
242
+ gasLimit: finalGasLimit,
243
+ gasPrice,
244
+ chainId: chainIdNum,
245
+ type: txType,
246
+ }));
247
+ // 所有买入交易
248
+ buyers.forEach((buyer, i) => {
249
+ signPromises.push(buyer.signTransaction({
250
+ ...buyUnsignedList[i],
251
+ from: buyer.address,
252
+ nonce: buyerNonces[i],
253
+ gasLimit: finalGasLimit,
254
+ gasPrice,
255
+ chainId: chainIdNum,
256
+ type: txType,
257
+ value: buyAmountsWei[i],
258
+ }));
259
+ });
260
+ const signedTxs = await Promise.all(signPromises);
261
+ // 解析签名结果
262
+ let signIdx = 0;
263
+ let bribeTx = null;
264
+ let approvalTx = null;
265
+ if (needBribeTx)
266
+ bribeTx = signedTxs[signIdx++];
267
+ if (needApproval)
268
+ approvalTx = signedTxs[signIdx++];
269
+ const signedSell = signedTxs[signIdx++];
270
+ const signedBuys = signedTxs.slice(signIdx, signIdx + buyers.length);
271
+ nonceManager.clearTemp();
272
+ // ✅ 按顺序组装交易数组:贿赂 → 授权 → 卖出 → 买入
273
+ const signedTransactions = [];
274
+ if (bribeTx)
275
+ signedTransactions.push(bribeTx);
276
+ if (approvalTx)
277
+ signedTransactions.push(approvalTx);
278
+ signedTransactions.push(signedSell);
279
+ signedTransactions.push(...signedBuys);
280
+ // ✅ 利润多跳转账(强制 2 跳中转)
281
+ let profitHopWallets;
282
+ if (profitAmount > 0n) {
283
+ const profitHopResult = await buildProfitHopTransactions({
284
+ provider,
285
+ payerWallet: seller,
286
+ profitAmount: profitAmount,
287
+ profitRecipient: getProfitRecipient(),
288
+ hopCount: PROFIT_HOP_COUNT,
289
+ gasPrice,
290
+ chainId: chainIdNum,
291
+ txType,
292
+ startNonce: profitNonce,
293
+ });
294
+ signedTransactions.push(...profitHopResult.signedTransactions);
295
+ profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
296
+ }
297
+ return {
298
+ signedTransactions,
299
+ profitHopWallets, // ✅ 导出利润多跳钱包
300
+ metadata: {
301
+ sellerAddress: seller.address,
302
+ buyerAddresses: buyers.map((b) => b.address),
303
+ sellAmount: ethers.formatUnits(sellAmountWei, decimals),
304
+ buyAmounts: buyAmountsWei.map((amt) => ethers.formatEther(amt)),
305
+ hasApproval: !!approvalTx,
306
+ profitAmount: ethers.formatEther(profitAmount),
307
+ },
308
+ };
309
+ }
310
+ // ==================== 快捷批量换手(资金利用率模式)====================
311
+ /**
312
+ * Four 内盘快捷批量换手(资金利用率模式)
313
+ */
314
+ export async function fourQuickBatchSwapMerkle(params) {
315
+ const { sellerPrivateKey, sellAmount, sellPercentage, buyerPrivateKeys, buyerRatios, buyerAmounts, tokenAddress, config, disperseHopCount = 0, // ✅ 转账多跳数(默认0=直接转账)
316
+ startNonces, // ✅ 可选:前端预获取的 nonces
317
+ } = params;
318
+ // ✅ 动态计算最大买方数量(根据多跳数)
319
+ // 固定开销: 贿赂(1) + 卖出(1) + 利润多跳(PROFIT_HOP_COUNT + 1)
320
+ // 转账(N*(H+1)) + 买入(N) = N*(H+2)
321
+ const fixedOverhead = 1 + 1 + PROFIT_HOP_COUNT + 1;
322
+ const maxTxs = 50 - fixedOverhead;
323
+ let MAX_BUYERS = Math.floor(maxTxs / (disperseHopCount + 2));
324
+ MAX_BUYERS = Math.max(1, MAX_BUYERS);
325
+ if (buyerPrivateKeys.length === 0) {
326
+ throw new Error('至少需要一个买方钱包');
327
+ }
328
+ if (buyerPrivateKeys.length > MAX_BUYERS) {
329
+ throw new Error(`资金利用率模式(${disperseHopCount}跳)买方钱包数量超过限制: ${buyerPrivateKeys.length} > ${MAX_BUYERS}`);
330
+ }
331
+ // ✅ 校验分配模式
332
+ if (!buyerRatios && !buyerAmounts) {
333
+ throw new Error('必须提供 buyerRatios 或 buyerAmounts');
334
+ }
335
+ if (buyerRatios && buyerRatios.length !== buyerPrivateKeys.length) {
336
+ throw new Error(`buyerRatios 长度 (${buyerRatios.length}) 与 buyerPrivateKeys 长度 (${buyerPrivateKeys.length}) 不匹配`);
337
+ }
338
+ if (buyerAmounts && buyerAmounts.length !== buyerPrivateKeys.length) {
339
+ throw new Error(`buyerAmounts 长度 (${buyerAmounts.length}) 与 buyerPrivateKeys 长度 (${buyerPrivateKeys.length}) 不匹配`);
340
+ }
341
+ const { chainIdNum, provider, bundleConfig, finalGasLimit, txType } = createFourSwapGasContext(config);
342
+ const seller = new Wallet(sellerPrivateKey, provider);
343
+ const buyers = buyerPrivateKeys.map((pk) => new Wallet(pk, provider));
344
+ const nonceManager = new NonceManager(provider);
345
+ // ✅ 并行获取:卖出数量、gasPrice
346
+ const [sellAmountResult, gasPrice] = await Promise.all([
347
+ calculateSellAmount(provider, tokenAddress, seller.address, sellAmount, sellPercentage),
348
+ getOptimizedGasPrice(provider, getGasPriceConfig(bundleConfig)),
349
+ ]);
350
+ const { amount: sellAmountWei, decimals } = sellAmountResult;
351
+ const estimatedBNBOut = await quoteFourSwapSellFunds(provider, tokenAddress, sellAmountWei);
352
+ // ✅ 计算利润(根据 userType 动态调整)
353
+ const profitRateBps = getFourSwapProfitRateBps(config.userType);
354
+ const profitAmount = estimatedBNBOut > 0n ? (estimatedBNBOut * BigInt(profitRateBps)) / 10000n : 0n;
355
+ const distributableAmount = estimatedBNBOut - profitAmount;
356
+ // ✅ 计算每个买方分到的金额
357
+ let transferAmountsWei;
358
+ if (buyerAmounts && buyerAmounts.length === buyers.length) {
359
+ // 数量模式
360
+ transferAmountsWei = buyerAmounts.map((amt) => ethers.parseEther(amt));
361
+ const totalTransfer = transferAmountsWei.reduce((a, b) => a + b, 0n);
362
+ if (totalTransfer > distributableAmount) {
363
+ throw new Error(`指定的买入总金额超过可分配金额 (${ethers.formatEther(distributableAmount)} BNB)`);
364
+ }
365
+ }
366
+ else if (buyerRatios && buyerRatios.length === buyers.length) {
367
+ // 比例模式
368
+ transferAmountsWei = buyerRatios.map((ratio) => {
369
+ return (distributableAmount * BigInt(Math.round(ratio * 10000))) / 10000n;
370
+ });
371
+ }
372
+ else {
373
+ throw new Error('必须提供 buyerRatios 或 buyerAmounts');
374
+ }
375
+ // ✅ 获取贿赂金额
376
+ const bribeAmount = getBribeAmount(config);
377
+ // ✅ 验证主钱包余额
378
+ const sellerBalance = await seller.provider.getBalance(seller.address);
379
+ // 主钱包只需要支付:贿赂 + Gas(卖出后有 BNB 可用于转账和利润)
380
+ const sellerGasCost = gasPrice * (21000n + finalGasLimit + 21000n * BigInt(buyers.length) + 21000n);
381
+ const sellerRequired = bribeAmount + sellerGasCost;
382
+ if (sellerBalance < sellerRequired) {
383
+ throw new Error(`主钱包 BNB 余额不足: 需要约 ${ethers.formatEther(sellerRequired)} BNB (贿赂: ${ethers.formatEther(bribeAmount)}, Gas: ${ethers.formatEther(sellerGasCost)}), 实际 ${ethers.formatEther(sellerBalance)} BNB`);
384
+ }
385
+ // ==================== 规划 Nonce ====================
386
+ // ✅ 如果前端传入了 startNonces,直接使用(性能优化)
387
+ let sellerNonce = startNonces && startNonces.length > 0 ? startNonces[0] : await nonceManager.getNextNonce(seller);
388
+ // ==================== 1. 贿赂交易 ====================
389
+ let bribeTx = null;
390
+ if (bribeAmount > 0n) {
391
+ bribeTx = await signBribeTransaction(seller, bribeAmount, sellerNonce, gasPrice, chainIdNum, txType);
392
+ sellerNonce++;
393
+ }
394
+ // ==================== 2. 卖出交易 ====================
395
+ const tmSeller = new Contract(TM_ADDRESS, TM_ABI, seller);
396
+ const sellUnsigned = await tmSeller.sellToken.populateTransaction(0n, tokenAddress, sellAmountWei, 0n);
397
+ const signedSell = await seller.signTransaction({
398
+ ...sellUnsigned,
399
+ from: seller.address,
400
+ nonce: sellerNonce++,
401
+ gasLimit: finalGasLimit,
402
+ gasPrice,
403
+ chainId: chainIdNum,
404
+ type: txType,
405
+ });
406
+ // ==================== 3. 转账交易(支持多跳)====================
407
+ const reserveGas = ethers.parseEther((config.reserveGasBNB || 0.0005).toString());
408
+ const buyerGasCost = gasPrice * finalGasLimit;
409
+ // ✅ 生成多跳路径
410
+ const hopPaths = generateDisperseHopPaths(buyers.map((b) => b.address), disperseHopCount, provider);
411
+ // 收集所有中间钱包信息
412
+ const allHopWallets = [];
413
+ hopPaths.forEach((path) => {
414
+ allHopWallets.push(...path.hopWalletsInfo);
415
+ });
416
+ let transferTxs;
417
+ if (disperseHopCount === 0) {
418
+ // ✅ 无多跳:直接转账
419
+ const transferNonces = buyers.map((_, i) => sellerNonce + i);
420
+ sellerNonce += buyers.length;
421
+ transferTxs = await Promise.all(buyers.map((buyer, i) => {
422
+ const transferValue = transferAmountsWei[i] + reserveGas + buyerGasCost;
423
+ return seller.signTransaction({
424
+ to: buyer.address,
425
+ value: transferValue,
426
+ nonce: transferNonces[i],
427
+ gasPrice,
428
+ gasLimit: NATIVE_TRANSFER_GAS_LIMIT,
429
+ chainId: chainIdNum,
430
+ type: txType,
431
+ });
432
+ }));
433
+ }
434
+ else {
435
+ // ✅ 有多跳:构建多跳转账链
436
+ // ✅ 修复:payer 每次只发送 1 笔交易(到第一个hop钱包),hop钱包用自己的nonce=0
437
+ const hopChains = await Promise.all(hopPaths.map((path, i) => {
438
+ const finalAmount = transferAmountsWei[i] + reserveGas + buyerGasCost;
439
+ const payerNonce = sellerNonce + i; // ✅ payer 每个 buyer 只用 1 个 nonce
440
+ return buildNativeHopChain(seller, path, finalAmount, gasPrice, chainIdNum, txType, payerNonce);
441
+ }));
442
+ transferTxs = hopChains.flat();
443
+ sellerNonce += buyers.length; // ✅ payer 只增加 buyers.length 个 nonce
444
+ }
445
+ // ==================== 4. 买入交易 ====================
446
+ // ✅ 如果前端传入了 startNonces,使用 buyer 部分(从索引 1 开始)
447
+ const buyerNonces = startNonces && startNonces.length > 1
448
+ ? startNonces.slice(1)
449
+ : await Promise.all(buyers.map((buyer) => nonceManager.getNextNonce(buyer)));
450
+ const signedBuys = await Promise.all(buyers.map(async (buyer, i) => {
451
+ const buyAmount = transferAmountsWei[i];
452
+ const tmBuyer = new Contract(TM_ADDRESS, TM_ABI, buyer);
453
+ const buyUnsigned = await tmBuyer.buyTokenAMAP.populateTransaction(0n, tokenAddress, buyer.address, buyAmount, 0n, { value: buyAmount });
454
+ return buyer.signTransaction({
455
+ ...buyUnsigned,
456
+ from: buyer.address,
457
+ nonce: buyerNonces[i],
458
+ gasLimit: finalGasLimit,
459
+ gasPrice,
460
+ chainId: chainIdNum,
461
+ type: txType,
462
+ value: buyAmount,
463
+ });
464
+ }));
465
+ nonceManager.clearTemp();
466
+ // ==================== 组装交易数组 ====================
467
+ const signedTransactions = [];
468
+ if (bribeTx)
469
+ signedTransactions.push(bribeTx);
470
+ signedTransactions.push(signedSell);
471
+ signedTransactions.push(...transferTxs);
472
+ signedTransactions.push(...signedBuys);
473
+ // ==================== 5. 利润多跳转账(强制 2 跳中转)====================
474
+ let profitHopWallets;
475
+ if (profitAmount > 0n) {
476
+ const profitHopResult = await buildProfitHopTransactions({
477
+ provider,
478
+ payerWallet: seller,
479
+ profitAmount: profitAmount,
480
+ profitRecipient: getProfitRecipient(),
481
+ hopCount: PROFIT_HOP_COUNT,
482
+ gasPrice,
483
+ chainId: chainIdNum,
484
+ txType,
485
+ startNonce: sellerNonce++,
486
+ });
487
+ signedTransactions.push(...profitHopResult.signedTransactions);
488
+ profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
489
+ // 多跳交易已签名
490
+ }
491
+ return {
492
+ signedTransactions,
493
+ disperseHopWallets: allHopWallets.length > 0 ? allHopWallets : undefined, // ✅ 返回转账多跳钱包
494
+ profitHopWallets, // ✅ 返回利润多跳钱包
495
+ metadata: {
496
+ sellerAddress: seller.address,
497
+ buyerAddresses: buyers.map((b) => b.address),
498
+ sellAmount: ethers.formatUnits(sellAmountWei, decimals),
499
+ estimatedBNBOut: ethers.formatEther(estimatedBNBOut),
500
+ transferAmounts: transferAmountsWei.map((amt) => ethers.formatEther(amt)),
501
+ profitAmount: profitAmount > 0n ? ethers.formatEther(profitAmount) : undefined,
502
+ disperseHopCount: disperseHopCount > 0 ? disperseHopCount : undefined, // ✅ 返回多跳数
503
+ },
504
+ };
505
+ }
@@ -0,0 +1,50 @@
1
+ import type { CommonBundleConfig } from '../../../utils/bundle-helpers.js';
2
+ import type { GeneratedWallet } from '../../../utils/wallet.js';
3
+ import type { FourSignConfig, UserType } from './index.js';
4
+ export type FourBuyFirstSignConfig = FourSignConfig & {
5
+ reserveGasBNB?: number;
6
+ userType?: UserType;
7
+ };
8
+ export type FourBuyFirstConfig = CommonBundleConfig & {
9
+ apiKey: string;
10
+ customRpcUrl?: string;
11
+ bundleBlockOffset?: number;
12
+ reserveGasBNB?: number;
13
+ waitForConfirmation?: boolean;
14
+ waitTimeoutMs?: number;
15
+ };
16
+ export type FourBundleBuyFirstSignParams = {
17
+ buyerPrivateKey?: string;
18
+ buyerPrivateKeys?: string[];
19
+ buyerFunds?: string;
20
+ buyerFundsPercentage?: number;
21
+ sellerPrivateKey?: string;
22
+ sellerPrivateKeys?: string[];
23
+ tokenAddress: string;
24
+ config: FourBuyFirstSignConfig;
25
+ buyCount?: number;
26
+ sellCount?: number;
27
+ };
28
+ export type FourBundleBuyFirstParams = {
29
+ buyerPrivateKey: string;
30
+ buyerFunds?: string;
31
+ buyerFundsPercentage?: number;
32
+ sellerPrivateKey: string;
33
+ tokenAddress: string;
34
+ config: FourBuyFirstConfig;
35
+ };
36
+ export type FourBuyFirstResult = {
37
+ signedTransactions: string[];
38
+ profitHopWallets?: GeneratedWallet[];
39
+ metadata?: {
40
+ buyerAddress: string;
41
+ sellerAddress: string;
42
+ buyAmount: string;
43
+ sellAmount: string;
44
+ profitAmount?: string;
45
+ buyCount?: number;
46
+ sellCount?: number;
47
+ buyAmounts?: string[];
48
+ sellAmounts?: string[];
49
+ };
50
+ };
@@ -0,0 +1 @@
1
+ export {};