@mantleio/viem 0.0.1-alpha.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 (453) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +54 -0
  3. package/dist/cjs/abis.js +3338 -0
  4. package/dist/cjs/abis.js.map +1 -0
  5. package/dist/cjs/actions/buildProveWithdrawal.js +55 -0
  6. package/dist/cjs/actions/buildProveWithdrawal.js.map +1 -0
  7. package/dist/cjs/actions/depositERC20.js +37 -0
  8. package/dist/cjs/actions/depositERC20.js.map +1 -0
  9. package/dist/cjs/actions/depositETH.js +36 -0
  10. package/dist/cjs/actions/depositETH.js.map +1 -0
  11. package/dist/cjs/actions/depositMNT.js +35 -0
  12. package/dist/cjs/actions/depositMNT.js.map +1 -0
  13. package/dist/cjs/actions/estimateDepositERC20Gas.js +38 -0
  14. package/dist/cjs/actions/estimateDepositERC20Gas.js.map +1 -0
  15. package/dist/cjs/actions/estimateDepositETHGas.js +37 -0
  16. package/dist/cjs/actions/estimateDepositETHGas.js.map +1 -0
  17. package/dist/cjs/actions/estimateDepositMNTGas.js +36 -0
  18. package/dist/cjs/actions/estimateDepositMNTGas.js.map +1 -0
  19. package/dist/cjs/actions/estimateFinalizeWithdrawalGas.js +29 -0
  20. package/dist/cjs/actions/estimateFinalizeWithdrawalGas.js.map +1 -0
  21. package/dist/cjs/actions/estimateInitiateERC20WithdrawalGas.js +30 -0
  22. package/dist/cjs/actions/estimateInitiateERC20WithdrawalGas.js.map +1 -0
  23. package/dist/cjs/actions/estimateInitiateETHWithdrawalGas.js +29 -0
  24. package/dist/cjs/actions/estimateInitiateETHWithdrawalGas.js.map +1 -0
  25. package/dist/cjs/actions/estimateInitiateMNTWithdrawalGas.js +30 -0
  26. package/dist/cjs/actions/estimateInitiateMNTWithdrawalGas.js.map +1 -0
  27. package/dist/cjs/actions/estimateProveWithdrawalGas.js +29 -0
  28. package/dist/cjs/actions/estimateProveWithdrawalGas.js.map +1 -0
  29. package/dist/cjs/actions/finalizeWithdrawal.js +28 -0
  30. package/dist/cjs/actions/finalizeWithdrawal.js.map +1 -0
  31. package/dist/cjs/actions/getL2Output.js +31 -0
  32. package/dist/cjs/actions/getL2Output.js.map +1 -0
  33. package/dist/cjs/actions/getPortalVersion.js +24 -0
  34. package/dist/cjs/actions/getPortalVersion.js.map +1 -0
  35. package/dist/cjs/actions/getTimeToFinalize.js +46 -0
  36. package/dist/cjs/actions/getTimeToFinalize.js.map +1 -0
  37. package/dist/cjs/actions/getTimeToNextL2Output.js +62 -0
  38. package/dist/cjs/actions/getTimeToNextL2Output.js.map +1 -0
  39. package/dist/cjs/actions/getTimeToProve.js +12 -0
  40. package/dist/cjs/actions/getTimeToProve.js.map +1 -0
  41. package/dist/cjs/actions/getWithdrawalStatus.js +133 -0
  42. package/dist/cjs/actions/getWithdrawalStatus.js.map +1 -0
  43. package/dist/cjs/actions/initiateERC20Withdrawal.js +29 -0
  44. package/dist/cjs/actions/initiateERC20Withdrawal.js.map +1 -0
  45. package/dist/cjs/actions/initiateETHWithdrawal.js +28 -0
  46. package/dist/cjs/actions/initiateETHWithdrawal.js.map +1 -0
  47. package/dist/cjs/actions/initiateMNTWithdrawal.js +29 -0
  48. package/dist/cjs/actions/initiateMNTWithdrawal.js.map +1 -0
  49. package/dist/cjs/actions/proveWithdrawal.js +28 -0
  50. package/dist/cjs/actions/proveWithdrawal.js.map +1 -0
  51. package/dist/cjs/actions/waitForNextL2Output.js +31 -0
  52. package/dist/cjs/actions/waitForNextL2Output.js.map +1 -0
  53. package/dist/cjs/actions/waitToFinalize.js +10 -0
  54. package/dist/cjs/actions/waitToFinalize.js.map +1 -0
  55. package/dist/cjs/actions/waitToProve.js +24 -0
  56. package/dist/cjs/actions/waitToProve.js.map +1 -0
  57. package/dist/cjs/chainConfig.js +12 -0
  58. package/dist/cjs/chainConfig.js.map +1 -0
  59. package/dist/cjs/chains/index.js +8 -0
  60. package/dist/cjs/chains/index.js.map +1 -0
  61. package/dist/cjs/chains/mantle.js +53 -0
  62. package/dist/cjs/chains/mantle.js.map +1 -0
  63. package/dist/cjs/chains/mantleSepoliaTestnet.js +54 -0
  64. package/dist/cjs/chains/mantleSepoliaTestnet.js.map +1 -0
  65. package/dist/cjs/contracts.js +16 -0
  66. package/dist/cjs/contracts.js.map +1 -0
  67. package/dist/cjs/decorators/publicL1.js +38 -0
  68. package/dist/cjs/decorators/publicL1.js.map +1 -0
  69. package/dist/cjs/decorators/publicL2.js +18 -0
  70. package/dist/cjs/decorators/publicL2.js.map +1 -0
  71. package/dist/cjs/decorators/walletL1.js +20 -0
  72. package/dist/cjs/decorators/walletL1.js.map +1 -0
  73. package/dist/cjs/decorators/walletL2.js +16 -0
  74. package/dist/cjs/decorators/walletL2.js.map +1 -0
  75. package/dist/cjs/errors/utils.js +3 -0
  76. package/dist/cjs/errors/utils.js.map +1 -0
  77. package/dist/cjs/errors/withdrawal.js +17 -0
  78. package/dist/cjs/errors/withdrawal.js.map +1 -0
  79. package/dist/cjs/formatters.js +51 -0
  80. package/dist/cjs/formatters.js.map +1 -0
  81. package/dist/cjs/index.js +59 -0
  82. package/dist/cjs/index.js.map +1 -0
  83. package/dist/cjs/package.json +1 -0
  84. package/dist/cjs/parsers.js +58 -0
  85. package/dist/cjs/parsers.js.map +1 -0
  86. package/dist/cjs/serializers.js +53 -0
  87. package/dist/cjs/serializers.js.map +1 -0
  88. package/dist/cjs/types/account.js +3 -0
  89. package/dist/cjs/types/account.js.map +1 -0
  90. package/dist/cjs/types/block.js +3 -0
  91. package/dist/cjs/types/block.js.map +1 -0
  92. package/dist/cjs/types/chain.js +3 -0
  93. package/dist/cjs/types/chain.js.map +1 -0
  94. package/dist/cjs/types/contract.js +3 -0
  95. package/dist/cjs/types/contract.js.map +1 -0
  96. package/dist/cjs/types/deposit.js +3 -0
  97. package/dist/cjs/types/deposit.js.map +1 -0
  98. package/dist/cjs/types/l1Actions.js +8 -0
  99. package/dist/cjs/types/l1Actions.js.map +1 -0
  100. package/dist/cjs/types/l2Actions.js +11 -0
  101. package/dist/cjs/types/l2Actions.js.map +1 -0
  102. package/dist/cjs/types/transaction.js +3 -0
  103. package/dist/cjs/types/transaction.js.map +1 -0
  104. package/dist/cjs/types/withdrawal.js +3 -0
  105. package/dist/cjs/types/withdrawal.js.map +1 -0
  106. package/dist/cjs/utils/extractTransactionDepositedLogs.js +13 -0
  107. package/dist/cjs/utils/extractTransactionDepositedLogs.js.map +1 -0
  108. package/dist/cjs/utils/extractWithdrawalMessageLogs.js +13 -0
  109. package/dist/cjs/utils/extractWithdrawalMessageLogs.js.map +1 -0
  110. package/dist/cjs/utils/getL2TransactionHash.js +29 -0
  111. package/dist/cjs/utils/getL2TransactionHash.js.map +1 -0
  112. package/dist/cjs/utils/getL2TransactionHashes.js +10 -0
  113. package/dist/cjs/utils/getL2TransactionHashes.js.map +1 -0
  114. package/dist/cjs/utils/getSourceHash.js +17 -0
  115. package/dist/cjs/utils/getSourceHash.js.map +1 -0
  116. package/dist/cjs/utils/getWithdrawalHashStorageSlot.js +9 -0
  117. package/dist/cjs/utils/getWithdrawalHashStorageSlot.js.map +1 -0
  118. package/dist/cjs/utils/getWithdrawals.js +9 -0
  119. package/dist/cjs/utils/getWithdrawals.js.map +1 -0
  120. package/dist/cjs/utils/opaqueDataToDepositData.js +32 -0
  121. package/dist/cjs/utils/opaqueDataToDepositData.js.map +1 -0
  122. package/dist/cjs/utils/parseDepositRequest.js +43 -0
  123. package/dist/cjs/utils/parseDepositRequest.js.map +1 -0
  124. package/dist/cjs/utils/parseInitWithdrawRequest.js +55 -0
  125. package/dist/cjs/utils/parseInitWithdrawRequest.js.map +1 -0
  126. package/dist/cjs/utils/poll.js +26 -0
  127. package/dist/cjs/utils/poll.js.map +1 -0
  128. package/dist/cjs/utils/promise/withCache.js +47 -0
  129. package/dist/cjs/utils/promise/withCache.js.map +1 -0
  130. package/dist/cjs/utils/wait.js +7 -0
  131. package/dist/cjs/utils/wait.js.map +1 -0
  132. package/dist/esm/abis.js +3335 -0
  133. package/dist/esm/abis.js.map +1 -0
  134. package/dist/esm/actions/buildProveWithdrawal.js +67 -0
  135. package/dist/esm/actions/buildProveWithdrawal.js.map +1 -0
  136. package/dist/esm/actions/depositERC20.js +39 -0
  137. package/dist/esm/actions/depositERC20.js.map +1 -0
  138. package/dist/esm/actions/depositETH.js +38 -0
  139. package/dist/esm/actions/depositETH.js.map +1 -0
  140. package/dist/esm/actions/depositMNT.js +37 -0
  141. package/dist/esm/actions/depositMNT.js.map +1 -0
  142. package/dist/esm/actions/estimateDepositERC20Gas.js +43 -0
  143. package/dist/esm/actions/estimateDepositERC20Gas.js.map +1 -0
  144. package/dist/esm/actions/estimateDepositETHGas.js +43 -0
  145. package/dist/esm/actions/estimateDepositETHGas.js.map +1 -0
  146. package/dist/esm/actions/estimateDepositMNTGas.js +41 -0
  147. package/dist/esm/actions/estimateDepositMNTGas.js.map +1 -0
  148. package/dist/esm/actions/estimateFinalizeWithdrawalGas.js +34 -0
  149. package/dist/esm/actions/estimateFinalizeWithdrawalGas.js.map +1 -0
  150. package/dist/esm/actions/estimateInitiateERC20WithdrawalGas.js +35 -0
  151. package/dist/esm/actions/estimateInitiateERC20WithdrawalGas.js.map +1 -0
  152. package/dist/esm/actions/estimateInitiateETHWithdrawalGas.js +34 -0
  153. package/dist/esm/actions/estimateInitiateETHWithdrawalGas.js.map +1 -0
  154. package/dist/esm/actions/estimateInitiateMNTWithdrawalGas.js +35 -0
  155. package/dist/esm/actions/estimateInitiateMNTWithdrawalGas.js.map +1 -0
  156. package/dist/esm/actions/estimateProveWithdrawalGas.js +34 -0
  157. package/dist/esm/actions/estimateProveWithdrawalGas.js.map +1 -0
  158. package/dist/esm/actions/finalizeWithdrawal.js +30 -0
  159. package/dist/esm/actions/finalizeWithdrawal.js.map +1 -0
  160. package/dist/esm/actions/getL2Output.js +33 -0
  161. package/dist/esm/actions/getL2Output.js.map +1 -0
  162. package/dist/esm/actions/getPortalVersion.js +26 -0
  163. package/dist/esm/actions/getPortalVersion.js.map +1 -0
  164. package/dist/esm/actions/getTimeToFinalize.js +48 -0
  165. package/dist/esm/actions/getTimeToFinalize.js.map +1 -0
  166. package/dist/esm/actions/getTimeToNextL2Output.js +68 -0
  167. package/dist/esm/actions/getTimeToNextL2Output.js.map +1 -0
  168. package/dist/esm/actions/getTimeToProve.js +14 -0
  169. package/dist/esm/actions/getTimeToProve.js.map +1 -0
  170. package/dist/esm/actions/getWithdrawalStatus.js +138 -0
  171. package/dist/esm/actions/getWithdrawalStatus.js.map +1 -0
  172. package/dist/esm/actions/initiateERC20Withdrawal.js +31 -0
  173. package/dist/esm/actions/initiateERC20Withdrawal.js.map +1 -0
  174. package/dist/esm/actions/initiateETHWithdrawal.js +30 -0
  175. package/dist/esm/actions/initiateETHWithdrawal.js.map +1 -0
  176. package/dist/esm/actions/initiateMNTWithdrawal.js +31 -0
  177. package/dist/esm/actions/initiateMNTWithdrawal.js.map +1 -0
  178. package/dist/esm/actions/proveWithdrawal.js +30 -0
  179. package/dist/esm/actions/proveWithdrawal.js.map +1 -0
  180. package/dist/esm/actions/waitForNextL2Output.js +33 -0
  181. package/dist/esm/actions/waitForNextL2Output.js.map +1 -0
  182. package/dist/esm/actions/waitToFinalize.js +11 -0
  183. package/dist/esm/actions/waitToFinalize.js.map +1 -0
  184. package/dist/esm/actions/waitToProve.js +26 -0
  185. package/dist/esm/actions/waitToProve.js.map +1 -0
  186. package/dist/esm/chainConfig.js +9 -0
  187. package/dist/esm/chainConfig.js.map +1 -0
  188. package/dist/esm/chains/index.js +3 -0
  189. package/dist/esm/chains/index.js.map +1 -0
  190. package/dist/esm/chains/mantle.js +50 -0
  191. package/dist/esm/chains/mantle.js.map +1 -0
  192. package/dist/esm/chains/mantleSepoliaTestnet.js +51 -0
  193. package/dist/esm/chains/mantleSepoliaTestnet.js.map +1 -0
  194. package/dist/esm/contracts.js +13 -0
  195. package/dist/esm/contracts.js.map +1 -0
  196. package/dist/esm/decorators/publicL1.js +35 -0
  197. package/dist/esm/decorators/publicL1.js.map +1 -0
  198. package/dist/esm/decorators/publicL2.js +15 -0
  199. package/dist/esm/decorators/publicL2.js.map +1 -0
  200. package/dist/esm/decorators/walletL1.js +17 -0
  201. package/dist/esm/decorators/walletL1.js.map +1 -0
  202. package/dist/esm/decorators/walletL2.js +13 -0
  203. package/dist/esm/decorators/walletL2.js.map +1 -0
  204. package/dist/esm/errors/utils.js +2 -0
  205. package/dist/esm/errors/utils.js.map +1 -0
  206. package/dist/esm/errors/withdrawal.js +12 -0
  207. package/dist/esm/errors/withdrawal.js.map +1 -0
  208. package/dist/esm/formatters.js +48 -0
  209. package/dist/esm/formatters.js.map +1 -0
  210. package/dist/esm/index.js +29 -0
  211. package/dist/esm/index.js.map +1 -0
  212. package/dist/esm/package.json +1 -0
  213. package/dist/esm/parsers.js +54 -0
  214. package/dist/esm/parsers.js.map +1 -0
  215. package/dist/esm/serializers.js +48 -0
  216. package/dist/esm/serializers.js.map +1 -0
  217. package/dist/esm/types/account.js +2 -0
  218. package/dist/esm/types/account.js.map +1 -0
  219. package/dist/esm/types/block.js +2 -0
  220. package/dist/esm/types/block.js.map +1 -0
  221. package/dist/esm/types/chain.js +2 -0
  222. package/dist/esm/types/chain.js.map +1 -0
  223. package/dist/esm/types/contract.js +2 -0
  224. package/dist/esm/types/contract.js.map +1 -0
  225. package/dist/esm/types/deposit.js +2 -0
  226. package/dist/esm/types/deposit.js.map +1 -0
  227. package/dist/esm/types/l1Actions.js +5 -0
  228. package/dist/esm/types/l1Actions.js.map +1 -0
  229. package/dist/esm/types/l2Actions.js +7 -0
  230. package/dist/esm/types/l2Actions.js.map +1 -0
  231. package/dist/esm/types/transaction.js +2 -0
  232. package/dist/esm/types/transaction.js.map +1 -0
  233. package/dist/esm/types/withdrawal.js +2 -0
  234. package/dist/esm/types/withdrawal.js.map +1 -0
  235. package/dist/esm/utils/extractTransactionDepositedLogs.js +10 -0
  236. package/dist/esm/utils/extractTransactionDepositedLogs.js.map +1 -0
  237. package/dist/esm/utils/extractWithdrawalMessageLogs.js +10 -0
  238. package/dist/esm/utils/extractWithdrawalMessageLogs.js.map +1 -0
  239. package/dist/esm/utils/getL2TransactionHash.js +26 -0
  240. package/dist/esm/utils/getL2TransactionHash.js.map +1 -0
  241. package/dist/esm/utils/getL2TransactionHashes.js +7 -0
  242. package/dist/esm/utils/getL2TransactionHashes.js.map +1 -0
  243. package/dist/esm/utils/getSourceHash.js +14 -0
  244. package/dist/esm/utils/getSourceHash.js.map +1 -0
  245. package/dist/esm/utils/getWithdrawalHashStorageSlot.js +6 -0
  246. package/dist/esm/utils/getWithdrawalHashStorageSlot.js.map +1 -0
  247. package/dist/esm/utils/getWithdrawals.js +6 -0
  248. package/dist/esm/utils/getWithdrawals.js.map +1 -0
  249. package/dist/esm/utils/opaqueDataToDepositData.js +29 -0
  250. package/dist/esm/utils/opaqueDataToDepositData.js.map +1 -0
  251. package/dist/esm/utils/parseDepositRequest.js +39 -0
  252. package/dist/esm/utils/parseDepositRequest.js.map +1 -0
  253. package/dist/esm/utils/parseInitWithdrawRequest.js +51 -0
  254. package/dist/esm/utils/parseInitWithdrawRequest.js.map +1 -0
  255. package/dist/esm/utils/poll.js +26 -0
  256. package/dist/esm/utils/poll.js.map +1 -0
  257. package/dist/esm/utils/promise/withCache.js +57 -0
  258. package/dist/esm/utils/promise/withCache.js.map +1 -0
  259. package/dist/esm/utils/wait.js +4 -0
  260. package/dist/esm/utils/wait.js.map +1 -0
  261. package/dist/types/abis.d.ts +3110 -0
  262. package/dist/types/abis.d.ts.map +1 -0
  263. package/dist/types/actions/buildProveWithdrawal.d.ts +34 -0
  264. package/dist/types/actions/buildProveWithdrawal.d.ts.map +1 -0
  265. package/dist/types/actions/depositERC20.d.ts +29 -0
  266. package/dist/types/actions/depositERC20.d.ts.map +1 -0
  267. package/dist/types/actions/depositETH.d.ts +29 -0
  268. package/dist/types/actions/depositETH.d.ts.map +1 -0
  269. package/dist/types/actions/depositMNT.d.ts +29 -0
  270. package/dist/types/actions/depositMNT.d.ts.map +1 -0
  271. package/dist/types/actions/estimateDepositERC20Gas.d.ts +26 -0
  272. package/dist/types/actions/estimateDepositERC20Gas.d.ts.map +1 -0
  273. package/dist/types/actions/estimateDepositETHGas.d.ts +26 -0
  274. package/dist/types/actions/estimateDepositETHGas.d.ts.map +1 -0
  275. package/dist/types/actions/estimateDepositMNTGas.d.ts +26 -0
  276. package/dist/types/actions/estimateDepositMNTGas.d.ts.map +1 -0
  277. package/dist/types/actions/estimateFinalizeWithdrawalGas.d.ts +26 -0
  278. package/dist/types/actions/estimateFinalizeWithdrawalGas.d.ts.map +1 -0
  279. package/dist/types/actions/estimateInitiateERC20WithdrawalGas.d.ts +25 -0
  280. package/dist/types/actions/estimateInitiateERC20WithdrawalGas.d.ts.map +1 -0
  281. package/dist/types/actions/estimateInitiateETHWithdrawalGas.d.ts +25 -0
  282. package/dist/types/actions/estimateInitiateETHWithdrawalGas.d.ts.map +1 -0
  283. package/dist/types/actions/estimateInitiateMNTWithdrawalGas.d.ts +25 -0
  284. package/dist/types/actions/estimateInitiateMNTWithdrawalGas.d.ts.map +1 -0
  285. package/dist/types/actions/estimateProveWithdrawalGas.d.ts +35 -0
  286. package/dist/types/actions/estimateProveWithdrawalGas.d.ts.map +1 -0
  287. package/dist/types/actions/finalizeWithdrawal.d.ts +29 -0
  288. package/dist/types/actions/finalizeWithdrawal.d.ts.map +1 -0
  289. package/dist/types/actions/getL2Output.d.ts +24 -0
  290. package/dist/types/actions/getL2Output.d.ts.map +1 -0
  291. package/dist/types/actions/getPortalVersion.d.ts +23 -0
  292. package/dist/types/actions/getPortalVersion.d.ts.map +1 -0
  293. package/dist/types/actions/getTimeToFinalize.d.ts +26 -0
  294. package/dist/types/actions/getTimeToFinalize.d.ts.map +1 -0
  295. package/dist/types/actions/getTimeToNextL2Output.d.ts +35 -0
  296. package/dist/types/actions/getTimeToNextL2Output.d.ts.map +1 -0
  297. package/dist/types/actions/getTimeToProve.d.ts +24 -0
  298. package/dist/types/actions/getTimeToProve.d.ts.map +1 -0
  299. package/dist/types/actions/getWithdrawalStatus.d.ts +22 -0
  300. package/dist/types/actions/getWithdrawalStatus.d.ts.map +1 -0
  301. package/dist/types/actions/initiateERC20Withdrawal.d.ts +27 -0
  302. package/dist/types/actions/initiateERC20Withdrawal.d.ts.map +1 -0
  303. package/dist/types/actions/initiateETHWithdrawal.d.ts +27 -0
  304. package/dist/types/actions/initiateETHWithdrawal.d.ts.map +1 -0
  305. package/dist/types/actions/initiateMNTWithdrawal.d.ts +27 -0
  306. package/dist/types/actions/initiateMNTWithdrawal.d.ts.map +1 -0
  307. package/dist/types/actions/proveWithdrawal.d.ts +36 -0
  308. package/dist/types/actions/proveWithdrawal.d.ts.map +1 -0
  309. package/dist/types/actions/waitForNextL2Output.d.ts +29 -0
  310. package/dist/types/actions/waitForNextL2Output.d.ts.map +1 -0
  311. package/dist/types/actions/waitToFinalize.d.ts +14 -0
  312. package/dist/types/actions/waitToFinalize.d.ts.map +1 -0
  313. package/dist/types/actions/waitToProve.d.ts +27 -0
  314. package/dist/types/actions/waitToProve.d.ts.map +1 -0
  315. package/dist/types/chainConfig.d.ts +43 -0
  316. package/dist/types/chainConfig.d.ts.map +1 -0
  317. package/dist/types/chains/index.d.ts +3 -0
  318. package/dist/types/chains/index.d.ts.map +1 -0
  319. package/dist/types/chains/mantle.d.ts +299 -0
  320. package/dist/types/chains/mantle.d.ts.map +1 -0
  321. package/dist/types/chains/mantleSepoliaTestnet.d.ts +299 -0
  322. package/dist/types/chains/mantleSepoliaTestnet.d.ts.map +1 -0
  323. package/dist/types/contracts.d.ts +21 -0
  324. package/dist/types/contracts.d.ts.map +1 -0
  325. package/dist/types/decorators/publicL1.d.ts +35 -0
  326. package/dist/types/decorators/publicL1.d.ts.map +1 -0
  327. package/dist/types/decorators/publicL2.d.ts +16 -0
  328. package/dist/types/decorators/publicL2.d.ts.map +1 -0
  329. package/dist/types/decorators/walletL1.d.ts +17 -0
  330. package/dist/types/decorators/walletL1.d.ts.map +1 -0
  331. package/dist/types/decorators/walletL2.d.ts +13 -0
  332. package/dist/types/decorators/walletL2.d.ts.map +1 -0
  333. package/dist/types/errors/utils.d.ts +4 -0
  334. package/dist/types/errors/utils.d.ts.map +1 -0
  335. package/dist/types/errors/withdrawal.d.ts +17 -0
  336. package/dist/types/errors/withdrawal.d.ts.map +1 -0
  337. package/dist/types/formatters.d.ts +20 -0
  338. package/dist/types/formatters.d.ts.map +1 -0
  339. package/dist/types/index.d.ts +30 -0
  340. package/dist/types/index.d.ts.map +1 -0
  341. package/dist/types/parsers.d.ts +8 -0
  342. package/dist/types/parsers.d.ts.map +1 -0
  343. package/dist/types/serializers.d.ts +13 -0
  344. package/dist/types/serializers.d.ts.map +1 -0
  345. package/dist/types/types/account.d.ts +7 -0
  346. package/dist/types/types/account.d.ts.map +1 -0
  347. package/dist/types/types/block.d.ts +13 -0
  348. package/dist/types/types/block.d.ts.map +1 -0
  349. package/dist/types/types/chain.d.ts +9 -0
  350. package/dist/types/types/chain.d.ts.map +1 -0
  351. package/dist/types/types/contract.d.ts +14 -0
  352. package/dist/types/types/contract.d.ts.map +1 -0
  353. package/dist/types/types/deposit.d.ts +35 -0
  354. package/dist/types/types/deposit.d.ts.map +1 -0
  355. package/dist/types/types/l1Actions.d.ts +856 -0
  356. package/dist/types/types/l1Actions.d.ts.map +1 -0
  357. package/dist/types/types/l2Actions.d.ts +3 -0
  358. package/dist/types/types/l2Actions.d.ts.map +1 -0
  359. package/dist/types/types/transaction.d.ts +58 -0
  360. package/dist/types/types/transaction.d.ts.map +1 -0
  361. package/dist/types/types/withdrawal.d.ts +39 -0
  362. package/dist/types/types/withdrawal.d.ts.map +1 -0
  363. package/dist/types/utils/extractTransactionDepositedLogs.d.ts +450 -0
  364. package/dist/types/utils/extractTransactionDepositedLogs.d.ts.map +1 -0
  365. package/dist/types/utils/extractWithdrawalMessageLogs.d.ts +160 -0
  366. package/dist/types/utils/extractWithdrawalMessageLogs.d.ts.map +1 -0
  367. package/dist/types/utils/getL2TransactionHash.d.ts +12 -0
  368. package/dist/types/utils/getL2TransactionHash.d.ts.map +1 -0
  369. package/dist/types/utils/getL2TransactionHashes.d.ts +11 -0
  370. package/dist/types/utils/getL2TransactionHashes.d.ts.map +1 -0
  371. package/dist/types/utils/getSourceHash.d.ts +25 -0
  372. package/dist/types/utils/getSourceHash.d.ts.map +1 -0
  373. package/dist/types/utils/getWithdrawalHashStorageSlot.d.ts +10 -0
  374. package/dist/types/utils/getWithdrawalHashStorageSlot.d.ts.map +1 -0
  375. package/dist/types/utils/getWithdrawals.d.ts +12 -0
  376. package/dist/types/utils/getWithdrawals.d.ts.map +1 -0
  377. package/dist/types/utils/opaqueDataToDepositData.d.ts +16 -0
  378. package/dist/types/utils/opaqueDataToDepositData.d.ts.map +1 -0
  379. package/dist/types/utils/parseDepositRequest.d.ts +11 -0
  380. package/dist/types/utils/parseDepositRequest.d.ts.map +1 -0
  381. package/dist/types/utils/parseInitWithdrawRequest.d.ts +11 -0
  382. package/dist/types/utils/parseInitWithdrawRequest.d.ts.map +1 -0
  383. package/dist/types/utils/poll.d.ts +15 -0
  384. package/dist/types/utils/poll.d.ts.map +1 -0
  385. package/dist/types/utils/promise/withCache.d.ts +41 -0
  386. package/dist/types/utils/promise/withCache.d.ts.map +1 -0
  387. package/dist/types/utils/wait.d.ts +2 -0
  388. package/dist/types/utils/wait.d.ts.map +1 -0
  389. package/package.json +113 -0
  390. package/src/mantle/abis.ts +3339 -0
  391. package/src/mantle/actions/buildProveWithdrawal.ts +150 -0
  392. package/src/mantle/actions/depositERC20.ts +103 -0
  393. package/src/mantle/actions/depositETH.ts +102 -0
  394. package/src/mantle/actions/depositMNT.ts +101 -0
  395. package/src/mantle/actions/estimateDepositERC20Gas.ts +113 -0
  396. package/src/mantle/actions/estimateDepositETHGas.ts +113 -0
  397. package/src/mantle/actions/estimateDepositMNTGas.ts +111 -0
  398. package/src/mantle/actions/estimateFinalizeWithdrawalGas.ts +102 -0
  399. package/src/mantle/actions/estimateInitiateERC20WithdrawalGas.ts +106 -0
  400. package/src/mantle/actions/estimateInitiateETHWithdrawalGas.ts +105 -0
  401. package/src/mantle/actions/estimateInitiateMNTWithdrawalGas.ts +106 -0
  402. package/src/mantle/actions/estimateProveWithdrawalGas.ts +114 -0
  403. package/src/mantle/actions/finalizeWithdrawal.ts +95 -0
  404. package/src/mantle/actions/getL2Output.ts +75 -0
  405. package/src/mantle/actions/getPortalVersion.ts +57 -0
  406. package/src/mantle/actions/getTimeToFinalize.ts +85 -0
  407. package/src/mantle/actions/getTimeToNextL2Output.ts +132 -0
  408. package/src/mantle/actions/getTimeToProve.ts +58 -0
  409. package/src/mantle/actions/getWithdrawalStatus.ts +225 -0
  410. package/src/mantle/actions/initiateERC20Withdrawal.ts +93 -0
  411. package/src/mantle/actions/initiateETHWithdrawal.ts +90 -0
  412. package/src/mantle/actions/initiateMNTWithdrawal.ts +91 -0
  413. package/src/mantle/actions/proveWithdrawal.ts +107 -0
  414. package/src/mantle/actions/waitForNextL2Output.ts +87 -0
  415. package/src/mantle/actions/waitToFinalize.ts +33 -0
  416. package/src/mantle/actions/waitToProve.ts +83 -0
  417. package/src/mantle/chainConfig.ts +9 -0
  418. package/src/mantle/chains/index.ts +2 -0
  419. package/src/mantle/chains/mantle.ts +51 -0
  420. package/src/mantle/chains/mantleSepoliaTestnet.ts +52 -0
  421. package/src/mantle/contracts.ts +14 -0
  422. package/src/mantle/decorators/publicL1.ts +182 -0
  423. package/src/mantle/decorators/publicL2.ts +96 -0
  424. package/src/mantle/decorators/walletL1.ts +67 -0
  425. package/src/mantle/decorators/walletL2.ts +55 -0
  426. package/src/mantle/errors/utils.ts +1 -0
  427. package/src/mantle/errors/withdrawal.ts +24 -0
  428. package/src/mantle/formatters.ts +64 -0
  429. package/src/mantle/index.ts +179 -0
  430. package/src/mantle/parsers.ts +97 -0
  431. package/src/mantle/serializers.ts +106 -0
  432. package/src/mantle/types/account.ts +25 -0
  433. package/src/mantle/types/block.ts +34 -0
  434. package/src/mantle/types/chain.ts +10 -0
  435. package/src/mantle/types/contract.ts +26 -0
  436. package/src/mantle/types/deposit.ts +40 -0
  437. package/src/mantle/types/l1Actions.ts +21 -0
  438. package/src/mantle/types/l2Actions.ts +6 -0
  439. package/src/mantle/types/transaction.ts +108 -0
  440. package/src/mantle/types/withdrawal.ts +45 -0
  441. package/src/mantle/utils/extractTransactionDepositedLogs.ts +33 -0
  442. package/src/mantle/utils/extractWithdrawalMessageLogs.ts +33 -0
  443. package/src/mantle/utils/getL2TransactionHash.ts +51 -0
  444. package/src/mantle/utils/getL2TransactionHashes.ts +21 -0
  445. package/src/mantle/utils/getSourceHash.ts +62 -0
  446. package/src/mantle/utils/getWithdrawalHashStorageSlot.ts +27 -0
  447. package/src/mantle/utils/getWithdrawals.ts +25 -0
  448. package/src/mantle/utils/opaqueDataToDepositData.ts +58 -0
  449. package/src/mantle/utils/parseDepositRequest.ts +67 -0
  450. package/src/mantle/utils/parseInitWithdrawRequest.ts +68 -0
  451. package/src/mantle/utils/poll.ts +45 -0
  452. package/src/mantle/utils/promise/withCache.ts +81 -0
  453. package/src/mantle/utils/wait.ts +3 -0
@@ -0,0 +1,225 @@
1
+ import type {
2
+ Account,
3
+ Chain,
4
+ Client,
5
+ DeriveChain,
6
+ GetChainParameter,
7
+ Transport,
8
+ } from "viem";
9
+ import { ContractFunctionRevertedError } from "viem";
10
+ import { readContract, type ReadContractErrorType } from "viem/actions";
11
+ import type { ErrorType } from "../errors/utils.js";
12
+
13
+ import type { TransactionReceipt } from "viem";
14
+ import type { OneOf } from "viem";
15
+ import { portal2Abi, portalAbi } from "../abis.js";
16
+ import {
17
+ ReceiptContainsNoWithdrawalsError,
18
+ type ReceiptContainsNoWithdrawalsErrorType,
19
+ } from "../errors/withdrawal.js";
20
+ import type { TargetChain } from "../types/chain.js";
21
+ import type { GetContractAddressParameter } from "../types/contract.js";
22
+ import {
23
+ getWithdrawals,
24
+ type GetWithdrawalsErrorType,
25
+ } from "../utils/getWithdrawals.js";
26
+ import {
27
+ getL2Output,
28
+ type GetL2OutputErrorType,
29
+ type GetL2OutputParameters,
30
+ } from "./getL2Output.js";
31
+ import {
32
+ getPortalVersion,
33
+ type GetPortalVersionParameters,
34
+ } from "./getPortalVersion.js";
35
+ import {
36
+ getTimeToFinalize,
37
+ type GetTimeToFinalizeErrorType,
38
+ type GetTimeToFinalizeParameters,
39
+ } from "./getTimeToFinalize.js";
40
+
41
+ export type GetWithdrawalStatusParameters<
42
+ chain extends Chain | undefined = Chain | undefined,
43
+ chainOverride extends Chain | undefined = Chain | undefined,
44
+ _derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
45
+ > = GetChainParameter<chain, chainOverride> &
46
+ OneOf<
47
+ GetContractAddressParameter<_derivedChain, "l2OutputOracle" | "portal">
48
+ > & {
49
+ receipt: TransactionReceipt;
50
+ };
51
+ export type GetWithdrawalStatusReturnType =
52
+ | "waiting-to-prove"
53
+ | "ready-to-prove"
54
+ | "waiting-to-finalize"
55
+ | "ready-to-finalize"
56
+ | "finalized";
57
+
58
+ export type GetWithdrawalStatusErrorType =
59
+ | GetL2OutputErrorType
60
+ | GetTimeToFinalizeErrorType
61
+ | GetWithdrawalsErrorType
62
+ | ReadContractErrorType
63
+ | ReceiptContainsNoWithdrawalsErrorType
64
+ | ErrorType;
65
+
66
+ /**
67
+ * @param client - Client to use
68
+ * @param parameters - {@link GetWithdrawalStatusParameters}
69
+ * @returns Status of the withdrawal. {@link GetWithdrawalStatusReturnType}
70
+ */
71
+ export async function getWithdrawalStatus<
72
+ chain extends Chain | undefined,
73
+ account extends Account | undefined,
74
+ chainOverride extends Chain | undefined = undefined,
75
+ >(
76
+ client: Client<Transport, chain, account>,
77
+ parameters: GetWithdrawalStatusParameters<chain, chainOverride>,
78
+ ): Promise<GetWithdrawalStatusReturnType> {
79
+ const {
80
+ chain = client.chain,
81
+ receipt,
82
+ targetChain: targetChain_,
83
+ } = parameters;
84
+
85
+ const targetChain = targetChain_ as unknown as TargetChain;
86
+
87
+ const portalAddress = (() => {
88
+ if (parameters.portalAddress) return parameters.portalAddress;
89
+ if (chain) return targetChain.contracts.portal[chain.id].address;
90
+ return Object.values(targetChain.contracts.portal)[0].address;
91
+ })();
92
+
93
+ const [withdrawal] = getWithdrawals(receipt);
94
+
95
+ if (!withdrawal) {
96
+ throw new ReceiptContainsNoWithdrawalsError({
97
+ hash: receipt.transactionHash,
98
+ });
99
+ }
100
+
101
+ const portalVersion = await getPortalVersion(
102
+ client,
103
+ parameters as GetPortalVersionParameters,
104
+ );
105
+
106
+ // Legacy (Portal < v3)
107
+ if (portalVersion.major < 3) {
108
+ const [outputResult, proveResult, finalizedResult, timeToFinalizeResult] =
109
+ await Promise.allSettled([
110
+ getL2Output(client, {
111
+ ...parameters,
112
+ l2BlockNumber: receipt.blockNumber,
113
+ } as GetL2OutputParameters),
114
+ readContract(client, {
115
+ abi: portalAbi,
116
+ address: portalAddress,
117
+ functionName: "provenWithdrawals",
118
+ args: [withdrawal.withdrawalHash],
119
+ }),
120
+ readContract(client, {
121
+ abi: portalAbi,
122
+ address: portalAddress,
123
+ functionName: "finalizedWithdrawals",
124
+ args: [withdrawal.withdrawalHash],
125
+ }),
126
+ getTimeToFinalize(client, {
127
+ ...parameters,
128
+ withdrawalHash: withdrawal.withdrawalHash,
129
+ } as GetTimeToFinalizeParameters),
130
+ ]);
131
+
132
+ // If the L2 Output is not processed yet (ie. the actions throws), this means
133
+ // that the withdrawal is not ready to prove.
134
+ if (outputResult.status === "rejected") {
135
+ const error = outputResult.reason as GetL2OutputErrorType;
136
+ if (
137
+ error.cause instanceof ContractFunctionRevertedError &&
138
+ error.cause.data?.args?.[0] ===
139
+ "L2OutputOracle: cannot get output for a block that has not been proposed"
140
+ ) {
141
+ return "waiting-to-prove";
142
+ }
143
+ throw error;
144
+ }
145
+ if (proveResult.status === "rejected") throw proveResult.reason;
146
+ if (finalizedResult.status === "rejected") throw finalizedResult.reason;
147
+ if (timeToFinalizeResult.status === "rejected") {
148
+ throw timeToFinalizeResult.reason;
149
+ }
150
+
151
+ const [_, proveTimestamp] = proveResult.value;
152
+ if (!proveTimestamp) return "ready-to-prove";
153
+
154
+ const finalized = finalizedResult.value;
155
+ if (finalized) return "finalized";
156
+
157
+ const { seconds } = timeToFinalizeResult.value;
158
+ return seconds > 0 ? "waiting-to-finalize" : "ready-to-finalize";
159
+ }
160
+
161
+ const numProofSubmitters = await readContract(client, {
162
+ abi: portal2Abi,
163
+ address: portalAddress,
164
+ functionName: "numProofSubmitters",
165
+ args: [withdrawal.withdrawalHash],
166
+ }).catch(() => 1n);
167
+
168
+ const proofSubmitter = await readContract(client, {
169
+ abi: portal2Abi,
170
+ address: portalAddress,
171
+ functionName: "proofSubmitters",
172
+ args: [withdrawal.withdrawalHash, numProofSubmitters - 1n],
173
+ }).catch(() => withdrawal.sender);
174
+
175
+ const [checkWithdrawalResult, finalizedResult] = await Promise.allSettled([
176
+ readContract(client, {
177
+ abi: portal2Abi,
178
+ address: portalAddress,
179
+ functionName: "checkWithdrawal",
180
+ args: [withdrawal.withdrawalHash, proofSubmitter],
181
+ }),
182
+ readContract(client, {
183
+ abi: portal2Abi,
184
+ address: portalAddress,
185
+ functionName: "finalizedWithdrawals",
186
+ args: [withdrawal.withdrawalHash],
187
+ }),
188
+ ]);
189
+
190
+ if (finalizedResult.status === "fulfilled" && finalizedResult.value) {
191
+ return "finalized";
192
+ }
193
+
194
+ if (checkWithdrawalResult.status === "rejected") {
195
+ const error = checkWithdrawalResult.reason as ReadContractErrorType;
196
+ if (error.cause instanceof ContractFunctionRevertedError) {
197
+ const errorMessage = error.cause.data?.args?.[0];
198
+ if (
199
+ errorMessage === "OptimismPortal: invalid game type" ||
200
+ errorMessage === "OptimismPortal: withdrawal has not been proven yet" ||
201
+ errorMessage ===
202
+ "OptimismPortal: withdrawal has not been proven by proof submitter address yet"
203
+ ) {
204
+ return "ready-to-prove";
205
+ }
206
+ if (
207
+ errorMessage ===
208
+ "OptimismPortal: proven withdrawal has not matured yet" ||
209
+ errorMessage ===
210
+ "OptimismPortal: output proposal has not been finalized yet" ||
211
+ errorMessage === "OptimismPortal: output proposal in air-gap"
212
+ ) {
213
+ return "waiting-to-finalize";
214
+ }
215
+
216
+ if (error.cause.data?.errorName === "InvalidGameType") {
217
+ return "ready-to-prove";
218
+ }
219
+ }
220
+ throw checkWithdrawalResult.reason;
221
+ }
222
+ if (finalizedResult.status === "rejected") throw finalizedResult.reason;
223
+
224
+ return "ready-to-finalize";
225
+ }
@@ -0,0 +1,93 @@
1
+ import type { Address } from "viem";
2
+ import type { Client, FormattedTransactionRequest, Transport } from "viem";
3
+ import type { Account } from "viem";
4
+ import type { Chain, DeriveChain, GetChainParameter } from "viem";
5
+ import type { Hash } from "viem";
6
+ import type { UnionEvaluate, UnionOmit } from "viem";
7
+ import {
8
+ writeContract,
9
+ type WriteContractErrorType,
10
+ type WriteContractParameters,
11
+ } from "viem/actions";
12
+ import { l2StandardBridge } from "../abis.js";
13
+ import { contracts } from "../contracts.js";
14
+ import type { ErrorType } from "../errors/utils.js";
15
+ import type { GetAccountParameter } from "../types/account.js";
16
+ import type { InitiateERC20WithdrawalRequest } from "../types/withdrawal.js";
17
+ import { parseInitWithdrawequest } from "../utils/parseInitWithdrawRequest.js";
18
+
19
+ export type InitiateERC20WithdrawalParameters<
20
+ chain extends Chain | undefined = Chain | undefined,
21
+ account extends Account | undefined = Account | undefined,
22
+ chainOverride extends Chain | undefined = Chain | undefined,
23
+ _derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
24
+ > = UnionEvaluate<
25
+ UnionOmit<
26
+ FormattedTransactionRequest<_derivedChain>,
27
+ | "accessList"
28
+ | "data"
29
+ | "from"
30
+ | "gas"
31
+ | "gasPrice"
32
+ | "to"
33
+ | "type"
34
+ | "value"
35
+ >
36
+ > &
37
+ GetAccountParameter<account, Account | Address> &
38
+ GetChainParameter<chain, chainOverride> & {
39
+ /**
40
+ * Gas limit for transaction execution on the L2.
41
+ */
42
+ gas?: bigint | undefined;
43
+ /** Withdrawal request. Supplied to the L2ToL1MessagePasser `initiateERC20Withdrawal` method. */
44
+ request: InitiateERC20WithdrawalRequest;
45
+ };
46
+ export type InitiateERC20WithdrawalReturnType = Hash;
47
+ export type InitiateERC20WithdrawalErrorType =
48
+ | WriteContractErrorType
49
+ | ErrorType;
50
+
51
+ /**
52
+ * @param client - Client to use
53
+ * @param parameters - {@link InitiateERC20WithdrawalParameters}
54
+ * @returns The L2 transaction hash. {@link InitiateERC20WithdrawalReturnType}
55
+ */
56
+ export async function initiateERC20Withdrawal<
57
+ chain extends Chain | undefined,
58
+ account extends Account | undefined,
59
+ chainOverride extends Chain | undefined = undefined,
60
+ >(
61
+ client: Client<Transport, chain, account>,
62
+ parameters: InitiateERC20WithdrawalParameters<chain, account, chainOverride>,
63
+ ) {
64
+ const {
65
+ account,
66
+ chain = client.chain,
67
+ gas,
68
+ maxFeePerGas,
69
+ maxPriorityFeePerGas,
70
+ nonce,
71
+ request: { amount, to },
72
+ } = parameters;
73
+
74
+ const { functionName, args } = parseInitWithdrawequest({
75
+ type: "erc20",
76
+ l2Token: "0x9EF6f9160Ba00B6621e5CB3217BB8b54a92B2828",
77
+ amount,
78
+ to,
79
+ });
80
+
81
+ return writeContract(client, {
82
+ account: account!,
83
+ abi: l2StandardBridge,
84
+ address: contracts.l2StandardBridge.address,
85
+ chain,
86
+ functionName,
87
+ args,
88
+ gas,
89
+ maxFeePerGas,
90
+ maxPriorityFeePerGas,
91
+ nonce,
92
+ } satisfies WriteContractParameters as any);
93
+ }
@@ -0,0 +1,90 @@
1
+ import type { Address } from "viem";
2
+ import type { Client, FormattedTransactionRequest, Transport } from "viem";
3
+ import type { Account } from "viem";
4
+ import type { Chain, DeriveChain, GetChainParameter } from "viem";
5
+ import type { Hash } from "viem";
6
+ import type { UnionEvaluate, UnionOmit } from "viem";
7
+ import {
8
+ writeContract,
9
+ type WriteContractErrorType,
10
+ type WriteContractParameters,
11
+ } from "viem/actions";
12
+ import { l2StandardBridge } from "../abis.js";
13
+ import { contracts } from "../contracts.js";
14
+ import type { ErrorType } from "../errors/utils.js";
15
+ import type { GetAccountParameter } from "../types/account.js";
16
+ import type { InitiateETHWithdrawalRequest } from "../types/withdrawal.js";
17
+ import { parseInitWithdrawequest } from "../utils/parseInitWithdrawRequest.js";
18
+
19
+ export type InitiateETHWithdrawalParameters<
20
+ chain extends Chain | undefined = Chain | undefined,
21
+ account extends Account | undefined = Account | undefined,
22
+ chainOverride extends Chain | undefined = Chain | undefined,
23
+ _derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
24
+ > = UnionEvaluate<
25
+ UnionOmit<
26
+ FormattedTransactionRequest<_derivedChain>,
27
+ | "accessList"
28
+ | "data"
29
+ | "from"
30
+ | "gas"
31
+ | "gasPrice"
32
+ | "to"
33
+ | "type"
34
+ | "value"
35
+ >
36
+ > &
37
+ GetAccountParameter<account, Account | Address> &
38
+ GetChainParameter<chain, chainOverride> & {
39
+ /**
40
+ * Gas limit for transaction execution on the L2.
41
+ */
42
+ gas?: bigint | undefined;
43
+ /** Withdrawal request. Supplied to the L2ToL1MessagePasser `initiateETHWithdrawal` method. */
44
+ request: InitiateETHWithdrawalRequest;
45
+ };
46
+ export type InitiateETHWithdrawalReturnType = Hash;
47
+ export type InitiateETHWithdrawalErrorType = WriteContractErrorType | ErrorType;
48
+
49
+ /**
50
+ * @param client - Client to use
51
+ * @param parameters - {@link InitiateETHWithdrawalParameters}
52
+ * @returns The L2 transaction hash. {@link InitiateETHWithdrawalReturnType}
53
+ */
54
+ export async function initiateETHWithdrawal<
55
+ chain extends Chain | undefined,
56
+ account extends Account | undefined,
57
+ chainOverride extends Chain | undefined = undefined,
58
+ >(
59
+ client: Client<Transport, chain, account>,
60
+ parameters: InitiateETHWithdrawalParameters<chain, account, chainOverride>,
61
+ ) {
62
+ const {
63
+ account,
64
+ chain = client.chain,
65
+ gas,
66
+ maxFeePerGas,
67
+ maxPriorityFeePerGas,
68
+ nonce,
69
+ request: { amount, to },
70
+ } = parameters;
71
+
72
+ const { functionName, args } = parseInitWithdrawequest({
73
+ type: "eth",
74
+ amount,
75
+ to,
76
+ });
77
+
78
+ return writeContract(client, {
79
+ account: account!,
80
+ abi: l2StandardBridge,
81
+ address: contracts.l2StandardBridge.address,
82
+ chain,
83
+ functionName,
84
+ args,
85
+ gas,
86
+ maxFeePerGas,
87
+ maxPriorityFeePerGas,
88
+ nonce,
89
+ } satisfies WriteContractParameters as any);
90
+ }
@@ -0,0 +1,91 @@
1
+ import type { Address } from "viem";
2
+ import type { Client, FormattedTransactionRequest, Transport } from "viem";
3
+ import type { Account } from "viem";
4
+ import type { Chain, DeriveChain, GetChainParameter } from "viem";
5
+ import type { Hash } from "viem";
6
+ import type { UnionEvaluate, UnionOmit } from "viem";
7
+ import {
8
+ writeContract,
9
+ type WriteContractErrorType,
10
+ type WriteContractParameters,
11
+ } from "viem/actions";
12
+ import { l2StandardBridge } from "../abis.js";
13
+ import { contracts } from "../contracts.js";
14
+ import type { ErrorType } from "../errors/utils.js";
15
+ import type { GetAccountParameter } from "../types/account.js";
16
+ import type { InitiateMNTWithdrawalRequest } from "../types/withdrawal.js";
17
+ import { parseInitWithdrawequest } from "../utils/parseInitWithdrawRequest.js";
18
+
19
+ export type InitiateMNTWithdrawalParameters<
20
+ chain extends Chain | undefined = Chain | undefined,
21
+ account extends Account | undefined = Account | undefined,
22
+ chainOverride extends Chain | undefined = Chain | undefined,
23
+ _derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
24
+ > = UnionEvaluate<
25
+ UnionOmit<
26
+ FormattedTransactionRequest<_derivedChain>,
27
+ | "accessList"
28
+ | "data"
29
+ | "from"
30
+ | "gas"
31
+ | "gasPrice"
32
+ | "to"
33
+ | "type"
34
+ | "value"
35
+ >
36
+ > &
37
+ GetAccountParameter<account, Account | Address> &
38
+ GetChainParameter<chain, chainOverride> & {
39
+ /**
40
+ * Gas limit for transaction execution on the L2.
41
+ */
42
+ gas?: bigint | undefined;
43
+ /** Withdrawal request. Supplied to the L2ToL1MessagePasser `initiateMNTWithdrawal` method. */
44
+ request: InitiateMNTWithdrawalRequest;
45
+ };
46
+ export type InitiateMNTWithdrawalReturnType = Hash;
47
+ export type InitiateMNTWithdrawalErrorType = WriteContractErrorType | ErrorType;
48
+
49
+ /**
50
+ * @param client - Client to use
51
+ * @param parameters - {@link InitiateMNTWithdrawalParameters}
52
+ * @returns The L2 transaction hash. {@link InitiateMNTWithdrawalReturnType}
53
+ */
54
+ export async function initiateMNTWithdrawal<
55
+ chain extends Chain | undefined,
56
+ account extends Account | undefined,
57
+ chainOverride extends Chain | undefined = undefined,
58
+ >(
59
+ client: Client<Transport, chain, account>,
60
+ parameters: InitiateMNTWithdrawalParameters<chain, account, chainOverride>,
61
+ ) {
62
+ const {
63
+ account,
64
+ chain = client.chain,
65
+ gas,
66
+ maxFeePerGas,
67
+ maxPriorityFeePerGas,
68
+ nonce,
69
+ request: { amount, to },
70
+ } = parameters;
71
+
72
+ const { functionName, args } = parseInitWithdrawequest({
73
+ type: "mnt",
74
+ amount,
75
+ to,
76
+ });
77
+
78
+ return writeContract(client, {
79
+ account: account!,
80
+ abi: l2StandardBridge,
81
+ address: contracts.l2StandardBridge.address,
82
+ chain,
83
+ functionName,
84
+ args,
85
+ gas,
86
+ maxFeePerGas,
87
+ maxPriorityFeePerGas,
88
+ nonce,
89
+ value: amount,
90
+ } satisfies WriteContractParameters as any);
91
+ }
@@ -0,0 +1,107 @@
1
+ import type { Address } from "viem";
2
+ import type { Client, FormattedTransactionRequest, Transport } from "viem";
3
+ import type { Account } from "viem";
4
+ import type { Chain, DeriveChain, GetChainParameter } from "viem";
5
+ import type { Hash, Hex } from "viem";
6
+ import type { UnionEvaluate, UnionOmit } from "viem";
7
+ import {
8
+ writeContract,
9
+ type WriteContractErrorType,
10
+ type WriteContractParameters,
11
+ } from "viem/actions";
12
+ import { portalAbi } from "../abis.js";
13
+ import type { ErrorType } from "../errors/utils.js";
14
+ import type { GetAccountParameter } from "../types/account.js";
15
+ import type { GetContractAddressParameter } from "../types/contract.js";
16
+ import type { Withdrawal } from "../types/withdrawal.js";
17
+ import type { EstimateProveWithdrawalGasErrorType } from "./estimateProveWithdrawalGas.js";
18
+
19
+ export type ProveWithdrawalParameters<
20
+ chain extends Chain | undefined = Chain | undefined,
21
+ account extends Account | undefined = Account | undefined,
22
+ chainOverride extends Chain | undefined = Chain | undefined,
23
+ _derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
24
+ > = UnionEvaluate<
25
+ UnionOmit<
26
+ FormattedTransactionRequest<_derivedChain>,
27
+ | "accessList"
28
+ | "blobs"
29
+ | "data"
30
+ | "from"
31
+ | "gas"
32
+ | "maxFeePerBlobGas"
33
+ | "gasPrice"
34
+ | "to"
35
+ | "type"
36
+ | "value"
37
+ >
38
+ > &
39
+ GetAccountParameter<account, Account | Address> &
40
+ GetChainParameter<chain, chainOverride> &
41
+ GetContractAddressParameter<_derivedChain, "portal"> & {
42
+ /**
43
+ * Gas limit for transaction execution on the L1.
44
+ */
45
+ gas?: bigint | undefined;
46
+ l2OutputIndex: bigint;
47
+ outputRootProof: {
48
+ version: Hex;
49
+ stateRoot: Hex;
50
+ messagePasserStorageRoot: Hex;
51
+ latestBlockhash: Hex;
52
+ };
53
+ withdrawalProof: readonly Hex[];
54
+ withdrawal: Withdrawal;
55
+ };
56
+ export type ProveWithdrawalReturnType = Hash;
57
+ export type ProveWithdrawalErrorType =
58
+ | EstimateProveWithdrawalGasErrorType
59
+ | WriteContractErrorType
60
+ | ErrorType;
61
+
62
+ /**
63
+ * @param client - Client to use
64
+ * @param parameters - {@link ProveWithdrawalParameters}
65
+ * @returns The prove transaction hash. {@link ProveWithdrawalReturnType}
66
+ */
67
+ export async function proveWithdrawal<
68
+ chain extends Chain | undefined,
69
+ account extends Account | undefined,
70
+ chainOverride extends Chain | undefined = undefined,
71
+ >(
72
+ client: Client<Transport, chain, account>,
73
+ parameters: ProveWithdrawalParameters<chain, account, chainOverride>,
74
+ ): Promise<ProveWithdrawalReturnType> {
75
+ const {
76
+ account,
77
+ chain = client.chain,
78
+ gas,
79
+ l2OutputIndex,
80
+ maxFeePerGas,
81
+ maxPriorityFeePerGas,
82
+ nonce,
83
+ outputRootProof,
84
+ targetChain,
85
+ withdrawalProof,
86
+ withdrawal,
87
+ } = parameters;
88
+
89
+ const portalAddress = (() => {
90
+ if (parameters.portalAddress) return parameters.portalAddress;
91
+ if (chain) return targetChain!.contracts.portal[chain.id].address;
92
+ return Object.values(targetChain!.contracts.portal)[0].address;
93
+ })();
94
+
95
+ return writeContract(client, {
96
+ account: account!,
97
+ abi: portalAbi,
98
+ address: portalAddress,
99
+ chain,
100
+ functionName: "proveWithdrawalTransaction",
101
+ args: [withdrawal, l2OutputIndex, outputRootProof, withdrawalProof],
102
+ gas,
103
+ maxFeePerGas,
104
+ maxPriorityFeePerGas,
105
+ nonce,
106
+ } satisfies WriteContractParameters as any);
107
+ }
@@ -0,0 +1,87 @@
1
+ import type { Client, Transport } from "viem";
2
+ import { ContractFunctionRevertedError } from "viem";
3
+ import type { Account } from "viem";
4
+ import type { Chain, DeriveChain, GetChainParameter } from "viem";
5
+ import type { ErrorType } from "../errors/utils.js";
6
+ import type { GetContractAddressParameter } from "../types/contract.js";
7
+ import { poll } from "../utils/poll.js";
8
+ import {
9
+ getL2Output,
10
+ type GetL2OutputErrorType,
11
+ type GetL2OutputParameters,
12
+ type GetL2OutputReturnType,
13
+ } from "./getL2Output.js";
14
+ import {
15
+ getTimeToNextL2Output,
16
+ type GetTimeToNextL2OutputErrorType,
17
+ type GetTimeToNextL2OutputParameters,
18
+ } from "./getTimeToNextL2Output.js";
19
+
20
+ export type WaitForNextL2OutputParameters<
21
+ chain extends Chain | undefined = Chain | undefined,
22
+ chainOverride extends Chain | undefined = Chain | undefined,
23
+ _derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
24
+ > = GetChainParameter<chain, chainOverride> &
25
+ GetContractAddressParameter<_derivedChain, "l2OutputOracle"> & {
26
+ /**
27
+ * The buffer to account for discrepancies between non-deterministic time intervals.
28
+ * @default 1.1
29
+ */
30
+ intervalBuffer?:
31
+ | GetTimeToNextL2OutputParameters["intervalBuffer"]
32
+ | undefined;
33
+ l2BlockNumber: bigint;
34
+ /**
35
+ * Polling frequency (in ms). Defaults to Client's pollingInterval config.
36
+ * @default client.pollingInterval
37
+ */
38
+ pollingInterval?: number | undefined;
39
+ };
40
+ export type WaitForNextL2OutputReturnType = GetL2OutputReturnType;
41
+ export type WaitForNextL2OutputErrorType =
42
+ | GetL2OutputErrorType
43
+ | GetTimeToNextL2OutputErrorType
44
+ | ErrorType;
45
+
46
+ /**
47
+ * @param client - Client to use
48
+ * @param parameters - {@link WaitForNextL2OutputParameters}
49
+ * @returns The L2 transaction hash. {@link WaitForNextL2OutputReturnType}
50
+ */
51
+ export async function waitForNextL2Output<
52
+ chain extends Chain | undefined,
53
+ account extends Account | undefined,
54
+ chainOverride extends Chain | undefined = undefined,
55
+ >(
56
+ client: Client<Transport, chain, account>,
57
+ parameters: WaitForNextL2OutputParameters<chain, chainOverride>,
58
+ ): Promise<WaitForNextL2OutputReturnType> {
59
+ const { pollingInterval = client.pollingInterval } = parameters;
60
+
61
+ const { seconds } = await getTimeToNextL2Output(client, parameters);
62
+
63
+ return new Promise((resolve, reject) => {
64
+ poll(
65
+ async ({ unpoll }) => {
66
+ try {
67
+ const output = await getL2Output(
68
+ client,
69
+ parameters as GetL2OutputParameters,
70
+ );
71
+ unpoll();
72
+ resolve(output);
73
+ } catch (e) {
74
+ const error = e as GetL2OutputErrorType;
75
+ if (!(error.cause instanceof ContractFunctionRevertedError)) {
76
+ unpoll();
77
+ reject(e);
78
+ }
79
+ }
80
+ },
81
+ {
82
+ interval: pollingInterval,
83
+ initialWaitTime: async () => seconds * 1000,
84
+ },
85
+ );
86
+ });
87
+ }