four-flap-meme-sdk 3.0.0 → 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 (446) 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/index.d.ts +1 -1
  97. package/dist/chains/bsc/index.js +2 -0
  98. package/dist/chains/bsc/pancake/bundle-buy-first-build.d.ts +25 -0
  99. package/dist/chains/bsc/pancake/bundle-buy-first-build.js +177 -0
  100. package/dist/chains/bsc/pancake/bundle-buy-first-constants.d.ts +30 -0
  101. package/dist/chains/bsc/pancake/bundle-buy-first-constants.js +24 -0
  102. package/dist/chains/bsc/pancake/bundle-buy-first-helpers.d.ts +11 -149
  103. package/dist/chains/bsc/pancake/bundle-buy-first-helpers.js +12 -74
  104. package/dist/chains/bsc/pancake/bundle-buy-first-multi-wallet.d.ts +9 -0
  105. package/dist/chains/bsc/pancake/bundle-buy-first-multi-wallet.js +225 -0
  106. package/dist/chains/bsc/pancake/bundle-buy-first-plan.d.ts +14 -0
  107. package/dist/chains/bsc/pancake/bundle-buy-first-plan.js +64 -0
  108. package/dist/chains/bsc/pancake/bundle-buy-first-profit.d.ts +12 -0
  109. package/dist/chains/bsc/pancake/bundle-buy-first-profit.js +22 -0
  110. package/dist/chains/bsc/pancake/bundle-buy-first-quote.d.ts +15 -0
  111. package/dist/chains/bsc/pancake/bundle-buy-first-quote.js +122 -0
  112. package/dist/chains/bsc/pancake/bundle-buy-first-types.d.ts +179 -0
  113. package/dist/chains/bsc/pancake/bundle-buy-first-types.js +1 -0
  114. package/dist/chains/bsc/pancake/bundle-buy-first-validate.d.ts +2 -0
  115. package/dist/chains/bsc/pancake/bundle-buy-first-validate.js +41 -0
  116. package/dist/chains/bsc/pancake/bundle-buy-first.d.ts +1 -1
  117. package/dist/chains/bsc/pancake/bundle-buy-first.js +8 -578
  118. package/dist/chains/bsc/pancake/bundle-swap-helpers.d.ts +11 -239
  119. package/dist/chains/bsc/pancake/bundle-swap-helpers.js +12 -564
  120. package/dist/chains/bsc/pancake/bundle-swap-types.d.ts +183 -0
  121. package/dist/chains/bsc/pancake/bundle-swap-types.js +17 -0
  122. package/dist/chains/bsc/pancake/bundle-swap.d.ts +10 -132
  123. package/dist/chains/bsc/pancake/bundle-swap.js +12 -1003
  124. package/dist/chains/bsc/pancake/hop-chain.d.ts +18 -0
  125. package/dist/chains/bsc/pancake/hop-chain.js +227 -0
  126. package/dist/chains/bsc/pancake/quote.d.ts +14 -0
  127. package/dist/chains/bsc/pancake/quote.js +84 -0
  128. package/dist/chains/bsc/pancake/swap-batch.d.ts +42 -0
  129. package/dist/chains/bsc/pancake/swap-batch.js +283 -0
  130. package/dist/chains/bsc/pancake/swap-build.d.ts +19 -0
  131. package/dist/chains/bsc/pancake/swap-build.js +226 -0
  132. package/dist/chains/bsc/pancake/swap-cross.d.ts +42 -0
  133. package/dist/chains/bsc/pancake/swap-cross.js +140 -0
  134. package/dist/chains/bsc/pancake/swap-quick.d.ts +54 -0
  135. package/dist/chains/bsc/pancake/swap-quick.js +424 -0
  136. package/dist/chains/bsc/pancake/swap-single.d.ts +2 -0
  137. package/dist/chains/bsc/pancake/swap-single.js +182 -0
  138. package/dist/chains/bsc/platforms/four/index.d.ts +21 -3
  139. package/dist/chains/bsc/platforms/four/index.js +28 -3
  140. package/dist/chains/eni/batch-router/transfer-disperse.d.ts +37 -0
  141. package/dist/chains/eni/batch-router/transfer-disperse.js +302 -0
  142. package/dist/chains/eni/batch-router/transfer-shared.d.ts +9 -0
  143. package/dist/chains/eni/batch-router/transfer-shared.js +10 -0
  144. package/dist/chains/eni/batch-router/transfer-sweep.d.ts +51 -0
  145. package/dist/chains/eni/batch-router/transfer-sweep.js +364 -0
  146. package/dist/chains/eni/batch-router/transfer.d.ts +4 -74
  147. package/dist/chains/eni/batch-router/transfer.js +2 -647
  148. package/dist/chains/eni/index.d.ts +2 -0
  149. package/dist/chains/eni/index.js +4 -0
  150. package/dist/chains/eni/platforms/daoaas/portal-direct-profit.d.ts +17 -0
  151. package/dist/chains/eni/platforms/daoaas/portal-direct-profit.js +30 -0
  152. package/dist/chains/eni/platforms/daoaas/portal-direct-submit.d.ts +12 -0
  153. package/dist/chains/eni/platforms/daoaas/portal-direct-submit.js +396 -0
  154. package/dist/chains/eni/platforms/daoaas/portal-direct-tx.d.ts +20 -0
  155. package/dist/chains/eni/platforms/daoaas/portal-direct-tx.js +165 -0
  156. package/dist/chains/eni/platforms/daoaas/portal-direct.d.ts +3 -32
  157. package/dist/chains/eni/platforms/daoaas/portal-direct.js +3 -571
  158. package/dist/chains/eni/submit.js +1 -1
  159. package/dist/chains/xlayer/constants.d.ts +0 -2
  160. package/dist/chains/xlayer/constants.js +0 -2
  161. package/dist/chains/xlayer/eip7702/auth.d.ts +16 -0
  162. package/dist/chains/xlayer/eip7702/auth.js +81 -0
  163. package/dist/chains/xlayer/eip7702/bundle-create-buy.d.ts +22 -0
  164. package/dist/chains/xlayer/eip7702/bundle-create-buy.js +201 -0
  165. package/dist/chains/xlayer/eip7702/bundle-create-helpers.d.ts +114 -0
  166. package/dist/chains/xlayer/eip7702/bundle-create-helpers.js +139 -0
  167. package/dist/chains/xlayer/eip7702/bundle-create-to-dex.d.ts +24 -0
  168. package/dist/chains/xlayer/eip7702/bundle-create-to-dex.js +233 -0
  169. package/dist/chains/xlayer/eip7702/bundle-create.d.ts +3 -35
  170. package/dist/chains/xlayer/eip7702/bundle-create.js +3 -746
  171. package/dist/chains/xlayer/eip7702/bundle-graduate-buy.d.ts +22 -0
  172. package/dist/chains/xlayer/eip7702/bundle-graduate-buy.js +214 -0
  173. package/dist/chains/xlayer/eip7702/bundle-sell.js +1 -1
  174. package/dist/chains/xlayer/eip7702/bundle-swap-batch.d.ts +31 -0
  175. package/dist/chains/xlayer/eip7702/bundle-swap-batch.js +216 -0
  176. package/dist/chains/xlayer/eip7702/bundle-swap-helpers.d.ts +21 -0
  177. package/dist/chains/xlayer/eip7702/bundle-swap-helpers.js +206 -0
  178. package/dist/chains/xlayer/eip7702/bundle-swap-multi.d.ts +33 -0
  179. package/dist/chains/xlayer/eip7702/bundle-swap-multi.js +146 -0
  180. package/dist/chains/xlayer/eip7702/bundle-swap-single.d.ts +31 -0
  181. package/dist/chains/xlayer/eip7702/bundle-swap-single.js +177 -0
  182. package/dist/chains/xlayer/eip7702/bundle-swap.d.ts +6 -61
  183. package/dist/chains/xlayer/eip7702/bundle-swap.js +3 -712
  184. package/dist/chains/xlayer/eip7702/bytes.d.ts +4 -0
  185. package/dist/chains/xlayer/eip7702/bytes.js +31 -0
  186. package/dist/chains/xlayer/eip7702/gas.d.ts +19 -0
  187. package/dist/chains/xlayer/eip7702/gas.js +152 -0
  188. package/dist/chains/xlayer/eip7702/multi-hop-transfer-disperse.d.ts +5 -0
  189. package/dist/chains/xlayer/eip7702/multi-hop-transfer-disperse.js +196 -0
  190. package/dist/chains/xlayer/eip7702/multi-hop-transfer-pairwise.d.ts +5 -0
  191. package/dist/chains/xlayer/eip7702/multi-hop-transfer-pairwise.js +188 -0
  192. package/dist/chains/xlayer/eip7702/multi-hop-transfer-sweep.d.ts +5 -0
  193. package/dist/chains/xlayer/eip7702/multi-hop-transfer-sweep.js +220 -0
  194. package/dist/chains/xlayer/eip7702/multi-hop-transfer.d.ts +8 -4
  195. package/dist/chains/xlayer/eip7702/multi-hop-transfer.js +5 -591
  196. package/dist/chains/xlayer/eip7702/profit.d.ts +32 -0
  197. package/dist/chains/xlayer/eip7702/profit.js +59 -0
  198. package/dist/chains/xlayer/eip7702/provider.d.ts +3 -0
  199. package/dist/chains/xlayer/eip7702/provider.js +17 -0
  200. package/dist/chains/xlayer/eip7702/time.d.ts +2 -0
  201. package/dist/chains/xlayer/eip7702/time.js +10 -0
  202. package/dist/chains/xlayer/eip7702/tx-build.d.ts +10 -0
  203. package/dist/chains/xlayer/eip7702/tx-build.js +128 -0
  204. package/dist/chains/xlayer/eip7702/utils.d.ts +19 -85
  205. package/dist/chains/xlayer/eip7702/utils.js +19 -484
  206. package/dist/chains/xlayer/eip7702/volume-bundle.d.ts +13 -0
  207. package/dist/chains/xlayer/eip7702/volume-bundle.js +250 -0
  208. package/dist/chains/xlayer/eip7702/volume-internal.d.ts +13 -0
  209. package/dist/chains/xlayer/eip7702/volume-internal.js +169 -0
  210. package/dist/chains/xlayer/eip7702/volume-make.d.ts +8 -0
  211. package/dist/chains/xlayer/eip7702/volume-make.js +38 -0
  212. package/dist/chains/xlayer/eip7702/volume-single-round.d.ts +17 -0
  213. package/dist/chains/xlayer/eip7702/volume-single-round.js +44 -0
  214. package/dist/chains/xlayer/eip7702/volume-swap.d.ts +18 -0
  215. package/dist/chains/xlayer/eip7702/volume-swap.js +30 -0
  216. package/dist/chains/xlayer/eip7702/volume-wash.d.ts +8 -0
  217. package/dist/chains/xlayer/eip7702/volume-wash.js +191 -0
  218. package/dist/chains/xlayer/eip7702/volume.d.ts +7 -35
  219. package/dist/chains/xlayer/eip7702/volume.js +5 -697
  220. package/dist/chains/xlayer/eip7702/wallet.d.ts +6 -0
  221. package/dist/chains/xlayer/eip7702/wallet.js +17 -0
  222. package/dist/chains/xlayer/eoa/aa-types.d.ts +176 -0
  223. package/dist/chains/xlayer/eoa/aa-types.js +6 -0
  224. package/dist/chains/xlayer/eoa/constants.d.ts +0 -2
  225. package/dist/chains/xlayer/eoa/constants.js +0 -2
  226. package/dist/chains/xlayer/eoa/context.d.ts +8 -0
  227. package/dist/chains/xlayer/eoa/context.js +23 -0
  228. package/dist/chains/xlayer/eoa/encoders.d.ts +147 -0
  229. package/dist/chains/xlayer/eoa/encoders.js +147 -0
  230. package/dist/chains/xlayer/eoa/eoa-bundle-swap-cross.d.ts +5 -0
  231. package/dist/chains/xlayer/eoa/eoa-bundle-swap-cross.js +113 -0
  232. package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.d.ts +10 -123
  233. package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.js +10 -225
  234. package/dist/chains/xlayer/eoa/eoa-bundle-swap-pure.d.ts +50 -0
  235. package/dist/chains/xlayer/eoa/eoa-bundle-swap-pure.js +170 -0
  236. package/dist/chains/xlayer/eoa/eoa-bundle-swap-quick.d.ts +5 -0
  237. package/dist/chains/xlayer/eoa/eoa-bundle-swap-quick.js +257 -0
  238. package/dist/chains/xlayer/eoa/eoa-bundle-swap-types.d.ts +99 -0
  239. package/dist/chains/xlayer/eoa/eoa-bundle-swap-types.js +11 -0
  240. package/dist/chains/xlayer/eoa/eoa-bundle-swap.d.ts +5 -47
  241. package/dist/chains/xlayer/eoa/eoa-bundle-swap.js +3 -522
  242. package/dist/chains/xlayer/eoa/eoa-types.d.ts +776 -0
  243. package/dist/chains/xlayer/eoa/eoa-types.js +6 -0
  244. package/dist/chains/xlayer/eoa/eoa-wash-volume.d.ts +8 -0
  245. package/dist/chains/xlayer/eoa/eoa-wash-volume.js +8 -0
  246. package/dist/chains/xlayer/eoa/format.d.ts +34 -0
  247. package/dist/chains/xlayer/eoa/format.js +56 -0
  248. package/dist/chains/xlayer/eoa/hop-chain.d.ts +4 -0
  249. package/dist/chains/xlayer/eoa/hop-chain.js +87 -0
  250. package/dist/chains/xlayer/eoa/nonce-map.d.ts +20 -0
  251. package/dist/chains/xlayer/eoa/nonce-map.js +51 -0
  252. package/dist/chains/xlayer/eoa/portal-ops.d.ts +9 -292
  253. package/dist/chains/xlayer/eoa/portal-ops.js +9 -486
  254. package/dist/chains/xlayer/eoa/query.d.ts +117 -0
  255. package/dist/chains/xlayer/eoa/query.js +285 -0
  256. package/dist/chains/xlayer/eoa/quote.d.ts +6 -0
  257. package/dist/chains/xlayer/eoa/quote.js +90 -0
  258. package/dist/chains/xlayer/eoa/types.d.ts +9 -959
  259. package/dist/chains/xlayer/eoa/types.js +9 -49
  260. package/dist/core/clients/blockrazor.js +1 -1
  261. package/dist/core/clients/merkle.js +1 -1
  262. package/dist/core/erc20/allowances.d.ts +104 -0
  263. package/dist/core/erc20/allowances.js +205 -0
  264. package/dist/core/erc20/approve.d.ts +141 -0
  265. package/dist/core/erc20/approve.js +325 -0
  266. package/dist/core/erc20/helpers.d.ts +20 -0
  267. package/dist/core/erc20/helpers.js +109 -0
  268. package/dist/core/erc20/index.d.ts +13 -0
  269. package/dist/core/erc20/index.js +12 -0
  270. package/dist/core/gas/bundle-gas.d.ts +6 -1
  271. package/dist/core/index.d.ts +1 -1
  272. package/dist/core/index.js +1 -1
  273. package/dist/core/quote/index.d.ts +1 -0
  274. package/dist/core/quote/index.js +1 -0
  275. package/dist/core/quote/quote-helpers.d.ts +78 -0
  276. package/dist/core/quote/quote-helpers.js +289 -0
  277. package/dist/core/quote/types.d.ts +1 -0
  278. package/dist/core/quote/types.js +1 -0
  279. package/dist/core/sign-context-helpers.d.ts +29 -0
  280. package/dist/core/sign-context-helpers.js +63 -0
  281. package/dist/domains/dex/direct-router-helpers.d.ts +16 -268
  282. package/dist/domains/dex/direct-router-helpers.js +16 -535
  283. package/dist/domains/dex/direct-router-types.d.ts +104 -0
  284. package/dist/domains/dex/direct-router-types.js +81 -0
  285. package/dist/domains/dex/direct-router-v2-buy.d.ts +2 -0
  286. package/dist/domains/dex/direct-router-v2-buy.js +249 -0
  287. package/dist/domains/dex/direct-router-v2-sell.d.ts +5 -0
  288. package/dist/domains/dex/direct-router-v2-sell.js +270 -0
  289. package/dist/domains/dex/direct-router-v2.d.ts +9 -0
  290. package/dist/domains/dex/direct-router-v2.js +9 -0
  291. package/dist/domains/dex/direct-router-v3.d.ts +17 -0
  292. package/dist/domains/dex/direct-router-v3.js +432 -0
  293. package/dist/domains/dex/direct-router.d.ts +11 -26
  294. package/dist/domains/dex/direct-router.js +10 -977
  295. package/dist/domains/dex/dyo-encode.d.ts +62 -0
  296. package/dist/domains/dex/dyo-encode.js +124 -0
  297. package/dist/domains/dex/profit.d.ts +24 -0
  298. package/dist/domains/dex/profit.js +86 -0
  299. package/dist/domains/dex/provider.d.ts +10 -0
  300. package/dist/domains/dex/provider.js +27 -0
  301. package/dist/domains/dex/quote.d.ts +7 -0
  302. package/dist/domains/dex/quote.js +52 -0
  303. package/dist/domains/dex/router.d.ts +56 -0
  304. package/dist/domains/dex/router.js +193 -0
  305. package/dist/domains/flap/portal-bundle/batch.d.ts +9 -0
  306. package/dist/domains/flap/portal-bundle/batch.js +193 -0
  307. package/dist/domains/flap/portal-bundle/create.d.ts +5 -0
  308. package/dist/domains/flap/portal-bundle/create.js +153 -0
  309. package/dist/domains/flap/portal-bundle/helpers.d.ts +32 -0
  310. package/dist/domains/flap/portal-bundle/helpers.js +50 -0
  311. package/dist/domains/flap/portal-bundle/index.d.ts +16 -0
  312. package/dist/domains/flap/portal-bundle/index.js +15 -0
  313. package/dist/domains/flap/portal-bundle/private.d.ts +5 -0
  314. package/dist/domains/flap/portal-bundle/private.js +198 -0
  315. package/dist/domains/flap/portal-bundle/types.d.ts +102 -0
  316. package/dist/domains/flap/portal-bundle/types.js +1 -0
  317. package/dist/domains/flap/portal-bundle-merkle/core-batch.d.ts +13 -0
  318. package/dist/domains/flap/portal-bundle-merkle/core-batch.js +376 -0
  319. package/dist/domains/flap/portal-bundle-merkle/core-helpers.d.ts +75 -7
  320. package/dist/domains/flap/portal-bundle-merkle/core-helpers.js +259 -20
  321. package/dist/domains/flap/portal-bundle-merkle/core.d.ts +2 -13
  322. package/dist/domains/flap/portal-bundle-merkle/core.js +12 -629
  323. package/dist/domains/flap/portal-bundle-merkle/create-to-dex/constants.d.ts +70 -0
  324. package/dist/domains/flap/portal-bundle-merkle/create-to-dex/constants.js +90 -0
  325. package/dist/domains/flap/portal-bundle-merkle/create-to-dex/index.d.ts +12 -0
  326. package/dist/domains/flap/portal-bundle-merkle/create-to-dex/index.js +11 -0
  327. package/dist/domains/flap/portal-bundle-merkle/create-to-dex/main.d.ts +15 -0
  328. package/dist/domains/flap/portal-bundle-merkle/create-to-dex/main.js +432 -0
  329. package/dist/domains/flap/portal-bundle-merkle/create-to-dex/types.d.ts +113 -0
  330. package/dist/domains/flap/portal-bundle-merkle/create-to-dex/types.js +4 -0
  331. package/dist/domains/flap/portal-bundle-merkle/create-to-dex.d.ts +4 -127
  332. package/dist/domains/flap/portal-bundle-merkle/create-to-dex.js +4 -527
  333. package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/constants.d.ts +42 -0
  334. package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/constants.js +81 -0
  335. package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/index.d.ts +12 -0
  336. package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/index.js +11 -0
  337. package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/main.d.ts +15 -0
  338. package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/main.js +339 -0
  339. package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/types.d.ts +72 -0
  340. package/dist/domains/flap/portal-bundle-merkle/curve-to-dex/types.js +4 -0
  341. package/dist/domains/flap/portal-bundle-merkle/curve-to-dex.d.ts +4 -85
  342. package/dist/domains/flap/portal-bundle-merkle/curve-to-dex.js +4 -425
  343. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/approve.d.ts +12 -0
  344. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/approve.js +102 -0
  345. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/buy.d.ts +5 -0
  346. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/buy.js +135 -0
  347. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/helpers.d.ts +52 -0
  348. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/helpers.js +267 -0
  349. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/index.d.ts +14 -0
  350. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/index.js +14 -0
  351. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/sell.d.ts +5 -0
  352. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy/sell.js +195 -0
  353. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy.d.ts +3 -24
  354. package/dist/domains/flap/portal-bundle-merkle/pancake-proxy.js +3 -700
  355. package/dist/domains/flap/portal-bundle-merkle/private/buy.d.ts +9 -0
  356. package/dist/domains/flap/portal-bundle-merkle/private/buy.js +188 -0
  357. package/dist/domains/flap/portal-bundle-merkle/private/helpers.d.ts +36 -0
  358. package/dist/domains/flap/portal-bundle-merkle/private/helpers.js +127 -0
  359. package/dist/domains/flap/portal-bundle-merkle/private/index.d.ts +12 -0
  360. package/dist/domains/flap/portal-bundle-merkle/private/index.js +12 -0
  361. package/dist/domains/flap/portal-bundle-merkle/private/sell.d.ts +9 -0
  362. package/dist/domains/flap/portal-bundle-merkle/private/sell.js +191 -0
  363. package/dist/domains/flap/portal-bundle-merkle/private.d.ts +5 -15
  364. package/dist/domains/flap/portal-bundle-merkle/private.js +5 -494
  365. package/dist/domains/flap/portal-bundle-merkle/swap-batch.js +3 -2
  366. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-chain.d.ts +4 -0
  367. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-chain.js +43 -0
  368. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-constants.d.ts +13 -0
  369. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-constants.js +21 -0
  370. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-helpers.d.ts +11 -121
  371. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-helpers.js +11 -109
  372. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-multi-wallet.d.ts +20 -0
  373. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-multi-wallet.js +223 -0
  374. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-plan.d.ts +32 -0
  375. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-plan.js +66 -0
  376. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-profit.d.ts +22 -0
  377. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-profit.js +22 -0
  378. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-quote.d.ts +51 -0
  379. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-quote.js +149 -0
  380. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-types.d.ts +87 -0
  381. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-types.js +1 -0
  382. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first.js +5 -404
  383. package/dist/domains/flap/portal-bundle-merkle/swap-helpers.d.ts +0 -1
  384. package/dist/domains/flap/portal-bundle-merkle/swap-helpers.js +0 -7
  385. package/dist/domains/flap/portal-bundle-merkle/swap-planning.js +1 -1
  386. package/dist/domains/flap/portal-bundle-merkle/swap-quick-batch.js +3 -2
  387. package/dist/domains/flap/portal-bundle-merkle/swap-single.js +3 -2
  388. package/dist/domains/flap/portal-bundle-merkle/utils/disperse.d.ts +2 -0
  389. package/dist/domains/flap/portal-bundle-merkle/utils/disperse.js +275 -0
  390. package/dist/domains/flap/portal-bundle-merkle/utils/index.d.ts +11 -0
  391. package/dist/domains/flap/portal-bundle-merkle/utils/index.js +11 -0
  392. package/dist/domains/flap/portal-bundle-merkle/utils/sweep.d.ts +9 -0
  393. package/dist/domains/flap/portal-bundle-merkle/utils/sweep.js +570 -0
  394. package/dist/domains/flap/portal-bundle-merkle/utils.d.ts +5 -8
  395. package/dist/domains/flap/portal-bundle-merkle/utils.js +5 -841
  396. package/dist/domains/flap/portal-bundle.d.ts +5 -117
  397. package/dist/domains/flap/portal-bundle.js +5 -587
  398. package/dist/domains/flap/portal.d.ts +13 -404
  399. package/dist/domains/flap/portal.js +12 -619
  400. package/dist/domains/flap/reader.d.ts +51 -0
  401. package/dist/domains/flap/reader.js +275 -0
  402. package/dist/domains/flap/types.d.ts +246 -0
  403. package/dist/domains/flap/types.js +104 -0
  404. package/dist/domains/flap/vault/constants.d.ts +220 -0
  405. package/dist/domains/flap/vault/constants.js +173 -0
  406. package/dist/domains/flap/vault/encode.d.ts +39 -0
  407. package/dist/domains/flap/vault/encode.js +135 -0
  408. package/dist/domains/flap/vault/index.d.ts +15 -0
  409. package/dist/domains/flap/vault/index.js +14 -0
  410. package/dist/domains/flap/vault/query.d.ts +40 -0
  411. package/dist/domains/flap/vault/query.js +104 -0
  412. package/dist/domains/flap/vault/types.d.ts +147 -0
  413. package/dist/domains/flap/vault/types.js +29 -0
  414. package/dist/domains/flap/vault.d.ts +3 -413
  415. package/dist/domains/flap/vault.js +3 -467
  416. package/dist/domains/flap/writer.d.ts +124 -0
  417. package/dist/domains/flap/writer.js +255 -0
  418. package/dist/domains/four/contracts/tm-bundle-batch.d.ts +35 -0
  419. package/dist/domains/four/contracts/tm-bundle-batch.js +286 -0
  420. package/dist/domains/four/contracts/tm-bundle-create.d.ts +2 -0
  421. package/dist/domains/four/contracts/tm-bundle-create.js +304 -0
  422. package/dist/domains/four/contracts/tm-bundle-helpers.d.ts +2 -1
  423. package/dist/domains/four/contracts/tm-bundle-helpers.js +3 -0
  424. package/dist/domains/four/contracts/tm-bundle-private.d.ts +36 -0
  425. package/dist/domains/four/contracts/tm-bundle-private.js +164 -0
  426. package/dist/domains/four/contracts/tm-bundle.d.ts +10 -71
  427. package/dist/domains/four/contracts/tm-bundle.js +9 -738
  428. package/dist/domains/lp-inspect/inspect-helpers.d.ts +25 -0
  429. package/dist/domains/lp-inspect/inspect-helpers.js +343 -0
  430. package/dist/domains/lp-inspect/inspect.d.ts +8 -0
  431. package/dist/domains/lp-inspect/inspect.js +332 -0
  432. package/dist/domains/lp-inspect/lp-inspect.d.ts +9 -37
  433. package/dist/domains/lp-inspect/lp-inspect.js +9 -775
  434. package/dist/domains/lp-inspect/registry.d.ts +43 -0
  435. package/dist/domains/lp-inspect/registry.js +127 -0
  436. package/dist/domains/merkle/index.d.ts +1 -1
  437. package/dist/exports/root-bundle-and-tooling.d.ts +9 -1
  438. package/dist/exports/root-bundle-and-tooling.js +8 -1
  439. package/dist/exports/root-foundations.d.ts +1 -1
  440. package/dist/exports/root-foundations.js +1 -1
  441. package/dist/exports/root-swap-dex-and-xlayer.d.ts +4 -4
  442. package/dist/exports/root-swap-dex-and-xlayer.js +4 -4
  443. package/dist/index.d.ts +1 -1
  444. package/dist/index.js +1 -1
  445. package/dist/utils/swap-helpers.js +1 -1
  446. package/package.json +1 -81
@@ -1,704 +1,7 @@
1
1
  /**
2
2
  * PancakeSwap 官方 Router 交易模块(Flap 版本,支持多链)
3
3
  *
4
- * ✅ 使用官方 PancakeSwap V2/V3 Router(非代理合约)
5
- * - V2 Router (BSC): 0x10ED43C718714eb63d5aA57B78B54704E256024E
6
- * - V3 Router (BSC): 0x13f4EA83D0bd40E75C8222255bc855a974568Dd4
7
- * - V3 Quoter (BSC): 0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997
4
+ * 原超长文件按职责拆分为 pancake-proxy/ 目录下的多个子文件,
5
+ * 对外 export 符号与路径保持不变(见 pancake-proxy/index.ts)。
8
6
  */
9
- import { ethers, Wallet, JsonRpcProvider, Contract, Interface } from 'ethers';
10
- import { NonceManager, getOptimizedGasPrice, getDeadline, encodeV3Path, buildProfitHopTransactions, PROFIT_HOP_COUNT, } from '../../../utils/bundle-helpers.js';
11
- import { ADDRESSES, ZERO_ADDRESS } from '../../../core/constants/index.js';
12
- import { GAS_LIMITS } from '../../../core/constants/index.js';
13
- import { MULTICALL3_ABI, V2_ROUTER_ABI, V3_ROUTER02_ABI, V3_QUOTER_ABI, ERC20_ABI } from '../../../core/shared-abis/common.js';
14
- import { getErrorMessageFromUnknown } from '../../../core/index.js';
15
- import { CHAIN_ID_MAP, getTxType, getGasPriceConfig, shouldExtractProfit, calculateProfit, calculateBatchProfit, getProfitRecipient, getBribeAmount, BLOCKRAZOR_BUILDER_EOA, } from './config.js';
16
- // ==================== 常量 ====================
17
- const MULTICALL3_ADDRESS = ADDRESSES.BSC.Multicall3;
18
- const WBNB_ADDRESS = ADDRESSES.BSC.WBNB;
19
- const DEFAULT_GAS_LIMIT = 800000;
20
- // ✅ PancakeSwap 官方合约地址
21
- const PANCAKE_V2_ROUTER_ADDRESS = ADDRESSES.BSC.PancakeV2Router;
22
- const PANCAKE_V3_ROUTER_ADDRESS = ADDRESSES.BSC.PancakeV3Router;
23
- const PANCAKE_V3_QUOTER_ADDRESS = ADDRESSES.BSC.PancakeV3Quoter;
24
- // ==================== ABI 别名(从公共模块导入)====================
25
- const V3_ROUTER_ABI = V3_ROUTER02_ABI;
26
- // ==================== 官方 ABI ====================
27
- // ✅ ABI 从公共模块导入:V2_ROUTER_ABI, V3_ROUTER02_ABI (as V3_ROUTER_ABI), V3_QUOTER_ABI, ERC20_ABI, MULTICALL3_ABI
28
- // ✅ 工具函数从 bundle-helpers.js 导入:getDeadline, encodeV3Path
29
- // ==================== Provider 缓存 ====================
30
- const providerCache = new Map();
31
- const PROVIDER_CACHE_TTL_MS = 60 * 1000;
32
- // Token Decimals 缓存
33
- const tokenDecimalsCache = new Map();
34
- function getCachedProvider(chain, rpcUrl, chainId) {
35
- const cacheKey = `${chain}-${rpcUrl}`;
36
- const now = Date.now();
37
- const cached = providerCache.get(cacheKey);
38
- if (cached && cached.expireAt > now) {
39
- return cached.provider;
40
- }
41
- const resolvedChainId = chainId ?? (CHAIN_ID_MAP[chain] || 56);
42
- const provider = new JsonRpcProvider(rpcUrl, { chainId: resolvedChainId, name: chain });
43
- providerCache.set(cacheKey, { provider, expireAt: now + PROVIDER_CACHE_TTL_MS });
44
- return provider;
45
- }
46
- // ==================== 辅助函数 ====================
47
- function getGasLimit(config, defaultGas = DEFAULT_GAS_LIMIT) {
48
- if (config.gasLimit !== undefined) {
49
- return typeof config.gasLimit === 'bigint' ? config.gasLimit : BigInt(config.gasLimit);
50
- }
51
- const multiplier = config.gasLimitMultiplier ?? 1.0;
52
- const calculatedGas = Math.ceil(defaultGas * multiplier);
53
- return BigInt(calculatedGas);
54
- }
55
- async function getTokenDecimals(tokenAddress, provider) {
56
- const cacheKey = tokenAddress.toLowerCase();
57
- const cached = tokenDecimalsCache.get(cacheKey);
58
- if (cached !== undefined) {
59
- return cached;
60
- }
61
- try {
62
- const token = new Contract(tokenAddress, ERC20_ABI, provider);
63
- const decimals = await token.decimals();
64
- const result = Number(decimals);
65
- tokenDecimalsCache.set(cacheKey, result);
66
- return result;
67
- }
68
- catch {
69
- tokenDecimalsCache.set(cacheKey, 18);
70
- return 18;
71
- }
72
- }
73
- function needSendBNB(routeType, params, useNativeToken = true) {
74
- if (!useNativeToken) {
75
- return false;
76
- }
77
- if (routeType === 'v2' && params.v2Path && params.v2Path[0].toLowerCase() === WBNB_ADDRESS.toLowerCase()) {
78
- return true;
79
- }
80
- if (routeType === 'v3-single' && params.v3TokenIn && params.v3TokenIn.toLowerCase() === WBNB_ADDRESS.toLowerCase()) {
81
- return true;
82
- }
83
- if (routeType === 'v3-multi' &&
84
- params.v3ExactTokenIn &&
85
- params.v3ExactTokenIn.toLowerCase() === WBNB_ADDRESS.toLowerCase()) {
86
- return true;
87
- }
88
- return false;
89
- }
90
- function isUsingNativeToken(quoteToken) {
91
- return !quoteToken || quoteToken === ZERO_ADDRESS || quoteToken.toLowerCase() === WBNB_ADDRESS.toLowerCase();
92
- }
93
- // ✅ getDeadline 从 bundle-helpers.js 导入
94
- /**
95
- * 根据 routeType 获取授权目标地址
96
- */
97
- function getApprovalTarget(routeType) {
98
- if (routeType === 'v2') {
99
- return PANCAKE_V2_ROUTER_ADDRESS;
100
- }
101
- return PANCAKE_V3_ROUTER_ADDRESS;
102
- }
103
- /**
104
- * ✅ 构建 V2 交易(使用官方 Router)
105
- */
106
- async function buildV2Transactions(routers, wallets, amountsWei, minOuts, path, isBuy, needBNB) {
107
- const deadline = getDeadline();
108
- return Promise.all(routers.map(async (router, i) => {
109
- if (isBuy && needBNB) {
110
- return router.swapExactETHForTokensSupportingFeeOnTransferTokens.populateTransaction(minOuts[i], path, wallets[i].address, deadline, { value: amountsWei[i] });
111
- }
112
- else {
113
- return router.swapExactTokensForETHSupportingFeeOnTransferTokens.populateTransaction(amountsWei[i], minOuts[i], path, wallets[i].address, deadline);
114
- }
115
- }));
116
- }
117
- /**
118
- * ✅ 构建 V3 单跳交易(使用官方 SwapRouter02 + multicall)
119
- */
120
- async function buildV3SingleTransactions(routers, wallets, tokenIn, tokenOut, fee, amountsWei, minOuts, isBuy, needBNB) {
121
- const deadline = getDeadline();
122
- const v3RouterIface = new Interface(V3_ROUTER_ABI);
123
- return Promise.all(routers.map(async (router, i) => {
124
- const isTokenOutWBNB = tokenOut.toLowerCase() === WBNB_ADDRESS.toLowerCase();
125
- const exactInputSingleData = v3RouterIface.encodeFunctionData('exactInputSingle', [
126
- {
127
- tokenIn: tokenIn,
128
- tokenOut: tokenOut,
129
- fee: fee,
130
- recipient: isTokenOutWBNB ? PANCAKE_V3_ROUTER_ADDRESS : wallets[i].address,
131
- amountIn: amountsWei[i],
132
- amountOutMinimum: minOuts[i],
133
- sqrtPriceLimitX96: 0n,
134
- },
135
- ]);
136
- if (isBuy && needBNB) {
137
- return router.multicall.populateTransaction(deadline, [exactInputSingleData], { value: amountsWei[i] });
138
- }
139
- else if (!isBuy && isTokenOutWBNB) {
140
- const unwrapData = v3RouterIface.encodeFunctionData('unwrapWETH9', [minOuts[i], wallets[i].address]);
141
- return router.multicall.populateTransaction(deadline, [exactInputSingleData, unwrapData]);
142
- }
143
- else {
144
- return router.multicall.populateTransaction(deadline, [exactInputSingleData]);
145
- }
146
- }));
147
- }
148
- /**
149
- * ✅ 构建 V3 多跳交易(使用官方 SwapRouter02 的 exactInput)
150
- */
151
- async function buildV3MultiHopTransactions(routers, wallets, tokens, fees, amountsWei, minOuts, isBuy, needBNB) {
152
- if (!tokens || tokens.length < 2) {
153
- throw new Error('V3 多跳需要至少 2 个代币(v3Tokens)');
154
- }
155
- if (!fees || fees.length !== tokens.length - 1) {
156
- throw new Error(`V3 多跳费率数量 (${fees?.length || 0}) 必须等于代币数量 - 1 (${tokens.length - 1})(v3Fees)`);
157
- }
158
- const deadline = getDeadline();
159
- const v3RouterIface = new Interface(V3_ROUTER_ABI);
160
- const forwardPath = encodeV3Path(tokens, fees);
161
- const reversedTokens = [...tokens].reverse();
162
- const reversedFees = [...fees].reverse();
163
- const reversePath = encodeV3Path(reversedTokens, reversedFees);
164
- const tokenOut = tokens[tokens.length - 1];
165
- const isTokenOutWBNB = tokenOut.toLowerCase() === WBNB_ADDRESS.toLowerCase();
166
- return Promise.all(routers.map(async (router, i) => {
167
- if (isBuy && needBNB) {
168
- const swapData = v3RouterIface.encodeFunctionData('exactInput', [
169
- {
170
- path: forwardPath,
171
- recipient: wallets[i].address,
172
- amountIn: amountsWei[i],
173
- amountOutMinimum: minOuts[i],
174
- },
175
- ]);
176
- return router.multicall.populateTransaction(deadline, [swapData], { value: amountsWei[i] });
177
- }
178
- else if (!isBuy) {
179
- const swapData = v3RouterIface.encodeFunctionData('exactInput', [
180
- {
181
- path: reversePath,
182
- recipient: isTokenOutWBNB ? PANCAKE_V3_ROUTER_ADDRESS : wallets[i].address,
183
- amountIn: amountsWei[i],
184
- amountOutMinimum: minOuts[i],
185
- },
186
- ]);
187
- if (isTokenOutWBNB) {
188
- const unwrapData = v3RouterIface.encodeFunctionData('unwrapWETH9', [minOuts[i], wallets[i].address]);
189
- return router.multicall.populateTransaction(deadline, [swapData, unwrapData]);
190
- }
191
- return router.multicall.populateTransaction(deadline, [swapData]);
192
- }
193
- else {
194
- const swapData = v3RouterIface.encodeFunctionData('exactInput', [
195
- {
196
- path: forwardPath,
197
- recipient: wallets[i].address,
198
- amountIn: amountsWei[i],
199
- amountOutMinimum: minOuts[i],
200
- },
201
- ]);
202
- return router.multicall.populateTransaction(deadline, [swapData]);
203
- }
204
- }));
205
- }
206
- // ==================== 主要导出函数 ====================
207
- /**
208
- * ✅ 授权代币给 PancakeSwap Router
209
- */
210
- export async function approvePancakeProxy(params) {
211
- const { chain, privateKey, tokenAddress, amount, rpcUrl, routeType } = params;
212
- const approvalTarget = getApprovalTarget(routeType || 'v2');
213
- const provider = getCachedProvider(chain, rpcUrl);
214
- const wallet = new Wallet(privateKey, provider);
215
- const token = new Contract(tokenAddress, ERC20_ABI, wallet);
216
- const decimals = await getTokenDecimals(tokenAddress, provider);
217
- const currentAllowance = await token.allowance(wallet.address, approvalTarget);
218
- const amountBigInt = amount === 'max' ? ethers.MaxUint256 : ethers.parseUnits(amount, decimals);
219
- if (currentAllowance >= amountBigInt) {
220
- return { txHash: '', approved: true };
221
- }
222
- const tx = await token.approve(approvalTarget, amountBigInt);
223
- const receipt = await tx.wait();
224
- return {
225
- txHash: receipt.hash,
226
- approved: receipt.status === 1,
227
- };
228
- }
229
- /**
230
- * ✅ 批量授权代币给 PancakeSwap Router
231
- */
232
- export async function approvePancakeProxyBatch(params) {
233
- const { chain, privateKeys, tokenAddress, amounts, config, routeType } = params;
234
- if (privateKeys.length === 0 || amounts.length !== privateKeys.length) {
235
- throw new Error('Private key count and amount count must match');
236
- }
237
- const approvalTarget = getApprovalTarget(routeType || 'v2');
238
- const chainId = CHAIN_ID_MAP[chain];
239
- const provider = getCachedProvider(chain, config.rpcUrl, chainId);
240
- const gasPrice = await getOptimizedGasPrice(provider, getGasPriceConfig(config));
241
- const decimals = await getTokenDecimals(tokenAddress, provider);
242
- const wallets = privateKeys.map((k) => new Wallet(k, provider));
243
- const amountsBigInt = amounts.map((a) => (a === 'max' ? ethers.MaxUint256 : ethers.parseUnits(a, decimals)));
244
- const tokens = wallets.map((w) => new Contract(tokenAddress, ERC20_ABI, w));
245
- const allowances = await Promise.all(tokens.map((token, i) => token.allowance(wallets[i].address, approvalTarget)));
246
- const needApproval = wallets.filter((_, i) => allowances[i] < amountsBigInt[i]);
247
- const needApprovalAmounts = amountsBigInt.filter((amount, i) => allowances[i] < amount);
248
- if (needApproval.length === 0) {
249
- return {
250
- success: true,
251
- approvedCount: 0,
252
- signedTransactions: [],
253
- message: '所有钱包已授权',
254
- };
255
- }
256
- const needApprovalTokens = needApproval.map((w) => new Contract(tokenAddress, ERC20_ABI, w));
257
- const unsignedApprovals = await Promise.all(needApprovalTokens.map((token, i) => token.approve.populateTransaction(approvalTarget, needApprovalAmounts[i])));
258
- const finalGasLimit = getGasLimit(config);
259
- const nonceManager = new NonceManager(provider);
260
- const nonces = await Promise.all(needApproval.map((w) => nonceManager.getNextNonce(w)));
261
- const signedTxs = await Promise.all(unsignedApprovals.map((unsigned, i) => needApproval[i].signTransaction({
262
- ...unsigned,
263
- from: needApproval[i].address,
264
- nonce: nonces[i],
265
- gasLimit: finalGasLimit,
266
- gasPrice,
267
- chainId,
268
- type: getTxType(config),
269
- })));
270
- nonceManager.clearTemp();
271
- const txHashes = [];
272
- const errors = [];
273
- for (let i = 0; i < signedTxs.length; i++) {
274
- try {
275
- const tx = await provider.broadcastTransaction(signedTxs[i]);
276
- txHashes.push(tx.hash);
277
- }
278
- catch (error) {
279
- errors.push(`钱包 ${i} 授权失败: ${getErrorMessageFromUnknown(error)}`);
280
- }
281
- }
282
- const successCount = txHashes.length;
283
- if (successCount > 0) {
284
- return {
285
- success: true,
286
- approvedCount: successCount,
287
- signedTransactions: signedTxs,
288
- txHashes,
289
- message: `授权成功,共 ${successCount} 个钱包${errors.length > 0 ? `,${errors.length} 个失败` : ''}`,
290
- };
291
- }
292
- else {
293
- return {
294
- success: false,
295
- approvedCount: 0,
296
- signedTransactions: signedTxs,
297
- txHashes: [],
298
- message: `授权失败: ${errors.join('; ')}`,
299
- };
300
- }
301
- }
302
- /**
303
- * ✅ 使用 PancakeSwap 官方 Router 批量购买代币
304
- */
305
- export async function pancakeProxyBatchBuyMerkle(params) {
306
- const { chain, privateKeys, buyAmounts, tokenAddress, routeType, config, quoteToken, quoteTokenDecimals } = params;
307
- if (privateKeys.length === 0 || buyAmounts.length !== privateKeys.length) {
308
- throw new Error('Private key count and buy amount count must match');
309
- }
310
- const chainId = CHAIN_ID_MAP[chain];
311
- const provider = getCachedProvider(chain, config.rpcUrl, chainId);
312
- const buyers = privateKeys.map((k) => new Wallet(k, provider));
313
- const extractProfit = shouldExtractProfit();
314
- const nonceManager = new NonceManager(provider);
315
- const finalGasLimit = getGasLimit(config);
316
- const useNativeToken = isUsingNativeToken(quoteToken);
317
- const originalAmountsWei = buyAmounts.map((amount) => ethers.parseEther(amount));
318
- const { totalProfit, remainingAmounts } = calculateBatchProfit(originalAmountsWei);
319
- const maxFundsIndex = findMaxAmountIndex(originalAmountsWei);
320
- const shouldExtractProfitForBuy = extractProfit && useNativeToken;
321
- const nativeProfitAmount = shouldExtractProfitForBuy ? totalProfit : 0n;
322
- let actualAmountsWei = remainingAmounts;
323
- if (!useNativeToken && quoteTokenDecimals !== undefined && quoteTokenDecimals !== 18) {
324
- const decimalsDiff = 18 - quoteTokenDecimals;
325
- const divisor = BigInt(10 ** decimalsDiff);
326
- actualAmountsWei = remainingAmounts.map((amount) => amount / divisor);
327
- }
328
- const presetGasPrice = config.gasPrice;
329
- const presetNonces = config.nonces;
330
- const [gasPrice, nonces] = await Promise.all([
331
- presetGasPrice !== undefined
332
- ? Promise.resolve(presetGasPrice)
333
- : getOptimizedGasPrice(provider, getGasPriceConfig(config)),
334
- presetNonces && presetNonces.length === buyers.length
335
- ? Promise.resolve(presetNonces)
336
- : allocateProfitAwareNonces(buyers, shouldExtractProfitForBuy, maxFundsIndex, nativeProfitAmount, nonceManager),
337
- ]);
338
- const minOuts = new Array(buyers.length).fill(0n);
339
- const needBNB = needSendBNB(routeType, params, useNativeToken);
340
- // ✅ 使用官方 Router
341
- let routers;
342
- let unsignedBuys;
343
- if (routeType === 'v2') {
344
- if (!params.v2Path || params.v2Path.length < 2) {
345
- throw new Error('v2Path is required for V2 routing');
346
- }
347
- routers = buyers.map((w) => new Contract(PANCAKE_V2_ROUTER_ADDRESS, V2_ROUTER_ABI, w));
348
- unsignedBuys = await buildV2Transactions(routers, buyers, actualAmountsWei, minOuts, params.v2Path, true, needBNB);
349
- }
350
- else if (routeType === 'v3-single') {
351
- if (!params.v3TokenIn || !params.v3Fee) {
352
- throw new Error('v3TokenIn and v3Fee are required for V3 single-hop');
353
- }
354
- routers = buyers.map((w) => new Contract(PANCAKE_V3_ROUTER_ADDRESS, V3_ROUTER_ABI, w));
355
- unsignedBuys = await buildV3SingleTransactions(routers, buyers, params.v3TokenIn, tokenAddress, params.v3Fee, actualAmountsWei, minOuts, true, needBNB);
356
- }
357
- else if (routeType === 'v3-multi') {
358
- // ✅ V3 多跳:需要 v3Tokens 和 v3Fees 参数
359
- if (!params.v3Tokens || params.v3Tokens.length < 2) {
360
- throw new Error('v3Tokens(至少 2 个代币)是 V3 多跳必需的');
361
- }
362
- if (!params.v3Fees || params.v3Fees.length !== params.v3Tokens.length - 1) {
363
- throw new Error(`v3Fees 长度必须等于 v3Tokens 长度 - 1`);
364
- }
365
- routers = buyers.map((w) => new Contract(PANCAKE_V3_ROUTER_ADDRESS, V3_ROUTER_ABI, w));
366
- unsignedBuys = await buildV3MultiHopTransactions(routers, buyers, params.v3Tokens, params.v3Fees, actualAmountsWei, minOuts, true, needBNB);
367
- }
368
- else {
369
- throw new Error(`Unsupported routeType: ${routeType}`);
370
- }
371
- const bribeAmount = getBribeAmount(config);
372
- const needBribeTx = bribeAmount > 0n && maxFundsIndex >= 0 && buyers.length > 0;
373
- const txType = getTxType(config);
374
- let bribeNonce;
375
- const mutableNonces = [...nonces];
376
- if (needBribeTx) {
377
- bribeNonce = mutableNonces[maxFundsIndex];
378
- mutableNonces[maxFundsIndex] = bribeNonce + 1;
379
- }
380
- const signPromises = [];
381
- if (needBribeTx && bribeNonce !== undefined) {
382
- signPromises.push(buyers[maxFundsIndex].signTransaction({
383
- to: BLOCKRAZOR_BUILDER_EOA,
384
- value: bribeAmount,
385
- nonce: bribeNonce,
386
- gasPrice,
387
- gasLimit: GAS_LIMITS.BRIBE,
388
- chainId,
389
- type: txType,
390
- }));
391
- }
392
- unsignedBuys.forEach((unsigned, i) => {
393
- const txValue = useNativeToken ? (unsigned.value ?? 0n) : 0n;
394
- signPromises.push(buyers[i].signTransaction({
395
- ...unsigned,
396
- from: buyers[i].address,
397
- nonce: mutableNonces[i],
398
- gasLimit: finalGasLimit,
399
- gasPrice,
400
- chainId,
401
- type: txType,
402
- value: txValue,
403
- }));
404
- });
405
- const signedTxs = await Promise.all(signPromises);
406
- // 利润多跳转账(强制 2 跳中转)
407
- let profitHopWallets;
408
- if (shouldExtractProfitForBuy && nativeProfitAmount > 0n && maxFundsIndex >= 0) {
409
- const profitNonce = mutableNonces[maxFundsIndex] + 1;
410
- const profitHopResult = await buildProfitHopTransactions({
411
- provider,
412
- payerWallet: buyers[maxFundsIndex],
413
- profitAmount: nativeProfitAmount,
414
- profitRecipient: getProfitRecipient(),
415
- hopCount: PROFIT_HOP_COUNT,
416
- gasPrice,
417
- chainId,
418
- txType,
419
- startNonce: profitNonce,
420
- });
421
- signedTxs.push(...profitHopResult.signedTransactions);
422
- profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
423
- }
424
- nonceManager.clearTemp();
425
- return {
426
- signedTransactions: signedTxs,
427
- profitHopWallets, // ✅ 返回利润多跳钱包
428
- };
429
- }
430
- /**
431
- * ✅ 使用 PancakeSwap 官方 Router 批量卖出代币
432
- */
433
- export async function pancakeProxyBatchSellMerkle(params) {
434
- const { chain, privateKeys, sellAmounts, tokenAddress, routeType, config } = params;
435
- if (privateKeys.length === 0 || sellAmounts.length !== privateKeys.length) {
436
- throw new Error('Private key count and sell amount count must match');
437
- }
438
- const chainId = CHAIN_ID_MAP[chain];
439
- const provider = getCachedProvider(chain, config.rpcUrl, chainId);
440
- const sellers = privateKeys.map((k) => new Wallet(k, provider));
441
- const finalGasLimit = getGasLimit(config);
442
- const extractProfit = shouldExtractProfit();
443
- const nonceManager = new NonceManager(provider);
444
- const presetGasPrice = config.gasPrice;
445
- const presetNonces = config.nonces;
446
- const [gasPrice, tokenDecimals] = await Promise.all([
447
- presetGasPrice !== undefined
448
- ? Promise.resolve(presetGasPrice)
449
- : getOptimizedGasPrice(provider, getGasPriceConfig(config)),
450
- getTokenDecimals(tokenAddress, provider),
451
- ]);
452
- const amountsWei = sellAmounts.map((amount) => ethers.parseUnits(amount, tokenDecimals));
453
- // 获取报价
454
- let quotedOutputs;
455
- if (routeType === 'v2' && params.v2Path && params.v2Path.length >= 2) {
456
- quotedOutputs = await batchGetV2Quotes(provider, amountsWei, params.v2Path);
457
- }
458
- else if (routeType === 'v3-single') {
459
- quotedOutputs = await Promise.all(amountsWei.map(async (amount) => {
460
- try {
461
- const quoter = new Contract(PANCAKE_V3_QUOTER_ADDRESS, V3_QUOTER_ABI, provider);
462
- const result = await quoter.quoteExactInputSingle.staticCall({
463
- tokenIn: tokenAddress,
464
- tokenOut: params.v3TokenOut,
465
- amountIn: amount,
466
- fee: params.v3Fee,
467
- sqrtPriceLimitX96: 0,
468
- });
469
- return result[0];
470
- }
471
- catch {
472
- return 0n;
473
- }
474
- }));
475
- }
476
- else {
477
- quotedOutputs = new Array(amountsWei.length).fill(0n);
478
- }
479
- const minOuts = new Array(sellers.length).fill(0n);
480
- // 计算利润
481
- let totalProfit = 0n;
482
- let maxRevenueIndex = -1;
483
- let maxRevenue = 0n;
484
- if (extractProfit && quotedOutputs.length > 0) {
485
- for (let i = 0; i < sellers.length; i++) {
486
- const quoted = quotedOutputs[i];
487
- if (quoted > 0n) {
488
- const { profit } = calculateProfit(quoted);
489
- totalProfit += profit;
490
- if (quoted > maxRevenue) {
491
- maxRevenue = quoted;
492
- maxRevenueIndex = i;
493
- }
494
- }
495
- }
496
- }
497
- const bribeAmount = getBribeAmount(config);
498
- const needBribeTx = bribeAmount > 0n && maxRevenueIndex >= 0;
499
- const needProfitTx = extractProfit && totalProfit > 0n && maxRevenueIndex >= 0;
500
- const maxRevenueNonceCount = 1 + (needBribeTx ? 1 : 0) + (needProfitTx ? 1 : 0);
501
- let nonces;
502
- let bribeNonce;
503
- let profitNonce;
504
- if (presetNonces && presetNonces.length === sellers.length) {
505
- nonces = [...presetNonces];
506
- if (needBribeTx) {
507
- bribeNonce = nonces[maxRevenueIndex];
508
- nonces[maxRevenueIndex] = bribeNonce + 1;
509
- }
510
- profitNonce = needProfitTx ? nonces[maxRevenueIndex] + 1 : undefined;
511
- }
512
- else if (maxRevenueNonceCount > 1 && maxRevenueIndex >= 0) {
513
- const maxRevenueNonces = await nonceManager.getNextNonceBatch(sellers[maxRevenueIndex], maxRevenueNonceCount);
514
- const otherSellers = sellers.filter((_, i) => i !== maxRevenueIndex);
515
- const otherNonces = otherSellers.length > 0 ? await nonceManager.getNextNoncesForWallets(otherSellers) : [];
516
- nonces = [];
517
- let otherIdx = 0;
518
- let nonceIdx = 0;
519
- if (needBribeTx) {
520
- bribeNonce = maxRevenueNonces[nonceIdx++];
521
- }
522
- for (let i = 0; i < sellers.length; i++) {
523
- if (i === maxRevenueIndex) {
524
- nonces.push(maxRevenueNonces[nonceIdx++]);
525
- }
526
- else {
527
- nonces.push(otherNonces[otherIdx++]);
528
- }
529
- }
530
- if (needProfitTx) {
531
- profitNonce = maxRevenueNonces[nonceIdx];
532
- }
533
- }
534
- else {
535
- nonces = await nonceManager.getNextNoncesForWallets(sellers);
536
- }
537
- // ✅ 使用官方 Router 构建卖出交易
538
- let routers;
539
- let unsignedSells;
540
- if (routeType === 'v2') {
541
- if (!params.v2Path || params.v2Path.length < 2) {
542
- throw new Error('v2Path is required for V2 routing');
543
- }
544
- routers = sellers.map((w) => new Contract(PANCAKE_V2_ROUTER_ADDRESS, V2_ROUTER_ABI, w));
545
- unsignedSells = await buildV2Transactions(routers, sellers, amountsWei, minOuts, params.v2Path, false, false);
546
- }
547
- else if (routeType === 'v3-single') {
548
- if (!params.v3TokenOut || !params.v3Fee) {
549
- throw new Error('v3TokenOut and v3Fee are required for V3 single-hop');
550
- }
551
- routers = sellers.map((w) => new Contract(PANCAKE_V3_ROUTER_ADDRESS, V3_ROUTER_ABI, w));
552
- unsignedSells = await buildV3SingleTransactions(routers, sellers, tokenAddress, params.v3TokenOut, params.v3Fee, amountsWei, minOuts, false, false);
553
- }
554
- else if (routeType === 'v3-multi') {
555
- // ✅ V3 多跳:需要 v3Tokens 和 v3Fees 参数
556
- if (!params.v3Tokens || params.v3Tokens.length < 2) {
557
- throw new Error('v3Tokens(至少 2 个代币)是 V3 多跳必需的');
558
- }
559
- if (!params.v3Fees || params.v3Fees.length !== params.v3Tokens.length - 1) {
560
- throw new Error(`v3Fees 长度必须等于 v3Tokens 长度 - 1`);
561
- }
562
- routers = sellers.map((w) => new Contract(PANCAKE_V3_ROUTER_ADDRESS, V3_ROUTER_ABI, w));
563
- unsignedSells = await buildV3MultiHopTransactions(routers, sellers, params.v3Tokens, params.v3Fees, amountsWei, minOuts, false, false);
564
- }
565
- else {
566
- throw new Error(`Unsupported routeType: ${routeType}`);
567
- }
568
- const txType = getTxType(config);
569
- const signPromises = [];
570
- if (needBribeTx && bribeNonce !== undefined) {
571
- signPromises.push(sellers[maxRevenueIndex].signTransaction({
572
- to: BLOCKRAZOR_BUILDER_EOA,
573
- value: bribeAmount,
574
- nonce: bribeNonce,
575
- gasPrice,
576
- gasLimit: GAS_LIMITS.BRIBE,
577
- chainId,
578
- type: txType,
579
- }));
580
- }
581
- unsignedSells.forEach((unsigned, i) => {
582
- const txValue = unsigned.value ?? 0n;
583
- signPromises.push(sellers[i].signTransaction({
584
- ...unsigned,
585
- from: sellers[i].address,
586
- nonce: nonces[i],
587
- gasLimit: finalGasLimit,
588
- gasPrice,
589
- chainId,
590
- type: txType,
591
- value: txValue,
592
- }));
593
- });
594
- const signedTxs = await Promise.all(signPromises);
595
- // 利润多跳转账(强制 2 跳中转)
596
- let profitHopWallets;
597
- if (needProfitTx && profitNonce !== undefined) {
598
- const profitHopResult = await buildProfitHopTransactions({
599
- provider,
600
- payerWallet: sellers[maxRevenueIndex],
601
- profitAmount: totalProfit,
602
- profitRecipient: getProfitRecipient(),
603
- hopCount: PROFIT_HOP_COUNT,
604
- gasPrice,
605
- chainId,
606
- txType,
607
- startNonce: profitNonce,
608
- });
609
- signedTxs.push(...profitHopResult.signedTransactions);
610
- profitHopWallets = profitHopResult.hopWallets; // ✅ 收集利润多跳钱包
611
- }
612
- nonceManager.clearTemp();
613
- return {
614
- signedTransactions: signedTxs,
615
- profitHopWallets, // ✅ 返回利润多跳钱包
616
- };
617
- }
618
- // ==================== 内部工具函数 ====================
619
- /**
620
- * ✅ 使用 Multicall3 批量获取 V2 报价
621
- */
622
- async function batchGetV2Quotes(provider, amountsWei, v2Path) {
623
- if (amountsWei.length === 0)
624
- return [];
625
- if (amountsWei.length === 1) {
626
- try {
627
- const v2Router = new Contract(PANCAKE_V2_ROUTER_ADDRESS, V2_ROUTER_ABI, provider);
628
- const amounts = await v2Router.getAmountsOut(amountsWei[0], v2Path);
629
- return [amounts[amounts.length - 1]];
630
- }
631
- catch {
632
- return [0n];
633
- }
634
- }
635
- try {
636
- const v2RouterIface = new Interface(V2_ROUTER_ABI);
637
- const multicall = new Contract(MULTICALL3_ADDRESS, MULTICALL3_ABI, provider);
638
- const calls = amountsWei.map((amount) => ({
639
- target: PANCAKE_V2_ROUTER_ADDRESS,
640
- allowFailure: true,
641
- callData: v2RouterIface.encodeFunctionData('getAmountsOut', [amount, v2Path]),
642
- }));
643
- const results = await multicall.aggregate3.staticCall(calls);
644
- return results.map((r) => {
645
- if (r.success && r.returnData && r.returnData !== '0x') {
646
- try {
647
- const decoded = v2RouterIface.decodeFunctionResult('getAmountsOut', r.returnData);
648
- const amounts = decoded[0];
649
- return amounts[amounts.length - 1];
650
- }
651
- catch {
652
- return 0n;
653
- }
654
- }
655
- return 0n;
656
- });
657
- }
658
- catch {
659
- return await Promise.all(amountsWei.map(async (amount) => {
660
- try {
661
- const v2Router = new Contract(PANCAKE_V2_ROUTER_ADDRESS, V2_ROUTER_ABI, provider);
662
- const amounts = await v2Router.getAmountsOut(amount, v2Path);
663
- return amounts[amounts.length - 1];
664
- }
665
- catch {
666
- return 0n;
667
- }
668
- }));
669
- }
670
- }
671
- function findMaxAmountIndex(amounts) {
672
- if (!amounts.length) {
673
- return -1;
674
- }
675
- let maxIndex = 0;
676
- let maxValue = amounts[0];
677
- for (let i = 1; i < amounts.length; i++) {
678
- if (amounts[i] > maxValue) {
679
- maxValue = amounts[i];
680
- maxIndex = i;
681
- }
682
- }
683
- return maxIndex;
684
- }
685
- async function allocateProfitAwareNonces(wallets, extractProfit, maxIndex, totalProfit, nonceManager) {
686
- const needProfitTx = extractProfit && totalProfit > 0n && maxIndex >= 0 && maxIndex < wallets.length;
687
- if (!needProfitTx) {
688
- return await nonceManager.getNextNoncesForWallets(wallets);
689
- }
690
- const maxIndexNonces = await nonceManager.getNextNonceBatch(wallets[maxIndex], 2);
691
- const otherWallets = wallets.filter((_, i) => i !== maxIndex);
692
- const otherNonces = otherWallets.length > 0 ? await nonceManager.getNextNoncesForWallets(otherWallets) : [];
693
- const nonces = [];
694
- let otherIdx = 0;
695
- for (let i = 0; i < wallets.length; i++) {
696
- if (i === maxIndex) {
697
- nonces.push(maxIndexNonces[0]);
698
- }
699
- else {
700
- nonces.push(otherNonces[otherIdx++]);
701
- }
702
- }
703
- return nonces;
704
- }
7
+ export * from './pancake-proxy/index.js';