four-flap-meme-sdk 2.2.19 → 3.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 (519) hide show
  1. package/dist/{shared/abis → abis}/common.d.ts +1 -1
  2. package/dist/{shared/abis → abis}/common.js +75 -91
  3. package/dist/abis/contracts/TaxToken.json +969 -0
  4. package/dist/abis/contracts/TokenManager2.json +136 -0
  5. package/dist/{shared/abis → abis/contracts}/index.d.ts +0 -1
  6. package/dist/{shared/abis → abis/contracts}/index.js +0 -2
  7. package/dist/abis/flap/index.d.ts +5 -0
  8. package/dist/abis/flap/index.js +5 -0
  9. package/dist/abis/flap/portal-eip7702.d.ts +4 -0
  10. package/dist/abis/flap/portal-eip7702.js +39 -0
  11. package/dist/abis/flap/portal-events.d.ts +6 -0
  12. package/dist/abis/flap/portal-events.js +17 -0
  13. package/dist/abis/flap/portal-merkle.d.ts +4 -0
  14. package/dist/abis/flap/portal-merkle.js +25 -0
  15. package/dist/abis/flap/portal.d.ts +6 -0
  16. package/dist/abis/flap/portal.js +37 -0
  17. package/dist/abis/flap/vault.d.ts +171 -0
  18. package/dist/abis/flap/vault.js +91 -0
  19. package/dist/abis/index.d.ts +6 -0
  20. package/dist/abis/index.js +9 -0
  21. package/dist/bundle/config-helpers.d.ts +37 -0
  22. package/dist/bundle/config-helpers.js +58 -0
  23. package/dist/bundle/errors.d.ts +50 -0
  24. package/dist/bundle/errors.js +38 -0
  25. package/dist/bundle/four-meme/approve-tokenmanager.d.ts +7 -0
  26. package/dist/bundle/four-meme/approve-tokenmanager.js +99 -0
  27. package/dist/bundle/four-meme/core-helpers.d.ts +8 -0
  28. package/dist/bundle/four-meme/core-helpers.js +41 -0
  29. package/dist/{contracts/tm-bundle-merkle → bundle/four-meme}/core.d.ts +1 -1
  30. package/dist/{contracts/tm-bundle-merkle → bundle/four-meme}/core.js +74 -150
  31. package/dist/{contracts/tm-bundle-merkle → bundle/four-meme}/pancake-proxy.d.ts +1 -1
  32. package/dist/{contracts/tm-bundle-merkle → bundle/four-meme}/pancake-proxy.js +85 -92
  33. package/dist/{contracts/tm-bundle-merkle → bundle/four-meme}/private.d.ts +1 -1
  34. package/dist/{contracts/tm-bundle-merkle → bundle/four-meme}/private.js +48 -59
  35. package/dist/bundle/four-meme/sign-context-helpers.d.ts +2 -0
  36. package/dist/bundle/four-meme/sign-context-helpers.js +2 -0
  37. package/dist/bundle/four-meme/swap-buy-first.d.ts +8 -0
  38. package/dist/{contracts/tm-bundle-merkle → bundle/four-meme}/swap-buy-first.js +56 -108
  39. package/dist/bundle/four-meme/swap-hop-helpers.d.ts +6 -0
  40. package/dist/bundle/four-meme/swap-hop-helpers.js +63 -0
  41. package/dist/{contracts/tm-bundle-merkle → bundle/four-meme}/swap-internal.js +4 -4
  42. package/dist/bundle/four-meme/swap-sign-helpers.d.ts +28 -0
  43. package/dist/bundle/four-meme/swap-sign-helpers.js +105 -0
  44. package/dist/bundle/four-meme/swap.d.ts +17 -0
  45. package/dist/{contracts/tm-bundle-merkle → bundle/four-meme}/swap.js +84 -345
  46. package/dist/{contracts/tm-bundle-merkle/swap-buy-first.d.ts → bundle/four-meme/types/buy-first.d.ts} +11 -18
  47. package/dist/bundle/four-meme/types/core-flow.d.ts +63 -0
  48. package/dist/bundle/four-meme/types/core-flow.js +1 -0
  49. package/dist/{contracts/tm-bundle-merkle/types.d.ts → bundle/four-meme/types/index.d.ts} +130 -6
  50. package/dist/bundle/four-meme/types/index.js +1 -0
  51. package/dist/bundle/four-meme/types/swap-internal.d.ts +19 -0
  52. package/dist/bundle/four-meme/types/swap-internal.js +1 -0
  53. package/dist/bundle/four-meme/types.d.ts +1 -0
  54. package/dist/bundle/four-meme/utils-disperse.d.ts +7 -0
  55. package/dist/bundle/four-meme/utils-disperse.js +396 -0
  56. package/dist/bundle/four-meme/utils-pairwise.d.ts +8 -0
  57. package/dist/bundle/four-meme/utils-pairwise.js +328 -0
  58. package/dist/bundle/four-meme/utils-sweep.d.ts +8 -0
  59. package/dist/bundle/four-meme/utils-sweep.js +744 -0
  60. package/dist/bundle/index.d.ts +8 -0
  61. package/dist/bundle/index.js +8 -0
  62. package/dist/bundle/internal.d.ts +16 -0
  63. package/dist/bundle/internal.js +160 -0
  64. package/dist/bundle/sign-context-helpers.d.ts +26 -0
  65. package/dist/bundle/sign-context-helpers.js +63 -0
  66. package/dist/{contracts/tm-bundle-merkle → bundle}/submit.d.ts +6 -27
  67. package/dist/{contracts/tm-bundle-merkle → bundle}/submit.js +116 -313
  68. package/dist/bundle/types/index.d.ts +8 -0
  69. package/dist/bundle/types/index.js +1 -0
  70. package/dist/bundle/types.d.ts +1 -0
  71. package/dist/bundle/types.js +1 -0
  72. package/dist/chains/bsc/constants.js +1 -1
  73. package/dist/chains/bsc/four/approve-tokenmanager.d.ts +1 -26
  74. package/dist/chains/bsc/four/approve-tokenmanager.js +1 -113
  75. package/dist/chains/bsc/four/config.d.ts +5 -67
  76. package/dist/chains/bsc/four/config.js +2 -114
  77. package/dist/chains/bsc/four/core.d.ts +1 -4
  78. package/dist/chains/bsc/four/core.js +1 -592
  79. package/dist/chains/bsc/four/index.d.ts +6 -6
  80. package/dist/chains/bsc/four/index.js +6 -6
  81. package/dist/chains/bsc/four/internal.d.ts +2 -46
  82. package/dist/chains/bsc/four/internal.js +2 -239
  83. package/dist/chains/bsc/four/pancake-proxy.d.ts +1 -28
  84. package/dist/chains/bsc/four/pancake-proxy.js +1 -687
  85. package/dist/chains/bsc/four/private.d.ts +1 -27
  86. package/dist/chains/bsc/four/private.js +1 -477
  87. package/dist/chains/bsc/four/submit.d.ts +2 -315
  88. package/dist/chains/bsc/four/submit.js +2 -752
  89. package/dist/chains/bsc/four/swap-buy-first.d.ts +2 -55
  90. package/dist/chains/bsc/four/swap-buy-first.js +2 -507
  91. package/dist/chains/bsc/four/swap-internal.d.ts +1 -3
  92. package/dist/chains/bsc/four/swap-internal.js +1 -18
  93. package/dist/chains/bsc/four/swap.d.ts +2 -144
  94. package/dist/chains/bsc/four/swap.js +2 -766
  95. package/dist/chains/bsc/four/types.d.ts +1 -476
  96. package/dist/chains/bsc/four/utils-disperse.d.ts +1 -0
  97. package/dist/chains/bsc/four/utils-disperse.js +1 -0
  98. package/dist/chains/bsc/four/utils-pairwise.d.ts +1 -0
  99. package/dist/chains/bsc/four/utils-pairwise.js +1 -0
  100. package/dist/chains/bsc/four/utils-sweep.d.ts +1 -0
  101. package/dist/chains/bsc/four/utils-sweep.js +1 -0
  102. package/dist/chains/bsc/four/utils.d.ts +5 -18
  103. package/dist/chains/bsc/four/utils.js +5 -1552
  104. package/dist/chains/bsc/iro.d.ts +5 -0
  105. package/dist/chains/bsc/iro.js +4 -0
  106. package/dist/chains/bsc/pancake/bundle-buy-first-helpers.d.ts +155 -0
  107. package/dist/chains/bsc/pancake/bundle-buy-first-helpers.js +80 -0
  108. package/dist/chains/bsc/pancake/bundle-buy-first.d.ts +1 -91
  109. package/dist/chains/bsc/pancake/bundle-buy-first.js +99 -214
  110. package/dist/chains/bsc/pancake/bundle-swap-helpers.d.ts +241 -0
  111. package/dist/chains/bsc/pancake/bundle-swap-helpers.js +565 -0
  112. package/dist/chains/bsc/pancake/bundle-swap.d.ts +1 -79
  113. package/dist/chains/bsc/pancake/bundle-swap.js +114 -726
  114. package/dist/chains/bsc/pancake/index.d.ts +4 -2
  115. package/dist/chains/bsc/pancake/index.js +1 -3
  116. package/dist/chains/bsc/platforms/iro/constants.js +1 -1
  117. package/dist/chains/bsc/platforms/iro/factory.d.ts +2 -2
  118. package/dist/chains/bsc/platforms/iro/factory.js +3 -1
  119. package/dist/chains/bsc/platforms/iro/index.d.ts +5 -5
  120. package/dist/chains/bsc/platforms/iro/index.js +3 -3
  121. package/dist/chains/bsc/platforms/iro/pool.js +31 -10
  122. package/dist/chains/bsc/platforms/iro/token.js +5 -2
  123. package/dist/chains/eni/batch-router/bundle-approve.js +4 -3
  124. package/dist/chains/eni/batch-router/transfer.js +57 -27
  125. package/dist/chains/eni/batch-router/utils.js +32 -6
  126. package/dist/chains/eni/bundler/sign.js +5 -6
  127. package/dist/chains/eni/bundler/submit.js +1 -4
  128. package/dist/chains/eni/constants.js +2 -2
  129. package/dist/chains/eni/flat-aliases.d.ts +10 -0
  130. package/dist/chains/eni/flat-aliases.js +8 -0
  131. package/dist/chains/eni/index.d.ts +2 -1
  132. package/dist/chains/eni/index.js +1 -0
  133. package/dist/chains/eni/platforms/daoaas/create.js +3 -3
  134. package/dist/chains/eni/platforms/daoaas/index.d.ts +3 -3
  135. package/dist/chains/eni/platforms/daoaas/index.js +3 -3
  136. package/dist/chains/eni/platforms/daoaas/meta.js +9 -6
  137. package/dist/chains/eni/platforms/daoaas/portal-direct.js +29 -45
  138. package/dist/chains/eni/platforms/daoaas/portal.js +10 -6
  139. package/dist/chains/eni/platforms/dswap/liquidity.js +59 -27
  140. package/dist/chains/eni/platforms/fair-launch/constants.js +1 -1
  141. package/dist/chains/eni/platforms/fair-launch/index.d.ts +2 -2
  142. package/dist/chains/eni/platforms/fair-launch/index.js +1 -1
  143. package/dist/chains/eni/platforms/fair-launch/launcher.js +88 -47
  144. package/dist/chains/eni/platforms/fair-launch/pool.js +5 -2
  145. package/dist/chains/eni/platforms/fair-launch/presets.js +2 -2
  146. package/dist/chains/eni/platforms/iro/constants.d.ts +1 -1
  147. package/dist/chains/eni/platforms/iro/constants.js +2 -2
  148. package/dist/chains/eni/platforms/iro/factory.d.ts +2 -2
  149. package/dist/chains/eni/platforms/iro/factory.js +3 -1
  150. package/dist/chains/eni/platforms/iro/index.d.ts +6 -6
  151. package/dist/chains/eni/platforms/iro/index.js +4 -4
  152. package/dist/chains/eni/platforms/iro/pool.js +90 -26
  153. package/dist/chains/eni/platforms/iro/token.js +108 -32
  154. package/dist/chains/eni/platforms/iro/whitelist.js +6 -18
  155. package/dist/chains/eni/submit.d.ts +43 -0
  156. package/dist/chains/eni/submit.js +287 -0
  157. package/dist/chains/index.d.ts +13 -0
  158. package/dist/chains/index.js +13 -0
  159. package/dist/chains/monad/constants.js +1 -1
  160. package/dist/chains/xlayer/constants.d.ts +5 -0
  161. package/dist/chains/xlayer/constants.js +1 -1
  162. package/dist/chains/xlayer/eip7702/bundle-approve.d.ts +2 -26
  163. package/dist/chains/xlayer/eip7702/bundle-approve.js +11 -21
  164. package/dist/chains/xlayer/eip7702/bundle-buy.d.ts +2 -6
  165. package/dist/chains/xlayer/eip7702/bundle-buy.js +13 -51
  166. package/dist/chains/xlayer/eip7702/bundle-create.js +104 -74
  167. package/dist/chains/xlayer/eip7702/bundle-sell.d.ts +2 -6
  168. package/dist/chains/xlayer/eip7702/bundle-sell.js +30 -112
  169. package/dist/chains/xlayer/eip7702/bundle-swap.d.ts +3 -65
  170. package/dist/chains/xlayer/eip7702/bundle-swap.js +52 -246
  171. package/dist/chains/xlayer/eip7702/constants.d.ts +11 -26
  172. package/dist/chains/xlayer/eip7702/constants.js +15 -68
  173. package/dist/chains/xlayer/eip7702/flat-aliases.d.ts +13 -0
  174. package/dist/chains/xlayer/eip7702/flat-aliases.js +10 -0
  175. package/dist/chains/xlayer/eip7702/index.d.ts +28 -46
  176. package/dist/chains/xlayer/eip7702/index.js +28 -81
  177. package/dist/chains/xlayer/eip7702/multi-hop-transfer-helpers.d.ts +79 -0
  178. package/dist/chains/xlayer/eip7702/multi-hop-transfer-helpers.js +1 -0
  179. package/dist/chains/xlayer/eip7702/multi-hop-transfer.d.ts +2 -203
  180. package/dist/chains/xlayer/eip7702/multi-hop-transfer.js +64 -308
  181. package/dist/chains/xlayer/eip7702/transfer-context-helpers.d.ts +26 -0
  182. package/dist/chains/xlayer/eip7702/transfer-context-helpers.js +58 -0
  183. package/dist/chains/xlayer/eip7702/types.d.ts +88 -0
  184. package/dist/chains/xlayer/eip7702/utils.d.ts +0 -3
  185. package/dist/chains/xlayer/eip7702/utils.js +23 -28
  186. package/dist/chains/xlayer/eip7702/volume-helpers.d.ts +148 -0
  187. package/dist/chains/xlayer/eip7702/volume-helpers.js +48 -0
  188. package/dist/chains/xlayer/eip7702/volume.d.ts +6 -184
  189. package/dist/chains/xlayer/eip7702/volume.js +89 -164
  190. package/dist/chains/xlayer/eoa/constants.d.ts +1 -1
  191. package/dist/chains/xlayer/eoa/constants.js +2 -16
  192. package/dist/chains/xlayer/eoa/dex-helpers.d.ts +1 -1
  193. package/dist/chains/xlayer/eoa/dex-helpers.js +7 -37
  194. package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.d.ts +126 -0
  195. package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.js +228 -0
  196. package/dist/chains/xlayer/eoa/eoa-bundle-swap.d.ts +1 -95
  197. package/dist/chains/xlayer/eoa/eoa-bundle-swap.js +66 -299
  198. package/dist/chains/xlayer/eoa/eoa-wash-volume.d.ts +1 -1
  199. package/dist/chains/xlayer/eoa/eoa-wash-volume.js +18 -23
  200. package/dist/chains/xlayer/eoa/index.d.ts +10 -6
  201. package/dist/chains/xlayer/eoa/index.js +8 -23
  202. package/dist/chains/xlayer/eoa/portal-ops.js +7 -2
  203. package/dist/chains/xlayer/eoa/router-manager.js +5 -4
  204. package/dist/chains/xlayer/eoa/types.d.ts +2 -2
  205. package/dist/chains/xlayer/eoa/types.js +1 -3
  206. package/dist/chains/xlayer/index.d.ts +3 -2
  207. package/dist/chains/xlayer/index.js +4 -7
  208. package/dist/core/amount/split-by-weight.d.ts +5 -0
  209. package/dist/core/amount/split-by-weight.js +35 -0
  210. package/dist/{shared → core}/clients/blockrazor.d.ts +4 -8
  211. package/dist/{shared → core}/clients/blockrazor.js +43 -35
  212. package/dist/{shared → core}/clients/club48.d.ts +2 -2
  213. package/dist/{shared → core}/clients/club48.js +36 -30
  214. package/dist/{shared → core}/clients/emitservice.js +2 -0
  215. package/dist/{shared → core}/clients/four.d.ts +21 -6
  216. package/dist/{shared → core}/clients/four.js +29 -24
  217. package/dist/core/clients/index.d.ts +8 -0
  218. package/dist/core/clients/index.js +8 -0
  219. package/dist/{shared → core}/clients/merkle.d.ts +4 -3
  220. package/dist/{shared → core}/clients/merkle.js +30 -47
  221. package/dist/{shared → core}/constants/addresses.d.ts +27 -1
  222. package/dist/{shared → core}/constants/addresses.js +39 -2
  223. package/dist/{shared → core}/constants/chains.d.ts +1 -1
  224. package/dist/{shared → core}/constants/chains.js +1 -1
  225. package/dist/{shared → core}/constants/gas.d.ts +1 -1
  226. package/dist/{shared → core}/constants/gas.js +2 -6
  227. package/dist/{shared → core}/constants/index.d.ts +5 -2
  228. package/dist/{shared → core}/constants/index.js +3 -2
  229. package/dist/core/constants/quote.d.ts +30 -0
  230. package/dist/core/constants/quote.js +37 -0
  231. package/dist/core/dex/v3-path.d.ts +6 -0
  232. package/dist/core/dex/v3-path.js +35 -0
  233. package/dist/core/erc20/decimals.d.ts +7 -0
  234. package/dist/core/erc20/decimals.js +24 -0
  235. package/dist/{utils → core}/erc20.d.ts +7 -89
  236. package/dist/{utils → core}/erc20.js +99 -130
  237. package/dist/core/foundation.d.ts +15 -0
  238. package/dist/core/foundation.js +14 -0
  239. package/dist/core/gas/bundle-gas.d.ts +49 -0
  240. package/dist/core/gas/bundle-gas.js +93 -0
  241. package/dist/core/gas/profit-hop.d.ts +20 -0
  242. package/dist/core/gas/profit-hop.js +72 -0
  243. package/dist/core/index.d.ts +5 -0
  244. package/dist/core/index.js +5 -0
  245. package/dist/core/legacy-types/errors.d.ts +27 -0
  246. package/dist/core/legacy-types/errors.js +34 -0
  247. package/dist/core/nonce/nonce-manager.d.ts +19 -0
  248. package/dist/core/nonce/nonce-manager.js +217 -0
  249. package/dist/core/normalize-unknown.d.ts +9 -0
  250. package/dist/core/normalize-unknown.js +29 -0
  251. package/dist/core/sdk-logger.d.ts +13 -0
  252. package/dist/core/sdk-logger.js +12 -0
  253. package/dist/core/shared-abis/common.d.ts +4 -0
  254. package/dist/core/shared-abis/common.js +4 -0
  255. package/dist/core/shared-abis/index.d.ts +5 -0
  256. package/dist/core/shared-abis/index.js +5 -0
  257. package/dist/core/tx/build-request.d.ts +17 -0
  258. package/dist/core/tx/build-request.js +25 -0
  259. package/dist/core/tx/sign-batch.d.ts +5 -0
  260. package/dist/core/tx/sign-batch.js +26 -0
  261. package/dist/core/tx/wallet-sign-patch.d.ts +1 -0
  262. package/dist/core/tx/wallet-sign-patch.js +18 -0
  263. package/dist/core/types/airdrop-sweep.d.ts +79 -0
  264. package/dist/core/types/airdrop-sweep.js +1 -0
  265. package/dist/core/types/erc20.d.ts +65 -0
  266. package/dist/core/types/erc20.js +1 -0
  267. package/dist/core/types/holders-maker.d.ts +64 -0
  268. package/dist/core/types/holders-maker.js +1 -0
  269. package/dist/core/types/index.d.ts +7 -0
  270. package/dist/core/types/index.js +1 -0
  271. package/dist/{utils → core/types}/lp-inspect.d.ts +4 -52
  272. package/dist/core/types/lp-inspect.js +1 -0
  273. package/dist/core/types/multicall.d.ts +5 -0
  274. package/dist/core/types/multicall.js +1 -0
  275. package/dist/core/types/private-sale.d.ts +35 -0
  276. package/dist/core/types/private-sale.js +1 -0
  277. package/dist/core/types/quote-helpers.d.ts +17 -0
  278. package/dist/core/types/quote-helpers.js +1 -0
  279. package/dist/core/types-erc20.d.ts +1 -0
  280. package/dist/core/types-erc20.js +1 -0
  281. package/dist/core/wallet/generate.d.ts +5 -0
  282. package/dist/core/wallet/generate.js +8 -0
  283. package/dist/domains/dex/direct-router-helpers.d.ts +269 -0
  284. package/dist/domains/dex/direct-router-helpers.js +536 -0
  285. package/dist/domains/dex/direct-router.d.ts +28 -0
  286. package/dist/{dex → domains/dex}/direct-router.js +246 -674
  287. package/dist/domains/dex/types.d.ts +81 -0
  288. package/dist/domains/dex/types.js +1 -0
  289. package/dist/{shared → domains}/flap/abi.js +1 -1
  290. package/dist/{shared → domains}/flap/constants.d.ts +1 -2
  291. package/dist/{shared → domains}/flap/constants.js +3 -4
  292. package/dist/{shared → domains}/flap/curve.js +3 -0
  293. package/dist/{shared → domains}/flap/errors.d.ts +1 -4
  294. package/dist/{shared → domains}/flap/errors.js +20 -1
  295. package/dist/domains/flap/index.d.ts +7 -0
  296. package/dist/domains/flap/index.js +5 -0
  297. package/dist/{shared → domains}/flap/meta.d.ts +22 -18
  298. package/dist/{shared → domains}/flap/meta.js +32 -24
  299. package/dist/{shared/flap/index.d.ts → domains/flap/module.d.ts} +4 -5
  300. package/dist/{shared/flap/index.js → domains/flap/module.js} +4 -5
  301. package/dist/{shared → domains}/flap/permit.js +10 -3
  302. package/dist/{shared → domains}/flap/pinata.d.ts +22 -6
  303. package/dist/{shared → domains}/flap/pinata.js +21 -26
  304. package/dist/domains/flap/portal-bundle-merkle/config.d.ts +10 -0
  305. package/dist/domains/flap/portal-bundle-merkle/config.js +13 -0
  306. package/dist/domains/flap/portal-bundle-merkle/core-helpers.d.ts +32 -0
  307. package/dist/domains/flap/portal-bundle-merkle/core-helpers.js +83 -0
  308. package/dist/{shared → domains}/flap/portal-bundle-merkle/core.d.ts +0 -4
  309. package/dist/{shared → domains}/flap/portal-bundle-merkle/core.js +168 -175
  310. package/dist/{shared → domains}/flap/portal-bundle-merkle/create-to-dex.d.ts +17 -4
  311. package/dist/{shared → domains}/flap/portal-bundle-merkle/create-to-dex.js +97 -118
  312. package/dist/{shared → domains}/flap/portal-bundle-merkle/curve-to-dex.js +105 -123
  313. package/dist/domains/flap/portal-bundle-merkle/index.d.ts +18 -0
  314. package/dist/{shared → domains}/flap/portal-bundle-merkle/index.js +4 -7
  315. package/dist/{shared → domains}/flap/portal-bundle-merkle/pancake-proxy.js +73 -70
  316. package/dist/{shared → domains}/flap/portal-bundle-merkle/private.js +63 -116
  317. package/dist/domains/flap/portal-bundle-merkle/swap-batch.d.ts +8 -0
  318. package/dist/domains/flap/portal-bundle-merkle/swap-batch.js +227 -0
  319. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-helpers.d.ts +125 -0
  320. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-helpers.js +113 -0
  321. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first.d.ts +2 -0
  322. package/dist/{shared → domains}/flap/portal-bundle-merkle/swap-buy-first.js +69 -288
  323. package/dist/domains/flap/portal-bundle-merkle/swap-cross.d.ts +9 -0
  324. package/dist/domains/flap/portal-bundle-merkle/swap-cross.js +139 -0
  325. package/dist/domains/flap/portal-bundle-merkle/swap-helpers.d.ts +149 -0
  326. package/dist/domains/flap/portal-bundle-merkle/swap-helpers.js +259 -0
  327. package/dist/domains/flap/portal-bundle-merkle/swap-planning.d.ts +70 -0
  328. package/dist/domains/flap/portal-bundle-merkle/swap-planning.js +182 -0
  329. package/dist/domains/flap/portal-bundle-merkle/swap-quick-batch.d.ts +16 -0
  330. package/dist/domains/flap/portal-bundle-merkle/swap-quick-batch.js +327 -0
  331. package/dist/domains/flap/portal-bundle-merkle/swap-single.d.ts +2 -0
  332. package/dist/domains/flap/portal-bundle-merkle/swap-single.js +184 -0
  333. package/dist/domains/flap/portal-bundle-merkle/swap-types.d.ts +101 -0
  334. package/dist/domains/flap/portal-bundle-merkle/swap-types.js +1 -0
  335. package/dist/domains/flap/portal-bundle-merkle/swap.d.ts +8 -0
  336. package/dist/domains/flap/portal-bundle-merkle/swap.js +7 -0
  337. package/dist/{shared → domains}/flap/portal-bundle-merkle/types.d.ts +88 -12
  338. package/dist/domains/flap/portal-bundle-merkle/types.js +1 -0
  339. package/dist/domains/flap/portal-bundle-merkle/utils.d.ts +10 -0
  340. package/dist/{shared → domains}/flap/portal-bundle-merkle/utils.js +145 -265
  341. package/dist/{shared → domains}/flap/portal-bundle.d.ts +2 -2
  342. package/dist/{shared → domains}/flap/portal-bundle.js +84 -79
  343. package/dist/domains/flap/portal-create-token.d.ts +81 -0
  344. package/dist/domains/flap/portal-create-token.js +255 -0
  345. package/dist/{shared → domains}/flap/portal.d.ts +1 -2
  346. package/dist/{shared → domains}/flap/portal.js +36 -28
  347. package/dist/{shared → domains}/flap/vanity.d.ts +6 -6
  348. package/dist/{shared → domains}/flap/vanity.js +15 -21
  349. package/dist/{shared → domains}/flap/vault.d.ts +25 -93
  350. package/dist/{shared → domains}/flap/vault.js +77 -127
  351. package/dist/{flows → domains/flows}/create.d.ts +2 -1
  352. package/dist/{flows → domains/flows}/create.js +8 -8
  353. package/dist/domains/flows/index.d.ts +9 -0
  354. package/dist/domains/flows/index.js +9 -0
  355. package/dist/{contracts → domains/four/contracts}/helper3.d.ts +20 -5
  356. package/dist/{contracts → domains/four/contracts}/helper3.js +56 -20
  357. package/dist/domains/four/contracts/tm-bundle-helpers.d.ts +88 -0
  358. package/dist/domains/four/contracts/tm-bundle-helpers.js +73 -0
  359. package/dist/{contracts → domains/four/contracts}/tm-bundle.d.ts +4 -52
  360. package/dist/{contracts → domains/four/contracts}/tm-bundle.js +122 -189
  361. package/dist/{contracts → domains/four/contracts}/tm.d.ts +10 -8
  362. package/dist/{contracts → domains/four/contracts}/tm.js +39 -35
  363. package/dist/{contracts → domains/four/contracts}/tm1.js +9 -4
  364. package/dist/{contracts → domains/four/contracts}/tm2.js +10 -5
  365. package/dist/domains/four/index.d.ts +7 -0
  366. package/dist/domains/four/index.js +7 -0
  367. package/dist/{shared → domains}/four/tax-token.d.ts +1 -1
  368. package/dist/{shared → domains}/four/tax-token.js +31 -10
  369. package/dist/domains/holders/holders-maker-helpers.d.ts +9 -0
  370. package/dist/domains/holders/holders-maker-helpers.js +9 -0
  371. package/dist/domains/holders/holders-maker.d.ts +18 -0
  372. package/dist/domains/holders/holders-maker.js +324 -0
  373. package/dist/domains/holders/index.d.ts +1 -0
  374. package/dist/domains/holders/index.js +1 -0
  375. package/dist/domains/holders/internal/addresses.d.ts +12 -0
  376. package/dist/domains/holders/internal/addresses.js +15 -0
  377. package/dist/domains/holders/internal/buy-tx.d.ts +44 -0
  378. package/dist/domains/holders/internal/buy-tx.js +278 -0
  379. package/dist/domains/holders/internal/constants.d.ts +6 -0
  380. package/dist/domains/holders/internal/constants.js +7 -0
  381. package/dist/domains/holders/internal/disperse.d.ts +18 -0
  382. package/dist/domains/holders/internal/disperse.js +90 -0
  383. package/dist/domains/holders/internal/routing.d.ts +4 -0
  384. package/dist/domains/holders/internal/routing.js +45 -0
  385. package/dist/domains/holders/internal/transfer-tx.d.ts +4 -0
  386. package/dist/domains/holders/internal/transfer-tx.js +67 -0
  387. package/dist/domains/holders/types.d.ts +1 -0
  388. package/dist/domains/holders/types.js +1 -0
  389. package/dist/domains/lp-inspect/index.d.ts +1 -0
  390. package/dist/domains/lp-inspect/index.js +1 -0
  391. package/dist/domains/lp-inspect/lp-inspect-helpers.d.ts +9 -0
  392. package/dist/domains/lp-inspect/lp-inspect-helpers.js +109 -0
  393. package/dist/domains/lp-inspect/lp-inspect.d.ts +40 -0
  394. package/dist/{utils → domains/lp-inspect}/lp-inspect.js +78 -293
  395. package/dist/domains/lp-inspect/types.d.ts +1 -0
  396. package/dist/domains/lp-inspect/types.js +1 -0
  397. package/dist/domains/merkle/index.d.ts +12 -0
  398. package/dist/domains/merkle/index.js +11 -0
  399. package/dist/domains/private-sale/index.d.ts +1 -0
  400. package/dist/domains/private-sale/index.js +1 -0
  401. package/dist/domains/private-sale/private-sale.d.ts +34 -0
  402. package/dist/{utils → domains/private-sale}/private-sale.js +5 -16
  403. package/dist/domains/private-sale/types.d.ts +1 -0
  404. package/dist/domains/private-sale/types.js +1 -0
  405. package/dist/domains/quote/index.d.ts +1 -0
  406. package/dist/domains/quote/index.js +1 -0
  407. package/dist/{utils → domains/quote}/quote-helpers.d.ts +4 -45
  408. package/dist/{utils → domains/quote}/quote-helpers.js +17 -74
  409. package/dist/domains/quote/types.d.ts +1 -0
  410. package/dist/domains/quote/types.js +1 -0
  411. package/dist/domains/vanity/index.d.ts +5 -0
  412. package/dist/domains/vanity/index.js +5 -0
  413. package/dist/exports/root-bundle-and-tooling.d.ts +27 -0
  414. package/dist/exports/root-bundle-and-tooling.js +30 -0
  415. package/dist/exports/root-eni-and-bsc-iro.d.ts +26 -0
  416. package/dist/exports/root-eni-and-bsc-iro.js +66 -0
  417. package/dist/exports/root-foundations.d.ts +35 -0
  418. package/dist/exports/root-foundations.js +70 -0
  419. package/dist/exports/root-swap-dex-and-xlayer.d.ts +30 -0
  420. package/dist/exports/root-swap-dex-and-xlayer.js +78 -0
  421. package/dist/index.d.ts +17 -88
  422. package/dist/index.js +17 -218
  423. package/dist/utils/airdrop-sweep.d.ts +4 -76
  424. package/dist/utils/airdrop-sweep.js +42 -55
  425. package/dist/utils/bundle-helpers.d.ts +9 -243
  426. package/dist/utils/bundle-helpers.js +10 -584
  427. package/dist/utils/constants.d.ts +5 -61
  428. package/dist/utils/constants.js +5 -80
  429. package/dist/utils/contract-factory.d.ts +2 -4
  430. package/dist/utils/contract-factory.js +25 -18
  431. package/dist/utils/errors.d.ts +12 -1
  432. package/dist/utils/errors.js +60 -1
  433. package/dist/utils/hop-chains.d.ts +35 -0
  434. package/dist/utils/hop-chains.js +215 -0
  435. package/dist/utils/index.d.ts +5 -0
  436. package/dist/utils/index.js +5 -0
  437. package/dist/utils/mpcExclusive.d.ts +2 -5
  438. package/dist/utils/mpcExclusive.js +4 -3
  439. package/dist/utils/provider-factory.d.ts +4 -0
  440. package/dist/utils/provider-factory.js +10 -0
  441. package/dist/utils/stealth-transfer.d.ts +2 -28
  442. package/dist/utils/stealth-transfer.js +41 -21
  443. package/dist/utils/swap-helpers.d.ts +2 -15
  444. package/dist/utils/swap-helpers.js +7 -12
  445. package/dist/utils/types/airdrop-sweep.d.ts +1 -0
  446. package/dist/utils/types/airdrop-sweep.js +1 -0
  447. package/dist/utils/types/contract-factory.d.ts +1 -0
  448. package/dist/utils/types/contract-factory.js +1 -0
  449. package/dist/utils/types/errors.d.ts +1 -0
  450. package/dist/utils/types/errors.js +1 -0
  451. package/dist/utils/types/hop-chains.d.ts +8 -0
  452. package/dist/utils/types/hop-chains.js +1 -0
  453. package/dist/utils/types/index.d.ts +13 -0
  454. package/dist/utils/types/index.js +1 -0
  455. package/dist/utils/types/mpc-exclusive.d.ts +5 -0
  456. package/dist/utils/types/mpc-exclusive.js +1 -0
  457. package/dist/utils/types/stealth-transfer.d.ts +44 -0
  458. package/dist/utils/types/stealth-transfer.js +1 -0
  459. package/dist/utils/types/wallet.d.ts +25 -0
  460. package/dist/utils/types/wallet.js +1 -0
  461. package/dist/utils/wallet.d.ts +4 -25
  462. package/dist/utils/wallet.js +27 -22
  463. package/package.json +96 -2
  464. package/dist/contracts/tm-bundle-merkle/approve-tokenmanager.d.ts +0 -26
  465. package/dist/contracts/tm-bundle-merkle/approve-tokenmanager.js +0 -113
  466. package/dist/contracts/tm-bundle-merkle/config.d.ts +0 -70
  467. package/dist/contracts/tm-bundle-merkle/config.js +0 -114
  468. package/dist/contracts/tm-bundle-merkle/index.d.ts +0 -15
  469. package/dist/contracts/tm-bundle-merkle/index.js +0 -29
  470. package/dist/contracts/tm-bundle-merkle/internal.d.ts +0 -48
  471. package/dist/contracts/tm-bundle-merkle/internal.js +0 -240
  472. package/dist/contracts/tm-bundle-merkle/swap.d.ts +0 -146
  473. package/dist/contracts/tm-bundle-merkle/utils.d.ts +0 -20
  474. package/dist/contracts/tm-bundle-merkle/utils.js +0 -1503
  475. package/dist/dex/direct-router.d.ts +0 -150
  476. package/dist/shared/abis/TaxToken.json +0 -105
  477. package/dist/shared/abis/TokenManager2.json +0 -60
  478. package/dist/shared/flap/graduated-dex.d.ts +0 -1
  479. package/dist/shared/flap/graduated-dex.js +0 -1
  480. package/dist/shared/flap/launch-v6.d.ts +0 -132
  481. package/dist/shared/flap/launch-v6.js +0 -137
  482. package/dist/shared/flap/portal-bundle-merkle/config.d.ts +0 -79
  483. package/dist/shared/flap/portal-bundle-merkle/config.js +0 -133
  484. package/dist/shared/flap/portal-bundle-merkle/index.d.ts +0 -14
  485. package/dist/shared/flap/portal-bundle-merkle/swap-buy-first.d.ts +0 -65
  486. package/dist/shared/flap/portal-bundle-merkle/swap.d.ts +0 -201
  487. package/dist/shared/flap/portal-bundle-merkle/swap.js +0 -1359
  488. package/dist/shared/flap/portal-bundle-merkle/utils.d.ts +0 -89
  489. package/dist/shared/flap/portal-create-token.d.ts +0 -63
  490. package/dist/shared/flap/portal-create-token.js +0 -258
  491. package/dist/shared/four/index.d.ts +0 -7
  492. package/dist/shared/four/index.js +0 -22
  493. package/dist/shared/index.d.ts +0 -10
  494. package/dist/shared/index.js +0 -10
  495. package/dist/utils/holders-maker.d.ts +0 -154
  496. package/dist/utils/holders-maker.js +0 -945
  497. package/dist/utils/pcs-infinity-cl.d.ts +0 -65
  498. package/dist/utils/pcs-infinity-cl.js +0 -426
  499. package/dist/utils/private-sale.d.ts +0 -90
  500. /package/dist/{shared/abis → abis/contracts}/TokenManager.json +0 -0
  501. /package/dist/{shared/abis → abis/contracts}/TokenManagerHelper3.json +0 -0
  502. /package/dist/{contracts/tm-bundle-merkle → bundle/four-meme}/swap-internal.d.ts +0 -0
  503. /package/dist/{shared/flap/portal-bundle-merkle/types.js → bundle/four-meme/types/buy-first.js} +0 -0
  504. /package/dist/{contracts/tm-bundle-merkle → bundle/four-meme}/types.js +0 -0
  505. /package/dist/{shared → core}/clients/emitservice.d.ts +0 -0
  506. /package/dist/{shared → core}/constants/profit.d.ts +0 -0
  507. /package/dist/{shared → core}/constants/profit.js +0 -0
  508. /package/dist/{dex → domains/dex}/index.d.ts +0 -0
  509. /package/dist/{dex → domains/dex}/index.js +0 -0
  510. /package/dist/{shared → domains}/flap/abi.d.ts +0 -0
  511. /package/dist/{shared → domains}/flap/curve.d.ts +0 -0
  512. /package/dist/{shared → domains}/flap/ipfs.d.ts +0 -0
  513. /package/dist/{shared → domains}/flap/ipfs.js +0 -0
  514. /package/dist/{shared → domains}/flap/permit.d.ts +0 -0
  515. /package/dist/{shared → domains}/flap/portal-bundle-merkle/curve-to-dex.d.ts +0 -0
  516. /package/dist/{shared → domains}/flap/portal-bundle-merkle/pancake-proxy.d.ts +0 -0
  517. /package/dist/{shared → domains}/flap/portal-bundle-merkle/private.d.ts +0 -0
  518. /package/dist/{contracts → domains/four/contracts}/tm1.d.ts +0 -0
  519. /package/dist/{contracts → domains/four/contracts}/tm2.d.ts +0 -0
@@ -4,9 +4,13 @@
4
4
  * 用于服务器端接收前端构建的签名交易后,提交到Merkle或BlockRazor
5
5
  * 以及 Monad 等不支持 Bundle 的链的逐笔广播
6
6
  */
7
- import { MerkleClient } from '../../shared/clients/merkle.js';
8
- import { BlockRazorClient } from '../../shared/clients/blockrazor.js';
7
+ import { MerkleClient } from '../core/clients/merkle.js';
8
+ import { BlockRazorClient } from '../core/clients/blockrazor.js';
9
9
  import { ethers } from 'ethers';
10
+ import { getErrorMessageFromUnknown, consoleSdkLogger } from '../core/index.js';
11
+ import { CHAINS } from '../core/constants/index.js';
12
+ import { createSignProvider } from './sign-context-helpers.js';
13
+ const sdkLogger = consoleSdkLogger;
10
14
  // ✅ MerkleClient 缓存(复用连接,减少初始化开销)
11
15
  const merkleClientCache = new Map();
12
16
  const CLIENT_CACHE_TTL_MS = 60 * 1000; // 60秒缓存
@@ -14,7 +18,7 @@ const CLIENT_CACHE_TTL_MS = 60 * 1000; // 60秒缓存
14
18
  * 获取或创建 MerkleClient(带缓存)
15
19
  */
16
20
  function getMerkleClient(config) {
17
- const cacheKey = `${config.apiKey}-${config.chainId ?? 56}-${config.customRpcUrl || ''}`;
21
+ const cacheKey = `${config.apiKey}-${config.chainId ?? CHAINS.BSC.chainId}-${config.customRpcUrl || ''}`;
18
22
  const now = Date.now();
19
23
  const cached = merkleClientCache.get(cacheKey);
20
24
  if (cached && cached.expireAt > now) {
@@ -23,12 +27,22 @@ function getMerkleClient(config) {
23
27
  // 创建新客户端并缓存
24
28
  const client = new MerkleClient({
25
29
  apiKey: config.apiKey,
26
- chainId: config.chainId ?? 56,
27
- customRpcUrl: config.customRpcUrl
30
+ chainId: config.chainId ?? CHAINS.BSC.chainId,
31
+ customRpcUrl: config.customRpcUrl,
28
32
  });
29
33
  merkleClientCache.set(cacheKey, { client, expireAt: now + CLIENT_CACHE_TTL_MS });
30
34
  return client;
31
35
  }
36
+ async function submitBundlesSequential(bundles, submitFn) {
37
+ const results = [];
38
+ for (const signedTransactions of bundles) {
39
+ results.push(await submitFn(signedTransactions));
40
+ }
41
+ return results;
42
+ }
43
+ async function submitBundlesParallel(bundles, submitFn) {
44
+ return Promise.all(bundles.map((signedTransactions) => submitFn(signedTransactions)));
45
+ }
32
46
  /**
33
47
  * 提交已签名的交易到Merkle(服务器端使用)
34
48
  *
@@ -63,14 +77,14 @@ export async function submitBundleToMerkle(signedTransactions, config) {
63
77
  return {
64
78
  code: false,
65
79
  totalTransactions,
66
- error: 'signedTransactions cannot be empty'
80
+ error: 'signedTransactions cannot be empty',
67
81
  };
68
82
  }
69
83
  if (!config.apiKey) {
70
84
  return {
71
85
  code: false,
72
86
  totalTransactions,
73
- error: 'apiKey is required in config'
87
+ error: 'apiKey is required in config',
74
88
  };
75
89
  }
76
90
  // ✅ 使用缓存的 MerkleClient(复用连接 + 区块号缓存)
@@ -81,7 +95,7 @@ export async function submitBundleToMerkle(signedTransactions, config) {
81
95
  blockOffset: config.bundleBlockOffset ?? 3,
82
96
  minBlockOffset: config.minBlockOffset ?? 3,
83
97
  autoRetry: config.autoRetryBundle ?? false,
84
- maxRetries: config.maxBundleRetries ?? 2
98
+ maxRetries: config.maxBundleRetries ?? 2,
85
99
  });
86
100
  // ✅ 提交成功
87
101
  return {
@@ -90,7 +104,7 @@ export async function submitBundleToMerkle(signedTransactions, config) {
90
104
  bundleHash: bundleResult.bundleHash,
91
105
  txHashes: bundleResult.txHashes,
92
106
  targetBlock: bundleResult.targetBlock,
93
- txCount: bundleResult.txCount
107
+ txCount: bundleResult.txCount,
94
108
  };
95
109
  }
96
110
  catch (error) {
@@ -98,7 +112,7 @@ export async function submitBundleToMerkle(signedTransactions, config) {
98
112
  return {
99
113
  code: false,
100
114
  totalTransactions: signedTransactions?.length ?? 0,
101
- error: error?.message || String(error)
115
+ error: getErrorMessageFromUnknown(error),
102
116
  };
103
117
  }
104
118
  }
@@ -110,12 +124,7 @@ export async function submitBundleToMerkle(signedTransactions, config) {
110
124
  * @returns Bundle提交结果数组
111
125
  */
112
126
  export async function submitMultipleBundles(bundles, config) {
113
- const results = [];
114
- for (const signedTransactions of bundles) {
115
- const result = await submitBundleToMerkle(signedTransactions, config);
116
- results.push(result);
117
- }
118
- return results;
127
+ return submitBundlesSequential(bundles, (signedTransactions) => submitBundleToMerkle(signedTransactions, config));
119
128
  }
120
129
  /**
121
130
  * 并行提交多个Bundle到Merkle(适用于独立的Bundle)
@@ -125,8 +134,7 @@ export async function submitMultipleBundles(bundles, config) {
125
134
  * @returns Bundle提交结果数组
126
135
  */
127
136
  export async function submitMultipleBundlesParallel(bundles, config) {
128
- const promises = bundles.map(signedTransactions => submitBundleToMerkle(signedTransactions, config));
129
- return await Promise.all(promises);
137
+ return submitBundlesParallel(bundles, (signedTransactions) => submitBundleToMerkle(signedTransactions, config));
130
138
  }
131
139
  // ==================== BlockRazor Bundle 提交方法 ====================
132
140
  // ✅ BlockRazorClient 缓存(复用连接,减少初始化开销)
@@ -144,9 +152,9 @@ function getBlockRazorClient(config) {
144
152
  // 创建新客户端并缓存
145
153
  const client = new BlockRazorClient({
146
154
  apiKey: config.apiKey,
147
- chainId: 56, // BlockRazor 目前只支持 BSC
155
+ chainId: CHAINS.BSC.chainId, // BlockRazor 目前只支持 BSC
148
156
  customRpcUrl: config.customRpcUrl,
149
- builderRpcUrl: config.builderRpcUrl
157
+ builderRpcUrl: config.builderRpcUrl,
150
158
  });
151
159
  blockRazorClientCache.set(cacheKey, { client, expireAt: now + CLIENT_CACHE_TTL_MS });
152
160
  return client;
@@ -190,7 +198,7 @@ export async function submitBundleToBlockRazor(signedTransactions, config) {
190
198
  return {
191
199
  code: false,
192
200
  totalTransactions,
193
- error: 'signedTransactions cannot be empty'
201
+ error: 'signedTransactions cannot be empty',
194
202
  };
195
203
  }
196
204
  // ✅ 使用缓存的 BlockRazorClient
@@ -203,7 +211,7 @@ export async function submitBundleToBlockRazor(signedTransactions, config) {
203
211
  noMerge: config.noMerge ?? false,
204
212
  revertingTxHashes: config.revertingTxHashes,
205
213
  autoRetry: config.autoRetry ?? false,
206
- maxRetries: config.maxRetries ?? 3
214
+ maxRetries: config.maxRetries ?? 3,
207
215
  });
208
216
  // ✅ 提交成功
209
217
  return {
@@ -212,7 +220,7 @@ export async function submitBundleToBlockRazor(signedTransactions, config) {
212
220
  bundleHash: bundleResult.bundleHash,
213
221
  txHashes: bundleResult.txHashes,
214
222
  maxBlockNumber: bundleResult.maxBlockNumber,
215
- txCount: bundleResult.txCount
223
+ txCount: bundleResult.txCount,
216
224
  };
217
225
  }
218
226
  catch (error) {
@@ -220,7 +228,7 @@ export async function submitBundleToBlockRazor(signedTransactions, config) {
220
228
  return {
221
229
  code: false,
222
230
  totalTransactions: signedTransactions?.length ?? 0,
223
- error: error?.message || String(error)
231
+ error: getErrorMessageFromUnknown(error),
224
232
  };
225
233
  }
226
234
  }
@@ -232,12 +240,7 @@ export async function submitBundleToBlockRazor(signedTransactions, config) {
232
240
  * @returns Bundle 提交结果数组
233
241
  */
234
242
  export async function submitMultipleBundlesToBlockRazor(bundles, config) {
235
- const results = [];
236
- for (const signedTransactions of bundles) {
237
- const result = await submitBundleToBlockRazor(signedTransactions, config);
238
- results.push(result);
239
- }
240
- return results;
243
+ return submitBundlesSequential(bundles, (signedTransactions) => submitBundleToBlockRazor(signedTransactions, config));
241
244
  }
242
245
  /**
243
246
  * 并行提交多个 Bundle 到 BlockRazor(适用于独立的 Bundle)
@@ -247,8 +250,7 @@ export async function submitMultipleBundlesToBlockRazor(bundles, config) {
247
250
  * @returns Bundle 提交结果数组
248
251
  */
249
252
  export async function submitMultipleBundlesToBlockRazorParallel(bundles, config) {
250
- const promises = bundles.map(signedTransactions => submitBundleToBlockRazor(signedTransactions, config));
251
- return await Promise.all(promises);
253
+ return submitBundlesParallel(bundles, (signedTransactions) => submitBundleToBlockRazor(signedTransactions, config));
252
254
  }
253
255
  function shouldTreatBroadcastErrorAsMaybeSent(msg) {
254
256
  const m = String(msg || '').toLowerCase();
@@ -264,7 +266,7 @@ async function recoverTxHashIfAlreadySeen(provider, signedTx, errorMessage) {
264
266
  if (!shouldTreatBroadcastErrorAsMaybeSent(errorMessage))
265
267
  return undefined;
266
268
  try {
267
- const hash = ethers.keccak256(signedTx);
269
+ const hash = ethers.Transaction.from(signedTx).hash;
268
270
  if (!hash)
269
271
  return undefined;
270
272
  const tx = await provider.getTransaction(hash);
@@ -311,7 +313,7 @@ export async function submitDirectToRpc(signedTransactions, config) {
311
313
  failedCount: 0,
312
314
  txHashes: [],
313
315
  results: [],
314
- errorSummary: 'signedTransactions cannot be empty'
316
+ errorSummary: 'signedTransactions cannot be empty',
315
317
  };
316
318
  }
317
319
  if (!config.rpcUrl) {
@@ -322,16 +324,12 @@ export async function submitDirectToRpc(signedTransactions, config) {
322
324
  failedCount: totalTransactions,
323
325
  txHashes: [],
324
326
  results: [],
325
- errorSummary: 'rpcUrl is required in config'
327
+ errorSummary: 'rpcUrl is required in config',
326
328
  };
327
329
  }
328
330
  const chainId = config.chainId ?? 143;
329
331
  const chainName = config.chainName ?? 'MONAD';
330
- // 创建 Provider
331
- const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
332
- chainId,
333
- name: chainName
334
- });
332
+ const provider = createSignProvider(config.rpcUrl, chainId, chainName);
335
333
  // ✅ 并行广播所有交易
336
334
  const broadcastPromises = signedTransactions.map(async (signedTx, i) => {
337
335
  try {
@@ -344,18 +342,18 @@ export async function submitDirectToRpc(signedTransactions, config) {
344
342
  console.warn(`⚠️ [${chainName}] 交易 ${txResponse.hash} 执行失败(已上链但状态为0)`);
345
343
  }
346
344
  }
347
- catch (waitError) {
345
+ catch (_waitError) {
348
346
  console.warn(`⚠️ [${chainName}] 等待交易确认超时: ${txResponse.hash}`);
349
347
  }
350
348
  }
351
349
  return {
352
350
  index: i,
353
351
  success: true,
354
- txHash: txResponse.hash
352
+ txHash: txResponse.hash,
355
353
  };
356
354
  }
357
355
  catch (error) {
358
- const errorMessage = error?.message || String(error);
356
+ const errorMessage = getErrorMessageFromUnknown(error);
359
357
  console.error(`❌ [${chainName}] 交易 ${i + 1}/${totalTransactions} 广播失败:`, errorMessage);
360
358
  // ✅ 兼容:nonce too low / already known 等情况下,交易可能已经被接收
361
359
  const recovered = await recoverTxHashIfAlreadySeen(provider, signedTx, errorMessage);
@@ -364,22 +362,24 @@ export async function submitDirectToRpc(signedTransactions, config) {
364
362
  try {
365
363
  await provider.waitForTransaction(recovered, 1, config.confirmationTimeout ?? 30000);
366
364
  }
367
- catch { }
365
+ catch (waitError) {
366
+ sdkLogger.debug?.(`[DirectSubmit] recovered tx waitForTransaction failed: ${recovered}`, getErrorMessageFromUnknown(waitError));
367
+ }
368
368
  }
369
369
  return { index: i, success: true, txHash: recovered, error: errorMessage };
370
370
  }
371
371
  return {
372
372
  index: i,
373
373
  success: false,
374
- error: errorMessage
374
+ error: errorMessage,
375
375
  };
376
376
  }
377
377
  });
378
378
  const results = await Promise.all(broadcastPromises);
379
379
  // 按索引排序结果
380
380
  results.sort((a, b) => a.index - b.index);
381
- const txHashes = results.filter(r => r.success && r.txHash).map(r => r.txHash);
382
- const errors = results.filter(r => !r.success).map(r => `交易 ${r.index + 1}: ${r.error}`);
381
+ const txHashes = results.filter((r) => r.success && r.txHash).map((r) => r.txHash);
382
+ const errors = results.filter((r) => !r.success).map((r) => `交易 ${r.index + 1}: ${r.error}`);
383
383
  const successCount = txHashes.length;
384
384
  const failedCount = totalTransactions - successCount;
385
385
  return {
@@ -389,7 +389,7 @@ export async function submitDirectToRpc(signedTransactions, config) {
389
389
  failedCount,
390
390
  txHashes,
391
391
  results,
392
- errorSummary: errors.length > 0 ? errors.join('; ') : undefined
392
+ errorSummary: errors.length > 0 ? errors.join('; ') : undefined,
393
393
  };
394
394
  }
395
395
  /**
@@ -413,7 +413,7 @@ export async function submitDirectToRpcSequential(signedTransactions, config) {
413
413
  failedCount: 0,
414
414
  txHashes: [],
415
415
  results: [],
416
- errorSummary: 'signedTransactions cannot be empty'
416
+ errorSummary: 'signedTransactions cannot be empty',
417
417
  };
418
418
  }
419
419
  if (!config.rpcUrl) {
@@ -424,37 +424,31 @@ export async function submitDirectToRpcSequential(signedTransactions, config) {
424
424
  failedCount: totalTransactions,
425
425
  txHashes: [],
426
426
  results: [],
427
- errorSummary: 'rpcUrl is required in config'
427
+ errorSummary: 'rpcUrl is required in config',
428
428
  };
429
429
  }
430
430
  const chainId = config.chainId ?? 143;
431
431
  const chainName = config.chainName ?? 'MONAD';
432
432
  // ✅ XLayer 链默认 120 秒超时(网络可能较慢)
433
433
  const confirmationTimeout = config.confirmationTimeout ?? (chainId === 196 ? 120000 : 60000);
434
- const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
435
- chainId,
436
- name: chainName
437
- });
434
+ const provider = createSignProvider(config.rpcUrl, chainId, chainName);
438
435
  const results = [];
439
436
  const txHashes = [];
440
437
  const errors = [];
441
- console.log(`📤 [${chainName}] 开始顺序广播 ${totalTransactions} 笔交易(等待每笔确认)`);
442
438
  // 顺序广播并等待确认
443
439
  for (let i = 0; i < signedTransactions.length; i++) {
444
440
  const signedTx = signedTransactions[i];
445
441
  try {
446
442
  // 广播交易
447
443
  const txResponse = await provider.broadcastTransaction(signedTx);
448
- console.log(`📡 [${chainName}] 交易 ${i + 1}/${totalTransactions} 广播成功: ${txResponse.hash},等待确认...`);
449
444
  // ✅ 等待交易确认
450
445
  const receipt = await provider.waitForTransaction(txResponse.hash, 1, // 等待1个确认
451
446
  confirmationTimeout);
452
447
  if (receipt && receipt.status === 1) {
453
- console.log(`✅ [${chainName}] 交易 ${i + 1}/${totalTransactions} 已确认: ${txResponse.hash}`);
454
448
  results.push({
455
449
  index: i,
456
450
  success: true,
457
- txHash: txResponse.hash
451
+ txHash: txResponse.hash,
458
452
  });
459
453
  txHashes.push(txResponse.hash);
460
454
  }
@@ -465,7 +459,7 @@ export async function submitDirectToRpcSequential(signedTransactions, config) {
465
459
  index: i,
466
460
  success: false,
467
461
  txHash: txResponse.hash,
468
- error: errorMsg
462
+ error: errorMsg,
469
463
  });
470
464
  errors.push(`交易 ${i + 1}: ${errorMsg}`);
471
465
  // ✅ 多跳场景:如果某笔失败,后续交易肯定也会失败,立即停止
@@ -474,17 +468,15 @@ export async function submitDirectToRpcSequential(signedTransactions, config) {
474
468
  }
475
469
  }
476
470
  catch (error) {
477
- const errorMessage = error?.message || String(error);
471
+ const errorMessage = getErrorMessageFromUnknown(error);
478
472
  console.error(`❌ [${chainName}] 交易 ${i + 1}/${totalTransactions} 广播/确认失败:`, errorMessage);
479
473
  // ✅ 兼容:nonce too low / already known 等情况下,交易可能已经被接收
480
474
  const recovered = await recoverTxHashIfAlreadySeen(provider, signedTx, errorMessage);
481
475
  if (recovered) {
482
- console.log(`🔄 [${chainName}] 交易 ${i + 1} 可能已广播,尝试等待确认: ${recovered}`);
483
476
  // 顺序模式依赖确认:尽量等待一下
484
477
  try {
485
478
  const receipt = await provider.waitForTransaction(recovered, 1, confirmationTimeout);
486
479
  if (receipt && receipt.status === 1) {
487
- console.log(`✅ [${chainName}] 交易 ${i + 1}/${totalTransactions} 恢复成功: ${recovered}`);
488
480
  results.push({ index: i, success: true, txHash: recovered, error: errorMessage });
489
481
  txHashes.push(recovered);
490
482
  continue;
@@ -499,9 +491,14 @@ export async function submitDirectToRpcSequential(signedTransactions, config) {
499
491
  }
500
492
  catch (waitError) {
501
493
  // 等待超时:对于多跳场景,不能假设成功,需要停止
502
- const waitErrorMsg = waitError?.message || String(waitError);
494
+ const waitErrorMsg = getErrorMessageFromUnknown(waitError);
503
495
  console.error(`⏱️ [${chainName}] 交易 ${i + 1} 等待确认超时: ${waitErrorMsg}`);
504
- results.push({ index: i, success: false, txHash: recovered, error: `${errorMessage} | 等待确认超时: ${waitErrorMsg}` });
496
+ results.push({
497
+ index: i,
498
+ success: false,
499
+ txHash: recovered,
500
+ error: `${errorMessage} | 等待确认超时: ${waitErrorMsg}`,
501
+ });
505
502
  errors.push(`交易 ${i + 1}: ${errorMessage} | 等待确认超时`);
506
503
  // ✅ 多跳场景:超时也停止
507
504
  console.warn(`⚠️ [${chainName}] 多跳模式检测到超时,停止后续 ${totalTransactions - i - 1} 笔交易`);
@@ -511,7 +508,7 @@ export async function submitDirectToRpcSequential(signedTransactions, config) {
511
508
  results.push({
512
509
  index: i,
513
510
  success: false,
514
- error: errorMessage
511
+ error: errorMessage,
515
512
  });
516
513
  errors.push(`交易 ${i + 1}: ${errorMessage}`);
517
514
  // ✅ 多跳场景:如果某笔失败,后续交易肯定也会失败,立即停止
@@ -521,7 +518,6 @@ export async function submitDirectToRpcSequential(signedTransactions, config) {
521
518
  }
522
519
  const successCount = txHashes.length;
523
520
  const failedCount = totalTransactions - successCount;
524
- console.log(`📊 [${chainName}] 顺序广播完成: 成功 ${successCount}/${totalTransactions}`);
525
521
  return {
526
522
  code: successCount > 0,
527
523
  totalTransactions,
@@ -529,7 +525,7 @@ export async function submitDirectToRpcSequential(signedTransactions, config) {
529
525
  failedCount,
530
526
  txHashes,
531
527
  results,
532
- errorSummary: errors.length > 0 ? errors.join('; ') : undefined
528
+ errorSummary: errors.length > 0 ? errors.join('; ') : undefined,
533
529
  };
534
530
  }
535
531
  /**
@@ -552,7 +548,7 @@ export async function submitDirectToRpcSequentialNoWait(signedTransactions, conf
552
548
  failedCount: 0,
553
549
  txHashes: [],
554
550
  results: [],
555
- errorSummary: 'signedTransactions cannot be empty'
551
+ errorSummary: 'signedTransactions cannot be empty',
556
552
  };
557
553
  }
558
554
  if (!config.rpcUrl) {
@@ -563,15 +559,12 @@ export async function submitDirectToRpcSequentialNoWait(signedTransactions, conf
563
559
  failedCount: totalTransactions,
564
560
  txHashes: [],
565
561
  results: [],
566
- errorSummary: 'rpcUrl is required in config'
562
+ errorSummary: 'rpcUrl is required in config',
567
563
  };
568
564
  }
569
565
  const chainId = config.chainId ?? 143;
570
566
  const chainName = config.chainName ?? 'MONAD';
571
- const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
572
- chainId,
573
- name: chainName
574
- });
567
+ const provider = createSignProvider(config.rpcUrl, chainId, chainName);
575
568
  const results = [];
576
569
  const txHashes = [];
577
570
  const errors = [];
@@ -584,13 +577,12 @@ export async function submitDirectToRpcSequentialNoWait(signedTransactions, conf
584
577
  results.push({
585
578
  index: i,
586
579
  success: true,
587
- txHash: txResponse.hash
580
+ txHash: txResponse.hash,
588
581
  });
589
582
  txHashes.push(txResponse.hash);
590
- console.log(`✅ [${chainName}] 交易 ${i + 1}/${totalTransactions} 广播成功: ${txResponse.hash}`);
591
583
  }
592
584
  catch (error) {
593
- const errorMessage = error?.message || String(error);
585
+ const errorMessage = getErrorMessageFromUnknown(error);
594
586
  console.error(`❌ [${chainName}] 交易 ${i + 1}/${totalTransactions} 广播失败:`, errorMessage);
595
587
  // ✅ 兼容:nonce too low / already known 等情况下,交易可能已经被接收
596
588
  const recovered = await recoverTxHashIfAlreadySeen(provider, signedTx, errorMessage);
@@ -602,7 +594,7 @@ export async function submitDirectToRpcSequentialNoWait(signedTransactions, conf
602
594
  results.push({
603
595
  index: i,
604
596
  success: false,
605
- error: errorMessage
597
+ error: errorMessage,
606
598
  });
607
599
  errors.push(`交易 ${i + 1}: ${errorMessage}`);
608
600
  // ✅ 如果某笔失败,继续尝试后续交易(可能是 nonce 问题可以自动恢复)
@@ -617,7 +609,7 @@ export async function submitDirectToRpcSequentialNoWait(signedTransactions, conf
617
609
  failedCount,
618
610
  txHashes,
619
611
  results,
620
- errorSummary: errors.length > 0 ? errors.join('; ') : undefined
612
+ errorSummary: errors.length > 0 ? errors.join('; ') : undefined,
621
613
  };
622
614
  }
623
615
  /**
@@ -639,7 +631,7 @@ export async function submitDirectToRpcParallel(signedTransactions, config) {
639
631
  failedCount: 0,
640
632
  txHashes: [],
641
633
  results: [],
642
- errorSummary: 'signedTransactions cannot be empty'
634
+ errorSummary: 'signedTransactions cannot be empty',
643
635
  };
644
636
  }
645
637
  if (!config.rpcUrl) {
@@ -650,15 +642,12 @@ export async function submitDirectToRpcParallel(signedTransactions, config) {
650
642
  failedCount: totalTransactions,
651
643
  txHashes: [],
652
644
  results: [],
653
- errorSummary: 'rpcUrl is required in config'
645
+ errorSummary: 'rpcUrl is required in config',
654
646
  };
655
647
  }
656
648
  const chainId = config.chainId ?? 143;
657
649
  const chainName = config.chainName ?? 'MONAD';
658
- const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
659
- chainId,
660
- name: chainName
661
- });
650
+ const provider = createSignProvider(config.rpcUrl, chainId, chainName);
662
651
  // 并行广播
663
652
  const broadcastPromises = signedTransactions.map(async (signedTx, i) => {
664
653
  try {
@@ -666,20 +655,20 @@ export async function submitDirectToRpcParallel(signedTransactions, config) {
666
655
  return {
667
656
  index: i,
668
657
  success: true,
669
- txHash: txResponse.hash
658
+ txHash: txResponse.hash,
670
659
  };
671
660
  }
672
661
  catch (error) {
673
662
  return {
674
663
  index: i,
675
664
  success: false,
676
- error: error?.message || String(error)
665
+ error: getErrorMessageFromUnknown(error),
677
666
  };
678
667
  }
679
668
  });
680
669
  const results = await Promise.all(broadcastPromises);
681
- const txHashes = results.filter(r => r.success && r.txHash).map(r => r.txHash);
682
- const errors = results.filter(r => !r.success).map(r => `交易 ${r.index + 1}: ${r.error}`);
670
+ const txHashes = results.filter((r) => r.success && r.txHash).map((r) => r.txHash);
671
+ const errors = results.filter((r) => !r.success).map((r) => `交易 ${r.index + 1}: ${r.error}`);
683
672
  const successCount = txHashes.length;
684
673
  const failedCount = totalTransactions - successCount;
685
674
  return {
@@ -689,240 +678,54 @@ export async function submitDirectToRpcParallel(signedTransactions, config) {
689
678
  failedCount,
690
679
  txHashes,
691
680
  results,
692
- errorSummary: errors.length > 0 ? errors.join('; ') : undefined
693
- };
694
- }
695
- /**
696
- * ENI 快速并行广播:业务交易并行 + 利润交易顺序跟随
697
- *
698
- * 流程:
699
- * 1. 解码所有签名交易,识别哪些 from 地址有多笔交易(即含利润尾随交易的 payer)
700
- * 2. 把交易分为 "独立交易" 和 "依赖交易"(同 from 的第 2 笔及之后的交易)
701
- * 3. 并行广播所有独立交易(业务交易)
702
- * 4. 等待 payer 的业务交易上链后,再提交其利润交易(顺序跟随)
703
- * 5. 返回合并结果
704
- */
705
- export async function submitEniParallelThenProfit(signedTransactions, config) {
706
- const totalTransactions = signedTransactions?.length ?? 0;
707
- const emptyFail = (msg) => ({
708
- code: false, totalTransactions, successCount: 0, failedCount: totalTransactions,
709
- txHashes: [], results: [], errorSummary: msg,
710
- });
711
- if (!signedTransactions || signedTransactions.length === 0)
712
- return emptyFail('signedTransactions cannot be empty');
713
- if (!config.rpcUrl)
714
- return emptyFail('rpcUrl is required');
715
- const chainId = config.chainId ?? 173;
716
- const chainName = config.chainName ?? 'ENI';
717
- const provider = new ethers.JsonRpcProvider(config.rpcUrl, { chainId, name: chainName });
718
- // Step 1: 按 from 地址分组,识别独立交易和依赖交易
719
- const fromCounts = new Map();
720
- const txMeta = [];
721
- for (let i = 0; i < signedTransactions.length; i++) {
722
- try {
723
- const tx = ethers.Transaction.from(signedTransactions[i]);
724
- const from = (tx.from || '').toLowerCase();
725
- const seq = fromCounts.get(from) || 0;
726
- txMeta.push({ from, index: i, seqInFrom: seq });
727
- fromCounts.set(from, seq + 1);
728
- }
729
- catch {
730
- txMeta.push({ from: '', index: i, seqInFrom: 0 });
731
- }
732
- }
733
- // 独立交易:每个 from 的第一笔(seqInFrom === 0)
734
- // 依赖交易:每个 from 的第 2 笔及之后(seqInFrom > 0,通常是利润交易)
735
- const independentIndices = txMeta.filter(m => m.seqInFrom === 0).map(m => m.index);
736
- const dependentGroups = new Map();
737
- for (const m of txMeta) {
738
- if (m.seqInFrom > 0) {
739
- if (!dependentGroups.has(m.from))
740
- dependentGroups.set(m.from, []);
741
- dependentGroups.get(m.from).push(m.index);
742
- }
743
- }
744
- console.log(`🚀 [${chainName}] 并行广播 ${independentIndices.length} 笔业务交易,${totalTransactions - independentIndices.length} 笔利润交易顺序跟随`);
745
- // Step 2: 并行广播所有独立交易
746
- const allResults = new Array(totalTransactions);
747
- const independentPromises = independentIndices.map(async (idx) => {
748
- try {
749
- const resp = await provider.broadcastTransaction(signedTransactions[idx]);
750
- allResults[idx] = { index: idx, success: true, txHash: resp.hash };
751
- }
752
- catch (error) {
753
- const errorMessage = error?.message || String(error);
754
- const recovered = await recoverTxHashIfAlreadySeen(provider, signedTransactions[idx], errorMessage);
755
- if (recovered) {
756
- allResults[idx] = { index: idx, success: true, txHash: recovered, error: errorMessage };
757
- }
758
- else {
759
- allResults[idx] = { index: idx, success: false, error: errorMessage };
760
- console.error(`❌ [${chainName}] 业务交易 ${idx + 1} 广播失败: ${errorMessage.slice(0, 120)}`);
761
- }
762
- }
763
- });
764
- await Promise.all(independentPromises);
765
- // Step 3: 顺序提交依赖交易(利润交易)
766
- // 需要等待同 from 的业务交易先上链(nonce 依赖)
767
- for (const [from, indices] of dependentGroups) {
768
- // 找到该 from 的业务交易(seqInFrom===0)
769
- const parentMeta = txMeta.find(m => m.from === from && m.seqInFrom === 0);
770
- if (parentMeta) {
771
- const parentResult = allResults[parentMeta.index];
772
- if (parentResult?.success && parentResult.txHash) {
773
- // 等待业务交易上链确认
774
- try {
775
- await Promise.race([
776
- provider.waitForTransaction(parentResult.txHash, 1, 10000),
777
- new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), 10000)),
778
- ]);
779
- }
780
- catch {
781
- console.warn(`⚠️ [${chainName}] 等待 ${from.slice(0, 10)}... 业务交易确认超时,仍尝试发送利润交易`);
782
- }
783
- }
784
- }
785
- // 按顺序提交该 from 的依赖交易
786
- for (const idx of indices) {
787
- try {
788
- const resp = await provider.broadcastTransaction(signedTransactions[idx]);
789
- allResults[idx] = { index: idx, success: true, txHash: resp.hash };
790
- console.log(`💰 [${chainName}] 利润交易 ${idx + 1} 广播成功: ${resp.hash}`);
791
- }
792
- catch (error) {
793
- const errorMessage = error?.message || String(error);
794
- const recovered = await recoverTxHashIfAlreadySeen(provider, signedTransactions[idx], errorMessage);
795
- if (recovered) {
796
- allResults[idx] = { index: idx, success: true, txHash: recovered, error: errorMessage };
797
- }
798
- else {
799
- allResults[idx] = { index: idx, success: false, error: errorMessage };
800
- console.error(`❌ [${chainName}] 利润交易 ${idx + 1} 广播失败: ${errorMessage.slice(0, 120)}`);
801
- }
802
- }
803
- }
804
- }
805
- // Step 4: 汇总结果
806
- const txHashes = allResults.filter(r => r?.success && r.txHash).map(r => r.txHash);
807
- const errors = allResults.filter(r => r && !r.success).map(r => `交易 ${r.index + 1}: ${r.error}`);
808
- return {
809
- code: txHashes.length > 0,
810
- totalTransactions,
811
- successCount: txHashes.length,
812
- failedCount: totalTransactions - txHashes.length,
813
- txHashes,
814
- results: allResults.filter(Boolean),
815
681
  errorSummary: errors.length > 0 ? errors.join('; ') : undefined,
816
682
  };
817
683
  }
818
684
  /**
819
- * ENI Bundle 提交:模拟验证 → 快速顺序广播 → 同块确认
820
- *
821
- * 复用同一 Provider 快速顺序广播,最小化延迟、最大化同块概率。
822
- * ENI 出块 ~1.08s,连续 nonce 快速提交同块率极高。
685
+ * 智能广播到 RPC(自动选择并行或顺序)
823
686
  */
824
- export async function submitBundleToEni(signedTransactions, config) {
825
- const totalTransactions = signedTransactions?.length ?? 0;
826
- const emptyFail = (msg) => ({
827
- code: false, totalTransactions, successCount: 0, failedCount: totalTransactions,
828
- txHashes: [], results: [], sameBlock: false, errorSummary: msg,
687
+ export async function submitDirectToRpcSmart(signedTransactions, config, options) {
688
+ const emptyFail = (mode) => ({
689
+ code: false,
690
+ totalTransactions: 0,
691
+ successCount: 0,
692
+ failedCount: 0,
693
+ txHashes: [],
694
+ results: [],
695
+ errorSummary: 'signedTransactions cannot be empty',
696
+ mode,
829
697
  });
830
- if (!signedTransactions || signedTransactions.length === 0)
831
- return emptyFail('signedTransactions cannot be empty');
832
- if (!config.rpcUrl)
833
- return emptyFail('rpcUrl is required');
834
- const chainId = config.chainId ?? 173;
835
- const chainName = config.chainName ?? 'ENI';
836
- const simulationTimeout = config.simulationTimeout ?? 10000;
837
- const blockConfirmTimeout = config.blockConfirmTimeout ?? 15000;
838
- const provider = new ethers.JsonRpcProvider(config.rpcUrl, { chainId, name: chainName });
839
- // Phase 1: 模拟验证
840
- const simStart = Date.now();
841
- const simErrors = [];
842
- for (let i = 0; i < signedTransactions.length; i++) {
843
- try {
844
- const tx = ethers.Transaction.from(signedTransactions[i]);
845
- await Promise.race([
846
- provider.call({ to: tx.to, data: tx.data, value: tx.value, from: tx.from }),
847
- new Promise((_, reject) => setTimeout(() => reject(new Error('simulation timeout')), simulationTimeout)),
848
- ]);
849
- }
850
- catch (e) {
851
- const msg = e?.message || String(e);
852
- if (msg.includes('simulation timeout')) {
853
- console.warn(`⚠️ [${chainName}] 交易 ${i + 1} 模拟超时,跳过验证`);
854
- }
855
- else if (msg.includes('execution reverted') || msg.includes('CALL_EXCEPTION')) {
856
- simErrors.push(`交易 ${i + 1} 模拟失败: ${msg.slice(0, 200)}`);
857
- }
858
- }
859
- }
860
- const simulationDurationMs = Date.now() - simStart;
861
- if (simErrors.length > 0) {
862
- return { ...emptyFail(simErrors.join('; ')), simulationDurationMs };
698
+ if (!signedTransactions || signedTransactions.length === 0) {
699
+ return emptyFail('parallel');
863
700
  }
864
- console.log(`✅ [${chainName}] Bundle 模拟通过 (${totalTransactions} 笔, ${simulationDurationMs}ms)`);
865
- // Phase 2: 快速顺序广播(复用同一 provider 减少连接开销)
866
- const broadStart = Date.now();
867
- const results = [];
868
- const txHashes = [];
869
- for (let i = 0; i < signedTransactions.length; i++) {
870
- try {
871
- const txResponse = await provider.broadcastTransaction(signedTransactions[i]);
872
- results.push({ index: i, success: true, txHash: txResponse.hash });
873
- txHashes.push(txResponse.hash);
874
- }
875
- catch (error) {
876
- const errorMessage = error?.message || String(error);
877
- const recovered = await recoverTxHashIfAlreadySeen(provider, signedTransactions[i], errorMessage);
878
- if (recovered) {
879
- results.push({ index: i, success: true, txHash: recovered, error: errorMessage });
880
- txHashes.push(recovered);
881
- }
882
- else {
883
- results.push({ index: i, success: false, error: errorMessage });
884
- console.error(`❌ [${chainName}] Bundle tx ${i + 1}/${totalTransactions} 失败: ${errorMessage}`);
701
+ const hasMultipleFromSameWallet = (() => {
702
+ if (signedTransactions.length < 2)
703
+ return false;
704
+ const seen = new Set();
705
+ for (const raw of signedTransactions) {
706
+ if (!raw)
707
+ continue;
708
+ try {
709
+ const tx = ethers.Transaction.from(raw);
710
+ const from = (tx.from || '').toLowerCase();
711
+ if (!from)
712
+ continue;
713
+ if (seen.has(from))
714
+ return true;
715
+ seen.add(from);
885
716
  }
886
- }
887
- }
888
- const broadcastDurationMs = Date.now() - broadStart;
889
- const successCount = txHashes.length;
890
- const failedCount = totalTransactions - successCount;
891
- if (successCount === 0) {
892
- return {
893
- code: false, totalTransactions, successCount, failedCount, txHashes, results,
894
- sameBlock: false, simulationDurationMs, broadcastDurationMs,
895
- errorSummary: results.filter(r => !r.success).map(r => r.error).join('; '),
896
- };
897
- }
898
- // Phase 3: 同块确认
899
- let sameBlock = false;
900
- let blockNumber;
901
- const blockNumbers = [];
902
- try {
903
- const receipts = await Promise.all(txHashes.map(hash => Promise.race([
904
- provider.waitForTransaction(hash, 1, blockConfirmTimeout),
905
- new Promise((resolve) => setTimeout(() => resolve(null), blockConfirmTimeout)),
906
- ])));
907
- for (const receipt of receipts) {
908
- if (receipt && receipt.blockNumber) {
909
- blockNumbers.push(receipt.blockNumber);
717
+ catch {
718
+ // ignore parse errors
910
719
  }
911
720
  }
912
- if (blockNumbers.length === txHashes.length && blockNumbers.length > 0) {
913
- const uniqueBlocks = new Set(blockNumbers);
914
- sameBlock = uniqueBlocks.size === 1;
915
- blockNumber = sameBlock ? blockNumbers[0] : undefined;
916
- console.log(`📦 [${chainName}] Bundle 区块: blocks=[${[...uniqueBlocks].join(',')}] sameBlock=${sameBlock}`);
917
- }
721
+ return false;
722
+ })();
723
+ if (hasMultipleFromSameWallet) {
724
+ const result = options?.waitConfirmation
725
+ ? await submitDirectToRpcSequential(signedTransactions, config)
726
+ : await submitDirectToRpcSequentialNoWait(signedTransactions, config);
727
+ return { ...result, mode: 'sequential' };
918
728
  }
919
- catch (e) {
920
- console.warn(`⚠️ [${chainName}] Bundle 区块确认超时`);
921
- }
922
- return {
923
- code: true, totalTransactions, successCount, failedCount, txHashes, results,
924
- sameBlock, blockNumber,
925
- blockNumbers: blockNumbers.length > 0 ? blockNumbers : undefined,
926
- simulationDurationMs, broadcastDurationMs,
927
- };
729
+ const result = await submitDirectToRpcParallel(signedTransactions, config);
730
+ return { ...result, mode: 'parallel' };
928
731
  }