four-flap-meme-sdk 2.2.0 → 2.2.2

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 (467) hide show
  1. package/README.en.md +6 -41
  2. package/README.md +0 -31
  3. package/README.zh-CN.md +6 -41
  4. package/dist/chains/bsc/four/approve-tokenmanager.d.ts +26 -1
  5. package/dist/chains/bsc/four/approve-tokenmanager.js +113 -1
  6. package/dist/chains/bsc/four/config.d.ts +67 -5
  7. package/dist/chains/bsc/four/config.js +114 -2
  8. package/dist/chains/bsc/four/core.d.ts +4 -1
  9. package/dist/chains/bsc/four/core.js +592 -1
  10. package/dist/chains/bsc/four/index.d.ts +6 -6
  11. package/dist/chains/bsc/four/index.js +6 -6
  12. package/dist/chains/bsc/four/internal.d.ts +46 -2
  13. package/dist/chains/bsc/four/internal.js +239 -2
  14. package/dist/chains/bsc/four/pancake-proxy.d.ts +28 -1
  15. package/dist/chains/bsc/four/pancake-proxy.js +687 -1
  16. package/dist/chains/bsc/four/private.d.ts +27 -1
  17. package/dist/chains/bsc/four/private.js +477 -1
  18. package/dist/chains/bsc/four/submit.d.ts +315 -2
  19. package/dist/chains/bsc/four/submit.js +752 -2
  20. package/dist/chains/bsc/four/swap-buy-first.d.ts +55 -2
  21. package/dist/chains/bsc/four/swap-buy-first.js +507 -2
  22. package/dist/chains/bsc/four/swap-internal.d.ts +3 -1
  23. package/dist/chains/bsc/four/swap-internal.js +18 -1
  24. package/dist/chains/bsc/four/swap.d.ts +144 -2
  25. package/dist/chains/bsc/four/swap.js +766 -2
  26. package/dist/chains/bsc/four/types.d.ts +476 -1
  27. package/dist/chains/bsc/four/utils.d.ts +18 -5
  28. package/dist/chains/bsc/four/utils.js +1552 -5
  29. package/dist/chains/bsc/pancake/bundle-buy-first.d.ts +91 -1
  30. package/dist/chains/bsc/pancake/bundle-buy-first.js +212 -97
  31. package/dist/chains/bsc/pancake/bundle-swap.d.ts +79 -1
  32. package/dist/chains/bsc/pancake/bundle-swap.js +726 -114
  33. package/dist/chains/bsc/pancake/index.d.ts +2 -4
  34. package/dist/chains/bsc/pancake/index.js +3 -1
  35. package/dist/chains/bsc/platforms/iro/factory.js +1 -3
  36. package/dist/chains/bsc/platforms/iro/index.d.ts +5 -5
  37. package/dist/chains/bsc/platforms/iro/index.js +3 -3
  38. package/dist/chains/bsc/platforms/iro/pool.js +10 -31
  39. package/dist/chains/bsc/platforms/iro/token.js +1 -4
  40. package/dist/chains/eni/batch-router/bundle-approve.js +3 -4
  41. package/dist/chains/eni/batch-router/transfer.js +25 -55
  42. package/dist/chains/eni/batch-router/utils.js +6 -32
  43. package/dist/chains/eni/bundler/sign.js +4 -4
  44. package/dist/chains/eni/bundler/submit.js +4 -1
  45. package/dist/chains/eni/constants.js +1 -1
  46. package/dist/chains/eni/index.d.ts +1 -2
  47. package/dist/chains/eni/index.js +0 -1
  48. package/dist/chains/eni/platforms/daoaas/create.js +2 -2
  49. package/dist/chains/eni/platforms/daoaas/index.d.ts +3 -3
  50. package/dist/chains/eni/platforms/daoaas/index.js +3 -3
  51. package/dist/chains/eni/platforms/daoaas/meta.js +4 -8
  52. package/dist/chains/eni/platforms/daoaas/portal-direct.js +44 -28
  53. package/dist/chains/eni/platforms/daoaas/portal.js +6 -10
  54. package/dist/chains/eni/platforms/dswap/liquidity.js +26 -58
  55. package/dist/chains/eni/platforms/fair-launch/index.d.ts +2 -2
  56. package/dist/chains/eni/platforms/fair-launch/index.js +1 -1
  57. package/dist/chains/eni/platforms/fair-launch/launcher.js +46 -87
  58. package/dist/chains/eni/platforms/fair-launch/pool.js +1 -4
  59. package/dist/chains/eni/platforms/fair-launch/presets.js +2 -2
  60. package/dist/chains/eni/platforms/iro/factory.js +1 -3
  61. package/dist/chains/eni/platforms/iro/index.d.ts +6 -6
  62. package/dist/chains/eni/platforms/iro/index.js +4 -4
  63. package/dist/chains/eni/platforms/iro/pool.js +26 -90
  64. package/dist/chains/eni/platforms/iro/token.js +31 -107
  65. package/dist/chains/eni/platforms/iro/whitelist.js +18 -6
  66. package/dist/chains/index.d.ts +0 -13
  67. package/dist/chains/index.js +0 -13
  68. package/dist/chains/xlayer/eip7702/bundle-approve.d.ts +26 -2
  69. package/dist/chains/xlayer/eip7702/bundle-approve.js +21 -11
  70. package/dist/chains/xlayer/eip7702/bundle-buy.d.ts +6 -2
  71. package/dist/chains/xlayer/eip7702/bundle-buy.js +51 -13
  72. package/dist/chains/xlayer/eip7702/bundle-create.js +59 -93
  73. package/dist/chains/xlayer/eip7702/bundle-sell.d.ts +6 -2
  74. package/dist/chains/xlayer/eip7702/bundle-sell.js +97 -26
  75. package/dist/chains/xlayer/eip7702/bundle-swap.d.ts +65 -3
  76. package/dist/chains/xlayer/eip7702/bundle-swap.js +245 -51
  77. package/dist/chains/xlayer/eip7702/constants.d.ts +16 -1
  78. package/dist/chains/xlayer/eip7702/constants.js +21 -3
  79. package/dist/chains/xlayer/eip7702/index.d.ts +46 -28
  80. package/dist/chains/xlayer/eip7702/index.js +81 -28
  81. package/dist/chains/xlayer/eip7702/multi-hop-transfer.d.ts +203 -2
  82. package/dist/chains/xlayer/eip7702/multi-hop-transfer.js +301 -58
  83. package/dist/chains/xlayer/eip7702/types.d.ts +0 -88
  84. package/dist/chains/xlayer/eip7702/utils.d.ts +3 -0
  85. package/dist/chains/xlayer/eip7702/utils.js +28 -23
  86. package/dist/chains/xlayer/eip7702/volume.d.ts +184 -6
  87. package/dist/chains/xlayer/eip7702/volume.js +158 -83
  88. package/dist/chains/xlayer/eoa/constants.js +1 -1
  89. package/dist/chains/xlayer/eoa/dex-helpers.js +5 -5
  90. package/dist/chains/xlayer/eoa/eoa-bundle-swap.d.ts +95 -1
  91. package/dist/chains/xlayer/eoa/eoa-bundle-swap.js +299 -66
  92. package/dist/chains/xlayer/eoa/eoa-wash-volume.d.ts +1 -1
  93. package/dist/chains/xlayer/eoa/eoa-wash-volume.js +23 -18
  94. package/dist/chains/xlayer/eoa/index.d.ts +6 -10
  95. package/dist/chains/xlayer/eoa/index.js +23 -8
  96. package/dist/chains/xlayer/eoa/portal-ops.js +2 -7
  97. package/dist/chains/xlayer/eoa/router-manager.js +3 -3
  98. package/dist/chains/xlayer/eoa/types.d.ts +2 -2
  99. package/dist/chains/xlayer/eoa/types.js +3 -1
  100. package/dist/chains/xlayer/index.d.ts +2 -3
  101. package/dist/chains/xlayer/index.js +7 -4
  102. package/dist/contracts/helper3.d.ts +5 -20
  103. package/dist/contracts/helper3.js +20 -56
  104. package/dist/contracts/tm-bundle-merkle/approve-tokenmanager.d.ts +26 -1
  105. package/dist/contracts/tm-bundle-merkle/approve-tokenmanager.js +113 -1
  106. package/dist/contracts/tm-bundle-merkle/config.d.ts +67 -5
  107. package/dist/contracts/tm-bundle-merkle/config.js +114 -2
  108. package/dist/contracts/tm-bundle-merkle/core.d.ts +4 -1
  109. package/dist/contracts/tm-bundle-merkle/core.js +591 -1
  110. package/dist/contracts/tm-bundle-merkle/index.d.ts +5 -5
  111. package/dist/contracts/tm-bundle-merkle/index.js +5 -5
  112. package/dist/contracts/tm-bundle-merkle/internal.d.ts +46 -2
  113. package/dist/contracts/tm-bundle-merkle/internal.js +238 -2
  114. package/dist/contracts/tm-bundle-merkle/pancake-proxy.d.ts +28 -1
  115. package/dist/contracts/tm-bundle-merkle/pancake-proxy.js +686 -1
  116. package/dist/contracts/tm-bundle-merkle/private.d.ts +27 -1
  117. package/dist/contracts/tm-bundle-merkle/private.js +476 -1
  118. package/dist/contracts/tm-bundle-merkle/submit.d.ts +314 -3
  119. package/dist/contracts/tm-bundle-merkle/submit.js +928 -3
  120. package/dist/contracts/tm-bundle-merkle/swap-buy-first.d.ts +55 -2
  121. package/dist/contracts/tm-bundle-merkle/swap-buy-first.js +506 -2
  122. package/dist/contracts/tm-bundle-merkle/swap-internal.d.ts +3 -1
  123. package/dist/contracts/tm-bundle-merkle/swap-internal.js +18 -1
  124. package/dist/contracts/tm-bundle-merkle/swap.d.ts +144 -2
  125. package/dist/contracts/tm-bundle-merkle/swap.js +764 -2
  126. package/dist/contracts/tm-bundle-merkle/types.d.ts +476 -1
  127. package/dist/contracts/tm-bundle-merkle/utils.d.ts +18 -6
  128. package/dist/contracts/tm-bundle-merkle/utils.js +1501 -6
  129. package/dist/contracts/tm-bundle.d.ts +51 -3
  130. package/dist/contracts/tm-bundle.js +177 -108
  131. package/dist/contracts/tm.d.ts +2 -3
  132. package/dist/contracts/tm.js +32 -37
  133. package/dist/contracts/tm1.js +4 -9
  134. package/dist/contracts/tm2.js +4 -9
  135. package/dist/dex/direct-router.d.ts +125 -3
  136. package/dist/dex/direct-router.js +666 -237
  137. package/dist/flows/create.d.ts +1 -2
  138. package/dist/flows/create.js +6 -6
  139. package/dist/index.d.ts +85 -20
  140. package/dist/index.js +215 -20
  141. package/dist/shared/abis/TaxToken.json +105 -0
  142. package/dist/shared/abis/TokenManager2.json +60 -0
  143. package/dist/shared/abis/common.d.ts +83 -2
  144. package/dist/shared/abis/common.js +252 -2
  145. package/dist/shared/abis/index.d.ts +6 -5
  146. package/dist/shared/abis/index.js +7 -5
  147. package/dist/shared/clients/blockrazor.js +25 -39
  148. package/dist/shared/clients/club48.d.ts +2 -2
  149. package/dist/shared/clients/club48.js +29 -34
  150. package/dist/shared/clients/emitservice.js +0 -2
  151. package/dist/shared/clients/four.d.ts +5 -5
  152. package/dist/shared/clients/four.js +17 -21
  153. package/dist/shared/clients/merkle.js +34 -27
  154. package/dist/shared/constants/addresses.d.ts +1 -1
  155. package/dist/shared/constants/addresses.js +2 -11
  156. package/dist/shared/constants/chains.d.ts +1 -1
  157. package/dist/shared/constants/chains.js +1 -1
  158. package/dist/shared/constants/gas.d.ts +1 -1
  159. package/dist/shared/constants/gas.js +6 -2
  160. package/dist/shared/constants/index.d.ts +0 -3
  161. package/dist/shared/constants/index.js +0 -1
  162. package/dist/shared/flap/abi.js +1 -1
  163. package/dist/shared/flap/constants.d.ts +2 -1
  164. package/dist/shared/flap/constants.js +3 -2
  165. package/dist/shared/flap/curve.js +0 -3
  166. package/dist/shared/flap/errors.d.ts +4 -1
  167. package/dist/shared/flap/errors.js +1 -20
  168. package/dist/shared/flap/index.d.ts +3 -3
  169. package/dist/shared/flap/index.js +3 -3
  170. package/dist/shared/flap/meta.d.ts +18 -16
  171. package/dist/shared/flap/meta.js +17 -12
  172. package/dist/shared/flap/permit.js +2 -5
  173. package/dist/shared/flap/pinata.d.ts +4 -11
  174. package/dist/shared/flap/pinata.js +16 -21
  175. package/dist/shared/flap/portal-bundle-merkle/config.d.ts +72 -3
  176. package/dist/shared/flap/portal-bundle-merkle/config.js +124 -4
  177. package/dist/shared/flap/portal-bundle-merkle/core.d.ts +4 -0
  178. package/dist/shared/flap/portal-bundle-merkle/core.js +172 -92
  179. package/dist/shared/flap/portal-bundle-merkle/create-to-dex.js +99 -106
  180. package/dist/shared/flap/portal-bundle-merkle/curve-to-dex.js +92 -100
  181. package/dist/shared/flap/portal-bundle-merkle/index.d.ts +7 -11
  182. package/dist/shared/flap/portal-bundle-merkle/index.js +7 -4
  183. package/dist/shared/flap/portal-bundle-merkle/pancake-proxy.js +68 -71
  184. package/dist/shared/flap/portal-bundle-merkle/private.js +114 -61
  185. package/dist/shared/flap/portal-bundle-merkle/swap-buy-first.d.ts +64 -1
  186. package/dist/shared/flap/portal-bundle-merkle/swap-buy-first.js +247 -66
  187. package/dist/shared/flap/portal-bundle-merkle/swap.d.ts +71 -2
  188. package/dist/shared/flap/portal-bundle-merkle/swap.js +410 -103
  189. package/dist/shared/flap/portal-bundle-merkle/types.d.ts +7 -73
  190. package/dist/shared/flap/portal-bundle-merkle/utils.d.ts +80 -1
  191. package/dist/shared/flap/portal-bundle-merkle/utils.js +265 -145
  192. package/dist/shared/flap/portal-bundle.js +56 -55
  193. package/dist/shared/flap/portal.d.ts +3 -1
  194. package/dist/shared/flap/portal.js +25 -32
  195. package/dist/shared/flap/vanity.d.ts +5 -1
  196. package/dist/shared/flap/vanity.js +17 -6
  197. package/dist/shared/flap/vault.d.ts +124 -17
  198. package/dist/shared/flap/vault.js +148 -67
  199. package/dist/shared/four/tax-token.d.ts +1 -1
  200. package/dist/shared/four/tax-token.js +7 -27
  201. package/dist/shared/index.d.ts +0 -6
  202. package/dist/shared/index.js +0 -4
  203. package/dist/utils/airdrop-sweep.d.ts +76 -4
  204. package/dist/utils/airdrop-sweep.js +54 -40
  205. package/dist/utils/bundle-helpers.d.ts +243 -9
  206. package/dist/utils/bundle-helpers.js +584 -10
  207. package/dist/utils/constants.d.ts +61 -5
  208. package/dist/utils/constants.js +80 -5
  209. package/dist/utils/contract-factory.d.ts +4 -2
  210. package/dist/utils/contract-factory.js +18 -25
  211. package/dist/utils/erc20.d.ts +89 -7
  212. package/dist/utils/erc20.js +125 -94
  213. package/dist/utils/errors.d.ts +1 -12
  214. package/dist/utils/errors.js +1 -60
  215. package/dist/utils/holders-maker.d.ts +138 -2
  216. package/dist/utils/holders-maker.js +661 -26
  217. package/dist/utils/lp-inspect.d.ts +112 -2
  218. package/dist/utils/lp-inspect.js +223 -73
  219. package/dist/utils/mpcExclusive.d.ts +5 -2
  220. package/dist/utils/mpcExclusive.js +3 -4
  221. package/dist/utils/private-sale.d.ts +58 -2
  222. package/dist/utils/private-sale.js +15 -4
  223. package/dist/utils/provider-factory.d.ts +0 -4
  224. package/dist/utils/provider-factory.js +0 -10
  225. package/dist/utils/quote-helpers.d.ts +45 -4
  226. package/dist/utils/quote-helpers.js +74 -17
  227. package/dist/utils/stealth-transfer.d.ts +28 -2
  228. package/dist/utils/stealth-transfer.js +15 -31
  229. package/dist/utils/swap-helpers.d.ts +15 -2
  230. package/dist/utils/swap-helpers.js +10 -5
  231. package/dist/utils/wallet.d.ts +25 -2
  232. package/dist/utils/wallet.js +8 -9
  233. package/package.json +4 -159
  234. package/dist/__tests__/subpath-exports.test.d.ts +0 -1
  235. package/dist/__tests__/subpath-exports.test.js +0 -64
  236. package/dist/abis/common.d.ts +0 -85
  237. package/dist/abis/common.js +0 -260
  238. package/dist/abis/contracts/TaxToken.json +0 -969
  239. package/dist/abis/contracts/TokenManager2.json +0 -136
  240. package/dist/abis/contracts/index.d.ts +0 -5
  241. package/dist/abis/contracts/index.js +0 -5
  242. package/dist/abis/flap/index.d.ts +0 -3
  243. package/dist/abis/flap/index.js +0 -3
  244. package/dist/abis/flap/portal-events.d.ts +0 -6
  245. package/dist/abis/flap/portal-events.js +0 -17
  246. package/dist/abis/flap/portal.d.ts +0 -6
  247. package/dist/abis/flap/portal.js +0 -37
  248. package/dist/abis/flap/vault.d.ts +0 -171
  249. package/dist/abis/flap/vault.js +0 -91
  250. package/dist/abis/index.d.ts +0 -8
  251. package/dist/abis/index.js +0 -11
  252. package/dist/bundle-core/__tests__/config-helpers.test.d.ts +0 -1
  253. package/dist/bundle-core/__tests__/config-helpers.test.js +0 -28
  254. package/dist/bundle-core/__tests__/facade-parity.test.d.ts +0 -1
  255. package/dist/bundle-core/__tests__/facade-parity.test.js +0 -33
  256. package/dist/bundle-core/__tests__/sign-context-helpers.test.d.ts +0 -1
  257. package/dist/bundle-core/__tests__/sign-context-helpers.test.js +0 -60
  258. package/dist/bundle-core/__tests__/sign-fixture.test.d.ts +0 -1
  259. package/dist/bundle-core/__tests__/sign-fixture.test.js +0 -220
  260. package/dist/bundle-core/__tests__/sign-fixtures.d.ts +0 -10
  261. package/dist/bundle-core/__tests__/sign-fixtures.js +0 -16
  262. package/dist/bundle-core/config-helpers.d.ts +0 -36
  263. package/dist/bundle-core/config-helpers.js +0 -57
  264. package/dist/bundle-core/errors.d.ts +0 -50
  265. package/dist/bundle-core/errors.js +0 -34
  266. package/dist/bundle-core/four-meme/approve-tokenmanager.d.ts +0 -7
  267. package/dist/bundle-core/four-meme/approve-tokenmanager.js +0 -99
  268. package/dist/bundle-core/four-meme/core-helpers.d.ts +0 -8
  269. package/dist/bundle-core/four-meme/core-helpers.js +0 -40
  270. package/dist/bundle-core/four-meme/core.d.ts +0 -4
  271. package/dist/bundle-core/four-meme/core.js +0 -515
  272. package/dist/bundle-core/four-meme/pancake-proxy.d.ts +0 -28
  273. package/dist/bundle-core/four-meme/pancake-proxy.js +0 -679
  274. package/dist/bundle-core/four-meme/private.d.ts +0 -27
  275. package/dist/bundle-core/four-meme/private.js +0 -465
  276. package/dist/bundle-core/four-meme/sign-context-helpers.d.ts +0 -2
  277. package/dist/bundle-core/four-meme/sign-context-helpers.js +0 -2
  278. package/dist/bundle-core/four-meme/swap-buy-first.d.ts +0 -8
  279. package/dist/bundle-core/four-meme/swap-buy-first.js +0 -493
  280. package/dist/bundle-core/four-meme/swap-hop-helpers.d.ts +0 -6
  281. package/dist/bundle-core/four-meme/swap-hop-helpers.js +0 -63
  282. package/dist/bundle-core/four-meme/swap-internal.d.ts +0 -3
  283. package/dist/bundle-core/four-meme/swap-internal.js +0 -18
  284. package/dist/bundle-core/four-meme/swap-sign-helpers.d.ts +0 -27
  285. package/dist/bundle-core/four-meme/swap-sign-helpers.js +0 -105
  286. package/dist/bundle-core/four-meme/swap.d.ts +0 -17
  287. package/dist/bundle-core/four-meme/swap.js +0 -505
  288. package/dist/bundle-core/four-meme/types/buy-first.d.ts +0 -50
  289. package/dist/bundle-core/four-meme/types/buy-first.js +0 -1
  290. package/dist/bundle-core/four-meme/types/core-flow.d.ts +0 -63
  291. package/dist/bundle-core/four-meme/types/core-flow.js +0 -1
  292. package/dist/bundle-core/four-meme/types/index.d.ts +0 -600
  293. package/dist/bundle-core/four-meme/types/index.js +0 -1
  294. package/dist/bundle-core/four-meme/types/swap-internal.d.ts +0 -19
  295. package/dist/bundle-core/four-meme/types/swap-internal.js +0 -1
  296. package/dist/bundle-core/four-meme/types.d.ts +0 -1
  297. package/dist/bundle-core/four-meme/types.js +0 -1
  298. package/dist/bundle-core/four-meme/utils-disperse.d.ts +0 -7
  299. package/dist/bundle-core/four-meme/utils-disperse.js +0 -396
  300. package/dist/bundle-core/four-meme/utils-pairwise.d.ts +0 -8
  301. package/dist/bundle-core/four-meme/utils-pairwise.js +0 -328
  302. package/dist/bundle-core/four-meme/utils-sweep.d.ts +0 -8
  303. package/dist/bundle-core/four-meme/utils-sweep.js +0 -744
  304. package/dist/bundle-core/index.d.ts +0 -8
  305. package/dist/bundle-core/index.js +0 -8
  306. package/dist/bundle-core/internal.d.ts +0 -21
  307. package/dist/bundle-core/internal.js +0 -182
  308. package/dist/bundle-core/sign-context-helpers.d.ts +0 -25
  309. package/dist/bundle-core/sign-context-helpers.js +0 -67
  310. package/dist/bundle-core/submit.d.ts +0 -293
  311. package/dist/bundle-core/submit.js +0 -727
  312. package/dist/bundle-core/types/index.d.ts +0 -8
  313. package/dist/bundle-core/types/index.js +0 -1
  314. package/dist/bundle-core/types.d.ts +0 -1
  315. package/dist/bundle-core/types.js +0 -1
  316. package/dist/chains/bsc/four/utils-disperse.d.ts +0 -1
  317. package/dist/chains/bsc/four/utils-disperse.js +0 -1
  318. package/dist/chains/bsc/four/utils-pairwise.d.ts +0 -1
  319. package/dist/chains/bsc/four/utils-pairwise.js +0 -1
  320. package/dist/chains/bsc/four/utils-sweep.d.ts +0 -1
  321. package/dist/chains/bsc/four/utils-sweep.js +0 -1
  322. package/dist/chains/bsc/iro.d.ts +0 -5
  323. package/dist/chains/bsc/iro.js +0 -4
  324. package/dist/chains/bsc/pancake/bundle-buy-first-helpers.d.ts +0 -159
  325. package/dist/chains/bsc/pancake/bundle-buy-first-helpers.js +0 -117
  326. package/dist/chains/bsc/pancake/bundle-swap-helpers.d.ts +0 -241
  327. package/dist/chains/bsc/pancake/bundle-swap-helpers.js +0 -565
  328. package/dist/chains/eni/flat-aliases.d.ts +0 -10
  329. package/dist/chains/eni/flat-aliases.js +0 -8
  330. package/dist/chains/eni/submit.d.ts +0 -43
  331. package/dist/chains/eni/submit.js +0 -286
  332. package/dist/chains/xlayer/eip7702/flat-aliases.d.ts +0 -13
  333. package/dist/chains/xlayer/eip7702/flat-aliases.js +0 -10
  334. package/dist/chains/xlayer/eip7702/multi-hop-transfer-helpers.d.ts +0 -79
  335. package/dist/chains/xlayer/eip7702/multi-hop-transfer-helpers.js +0 -1
  336. package/dist/chains/xlayer/eip7702/transfer-context-helpers.d.ts +0 -26
  337. package/dist/chains/xlayer/eip7702/transfer-context-helpers.js +0 -57
  338. package/dist/chains/xlayer/eip7702/volume-helpers.d.ts +0 -148
  339. package/dist/chains/xlayer/eip7702/volume-helpers.js +0 -48
  340. package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.d.ts +0 -126
  341. package/dist/chains/xlayer/eoa/eoa-bundle-swap-helpers.js +0 -228
  342. package/dist/contracts/tm-bundle-helpers.d.ts +0 -88
  343. package/dist/contracts/tm-bundle-helpers.js +0 -72
  344. package/dist/contracts/tm-bundle-merkle/utils-disperse.d.ts +0 -1
  345. package/dist/contracts/tm-bundle-merkle/utils-disperse.js +0 -1
  346. package/dist/contracts/tm-bundle-merkle/utils-pairwise.d.ts +0 -1
  347. package/dist/contracts/tm-bundle-merkle/utils-pairwise.js +0 -1
  348. package/dist/contracts/tm-bundle-merkle/utils-sweep.d.ts +0 -1
  349. package/dist/contracts/tm-bundle-merkle/utils-sweep.js +0 -1
  350. package/dist/dex/direct-router-helpers.d.ts +0 -264
  351. package/dist/dex/direct-router-helpers.js +0 -539
  352. package/dist/dex/types.d.ts +0 -81
  353. package/dist/dex/types.js +0 -1
  354. package/dist/exports/root-bundle-and-tooling.d.ts +0 -27
  355. package/dist/exports/root-bundle-and-tooling.js +0 -30
  356. package/dist/exports/root-eni-and-bsc-iro.d.ts +0 -26
  357. package/dist/exports/root-eni-and-bsc-iro.js +0 -66
  358. package/dist/exports/root-foundations.d.ts +0 -35
  359. package/dist/exports/root-foundations.js +0 -70
  360. package/dist/exports/root-swap-dex-and-xlayer.d.ts +0 -30
  361. package/dist/exports/root-swap-dex-and-xlayer.js +0 -78
  362. package/dist/flap/index.d.ts +0 -10
  363. package/dist/flap/index.js +0 -8
  364. package/dist/flows/index.d.ts +0 -1
  365. package/dist/flows/index.js +0 -1
  366. package/dist/merkle/index.d.ts +0 -12
  367. package/dist/merkle/index.js +0 -11
  368. package/dist/shared/clients/index.d.ts +0 -8
  369. package/dist/shared/clients/index.js +0 -8
  370. package/dist/shared/constants/quote.d.ts +0 -30
  371. package/dist/shared/constants/quote.js +0 -37
  372. package/dist/shared/flap/portal-bundle-merkle/core-helpers.d.ts +0 -32
  373. package/dist/shared/flap/portal-bundle-merkle/core-helpers.js +0 -83
  374. package/dist/shared/flap/portal-bundle-merkle/swap-buy-first-helpers.d.ts +0 -125
  375. package/dist/shared/flap/portal-bundle-merkle/swap-buy-first-helpers.js +0 -113
  376. package/dist/shared/flap/portal-bundle-merkle/swap-helpers.d.ts +0 -149
  377. package/dist/shared/flap/portal-bundle-merkle/swap-helpers.js +0 -259
  378. package/dist/shared/foundation/dex/v3-path.d.ts +0 -6
  379. package/dist/shared/foundation/dex/v3-path.js +0 -35
  380. package/dist/shared/foundation/gas/bundle-gas.d.ts +0 -39
  381. package/dist/shared/foundation/gas/bundle-gas.js +0 -93
  382. package/dist/shared/foundation/gas/profit-hop.d.ts +0 -20
  383. package/dist/shared/foundation/gas/profit-hop.js +0 -72
  384. package/dist/shared/foundation/index.d.ts +0 -13
  385. package/dist/shared/foundation/index.js +0 -12
  386. package/dist/shared/foundation/nonce/nonce-manager.d.ts +0 -17
  387. package/dist/shared/foundation/nonce/nonce-manager.js +0 -180
  388. package/dist/shared/foundation/normalize-unknown.d.ts +0 -9
  389. package/dist/shared/foundation/normalize-unknown.js +0 -29
  390. package/dist/shared/foundation/sdk-logger.d.ts +0 -13
  391. package/dist/shared/foundation/sdk-logger.js +0 -12
  392. package/dist/shared/foundation/tx/build-request.d.ts +0 -17
  393. package/dist/shared/foundation/tx/build-request.js +0 -25
  394. package/dist/shared/foundation/tx/sign-batch.d.ts +0 -5
  395. package/dist/shared/foundation/tx/sign-batch.js +0 -26
  396. package/dist/shared/foundation/tx/wallet-sign-patch.d.ts +0 -1
  397. package/dist/shared/foundation/tx/wallet-sign-patch.js +0 -18
  398. package/dist/shared/foundation/types/airdrop-sweep.d.ts +0 -79
  399. package/dist/shared/foundation/types/airdrop-sweep.js +0 -1
  400. package/dist/shared/foundation/types/erc20.d.ts +0 -65
  401. package/dist/shared/foundation/types/erc20.js +0 -1
  402. package/dist/shared/foundation/types/holders-maker.d.ts +0 -64
  403. package/dist/shared/foundation/types/holders-maker.js +0 -1
  404. package/dist/shared/foundation/types/index.d.ts +0 -7
  405. package/dist/shared/foundation/types/index.js +0 -1
  406. package/dist/shared/foundation/types/lp-inspect.d.ts +0 -102
  407. package/dist/shared/foundation/types/lp-inspect.js +0 -1
  408. package/dist/shared/foundation/types/multicall.d.ts +0 -5
  409. package/dist/shared/foundation/types/multicall.js +0 -1
  410. package/dist/shared/foundation/types/private-sale.d.ts +0 -35
  411. package/dist/shared/foundation/types/private-sale.js +0 -1
  412. package/dist/shared/foundation/types/quote-helpers.d.ts +0 -17
  413. package/dist/shared/foundation/types/quote-helpers.js +0 -1
  414. package/dist/types/errors.d.ts +0 -27
  415. package/dist/types/errors.js +0 -34
  416. package/dist/utils/holders-maker/addresses.d.ts +0 -12
  417. package/dist/utils/holders-maker/addresses.js +0 -15
  418. package/dist/utils/holders-maker/buy-tx.d.ts +0 -44
  419. package/dist/utils/holders-maker/buy-tx.js +0 -278
  420. package/dist/utils/holders-maker/constants.d.ts +0 -6
  421. package/dist/utils/holders-maker/constants.js +0 -7
  422. package/dist/utils/holders-maker/disperse.d.ts +0 -18
  423. package/dist/utils/holders-maker/disperse.js +0 -90
  424. package/dist/utils/holders-maker/routing.d.ts +0 -4
  425. package/dist/utils/holders-maker/routing.js +0 -45
  426. package/dist/utils/holders-maker/transfer-tx.d.ts +0 -4
  427. package/dist/utils/holders-maker/transfer-tx.js +0 -67
  428. package/dist/utils/holders-maker-helpers.d.ts +0 -9
  429. package/dist/utils/holders-maker-helpers.js +0 -9
  430. package/dist/utils/hop-chains.d.ts +0 -35
  431. package/dist/utils/hop-chains.js +0 -215
  432. package/dist/utils/lp-inspect-helpers.d.ts +0 -9
  433. package/dist/utils/lp-inspect-helpers.js +0 -109
  434. package/dist/utils/types/airdrop-sweep.d.ts +0 -1
  435. package/dist/utils/types/airdrop-sweep.js +0 -1
  436. package/dist/utils/types/contract-factory.d.ts +0 -1
  437. package/dist/utils/types/contract-factory.js +0 -1
  438. package/dist/utils/types/erc20.d.ts +0 -1
  439. package/dist/utils/types/erc20.js +0 -1
  440. package/dist/utils/types/errors.d.ts +0 -1
  441. package/dist/utils/types/errors.js +0 -1
  442. package/dist/utils/types/holders-maker.d.ts +0 -1
  443. package/dist/utils/types/holders-maker.js +0 -1
  444. package/dist/utils/types/hop-chains.d.ts +0 -8
  445. package/dist/utils/types/hop-chains.js +0 -1
  446. package/dist/utils/types/index.d.ts +0 -13
  447. package/dist/utils/types/index.js +0 -1
  448. package/dist/utils/types/lp-inspect.d.ts +0 -1
  449. package/dist/utils/types/lp-inspect.js +0 -1
  450. package/dist/utils/types/mpc-exclusive.d.ts +0 -5
  451. package/dist/utils/types/mpc-exclusive.js +0 -1
  452. package/dist/utils/types/private-sale.d.ts +0 -1
  453. package/dist/utils/types/private-sale.js +0 -1
  454. package/dist/utils/types/quote-helpers.d.ts +0 -1
  455. package/dist/utils/types/quote-helpers.js +0 -1
  456. package/dist/utils/types/stealth-transfer.d.ts +0 -44
  457. package/dist/utils/types/stealth-transfer.js +0 -1
  458. package/dist/utils/types/wallet.d.ts +0 -25
  459. package/dist/utils/types/wallet.js +0 -1
  460. package/dist/vanity/index.d.ts +0 -5
  461. package/dist/vanity/index.js +0 -5
  462. package/src/abis/contracts/TaxToken.json +0 -969
  463. package/src/abis/contracts/TokenManager.json +0 -836
  464. package/src/abis/contracts/TokenManager2.json +0 -136
  465. package/src/abis/contracts/TokenManagerHelper3.json +0 -993
  466. /package/dist/{abis/contracts → shared/abis}/TokenManager.json +0 -0
  467. /package/dist/{abis/contracts → shared/abis}/TokenManagerHelper3.json +0 -0
@@ -1,3 +1,928 @@
1
- /** Bundle 提交 — 实现见 bundle-core/submit;ENI 见 chains/eni/submit */
2
- export { submitBundleToMerkle, submitMultipleBundles, submitMultipleBundlesParallel, submitBundleToBlockRazor, submitMultipleBundlesToBlockRazor, submitMultipleBundlesToBlockRazorParallel, submitDirectToRpc, submitDirectToRpcSequential, submitDirectToRpcSequentialNoWait, submitDirectToRpcParallel, submitDirectToRpcSmart, } from '../../bundle-core/submit.js';
3
- export { submitBundleToEni, submitEniParallelThenProfit, } from '../../chains/eni/submit.js';
1
+ /**
2
+ * 独立的Bundle提交方法
3
+ *
4
+ * 用于服务器端接收前端构建的签名交易后,提交到Merkle或BlockRazor
5
+ * 以及 Monad 等不支持 Bundle 的链的逐笔广播
6
+ */
7
+ import { MerkleClient } from '../../shared/clients/merkle.js';
8
+ import { BlockRazorClient } from '../../shared/clients/blockrazor.js';
9
+ import { ethers } from 'ethers';
10
+ // ✅ MerkleClient 缓存(复用连接,减少初始化开销)
11
+ const merkleClientCache = new Map();
12
+ const CLIENT_CACHE_TTL_MS = 60 * 1000; // 60秒缓存
13
+ /**
14
+ * 获取或创建 MerkleClient(带缓存)
15
+ */
16
+ function getMerkleClient(config) {
17
+ const cacheKey = `${config.apiKey}-${config.chainId ?? 56}-${config.customRpcUrl || ''}`;
18
+ const now = Date.now();
19
+ const cached = merkleClientCache.get(cacheKey);
20
+ if (cached && cached.expireAt > now) {
21
+ return cached.client;
22
+ }
23
+ // 创建新客户端并缓存
24
+ const client = new MerkleClient({
25
+ apiKey: config.apiKey,
26
+ chainId: config.chainId ?? 56,
27
+ customRpcUrl: config.customRpcUrl
28
+ });
29
+ merkleClientCache.set(cacheKey, { client, expireAt: now + CLIENT_CACHE_TTL_MS });
30
+ return client;
31
+ }
32
+ /**
33
+ * 提交已签名的交易到Merkle(服务器端使用)
34
+ *
35
+ * 这个方法接收前端构建和签名好的交易,直接提交到Merkle服务
36
+ *
37
+ * @param signedTransactions 签名后的交易数组
38
+ * @param config Merkle提交配置(精简版,只需要提交相关参数)
39
+ * @returns Bundle提交结果
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * // 服务器端代码
44
+ * import { submitBundleToMerkle } from 'four-flap-meme-sdk';
45
+ *
46
+ * const result = await submitBundleToMerkle(signedTransactions, {
47
+ * apiKey: process.env.MERKLE_API_KEY,
48
+ * customRpcUrl: process.env.MERKLE_RPC_URL,
49
+ * bundleBlockOffset: 5
50
+ * });
51
+ *
52
+ * if (result.code) {
53
+ * } else {
54
+ * console.error('❌ Bundle提交失败:', result.error);
55
+ * }
56
+ * ```
57
+ */
58
+ export async function submitBundleToMerkle(signedTransactions, config) {
59
+ try {
60
+ const totalTransactions = signedTransactions?.length ?? 0;
61
+ // 验证输入
62
+ if (!signedTransactions || signedTransactions.length === 0) {
63
+ return {
64
+ code: false,
65
+ totalTransactions,
66
+ error: 'signedTransactions cannot be empty'
67
+ };
68
+ }
69
+ if (!config.apiKey) {
70
+ return {
71
+ code: false,
72
+ totalTransactions,
73
+ error: 'apiKey is required in config'
74
+ };
75
+ }
76
+ // ✅ 使用缓存的 MerkleClient(复用连接 + 区块号缓存)
77
+ const merkle = getMerkleClient(config);
78
+ // 提交Bundle
79
+ const bundleResult = await merkle.sendBundle({
80
+ transactions: signedTransactions,
81
+ blockOffset: config.bundleBlockOffset ?? 3,
82
+ minBlockOffset: config.minBlockOffset ?? 3,
83
+ autoRetry: config.autoRetryBundle ?? false,
84
+ maxRetries: config.maxBundleRetries ?? 2
85
+ });
86
+ // ✅ 提交成功
87
+ return {
88
+ code: true,
89
+ totalTransactions,
90
+ bundleHash: bundleResult.bundleHash,
91
+ txHashes: bundleResult.txHashes,
92
+ targetBlock: bundleResult.targetBlock,
93
+ txCount: bundleResult.txCount
94
+ };
95
+ }
96
+ catch (error) {
97
+ // ❌ 提交失败
98
+ return {
99
+ code: false,
100
+ totalTransactions: signedTransactions?.length ?? 0,
101
+ error: error?.message || String(error)
102
+ };
103
+ }
104
+ }
105
+ /**
106
+ * 批量提交多个Bundle到Merkle(顺序执行)
107
+ *
108
+ * @param bundles 多个Bundle的签名交易数组
109
+ * @param config Merkle提交配置
110
+ * @returns Bundle提交结果数组
111
+ */
112
+ 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;
119
+ }
120
+ /**
121
+ * 并行提交多个Bundle到Merkle(适用于独立的Bundle)
122
+ *
123
+ * @param bundles 多个Bundle的签名交易数组
124
+ * @param config Merkle提交配置
125
+ * @returns Bundle提交结果数组
126
+ */
127
+ export async function submitMultipleBundlesParallel(bundles, config) {
128
+ const promises = bundles.map(signedTransactions => submitBundleToMerkle(signedTransactions, config));
129
+ return await Promise.all(promises);
130
+ }
131
+ // ==================== BlockRazor Bundle 提交方法 ====================
132
+ // ✅ BlockRazorClient 缓存(复用连接,减少初始化开销)
133
+ const blockRazorClientCache = new Map();
134
+ /**
135
+ * 获取或创建 BlockRazorClient(带缓存)
136
+ */
137
+ function getBlockRazorClient(config) {
138
+ const cacheKey = `${config.apiKey || 'default'}-${config.customRpcUrl || ''}-${config.builderRpcUrl || ''}`;
139
+ const now = Date.now();
140
+ const cached = blockRazorClientCache.get(cacheKey);
141
+ if (cached && cached.expireAt > now) {
142
+ return cached.client;
143
+ }
144
+ // 创建新客户端并缓存
145
+ const client = new BlockRazorClient({
146
+ apiKey: config.apiKey,
147
+ chainId: 56, // BlockRazor 目前只支持 BSC
148
+ customRpcUrl: config.customRpcUrl,
149
+ builderRpcUrl: config.builderRpcUrl
150
+ });
151
+ blockRazorClientCache.set(cacheKey, { client, expireAt: now + CLIENT_CACHE_TTL_MS });
152
+ return client;
153
+ }
154
+ /**
155
+ * 提交已签名的交易到 BlockRazor(服务器端使用)
156
+ *
157
+ * BlockRazor 是 BSC 链的 Block Builder 服务,支持 Bundle 提交
158
+ *
159
+ * 特点:
160
+ * - 向 Builder EOA 转账 BNB 可提高优先级
161
+ * - 支持 Bundle 合并提高打包率
162
+ * - 最低 Gas Price 要求: 0.05 Gwei
163
+ *
164
+ * @param signedTransactions 签名后的交易数组
165
+ * @param config BlockRazor 提交配置
166
+ * @returns Bundle 提交结果
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * // 服务器端代码
171
+ * import { submitBundleToBlockRazor } from 'four-flap-meme-sdk';
172
+ *
173
+ * const result = await submitBundleToBlockRazor(signedTransactions, {
174
+ * blockOffset: 10,
175
+ * noMerge: false, // 允许合并
176
+ * autoRetry: true
177
+ * });
178
+ *
179
+ * if (result.code) {
180
+ * } else {
181
+ * console.error('❌ Bundle 提交失败:', result.error);
182
+ * }
183
+ * ```
184
+ */
185
+ export async function submitBundleToBlockRazor(signedTransactions, config) {
186
+ try {
187
+ const totalTransactions = signedTransactions?.length ?? 0;
188
+ // 验证输入
189
+ if (!signedTransactions || signedTransactions.length === 0) {
190
+ return {
191
+ code: false,
192
+ totalTransactions,
193
+ error: 'signedTransactions cannot be empty'
194
+ };
195
+ }
196
+ // ✅ 使用缓存的 BlockRazorClient
197
+ const client = getBlockRazorClient(config);
198
+ // 提交 Bundle
199
+ const bundleResult = await client.sendBundle({
200
+ transactions: signedTransactions,
201
+ blockOffset: config.blockOffset ?? 100,
202
+ maxBlockOffset: config.maxBlockOffset ?? 100,
203
+ noMerge: config.noMerge ?? false,
204
+ revertingTxHashes: config.revertingTxHashes,
205
+ autoRetry: config.autoRetry ?? false,
206
+ maxRetries: config.maxRetries ?? 3
207
+ });
208
+ // ✅ 提交成功
209
+ return {
210
+ code: true,
211
+ totalTransactions,
212
+ bundleHash: bundleResult.bundleHash,
213
+ txHashes: bundleResult.txHashes,
214
+ maxBlockNumber: bundleResult.maxBlockNumber,
215
+ txCount: bundleResult.txCount
216
+ };
217
+ }
218
+ catch (error) {
219
+ // ❌ 提交失败
220
+ return {
221
+ code: false,
222
+ totalTransactions: signedTransactions?.length ?? 0,
223
+ error: error?.message || String(error)
224
+ };
225
+ }
226
+ }
227
+ /**
228
+ * 批量提交多个 Bundle 到 BlockRazor(顺序执行)
229
+ *
230
+ * @param bundles 多个 Bundle 的签名交易数组
231
+ * @param config BlockRazor 提交配置
232
+ * @returns Bundle 提交结果数组
233
+ */
234
+ 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;
241
+ }
242
+ /**
243
+ * 并行提交多个 Bundle 到 BlockRazor(适用于独立的 Bundle)
244
+ *
245
+ * @param bundles 多个 Bundle 的签名交易数组
246
+ * @param config BlockRazor 提交配置
247
+ * @returns Bundle 提交结果数组
248
+ */
249
+ export async function submitMultipleBundlesToBlockRazorParallel(bundles, config) {
250
+ const promises = bundles.map(signedTransactions => submitBundleToBlockRazor(signedTransactions, config));
251
+ return await Promise.all(promises);
252
+ }
253
+ function shouldTreatBroadcastErrorAsMaybeSent(msg) {
254
+ const m = String(msg || '').toLowerCase();
255
+ return (m.includes('already known') ||
256
+ m.includes('known transaction') ||
257
+ m.includes('already exists') ||
258
+ m.includes('nonce too low') ||
259
+ m.includes('nonce has already been used') ||
260
+ m.includes('nonce expired') ||
261
+ m.includes('replacement transaction underpriced'));
262
+ }
263
+ async function recoverTxHashIfAlreadySeen(provider, signedTx, errorMessage) {
264
+ if (!shouldTreatBroadcastErrorAsMaybeSent(errorMessage))
265
+ return undefined;
266
+ try {
267
+ const hash = ethers.keccak256(signedTx);
268
+ if (!hash)
269
+ return undefined;
270
+ const tx = await provider.getTransaction(hash);
271
+ return tx ? hash : undefined;
272
+ }
273
+ catch {
274
+ return undefined;
275
+ }
276
+ }
277
+ /**
278
+ * 并行广播到 RPC(用于不支持 Bundle 的链,如 Monad)
279
+ *
280
+ * ✅ 优化:默认使用并行广播,速度更快
281
+ *
282
+ * @param signedTransactions 签名后的交易数组
283
+ * @param config 直接广播配置
284
+ * @returns 广播结果
285
+ *
286
+ * @example
287
+ * ```typescript
288
+ * // 服务器端代码(Monad 链)
289
+ * import { submitDirectToRpc } from 'four-flap-meme-sdk';
290
+ *
291
+ * const result = await submitDirectToRpc(signedTransactions, {
292
+ * rpcUrl: 'https://rpc-mainnet.monadinfra.com',
293
+ * chainId: 143,
294
+ * chainName: 'MONAD'
295
+ * });
296
+ *
297
+ * if (result.code) {
298
+ * } else {
299
+ * console.error('❌ 全部广播失败:', result.errorSummary);
300
+ * }
301
+ * ```
302
+ */
303
+ export async function submitDirectToRpc(signedTransactions, config) {
304
+ const totalTransactions = signedTransactions?.length ?? 0;
305
+ // 验证输入
306
+ if (!signedTransactions || signedTransactions.length === 0) {
307
+ return {
308
+ code: false,
309
+ totalTransactions: 0,
310
+ successCount: 0,
311
+ failedCount: 0,
312
+ txHashes: [],
313
+ results: [],
314
+ errorSummary: 'signedTransactions cannot be empty'
315
+ };
316
+ }
317
+ if (!config.rpcUrl) {
318
+ return {
319
+ code: false,
320
+ totalTransactions,
321
+ successCount: 0,
322
+ failedCount: totalTransactions,
323
+ txHashes: [],
324
+ results: [],
325
+ errorSummary: 'rpcUrl is required in config'
326
+ };
327
+ }
328
+ const chainId = config.chainId ?? 143;
329
+ const chainName = config.chainName ?? 'MONAD';
330
+ // 创建 Provider
331
+ const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
332
+ chainId,
333
+ name: chainName
334
+ });
335
+ // ✅ 并行广播所有交易
336
+ const broadcastPromises = signedTransactions.map(async (signedTx, i) => {
337
+ try {
338
+ const txResponse = await provider.broadcastTransaction(signedTx);
339
+ // 如果需要等待确认
340
+ if (config.waitForConfirmation) {
341
+ try {
342
+ const receipt = await provider.waitForTransaction(txResponse.hash, 1, config.confirmationTimeout ?? 30000);
343
+ if (receipt && receipt.status === 0) {
344
+ console.warn(`⚠️ [${chainName}] 交易 ${txResponse.hash} 执行失败(已上链但状态为0)`);
345
+ }
346
+ }
347
+ catch (waitError) {
348
+ console.warn(`⚠️ [${chainName}] 等待交易确认超时: ${txResponse.hash}`);
349
+ }
350
+ }
351
+ return {
352
+ index: i,
353
+ success: true,
354
+ txHash: txResponse.hash
355
+ };
356
+ }
357
+ catch (error) {
358
+ const errorMessage = error?.message || String(error);
359
+ console.error(`❌ [${chainName}] 交易 ${i + 1}/${totalTransactions} 广播失败:`, errorMessage);
360
+ // ✅ 兼容:nonce too low / already known 等情况下,交易可能已经被接收
361
+ const recovered = await recoverTxHashIfAlreadySeen(provider, signedTx, errorMessage);
362
+ if (recovered) {
363
+ if (config.waitForConfirmation) {
364
+ try {
365
+ await provider.waitForTransaction(recovered, 1, config.confirmationTimeout ?? 30000);
366
+ }
367
+ catch { }
368
+ }
369
+ return { index: i, success: true, txHash: recovered, error: errorMessage };
370
+ }
371
+ return {
372
+ index: i,
373
+ success: false,
374
+ error: errorMessage
375
+ };
376
+ }
377
+ });
378
+ const results = await Promise.all(broadcastPromises);
379
+ // 按索引排序结果
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}`);
383
+ const successCount = txHashes.length;
384
+ const failedCount = totalTransactions - successCount;
385
+ return {
386
+ code: successCount > 0,
387
+ totalTransactions,
388
+ successCount,
389
+ failedCount,
390
+ txHashes,
391
+ results,
392
+ errorSummary: errors.length > 0 ? errors.join('; ') : undefined
393
+ };
394
+ }
395
+ /**
396
+ * ✅ 顺序广播并等待确认(用于多跳交易等需要顺序执行的场景)
397
+ *
398
+ * 每笔交易广播后会等待上链确认,确保后续交易能正确执行
399
+ *
400
+ * ⚠️ 多跳场景:如果某笔交易失败,会立即停止(因为后续交易肯定也会失败)
401
+ *
402
+ * @param signedTransactions 签名后的交易数组
403
+ * @param config 直接广播配置
404
+ * @returns 广播结果
405
+ */
406
+ export async function submitDirectToRpcSequential(signedTransactions, config) {
407
+ const totalTransactions = signedTransactions?.length ?? 0;
408
+ if (!signedTransactions || signedTransactions.length === 0) {
409
+ return {
410
+ code: false,
411
+ totalTransactions: 0,
412
+ successCount: 0,
413
+ failedCount: 0,
414
+ txHashes: [],
415
+ results: [],
416
+ errorSummary: 'signedTransactions cannot be empty'
417
+ };
418
+ }
419
+ if (!config.rpcUrl) {
420
+ return {
421
+ code: false,
422
+ totalTransactions,
423
+ successCount: 0,
424
+ failedCount: totalTransactions,
425
+ txHashes: [],
426
+ results: [],
427
+ errorSummary: 'rpcUrl is required in config'
428
+ };
429
+ }
430
+ const chainId = config.chainId ?? 143;
431
+ const chainName = config.chainName ?? 'MONAD';
432
+ // ✅ XLayer 链默认 120 秒超时(网络可能较慢)
433
+ const confirmationTimeout = config.confirmationTimeout ?? (chainId === 196 ? 120000 : 60000);
434
+ const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
435
+ chainId,
436
+ name: chainName
437
+ });
438
+ const results = [];
439
+ const txHashes = [];
440
+ const errors = [];
441
+ console.log(`📤 [${chainName}] 开始顺序广播 ${totalTransactions} 笔交易(等待每笔确认)`);
442
+ // 顺序广播并等待确认
443
+ for (let i = 0; i < signedTransactions.length; i++) {
444
+ const signedTx = signedTransactions[i];
445
+ try {
446
+ // 广播交易
447
+ const txResponse = await provider.broadcastTransaction(signedTx);
448
+ console.log(`📡 [${chainName}] 交易 ${i + 1}/${totalTransactions} 广播成功: ${txResponse.hash},等待确认...`);
449
+ // ✅ 等待交易确认
450
+ const receipt = await provider.waitForTransaction(txResponse.hash, 1, // 等待1个确认
451
+ confirmationTimeout);
452
+ if (receipt && receipt.status === 1) {
453
+ console.log(`✅ [${chainName}] 交易 ${i + 1}/${totalTransactions} 已确认: ${txResponse.hash}`);
454
+ results.push({
455
+ index: i,
456
+ success: true,
457
+ txHash: txResponse.hash
458
+ });
459
+ txHashes.push(txResponse.hash);
460
+ }
461
+ else {
462
+ const errorMsg = `交易执行失败(status=${receipt?.status})`;
463
+ console.error(`❌ [${chainName}] 交易 ${i + 1}/${totalTransactions} 上链失败: ${errorMsg}`);
464
+ results.push({
465
+ index: i,
466
+ success: false,
467
+ txHash: txResponse.hash,
468
+ error: errorMsg
469
+ });
470
+ errors.push(`交易 ${i + 1}: ${errorMsg}`);
471
+ // ✅ 多跳场景:如果某笔失败,后续交易肯定也会失败,立即停止
472
+ console.warn(`⚠️ [${chainName}] 多跳模式检测到失败,停止后续 ${totalTransactions - i - 1} 笔交易`);
473
+ break;
474
+ }
475
+ }
476
+ catch (error) {
477
+ const errorMessage = error?.message || String(error);
478
+ console.error(`❌ [${chainName}] 交易 ${i + 1}/${totalTransactions} 广播/确认失败:`, errorMessage);
479
+ // ✅ 兼容:nonce too low / already known 等情况下,交易可能已经被接收
480
+ const recovered = await recoverTxHashIfAlreadySeen(provider, signedTx, errorMessage);
481
+ if (recovered) {
482
+ console.log(`🔄 [${chainName}] 交易 ${i + 1} 可能已广播,尝试等待确认: ${recovered}`);
483
+ // 顺序模式依赖确认:尽量等待一下
484
+ try {
485
+ const receipt = await provider.waitForTransaction(recovered, 1, confirmationTimeout);
486
+ if (receipt && receipt.status === 1) {
487
+ console.log(`✅ [${chainName}] 交易 ${i + 1}/${totalTransactions} 恢复成功: ${recovered}`);
488
+ results.push({ index: i, success: true, txHash: recovered, error: errorMessage });
489
+ txHashes.push(recovered);
490
+ continue;
491
+ }
492
+ const errorMsg = `交易执行失败(status=${receipt?.status})`;
493
+ console.error(`❌ [${chainName}] 交易 ${i + 1} 恢复失败: ${errorMsg}`);
494
+ results.push({ index: i, success: false, txHash: recovered, error: `${errorMessage} | ${errorMsg}` });
495
+ errors.push(`交易 ${i + 1}: ${errorMessage} | ${errorMsg}`);
496
+ // ✅ 多跳场景:失败则停止
497
+ console.warn(`⚠️ [${chainName}] 多跳模式检测到失败,停止后续 ${totalTransactions - i - 1} 笔交易`);
498
+ break;
499
+ }
500
+ catch (waitError) {
501
+ // 等待超时:对于多跳场景,不能假设成功,需要停止
502
+ const waitErrorMsg = waitError?.message || String(waitError);
503
+ console.error(`⏱️ [${chainName}] 交易 ${i + 1} 等待确认超时: ${waitErrorMsg}`);
504
+ results.push({ index: i, success: false, txHash: recovered, error: `${errorMessage} | 等待确认超时: ${waitErrorMsg}` });
505
+ errors.push(`交易 ${i + 1}: ${errorMessage} | 等待确认超时`);
506
+ // ✅ 多跳场景:超时也停止
507
+ console.warn(`⚠️ [${chainName}] 多跳模式检测到超时,停止后续 ${totalTransactions - i - 1} 笔交易`);
508
+ break;
509
+ }
510
+ }
511
+ results.push({
512
+ index: i,
513
+ success: false,
514
+ error: errorMessage
515
+ });
516
+ errors.push(`交易 ${i + 1}: ${errorMessage}`);
517
+ // ✅ 多跳场景:如果某笔失败,后续交易肯定也会失败,立即停止
518
+ console.warn(`⚠️ [${chainName}] 多跳模式检测到失败,停止后续 ${totalTransactions - i - 1} 笔交易`);
519
+ break;
520
+ }
521
+ }
522
+ const successCount = txHashes.length;
523
+ const failedCount = totalTransactions - successCount;
524
+ console.log(`📊 [${chainName}] 顺序广播完成: 成功 ${successCount}/${totalTransactions}`);
525
+ return {
526
+ code: successCount > 0,
527
+ totalTransactions,
528
+ successCount,
529
+ failedCount,
530
+ txHashes,
531
+ results,
532
+ errorSummary: errors.length > 0 ? errors.join('; ') : undefined
533
+ };
534
+ }
535
+ /**
536
+ * ✅ 顺序广播但不等待确认(用于 AA handleOps + tail 等 nonce 连续的场景)
537
+ *
538
+ * 按顺序逐笔发送交易,每笔只等待广播成功(RPC 返回 txHash),不等待链上确认。
539
+ * 这样可以保证交易按顺序进入 mempool,同时避免等待确认超时。
540
+ *
541
+ * @param signedTransactions 签名后的交易数组
542
+ * @param config 直接广播配置
543
+ * @returns 广播结果
544
+ */
545
+ export async function submitDirectToRpcSequentialNoWait(signedTransactions, config) {
546
+ const totalTransactions = signedTransactions?.length ?? 0;
547
+ if (!signedTransactions || signedTransactions.length === 0) {
548
+ return {
549
+ code: false,
550
+ totalTransactions: 0,
551
+ successCount: 0,
552
+ failedCount: 0,
553
+ txHashes: [],
554
+ results: [],
555
+ errorSummary: 'signedTransactions cannot be empty'
556
+ };
557
+ }
558
+ if (!config.rpcUrl) {
559
+ return {
560
+ code: false,
561
+ totalTransactions,
562
+ successCount: 0,
563
+ failedCount: totalTransactions,
564
+ txHashes: [],
565
+ results: [],
566
+ errorSummary: 'rpcUrl is required in config'
567
+ };
568
+ }
569
+ const chainId = config.chainId ?? 143;
570
+ const chainName = config.chainName ?? 'MONAD';
571
+ const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
572
+ chainId,
573
+ name: chainName
574
+ });
575
+ const results = [];
576
+ const txHashes = [];
577
+ const errors = [];
578
+ // ✅ 顺序广播,每笔只等待广播成功(不等待链上确认)
579
+ for (let i = 0; i < signedTransactions.length; i++) {
580
+ const signedTx = signedTransactions[i];
581
+ try {
582
+ // 广播交易,等待 RPC 返回 txHash
583
+ const txResponse = await provider.broadcastTransaction(signedTx);
584
+ results.push({
585
+ index: i,
586
+ success: true,
587
+ txHash: txResponse.hash
588
+ });
589
+ txHashes.push(txResponse.hash);
590
+ console.log(`✅ [${chainName}] 交易 ${i + 1}/${totalTransactions} 广播成功: ${txResponse.hash}`);
591
+ }
592
+ catch (error) {
593
+ const errorMessage = error?.message || String(error);
594
+ console.error(`❌ [${chainName}] 交易 ${i + 1}/${totalTransactions} 广播失败:`, errorMessage);
595
+ // ✅ 兼容:nonce too low / already known 等情况下,交易可能已经被接收
596
+ const recovered = await recoverTxHashIfAlreadySeen(provider, signedTx, errorMessage);
597
+ if (recovered) {
598
+ results.push({ index: i, success: true, txHash: recovered, error: errorMessage });
599
+ txHashes.push(recovered);
600
+ continue;
601
+ }
602
+ results.push({
603
+ index: i,
604
+ success: false,
605
+ error: errorMessage
606
+ });
607
+ errors.push(`交易 ${i + 1}: ${errorMessage}`);
608
+ // ✅ 如果某笔失败,继续尝试后续交易(可能是 nonce 问题可以自动恢复)
609
+ }
610
+ }
611
+ const successCount = txHashes.length;
612
+ const failedCount = totalTransactions - successCount;
613
+ return {
614
+ code: successCount > 0,
615
+ totalTransactions,
616
+ successCount,
617
+ failedCount,
618
+ txHashes,
619
+ results,
620
+ errorSummary: errors.length > 0 ? errors.join('; ') : undefined
621
+ };
622
+ }
623
+ /**
624
+ * 并行逐笔广播到 RPC(速度更快,但可能有 nonce 冲突)
625
+ *
626
+ * ⚠️ 注意:仅适用于不同钱包的交易,同一钱包的多笔交易应使用顺序广播
627
+ *
628
+ * @param signedTransactions 签名后的交易数组
629
+ * @param config 直接广播配置
630
+ * @returns 广播结果
631
+ */
632
+ export async function submitDirectToRpcParallel(signedTransactions, config) {
633
+ const totalTransactions = signedTransactions?.length ?? 0;
634
+ if (!signedTransactions || signedTransactions.length === 0) {
635
+ return {
636
+ code: false,
637
+ totalTransactions: 0,
638
+ successCount: 0,
639
+ failedCount: 0,
640
+ txHashes: [],
641
+ results: [],
642
+ errorSummary: 'signedTransactions cannot be empty'
643
+ };
644
+ }
645
+ if (!config.rpcUrl) {
646
+ return {
647
+ code: false,
648
+ totalTransactions,
649
+ successCount: 0,
650
+ failedCount: totalTransactions,
651
+ txHashes: [],
652
+ results: [],
653
+ errorSummary: 'rpcUrl is required in config'
654
+ };
655
+ }
656
+ const chainId = config.chainId ?? 143;
657
+ const chainName = config.chainName ?? 'MONAD';
658
+ const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
659
+ chainId,
660
+ name: chainName
661
+ });
662
+ // 并行广播
663
+ const broadcastPromises = signedTransactions.map(async (signedTx, i) => {
664
+ try {
665
+ const txResponse = await provider.broadcastTransaction(signedTx);
666
+ return {
667
+ index: i,
668
+ success: true,
669
+ txHash: txResponse.hash
670
+ };
671
+ }
672
+ catch (error) {
673
+ return {
674
+ index: i,
675
+ success: false,
676
+ error: error?.message || String(error)
677
+ };
678
+ }
679
+ });
680
+ 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}`);
683
+ const successCount = txHashes.length;
684
+ const failedCount = totalTransactions - successCount;
685
+ return {
686
+ code: successCount > 0,
687
+ totalTransactions,
688
+ successCount,
689
+ failedCount,
690
+ txHashes,
691
+ 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
+ errorSummary: errors.length > 0 ? errors.join('; ') : undefined,
816
+ };
817
+ }
818
+ /**
819
+ * ENI Bundle 提交:模拟验证 → 快速顺序广播 → 同块确认
820
+ *
821
+ * 复用同一 Provider 快速顺序广播,最小化延迟、最大化同块概率。
822
+ * ENI 出块 ~1.08s,连续 nonce 快速提交同块率极高。
823
+ */
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,
829
+ });
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 };
863
+ }
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}`);
885
+ }
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);
910
+ }
911
+ }
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
+ }
918
+ }
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
+ };
928
+ }