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
@@ -9,715 +9,6 @@
9
9
  * 支持 FLAP 内盘、V2 和 V3 三种交易类型
10
10
  * 只生成签名,由调用方决定如何提交
11
11
  */
12
- import { ethers, Contract } from 'ethers';
13
- import { quoteV2, quoteV3 } from '../../../domains/quote/quote-helpers.js';
14
- import { getCachedProvider, createWallet, signAuthorization, signAuthorizationsWithNonces, batchGetNonces, buildEIP7702TransactionSync, calculateProfitAmountByUserType, calculateProfitAmountByTxCount, getProfitRecipient, generateRandomWallets, } from './utils.js';
15
- import { UNIFIED_DELEGATE_ADDRESS, POTATOSWAP_V2_ROUTER, POTATOSWAP_V3_ROUTER, FLAP_PORTAL_ADDRESS, WOKB_ADDRESS, V3_FEE_TIERS, UNIFIED_DELEGATE_ABI, FLAP_PORTAL_ABI, ERC20_ABI, XLAYER_RPC_URL, } from './constants.js';
16
- // ========================================
17
- // 路由地址获取
18
- // ========================================
19
- function getDefaultRouter(tradeType) {
20
- switch (tradeType) {
21
- case 'FLAP':
22
- return FLAP_PORTAL_ADDRESS;
23
- case 'V2':
24
- return POTATOSWAP_V2_ROUTER;
25
- case 'V3':
26
- return POTATOSWAP_V3_ROUTER;
27
- }
28
- }
29
- /**
30
- * 截断小数位数,避免 parseEther/parseUnits 报错
31
- * @param value 数值字符串
32
- * @param decimals 保留的小数位数(默认 18)
33
- */
34
- function truncateDecimals(value, decimals = 18) {
35
- if (!value || value === '0')
36
- return value;
37
- const parts = String(value).split('.');
38
- if (parts.length === 1)
39
- return value;
40
- const intPart = parts[0] || '0';
41
- const decPart = (parts[1] || '').slice(0, decimals);
42
- return decPart ? `${intPart}.${decPart}` : intPart;
43
- }
44
- // ========================================
45
- // 卖出报价(Token → OKB)
46
- // ========================================
47
- /**
48
- * 获取卖出报价:预估卖出代币能得到多少 OKB
49
- */
50
- async function quoteSellOutput(sellAmount, tokenAddress, tradeType, fee, rpcUrl) {
51
- if (sellAmount <= 0n)
52
- return 0n;
53
- const provider = getCachedProvider(rpcUrl || XLAYER_RPC_URL);
54
- try {
55
- switch (tradeType) {
56
- case 'FLAP': {
57
- // FLAP Portal 报价
58
- const portalContract = new Contract(FLAP_PORTAL_ADDRESS, FLAP_PORTAL_ABI, provider);
59
- // ✅ 优先使用 quoteExactInput.staticCall(与 AA 模式一致)
60
- try {
61
- const okbOut = await portalContract.quoteExactInput.staticCall({
62
- inputToken: tokenAddress,
63
- outputToken: ethers.ZeroAddress,
64
- inputAmount: sellAmount,
65
- });
66
- return BigInt(okbOut.toString());
67
- }
68
- catch {
69
- // fallback to previewSell
70
- }
71
- // 回退到 previewSell
72
- try {
73
- const okbOut = await portalContract.previewSell(tokenAddress, sellAmount);
74
- return BigInt(okbOut.toString());
75
- }
76
- catch {
77
- // fallback to V2
78
- }
79
- // 回退到 V2
80
- const v2Result = await quoteV2(provider, tokenAddress, WOKB_ADDRESS, sellAmount, 'XLAYER');
81
- if (v2Result.amountOut > 0n) {
82
- return v2Result.amountOut;
83
- }
84
- break;
85
- }
86
- case 'V2': {
87
- const result = await quoteV2(provider, tokenAddress, WOKB_ADDRESS, sellAmount, 'XLAYER');
88
- if (result.amountOut > 0n) {
89
- return result.amountOut;
90
- }
91
- break;
92
- }
93
- case 'V3': {
94
- const result = await quoteV3(provider, tokenAddress, WOKB_ADDRESS, sellAmount, 'XLAYER', fee);
95
- if (result.amountOut > 0n) {
96
- return result.amountOut;
97
- }
98
- // 回退到 V2
99
- const v2Result = await quoteV2(provider, tokenAddress, WOKB_ADDRESS, sellAmount, 'XLAYER');
100
- if (v2Result.amountOut > 0n) {
101
- return v2Result.amountOut;
102
- }
103
- break;
104
- }
105
- }
106
- }
107
- catch {
108
- // quote failed, return 0
109
- }
110
- return 0n;
111
- }
112
- export async function bundleSwap(params) {
113
- const { sellerPrivateKey, buyerPrivateKey, tokenAddress, tokenDecimals = 18, sellAmount, hopCount = 0, tradeType = 'V3', routerAddress, fee = V3_FEE_TIERS.MEDIUM, userType = 'v0', useFundUtilization = false, // ✅ 默认普通模式
114
- config, } = params;
115
- const provider = getCachedProvider(config?.rpcUrl);
116
- const delegateAddress = (config?.delegateAddress && config.delegateAddress.trim()) || UNIFIED_DELEGATE_ADDRESS;
117
- const delegateInterface = new ethers.Interface(UNIFIED_DELEGATE_ABI);
118
- const actualRouter = routerAddress ?? getDefaultRouter(tradeType);
119
- const portalInterface = new ethers.Interface(FLAP_PORTAL_ABI);
120
- // ========================================
121
- // 同步操作 - 创建钱包
122
- // ========================================
123
- const sellerWallet = createWallet(sellerPrivateKey, provider);
124
- const buyerWallet = createWallet(buyerPrivateKey, provider);
125
- // 资金利用率模式才需要中间钱包
126
- const actualHopCount = useFundUtilization ? hopCount : 0;
127
- const hopWalletInfos = actualHopCount > 0 ? generateRandomWallets(actualHopCount) : [];
128
- const hopWallets = hopWalletInfos.map((info) => createWallet(info.privateKey, provider));
129
- const sellAmountWei = ethers.parseUnits(truncateDecimals(sellAmount, tokenDecimals), tokenDecimals);
130
- // 获取卖出报价
131
- const estimatedOkbOut = await quoteSellOutput(sellAmountWei, tokenAddress, tradeType, fee, config?.rpcUrl);
132
- // 使用双边费率计算利润(换手 = 卖 + 买)
133
- const profitAmount = estimatedOkbOut > 0n ? calculateProfitAmountByUserType(estimatedOkbOut, userType, true) : 0n;
134
- const profitRecipient = getProfitRecipient(config);
135
- // 计算买入金额
136
- const buyAmountAfterProfit = estimatedOkbOut > profitAmount ? estimatedOkbOut - profitAmount : 0n;
137
- // ========================================
138
- // 并行获取数据
139
- // ========================================
140
- const [nonces, feeData, buyerBalance] = await Promise.all([
141
- batchGetNonces([sellerWallet.address, buyerWallet.address], provider),
142
- provider.getFeeData(),
143
- provider.getBalance(buyerWallet.address),
144
- ]);
145
- const sellerNonce = nonces[0];
146
- const buyerNonce = nonces[1];
147
- // ========================================
148
- // 验证余额
149
- // ========================================
150
- if (tradeType === 'FLAP' && buyAmountAfterProfit <= 0n) {
151
- throw new Error('FLAP 内盘模式需要有效的报价,请检查代币地址或稍后重试');
152
- }
153
- // 普通模式:买家需要预存足够的 OKB
154
- if (!useFundUtilization && tradeType === 'FLAP') {
155
- if (buyerBalance < buyAmountAfterProfit) {
156
- throw new Error(`普通模式需要买家钱包有足够的 OKB,需要 ${ethers.formatEther(buyAmountAfterProfit)},当前 ${ethers.formatEther(buyerBalance)}`);
157
- }
158
- }
159
- // ========================================
160
- // 签署授权
161
- // ========================================
162
- const authPromises = [];
163
- // 卖家授权(交易发起者,nonce +1)
164
- authPromises.push(signAuthorization(sellerWallet, delegateAddress, BigInt(sellerNonce + 1)));
165
- // 买家授权
166
- authPromises.push(signAuthorization(buyerWallet, delegateAddress, BigInt(buyerNonce)));
167
- // 中间钱包授权(资金利用率模式)
168
- for (const hopWallet of hopWallets) {
169
- authPromises.push(signAuthorization(hopWallet, delegateAddress, 0n));
170
- }
171
- const authorizations = await Promise.all(authPromises);
172
- // ========================================
173
- // 构建调用
174
- // ========================================
175
- const calls = [];
176
- if (useFundUtilization) {
177
- // ========================================
178
- // ✅ 资金利用率模式
179
- // 核心逻辑:卖出获得的 OKB 按比例转给买家
180
- // 1. 卖家卖出代币 → 获得 OKB
181
- // 2. 利润从卖家 OKB 中扣除
182
- // 3. (可选多跳)卖家 → hop1 → hop2 → ... → 分发者
183
- // 4. 分发者按比例转账给买家
184
- // 5. 买家买入
185
- // ========================================
186
- // 1. 卖家卖出
187
- const sellCall = buildSellCallWithAmountInternal(sellerWallet, sellAmountWei, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
188
- calls.push(sellCall);
189
- // 2. 利润刮取(从卖家余额扣除)
190
- if (profitAmount > 0n) {
191
- calls.push({
192
- target: sellerWallet.address,
193
- allowFailure: false,
194
- value: 0n,
195
- callData: delegateInterface.encodeFunctionData('transferAmount', [profitRecipient, profitAmount]),
196
- });
197
- }
198
- // 3. 确定分发者:如果有多跳,最后一个 hop 是分发者;否则卖家是分发者
199
- const distributor = hopWallets.length > 0 ? hopWallets[hopWallets.length - 1] : sellerWallet;
200
- // 多跳转账(如果有)
201
- if (hopWallets.length > 0) {
202
- // ✅ 修复:卖家只转移"卖出所得 - 利润",不是全部余额
203
- // 避免把卖家原有的 OKB 也转走
204
- calls.push({
205
- target: sellerWallet.address,
206
- allowFailure: false,
207
- value: 0n,
208
- callData: delegateInterface.encodeFunctionData('transferAmount', [hopWallets[0].address, buyAmountAfterProfit]),
209
- });
210
- // hop1 → hop2 → ... → 最后一个 hop(分发者):使用 transferTo(全部余额)
211
- for (let i = 0; i < hopWallets.length - 1; i++) {
212
- calls.push({
213
- target: hopWallets[i].address,
214
- allowFailure: false,
215
- value: 0n,
216
- callData: delegateInterface.encodeFunctionData('transferTo', [hopWallets[i + 1].address]),
217
- });
218
- }
219
- }
220
- // 4. 分发者转账给买家:使用 transferTo(全部余额,确保资金不滞留)
221
- calls.push({
222
- target: distributor.address,
223
- allowFailure: false,
224
- value: 0n,
225
- callData: delegateInterface.encodeFunctionData('transferTo', [buyerWallet.address]),
226
- });
227
- // 5. 买家买入(使用收到的 OKB)
228
- const buyCall = buildBuyCallInternal(buyerWallet, buyAmountAfterProfit, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
229
- calls.push(buyCall);
230
- }
231
- else {
232
- // ========================================
233
- // ✅ 普通模式
234
- // 1. 卖家卖出代币 → OKB 留在卖家账户
235
- // 2. 买家用自己预存的 OKB 买入代币
236
- // 3. 利润从买家的 OKB 中扣除
237
- // ========================================
238
- // 1. 卖家卖出(OKB 留在卖家账户)
239
- const sellCall = buildSellCallWithAmountInternal(sellerWallet, sellAmountWei, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
240
- calls.push(sellCall);
241
- // 2. 利润刮取(从买家余额扣除)
242
- if (profitAmount > 0n) {
243
- calls.push({
244
- target: buyerWallet.address,
245
- allowFailure: false,
246
- value: 0n,
247
- callData: delegateInterface.encodeFunctionData('transferAmount', [profitRecipient, profitAmount]),
248
- });
249
- }
250
- // 3. 买家用自己的 OKB 买入(金额 = 卖家卖出所得,避免买卖资金不匹配)
251
- const buyCall = buildBuyCallInternal(buyerWallet, buyAmountAfterProfit, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
252
- calls.push(buyCall);
253
- }
254
- // ========================================
255
- // 构建交易
256
- // ========================================
257
- const signedTransaction = buildEIP7702TransactionSync(sellerWallet, authorizations, calls, 0n, sellerNonce, feeData, config);
258
- return {
259
- signedTransaction,
260
- hopWallets: hopWalletInfos,
261
- metadata: {
262
- sellerAddress: sellerWallet.address,
263
- buyerAddresses: [buyerWallet.address],
264
- sellAmount: ethers.formatUnits(sellAmountWei, tokenDecimals),
265
- estimatedOkbOut: ethers.formatEther(estimatedOkbOut),
266
- estimatedBuyAmount: ethers.formatEther(buyAmountAfterProfit),
267
- profitAmount: ethers.formatEther(profitAmount),
268
- profitRecipient,
269
- userType,
270
- useFundUtilization,
271
- },
272
- };
273
- }
274
- /**
275
- * 批量换手(一卖多买)- 生成签名后的交易
276
- *
277
- * @param params 批量换手参数
278
- * @returns 签名后的交易和元数据
279
- *
280
- * @example
281
- * // FLAP 内盘一对多换手
282
- * const result = await bundleBatchSwap({
283
- * sellerPrivateKey: '0x...',
284
- * buyerPrivateKeys: ['0x...', '0x...'],
285
- * tokenAddress: '0x...',
286
- * sellAmount: '100',
287
- * tradeType: 'FLAP',
288
- * });
289
- */
290
- export async function bundleBatchSwap(params) {
291
- const { sellerPrivateKey, buyerPrivateKeys, buyerRatios, tokenAddress, tokenDecimals = 18, sellAmount, hopCount = 0, tradeType = 'V3', routerAddress, fee = V3_FEE_TIERS.MEDIUM, userType = 'v0', useFundUtilization = false, // ✅ 默认普通模式
292
- config, } = params;
293
- const provider = getCachedProvider(config?.rpcUrl);
294
- const delegateAddress = (config?.delegateAddress && config.delegateAddress.trim()) || UNIFIED_DELEGATE_ADDRESS;
295
- const actualRouter = routerAddress ?? getDefaultRouter(tradeType);
296
- const delegateInterface = new ethers.Interface(UNIFIED_DELEGATE_ABI);
297
- const portalInterface = new ethers.Interface(FLAP_PORTAL_ABI);
298
- // ========================================
299
- // 创建钱包
300
- // ========================================
301
- const sellerWallet = createWallet(sellerPrivateKey, provider);
302
- const buyerWallets = buyerPrivateKeys.map((pk) => createWallet(pk, provider));
303
- // 资金利用率模式才需要中间钱包
304
- const actualHopCount = useFundUtilization ? hopCount : 0;
305
- const hopWalletInfos = actualHopCount > 0 ? generateRandomWallets(actualHopCount) : [];
306
- const hopWallets = hopWalletInfos.map((info) => createWallet(info.privateKey, provider));
307
- const sellAmountWei = ethers.parseUnits(truncateDecimals(sellAmount, tokenDecimals), tokenDecimals);
308
- // 获取卖出报价
309
- const estimatedOkbOut = await quoteSellOutput(sellAmountWei, tokenAddress, tradeType, fee, config?.rpcUrl);
310
- // 计算利润和买入金额
311
- const profitAmount = estimatedOkbOut > 0n ? calculateProfitAmountByUserType(estimatedOkbOut, userType, true) : 0n;
312
- const profitRecipient = getProfitRecipient(config);
313
- const totalBuyAmountAfterProfit = estimatedOkbOut > profitAmount ? estimatedOkbOut - profitAmount : 0n;
314
- // 验证报价
315
- if (tradeType === 'FLAP' && totalBuyAmountAfterProfit <= 0n) {
316
- throw new Error('FLAP 内盘模式需要有效的报价,请检查代币地址或稍后重试');
317
- }
318
- // ========================================
319
- // 并行获取数据
320
- // ========================================
321
- const addressesToQuery = [sellerWallet.address, ...buyerWallets.map((w) => w.address)];
322
- const [nonces, feeData, ...buyerBalances] = await Promise.all([
323
- batchGetNonces(addressesToQuery, provider),
324
- provider.getFeeData(),
325
- ...buyerWallets.map((w) => provider.getBalance(w.address)),
326
- ]);
327
- const sellerNonce = nonces[0];
328
- const buyerNonces = nonces.slice(1);
329
- // 普通模式验证:买家需要预存足够的 OKB
330
- if (!useFundUtilization && tradeType === 'FLAP') {
331
- const totalBuyerBalance = buyerBalances.reduce((sum, b) => sum + BigInt(b.toString()), 0n);
332
- if (totalBuyerBalance < totalBuyAmountAfterProfit) {
333
- throw new Error(`普通模式需要买家钱包总余额足够,需要 ${ethers.formatEther(totalBuyAmountAfterProfit)},当前总计 ${ethers.formatEther(totalBuyerBalance)}`);
334
- }
335
- }
336
- // ========================================
337
- // 签署授权
338
- // ========================================
339
- const authPromises = [];
340
- authPromises.push(signAuthorization(sellerWallet, delegateAddress, BigInt(sellerNonce + 1)));
341
- for (let i = 0; i < buyerWallets.length; i++) {
342
- authPromises.push(signAuthorization(buyerWallets[i], delegateAddress, BigInt(buyerNonces[i])));
343
- }
344
- // 中间钱包授权(资金利用率模式)
345
- for (const hopWallet of hopWallets) {
346
- authPromises.push(signAuthorization(hopWallet, delegateAddress, 0n));
347
- }
348
- const authorizations = await Promise.all(authPromises);
349
- // ========================================
350
- // 构建调用
351
- // ========================================
352
- const calls = [];
353
- // ✅ 计算每个买家的买入金额
354
- // 所有模式都按比例分配卖家卖出所得,避免买卖资金不匹配
355
- let buyAmountsPerBuyer;
356
- if (buyerWallets.length === 1) {
357
- // 单买家:使用全部卖出所得
358
- buyAmountsPerBuyer = [totalBuyAmountAfterProfit];
359
- }
360
- else if (buyerRatios && buyerRatios.length === buyerWallets.length) {
361
- // 多买家 + 有比例:按前端传入的比例分配
362
- let allocated = 0n;
363
- buyAmountsPerBuyer = buyerRatios.map((ratio, i) => {
364
- const amount = (totalBuyAmountAfterProfit * BigInt(Math.round(ratio * 10000))) / 10000n;
365
- if (i === buyerRatios.length - 1) {
366
- return totalBuyAmountAfterProfit - allocated;
367
- }
368
- allocated += amount;
369
- return amount;
370
- });
371
- }
372
- else {
373
- // 多买家无比例:均分
374
- const avgAmount = totalBuyAmountAfterProfit / BigInt(buyerWallets.length);
375
- const remainder = totalBuyAmountAfterProfit % BigInt(buyerWallets.length);
376
- buyAmountsPerBuyer = buyerWallets.map((_, i) => i === buyerWallets.length - 1 ? avgAmount + remainder : avgAmount);
377
- }
378
- if (useFundUtilization) {
379
- // ========================================
380
- // ✅ 资金利用率模式(一卖多买)
381
- // 1. 卖家卖出代币 → 获得 OKB
382
- // 2. 利润从卖家 OKB 中扣除
383
- // 3. 卖家(或最后一个 hop)按比例转账给各买家
384
- // 4. 各买家用收到的 OKB 买入
385
- // ========================================
386
- // 1. 卖家卖出
387
- const sellCall = buildSellCallWithAmountInternal(sellerWallet, sellAmountWei, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
388
- calls.push(sellCall);
389
- // 2. 利润刮取(从卖家余额扣除)
390
- if (profitAmount > 0n) {
391
- calls.push({
392
- target: sellerWallet.address,
393
- allowFailure: false,
394
- value: 0n,
395
- callData: delegateInterface.encodeFunctionData('transferAmount', [profitRecipient, profitAmount]),
396
- });
397
- }
398
- // 3. OKB 转账逻辑
399
- // 确定分发者:如果有多跳,最后一个 hop 是分发者;否则卖家是分发者
400
- const distributor = hopWallets.length > 0 ? hopWallets[hopWallets.length - 1] : sellerWallet;
401
- if (hopWallets.length > 0) {
402
- // ✅ 修复:卖家只转移"卖出所得 - 利润",不是全部余额
403
- // 避免把卖家原有的 OKB 也转走
404
- calls.push({
405
- target: sellerWallet.address,
406
- allowFailure: false,
407
- value: 0n,
408
- callData: delegateInterface.encodeFunctionData('transferAmount', [
409
- hopWallets[0].address,
410
- totalBuyAmountAfterProfit,
411
- ]),
412
- });
413
- // 中间钱包之间转账(到最后一个 hop):使用 transferTo(全部余额)
414
- for (let i = 0; i < hopWallets.length - 1; i++) {
415
- calls.push({
416
- target: hopWallets[i].address,
417
- allowFailure: false,
418
- value: 0n,
419
- callData: delegateInterface.encodeFunctionData('transferTo', [hopWallets[i + 1].address]),
420
- });
421
- }
422
- }
423
- // 分发者按比例转给各买家
424
- for (let i = 0; i < buyerWallets.length; i++) {
425
- const amountToTransfer = buyAmountsPerBuyer[i];
426
- if (amountToTransfer <= 0n)
427
- continue;
428
- // ✅ 最后一个买家使用 transferTo(全部余额),确保资金不滞留
429
- const isLastBuyer = i === buyerWallets.length - 1;
430
- calls.push({
431
- target: distributor.address,
432
- allowFailure: false,
433
- value: 0n,
434
- callData: isLastBuyer
435
- ? delegateInterface.encodeFunctionData('transferTo', [buyerWallets[i].address])
436
- : delegateInterface.encodeFunctionData('transferAmount', [buyerWallets[i].address, amountToTransfer]),
437
- });
438
- }
439
- // 4. 所有买家买入
440
- for (let i = 0; i < buyerWallets.length; i++) {
441
- const buyCall = buildBuyCallInternal(buyerWallets[i], buyAmountsPerBuyer[i], tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
442
- calls.push(buyCall);
443
- }
444
- }
445
- else {
446
- // ========================================
447
- // ✅ 普通模式(一卖多买)
448
- // 1. 卖家卖出代币 → OKB 留在卖家账户
449
- // 2. 利润从第一个买家 OKB 中扣除
450
- // 3. 各买家用自己预存的 OKB 买入
451
- // ========================================
452
- // 1. 卖家卖出(OKB 留在卖家账户)
453
- const sellCall = buildSellCallWithAmountInternal(sellerWallet, sellAmountWei, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
454
- calls.push(sellCall);
455
- // 2. 利润刮取(从第一个买家余额扣除)
456
- if (profitAmount > 0n) {
457
- calls.push({
458
- target: buyerWallets[0].address,
459
- allowFailure: false,
460
- value: 0n,
461
- callData: delegateInterface.encodeFunctionData('transferAmount', [profitRecipient, profitAmount]),
462
- });
463
- }
464
- // 3. 所有买家买入(使用自己预存的 OKB)
465
- for (let i = 0; i < buyerWallets.length; i++) {
466
- const buyCall = buildBuyCallInternal(buyerWallets[i], buyAmountsPerBuyer[i], tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
467
- calls.push(buyCall);
468
- }
469
- }
470
- // ========================================
471
- // 构建交易
472
- // ========================================
473
- const signedTransaction = buildEIP7702TransactionSync(sellerWallet, authorizations, calls, 0n, sellerNonce, feeData, config);
474
- return {
475
- signedTransaction,
476
- hopWallets: hopWalletInfos,
477
- metadata: {
478
- sellerAddress: sellerWallet.address,
479
- buyerAddresses: buyerWallets.map((w) => w.address),
480
- sellAmount: ethers.formatUnits(sellAmountWei, tokenDecimals),
481
- estimatedOkbOut: ethers.formatEther(estimatedOkbOut),
482
- estimatedBuyAmount: ethers.formatEther(totalBuyAmountAfterProfit),
483
- profitAmount: ethers.formatEther(profitAmount),
484
- profitRecipient,
485
- userType,
486
- useFundUtilization,
487
- },
488
- };
489
- }
490
- /**
491
- * 多对多换手 - 多个卖家 + 多个买家
492
- *
493
- * 核心逻辑:[利润刮取] + [卖出Ops...] + [买入Ops...]
494
- *
495
- * 特点:
496
- * - 多个卖家同时卖出
497
- * - 多个买家同时买入
498
- * - 所有操作在一笔交易中原子执行
499
- * - 利润根据 userType 动态计算
500
- *
501
- * @example
502
- * const result = await bundleMultiSwap({
503
- * mainPrivateKey: '0x...', // Payer 支付 Gas
504
- * sellerPrivateKeys: ['0x...', '0x...'],
505
- * buyerPrivateKeys: ['0x...', '0x...'],
506
- * totalBuyAmount: '0.1', // 总买入 0.1 OKB
507
- * tokenAddress: '0x...',
508
- * tradeType: 'V3',
509
- * userType: 'v0',
510
- * });
511
- */
512
- export async function bundleMultiSwap(params) {
513
- const { mainPrivateKey, sellerPrivateKeys, buyerPrivateKeys, totalBuyAmount, tokenAddress, tokenDecimals = 18, sellPercent = 100, tradeType = 'V3', routerAddress, fee = V3_FEE_TIERS.MEDIUM, userType = 'v0', config, } = params;
514
- // ✅ 验证私钥格式的辅助函数
515
- const isValidPrivateKey = (pk) => {
516
- const trimmed = (pk || '').trim();
517
- return trimmed.length >= 64 && (trimmed.startsWith('0x') || /^[0-9a-fA-F]{64}$/.test(trimmed));
518
- };
519
- if (!mainPrivateKey || !isValidPrivateKey(mainPrivateKey)) {
520
- throw new Error('必须提供有效的 mainPrivateKey(Payer 钱包私钥)');
521
- }
522
- // ✅ 验证卖家私钥
523
- const validSellerPrivateKeys = sellerPrivateKeys.filter((pk) => isValidPrivateKey(pk));
524
- if (validSellerPrivateKeys.length === 0) {
525
- throw new Error('没有有效的卖家私钥');
526
- }
527
- // ✅ 验证买家私钥
528
- const validBuyerPrivateKeys = buyerPrivateKeys.filter((pk) => isValidPrivateKey(pk));
529
- if (validBuyerPrivateKeys.length === 0) {
530
- throw new Error('没有有效的买家私钥');
531
- }
532
- const provider = getCachedProvider(config?.rpcUrl);
533
- // ✅ 空字符串也使用默认值
534
- const delegateAddress = (config?.delegateAddress && config.delegateAddress.trim()) || UNIFIED_DELEGATE_ADDRESS;
535
- const delegateInterface = new ethers.Interface(UNIFIED_DELEGATE_ABI);
536
- const portalInterface = new ethers.Interface(FLAP_PORTAL_ABI);
537
- const actualRouter = routerAddress ?? getDefaultRouter(tradeType);
538
- // ✅ 创建 Payer 钱包(支付 Gas 费)
539
- const mainWallet = createWallet(mainPrivateKey, provider);
540
- // 创建钱包
541
- const sellerWallets = validSellerPrivateKeys.map((pk) => createWallet(pk, provider));
542
- const buyerWallets = validBuyerPrivateKeys.map((pk) => createWallet(pk, provider));
543
- // 合并所有钱包(去重,包括 mainWallet)
544
- const allWalletsMap = new Map();
545
- allWalletsMap.set(mainWallet.address.toLowerCase(), mainWallet);
546
- sellerWallets.forEach((w) => allWalletsMap.set(w.address.toLowerCase(), w));
547
- buyerWallets.forEach((w) => allWalletsMap.set(w.address.toLowerCase(), w));
548
- const allWallets = Array.from(allWalletsMap.values());
549
- // 找出 mainWallet 在 allWallets 中的索引
550
- const mainWalletIndex = allWallets.findIndex((w) => w.address.toLowerCase() === mainWallet.address.toLowerCase());
551
- // 计算买入金额
552
- const totalBuyAmountWei = ethers.parseEther(truncateDecimals(totalBuyAmount));
553
- const buyAmountPerWallet = totalBuyAmountWei / BigInt(buyerWallets.length);
554
- // ✅ 计算利润(根据 userType 和交易数量)
555
- const totalTxCount = sellerWallets.length + buyerWallets.length;
556
- const profitAmount = calculateProfitAmountByTxCount(totalBuyAmountWei, totalTxCount, userType);
557
- const profitRecipient = getProfitRecipient(config);
558
- // ========================================
559
- // 并行获取数据
560
- // ========================================
561
- const allAddresses = allWallets.map((w) => w.address);
562
- // 获取卖出钱包的代币余额
563
- const tokenContract = new ethers.Contract(tokenAddress, ERC20_ABI, provider);
564
- const [nonces, feeData, sellerBalances] = await Promise.all([
565
- batchGetNonces(allAddresses, provider),
566
- provider.getFeeData(),
567
- Promise.all(sellerWallets.map((w) => tokenContract.balanceOf(w.address))),
568
- ]);
569
- // 计算每个卖家的卖出金额(按百分比)
570
- const percentBigInt = BigInt(Math.min(100, Math.max(1, sellPercent)));
571
- const sellAmountsWei = sellerBalances.map((balance) => (BigInt(balance.toString()) * percentBigInt) / 100n);
572
- const totalSellAmount = sellAmountsWei.reduce((sum, amt) => sum + amt, 0n);
573
- // ========================================
574
- // 同步签署授权
575
- // ========================================
576
- const authorizations = signAuthorizationsWithNonces(allWallets, nonces, delegateAddress, mainWalletIndex);
577
- // ========================================
578
- // 构建调用
579
- // ========================================
580
- const calls = [];
581
- // 卖出调用
582
- for (let i = 0; i < sellerWallets.length; i++) {
583
- if (sellAmountsWei[i] <= 0n)
584
- continue;
585
- const sellCall = buildSellCallWithAmountInternal(sellerWallets[i], sellAmountsWei[i], tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
586
- calls.push(sellCall);
587
- }
588
- // ✅ 修复:利润刮取放在卖出之后、买入之前(从第一个卖家余额转账)
589
- if (profitAmount > 0n && sellerWallets.length > 0) {
590
- calls.push({
591
- target: sellerWallets[0].address, // 从第一个卖家扣利润
592
- allowFailure: false,
593
- value: 0n,
594
- callData: delegateInterface.encodeFunctionData('transferAmount', [profitRecipient, profitAmount]),
595
- });
596
- }
597
- // 买入调用
598
- for (let i = 0; i < buyerWallets.length; i++) {
599
- const buyCall = buildBuyCallInternal(buyerWallets[i], buyAmountPerWallet, tokenAddress, tradeType, actualRouter, fee, delegateInterface, portalInterface);
600
- calls.push(buyCall);
601
- }
602
- // ========================================
603
- // 构建交易
604
- // ========================================
605
- // ✅ 修复:利润使用 transferAmount 从卖家余额转账,不需要通过 msg.value 传递
606
- const totalValue = 0n;
607
- const signedTransaction = buildEIP7702TransactionSync(mainWallet, authorizations, calls, totalValue, nonces[mainWalletIndex], feeData, config);
608
- return {
609
- signedTransaction,
610
- metadata: {
611
- payerAddress: mainWallet.address,
612
- sellerAddresses: sellerWallets.map((w) => w.address),
613
- buyerAddresses: buyerWallets.map((w) => w.address),
614
- sellerCount: sellerWallets.filter((_, i) => sellAmountsWei[i] > 0n).length,
615
- buyerCount: buyerWallets.length,
616
- totalBuyAmount: ethers.formatEther(totalBuyAmountWei),
617
- totalSellAmount: ethers.formatUnits(totalSellAmount, tokenDecimals),
618
- profitAmount: ethers.formatEther(profitAmount),
619
- profitRecipient,
620
- userType,
621
- },
622
- };
623
- }
624
- // ========================================
625
- // 内部工具函数
626
- // ========================================
627
- function buildBuyCallInternal(wallet, amount, tokenAddress, tradeType, routerAddress, fee, delegateInterface, portalInterface) {
628
- switch (tradeType) {
629
- case 'FLAP': {
630
- // ✅ FLAP: 使用 swapExactInput 买入(与 AA 模式保持一致)
631
- // 原 buy(address token) ABI 与 Portal 不匹配,改用 swapExactInput
632
- const portalCallData = portalInterface.encodeFunctionData('swapExactInput', [
633
- {
634
- inputToken: ethers.ZeroAddress, // 0x0 = OKB (原生代币)
635
- outputToken: tokenAddress,
636
- inputAmount: amount,
637
- minOutputAmount: 0n,
638
- permitData: '0x',
639
- },
640
- ]);
641
- const batchCalls = [{ target: FLAP_PORTAL_ADDRESS, value: amount, data: portalCallData }];
642
- return {
643
- target: wallet.address,
644
- allowFailure: false,
645
- value: 0n,
646
- callData: delegateInterface.encodeFunctionData('executeBatch', [batchCalls]),
647
- };
648
- }
649
- case 'V2': {
650
- const path = [WOKB_ADDRESS, tokenAddress];
651
- // ✅ 修复:使用指定的买入金额,而不是 0(使用全部余额会导致严重 bug)
652
- return {
653
- target: wallet.address,
654
- allowFailure: false,
655
- value: 0n,
656
- callData: delegateInterface.encodeFunctionData('executeBuyV2', [routerAddress, path, amount]),
657
- };
658
- }
659
- case 'V3': {
660
- // ✅ 修复:使用指定的买入金额,而不是 0(使用全部余额会导致严重 bug)
661
- return {
662
- target: wallet.address,
663
- allowFailure: false,
664
- value: 0n,
665
- callData: delegateInterface.encodeFunctionData('executeBuy', [
666
- routerAddress,
667
- WOKB_ADDRESS,
668
- tokenAddress,
669
- fee,
670
- amount,
671
- ]),
672
- };
673
- }
674
- }
675
- }
676
- function buildSellCallWithAmountInternal(wallet, amount, tokenAddress, tradeType, routerAddress, fee, delegateInterface, portalInterface) {
677
- switch (tradeType) {
678
- case 'FLAP': {
679
- // ✅ 使用 swapExactInput 卖出(与 AA 模式保持一致)
680
- const portalCallData = portalInterface.encodeFunctionData('swapExactInput', [
681
- {
682
- inputToken: tokenAddress,
683
- outputToken: ethers.ZeroAddress, // 0x0 = OKB
684
- inputAmount: amount,
685
- minOutputAmount: 0n,
686
- permitData: '0x',
687
- },
688
- ]);
689
- const batchCalls = [{ target: FLAP_PORTAL_ADDRESS, value: 0n, data: portalCallData }];
690
- return {
691
- target: wallet.address,
692
- allowFailure: false,
693
- value: 0n,
694
- callData: delegateInterface.encodeFunctionData('executeBatch', [batchCalls]),
695
- };
696
- }
697
- case 'V2': {
698
- const path = [tokenAddress, WOKB_ADDRESS];
699
- return {
700
- target: wallet.address,
701
- allowFailure: false,
702
- value: 0n,
703
- // ✅ 修复:传入实际数量,避免卖出全部
704
- callData: delegateInterface.encodeFunctionData('executeSellV2', [routerAddress, path, amount]),
705
- };
706
- }
707
- case 'V3': {
708
- return {
709
- target: wallet.address,
710
- allowFailure: false,
711
- value: 0n,
712
- // ✅ 修复:传入实际数量,避免卖出全部
713
- callData: delegateInterface.encodeFunctionData('executeSell', [
714
- routerAddress,
715
- tokenAddress,
716
- WOKB_ADDRESS,
717
- fee,
718
- amount,
719
- ]),
720
- };
721
- }
722
- }
723
- }
12
+ export { bundleSwap } from './bundle-swap-single.js';
13
+ export { bundleBatchSwap } from './bundle-swap-batch.js';
14
+ export { bundleMultiSwap } from './bundle-swap-multi.js';