four-flap-meme-sdk 3.0.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (442) hide show
  1. package/dist/bundle/four-meme/approve-tokenmanager.d.ts +2 -2
  2. package/dist/bundle/four-meme/approve-tokenmanager.js +3 -3
  3. package/dist/bundle/four-meme/core/buy-flow.d.ts +5 -0
  4. package/dist/bundle/four-meme/core/buy-flow.js +147 -0
  5. package/dist/bundle/four-meme/core/constants.d.ts +6 -0
  6. package/dist/bundle/four-meme/core/constants.js +15 -0
  7. package/dist/bundle/four-meme/core/create-token.d.ts +5 -0
  8. package/dist/bundle/four-meme/core/create-token.js +137 -0
  9. package/dist/bundle/four-meme/core/index.d.ts +14 -0
  10. package/dist/bundle/four-meme/core/index.js +14 -0
  11. package/dist/bundle/four-meme/core/sell-flow.d.ts +5 -0
  12. package/dist/bundle/four-meme/core/sell-flow.js +240 -0
  13. package/dist/bundle/four-meme/core-helpers.js +1 -1
  14. package/dist/bundle/four-meme/core.d.ts +7 -4
  15. package/dist/bundle/four-meme/core.js +5 -513
  16. package/dist/bundle/four-meme/pancake-proxy/approve.d.ts +15 -0
  17. package/dist/bundle/four-meme/pancake-proxy/approve.js +113 -0
  18. package/dist/bundle/four-meme/pancake-proxy/buy.d.ts +8 -0
  19. package/dist/bundle/four-meme/pancake-proxy/buy.js +143 -0
  20. package/dist/bundle/four-meme/pancake-proxy/constants.d.ts +25 -0
  21. package/dist/bundle/four-meme/pancake-proxy/constants.js +14 -0
  22. package/dist/bundle/four-meme/pancake-proxy/helpers.d.ts +45 -0
  23. package/dist/bundle/four-meme/pancake-proxy/helpers.js +232 -0
  24. package/dist/bundle/four-meme/pancake-proxy/index.d.ts +15 -0
  25. package/dist/bundle/four-meme/pancake-proxy/index.js +15 -0
  26. package/dist/bundle/four-meme/pancake-proxy/sell.d.ts +8 -0
  27. package/dist/bundle/four-meme/pancake-proxy/sell.js +194 -0
  28. package/dist/bundle/four-meme/pancake-proxy.d.ts +4 -20
  29. package/dist/bundle/four-meme/pancake-proxy.js +3 -670
  30. package/dist/bundle/four-meme/private/buy.d.ts +16 -0
  31. package/dist/bundle/four-meme/private/buy.js +225 -0
  32. package/dist/bundle/four-meme/private/index.d.ts +11 -0
  33. package/dist/bundle/four-meme/private/index.js +11 -0
  34. package/dist/bundle/four-meme/private/sell.d.ts +18 -0
  35. package/dist/bundle/four-meme/private/sell.js +245 -0
  36. package/dist/bundle/four-meme/private.d.ts +5 -25
  37. package/dist/bundle/four-meme/private.js +5 -463
  38. package/dist/bundle/four-meme/swap/batch.d.ts +8 -0
  39. package/dist/bundle/four-meme/swap/batch.js +170 -0
  40. package/dist/bundle/four-meme/swap/bundle.d.ts +8 -0
  41. package/dist/bundle/four-meme/swap/bundle.js +147 -0
  42. package/dist/bundle/four-meme/swap/index.d.ts +14 -0
  43. package/dist/bundle/four-meme/swap/index.js +13 -0
  44. package/dist/bundle/four-meme/swap/quick-batch.d.ts +8 -0
  45. package/dist/bundle/four-meme/swap/quick-batch.js +206 -0
  46. package/dist/bundle/four-meme/swap-buy-first/helpers.d.ts +20 -0
  47. package/dist/bundle/four-meme/swap-buy-first/helpers.js +39 -0
  48. package/dist/bundle/four-meme/swap-buy-first/index.d.ts +12 -0
  49. package/dist/bundle/four-meme/swap-buy-first/index.js +11 -0
  50. package/dist/bundle/four-meme/swap-buy-first/multi-wallet.d.ts +20 -0
  51. package/dist/bundle/four-meme/swap-buy-first/multi-wallet.js +198 -0
  52. package/dist/bundle/four-meme/swap-buy-first/single.d.ts +7 -0
  53. package/dist/bundle/four-meme/swap-buy-first/single.js +232 -0
  54. package/dist/bundle/four-meme/swap-buy-first.d.ts +4 -3
  55. package/dist/bundle/four-meme/swap-buy-first.js +4 -451
  56. package/dist/bundle/four-meme/swap-hop-helpers.d.ts +2 -2
  57. package/dist/bundle/four-meme/swap-sign-helpers.d.ts +2 -2
  58. package/dist/bundle/four-meme/swap-sign-helpers.js +1 -1
  59. package/dist/bundle/four-meme/swap.d.ts +4 -14
  60. package/dist/bundle/four-meme/swap.js +4 -502
  61. package/dist/bundle/four-meme/types/index.d.ts +1 -1
  62. package/dist/bundle/four-meme/utils-disperse.d.ts +1 -1
  63. package/dist/bundle/four-meme/utils-disperse.js +1 -1
  64. package/dist/bundle/four-meme/utils-pairwise.d.ts +1 -1
  65. package/dist/bundle/four-meme/utils-pairwise.js +1 -1
  66. package/dist/bundle/four-meme/utils-sweep/context.d.ts +39 -0
  67. package/dist/bundle/four-meme/utils-sweep/context.js +7 -0
  68. package/dist/bundle/four-meme/utils-sweep/erc20-no-hop.d.ts +5 -0
  69. package/dist/bundle/four-meme/utils-sweep/erc20-no-hop.js +162 -0
  70. package/dist/bundle/four-meme/utils-sweep/index.d.ts +13 -0
  71. package/dist/bundle/four-meme/utils-sweep/index.js +13 -0
  72. package/dist/bundle/four-meme/utils-sweep/main.d.ts +8 -0
  73. package/dist/bundle/four-meme/utils-sweep/main.js +114 -0
  74. package/dist/bundle/four-meme/utils-sweep/native-no-hop.d.ts +5 -0
  75. package/dist/bundle/four-meme/utils-sweep/native-no-hop.js +156 -0
  76. package/dist/bundle/four-meme/utils-sweep/with-hops.d.ts +6 -0
  77. package/dist/bundle/four-meme/utils-sweep/with-hops.js +382 -0
  78. package/dist/bundle/four-meme/utils-sweep.d.ts +3 -4
  79. package/dist/bundle/four-meme/utils-sweep.js +3 -740
  80. package/dist/bundle/internal.d.ts +2 -2
  81. package/dist/bundle/sign-context-helpers.d.ts +1 -26
  82. package/dist/bundle/sign-context-helpers.js +1 -63
  83. package/dist/bundle/submit/blockrazor.d.ts +94 -0
  84. package/dist/bundle/submit/blockrazor.js +122 -0
  85. package/dist/bundle/submit/direct.d.ts +118 -0
  86. package/dist/bundle/submit/direct.js +484 -0
  87. package/dist/bundle/submit/helpers.d.ts +7 -0
  88. package/dist/bundle/submit/helpers.js +15 -0
  89. package/dist/bundle/submit/index.d.ts +14 -0
  90. package/dist/bundle/submit/index.js +14 -0
  91. package/dist/bundle/submit/merkle.d.ts +84 -0
  92. package/dist/bundle/submit/merkle.js +121 -0
  93. package/dist/bundle/submit.d.ts +3 -286
  94. package/dist/bundle/submit.js +3 -724
  95. package/dist/chains/bsc/four/types.d.ts +1 -1
  96. package/dist/chains/bsc/pancake/bundle-buy-first-build.d.ts +25 -0
  97. package/dist/chains/bsc/pancake/bundle-buy-first-build.js +177 -0
  98. package/dist/chains/bsc/pancake/bundle-buy-first-constants.d.ts +30 -0
  99. package/dist/chains/bsc/pancake/bundle-buy-first-constants.js +24 -0
  100. package/dist/chains/bsc/pancake/bundle-buy-first-helpers.d.ts +11 -149
  101. package/dist/chains/bsc/pancake/bundle-buy-first-helpers.js +12 -74
  102. package/dist/chains/bsc/pancake/bundle-buy-first-multi-wallet.d.ts +9 -0
  103. package/dist/chains/bsc/pancake/bundle-buy-first-multi-wallet.js +225 -0
  104. package/dist/chains/bsc/pancake/bundle-buy-first-plan.d.ts +14 -0
  105. package/dist/chains/bsc/pancake/bundle-buy-first-plan.js +64 -0
  106. package/dist/chains/bsc/pancake/bundle-buy-first-profit.d.ts +12 -0
  107. package/dist/chains/bsc/pancake/bundle-buy-first-profit.js +22 -0
  108. package/dist/chains/bsc/pancake/bundle-buy-first-quote.d.ts +15 -0
  109. package/dist/chains/bsc/pancake/bundle-buy-first-quote.js +122 -0
  110. package/dist/chains/bsc/pancake/bundle-buy-first-types.d.ts +179 -0
  111. package/dist/chains/bsc/pancake/bundle-buy-first-types.js +1 -0
  112. package/dist/chains/bsc/pancake/bundle-buy-first-validate.d.ts +2 -0
  113. package/dist/chains/bsc/pancake/bundle-buy-first-validate.js +41 -0
  114. package/dist/chains/bsc/pancake/bundle-buy-first.d.ts +1 -1
  115. package/dist/chains/bsc/pancake/bundle-buy-first.js +8 -578
  116. package/dist/chains/bsc/pancake/bundle-swap-helpers.d.ts +11 -239
  117. package/dist/chains/bsc/pancake/bundle-swap-helpers.js +12 -564
  118. package/dist/chains/bsc/pancake/bundle-swap-types.d.ts +183 -0
  119. package/dist/chains/bsc/pancake/bundle-swap-types.js +17 -0
  120. package/dist/chains/bsc/pancake/bundle-swap.d.ts +10 -132
  121. package/dist/chains/bsc/pancake/bundle-swap.js +12 -1003
  122. package/dist/chains/bsc/pancake/hop-chain.d.ts +18 -0
  123. package/dist/chains/bsc/pancake/hop-chain.js +227 -0
  124. package/dist/chains/bsc/pancake/quote.d.ts +14 -0
  125. package/dist/chains/bsc/pancake/quote.js +84 -0
  126. package/dist/chains/bsc/pancake/swap-batch.d.ts +42 -0
  127. package/dist/chains/bsc/pancake/swap-batch.js +283 -0
  128. package/dist/chains/bsc/pancake/swap-build.d.ts +19 -0
  129. package/dist/chains/bsc/pancake/swap-build.js +226 -0
  130. package/dist/chains/bsc/pancake/swap-cross.d.ts +42 -0
  131. package/dist/chains/bsc/pancake/swap-cross.js +140 -0
  132. package/dist/chains/bsc/pancake/swap-quick.d.ts +54 -0
  133. package/dist/chains/bsc/pancake/swap-quick.js +424 -0
  134. package/dist/chains/bsc/pancake/swap-single.d.ts +2 -0
  135. package/dist/chains/bsc/pancake/swap-single.js +182 -0
  136. package/dist/chains/bsc/platforms/four/index.d.ts +21 -3
  137. package/dist/chains/bsc/platforms/four/index.js +28 -3
  138. package/dist/chains/eni/batch-router/transfer-disperse.d.ts +37 -0
  139. package/dist/chains/eni/batch-router/transfer-disperse.js +302 -0
  140. package/dist/chains/eni/batch-router/transfer-shared.d.ts +9 -0
  141. package/dist/chains/eni/batch-router/transfer-shared.js +10 -0
  142. package/dist/chains/eni/batch-router/transfer-sweep.d.ts +51 -0
  143. package/dist/chains/eni/batch-router/transfer-sweep.js +364 -0
  144. package/dist/chains/eni/batch-router/transfer.d.ts +4 -74
  145. package/dist/chains/eni/batch-router/transfer.js +2 -647
  146. package/dist/chains/eni/platforms/daoaas/portal-direct-profit.d.ts +17 -0
  147. package/dist/chains/eni/platforms/daoaas/portal-direct-profit.js +30 -0
  148. package/dist/chains/eni/platforms/daoaas/portal-direct-submit.d.ts +12 -0
  149. package/dist/chains/eni/platforms/daoaas/portal-direct-submit.js +396 -0
  150. package/dist/chains/eni/platforms/daoaas/portal-direct-tx.d.ts +20 -0
  151. package/dist/chains/eni/platforms/daoaas/portal-direct-tx.js +165 -0
  152. package/dist/chains/eni/platforms/daoaas/portal-direct.d.ts +3 -32
  153. package/dist/chains/eni/platforms/daoaas/portal-direct.js +3 -571
  154. package/dist/chains/eni/submit.js +1 -1
  155. package/dist/chains/xlayer/constants.d.ts +0 -2
  156. package/dist/chains/xlayer/constants.js +0 -2
  157. package/dist/chains/xlayer/eip7702/auth.d.ts +16 -0
  158. package/dist/chains/xlayer/eip7702/auth.js +81 -0
  159. package/dist/chains/xlayer/eip7702/bundle-create-buy.d.ts +22 -0
  160. package/dist/chains/xlayer/eip7702/bundle-create-buy.js +201 -0
  161. package/dist/chains/xlayer/eip7702/bundle-create-helpers.d.ts +114 -0
  162. package/dist/chains/xlayer/eip7702/bundle-create-helpers.js +139 -0
  163. package/dist/chains/xlayer/eip7702/bundle-create-to-dex.d.ts +24 -0
  164. package/dist/chains/xlayer/eip7702/bundle-create-to-dex.js +233 -0
  165. package/dist/chains/xlayer/eip7702/bundle-create.d.ts +3 -35
  166. package/dist/chains/xlayer/eip7702/bundle-create.js +3 -746
  167. package/dist/chains/xlayer/eip7702/bundle-graduate-buy.d.ts +22 -0
  168. package/dist/chains/xlayer/eip7702/bundle-graduate-buy.js +214 -0
  169. package/dist/chains/xlayer/eip7702/bundle-sell.js +1 -1
  170. package/dist/chains/xlayer/eip7702/bundle-swap-batch.d.ts +31 -0
  171. package/dist/chains/xlayer/eip7702/bundle-swap-batch.js +216 -0
  172. package/dist/chains/xlayer/eip7702/bundle-swap-helpers.d.ts +21 -0
  173. package/dist/chains/xlayer/eip7702/bundle-swap-helpers.js +206 -0
  174. package/dist/chains/xlayer/eip7702/bundle-swap-multi.d.ts +33 -0
  175. package/dist/chains/xlayer/eip7702/bundle-swap-multi.js +146 -0
  176. package/dist/chains/xlayer/eip7702/bundle-swap-single.d.ts +31 -0
  177. package/dist/chains/xlayer/eip7702/bundle-swap-single.js +177 -0
  178. package/dist/chains/xlayer/eip7702/bundle-swap.d.ts +6 -61
  179. package/dist/chains/xlayer/eip7702/bundle-swap.js +3 -712
  180. package/dist/chains/xlayer/eip7702/bytes.d.ts +4 -0
  181. package/dist/chains/xlayer/eip7702/bytes.js +31 -0
  182. package/dist/chains/xlayer/eip7702/gas.d.ts +19 -0
  183. package/dist/chains/xlayer/eip7702/gas.js +152 -0
  184. package/dist/chains/xlayer/eip7702/multi-hop-transfer-disperse.d.ts +5 -0
  185. package/dist/chains/xlayer/eip7702/multi-hop-transfer-disperse.js +196 -0
  186. package/dist/chains/xlayer/eip7702/multi-hop-transfer-pairwise.d.ts +5 -0
  187. package/dist/chains/xlayer/eip7702/multi-hop-transfer-pairwise.js +188 -0
  188. package/dist/chains/xlayer/eip7702/multi-hop-transfer-sweep.d.ts +5 -0
  189. package/dist/chains/xlayer/eip7702/multi-hop-transfer-sweep.js +220 -0
  190. package/dist/chains/xlayer/eip7702/multi-hop-transfer.d.ts +8 -4
  191. package/dist/chains/xlayer/eip7702/multi-hop-transfer.js +5 -591
  192. package/dist/chains/xlayer/eip7702/profit.d.ts +32 -0
  193. package/dist/chains/xlayer/eip7702/profit.js +59 -0
  194. package/dist/chains/xlayer/eip7702/provider.d.ts +3 -0
  195. package/dist/chains/xlayer/eip7702/provider.js +17 -0
  196. package/dist/chains/xlayer/eip7702/time.d.ts +2 -0
  197. package/dist/chains/xlayer/eip7702/time.js +10 -0
  198. package/dist/chains/xlayer/eip7702/tx-build.d.ts +10 -0
  199. package/dist/chains/xlayer/eip7702/tx-build.js +128 -0
  200. package/dist/chains/xlayer/eip7702/utils.d.ts +19 -85
  201. package/dist/chains/xlayer/eip7702/utils.js +19 -484
  202. package/dist/chains/xlayer/eip7702/volume-bundle.d.ts +13 -0
  203. package/dist/chains/xlayer/eip7702/volume-bundle.js +250 -0
  204. package/dist/chains/xlayer/eip7702/volume-internal.d.ts +13 -0
  205. package/dist/chains/xlayer/eip7702/volume-internal.js +169 -0
  206. package/dist/chains/xlayer/eip7702/volume-make.d.ts +8 -0
  207. package/dist/chains/xlayer/eip7702/volume-make.js +38 -0
  208. package/dist/chains/xlayer/eip7702/volume-single-round.d.ts +17 -0
  209. package/dist/chains/xlayer/eip7702/volume-single-round.js +44 -0
  210. package/dist/chains/xlayer/eip7702/volume-swap.d.ts +18 -0
  211. package/dist/chains/xlayer/eip7702/volume-swap.js +30 -0
  212. package/dist/chains/xlayer/eip7702/volume-wash.d.ts +8 -0
  213. package/dist/chains/xlayer/eip7702/volume-wash.js +191 -0
  214. package/dist/chains/xlayer/eip7702/volume.d.ts +7 -35
  215. package/dist/chains/xlayer/eip7702/volume.js +5 -697
  216. package/dist/chains/xlayer/eip7702/wallet.d.ts +6 -0
  217. package/dist/chains/xlayer/eip7702/wallet.js +17 -0
  218. package/dist/chains/xlayer/eoa/aa-types.d.ts +176 -0
  219. package/dist/chains/xlayer/eoa/aa-types.js +6 -0
  220. package/dist/chains/xlayer/eoa/constants.d.ts +0 -2
  221. package/dist/chains/xlayer/eoa/constants.js +0 -2
  222. package/dist/chains/xlayer/eoa/context.d.ts +8 -0
  223. package/dist/chains/xlayer/eoa/context.js +23 -0
  224. package/dist/chains/xlayer/eoa/encoders.d.ts +147 -0
  225. package/dist/chains/xlayer/eoa/encoders.js +147 -0
  226. package/dist/chains/xlayer/eoa/eoa-bundle-swap-cross.d.ts +5 -0
  227. package/dist/chains/xlayer/eoa/eoa-bundle-swap-cross.js +113 -0
  228. package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.d.ts +10 -123
  229. package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.js +10 -225
  230. package/dist/chains/xlayer/eoa/eoa-bundle-swap-pure.d.ts +50 -0
  231. package/dist/chains/xlayer/eoa/eoa-bundle-swap-pure.js +170 -0
  232. package/dist/chains/xlayer/eoa/eoa-bundle-swap-quick.d.ts +5 -0
  233. package/dist/chains/xlayer/eoa/eoa-bundle-swap-quick.js +257 -0
  234. package/dist/chains/xlayer/eoa/eoa-bundle-swap-types.d.ts +99 -0
  235. package/dist/chains/xlayer/eoa/eoa-bundle-swap-types.js +11 -0
  236. package/dist/chains/xlayer/eoa/eoa-bundle-swap.d.ts +5 -47
  237. package/dist/chains/xlayer/eoa/eoa-bundle-swap.js +3 -522
  238. package/dist/chains/xlayer/eoa/eoa-types.d.ts +776 -0
  239. package/dist/chains/xlayer/eoa/eoa-types.js +6 -0
  240. package/dist/chains/xlayer/eoa/eoa-wash-volume.d.ts +8 -0
  241. package/dist/chains/xlayer/eoa/eoa-wash-volume.js +8 -0
  242. package/dist/chains/xlayer/eoa/format.d.ts +34 -0
  243. package/dist/chains/xlayer/eoa/format.js +56 -0
  244. package/dist/chains/xlayer/eoa/hop-chain.d.ts +4 -0
  245. package/dist/chains/xlayer/eoa/hop-chain.js +87 -0
  246. package/dist/chains/xlayer/eoa/nonce-map.d.ts +20 -0
  247. package/dist/chains/xlayer/eoa/nonce-map.js +51 -0
  248. package/dist/chains/xlayer/eoa/portal-ops.d.ts +9 -292
  249. package/dist/chains/xlayer/eoa/portal-ops.js +9 -486
  250. package/dist/chains/xlayer/eoa/query.d.ts +117 -0
  251. package/dist/chains/xlayer/eoa/query.js +285 -0
  252. package/dist/chains/xlayer/eoa/quote.d.ts +6 -0
  253. package/dist/chains/xlayer/eoa/quote.js +90 -0
  254. package/dist/chains/xlayer/eoa/types.d.ts +9 -959
  255. package/dist/chains/xlayer/eoa/types.js +9 -49
  256. package/dist/core/clients/blockrazor.js +1 -1
  257. package/dist/core/clients/merkle.js +1 -1
  258. package/dist/core/erc20/allowances.d.ts +104 -0
  259. package/dist/core/erc20/allowances.js +205 -0
  260. package/dist/core/erc20/approve.d.ts +141 -0
  261. package/dist/core/erc20/approve.js +325 -0
  262. package/dist/core/erc20/helpers.d.ts +20 -0
  263. package/dist/core/erc20/helpers.js +109 -0
  264. package/dist/core/erc20/index.d.ts +13 -0
  265. package/dist/core/erc20/index.js +12 -0
  266. package/dist/core/gas/bundle-gas.d.ts +6 -1
  267. package/dist/core/index.d.ts +1 -1
  268. package/dist/core/index.js +1 -1
  269. package/dist/core/quote/index.d.ts +1 -0
  270. package/dist/core/quote/index.js +1 -0
  271. package/dist/core/quote/quote-helpers.d.ts +78 -0
  272. package/dist/core/quote/quote-helpers.js +289 -0
  273. package/dist/core/quote/types.d.ts +1 -0
  274. package/dist/core/quote/types.js +1 -0
  275. package/dist/core/sign-context-helpers.d.ts +29 -0
  276. package/dist/core/sign-context-helpers.js +63 -0
  277. package/dist/domains/dex/direct-router-helpers.d.ts +16 -268
  278. package/dist/domains/dex/direct-router-helpers.js +16 -535
  279. package/dist/domains/dex/direct-router-types.d.ts +104 -0
  280. package/dist/domains/dex/direct-router-types.js +81 -0
  281. package/dist/domains/dex/direct-router-v2-buy.d.ts +2 -0
  282. package/dist/domains/dex/direct-router-v2-buy.js +249 -0
  283. package/dist/domains/dex/direct-router-v2-sell.d.ts +5 -0
  284. package/dist/domains/dex/direct-router-v2-sell.js +270 -0
  285. package/dist/domains/dex/direct-router-v2.d.ts +9 -0
  286. package/dist/domains/dex/direct-router-v2.js +9 -0
  287. package/dist/domains/dex/direct-router-v3.d.ts +17 -0
  288. package/dist/domains/dex/direct-router-v3.js +432 -0
  289. package/dist/domains/dex/direct-router.d.ts +11 -26
  290. package/dist/domains/dex/direct-router.js +10 -977
  291. package/dist/domains/dex/dyo-encode.d.ts +62 -0
  292. package/dist/domains/dex/dyo-encode.js +124 -0
  293. package/dist/domains/dex/profit.d.ts +24 -0
  294. package/dist/domains/dex/profit.js +86 -0
  295. package/dist/domains/dex/provider.d.ts +10 -0
  296. package/dist/domains/dex/provider.js +27 -0
  297. package/dist/domains/dex/quote.d.ts +7 -0
  298. package/dist/domains/dex/quote.js +52 -0
  299. package/dist/domains/dex/router.d.ts +56 -0
  300. package/dist/domains/dex/router.js +193 -0
  301. package/dist/domains/flap/portal-bundle/batch.d.ts +9 -0
  302. package/dist/domains/flap/portal-bundle/batch.js +193 -0
  303. package/dist/domains/flap/portal-bundle/create.d.ts +5 -0
  304. package/dist/domains/flap/portal-bundle/create.js +153 -0
  305. package/dist/domains/flap/portal-bundle/helpers.d.ts +32 -0
  306. package/dist/domains/flap/portal-bundle/helpers.js +50 -0
  307. package/dist/domains/flap/portal-bundle/index.d.ts +16 -0
  308. package/dist/domains/flap/portal-bundle/index.js +15 -0
  309. package/dist/domains/flap/portal-bundle/private.d.ts +5 -0
  310. package/dist/domains/flap/portal-bundle/private.js +198 -0
  311. package/dist/domains/flap/portal-bundle/types.d.ts +102 -0
  312. package/dist/domains/flap/portal-bundle/types.js +1 -0
  313. package/dist/domains/flap/portal-bundle-merkle/core-batch.d.ts +13 -0
  314. package/dist/domains/flap/portal-bundle-merkle/core-batch.js +376 -0
  315. package/dist/domains/flap/portal-bundle-merkle/core-helpers.d.ts +75 -7
  316. package/dist/domains/flap/portal-bundle-merkle/core-helpers.js +259 -20
  317. package/dist/domains/flap/portal-bundle-merkle/core.d.ts +2 -13
  318. package/dist/domains/flap/portal-bundle-merkle/core.js +12 -629
  319. package/dist/domains/flap/portal-bundle-merkle/create-to-dex/constants.d.ts +70 -0
  320. package/dist/domains/flap/portal-bundle-merkle/create-to-dex/constants.js +90 -0
  321. package/dist/domains/flap/portal-bundle-merkle/create-to-dex/index.d.ts +12 -0
  322. package/dist/domains/flap/portal-bundle-merkle/create-to-dex/index.js +11 -0
  323. package/dist/domains/flap/portal-bundle-merkle/create-to-dex/main.d.ts +15 -0
  324. package/dist/domains/flap/portal-bundle-merkle/create-to-dex/main.js +432 -0
  325. package/dist/domains/flap/portal-bundle-merkle/create-to-dex/types.d.ts +113 -0
  326. package/dist/domains/flap/portal-bundle-merkle/create-to-dex/types.js +4 -0
  327. package/dist/domains/flap/portal-bundle-merkle/create-to-dex.d.ts +4 -127
  328. package/dist/domains/flap/portal-bundle-merkle/create-to-dex.js +4 -527
  329. package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/constants.d.ts +42 -0
  330. package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/constants.js +81 -0
  331. package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/index.d.ts +12 -0
  332. package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/index.js +11 -0
  333. package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/main.d.ts +15 -0
  334. package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/main.js +339 -0
  335. package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/types.d.ts +72 -0
  336. package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/types.js +4 -0
  337. package/dist/domains/flap/portal-bundle-merkle/curve-to-dex.d.ts +4 -85
  338. package/dist/domains/flap/portal-bundle-merkle/curve-to-dex.js +4 -425
  339. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/approve.d.ts +12 -0
  340. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/approve.js +102 -0
  341. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/buy.d.ts +5 -0
  342. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/buy.js +135 -0
  343. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/helpers.d.ts +52 -0
  344. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/helpers.js +267 -0
  345. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/index.d.ts +14 -0
  346. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/index.js +14 -0
  347. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/sell.d.ts +5 -0
  348. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/sell.js +195 -0
  349. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy.d.ts +3 -24
  350. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy.js +3 -700
  351. package/dist/domains/flap/portal-bundle-merkle/private/buy.d.ts +9 -0
  352. package/dist/domains/flap/portal-bundle-merkle/private/buy.js +188 -0
  353. package/dist/domains/flap/portal-bundle-merkle/private/helpers.d.ts +36 -0
  354. package/dist/domains/flap/portal-bundle-merkle/private/helpers.js +127 -0
  355. package/dist/domains/flap/portal-bundle-merkle/private/index.d.ts +12 -0
  356. package/dist/domains/flap/portal-bundle-merkle/private/index.js +12 -0
  357. package/dist/domains/flap/portal-bundle-merkle/private/sell.d.ts +9 -0
  358. package/dist/domains/flap/portal-bundle-merkle/private/sell.js +191 -0
  359. package/dist/domains/flap/portal-bundle-merkle/private.d.ts +5 -15
  360. package/dist/domains/flap/portal-bundle-merkle/private.js +5 -494
  361. package/dist/domains/flap/portal-bundle-merkle/swap-batch.js +3 -2
  362. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-chain.d.ts +4 -0
  363. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-chain.js +43 -0
  364. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-constants.d.ts +13 -0
  365. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-constants.js +21 -0
  366. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-helpers.d.ts +11 -121
  367. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-helpers.js +11 -109
  368. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-multi-wallet.d.ts +20 -0
  369. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-multi-wallet.js +223 -0
  370. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-plan.d.ts +32 -0
  371. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-plan.js +66 -0
  372. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-profit.d.ts +22 -0
  373. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-profit.js +22 -0
  374. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-quote.d.ts +51 -0
  375. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-quote.js +149 -0
  376. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-types.d.ts +87 -0
  377. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-types.js +1 -0
  378. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first.js +5 -404
  379. package/dist/domains/flap/portal-bundle-merkle/swap-helpers.d.ts +0 -1
  380. package/dist/domains/flap/portal-bundle-merkle/swap-helpers.js +0 -7
  381. package/dist/domains/flap/portal-bundle-merkle/swap-planning.js +1 -1
  382. package/dist/domains/flap/portal-bundle-merkle/swap-quick-batch.js +3 -2
  383. package/dist/domains/flap/portal-bundle-merkle/swap-single.js +3 -2
  384. package/dist/domains/flap/portal-bundle-merkle/utils/disperse.d.ts +2 -0
  385. package/dist/domains/flap/portal-bundle-merkle/utils/disperse.js +275 -0
  386. package/dist/domains/flap/portal-bundle-merkle/utils/index.d.ts +11 -0
  387. package/dist/domains/flap/portal-bundle-merkle/utils/index.js +11 -0
  388. package/dist/domains/flap/portal-bundle-merkle/utils/sweep.d.ts +9 -0
  389. package/dist/domains/flap/portal-bundle-merkle/utils/sweep.js +570 -0
  390. package/dist/domains/flap/portal-bundle-merkle/utils.d.ts +5 -8
  391. package/dist/domains/flap/portal-bundle-merkle/utils.js +5 -841
  392. package/dist/domains/flap/portal-bundle.d.ts +5 -117
  393. package/dist/domains/flap/portal-bundle.js +5 -587
  394. package/dist/domains/flap/portal.d.ts +13 -404
  395. package/dist/domains/flap/portal.js +12 -619
  396. package/dist/domains/flap/reader.d.ts +51 -0
  397. package/dist/domains/flap/reader.js +275 -0
  398. package/dist/domains/flap/types.d.ts +246 -0
  399. package/dist/domains/flap/types.js +104 -0
  400. package/dist/domains/flap/vault/constants.d.ts +220 -0
  401. package/dist/domains/flap/vault/constants.js +173 -0
  402. package/dist/domains/flap/vault/encode.d.ts +39 -0
  403. package/dist/domains/flap/vault/encode.js +135 -0
  404. package/dist/domains/flap/vault/index.d.ts +15 -0
  405. package/dist/domains/flap/vault/index.js +14 -0
  406. package/dist/domains/flap/vault/query.d.ts +40 -0
  407. package/dist/domains/flap/vault/query.js +104 -0
  408. package/dist/domains/flap/vault/types.d.ts +147 -0
  409. package/dist/domains/flap/vault/types.js +29 -0
  410. package/dist/domains/flap/vault.d.ts +3 -413
  411. package/dist/domains/flap/vault.js +3 -467
  412. package/dist/domains/flap/writer.d.ts +124 -0
  413. package/dist/domains/flap/writer.js +255 -0
  414. package/dist/domains/four/contracts/tm-bundle-batch.d.ts +35 -0
  415. package/dist/domains/four/contracts/tm-bundle-batch.js +286 -0
  416. package/dist/domains/four/contracts/tm-bundle-create.d.ts +2 -0
  417. package/dist/domains/four/contracts/tm-bundle-create.js +304 -0
  418. package/dist/domains/four/contracts/tm-bundle-helpers.d.ts +2 -1
  419. package/dist/domains/four/contracts/tm-bundle-helpers.js +3 -0
  420. package/dist/domains/four/contracts/tm-bundle-private.d.ts +36 -0
  421. package/dist/domains/four/contracts/tm-bundle-private.js +164 -0
  422. package/dist/domains/four/contracts/tm-bundle.d.ts +10 -71
  423. package/dist/domains/four/contracts/tm-bundle.js +9 -738
  424. package/dist/domains/lp-inspect/inspect-helpers.d.ts +25 -0
  425. package/dist/domains/lp-inspect/inspect-helpers.js +343 -0
  426. package/dist/domains/lp-inspect/inspect.d.ts +8 -0
  427. package/dist/domains/lp-inspect/inspect.js +332 -0
  428. package/dist/domains/lp-inspect/lp-inspect.d.ts +9 -37
  429. package/dist/domains/lp-inspect/lp-inspect.js +9 -775
  430. package/dist/domains/lp-inspect/registry.d.ts +43 -0
  431. package/dist/domains/lp-inspect/registry.js +127 -0
  432. package/dist/domains/merkle/index.d.ts +1 -1
  433. package/dist/exports/root-bundle-and-tooling.d.ts +9 -1
  434. package/dist/exports/root-bundle-and-tooling.js +8 -1
  435. package/dist/exports/root-foundations.d.ts +1 -1
  436. package/dist/exports/root-foundations.js +1 -1
  437. package/dist/exports/root-swap-dex-and-xlayer.d.ts +4 -4
  438. package/dist/exports/root-swap-dex-and-xlayer.js +4 -4
  439. package/dist/index.d.ts +1 -1
  440. package/dist/index.js +1 -1
  441. package/dist/utils/swap-helpers.js +1 -1
  442. package/package.json +1 -85
@@ -2,455 +2,8 @@
2
2
  * Four.meme 内盘捆绑换手(Merkle Bundle)- 先买后卖
3
3
  *
4
4
  * 功能:钱包B先买入代币 → 钱包A卖出相同数量 → 原子执行
5
+ *
6
+ * 原超长文件按职责拆分为 swap-buy-first/ 目录下的多个子文件,
7
+ * 对外 export 符号与路径保持不变(见 swap-buy-first/index.ts)。
5
8
  */
6
- import { ethers, Contract, Wallet } from 'ethers';
7
- import { createSignProvider } from '../sign-context-helpers.js';
8
- import { NonceManager, getOptimizedGasPrice, buildProfitHopTransactions, PROFIT_HOP_COUNT, } from '../../utils/bundle-helpers.js';
9
- import { ADDRESSES, BLOCKRAZOR_BUILDER_EOA, CHAINS, getProfitRateBps as getSharedProfitRateBps, } from '../../core/constants/index.js';
10
- import { TM_ABI, HELPER3_ABI, TM_ADDRESS } from './swap-internal.js';
11
- import { getTxType, getGasPriceConfig, getProfitRecipient, getBribeAmount, } from '../config-helpers.js';
12
- import { trySell } from '../../domains/four/contracts/tm.js';
13
- import { splitAmountByWeight as splitAmount } from '../../core/amount/split-by-weight.js';
14
- // ✅ 本地 getGasLimit(FourAnyConfig 支持 bigint gasLimit)
15
- function getGasLimit(config, defaultGas = 800000) {
16
- if (config.gasLimit !== undefined) {
17
- return typeof config.gasLimit === 'bigint' ? config.gasLimit : BigInt(config.gasLimit);
18
- }
19
- const multiplier = config.gasLimitMultiplier ?? 1.0;
20
- return BigInt(Math.ceil(defaultGas * multiplier));
21
- }
22
- // ==================== 多笔买卖常量 ====================
23
- /** 最大 Bundle 签名数 */
24
- const MAX_BUNDLE_SIGNATURES = 50;
25
- /** 贿赂交易数 */
26
- const BRIBE_TX_COUNT = 1;
27
- /** 利润中转交易数(支付者 1 笔 + 中转钱包 PROFIT_HOP_COUNT 笔 + 最终接收 1 笔) */
28
- const PROFIT_TX_COUNT = PROFIT_HOP_COUNT + 2; // 2 + 2 = 4
29
- /** 最大买卖交易数 */
30
- const MAX_SWAP_TX_COUNT = MAX_BUNDLE_SIGNATURES - BRIBE_TX_COUNT - PROFIT_TX_COUNT; // 50 - 1 - 4 = 45
31
- /**
32
- * 根据 userType 获取每笔交易的利润率
33
- */
34
- function getProfitRatePerTxBps(userType) {
35
- if (userType === 'v1') {
36
- return getSharedProfitRateBps('v1Double');
37
- }
38
- return getSharedProfitRateBps('v0Double');
39
- }
40
- /**
41
- * 验证买卖笔数
42
- */
43
- function validateSwapCounts(buyCount, sellCount) {
44
- if (buyCount < 1) {
45
- throw new Error(`买入笔数必须至少为 1,当前为 ${buyCount}`);
46
- }
47
- if (sellCount < 1) {
48
- throw new Error(`卖出笔数必须至少为 1,当前为 ${sellCount}`);
49
- }
50
- const totalSwaps = buyCount + sellCount;
51
- if (totalSwaps > MAX_SWAP_TX_COUNT) {
52
- throw new Error(`买卖笔数总和 (${totalSwaps}) 超出限制 (${MAX_SWAP_TX_COUNT}),` +
53
- `最大签名数为 ${MAX_BUNDLE_SIGNATURES}(${BRIBE_TX_COUNT} 贿赂 + ${PROFIT_TX_COUNT} 利润 + ${MAX_SWAP_TX_COUNT} 买卖)`);
54
- }
55
- }
56
- export async function fourBundleBuyFirstMerkle(params) {
57
- const { buyerPrivateKey, buyerPrivateKeys, buyerFunds, buyerFundsPercentage, sellerPrivateKey, sellerPrivateKeys, tokenAddress, config, buyCount: _buyCount, sellCount: _sellCount, } = params;
58
- // ✅ 判断是否为多钱包模式
59
- const isMultiWalletMode = !!(buyerPrivateKeys && buyerPrivateKeys.length > 0) || !!(sellerPrivateKeys && sellerPrivateKeys.length > 0);
60
- const buyCount = _buyCount ?? 1;
61
- const sellCount = _sellCount ?? 1;
62
- // ✅ 多钱包模式:使用单独的处理逻辑
63
- if (isMultiWalletMode) {
64
- return await fourBundleBuyFirstMultiWallet({
65
- buyerPrivateKeys: buyerPrivateKeys || (buyerPrivateKey ? [buyerPrivateKey] : []),
66
- sellerPrivateKeys: sellerPrivateKeys || (sellerPrivateKey ? [sellerPrivateKey] : []),
67
- tokenAddress,
68
- buyerFunds,
69
- config,
70
- });
71
- }
72
- // ✅ 单钱包模式(向后兼容)
73
- if (!buyerPrivateKey || !sellerPrivateKey) {
74
- throw new Error('单钱包模式需要提供 buyerPrivateKey 和 sellerPrivateKey');
75
- }
76
- validateSwapCounts(buyCount, sellCount);
77
- // ✅ 计算利润比例(根据 userType 动态调整)
78
- const totalTxCount = buyCount + sellCount;
79
- const profitRateBps = getProfitRatePerTxBps(config.userType) * totalTxCount;
80
- const chainIdNum = config.chainId ?? CHAINS.BSC.chainId;
81
- const provider = createSignProvider(config.rpcUrl, chainIdNum, 'BSC');
82
- const buyer = new Wallet(buyerPrivateKey, provider);
83
- const seller = new Wallet(sellerPrivateKey, provider);
84
- const sameAddress = buyer.address.toLowerCase() === seller.address.toLowerCase();
85
- const finalGasLimit = getGasLimit(config);
86
- const txType = getTxType(config);
87
- const nonceManager = new NonceManager(provider);
88
- const reserveGas = ethers.parseEther((config.reserveGasBNB || 0.0005).toString());
89
- // ✅ 优化:第一批并行 - buyerBalance、gasPrice
90
- const [buyerBalance, gasPrice] = await Promise.all([
91
- provider.getBalance(buyer.address),
92
- getOptimizedGasPrice(provider, getGasPriceConfig(config)),
93
- ]);
94
- // 计算买方投入资金
95
- let buyerFundsWei;
96
- if (buyerFunds !== undefined) {
97
- buyerFundsWei = ethers.parseEther(String(buyerFunds));
98
- }
99
- else if (buyerFundsPercentage !== undefined) {
100
- const pct = Math.max(0, Math.min(100, buyerFundsPercentage));
101
- const spendable = buyerBalance > reserveGas ? buyerBalance - reserveGas : 0n;
102
- buyerFundsWei = (spendable * BigInt(Math.round(pct * 100))) / 10000n;
103
- }
104
- else {
105
- throw new Error('必须提供 buyerFunds 或 buyerFundsPercentage');
106
- }
107
- if (buyerFundsWei <= 0n) {
108
- throw new Error('buyerFunds 需要大于 0');
109
- }
110
- // ✅ 优化:第二批并行 - buyQuote、sellerTokenBal、decimals
111
- const helper3 = new Contract(ADDRESSES.BSC.TokenManagerHelper3, HELPER3_ABI, provider);
112
- const erc20 = new Contract(tokenAddress, ['function balanceOf(address) view returns (uint256)', 'function decimals() view returns (uint8)'], provider);
113
- const [buyQuote, sellerTokenBal, decimals] = await Promise.all([
114
- helper3.tryBuy(tokenAddress, 0n, buyerFundsWei),
115
- erc20.balanceOf(seller.address),
116
- erc20.decimals(),
117
- ]);
118
- const estimatedTokenAmount = buyQuote.estimatedAmount ?? buyQuote[2];
119
- if (!estimatedTokenAmount || estimatedTokenAmount <= 0n) {
120
- throw new Error('报价失败:无法估算可买入的代币数量');
121
- }
122
- // ✅ 卖出数量直接使用估算的代币数量(无滑点保护)
123
- const sellAmountWei = estimatedTokenAmount;
124
- // 卖方余额检查
125
- if (!sameAddress && sellerTokenBal < sellAmountWei) {
126
- throw new Error(`卖方代币余额不足: 需要 ${ethers.formatUnits(sellAmountWei, decimals)},实际 ${ethers.formatUnits(sellerTokenBal, decimals)}`);
127
- }
128
- // ✅ 优化:第三批并行 - trySell、构建交易、获取 nonces
129
- const tmBuyer = new Contract(TM_ADDRESS, TM_ABI, buyer);
130
- const tmSeller = new Contract(TM_ADDRESS, TM_ABI, seller);
131
- // ✅ 拆分买入和卖出金额
132
- const buyAmountsWei = splitAmount(buyerFundsWei, buyCount);
133
- const sellAmountsWei = splitAmount(sellAmountWei, sellCount);
134
- // 预先规划 nonces
135
- const extractProfit = true;
136
- // ✅ 获取贿赂金额
137
- const bribeAmount = getBribeAmount(config);
138
- const needBribeTx = bribeAmount > 0n;
139
- // ✅ 构建多笔买入和卖出交易
140
- const buyUnsignedPromises = buyAmountsWei.map((amount) => tmBuyer.buyTokenAMAP.populateTransaction(0n, tokenAddress, buyer.address, amount, 0n, { value: amount }));
141
- const sellUnsignedPromises = sellAmountsWei.map((amount) => tmSeller.sellToken.populateTransaction(0n, tokenAddress, amount, 0n));
142
- // ✅ 规划多笔交易 nonce(与 Flap 一致,不含授权)
143
- const multiNoncePlan = await planMultiNonces({
144
- buyer,
145
- seller,
146
- buyCount,
147
- sellCount,
148
- extractProfit,
149
- needBribeTx,
150
- sameAddress,
151
- nonceManager,
152
- });
153
- const [sellResult, buyUnsignedArray, sellUnsignedArray] = await Promise.all([
154
- trySell('BSC', config.rpcUrl, tokenAddress, sellAmountWei),
155
- Promise.all(buyUnsignedPromises),
156
- Promise.all(sellUnsignedPromises),
157
- ]);
158
- const estimatedSellFunds = sellResult.funds;
159
- const profitAmount = extractProfit ? (estimatedSellFunds * BigInt(profitRateBps)) / 10000n : 0n;
160
- // ✅ 贿赂交易放在首位
161
- let bribeTx = null;
162
- if (needBribeTx && multiNoncePlan.bribeNonce !== undefined) {
163
- bribeTx = await seller.signTransaction({
164
- to: BLOCKRAZOR_BUILDER_EOA,
165
- value: bribeAmount,
166
- nonce: multiNoncePlan.bribeNonce,
167
- gasPrice,
168
- gasLimit: 21000n,
169
- chainId: BigInt(chainIdNum),
170
- type: txType,
171
- });
172
- }
173
- // ✅ 并行签名所有买入和卖出交易
174
- const buySignPromises = buyUnsignedArray.map((unsigned, i) => buyer.signTransaction({
175
- ...unsigned,
176
- from: buyer.address,
177
- nonce: multiNoncePlan.buyerNonces[i],
178
- gasLimit: finalGasLimit,
179
- gasPrice,
180
- chainId: BigInt(chainIdNum),
181
- type: txType,
182
- value: buyAmountsWei[i],
183
- }));
184
- const sellSignPromises = sellUnsignedArray.map((unsigned, i) => seller.signTransaction({
185
- ...unsigned,
186
- from: seller.address,
187
- nonce: multiNoncePlan.sellerNonces[i],
188
- gasLimit: finalGasLimit,
189
- gasPrice,
190
- chainId: BigInt(chainIdNum),
191
- type: txType,
192
- value: 0n,
193
- }));
194
- const [signedBuys, signedSells] = await Promise.all([Promise.all(buySignPromises), Promise.all(sellSignPromises)]);
195
- nonceManager.clearTemp();
196
- // ✅ 组装交易列表:贿赂 → 买入(多笔) → 卖出(多笔)(与 Flap 一致)
197
- const allTransactions = [];
198
- if (bribeTx)
199
- allTransactions.push(bribeTx);
200
- allTransactions.push(...signedBuys, ...signedSells);
201
- // ✅ 利润多跳转账(强制 2 跳中转)
202
- let profitHopWallets;
203
- if (extractProfit && profitAmount > 0n && multiNoncePlan.profitNonce !== undefined) {
204
- const profitHopResult = await buildProfitHopTransactions({
205
- provider,
206
- payerWallet: seller,
207
- profitAmount: profitAmount,
208
- profitRecipient: getProfitRecipient(),
209
- hopCount: PROFIT_HOP_COUNT,
210
- gasPrice,
211
- chainId: chainIdNum,
212
- txType,
213
- startNonce: multiNoncePlan.profitNonce,
214
- });
215
- allTransactions.push(...profitHopResult.signedTransactions);
216
- profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
217
- }
218
- return {
219
- signedTransactions: allTransactions,
220
- profitHopWallets, // ✅ 返回利润多跳钱包
221
- metadata: {
222
- buyerAddress: buyer.address,
223
- sellerAddress: seller.address,
224
- buyAmount: ethers.formatEther(buyerFundsWei),
225
- sellAmount: ethers.formatUnits(sellAmountWei, decimals),
226
- profitAmount: extractProfit ? ethers.formatEther(profitAmount) : undefined,
227
- // ✅ 返回多笔买卖信息
228
- buyCount,
229
- sellCount,
230
- // ✅ 返回每笔交易的具体金额(随机分配后的数组)
231
- buyAmounts: buyAmountsWei.map((amt) => ethers.formatEther(amt)),
232
- sellAmounts: sellAmountsWei.map((amt) => ethers.formatUnits(amt, decimals)),
233
- },
234
- };
235
- }
236
- /**
237
- * ✅ 规划多笔交易 nonce(与 Flap 一致)
238
- * 交易顺序:贿赂 → 买入(多笔) → 卖出(多笔) → 利润
239
- */
240
- async function planMultiNonces({ buyer, seller, buyCount, sellCount, extractProfit, needBribeTx, sameAddress, nonceManager, }) {
241
- const profitNonceCount = extractProfit ? 1 : 0;
242
- if (sameAddress) {
243
- // 同一地址:贿赂(可选) + 买入(多笔) + 卖出(多笔) + 利润(可选)
244
- const bribeTxCount = needBribeTx ? 1 : 0;
245
- const totalTxCount = bribeTxCount + buyCount + sellCount + profitNonceCount;
246
- const nonces = await nonceManager.getNextNonceBatch(buyer, totalTxCount);
247
- let idx = 0;
248
- const bribeNonce = needBribeTx ? nonces[idx++] : undefined;
249
- const buyerNonces = nonces.slice(idx, idx + buyCount);
250
- idx += buyCount;
251
- const sellerNonces = nonces.slice(idx, idx + sellCount);
252
- idx += sellCount;
253
- const profitNonce = extractProfit ? nonces[idx] : undefined;
254
- return { buyerNonces, sellerNonces, bribeNonce, profitNonce };
255
- }
256
- // 不同地址
257
- // 买方:buyCount 个 nonce
258
- // 卖方:贿赂(可选) + sellCount + 利润(可选) 个 nonce
259
- const bribeTxCount = needBribeTx ? 1 : 0;
260
- const sellerTxCount = bribeTxCount + sellCount + profitNonceCount;
261
- const [buyerNonces, sellerNoncesAll] = await Promise.all([
262
- nonceManager.getNextNonceBatch(buyer, buyCount),
263
- nonceManager.getNextNonceBatch(seller, sellerTxCount),
264
- ]);
265
- let idx = 0;
266
- const bribeNonce = needBribeTx ? sellerNoncesAll[idx++] : undefined;
267
- const sellerNonces = sellerNoncesAll.slice(idx, idx + sellCount);
268
- idx += sellCount;
269
- const profitNonce = extractProfit ? sellerNoncesAll[idx] : undefined;
270
- return { buyerNonces, sellerNonces, bribeNonce, profitNonce };
271
- }
272
- /**
273
- * ✅ Four 多钱包捆绑换手
274
- * - 多个买方钱包执行买入(每个钱包1笔)
275
- * - 多个卖方钱包执行卖出(每个钱包1笔)
276
- * - 买入总价值 = 卖出总价值
277
- * - ✅ 优化:最大化并行操作
278
- */
279
- async function fourBundleBuyFirstMultiWallet(params) {
280
- const { buyerPrivateKeys, sellerPrivateKeys, tokenAddress, buyerFunds, config } = params;
281
- const buyCount = buyerPrivateKeys.length;
282
- const sellCount = sellerPrivateKeys.length;
283
- if (buyCount === 0)
284
- throw new Error('买方钱包数量不能为0');
285
- if (sellCount === 0)
286
- throw new Error('卖方钱包数量不能为0');
287
- // 验证总交易数不超过限制
288
- validateSwapCounts(buyCount, sellCount);
289
- // ✅ 计算利润比例(根据 userType 动态调整)
290
- const totalTxCount = buyCount + sellCount;
291
- const profitRateBps = getProfitRatePerTxBps(config.userType) * totalTxCount;
292
- const chainIdNum = config.chainId ?? CHAINS.BSC.chainId;
293
- const provider = createSignProvider(config.rpcUrl, chainIdNum, 'BSC');
294
- const nonceManager = new NonceManager(provider);
295
- // 创建所有钱包实例
296
- const buyers = buyerPrivateKeys.map((pk) => new Wallet(pk, provider));
297
- const sellers = sellerPrivateKeys.map((pk) => new Wallet(pk, provider));
298
- // 使用第一个卖方作为主卖方(支付贿赂和利润)
299
- const mainSeller = sellers[0];
300
- // ✅ 计算总交易金额
301
- if (!buyerFunds) {
302
- throw new Error('多钱包模式必须提供 buyerFunds(总交易金额)');
303
- }
304
- const totalFundsWei = ethers.parseEther(String(buyerFunds));
305
- if (totalFundsWei <= 0n) {
306
- throw new Error('交易金额必须大于0');
307
- }
308
- const finalGasLimit = getGasLimit(config);
309
- const txType = getTxType(config);
310
- const bribeAmount = getBribeAmount(config);
311
- const needBribeTx = bribeAmount > 0n;
312
- // ✅ 第一批并行:报价 + Gas价格 + 代币精度
313
- const helper3 = new Contract(ADDRESSES.BSC.TokenManagerHelper3, HELPER3_ABI, provider);
314
- const erc20 = new Contract(tokenAddress, ['function decimals() view returns (uint8)'], provider);
315
- const [buyQuote, gasPrice, decimals] = await Promise.all([
316
- helper3.tryBuy(tokenAddress, 0n, totalFundsWei),
317
- getOptimizedGasPrice(provider, getGasPriceConfig(config)),
318
- erc20.decimals(),
319
- ]);
320
- const estimatedTokenAmount = buyQuote.estimatedAmount ?? buyQuote[2];
321
- if (!estimatedTokenAmount || estimatedTokenAmount <= 0n) {
322
- throw new Error('报价失败:无法估算可买入的代币数量');
323
- }
324
- // ✅ 将总金额平均分配给买方
325
- const buyAmountsWei = splitAmount(totalFundsWei, buyCount);
326
- // ✅ 将代币平均分配给卖方
327
- const sellAmountsWei = splitAmount(estimatedTokenAmount, sellCount);
328
- // ✅ 第二批并行:估算利润 + 获取所有钱包 nonces
329
- // 预先计算所有唯一钱包地址(去重)
330
- const allWallets = [...sellers, ...buyers];
331
- const uniqueWallets = allWallets.filter((w, i) => {
332
- const addr = w.address.toLowerCase();
333
- const firstIdx = allWallets.findIndex((x) => x.address.toLowerCase() === addr);
334
- return firstIdx === i;
335
- });
336
- const [sellResult, noncesArray] = await Promise.all([
337
- trySell('BSC', config.rpcUrl, tokenAddress, estimatedTokenAmount),
338
- nonceManager.getNextNoncesForWallets(uniqueWallets),
339
- ]);
340
- // 构建 nonces Map
341
- const noncesMap = new Map();
342
- uniqueWallets.forEach((wallet, i) => {
343
- noncesMap.set(wallet.address.toLowerCase(), noncesArray[i]);
344
- });
345
- const estimatedSellFunds = sellResult.funds;
346
- const profitAmount = (estimatedSellFunds * BigInt(profitRateBps)) / 10000n;
347
- // ✅ 第三批并行:构建并签名所有交易
348
- const allTransactions = [];
349
- const tm = new Contract(TM_ADDRESS, TM_ABI, provider);
350
- // 1. 贿赂交易(由主卖方支付)- 先处理以确定 nonce 偏移
351
- let bribeTxPromise = null;
352
- if (needBribeTx) {
353
- const mainSellerAddr = mainSeller.address.toLowerCase();
354
- const bribeNonce = noncesMap.get(mainSellerAddr);
355
- noncesMap.set(mainSellerAddr, bribeNonce + 1);
356
- bribeTxPromise = mainSeller.signTransaction({
357
- to: BLOCKRAZOR_BUILDER_EOA,
358
- value: bribeAmount,
359
- nonce: bribeNonce,
360
- gasPrice,
361
- gasLimit: 21000n,
362
- chainId: BigInt(chainIdNum),
363
- type: txType,
364
- });
365
- }
366
- // 2. 预分配所有 nonces(同步操作,避免竞态)
367
- const buyerNonces = [];
368
- const sellerNonces = [];
369
- buyers.forEach((buyer) => {
370
- const addr = buyer.address.toLowerCase();
371
- const nonce = noncesMap.get(addr);
372
- buyerNonces.push(nonce);
373
- noncesMap.set(addr, nonce + 1);
374
- });
375
- sellers.forEach((seller) => {
376
- const addr = seller.address.toLowerCase();
377
- const nonce = noncesMap.get(addr);
378
- sellerNonces.push(nonce);
379
- noncesMap.set(addr, nonce + 1);
380
- });
381
- // 3. 并行构建所有买入交易
382
- const buyTxPromises = buyers.map(async (buyer, i) => {
383
- const tmBuyer = tm.connect(buyer);
384
- const unsigned = await tmBuyer.buyTokenAMAP.populateTransaction(0n, tokenAddress, buyer.address, buyAmountsWei[i], 0n, { value: buyAmountsWei[i] });
385
- return buyer.signTransaction({
386
- ...unsigned,
387
- from: buyer.address,
388
- nonce: buyerNonces[i],
389
- gasLimit: finalGasLimit,
390
- gasPrice,
391
- chainId: BigInt(chainIdNum),
392
- type: txType,
393
- value: buyAmountsWei[i],
394
- });
395
- });
396
- // 4. 并行构建所有卖出交易
397
- const sellTxPromises = sellers.map(async (seller, i) => {
398
- const tmSeller = tm.connect(seller);
399
- const unsigned = await tmSeller.sellToken.populateTransaction(0n, tokenAddress, sellAmountsWei[i], 0n);
400
- return seller.signTransaction({
401
- ...unsigned,
402
- from: seller.address,
403
- nonce: sellerNonces[i],
404
- gasLimit: finalGasLimit,
405
- gasPrice,
406
- chainId: BigInt(chainIdNum),
407
- type: txType,
408
- value: 0n,
409
- });
410
- });
411
- // ✅ 并行签名所有交易(贿赂 + 买入 + 卖出)
412
- const [bribeTx, signedBuys, signedSells] = await Promise.all([
413
- bribeTxPromise,
414
- Promise.all(buyTxPromises),
415
- Promise.all(sellTxPromises),
416
- ]);
417
- // 组装交易顺序:贿赂 → 买入 → 卖出
418
- if (bribeTx)
419
- allTransactions.push(bribeTx);
420
- allTransactions.push(...signedBuys, ...signedSells);
421
- // 5. 利润多跳转账(由主卖方支付)
422
- let profitHopWallets;
423
- if (profitAmount > 0n) {
424
- const mainSellerAddr = mainSeller.address.toLowerCase();
425
- const profitNonce = noncesMap.get(mainSellerAddr);
426
- const profitHopResult = await buildProfitHopTransactions({
427
- provider,
428
- payerWallet: mainSeller,
429
- profitAmount,
430
- profitRecipient: getProfitRecipient(),
431
- hopCount: PROFIT_HOP_COUNT,
432
- gasPrice,
433
- chainId: chainIdNum,
434
- txType,
435
- startNonce: profitNonce,
436
- });
437
- allTransactions.push(...profitHopResult.signedTransactions);
438
- profitHopWallets = profitHopResult.hopWallets;
439
- }
440
- nonceManager.clearTemp();
441
- return {
442
- signedTransactions: allTransactions,
443
- profitHopWallets,
444
- metadata: {
445
- buyerAddress: buyers.map((b) => b.address).join(','),
446
- sellerAddress: sellers.map((s) => s.address).join(','),
447
- buyAmount: ethers.formatEther(totalFundsWei),
448
- sellAmount: ethers.formatUnits(estimatedTokenAmount, decimals),
449
- profitAmount: profitAmount > 0n ? ethers.formatEther(profitAmount) : undefined,
450
- buyCount,
451
- sellCount,
452
- buyAmounts: buyAmountsWei.map((amt) => ethers.formatEther(amt)),
453
- sellAmounts: sellAmountsWei.map((amt) => ethers.formatUnits(amt, decimals)),
454
- },
455
- };
456
- }
9
+ export * from './swap-buy-first/index.js';
@@ -1,6 +1,6 @@
1
1
  import { Wallet, type JsonRpcProvider } from 'ethers';
2
- import type { DisperseHopPath } from './types.js';
2
+ import type { DisperseHopPath } from './types/index.js';
3
3
  export declare const NATIVE_TRANSFER_GAS_LIMIT = 21055n;
4
- export type { DisperseHopPath } from './types.js';
4
+ export type { DisperseHopPath } from './types/index.js';
5
5
  export declare function generateDisperseHopPaths(targetAddresses: string[], hopCount: number, provider: JsonRpcProvider): DisperseHopPath[];
6
6
  export declare function buildNativeHopChain(payer: Wallet, path: DisperseHopPath, finalAmount: bigint, gasPrice: bigint, chainId: number, txType: 0 | 2, payerNonce: number): Promise<string[]>;
@@ -1,7 +1,7 @@
1
1
  import { Wallet, type JsonRpcProvider } from 'ethers';
2
2
  import { type CommonBundleConfig } from '../../utils/bundle-helpers.js';
3
- import type { FourSwapSignConfig, SellerNoncePlan, UserType } from './types.js';
4
- export type { SellerNoncePlan } from './types.js';
3
+ import type { FourSwapSignConfig, SellerNoncePlan, UserType } from './types/index.js';
4
+ export type { SellerNoncePlan } from './types/index.js';
5
5
  export declare function getFourSwapProfitRateBps(userType?: UserType): number;
6
6
  export declare function needsTmTokenApproval(currentAllowance: bigint, decimals: number): boolean;
7
7
  export declare function countSellerNonceSlots(needBribeTx: boolean, needApproval: boolean, includeProfit: boolean): number;
@@ -3,7 +3,7 @@ import { getGasLimit } from '../../utils/bundle-helpers.js';
3
3
  import { ADDRESSES, CHAINS } from '../../core/constants/index.js';
4
4
  import { getProfitRateBps as getSharedProfitRateBps } from '../../core/constants/index.js';
5
5
  import { getTxType } from '../config-helpers.js';
6
- import { createSignProvider } from '../sign-context-helpers.js';
6
+ import { createSignProvider } from '../../core/sign-context-helpers.js';
7
7
  import { HELPER3_ABI, TM_ADDRESS } from './swap-internal.js';
8
8
  const APPROVE_INTERFACE = new ethers.Interface(['function approve(address,uint256) returns (bool)']);
9
9
  const ERC20_ALLOWANCE_ABI = ['function allowance(address,address) view returns (uint256)'];
@@ -1,17 +1,7 @@
1
1
  /**
2
2
  * Four.meme 内盘捆绑换手(Merkle Bundle)
3
+ *
4
+ * 原超长文件按流程拆分为 swap/ 目录下的多个子文件,
5
+ * 对外 export 符号与路径保持不变(见 swap/index.ts)。
3
6
  */
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>;
7
+ export * from './swap/index.js';