@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,150 @@
1
+ import type { Address } from "viem";
2
+ import { type Client, fromRlp, keccak256, toRlp, type Transport } from "viem";
3
+ import type { Account, DeriveAccount } from "viem";
4
+ import type { Chain, DeriveChain, GetChainParameter } from "viem";
5
+ import type { Hex } from "viem";
6
+ import type { OneOf, Prettify } from "viem";
7
+ import {
8
+ getBlock,
9
+ type GetBlockErrorType,
10
+ getProof,
11
+ type GetProofErrorType,
12
+ } from "viem/actions";
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 { Withdrawal } from "../types/withdrawal.js";
17
+ import {
18
+ getWithdrawalHashStorageSlot,
19
+ type GetWithdrawalHashStorageSlotErrorType,
20
+ } from "../utils/getWithdrawalHashStorageSlot.js";
21
+ import type { GetL2OutputReturnType } from "./getL2Output.js";
22
+ import type { ProveWithdrawalParameters } from "./proveWithdrawal.js";
23
+
24
+ const outputRootProofVersion =
25
+ "0x0000000000000000000000000000000000000000000000000000000000000000" as const;
26
+
27
+ export type BuildProveWithdrawalParameters<
28
+ chain extends Chain | undefined = Chain | undefined,
29
+ account extends Account | undefined = Account | undefined,
30
+ chainOverride extends Chain | undefined = Chain | undefined,
31
+ accountOverride extends Account | Address | undefined =
32
+ | Account
33
+ | Address
34
+ | undefined,
35
+ _derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
36
+ > = GetAccountParameter<account, accountOverride, false> &
37
+ GetChainParameter<chain, chainOverride> & {
38
+ withdrawal: Withdrawal;
39
+ } & OneOf<{ output: GetL2OutputReturnType }>;
40
+
41
+ export type BuildProveWithdrawalReturnType<
42
+ chain extends Chain | undefined = Chain | undefined,
43
+ account extends Account | undefined = Account | undefined,
44
+ chainOverride extends Chain | undefined = Chain | undefined,
45
+ accountOverride extends Account | Address | undefined =
46
+ | Account
47
+ | Address
48
+ | undefined,
49
+ > = Prettify<
50
+ Pick<
51
+ ProveWithdrawalParameters,
52
+ "l2OutputIndex" | "outputRootProof" | "withdrawalProof" | "withdrawal"
53
+ > & {
54
+ account: DeriveAccount<account, accountOverride>;
55
+ targetChain: DeriveChain<chain, chainOverride>;
56
+ }
57
+ >;
58
+
59
+ export type BuildProveWithdrawalErrorType =
60
+ | GetBlockErrorType
61
+ | GetProofErrorType
62
+ | GetWithdrawalHashStorageSlotErrorType
63
+ | ErrorType;
64
+
65
+ /**
66
+ * Builds the transaction that proves a withdrawal was initiated on an L2. Used in the Withdrawal flow.
67
+ *
68
+ * @param client - Client to use
69
+ * @param parameters - {@link BuildProveWithdrawalParameters}
70
+ * @returns The prove withdraw transaction request. {@link BuildProveWithdrawalReturnType}
71
+ */
72
+ export async function buildProveWithdrawal<
73
+ chain extends Chain | undefined,
74
+ account extends Account | undefined,
75
+ chainOverride extends Chain | undefined = undefined,
76
+ accountOverride extends Account | Address | undefined = undefined,
77
+ >(
78
+ client: Client<Transport, chain, account>,
79
+ args: BuildProveWithdrawalParameters<
80
+ chain,
81
+ account,
82
+ chainOverride,
83
+ accountOverride
84
+ >,
85
+ ): Promise<
86
+ BuildProveWithdrawalReturnType<chain, account, chainOverride, accountOverride>
87
+ > {
88
+ const { account, chain = client.chain, output, withdrawal } = args;
89
+
90
+ const { withdrawalHash } = withdrawal;
91
+ const { l2BlockNumber } = output;
92
+
93
+ const slot = getWithdrawalHashStorageSlot({ withdrawalHash });
94
+ const [proof, block] = await Promise.all([
95
+ getProof(client, {
96
+ address: contracts.l2ToL1MessagePasser.address,
97
+ storageKeys: [slot],
98
+ blockNumber: l2BlockNumber,
99
+ }),
100
+ getBlock(client, {
101
+ blockNumber: l2BlockNumber,
102
+ }),
103
+ ]);
104
+
105
+ return {
106
+ account,
107
+ l2OutputIndex: output?.outputIndex,
108
+ outputRootProof: {
109
+ latestBlockhash: block.hash,
110
+ messagePasserStorageRoot: proof.storageHash,
111
+ stateRoot: block.stateRoot,
112
+ version: outputRootProofVersion,
113
+ },
114
+ targetChain: chain,
115
+ withdrawalProof: maybeAddProofNode(
116
+ keccak256(slot),
117
+ proof.storageProof[0].proof,
118
+ ),
119
+ withdrawal,
120
+ } as unknown as BuildProveWithdrawalReturnType<
121
+ chain,
122
+ account,
123
+ chainOverride,
124
+ accountOverride
125
+ >;
126
+ }
127
+
128
+ /** @internal */
129
+ export function maybeAddProofNode(key: string, proof: readonly Hex[]) {
130
+ const lastProofRlp = proof[proof.length - 1];
131
+ const lastProof = fromRlp(lastProofRlp);
132
+ if (lastProof.length !== 17) return proof;
133
+
134
+ const modifiedProof = [...proof];
135
+ for (const item of lastProof) {
136
+ // Find any nodes located inside of the branch node.
137
+ if (!Array.isArray(item)) continue;
138
+ // Check if the key inside the node matches the key we're looking for. We remove the first
139
+ // two characters (0x) and then we remove one more character (the first nibble) since this
140
+ // is the identifier for the type of node we're looking at. In this case we don't actually
141
+ // care what type of node it is because a branch node would only ever be the final proof
142
+ // element if (1) it includes the leaf node we're looking for or (2) it stores the value
143
+ // within itself. If (1) then this logic will work, if (2) then this won't find anything
144
+ // and we won't append any proof elements, which is exactly what we would want.
145
+ const suffix = item[0].slice(3);
146
+ if (typeof suffix !== "string" || !key.endsWith(suffix)) continue;
147
+ modifiedProof.push(toRlp(item));
148
+ }
149
+ return modifiedProof;
150
+ }
@@ -0,0 +1,103 @@
1
+ import type { Address } from "viem";
2
+ import type { Client, 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 type { FormattedTransactionRequest } from "viem/utils";
13
+ import { l1StandardBridge } from "../abis.js";
14
+ import type { ErrorType } from "../errors/utils.js";
15
+ import type { GetAccountParameter } from "../types/account.js";
16
+ import type { GetContractAddressParameter } from "../types/contract.js";
17
+ import type { DepositERC20Request } from "../types/deposit.js";
18
+ import { parseDepositRequest } from "../utils/parseDepositRequest.js";
19
+
20
+ export type DepositERC20Parameters<
21
+ chain extends Chain | undefined = Chain | undefined,
22
+ account extends Account | undefined = Account | undefined,
23
+ chainOverride extends Chain | undefined = Chain | undefined,
24
+ _derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
25
+ > = UnionEvaluate<
26
+ UnionOmit<
27
+ FormattedTransactionRequest<_derivedChain>,
28
+ | "accessList"
29
+ | "data"
30
+ | "from"
31
+ | "gas"
32
+ | "gasPrice"
33
+ | "to"
34
+ | "type"
35
+ | "value"
36
+ >
37
+ > &
38
+ GetAccountParameter<account, Account | Address> &
39
+ GetChainParameter<chain, chainOverride> &
40
+ GetContractAddressParameter<_derivedChain, "l1StandardBridge"> & {
41
+ /** L2 transaction request. */
42
+ request: DepositERC20Request;
43
+ /**
44
+ * Gas limit for transaction execution on the L1.
45
+ */
46
+ gas?: bigint | undefined;
47
+ };
48
+ export type DepositERC20ReturnType = Hash;
49
+ export type DepositERC20ErrorType = WriteContractErrorType | ErrorType;
50
+
51
+ /**
52
+ * @param client - Client to use
53
+ * @param parameters - {@link DepositERC20Parameters}
54
+ * @returns The L1 transaction hash. {@link DepositERC20ReturnType}
55
+ */
56
+ export async function depositERC20<
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: DepositERC20Parameters<chain, account, chainOverride>,
63
+ ) {
64
+ const {
65
+ account,
66
+ chain = client.chain,
67
+ gas,
68
+ maxFeePerGas,
69
+ maxPriorityFeePerGas,
70
+ nonce,
71
+ request: { l1Token, l2Token, amount, to },
72
+ targetChain,
73
+ } = parameters;
74
+
75
+ const l1StandardBridgeAddress = (() => {
76
+ if (parameters.l1StandardBridgeAddress) {
77
+ return parameters.l1StandardBridgeAddress;
78
+ }
79
+ if (chain) return targetChain!.contracts.l1StandardBridge[chain.id].address;
80
+ return Object.values(targetChain!.contracts.l1StandardBridge)[0].address;
81
+ })();
82
+
83
+ const { functionName, args } = parseDepositRequest({
84
+ type: "erc20",
85
+ l1Token,
86
+ l2Token,
87
+ amount,
88
+ to,
89
+ });
90
+
91
+ return writeContract(client, {
92
+ account: account!,
93
+ abi: l1StandardBridge,
94
+ address: l1StandardBridgeAddress,
95
+ chain,
96
+ functionName,
97
+ args,
98
+ maxFeePerGas,
99
+ maxPriorityFeePerGas,
100
+ nonce,
101
+ gas,
102
+ } satisfies WriteContractParameters as any);
103
+ }
@@ -0,0 +1,102 @@
1
+ import type { Address } from "viem";
2
+ import type { Client, 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 type { FormattedTransactionRequest } from "viem/utils";
13
+ import { l1StandardBridge } from "../abis.js";
14
+ import type { ErrorType } from "../errors/utils.js";
15
+ import type { GetAccountParameter } from "../types/account.js";
16
+ import type { GetContractAddressParameter } from "../types/contract.js";
17
+ import type { DepositETHRequest } from "../types/deposit.js";
18
+ import { parseDepositRequest } from "../utils/parseDepositRequest.js";
19
+
20
+ export type DepositETHParameters<
21
+ chain extends Chain | undefined = Chain | undefined,
22
+ account extends Account | undefined = Account | undefined,
23
+ chainOverride extends Chain | undefined = Chain | undefined,
24
+ _derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
25
+ > = UnionEvaluate<
26
+ UnionOmit<
27
+ FormattedTransactionRequest<_derivedChain>,
28
+ | "accessList"
29
+ | "data"
30
+ | "from"
31
+ | "gas"
32
+ | "gasPrice"
33
+ | "to"
34
+ | "type"
35
+ | "value"
36
+ >
37
+ > &
38
+ GetAccountParameter<account, Account | Address> &
39
+ GetChainParameter<chain, chainOverride> &
40
+ GetContractAddressParameter<_derivedChain, "l1StandardBridge"> & {
41
+ /** L2 transaction request. */
42
+ request: DepositETHRequest;
43
+ /**
44
+ * Gas limit for transaction execution on the L1.
45
+ */
46
+ gas?: bigint | undefined;
47
+ };
48
+ export type DepositETHReturnType = Hash;
49
+ export type DepositETHErrorType = WriteContractErrorType | ErrorType;
50
+
51
+ /**
52
+ * @param client - Client to use
53
+ * @param parameters - {@link DepositERC20Parameters}
54
+ * @returns The L1 transaction hash. {@link DepositERC20ReturnType}
55
+ */
56
+ export async function depositETH<
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: DepositETHParameters<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
+ targetChain,
73
+ } = parameters;
74
+
75
+ const l1StandardBridgeAddress = (() => {
76
+ if (parameters.l1StandardBridgeAddress) {
77
+ return parameters.l1StandardBridgeAddress;
78
+ }
79
+ if (chain) return targetChain!.contracts.l1StandardBridge[chain.id].address;
80
+ return Object.values(targetChain!.contracts.l1StandardBridge)[0].address;
81
+ })();
82
+
83
+ const { functionName, args } = parseDepositRequest({
84
+ type: "eth",
85
+ amount,
86
+ to,
87
+ });
88
+
89
+ return writeContract(client, {
90
+ account: account!,
91
+ abi: l1StandardBridge,
92
+ address: l1StandardBridgeAddress,
93
+ chain,
94
+ functionName,
95
+ args,
96
+ maxFeePerGas,
97
+ maxPriorityFeePerGas,
98
+ nonce,
99
+ gas,
100
+ value: amount,
101
+ } satisfies WriteContractParameters as any);
102
+ }
@@ -0,0 +1,101 @@
1
+ import type { Address } from "viem";
2
+ import type { Client, 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 type { FormattedTransactionRequest } from "viem/utils";
13
+ import { l1StandardBridge } from "../abis.js";
14
+ import type { ErrorType } from "../errors/utils.js";
15
+ import type { GetAccountParameter } from "../types/account.js";
16
+ import type { GetContractAddressParameter } from "../types/contract.js";
17
+ import type { DepositMNTRequest } from "../types/deposit.js";
18
+ import { parseDepositRequest } from "../utils/parseDepositRequest.js";
19
+
20
+ export type DepositMNTParameters<
21
+ chain extends Chain | undefined = Chain | undefined,
22
+ account extends Account | undefined = Account | undefined,
23
+ chainOverride extends Chain | undefined = Chain | undefined,
24
+ _derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
25
+ > = UnionEvaluate<
26
+ UnionOmit<
27
+ FormattedTransactionRequest<_derivedChain>,
28
+ | "accessList"
29
+ | "data"
30
+ | "from"
31
+ | "gas"
32
+ | "gasPrice"
33
+ | "to"
34
+ | "type"
35
+ | "value"
36
+ >
37
+ > &
38
+ GetAccountParameter<account, Account | Address> &
39
+ GetChainParameter<chain, chainOverride> &
40
+ GetContractAddressParameter<_derivedChain, "l1StandardBridge"> & {
41
+ /** L2 transaction request. */
42
+ request: DepositMNTRequest;
43
+ /**
44
+ * Gas limit for transaction execution on the L1.
45
+ */
46
+ gas?: bigint | undefined;
47
+ };
48
+ export type DepositMNTReturnType = Hash;
49
+ export type DepositMNTErrorType = WriteContractErrorType | ErrorType;
50
+
51
+ /**
52
+ * @param client - Client to use
53
+ * @param parameters - {@link DepositMNTParameters}
54
+ * @returns The L1 transaction hash. {@link DepositMNTReturnType}
55
+ */
56
+ export async function depositMNT<
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: DepositMNTParameters<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
+ targetChain,
73
+ } = parameters;
74
+
75
+ const l1StandardBridgeAddress = (() => {
76
+ if (parameters.l1StandardBridgeAddress) {
77
+ return parameters.l1StandardBridgeAddress;
78
+ }
79
+ if (chain) return targetChain!.contracts.l1StandardBridge[chain.id].address;
80
+ return Object.values(targetChain!.contracts.l1StandardBridge)[0].address;
81
+ })();
82
+
83
+ const { functionName, args } = parseDepositRequest({
84
+ type: "mnt",
85
+ amount,
86
+ to,
87
+ });
88
+
89
+ return writeContract(client, {
90
+ account: account!,
91
+ abi: l1StandardBridge,
92
+ address: l1StandardBridgeAddress,
93
+ chain,
94
+ functionName,
95
+ args,
96
+ maxFeePerGas,
97
+ maxPriorityFeePerGas,
98
+ nonce,
99
+ gas,
100
+ } satisfies WriteContractParameters as any);
101
+ }
@@ -0,0 +1,113 @@
1
+ import type { Address } from "viem";
2
+
3
+ import type { Client, Transport } from "viem";
4
+ import type { Account } from "viem";
5
+ import type { Chain, DeriveChain, GetChainParameter } from "viem";
6
+ import type { UnionEvaluate, UnionOmit } from "viem";
7
+ import {
8
+ estimateContractGas,
9
+ type EstimateContractGasErrorType,
10
+ type EstimateContractGasParameters,
11
+ } from "viem/actions";
12
+ import type { FormattedTransactionRequest } from "viem/utils";
13
+ import { l1StandardBridge } from "../abis.js";
14
+ import type { ErrorType } from "../errors/utils.js";
15
+ import type { GetAccountParameter } from "../types/account.js";
16
+ import type { GetContractAddressParameter } from "../types/contract.js";
17
+ import type { DepositERC20Request } from "../types/deposit.js";
18
+ import { parseDepositRequest } from "../utils/parseDepositRequest.js";
19
+
20
+ export type EstimateDepositERC20GasParameters<
21
+ chain extends Chain | undefined = Chain | undefined,
22
+ account extends Account | undefined = Account | undefined,
23
+ chainOverride extends Chain | undefined = Chain | undefined,
24
+ ///
25
+ derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
26
+ > = UnionEvaluate<
27
+ UnionOmit<
28
+ FormattedTransactionRequest<derivedChain>,
29
+ | "accessList"
30
+ | "data"
31
+ | "from"
32
+ | "gas"
33
+ | "gasPrice"
34
+ | "to"
35
+ | "type"
36
+ | "value"
37
+ >
38
+ > &
39
+ GetAccountParameter<account, Account | Address> &
40
+ GetChainParameter<chain, chainOverride> &
41
+ GetContractAddressParameter<derivedChain, "l1StandardBridge"> & {
42
+ /** L2 transaction request. */
43
+ request: DepositERC20Request;
44
+ /** Gas limit for transaction execution on the L1. */
45
+ gas?: bigint | undefined;
46
+ };
47
+
48
+ export type EstimateDepositERC20GasReturnType = bigint;
49
+
50
+ export type EstimateDepositERC20GasErrorType =
51
+ | EstimateContractGasErrorType
52
+ | ErrorType;
53
+
54
+ /**
55
+ * @param client - Client to use
56
+ * @param parameters - {@link EstimateDepositERC20GasParameters}
57
+ * @returns The L1 transaction hash. {@link EstimateDepositERC20GasReturnType}
58
+ */
59
+ export async function estimateDepositERC20Gas<
60
+ chain extends Chain | undefined,
61
+ account extends Account | undefined,
62
+ chainOverride extends Chain | undefined = undefined,
63
+ >(
64
+ client: Client<Transport, chain, account>,
65
+ parameters: EstimateDepositERC20GasParameters<chain, account, chainOverride>,
66
+ ) {
67
+ const {
68
+ account,
69
+ chain = client.chain,
70
+ gas,
71
+ maxFeePerGas,
72
+ maxPriorityFeePerGas,
73
+ nonce,
74
+ request: { l1Token, l2Token, amount, to },
75
+ targetChain,
76
+ } = parameters;
77
+
78
+ const l1StandardBridgeAddress = (() => {
79
+ if (parameters.l1StandardBridgeAddress) {
80
+ return parameters.l1StandardBridgeAddress;
81
+ }
82
+ if (chain) return targetChain!.contracts.l1StandardBridge[chain.id].address;
83
+ return Object.values(targetChain!.contracts.l1StandardBridge)[0].address;
84
+ })();
85
+
86
+ const { functionName, args } = parseDepositRequest({
87
+ type: "erc20",
88
+ l1Token,
89
+ l2Token,
90
+ amount,
91
+ to,
92
+ });
93
+
94
+ const params = {
95
+ account,
96
+ abi: l1StandardBridge,
97
+ address: l1StandardBridgeAddress,
98
+ functionName,
99
+ args,
100
+ gas,
101
+ maxFeePerGas,
102
+ maxPriorityFeePerGas,
103
+ nonce,
104
+ // TODO: Not sure `chain` is necessary since it's not used downstream
105
+ // in `estimateContractGas` or `estimateGas`
106
+ // @ts-ignore
107
+ chain,
108
+ } satisfies EstimateContractGasParameters<
109
+ typeof l1StandardBridge,
110
+ typeof functionName
111
+ >;
112
+ return estimateContractGas(client, params as any);
113
+ }
@@ -0,0 +1,113 @@
1
+ import type { Address } from "viem";
2
+
3
+ import type { Client, Transport } from "viem";
4
+ import type { Account } from "viem";
5
+ import type { Chain, DeriveChain, GetChainParameter } from "viem";
6
+ import type { UnionEvaluate, UnionOmit } from "viem";
7
+ import {
8
+ estimateContractGas,
9
+ type EstimateContractGasErrorType,
10
+ type EstimateContractGasParameters,
11
+ } from "viem/actions";
12
+ import type { FormattedTransactionRequest } from "viem/utils";
13
+ import { l1StandardBridge } from "../abis.js";
14
+ import type { ErrorType } from "../errors/utils.js";
15
+ import type { GetAccountParameter } from "../types/account.js";
16
+ import type { GetContractAddressParameter } from "../types/contract.js";
17
+ import type { DepositETHRequest } from "../types/deposit.js";
18
+ import { parseDepositRequest } from "../utils/parseDepositRequest.js";
19
+
20
+ export type EstimateDepositETHGasParameters<
21
+ chain extends Chain | undefined = Chain | undefined,
22
+ account extends Account | undefined = Account | undefined,
23
+ chainOverride extends Chain | undefined = Chain | undefined,
24
+ ///
25
+ derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
26
+ > = UnionEvaluate<
27
+ UnionOmit<
28
+ FormattedTransactionRequest<derivedChain>,
29
+ | "accessList"
30
+ | "data"
31
+ | "from"
32
+ | "gas"
33
+ | "gasPrice"
34
+ | "to"
35
+ | "type"
36
+ | "value"
37
+ >
38
+ > &
39
+ GetAccountParameter<account, Account | Address> &
40
+ GetChainParameter<chain, chainOverride> &
41
+ GetContractAddressParameter<derivedChain, "l1StandardBridge"> & {
42
+ /** L2 transaction request. */
43
+ request: DepositETHRequest;
44
+ /** Gas limit for transaction execution on the L1. */
45
+ gas?: bigint | undefined;
46
+ };
47
+
48
+ export type EstimateDepositETHGasReturnType = bigint;
49
+
50
+ export type EstimateDepositETHGasErrorType =
51
+ | EstimateContractGasErrorType
52
+ | ErrorType;
53
+
54
+ /**
55
+ * @param client - Client to use
56
+ * @param parameters - {@link EstimateDepositETHGasParameters}
57
+ * @returns The L1 transaction hash. {@link EstimateDepositETHGasReturnType}
58
+ */
59
+ export async function estimateDepositETHGas<
60
+ chain extends Chain | undefined,
61
+ account extends Account | undefined,
62
+ chainOverride extends Chain | undefined = undefined,
63
+ >(
64
+ client: Client<Transport, chain, account>,
65
+ parameters: EstimateDepositETHGasParameters<chain, account, chainOverride>,
66
+ ) {
67
+ const {
68
+ account,
69
+ chain = client.chain,
70
+ gas,
71
+ maxFeePerGas,
72
+ maxPriorityFeePerGas,
73
+ nonce,
74
+ request: { amount, to },
75
+ targetChain,
76
+ } = parameters;
77
+
78
+ const l1StandardBridgeAddress = (() => {
79
+ if (parameters.l1StandardBridgeAddress) {
80
+ return parameters.l1StandardBridgeAddress;
81
+ }
82
+ if (chain) return targetChain!.contracts.l1StandardBridge[chain.id].address;
83
+ return Object.values(targetChain!.contracts.l1StandardBridge)[0].address;
84
+ })();
85
+
86
+ const { functionName, args } = parseDepositRequest({
87
+ type: "eth",
88
+ amount,
89
+ to,
90
+ });
91
+
92
+ const params = {
93
+ account,
94
+ abi: l1StandardBridge,
95
+ address: l1StandardBridgeAddress,
96
+ functionName,
97
+ args,
98
+ gas,
99
+ maxFeePerGas,
100
+ maxPriorityFeePerGas,
101
+ nonce,
102
+ // TODO: Not sure `chain` is necessary since it's not used downstream
103
+ // in `estimateContractGas` or `estimateGas`
104
+ // @ts-ignore
105
+ chain,
106
+ // @ts-ignore
107
+ value: amount,
108
+ } satisfies EstimateContractGasParameters<
109
+ typeof l1StandardBridge,
110
+ typeof functionName
111
+ >;
112
+ return estimateContractGas(client, params as any);
113
+ }