viem 2.0.0-beta.8 → 2.0.0-rc.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 (474) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +9 -3
  3. package/_cjs/actions/ens/getEnsName.js +4 -2
  4. package/_cjs/actions/ens/getEnsName.js.map +1 -1
  5. package/_cjs/actions/index.js +16 -2
  6. package/_cjs/actions/index.js.map +1 -1
  7. package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
  8. package/_cjs/chains/definitions/arbitrumSepolia.js +4 -0
  9. package/_cjs/chains/definitions/arbitrumSepolia.js.map +1 -1
  10. package/_cjs/chains/definitions/base.js +5 -0
  11. package/_cjs/chains/definitions/base.js.map +1 -1
  12. package/_cjs/chains/definitions/baseGoerli.js +5 -0
  13. package/_cjs/chains/definitions/baseGoerli.js.map +1 -1
  14. package/_cjs/chains/definitions/baseSepolia.js +5 -0
  15. package/_cjs/chains/definitions/baseSepolia.js.map +1 -1
  16. package/_cjs/chains/definitions/fantomSonicTestnet.js +26 -0
  17. package/_cjs/chains/definitions/fantomSonicTestnet.js.map +1 -0
  18. package/_cjs/chains/definitions/optimism.js +5 -0
  19. package/_cjs/chains/definitions/optimism.js.map +1 -1
  20. package/_cjs/chains/definitions/optimismGoerli.js +5 -0
  21. package/_cjs/chains/definitions/optimismGoerli.js.map +1 -1
  22. package/_cjs/chains/definitions/optimismSepolia.js +5 -0
  23. package/_cjs/chains/definitions/optimismSepolia.js.map +1 -1
  24. package/_cjs/chains/definitions/pgn.js +12 -0
  25. package/_cjs/chains/definitions/pgn.js.map +1 -1
  26. package/_cjs/chains/definitions/pgnTestnet.js +7 -0
  27. package/_cjs/chains/definitions/pgnTestnet.js.map +1 -1
  28. package/_cjs/chains/definitions/zilliqa.js +26 -0
  29. package/_cjs/chains/definitions/zilliqa.js.map +1 -0
  30. package/_cjs/chains/definitions/zilliqaTestnet.js +26 -0
  31. package/_cjs/chains/definitions/zilliqaTestnet.js.map +1 -0
  32. package/_cjs/chains/definitions/zkSyncSepoliaTestnet.js +35 -0
  33. package/_cjs/chains/definitions/zkSyncSepoliaTestnet.js.map +1 -0
  34. package/_cjs/chains/definitions/zkSyncTestnet.js +4 -0
  35. package/_cjs/chains/definitions/zkSyncTestnet.js.map +1 -1
  36. package/_cjs/chains/definitions/zora.js +5 -0
  37. package/_cjs/chains/definitions/zora.js.map +1 -1
  38. package/_cjs/chains/definitions/zoraSepolia.js +5 -0
  39. package/_cjs/chains/definitions/zoraSepolia.js.map +1 -1
  40. package/_cjs/chains/index.js +12 -4
  41. package/_cjs/chains/index.js.map +1 -1
  42. package/_cjs/chains/opStack/abis.js +366 -1
  43. package/_cjs/chains/opStack/abis.js.map +1 -1
  44. package/_cjs/chains/opStack/actions/buildDepositTransaction.js +1 -1
  45. package/_cjs/chains/opStack/actions/buildDepositTransaction.js.map +1 -1
  46. package/_cjs/chains/opStack/actions/buildInitiateWithdrawal.js +29 -0
  47. package/_cjs/chains/opStack/actions/buildInitiateWithdrawal.js.map +1 -0
  48. package/_cjs/chains/opStack/actions/buildProveWithdrawal.js +39 -0
  49. package/_cjs/chains/opStack/actions/buildProveWithdrawal.js.map +1 -0
  50. package/_cjs/chains/opStack/actions/depositTransaction.js +11 -6
  51. package/_cjs/chains/opStack/actions/depositTransaction.js.map +1 -1
  52. package/_cjs/chains/opStack/actions/estimateDepositTransactionGas.js +37 -0
  53. package/_cjs/chains/opStack/actions/estimateDepositTransactionGas.js.map +1 -0
  54. package/_cjs/chains/opStack/actions/estimateFinalizeWithdrawalGas.js +29 -0
  55. package/_cjs/chains/opStack/actions/estimateFinalizeWithdrawalGas.js.map +1 -0
  56. package/_cjs/chains/opStack/actions/estimateInitiateWithdrawalGas.js +24 -0
  57. package/_cjs/chains/opStack/actions/estimateInitiateWithdrawalGas.js.map +1 -0
  58. package/_cjs/chains/opStack/actions/estimateProveWithdrawalGas.js +29 -0
  59. package/_cjs/chains/opStack/actions/estimateProveWithdrawalGas.js.map +1 -0
  60. package/_cjs/chains/opStack/actions/finalizeWithdrawal.js +33 -0
  61. package/_cjs/chains/opStack/actions/finalizeWithdrawal.js.map +1 -0
  62. package/_cjs/chains/opStack/actions/getL2Output.js +30 -0
  63. package/_cjs/chains/opStack/actions/getL2Output.js.map +1 -0
  64. package/_cjs/chains/opStack/actions/getTimeToFinalize.js +46 -0
  65. package/_cjs/chains/opStack/actions/getTimeToFinalize.js.map +1 -0
  66. package/_cjs/chains/opStack/actions/getTimeToNextL2Output.js +63 -0
  67. package/_cjs/chains/opStack/actions/getTimeToNextL2Output.js.map +1 -0
  68. package/_cjs/chains/opStack/actions/getTimeToProve.js +13 -0
  69. package/_cjs/chains/opStack/actions/getTimeToProve.js.map +1 -0
  70. package/_cjs/chains/opStack/actions/getWithdrawalStatus.js +71 -0
  71. package/_cjs/chains/opStack/actions/getWithdrawalStatus.js.map +1 -0
  72. package/_cjs/chains/opStack/actions/initiateWithdrawal.js +28 -0
  73. package/_cjs/chains/opStack/actions/initiateWithdrawal.js.map +1 -0
  74. package/_cjs/chains/opStack/actions/proveWithdrawal.js +33 -0
  75. package/_cjs/chains/opStack/actions/proveWithdrawal.js.map +1 -0
  76. package/_cjs/chains/opStack/actions/waitForNextL2Output.js +32 -0
  77. package/_cjs/chains/opStack/actions/waitForNextL2Output.js.map +1 -0
  78. package/_cjs/chains/opStack/actions/waitToFinalize.js +11 -0
  79. package/_cjs/chains/opStack/actions/waitToFinalize.js.map +1 -0
  80. package/_cjs/chains/opStack/actions/waitToProve.js +21 -0
  81. package/_cjs/chains/opStack/actions/waitToProve.js.map +1 -0
  82. package/_cjs/chains/opStack/chains.js +5 -1
  83. package/_cjs/chains/opStack/chains.js.map +1 -1
  84. package/_cjs/chains/opStack/decorators/publicL1.js +35 -0
  85. package/_cjs/chains/opStack/decorators/publicL1.js.map +1 -0
  86. package/_cjs/chains/opStack/decorators/publicL2.js +5 -1
  87. package/_cjs/chains/opStack/decorators/publicL2.js.map +1 -1
  88. package/_cjs/chains/opStack/decorators/walletL1.js +4 -0
  89. package/_cjs/chains/opStack/decorators/walletL1.js.map +1 -1
  90. package/_cjs/chains/opStack/decorators/walletL2.js +13 -0
  91. package/_cjs/chains/opStack/decorators/walletL2.js.map +1 -0
  92. package/_cjs/chains/opStack/errors/withdrawal.js +17 -0
  93. package/_cjs/chains/opStack/errors/withdrawal.js.map +1 -0
  94. package/_cjs/chains/opStack/index.js +43 -15
  95. package/_cjs/chains/opStack/index.js.map +1 -1
  96. package/_cjs/chains/opStack/types/deposit.js +3 -0
  97. package/_cjs/chains/opStack/types/deposit.js.map +1 -0
  98. package/_cjs/chains/opStack/types/withdrawal.js +3 -0
  99. package/_cjs/chains/opStack/types/withdrawal.js.map +1 -0
  100. package/_cjs/chains/opStack/utils/extractWithdrawalMessageLogs.js +14 -0
  101. package/_cjs/chains/opStack/utils/extractWithdrawalMessageLogs.js.map +1 -0
  102. package/_cjs/chains/opStack/utils/getL2TransactionHash.js +2 -2
  103. package/_cjs/chains/opStack/utils/getL2TransactionHash.js.map +1 -1
  104. package/_cjs/chains/opStack/utils/getWithdrawalHashStorageSlot.js +11 -0
  105. package/_cjs/chains/opStack/utils/getWithdrawalHashStorageSlot.js.map +1 -0
  106. package/_cjs/chains/opStack/utils/getWithdrawals.js +10 -0
  107. package/_cjs/chains/opStack/utils/getWithdrawals.js.map +1 -0
  108. package/_cjs/chains/opStack/utils/{fromOpaqueData.js → opaqueDataToDepositData.js} +4 -4
  109. package/_cjs/chains/opStack/utils/opaqueDataToDepositData.js.map +1 -0
  110. package/_cjs/errors/abi.js +21 -1
  111. package/_cjs/errors/abi.js.map +1 -1
  112. package/_cjs/errors/version.js +1 -1
  113. package/_cjs/errors/version.js.map +1 -1
  114. package/_cjs/index.js +10 -2
  115. package/_cjs/index.js.map +1 -1
  116. package/_cjs/utils/abi/getAbiItem.js +46 -3
  117. package/_cjs/utils/abi/getAbiItem.js.map +1 -1
  118. package/_cjs/utils/hash/ripemd160.js +16 -0
  119. package/_cjs/utils/hash/ripemd160.js.map +1 -0
  120. package/_cjs/utils/hash/sha256.js +16 -0
  121. package/_cjs/utils/hash/sha256.js.map +1 -0
  122. package/_cjs/utils/index.js +5 -1
  123. package/_cjs/utils/index.js.map +1 -1
  124. package/_esm/actions/ens/getEnsName.js +4 -2
  125. package/_esm/actions/ens/getEnsName.js.map +1 -1
  126. package/_esm/actions/index.js +7 -0
  127. package/_esm/actions/index.js.map +1 -1
  128. package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
  129. package/_esm/chains/definitions/arbitrumSepolia.js +4 -0
  130. package/_esm/chains/definitions/arbitrumSepolia.js.map +1 -1
  131. package/_esm/chains/definitions/base.js +5 -0
  132. package/_esm/chains/definitions/base.js.map +1 -1
  133. package/_esm/chains/definitions/baseGoerli.js +5 -0
  134. package/_esm/chains/definitions/baseGoerli.js.map +1 -1
  135. package/_esm/chains/definitions/baseSepolia.js +5 -0
  136. package/_esm/chains/definitions/baseSepolia.js.map +1 -1
  137. package/_esm/chains/definitions/fantomSonicTestnet.js +23 -0
  138. package/_esm/chains/definitions/fantomSonicTestnet.js.map +1 -0
  139. package/_esm/chains/definitions/optimism.js +5 -0
  140. package/_esm/chains/definitions/optimism.js.map +1 -1
  141. package/_esm/chains/definitions/optimismGoerli.js +5 -0
  142. package/_esm/chains/definitions/optimismGoerli.js.map +1 -1
  143. package/_esm/chains/definitions/optimismSepolia.js +5 -0
  144. package/_esm/chains/definitions/optimismSepolia.js.map +1 -1
  145. package/_esm/chains/definitions/pgn.js +12 -0
  146. package/_esm/chains/definitions/pgn.js.map +1 -1
  147. package/_esm/chains/definitions/pgnTestnet.js +7 -0
  148. package/_esm/chains/definitions/pgnTestnet.js.map +1 -1
  149. package/_esm/chains/definitions/zilliqa.js +23 -0
  150. package/_esm/chains/definitions/zilliqa.js.map +1 -0
  151. package/_esm/chains/definitions/zilliqaTestnet.js +23 -0
  152. package/_esm/chains/definitions/zilliqaTestnet.js.map +1 -0
  153. package/_esm/chains/definitions/zkSyncSepoliaTestnet.js +32 -0
  154. package/_esm/chains/definitions/zkSyncSepoliaTestnet.js.map +1 -0
  155. package/_esm/chains/definitions/zkSyncTestnet.js +5 -0
  156. package/_esm/chains/definitions/zkSyncTestnet.js.map +1 -1
  157. package/_esm/chains/definitions/zora.js +5 -0
  158. package/_esm/chains/definitions/zora.js.map +1 -1
  159. package/_esm/chains/definitions/zoraSepolia.js +5 -0
  160. package/_esm/chains/definitions/zoraSepolia.js.map +1 -1
  161. package/_esm/chains/index.js +4 -0
  162. package/_esm/chains/index.js.map +1 -1
  163. package/_esm/chains/opStack/abis.js +365 -0
  164. package/_esm/chains/opStack/abis.js.map +1 -1
  165. package/_esm/chains/opStack/actions/buildDepositTransaction.js +2 -2
  166. package/_esm/chains/opStack/actions/buildDepositTransaction.js.map +1 -1
  167. package/_esm/chains/opStack/actions/buildInitiateWithdrawal.js +50 -0
  168. package/_esm/chains/opStack/actions/buildInitiateWithdrawal.js.map +1 -0
  169. package/_esm/chains/opStack/actions/buildProveWithdrawal.js +59 -0
  170. package/_esm/chains/opStack/actions/buildProveWithdrawal.js.map +1 -0
  171. package/_esm/chains/opStack/actions/depositTransaction.js +17 -14
  172. package/_esm/chains/opStack/actions/depositTransaction.js.map +1 -1
  173. package/_esm/chains/opStack/actions/estimateDepositTransactionGas.js +62 -0
  174. package/_esm/chains/opStack/actions/estimateDepositTransactionGas.js.map +1 -0
  175. package/_esm/chains/opStack/actions/estimateFinalizeWithdrawalGas.js +50 -0
  176. package/_esm/chains/opStack/actions/estimateFinalizeWithdrawalGas.js.map +1 -0
  177. package/_esm/chains/opStack/actions/estimateInitiateWithdrawalGas.js +48 -0
  178. package/_esm/chains/opStack/actions/estimateInitiateWithdrawalGas.js.map +1 -0
  179. package/_esm/chains/opStack/actions/estimateProveWithdrawalGas.js +53 -0
  180. package/_esm/chains/opStack/actions/estimateProveWithdrawalGas.js.map +1 -0
  181. package/_esm/chains/opStack/actions/finalizeWithdrawal.js +53 -0
  182. package/_esm/chains/opStack/actions/finalizeWithdrawal.js.map +1 -0
  183. package/_esm/chains/opStack/actions/getL2Output.js +50 -0
  184. package/_esm/chains/opStack/actions/getL2Output.js.map +1 -0
  185. package/_esm/chains/opStack/actions/getTimeToFinalize.js +77 -0
  186. package/_esm/chains/opStack/actions/getTimeToFinalize.js.map +1 -0
  187. package/_esm/chains/opStack/actions/getTimeToNextL2Output.js +91 -0
  188. package/_esm/chains/opStack/actions/getTimeToNextL2Output.js.map +1 -0
  189. package/_esm/chains/opStack/actions/getTimeToProve.js +39 -0
  190. package/_esm/chains/opStack/actions/getTimeToProve.js.map +1 -0
  191. package/_esm/chains/opStack/actions/getWithdrawalStatus.js +99 -0
  192. package/_esm/chains/opStack/actions/getWithdrawalStatus.js.map +1 -0
  193. package/_esm/chains/opStack/actions/initiateWithdrawal.js +76 -0
  194. package/_esm/chains/opStack/actions/initiateWithdrawal.js.map +1 -0
  195. package/_esm/chains/opStack/actions/proveWithdrawal.js +57 -0
  196. package/_esm/chains/opStack/actions/proveWithdrawal.js.map +1 -0
  197. package/_esm/chains/opStack/actions/waitForNextL2Output.js +58 -0
  198. package/_esm/chains/opStack/actions/waitForNextL2Output.js.map +1 -0
  199. package/_esm/chains/opStack/actions/waitToFinalize.js +41 -0
  200. package/_esm/chains/opStack/actions/waitToFinalize.js.map +1 -0
  201. package/_esm/chains/opStack/actions/waitToProve.js +47 -0
  202. package/_esm/chains/opStack/actions/waitToProve.js.map +1 -0
  203. package/_esm/chains/opStack/chains.js +2 -0
  204. package/_esm/chains/opStack/chains.js.map +1 -1
  205. package/_esm/chains/opStack/decorators/publicL1.js +31 -0
  206. package/_esm/chains/opStack/decorators/publicL1.js.map +1 -0
  207. package/_esm/chains/opStack/decorators/publicL2.js +5 -1
  208. package/_esm/chains/opStack/decorators/publicL2.js.map +1 -1
  209. package/_esm/chains/opStack/decorators/walletL1.js +4 -0
  210. package/_esm/chains/opStack/decorators/walletL1.js.map +1 -1
  211. package/_esm/chains/opStack/decorators/walletL2.js +9 -0
  212. package/_esm/chains/opStack/decorators/walletL2.js.map +1 -0
  213. package/_esm/chains/opStack/errors/withdrawal.js +13 -0
  214. package/_esm/chains/opStack/errors/withdrawal.js.map +1 -0
  215. package/_esm/chains/opStack/index.js +21 -3
  216. package/_esm/chains/opStack/index.js.map +1 -1
  217. package/_esm/chains/opStack/types/deposit.js +2 -0
  218. package/_esm/chains/opStack/types/deposit.js.map +1 -0
  219. package/_esm/chains/opStack/types/withdrawal.js +2 -0
  220. package/_esm/chains/opStack/types/withdrawal.js.map +1 -0
  221. package/_esm/chains/opStack/utils/extractWithdrawalMessageLogs.js +10 -0
  222. package/_esm/chains/opStack/utils/extractWithdrawalMessageLogs.js.map +1 -0
  223. package/_esm/chains/opStack/utils/getL2TransactionHash.js +2 -2
  224. package/_esm/chains/opStack/utils/getL2TransactionHash.js.map +1 -1
  225. package/_esm/chains/opStack/utils/getWithdrawalHashStorageSlot.js +7 -0
  226. package/_esm/chains/opStack/utils/getWithdrawalHashStorageSlot.js.map +1 -0
  227. package/_esm/chains/opStack/utils/getWithdrawals.js +6 -0
  228. package/_esm/chains/opStack/utils/getWithdrawals.js.map +1 -0
  229. package/_esm/chains/opStack/utils/{fromOpaqueData.js → opaqueDataToDepositData.js} +2 -2
  230. package/_esm/chains/opStack/utils/opaqueDataToDepositData.js.map +1 -0
  231. package/_esm/errors/abi.js +19 -0
  232. package/_esm/errors/abi.js.map +1 -1
  233. package/_esm/errors/version.js +1 -1
  234. package/_esm/errors/version.js.map +1 -1
  235. package/_esm/index.js +4 -0
  236. package/_esm/index.js.map +1 -1
  237. package/_esm/utils/abi/getAbiItem.js +46 -2
  238. package/_esm/utils/abi/getAbiItem.js.map +1 -1
  239. package/_esm/utils/hash/ripemd160.js +12 -0
  240. package/_esm/utils/hash/ripemd160.js.map +1 -0
  241. package/_esm/utils/hash/sha256.js +12 -0
  242. package/_esm/utils/hash/sha256.js.map +1 -0
  243. package/_esm/utils/index.js +2 -0
  244. package/_esm/utils/index.js.map +1 -1
  245. package/_types/actions/ens/getEnsName.d.ts.map +1 -1
  246. package/_types/actions/index.d.ts +7 -0
  247. package/_types/actions/index.d.ts.map +1 -1
  248. package/_types/actions/public/getBlock.d.ts +1 -1
  249. package/_types/actions/public/getBlock.d.ts.map +1 -1
  250. package/_types/actions/public/getTransaction.d.ts +1 -1
  251. package/_types/actions/public/getTransaction.d.ts.map +1 -1
  252. package/_types/actions/public/getTransactionReceipt.d.ts +1 -1
  253. package/_types/actions/public/getTransactionReceipt.d.ts.map +1 -1
  254. package/_types/actions/wallet/prepareTransactionRequest.d.ts +5 -5
  255. package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
  256. package/_types/chains/celo/chainConfig.d.ts +180 -180
  257. package/_types/chains/celo/formatters.d.ts +180 -180
  258. package/_types/chains/definitions/arbitrumSepolia.d.ts +4 -0
  259. package/_types/chains/definitions/arbitrumSepolia.d.ts.map +1 -1
  260. package/_types/chains/definitions/base.d.ts +142 -137
  261. package/_types/chains/definitions/base.d.ts.map +1 -1
  262. package/_types/chains/definitions/baseGoerli.d.ts +142 -137
  263. package/_types/chains/definitions/baseGoerli.d.ts.map +1 -1
  264. package/_types/chains/definitions/baseSepolia.d.ts +142 -137
  265. package/_types/chains/definitions/baseSepolia.d.ts.map +1 -1
  266. package/_types/chains/definitions/celo.d.ts +180 -180
  267. package/_types/chains/definitions/celoAlfajores.d.ts +180 -180
  268. package/_types/chains/definitions/celoCannoli.d.ts +180 -180
  269. package/_types/chains/definitions/fantomSonicTestnet.d.ts +38 -0
  270. package/_types/chains/definitions/fantomSonicTestnet.d.ts.map +1 -0
  271. package/_types/chains/definitions/optimism.d.ts +142 -137
  272. package/_types/chains/definitions/optimism.d.ts.map +1 -1
  273. package/_types/chains/definitions/optimismGoerli.d.ts +142 -137
  274. package/_types/chains/definitions/optimismGoerli.d.ts.map +1 -1
  275. package/_types/chains/definitions/optimismSepolia.d.ts +142 -137
  276. package/_types/chains/definitions/optimismSepolia.d.ts.map +1 -1
  277. package/_types/chains/definitions/pgn.d.ts +147 -137
  278. package/_types/chains/definitions/pgn.d.ts.map +1 -1
  279. package/_types/chains/definitions/pgnTestnet.d.ts +142 -137
  280. package/_types/chains/definitions/pgnTestnet.d.ts.map +1 -1
  281. package/_types/chains/definitions/zilliqa.d.ts +38 -0
  282. package/_types/chains/definitions/zilliqa.d.ts.map +1 -0
  283. package/_types/chains/definitions/zilliqaTestnet.d.ts +38 -0
  284. package/_types/chains/definitions/zilliqaTestnet.d.ts.map +1 -0
  285. package/_types/chains/definitions/zkSync.d.ts +24 -24
  286. package/_types/chains/definitions/zkSyncSepoliaTestnet.d.ts +533 -0
  287. package/_types/chains/definitions/zkSyncSepoliaTestnet.d.ts.map +1 -0
  288. package/_types/chains/definitions/zkSyncTestnet.d.ts +29 -24
  289. package/_types/chains/definitions/zkSyncTestnet.d.ts.map +1 -1
  290. package/_types/chains/definitions/zora.d.ts +142 -137
  291. package/_types/chains/definitions/zora.d.ts.map +1 -1
  292. package/_types/chains/definitions/zoraSepolia.d.ts +142 -137
  293. package/_types/chains/definitions/zoraSepolia.d.ts.map +1 -1
  294. package/_types/chains/definitions/zoraTestnet.d.ts +137 -137
  295. package/_types/chains/index.d.ts +5 -1
  296. package/_types/chains/index.d.ts.map +1 -1
  297. package/_types/chains/opStack/abis.d.ts +457 -0
  298. package/_types/chains/opStack/abis.d.ts.map +1 -1
  299. package/_types/chains/opStack/actions/buildDepositTransaction.d.ts +5 -3
  300. package/_types/chains/opStack/actions/buildDepositTransaction.d.ts.map +1 -1
  301. package/_types/chains/opStack/actions/buildInitiateWithdrawal.d.ts +50 -0
  302. package/_types/chains/opStack/actions/buildInitiateWithdrawal.d.ts.map +1 -0
  303. package/_types/chains/opStack/actions/buildProveWithdrawal.d.ts +48 -0
  304. package/_types/chains/opStack/actions/buildProveWithdrawal.d.ts.map +1 -0
  305. package/_types/chains/opStack/actions/depositTransaction.d.ts +18 -34
  306. package/_types/chains/opStack/actions/depositTransaction.d.ts.map +1 -1
  307. package/_types/chains/opStack/actions/estimateDepositTransactionGas.d.ts +50 -0
  308. package/_types/chains/opStack/actions/estimateDepositTransactionGas.d.ts.map +1 -0
  309. package/_types/chains/opStack/actions/estimateFinalizeWithdrawalGas.d.ts +45 -0
  310. package/_types/chains/opStack/actions/estimateFinalizeWithdrawalGas.d.ts.map +1 -0
  311. package/_types/chains/opStack/actions/estimateInitiateWithdrawalGas.d.ts +51 -0
  312. package/_types/chains/opStack/actions/estimateInitiateWithdrawalGas.d.ts.map +1 -0
  313. package/_types/chains/opStack/actions/estimateProveWithdrawalGas.d.ts +63 -0
  314. package/_types/chains/opStack/actions/estimateProveWithdrawalGas.d.ts.map +1 -0
  315. package/_types/chains/opStack/actions/finalizeWithdrawal.d.ts +49 -0
  316. package/_types/chains/opStack/actions/finalizeWithdrawal.d.ts.map +1 -0
  317. package/_types/chains/opStack/actions/getL2Output.d.ts +44 -0
  318. package/_types/chains/opStack/actions/getL2Output.d.ts.map +1 -0
  319. package/_types/chains/opStack/actions/getTimeToFinalize.d.ts +57 -0
  320. package/_types/chains/opStack/actions/getTimeToFinalize.d.ts.map +1 -0
  321. package/_types/chains/opStack/actions/getTimeToNextL2Output.d.ts +61 -0
  322. package/_types/chains/opStack/actions/getTimeToNextL2Output.d.ts.map +1 -0
  323. package/_types/chains/opStack/actions/getTimeToProve.d.ts +50 -0
  324. package/_types/chains/opStack/actions/getTimeToProve.d.ts.map +1 -0
  325. package/_types/chains/opStack/actions/getWithdrawalStatus.d.ts +48 -0
  326. package/_types/chains/opStack/actions/getWithdrawalStatus.d.ts.map +1 -0
  327. package/_types/chains/opStack/actions/initiateWithdrawal.d.ts +77 -0
  328. package/_types/chains/opStack/actions/initiateWithdrawal.d.ts.map +1 -0
  329. package/_types/chains/opStack/actions/proveWithdrawal.d.ts +67 -0
  330. package/_types/chains/opStack/actions/proveWithdrawal.d.ts.map +1 -0
  331. package/_types/chains/opStack/actions/waitForNextL2Output.d.ts +55 -0
  332. package/_types/chains/opStack/actions/waitForNextL2Output.d.ts.map +1 -0
  333. package/_types/chains/opStack/actions/waitToFinalize.d.ts +45 -0
  334. package/_types/chains/opStack/actions/waitToFinalize.d.ts.map +1 -0
  335. package/_types/chains/opStack/actions/waitToProve.d.ts +55 -0
  336. package/_types/chains/opStack/actions/waitToProve.d.ts.map +1 -0
  337. package/_types/chains/opStack/chainConfig.d.ts +136 -136
  338. package/_types/chains/opStack/chains.d.ts +2 -0
  339. package/_types/chains/opStack/chains.d.ts.map +1 -1
  340. package/_types/chains/opStack/decorators/publicL1.d.ts +386 -0
  341. package/_types/chains/opStack/decorators/publicL1.d.ts.map +1 -0
  342. package/_types/chains/opStack/decorators/publicL2.d.ts +82 -26
  343. package/_types/chains/opStack/decorators/publicL2.d.ts.map +1 -1
  344. package/_types/chains/opStack/decorators/walletL1.d.ts +57 -2
  345. package/_types/chains/opStack/decorators/walletL1.d.ts.map +1 -1
  346. package/_types/chains/opStack/decorators/walletL2.d.ts +62 -0
  347. package/_types/chains/opStack/decorators/walletL2.d.ts.map +1 -0
  348. package/_types/chains/opStack/errors/withdrawal.d.ts +12 -0
  349. package/_types/chains/opStack/errors/withdrawal.d.ts.map +1 -0
  350. package/_types/chains/opStack/formatters.d.ts +136 -136
  351. package/_types/chains/opStack/index.d.ts +21 -3
  352. package/_types/chains/opStack/index.d.ts.map +1 -1
  353. package/_types/chains/opStack/types/deposit.d.ts +25 -0
  354. package/_types/chains/opStack/types/deposit.d.ts.map +1 -0
  355. package/_types/chains/opStack/types/withdrawal.d.ts +22 -0
  356. package/_types/chains/opStack/types/withdrawal.d.ts.map +1 -0
  357. package/_types/chains/opStack/utils/extractWithdrawalMessageLogs.d.ts +137 -0
  358. package/_types/chains/opStack/utils/extractWithdrawalMessageLogs.d.ts.map +1 -0
  359. package/_types/chains/opStack/utils/getWithdrawalHashStorageSlot.d.ts +11 -0
  360. package/_types/chains/opStack/utils/getWithdrawalHashStorageSlot.d.ts.map +1 -0
  361. package/_types/chains/opStack/utils/getWithdrawals.d.ts +12 -0
  362. package/_types/chains/opStack/utils/getWithdrawals.d.ts.map +1 -0
  363. package/_types/chains/opStack/utils/opaqueDataToDepositData.d.ts +15 -0
  364. package/_types/chains/opStack/utils/opaqueDataToDepositData.d.ts.map +1 -0
  365. package/_types/chains/zksync/chainConfig.d.ts +24 -24
  366. package/_types/chains/zksync/formatters.d.ts +24 -24
  367. package/_types/clients/decorators/public.d.ts +2 -2
  368. package/_types/clients/decorators/public.d.ts.map +1 -1
  369. package/_types/clients/decorators/wallet.d.ts +2 -2
  370. package/_types/clients/decorators/wallet.d.ts.map +1 -1
  371. package/_types/errors/abi.d.ts +14 -1
  372. package/_types/errors/abi.d.ts.map +1 -1
  373. package/_types/errors/version.d.ts +1 -1
  374. package/_types/errors/version.d.ts.map +1 -1
  375. package/_types/index.d.ts +15 -1
  376. package/_types/index.d.ts.map +1 -1
  377. package/_types/types/account.d.ts +1 -1
  378. package/_types/types/account.d.ts.map +1 -1
  379. package/_types/types/eip1193.d.ts +12 -0
  380. package/_types/types/eip1193.d.ts.map +1 -1
  381. package/_types/utils/abi/getAbiItem.d.ts +2 -1
  382. package/_types/utils/abi/getAbiItem.d.ts.map +1 -1
  383. package/_types/utils/formatters/block.d.ts +1 -1
  384. package/_types/utils/formatters/block.d.ts.map +1 -1
  385. package/_types/utils/formatters/transaction.d.ts +2 -2
  386. package/_types/utils/formatters/transaction.d.ts.map +1 -1
  387. package/_types/utils/formatters/transactionReceipt.d.ts +1 -1
  388. package/_types/utils/formatters/transactionReceipt.d.ts.map +1 -1
  389. package/_types/utils/formatters/transactionRequest.d.ts +1 -1
  390. package/_types/utils/hash/ripemd160.d.ts +11 -0
  391. package/_types/utils/hash/ripemd160.d.ts.map +1 -0
  392. package/_types/utils/hash/sha256.d.ts +11 -0
  393. package/_types/utils/hash/sha256.d.ts.map +1 -0
  394. package/_types/utils/index.d.ts +2 -0
  395. package/_types/utils/index.d.ts.map +1 -1
  396. package/actions/ens/getEnsName.ts +3 -2
  397. package/actions/index.ts +31 -0
  398. package/actions/public/getBlock.ts +1 -1
  399. package/actions/public/getTransaction.ts +1 -1
  400. package/actions/public/getTransactionReceipt.ts +1 -1
  401. package/actions/wallet/prepareTransactionRequest.ts +16 -9
  402. package/chains/definitions/arbitrumSepolia.ts +4 -0
  403. package/chains/definitions/base.ts +5 -0
  404. package/chains/definitions/baseGoerli.ts +5 -0
  405. package/chains/definitions/baseSepolia.ts +5 -0
  406. package/chains/definitions/fantomSonicTestnet.ts +23 -0
  407. package/chains/definitions/optimism.ts +5 -0
  408. package/chains/definitions/optimismGoerli.ts +5 -0
  409. package/chains/definitions/optimismSepolia.ts +5 -0
  410. package/chains/definitions/pgn.ts +13 -0
  411. package/chains/definitions/pgnTestnet.ts +8 -0
  412. package/chains/definitions/zilliqa.ts +23 -0
  413. package/chains/definitions/zilliqaTestnet.ts +23 -0
  414. package/chains/definitions/zkSyncSepoliaTestnet.ts +32 -0
  415. package/chains/definitions/zkSyncTestnet.ts +5 -0
  416. package/chains/definitions/zora.ts +5 -0
  417. package/chains/definitions/zoraSepolia.ts +5 -0
  418. package/chains/index.ts +9 -0
  419. package/chains/opStack/abis.ts +367 -0
  420. package/chains/opStack/actions/buildDepositTransaction.ts +11 -6
  421. package/chains/opStack/actions/buildInitiateWithdrawal.ts +118 -0
  422. package/chains/opStack/actions/buildProveWithdrawal.ts +149 -0
  423. package/chains/opStack/actions/depositTransaction.ts +50 -44
  424. package/chains/opStack/actions/estimateDepositTransactionGas.ts +138 -0
  425. package/chains/opStack/actions/estimateFinalizeWithdrawalGas.ts +118 -0
  426. package/chains/opStack/actions/estimateInitiateWithdrawalGas.ts +118 -0
  427. package/chains/opStack/actions/estimateProveWithdrawalGas.ts +139 -0
  428. package/chains/opStack/actions/finalizeWithdrawal.ts +130 -0
  429. package/chains/opStack/actions/getL2Output.ts +89 -0
  430. package/chains/opStack/actions/getTimeToFinalize.ts +122 -0
  431. package/chains/opStack/actions/getTimeToNextL2Output.ts +162 -0
  432. package/chains/opStack/actions/getTimeToProve.ts +79 -0
  433. package/chains/opStack/actions/getWithdrawalStatus.ts +152 -0
  434. package/chains/opStack/actions/initiateWithdrawal.ts +153 -0
  435. package/chains/opStack/actions/proveWithdrawal.ts +151 -0
  436. package/chains/opStack/actions/waitForNextL2Output.ts +111 -0
  437. package/chains/opStack/actions/waitToFinalize.ts +64 -0
  438. package/chains/opStack/actions/waitToProve.ts +99 -0
  439. package/chains/opStack/chains.ts +2 -0
  440. package/chains/opStack/decorators/publicL1.ts +514 -0
  441. package/chains/opStack/decorators/publicL2.ts +129 -37
  442. package/chains/opStack/decorators/walletL1.ts +71 -2
  443. package/chains/opStack/decorators/walletL2.ts +84 -0
  444. package/chains/opStack/errors/withdrawal.ts +15 -0
  445. package/chains/opStack/index.ts +112 -21
  446. package/chains/opStack/types/deposit.ts +28 -0
  447. package/chains/opStack/types/withdrawal.ts +23 -0
  448. package/chains/opStack/utils/extractWithdrawalMessageLogs.ts +36 -0
  449. package/chains/opStack/utils/getL2TransactionHash.ts +2 -2
  450. package/chains/opStack/utils/getWithdrawalHashStorageSlot.ts +29 -0
  451. package/chains/opStack/utils/getWithdrawals.ts +25 -0
  452. package/chains/opStack/utils/{fromOpaqueData.ts → opaqueDataToDepositData.ts} +9 -4
  453. package/clients/decorators/public.ts +2 -2
  454. package/clients/decorators/wallet.ts +2 -2
  455. package/errors/abi.ts +22 -1
  456. package/errors/version.ts +1 -1
  457. package/index.ts +40 -0
  458. package/package.json +1 -1
  459. package/types/account.ts +1 -1
  460. package/types/eip1193.ts +12 -0
  461. package/utils/abi/getAbiItem.ts +71 -2
  462. package/utils/formatters/block.ts +1 -1
  463. package/utils/formatters/transaction.ts +1 -1
  464. package/utils/formatters/transactionReceipt.ts +1 -1
  465. package/utils/hash/ripemd160.ts +31 -0
  466. package/utils/hash/sha256.ts +31 -0
  467. package/utils/index.ts +2 -0
  468. package/_cjs/chains/opStack/utils/fromOpaqueData.js.map +0 -1
  469. package/_esm/chains/opStack/utils/fromOpaqueData.js.map +0 -1
  470. package/_types/chains/opStack/utils/fromOpaqueData.d.ts +0 -15
  471. package/_types/chains/opStack/utils/fromOpaqueData.d.ts.map +0 -1
  472. package/chains/celo/package.json +0 -6
  473. package/chains/opStack/package.json +0 -6
  474. package/chains/zksync/package.json +0 -6
@@ -0,0 +1,152 @@
1
+ import {
2
+ type ReadContractErrorType,
3
+ readContract,
4
+ } from '../../../actions/public/readContract.js'
5
+ import type { Client } from '../../../clients/createClient.js'
6
+ import type { Transport } from '../../../clients/transports/createTransport.js'
7
+ import { ContractFunctionRevertedError } from '../../../errors/contract.js'
8
+ import type { ErrorType } from '../../../errors/utils.js'
9
+ import type { Account } from '../../../types/account.js'
10
+ import type {
11
+ Chain,
12
+ DeriveChain,
13
+ GetChainParameter,
14
+ } from '../../../types/chain.js'
15
+ import type { TransactionReceipt } from '../../../types/transaction.js'
16
+ import { portalAbi } from '../abis.js'
17
+ import { ReceiptContainsNoWithdrawalsError } from '../errors/withdrawal.js'
18
+ import type { GetContractAddressParameter } from '../types/contract.js'
19
+ import {
20
+ type GetWithdrawalsErrorType,
21
+ getWithdrawals,
22
+ } from '../utils/getWithdrawals.js'
23
+ import { type GetL2OutputErrorType, getL2Output } from './getL2Output.js'
24
+ import {
25
+ type GetTimeToFinalizeErrorType,
26
+ getTimeToFinalize,
27
+ } from './getTimeToFinalize.js'
28
+
29
+ export type GetWithdrawalStatusParameters<
30
+ chain extends Chain | undefined = Chain | undefined,
31
+ chainOverride extends Chain | undefined = Chain | undefined,
32
+ _derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
33
+ > = GetChainParameter<chain, chainOverride> &
34
+ GetContractAddressParameter<_derivedChain, 'l2OutputOracle' | 'portal'> & {
35
+ receipt: TransactionReceipt
36
+ }
37
+ export type GetWithdrawalStatusReturnType =
38
+ | 'waiting-to-prove'
39
+ | 'ready-to-prove'
40
+ | 'waiting-to-finalize'
41
+ | 'ready-to-finalize'
42
+ | 'finalized'
43
+ export type GetWithdrawalStatusErrorType =
44
+ | GetL2OutputErrorType
45
+ | GetTimeToFinalizeErrorType
46
+ | GetWithdrawalsErrorType
47
+ | ReadContractErrorType
48
+ | ErrorType
49
+
50
+ /**
51
+ * Returns the current status of a withdrawal. Used for the [Withdrawal](/op-stack/guides/withdrawals.html) flow.
52
+ *
53
+ * - Docs: https://viem.sh/op-stack/actions/getWithdrawalStatus.html
54
+ *
55
+ * @param client - Client to use
56
+ * @param parameters - {@link GetWithdrawalStatusParameters}
57
+ * @returns Status of the withdrawal. {@link GetWithdrawalStatusReturnType}
58
+ *
59
+ * @example
60
+ * import { createPublicClient, http } from 'viem'
61
+ * import { getBlockNumber } from 'viem/actions'
62
+ * import { mainnet, optimism } from 'viem/chains'
63
+ * import { getWithdrawalStatus } from 'viem/op-stack'
64
+ *
65
+ * const publicClientL1 = createPublicClient({
66
+ * chain: mainnet,
67
+ * transport: http(),
68
+ * })
69
+ * const publicClientL2 = createPublicClient({
70
+ * chain: optimism,
71
+ * transport: http(),
72
+ * })
73
+ *
74
+ * const receipt = await getTransactionReceipt(publicClientL2, { hash: '0x...' })
75
+ * const status = await getWithdrawalStatus(publicClientL1, {
76
+ * receipt,
77
+ * targetChain: optimism
78
+ * })
79
+ */
80
+ export async function getWithdrawalStatus<
81
+ chain extends Chain | undefined,
82
+ account extends Account | undefined,
83
+ chainOverride extends Chain | undefined = undefined,
84
+ >(
85
+ client: Client<Transport, chain, account>,
86
+ parameters: GetWithdrawalStatusParameters<chain, chainOverride>,
87
+ ): Promise<GetWithdrawalStatusReturnType> {
88
+ const { chain = client.chain, receipt, targetChain } = parameters
89
+
90
+ const portalAddress = (() => {
91
+ if (parameters.portalAddress) return parameters.portalAddress
92
+ if (chain) return targetChain!.contracts.portal[chain.id].address
93
+ return Object.values(targetChain!.contracts.portal)[0].address
94
+ })()
95
+
96
+ const [withdrawal] = getWithdrawals(receipt)
97
+
98
+ if (!withdrawal)
99
+ throw new ReceiptContainsNoWithdrawalsError({
100
+ hash: receipt.transactionHash,
101
+ })
102
+
103
+ const [outputResult, proveResult, finalizedResult, timeToFinalizeResult] =
104
+ await Promise.allSettled([
105
+ getL2Output(client, {
106
+ ...parameters,
107
+ l2BlockNumber: receipt.blockNumber,
108
+ }),
109
+ readContract(client, {
110
+ abi: portalAbi,
111
+ address: portalAddress,
112
+ functionName: 'provenWithdrawals',
113
+ args: [withdrawal.withdrawalHash],
114
+ }),
115
+ readContract(client, {
116
+ abi: portalAbi,
117
+ address: portalAddress,
118
+ functionName: 'finalizedWithdrawals',
119
+ args: [withdrawal.withdrawalHash],
120
+ }),
121
+ getTimeToFinalize(client, {
122
+ ...parameters,
123
+ withdrawalHash: withdrawal.withdrawalHash,
124
+ }),
125
+ ])
126
+
127
+ // If the L2 Output is not processed yet (ie. the actions throws), this means
128
+ // that the withdrawal is not ready to prove.
129
+ if (outputResult.status === 'rejected') {
130
+ const error = outputResult.reason as GetL2OutputErrorType
131
+ if (
132
+ error.cause instanceof ContractFunctionRevertedError &&
133
+ error.cause.data?.args?.[0] ===
134
+ 'L2OutputOracle: cannot get output for a block that has not been proposed'
135
+ )
136
+ return 'waiting-to-prove'
137
+ throw error
138
+ }
139
+ if (proveResult.status === 'rejected') throw proveResult.reason
140
+ if (finalizedResult.status === 'rejected') throw finalizedResult.reason
141
+ if (timeToFinalizeResult.status === 'rejected')
142
+ throw timeToFinalizeResult.reason
143
+
144
+ const [_, proveTimestamp] = proveResult.value
145
+ if (!proveTimestamp) return 'ready-to-prove'
146
+
147
+ const finalized = finalizedResult.value
148
+ if (finalized) return 'finalized'
149
+
150
+ const { seconds } = timeToFinalizeResult.value
151
+ return seconds > 0 ? 'waiting-to-finalize' : 'ready-to-finalize'
152
+ }
@@ -0,0 +1,153 @@
1
+ import type { Address } from 'abitype'
2
+ import {
3
+ type WriteContractErrorType,
4
+ type WriteContractParameters,
5
+ writeContract,
6
+ } from '../../../actions/wallet/writeContract.js'
7
+ import type { Client } from '../../../clients/createClient.js'
8
+ import type { Transport } from '../../../clients/transports/createTransport.js'
9
+ import type { ErrorType } from '../../../errors/utils.js'
10
+ import type { Account, GetAccountParameter } from '../../../types/account.js'
11
+ import type {
12
+ Chain,
13
+ DeriveChain,
14
+ GetChainParameter,
15
+ } from '../../../types/chain.js'
16
+ import type { Hash } from '../../../types/misc.js'
17
+ import type { UnionEvaluate, UnionOmit } from '../../../types/utils.js'
18
+ import type { FormattedTransactionRequest } from '../../../utils/formatters/transactionRequest.js'
19
+ import { l2ToL1MessagePasserAbi } from '../abis.js'
20
+ import { contracts } from '../contracts.js'
21
+ import type { WithdrawalRequest } from '../types/withdrawal.js'
22
+ import {
23
+ type EstimateInitiateWithdrawalGasErrorType,
24
+ type EstimateInitiateWithdrawalGasParameters,
25
+ estimateInitiateWithdrawalGas,
26
+ } from './estimateInitiateWithdrawalGas.js'
27
+
28
+ export type InitiateWithdrawalParameters<
29
+ chain extends Chain | undefined = Chain | undefined,
30
+ account extends Account | undefined = Account | undefined,
31
+ chainOverride extends Chain | undefined = Chain | undefined,
32
+ _derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
33
+ > = UnionEvaluate<
34
+ UnionOmit<
35
+ FormattedTransactionRequest<_derivedChain>,
36
+ | 'accessList'
37
+ | 'data'
38
+ | 'from'
39
+ | 'gas'
40
+ | 'gasPrice'
41
+ | 'to'
42
+ | 'type'
43
+ | 'value'
44
+ >
45
+ > &
46
+ GetAccountParameter<account, Account | Address> &
47
+ GetChainParameter<chain, chainOverride> & {
48
+ /**
49
+ * Gas limit for transaction execution on the L2.
50
+ * `null` to skip gas estimation & defer calculation to signer.
51
+ */
52
+ gas?: bigint | null
53
+ /** Withdrawal request. Supplied to the L2ToL1MessagePasser `initiateWithdrawal` method. */
54
+ request: WithdrawalRequest
55
+ }
56
+ export type InitiateWithdrawalReturnType = Hash
57
+ export type InitiateWithdrawalErrorType =
58
+ | EstimateInitiateWithdrawalGasErrorType
59
+ | WriteContractErrorType
60
+ | ErrorType
61
+
62
+ /**
63
+ * Initiates a [withdrawal](https://community.optimism.io/docs/protocol/withdrawal-flow/#withdrawal-initiating-transaction) on an L2 to the L1.
64
+ *
65
+ * Internally performs a contract write to the [`initiateWithdrawal` function](https://github.com/ethereum-optimism/optimism/blob/283f0aa2e3358ced30ff7cbd4028c0c0c3faa140/packages/contracts-bedrock/src/L2/L2ToL1MessagePasser.sol#L73)
66
+ * on the [Optimism L2ToL1MessagePasser predeploy contract](https://github.com/ethereum-optimism/optimism/blob/283f0aa2e3358ced30ff7cbd4028c0c0c3faa140/packages/contracts-bedrock/src/L2/L2ToL1MessagePasser.sol).
67
+ *
68
+ * - Docs: https://viem.sh/op-stack/actions/initiateWithdrawal.html
69
+ *
70
+ * @param client - Client to use
71
+ * @param parameters - {@link InitiateWithdrawalParameters}
72
+ * @returns The L2 transaction hash. {@link InitiateWithdrawalReturnType}
73
+ *
74
+ * @example
75
+ * import { createWalletClient, custom, parseEther } from 'viem'
76
+ * import { base, mainnet } from 'viem/chains'
77
+ * import { initiateWithdrawal } from 'viem/op-stack'
78
+ *
79
+ * const client = createWalletClient({
80
+ * chain: mainnet,
81
+ * transport: custom(window.ethereum),
82
+ * })
83
+ *
84
+ * const hash = await initiateWithdrawal(client, {
85
+ * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
86
+ * args: {
87
+ * gas: 21_000n,
88
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
89
+ * value: parseEther('1'),
90
+ * },
91
+ * })
92
+ *
93
+ * @example
94
+ * // Account Hoisting
95
+ * import { createWalletClient, http } from 'viem'
96
+ * import { privateKeyToAccount } from 'viem/accounts'
97
+ * import { base, mainnet } from 'viem/chains'
98
+ * import { initiateWithdrawal } from 'viem/op-stack'
99
+ *
100
+ * const client = createWalletClient({
101
+ * account: privateKeyToAccount('0x…'),
102
+ * chain: mainnet,
103
+ * transport: http(),
104
+ * })
105
+ *
106
+ * const hash = await initiateWithdrawal(client, {
107
+ * request: {
108
+ * gas: 21_000n,
109
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
110
+ * value: parseEther('1'),
111
+ * },
112
+ * })
113
+ */
114
+ export async function initiateWithdrawal<
115
+ chain extends Chain | undefined,
116
+ account extends Account | undefined,
117
+ chainOverride extends Chain | undefined = undefined,
118
+ >(
119
+ client: Client<Transport, chain, account>,
120
+ parameters: InitiateWithdrawalParameters<chain, account, chainOverride>,
121
+ ) {
122
+ const {
123
+ account,
124
+ chain = client.chain,
125
+ gas,
126
+ maxFeePerGas,
127
+ maxPriorityFeePerGas,
128
+ nonce,
129
+ request: { data = '0x', gas: l1Gas, to, value },
130
+ } = parameters
131
+
132
+ const gas_ =
133
+ typeof gas !== 'number' && gas !== null
134
+ ? await estimateInitiateWithdrawalGas(
135
+ client,
136
+ parameters as EstimateInitiateWithdrawalGasParameters,
137
+ )
138
+ : undefined
139
+
140
+ return writeContract(client, {
141
+ account: account!,
142
+ abi: l2ToL1MessagePasserAbi,
143
+ address: contracts.l2ToL1MessagePasser.address,
144
+ chain,
145
+ functionName: 'initiateWithdrawal',
146
+ args: [to, l1Gas, data],
147
+ gas: gas_,
148
+ maxFeePerGas,
149
+ maxPriorityFeePerGas,
150
+ nonce,
151
+ value,
152
+ } satisfies WriteContractParameters as any)
153
+ }
@@ -0,0 +1,151 @@
1
+ import type { Address } from 'abitype'
2
+ import {
3
+ type WriteContractErrorType,
4
+ writeContract,
5
+ } from '../../../actions/wallet/writeContract.js'
6
+ import type { Client } from '../../../clients/createClient.js'
7
+ import type { Transport } from '../../../clients/transports/createTransport.js'
8
+ import type { ErrorType } from '../../../errors/utils.js'
9
+ import type { Account, GetAccountParameter } from '../../../types/account.js'
10
+ import type {
11
+ Chain,
12
+ DeriveChain,
13
+ GetChainParameter,
14
+ } from '../../../types/chain.js'
15
+ import type { Hash, Hex } from '../../../types/misc.js'
16
+ import type { UnionEvaluate, UnionOmit } from '../../../types/utils.js'
17
+ import type { FormattedTransactionRequest } from '../../../utils/formatters/transactionRequest.js'
18
+ import { portalAbi } from '../abis.js'
19
+ import type { GetContractAddressParameter } from '../types/contract.js'
20
+ import {
21
+ type EstimateProveWithdrawalGasErrorType,
22
+ type EstimateProveWithdrawalGasParameters,
23
+ estimateProveWithdrawalGas,
24
+ } from './estimateProveWithdrawalGas.js'
25
+
26
+ export type ProveWithdrawalParameters<
27
+ chain extends Chain | undefined = Chain | undefined,
28
+ account extends Account | undefined = Account | undefined,
29
+ chainOverride extends Chain | undefined = Chain | undefined,
30
+ _derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
31
+ > = UnionEvaluate<
32
+ UnionOmit<
33
+ FormattedTransactionRequest<_derivedChain>,
34
+ | 'accessList'
35
+ | 'data'
36
+ | 'from'
37
+ | 'gas'
38
+ | 'gasPrice'
39
+ | 'to'
40
+ | 'type'
41
+ | 'value'
42
+ >
43
+ > &
44
+ GetAccountParameter<account, Account | Address> &
45
+ GetChainParameter<chain, chainOverride> &
46
+ GetContractAddressParameter<_derivedChain, 'portal'> & {
47
+ /**
48
+ * Gas limit for transaction execution on the L1.
49
+ * `null` to skip gas estimation & defer calculation to signer.
50
+ */
51
+ gas?: bigint | null
52
+ l2OutputIndex: bigint
53
+ outputRootProof: {
54
+ version: Hex
55
+ stateRoot: Hex
56
+ messagePasserStorageRoot: Hex
57
+ latestBlockhash: Hex
58
+ }
59
+ withdrawalProof: readonly Hex[]
60
+ withdrawal: {
61
+ data: Hex
62
+ gasLimit: bigint
63
+ nonce: bigint
64
+ sender: Address
65
+ target: Address
66
+ value: bigint
67
+ }
68
+ }
69
+ export type ProveWithdrawalReturnType = Hash
70
+ export type ProveWithdrawalErrorType =
71
+ | EstimateProveWithdrawalGasErrorType
72
+ | WriteContractErrorType
73
+ | ErrorType
74
+
75
+ /**
76
+ * Proves a withdrawal that occurred on an L2. Used in the Withdrawal flow.
77
+ *
78
+ * - Docs: https://viem.sh/op-stack/actions/proveWithdrawal.html
79
+ *
80
+ * @param client - Client to use
81
+ * @param parameters - {@link ProveWithdrawalParameters}
82
+ * @returns The prove transaction hash. {@link ProveWithdrawalReturnType}
83
+ *
84
+ * @example
85
+ * import { createWalletClient, http } from 'viem'
86
+ * import { mainnet, optimism } from 'viem/chains'
87
+ * import { proveWithdrawal } from 'viem/op-stack'
88
+ *
89
+ * const walletClientL1 = createWalletClient({
90
+ * chain: mainnet,
91
+ * transport: http(),
92
+ * })
93
+ *
94
+ * const request = await proveWithdrawal(walletClientL1, {
95
+ * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
96
+ * l2OutputIndex: 4529n,
97
+ * outputRootProof: { ... },
98
+ * targetChain: optimism,
99
+ * withdrawalProof: [ ... ],
100
+ * withdrawal: { ... },
101
+ * })
102
+ */
103
+ export async function proveWithdrawal<
104
+ chain extends Chain | undefined,
105
+ account extends Account | undefined,
106
+ chainOverride extends Chain | undefined = undefined,
107
+ >(
108
+ client: Client<Transport, chain, account>,
109
+ parameters: ProveWithdrawalParameters<chain, account, chainOverride>,
110
+ ): Promise<ProveWithdrawalReturnType> {
111
+ const {
112
+ account,
113
+ chain = client.chain,
114
+ gas,
115
+ l2OutputIndex,
116
+ maxFeePerGas,
117
+ maxPriorityFeePerGas,
118
+ nonce,
119
+ outputRootProof,
120
+ targetChain,
121
+ withdrawalProof,
122
+ withdrawal,
123
+ } = parameters
124
+
125
+ const portalAddress = (() => {
126
+ if (parameters.portalAddress) return parameters.portalAddress
127
+ if (chain) return targetChain!.contracts.portal[chain.id].address
128
+ return Object.values(targetChain!.contracts.portal)[0].address
129
+ })()
130
+
131
+ const gas_ =
132
+ typeof gas !== 'number' && gas !== null
133
+ ? await estimateProveWithdrawalGas(
134
+ client,
135
+ parameters as EstimateProveWithdrawalGasParameters,
136
+ )
137
+ : undefined
138
+
139
+ return writeContract(client, {
140
+ account,
141
+ abi: portalAbi,
142
+ address: portalAddress,
143
+ chain,
144
+ functionName: 'proveWithdrawalTransaction',
145
+ args: [withdrawal, l2OutputIndex, outputRootProof, withdrawalProof],
146
+ gas: gas_,
147
+ maxFeePerGas,
148
+ maxPriorityFeePerGas,
149
+ nonce,
150
+ })
151
+ }
@@ -0,0 +1,111 @@
1
+ import type { Client } from '../../../clients/createClient.js'
2
+ import type { Transport } from '../../../clients/transports/createTransport.js'
3
+ import { ContractFunctionRevertedError } from '../../../errors/contract.js'
4
+ import type { ErrorType } from '../../../errors/utils.js'
5
+ import type { Account } from '../../../types/account.js'
6
+ import type {
7
+ Chain,
8
+ DeriveChain,
9
+ GetChainParameter,
10
+ } from '../../../types/chain.js'
11
+ import { poll } from '../../../utils/poll.js'
12
+ import type { GetContractAddressParameter } from '../types/contract.js'
13
+ import {
14
+ type GetL2OutputErrorType,
15
+ type GetL2OutputReturnType,
16
+ getL2Output,
17
+ } from './getL2Output.js'
18
+ import {
19
+ type GetTimeToNextL2OutputErrorType,
20
+ type GetTimeToNextL2OutputParameters,
21
+ getTimeToNextL2Output,
22
+ } from './getTimeToNextL2Output.js'
23
+
24
+ export type WaitForNextL2OutputParameters<
25
+ chain extends Chain | undefined = Chain | undefined,
26
+ chainOverride extends Chain | undefined = Chain | undefined,
27
+ _derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
28
+ > = GetChainParameter<chain, chainOverride> &
29
+ GetContractAddressParameter<_derivedChain, 'l2OutputOracle'> & {
30
+ /**
31
+ * The buffer to account for discrepencies between non-deterministic time intervals.
32
+ * @default 1.1
33
+ */
34
+ intervalBuffer?: GetTimeToNextL2OutputParameters['intervalBuffer']
35
+ l2BlockNumber: bigint
36
+ /**
37
+ * Polling frequency (in ms). Defaults to Client's pollingInterval config.
38
+ * @default client.pollingInterval
39
+ */
40
+ pollingInterval?: number
41
+ }
42
+ export type WaitForNextL2OutputReturnType = GetL2OutputReturnType
43
+ export type WaitForNextL2OutputErrorType =
44
+ | GetL2OutputErrorType
45
+ | GetTimeToNextL2OutputErrorType
46
+ | ErrorType
47
+
48
+ /**
49
+ * Waits for the next L2 output (after the provided block number) to be submitted.
50
+ *
51
+ * - Docs: https://viem.sh/op-stack/actions/waitForNextL2Output.html
52
+ *
53
+ * @param client - Client to use
54
+ * @param parameters - {@link WaitForNextL2OutputParameters}
55
+ * @returns The L2 transaction hash. {@link WaitForNextL2OutputReturnType}
56
+ *
57
+ * @example
58
+ * import { createPublicClient, http } from 'viem'
59
+ * import { getBlockNumber } from 'viem/actions'
60
+ * import { mainnet, optimism } from 'viem/chains'
61
+ * import { waitForNextL2Output } from 'viem/op-stack'
62
+ *
63
+ * const publicClientL1 = createPublicClient({
64
+ * chain: mainnet,
65
+ * transport: http(),
66
+ * })
67
+ * const publicClientL2 = createPublicClient({
68
+ * chain: optimism,
69
+ * transport: http(),
70
+ * })
71
+ *
72
+ * const l2BlockNumber = await getBlockNumber(publicClientL2)
73
+ * await waitForNextL2Output(publicClientL1, {
74
+ * l2BlockNumber,
75
+ * targetChain: optimism
76
+ * })
77
+ */
78
+ export async function waitForNextL2Output<
79
+ chain extends Chain | undefined,
80
+ account extends Account | undefined,
81
+ chainOverride extends Chain | undefined = undefined,
82
+ >(
83
+ client: Client<Transport, chain, account>,
84
+ parameters: WaitForNextL2OutputParameters<chain, chainOverride>,
85
+ ): Promise<WaitForNextL2OutputReturnType> {
86
+ const { pollingInterval = client.pollingInterval } = parameters
87
+
88
+ const { seconds } = await getTimeToNextL2Output(client, parameters)
89
+
90
+ return new Promise((resolve, reject) => {
91
+ poll(
92
+ async ({ unpoll }) => {
93
+ try {
94
+ const output = await getL2Output(client, parameters)
95
+ unpoll()
96
+ resolve(output)
97
+ } catch (e) {
98
+ const error = e as GetL2OutputErrorType
99
+ if (!(error.cause instanceof ContractFunctionRevertedError)) {
100
+ unpoll()
101
+ reject(e)
102
+ }
103
+ }
104
+ },
105
+ {
106
+ interval: pollingInterval,
107
+ initialWaitTime: async () => seconds * 1000,
108
+ },
109
+ )
110
+ })
111
+ }
@@ -0,0 +1,64 @@
1
+ import type { Client } from '../../../clients/createClient.js'
2
+ import type { Transport } from '../../../clients/transports/createTransport.js'
3
+ import type { ErrorType } from '../../../errors/utils.js'
4
+ import type { Account } from '../../../types/account.js'
5
+ import type { Chain } from '../../../types/chain.js'
6
+ import { wait } from '../../../utils/wait.js'
7
+ import {
8
+ type GetTimeToFinalizeErrorType,
9
+ type GetTimeToFinalizeParameters,
10
+ getTimeToFinalize,
11
+ } from './getTimeToFinalize.js'
12
+
13
+ export type WaitToFinalizeParameters<
14
+ chain extends Chain | undefined = Chain | undefined,
15
+ chainOverride extends Chain | undefined = Chain | undefined,
16
+ > = GetTimeToFinalizeParameters<chain, chainOverride>
17
+ export type WaitToFinalizeReturnType = void
18
+ export type WaitToFinalizeErrorType = GetTimeToFinalizeErrorType | ErrorType
19
+
20
+ /**
21
+ * Waits until the withdrawal transaction can be finalized. Used for the [Withdrawal](/op-stack/guides/withdrawals.html) flow.
22
+ *
23
+ * - Docs: https://viem.sh/op-stack/actions/waitToFinalize.html
24
+ *
25
+ * @param client - Client to use
26
+ * @param parameters - {@link WaitToFinalizeParameters}
27
+ *
28
+ * @example
29
+ * import { createPublicClient, http } from 'viem'
30
+ * import { getBlockNumber } from 'viem/actions'
31
+ * import { mainnet, optimism } from 'viem/chains'
32
+ * import { waitToFinalize } from 'viem/op-stack'
33
+ *
34
+ * const publicClientL1 = createPublicClient({
35
+ * chain: mainnet,
36
+ * transport: http(),
37
+ * })
38
+ * const publicClientL2 = createPublicClient({
39
+ * chain: optimism,
40
+ * transport: http(),
41
+ * })
42
+ *
43
+ * const receipt = await getTransactionReceipt(publicClientL2, {
44
+ * hash: '0x9a2f4283636ddeb9ac32382961b22c177c9e86dd3b283735c154f897b1a7ff4a',
45
+ * })
46
+ *
47
+ * const [withdrawal] = getWithdrawals(receipt)
48
+ *
49
+ * await waitToFinalize(publicClientL1, {
50
+ * withdrawalHash: withdrawal.withdrawalHash,
51
+ * targetChain: optimism
52
+ * })
53
+ */
54
+ export async function waitToFinalize<
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: WaitToFinalizeParameters<chain, chainOverride>,
61
+ ): Promise<WaitToFinalizeReturnType> {
62
+ const { seconds } = await getTimeToFinalize(client, parameters)
63
+ await wait(seconds * 1000)
64
+ }