viem 2.57.11 → 2.57.13

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 (377) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/_cjs/actions/public/fillTransaction.js +6 -3
  3. package/_cjs/actions/public/fillTransaction.js.map +1 -1
  4. package/_cjs/actions/public/waitForTransactionReceipt.js +83 -23
  5. package/_cjs/actions/public/waitForTransactionReceipt.js.map +1 -1
  6. package/_cjs/actions/public/watchContractEvent.js +58 -29
  7. package/_cjs/actions/public/watchContractEvent.js.map +1 -1
  8. package/_cjs/actions/public/watchEvent.js +58 -28
  9. package/_cjs/actions/public/watchEvent.js.map +1 -1
  10. package/_cjs/actions/token/approve.js +1 -1
  11. package/_cjs/actions/token/approve.js.map +1 -1
  12. package/_cjs/actions/token/getAllowance.js +1 -1
  13. package/_cjs/actions/token/getAllowance.js.map +1 -1
  14. package/_cjs/actions/token/getBalance.js +1 -1
  15. package/_cjs/actions/token/getBalance.js.map +1 -1
  16. package/_cjs/actions/token/getTotalSupply.js +1 -1
  17. package/_cjs/actions/token/getTotalSupply.js.map +1 -1
  18. package/_cjs/actions/token/transfer.js +1 -1
  19. package/_cjs/actions/token/transfer.js.map +1 -1
  20. package/_cjs/actions/wallet/sendCalls.js +1 -1
  21. package/_cjs/actions/wallet/sendCalls.js.map +1 -1
  22. package/_cjs/chains/definitions/molibra.js +21 -0
  23. package/_cjs/chains/definitions/molibra.js.map +1 -0
  24. package/_cjs/chains/definitions/valuechain.js +22 -0
  25. package/_cjs/chains/definitions/valuechain.js.map +1 -0
  26. package/_cjs/chains/definitions/valuechainTestnet.js +23 -0
  27. package/_cjs/chains/definitions/valuechainTestnet.js.map +1 -0
  28. package/_cjs/chains/index.js +13 -7
  29. package/_cjs/chains/index.js.map +1 -1
  30. package/_cjs/clients/decorators/public.js.map +1 -1
  31. package/_cjs/clients/transports/http.js +5 -1
  32. package/_cjs/clients/transports/http.js.map +1 -1
  33. package/_cjs/errors/node.js +1 -1
  34. package/_cjs/errors/node.js.map +1 -1
  35. package/_cjs/errors/request.js +20 -2
  36. package/_cjs/errors/request.js.map +1 -1
  37. package/_cjs/errors/typedData.js +3 -1
  38. package/_cjs/errors/typedData.js.map +1 -1
  39. package/_cjs/errors/version.js +1 -1
  40. package/_cjs/op-stack/abis.js +52 -0
  41. package/_cjs/op-stack/abis.js.map +1 -1
  42. package/_cjs/op-stack/actions/getTimeToFinalize.js +53 -4
  43. package/_cjs/op-stack/actions/getTimeToFinalize.js.map +1 -1
  44. package/_cjs/op-stack/actions/getTimeToProve.js +29 -2
  45. package/_cjs/op-stack/actions/getTimeToProve.js.map +1 -1
  46. package/_cjs/op-stack/actions/getWithdrawalStatus.js +20 -4
  47. package/_cjs/op-stack/actions/getWithdrawalStatus.js.map +1 -1
  48. package/_cjs/op-stack/actions/waitToProve.js +28 -2
  49. package/_cjs/op-stack/actions/waitToProve.js.map +1 -1
  50. package/_cjs/op-stack/errors/withdrawal.js +12 -1
  51. package/_cjs/op-stack/errors/withdrawal.js.map +1 -1
  52. package/_cjs/tempo/Account.js +6 -9
  53. package/_cjs/tempo/Account.js.map +1 -1
  54. package/_cjs/tempo/Addresses.js +1 -2
  55. package/_cjs/tempo/Addresses.js.map +1 -1
  56. package/_cjs/tempo/Formatters.js +13 -2
  57. package/_cjs/tempo/Formatters.js.map +1 -1
  58. package/_cjs/tempo/Relay.js.map +1 -1
  59. package/_cjs/tempo/Transaction.js.map +1 -1
  60. package/_cjs/tempo/accounts/Config.js +22 -12
  61. package/_cjs/tempo/accounts/Config.js.map +1 -1
  62. package/_cjs/tempo/actions/accessKey.js +8 -8
  63. package/_cjs/tempo/actions/accessKey.js.map +1 -1
  64. package/_cjs/tempo/actions/accounts.js +5 -5
  65. package/_cjs/tempo/actions/accounts.js.map +1 -1
  66. package/_cjs/tempo/actions/amm.js +4 -4
  67. package/_cjs/tempo/actions/amm.js.map +1 -1
  68. package/_cjs/tempo/actions/channel.js +7 -7
  69. package/_cjs/tempo/actions/channel.js.map +1 -1
  70. package/_cjs/tempo/actions/dex.js +14 -14
  71. package/_cjs/tempo/actions/dex.js.map +1 -1
  72. package/_cjs/tempo/actions/earn/deployment.js +3 -3
  73. package/_cjs/tempo/actions/earn/deployment.js.map +1 -1
  74. package/_cjs/tempo/actions/earn.js +6 -6
  75. package/_cjs/tempo/actions/earn.js.map +1 -1
  76. package/_cjs/tempo/actions/fee.js +4 -4
  77. package/_cjs/tempo/actions/fee.js.map +1 -1
  78. package/_cjs/tempo/actions/nonce.js +1 -1
  79. package/_cjs/tempo/actions/nonce.js.map +1 -1
  80. package/_cjs/tempo/actions/policy.js +6 -6
  81. package/_cjs/tempo/actions/policy.js.map +1 -1
  82. package/_cjs/tempo/actions/propAmm.js +10 -10
  83. package/_cjs/tempo/actions/propAmm.js.map +1 -1
  84. package/_cjs/tempo/actions/receivePolicy.js +6 -6
  85. package/_cjs/tempo/actions/receivePolicy.js.map +1 -1
  86. package/_cjs/tempo/actions/reward.js +6 -6
  87. package/_cjs/tempo/actions/reward.js.map +1 -1
  88. package/_cjs/tempo/actions/token.js +21 -21
  89. package/_cjs/tempo/actions/token.js.map +1 -1
  90. package/_cjs/tempo/actions/validator.js +11 -11
  91. package/_cjs/tempo/actions/validator.js.map +1 -1
  92. package/_cjs/tempo/actions/virtualAddress.js +2 -2
  93. package/_cjs/tempo/actions/virtualAddress.js.map +1 -1
  94. package/_cjs/tempo/chainConfig.js +11 -4
  95. package/_cjs/tempo/chainConfig.js.map +1 -1
  96. package/_cjs/tempo/internal/relay/accounts.js +42 -7
  97. package/_cjs/tempo/internal/relay/accounts.js.map +1 -1
  98. package/_cjs/tempo/internal/relay/feePayer.js +4 -1
  99. package/_cjs/tempo/internal/relay/feePayer.js.map +1 -1
  100. package/_cjs/utils/abi/getAbiItem.js +33 -12
  101. package/_cjs/utils/abi/getAbiItem.js.map +1 -1
  102. package/_cjs/utils/abi/parseEventLogs.js +18 -10
  103. package/_cjs/utils/abi/parseEventLogs.js.map +1 -1
  104. package/_cjs/utils/authorization/serializeAuthorizationList.js +4 -1
  105. package/_cjs/utils/authorization/serializeAuthorizationList.js.map +1 -1
  106. package/_cjs/utils/buildRequest.js +25 -14
  107. package/_cjs/utils/buildRequest.js.map +1 -1
  108. package/_cjs/utils/data/isHex.js +3 -1
  109. package/_cjs/utils/data/isHex.js.map +1 -1
  110. package/_cjs/utils/hash/normalizeSignature.js +1 -1
  111. package/_cjs/utils/hash/normalizeSignature.js.map +1 -1
  112. package/_cjs/utils/rpc/http.js +24 -4
  113. package/_cjs/utils/rpc/http.js.map +1 -1
  114. package/_cjs/utils/signature/compactSignatureToSignature.js +3 -2
  115. package/_cjs/utils/signature/compactSignatureToSignature.js.map +1 -1
  116. package/_cjs/utils/signature/hashTypedData.js +1 -2
  117. package/_cjs/utils/signature/hashTypedData.js.map +1 -1
  118. package/_cjs/utils/signature/signatureToCompactSignature.js +15 -7
  119. package/_cjs/utils/signature/signatureToCompactSignature.js.map +1 -1
  120. package/_cjs/utils/siwe/createSiweMessage.js +1 -1
  121. package/_cjs/utils/siwe/createSiweMessage.js.map +1 -1
  122. package/_cjs/utils/typedData.js +6 -7
  123. package/_cjs/utils/typedData.js.map +1 -1
  124. package/_cjs/utils/wait.js +1 -1
  125. package/_cjs/utils/wait.js.map +1 -1
  126. package/_esm/actions/public/fillTransaction.js +8 -3
  127. package/_esm/actions/public/fillTransaction.js.map +1 -1
  128. package/_esm/actions/public/waitForTransactionReceipt.js +101 -23
  129. package/_esm/actions/public/waitForTransactionReceipt.js.map +1 -1
  130. package/_esm/actions/public/watchContractEvent.js +73 -36
  131. package/_esm/actions/public/watchContractEvent.js.map +1 -1
  132. package/_esm/actions/public/watchEvent.js +73 -35
  133. package/_esm/actions/public/watchEvent.js.map +1 -1
  134. package/_esm/actions/token/approve.js +1 -1
  135. package/_esm/actions/token/approve.js.map +1 -1
  136. package/_esm/actions/token/getAllowance.js +1 -1
  137. package/_esm/actions/token/getAllowance.js.map +1 -1
  138. package/_esm/actions/token/getBalance.js +1 -1
  139. package/_esm/actions/token/getBalance.js.map +1 -1
  140. package/_esm/actions/token/getTotalSupply.js +1 -1
  141. package/_esm/actions/token/getTotalSupply.js.map +1 -1
  142. package/_esm/actions/token/transfer.js +1 -1
  143. package/_esm/actions/token/transfer.js.map +1 -1
  144. package/_esm/actions/wallet/sendCalls.js +1 -1
  145. package/_esm/actions/wallet/sendCalls.js.map +1 -1
  146. package/_esm/chains/definitions/molibra.js +18 -0
  147. package/_esm/chains/definitions/molibra.js.map +1 -0
  148. package/_esm/chains/definitions/valuechain.js +20 -0
  149. package/_esm/chains/definitions/valuechain.js.map +1 -0
  150. package/_esm/chains/definitions/valuechainTestnet.js +21 -0
  151. package/_esm/chains/definitions/valuechainTestnet.js.map +1 -0
  152. package/_esm/chains/index.js +5 -0
  153. package/_esm/chains/index.js.map +1 -1
  154. package/_esm/clients/decorators/public.js.map +1 -1
  155. package/_esm/clients/transports/http.js +6 -1
  156. package/_esm/clients/transports/http.js.map +1 -1
  157. package/_esm/errors/node.js +1 -1
  158. package/_esm/errors/node.js.map +1 -1
  159. package/_esm/errors/request.js +22 -2
  160. package/_esm/errors/request.js.map +1 -1
  161. package/_esm/errors/typedData.js +3 -1
  162. package/_esm/errors/typedData.js.map +1 -1
  163. package/_esm/errors/version.js +1 -1
  164. package/_esm/op-stack/abis.js +52 -0
  165. package/_esm/op-stack/abis.js.map +1 -1
  166. package/_esm/op-stack/actions/getTimeToFinalize.js +64 -6
  167. package/_esm/op-stack/actions/getTimeToFinalize.js.map +1 -1
  168. package/_esm/op-stack/actions/getTimeToProve.js +30 -2
  169. package/_esm/op-stack/actions/getTimeToProve.js.map +1 -1
  170. package/_esm/op-stack/actions/getWithdrawalStatus.js +24 -5
  171. package/_esm/op-stack/actions/getWithdrawalStatus.js.map +1 -1
  172. package/_esm/op-stack/actions/waitToProve.js +30 -3
  173. package/_esm/op-stack/actions/waitToProve.js.map +1 -1
  174. package/_esm/op-stack/errors/withdrawal.js +10 -0
  175. package/_esm/op-stack/errors/withdrawal.js.map +1 -1
  176. package/_esm/tempo/Account.js +6 -9
  177. package/_esm/tempo/Account.js.map +1 -1
  178. package/_esm/tempo/Addresses.js +0 -2
  179. package/_esm/tempo/Addresses.js.map +1 -1
  180. package/_esm/tempo/Formatters.js +12 -2
  181. package/_esm/tempo/Formatters.js.map +1 -1
  182. package/_esm/tempo/Relay.js.map +1 -1
  183. package/_esm/tempo/Transaction.js.map +1 -1
  184. package/_esm/tempo/accounts/Config.js +28 -16
  185. package/_esm/tempo/accounts/Config.js.map +1 -1
  186. package/_esm/tempo/actions/accessKey.js +8 -8
  187. package/_esm/tempo/actions/accessKey.js.map +1 -1
  188. package/_esm/tempo/actions/accounts.js +7 -7
  189. package/_esm/tempo/actions/accounts.js.map +1 -1
  190. package/_esm/tempo/actions/amm.js +4 -4
  191. package/_esm/tempo/actions/amm.js.map +1 -1
  192. package/_esm/tempo/actions/channel.js +7 -7
  193. package/_esm/tempo/actions/channel.js.map +1 -1
  194. package/_esm/tempo/actions/dex.js +14 -14
  195. package/_esm/tempo/actions/dex.js.map +1 -1
  196. package/_esm/tempo/actions/earn/deployment.js +3 -3
  197. package/_esm/tempo/actions/earn/deployment.js.map +1 -1
  198. package/_esm/tempo/actions/earn.js +6 -6
  199. package/_esm/tempo/actions/earn.js.map +1 -1
  200. package/_esm/tempo/actions/fee.js +4 -4
  201. package/_esm/tempo/actions/fee.js.map +1 -1
  202. package/_esm/tempo/actions/nonce.js +1 -1
  203. package/_esm/tempo/actions/nonce.js.map +1 -1
  204. package/_esm/tempo/actions/policy.js +6 -6
  205. package/_esm/tempo/actions/policy.js.map +1 -1
  206. package/_esm/tempo/actions/propAmm.js +10 -10
  207. package/_esm/tempo/actions/propAmm.js.map +1 -1
  208. package/_esm/tempo/actions/receivePolicy.js +6 -6
  209. package/_esm/tempo/actions/receivePolicy.js.map +1 -1
  210. package/_esm/tempo/actions/reward.js +6 -6
  211. package/_esm/tempo/actions/reward.js.map +1 -1
  212. package/_esm/tempo/actions/token.js +21 -21
  213. package/_esm/tempo/actions/token.js.map +1 -1
  214. package/_esm/tempo/actions/validator.js +11 -11
  215. package/_esm/tempo/actions/validator.js.map +1 -1
  216. package/_esm/tempo/actions/virtualAddress.js +2 -2
  217. package/_esm/tempo/actions/virtualAddress.js.map +1 -1
  218. package/_esm/tempo/chainConfig.js +13 -4
  219. package/_esm/tempo/chainConfig.js.map +1 -1
  220. package/_esm/tempo/internal/relay/accounts.js +44 -7
  221. package/_esm/tempo/internal/relay/accounts.js.map +1 -1
  222. package/_esm/tempo/internal/relay/feePayer.js +4 -1
  223. package/_esm/tempo/internal/relay/feePayer.js.map +1 -1
  224. package/_esm/utils/abi/getAbiItem.js +36 -14
  225. package/_esm/utils/abi/getAbiItem.js.map +1 -1
  226. package/_esm/utils/abi/parseEventLogs.js +25 -11
  227. package/_esm/utils/abi/parseEventLogs.js.map +1 -1
  228. package/_esm/utils/authorization/serializeAuthorizationList.js +7 -1
  229. package/_esm/utils/authorization/serializeAuthorizationList.js.map +1 -1
  230. package/_esm/utils/buildRequest.js +29 -15
  231. package/_esm/utils/buildRequest.js.map +1 -1
  232. package/_esm/utils/data/isHex.js +3 -1
  233. package/_esm/utils/data/isHex.js.map +1 -1
  234. package/_esm/utils/hash/normalizeSignature.js +1 -1
  235. package/_esm/utils/hash/normalizeSignature.js.map +1 -1
  236. package/_esm/utils/hash/toSignature.js +1 -1
  237. package/_esm/utils/hash/toSignatureHash.js +1 -1
  238. package/_esm/utils/rpc/http.js +29 -7
  239. package/_esm/utils/rpc/http.js.map +1 -1
  240. package/_esm/utils/signature/compactSignatureToSignature.js +3 -2
  241. package/_esm/utils/signature/compactSignatureToSignature.js.map +1 -1
  242. package/_esm/utils/signature/hashTypedData.js +1 -2
  243. package/_esm/utils/signature/hashTypedData.js.map +1 -1
  244. package/_esm/utils/signature/signatureToCompactSignature.js +16 -7
  245. package/_esm/utils/signature/signatureToCompactSignature.js.map +1 -1
  246. package/_esm/utils/siwe/createSiweMessage.js +1 -1
  247. package/_esm/utils/siwe/createSiweMessage.js.map +1 -1
  248. package/_esm/utils/typedData.js +12 -8
  249. package/_esm/utils/typedData.js.map +1 -1
  250. package/_esm/utils/wait.js +2 -1
  251. package/_esm/utils/wait.js.map +1 -1
  252. package/_types/actions/getContract.d.ts +1 -1
  253. package/_types/actions/public/fillTransaction.d.ts.map +1 -1
  254. package/_types/actions/public/waitForTransactionReceipt.d.ts +31 -1
  255. package/_types/actions/public/waitForTransactionReceipt.d.ts.map +1 -1
  256. package/_types/actions/public/watchContractEvent.d.ts +1 -1
  257. package/_types/actions/public/watchContractEvent.d.ts.map +1 -1
  258. package/_types/actions/public/watchEvent.d.ts +1 -1
  259. package/_types/actions/public/watchEvent.d.ts.map +1 -1
  260. package/_types/chains/definitions/molibra.d.ts +52 -0
  261. package/_types/chains/definitions/molibra.d.ts.map +1 -0
  262. package/_types/chains/definitions/tempo.d.ts +14 -6
  263. package/_types/chains/definitions/tempo.d.ts.map +1 -1
  264. package/_types/chains/definitions/tempoDevnet.d.ts +14 -6
  265. package/_types/chains/definitions/tempoDevnet.d.ts.map +1 -1
  266. package/_types/chains/definitions/tempoLocalnet.d.ts +14 -6
  267. package/_types/chains/definitions/tempoLocalnet.d.ts.map +1 -1
  268. package/_types/chains/definitions/tempoModerato.d.ts +14 -6
  269. package/_types/chains/definitions/tempoModerato.d.ts.map +1 -1
  270. package/_types/chains/definitions/valuechain.d.ts +53 -0
  271. package/_types/chains/definitions/valuechain.d.ts.map +1 -0
  272. package/_types/chains/definitions/valuechainTestnet.d.ts +53 -0
  273. package/_types/chains/definitions/valuechainTestnet.d.ts.map +1 -0
  274. package/_types/chains/index.d.ts +5 -0
  275. package/_types/chains/index.d.ts.map +1 -1
  276. package/_types/clients/decorators/public.d.ts +5 -2
  277. package/_types/clients/decorators/public.d.ts.map +1 -1
  278. package/_types/clients/transports/http.d.ts.map +1 -1
  279. package/_types/errors/node.d.ts.map +1 -1
  280. package/_types/errors/request.d.ts +7 -1
  281. package/_types/errors/request.d.ts.map +1 -1
  282. package/_types/errors/typedData.d.ts.map +1 -1
  283. package/_types/errors/version.d.ts +1 -1
  284. package/_types/op-stack/abis.d.ts +40 -0
  285. package/_types/op-stack/abis.d.ts.map +1 -1
  286. package/_types/op-stack/actions/getTimeToFinalize.d.ts +3 -2
  287. package/_types/op-stack/actions/getTimeToFinalize.d.ts.map +1 -1
  288. package/_types/op-stack/actions/getTimeToProve.d.ts +3 -1
  289. package/_types/op-stack/actions/getTimeToProve.d.ts.map +1 -1
  290. package/_types/op-stack/actions/getWithdrawalStatus.d.ts +2 -2
  291. package/_types/op-stack/actions/getWithdrawalStatus.d.ts.map +1 -1
  292. package/_types/op-stack/actions/waitToProve.d.ts +3 -1
  293. package/_types/op-stack/actions/waitToProve.d.ts.map +1 -1
  294. package/_types/op-stack/errors/withdrawal.d.ts +8 -0
  295. package/_types/op-stack/errors/withdrawal.d.ts.map +1 -1
  296. package/_types/tempo/Account.d.ts +14 -5
  297. package/_types/tempo/Account.d.ts.map +1 -1
  298. package/_types/tempo/Addresses.d.ts +0 -2
  299. package/_types/tempo/Addresses.d.ts.map +1 -1
  300. package/_types/tempo/Formatters.d.ts +3 -0
  301. package/_types/tempo/Formatters.d.ts.map +1 -1
  302. package/_types/tempo/Relay.d.ts +20 -0
  303. package/_types/tempo/Relay.d.ts.map +1 -1
  304. package/_types/tempo/Transaction.d.ts +7 -2
  305. package/_types/tempo/Transaction.d.ts.map +1 -1
  306. package/_types/tempo/accounts/Config.d.ts +24 -2
  307. package/_types/tempo/accounts/Config.d.ts.map +1 -1
  308. package/_types/tempo/actions/accounts.d.ts +2 -2
  309. package/_types/tempo/chainConfig.d.ts +8 -3
  310. package/_types/tempo/chainConfig.d.ts.map +1 -1
  311. package/_types/tempo/internal/relay/accounts.d.ts.map +1 -1
  312. package/_types/tempo/internal/relay/feePayer.d.ts.map +1 -1
  313. package/_types/utils/abi/getAbiItem.d.ts.map +1 -1
  314. package/_types/utils/abi/parseEventLogs.d.ts.map +1 -1
  315. package/_types/utils/authorization/serializeAuthorizationList.d.ts.map +1 -1
  316. package/_types/utils/buildRequest.d.ts.map +1 -1
  317. package/_types/utils/data/isHex.d.ts +12 -1
  318. package/_types/utils/data/isHex.d.ts.map +1 -1
  319. package/_types/utils/hash/toSignature.d.ts +1 -1
  320. package/_types/utils/hash/toSignatureHash.d.ts +1 -1
  321. package/_types/utils/rpc/http.d.ts +2 -2
  322. package/_types/utils/rpc/http.d.ts.map +1 -1
  323. package/_types/utils/signature/compactSignatureToSignature.d.ts +2 -1
  324. package/_types/utils/signature/compactSignatureToSignature.d.ts.map +1 -1
  325. package/_types/utils/signature/hashTypedData.d.ts.map +1 -1
  326. package/_types/utils/signature/signatureToCompactSignature.d.ts +2 -1
  327. package/_types/utils/signature/signatureToCompactSignature.d.ts.map +1 -1
  328. package/_types/utils/typedData.d.ts.map +1 -1
  329. package/_types/utils/wait.d.ts.map +1 -1
  330. package/actions/getContract.ts +1 -1
  331. package/actions/public/fillTransaction.ts +12 -3
  332. package/actions/public/waitForTransactionReceipt.ts +164 -33
  333. package/actions/public/watchContractEvent.ts +82 -39
  334. package/actions/public/watchEvent.ts +82 -38
  335. package/actions/wallet/sendCalls.ts +1 -1
  336. package/chains/definitions/molibra.ts +18 -0
  337. package/chains/definitions/valuechain.ts +20 -0
  338. package/chains/definitions/valuechainTestnet.ts +21 -0
  339. package/chains/index.ts +5 -0
  340. package/clients/decorators/public.ts +5 -2
  341. package/clients/transports/http.ts +6 -1
  342. package/errors/node.ts +1 -1
  343. package/errors/request.ts +15 -1
  344. package/errors/typedData.ts +3 -1
  345. package/errors/version.ts +1 -1
  346. package/op-stack/abis.ts +52 -0
  347. package/op-stack/actions/getTimeToFinalize.ts +89 -10
  348. package/op-stack/actions/getTimeToProve.ts +43 -2
  349. package/op-stack/actions/getWithdrawalStatus.ts +30 -6
  350. package/op-stack/actions/waitToProve.ts +45 -3
  351. package/op-stack/errors/withdrawal.ts +17 -0
  352. package/package.json +2 -2
  353. package/tempo/Account.ts +20 -22
  354. package/tempo/Addresses.ts +0 -3
  355. package/tempo/Formatters.ts +19 -7
  356. package/tempo/Relay.ts +26 -0
  357. package/tempo/Transaction.ts +10 -2
  358. package/tempo/accounts/Config.ts +40 -25
  359. package/tempo/actions/accounts.ts +2 -2
  360. package/tempo/chainConfig.ts +15 -4
  361. package/tempo/internal/relay/accounts.ts +45 -9
  362. package/tempo/internal/relay/feePayer.ts +6 -1
  363. package/utils/abi/getAbiItem.ts +49 -17
  364. package/utils/abi/parseEventLogs.ts +32 -11
  365. package/utils/authorization/serializeAuthorizationList.ts +7 -1
  366. package/utils/buildRequest.ts +29 -14
  367. package/utils/data/isHex.ts +18 -1
  368. package/utils/hash/normalizeSignature.ts +1 -1
  369. package/utils/hash/toSignature.ts +1 -1
  370. package/utils/hash/toSignatureHash.ts +1 -1
  371. package/utils/rpc/http.ts +33 -8
  372. package/utils/signature/compactSignatureToSignature.ts +4 -2
  373. package/utils/signature/hashTypedData.ts +1 -2
  374. package/utils/signature/signatureToCompactSignature.ts +13 -8
  375. package/utils/siwe/createSiweMessage.ts +1 -1
  376. package/utils/typedData.ts +11 -8
  377. package/utils/wait.ts +8 -4
@@ -6,6 +6,8 @@ import {
6
6
  DecodeLogDataMismatch,
7
7
  DecodeLogTopicsMismatch,
8
8
  } from '../../errors/abi.js'
9
+ import { BaseError } from '../../errors/base.js'
10
+ import { HttpRequestError, RpcRequestError } from '../../errors/request.js'
9
11
  import { InvalidInputRpcError } from '../../errors/rpc.js'
10
12
  import type { ErrorType } from '../../errors/utils.js'
11
13
  import type { BlockNumber } from '../../types/block.js'
@@ -128,7 +130,7 @@ export type WatchEventErrorType =
128
130
  *
129
131
  * This Action will batch up all the Event Logs found within the [`pollingInterval`](https://viem.sh/docs/actions/public/watchEvent#pollinginterval-optional), and invoke them via [`onLogs`](https://viem.sh/docs/actions/public/watchEvent#onLogs).
130
132
  *
131
- * `watchEvent` will attempt to create an [Event Filter](https://viem.sh/docs/actions/public/createEventFilter) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs) instead.
133
+ * `watchEvent` will attempt to create an [Event Filter](https://viem.sh/docs/actions/public/createEventFilter) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs) instead. If `getLogs` fails for a block range, `watchEvent` will retry with smaller block ranges and may call `onLogs` more than once per polling interval.
132
134
  *
133
135
  * @param client - Client to use
134
136
  * @param parameters - {@link WatchEventParameters}
@@ -206,11 +208,34 @@ export function watchEvent<
206
208
  ])
207
209
 
208
210
  return observe(observerId, { onLogs, onError }, (emit) => {
209
- let previousBlockNumber: bigint
210
- if (fromBlock !== undefined) previousBlockNumber = fromBlock - 1n
211
+ let active = true
212
+ let previousBlockNumber =
213
+ fromBlock === undefined ? undefined : fromBlock - 1n
211
214
  let filter: Filter<'event', abiEvents, _eventName, any>
212
215
  let initialized = false
213
216
 
217
+ const emitLogs = (logs: Log[]) => {
218
+ if (logs.length === 0) return
219
+ if (batch) emit.onLogs(logs as any)
220
+ else for (const log of logs) emit.onLogs([log] as any)
221
+ }
222
+
223
+ // Fetches the logs of the blocks from `from` to `to`, inclusive.
224
+ const getLogsInRange = (from: bigint, to: bigint) =>
225
+ getAction(
226
+ client,
227
+ getLogs,
228
+ 'getLogs',
229
+ )({
230
+ address,
231
+ args,
232
+ event: event!,
233
+ events,
234
+ fromBlock: from,
235
+ strict,
236
+ toBlock: to,
237
+ } as unknown as GetLogsParameters)
238
+
214
239
  const unwatch = poll(
215
240
  async () => {
216
241
  if (!initialized) {
@@ -233,53 +258,55 @@ export function watchEvent<
233
258
  >
234
259
  } catch {}
235
260
  initialized = true
236
- return
261
+ if (filter) return
237
262
  }
238
263
 
239
264
  try {
240
- let logs: Log[]
241
265
  if (filter) {
242
- logs = await getAction(
266
+ const logs = await getAction(
243
267
  client,
244
268
  getFilterChanges,
245
269
  'getFilterChanges',
246
270
  )({ filter })
247
- } else {
248
- // If the filter doesn't exist, we will fall back to use `getLogs`.
249
- // The fall back exists because some RPC Providers do not support filters.
271
+ emitLogs(logs)
272
+ return
273
+ }
250
274
 
251
- // Fetch the block number to use for `getLogs`.
252
- const blockNumber = await getAction(
253
- client,
254
- getBlockNumber,
255
- 'getBlockNumber',
256
- )({})
275
+ // If the filter doesn't exist, we will fall back to use `getLogs`.
276
+ // The fall back exists because some RPC Providers do not support filters.
277
+ const blockNumber = await getAction(
278
+ client,
279
+ getBlockNumber,
280
+ 'getBlockNumber',
281
+ )({})
282
+
283
+ // Without `fromBlock`, start watching from the current block.
284
+ previousBlockNumber ??= blockNumber
257
285
 
258
- // If the block number has changed, we will need to fetch the logs.
259
- // If the block number doesn't exist, we are yet to reach the first poll interval,
260
- // so do not emit any logs.
261
- if (previousBlockNumber && previousBlockNumber !== blockNumber) {
262
- logs = await getAction(
263
- client,
264
- getLogs,
265
- 'getLogs',
266
- )({
267
- address,
268
- args,
269
- event: event!,
270
- events,
271
- fromBlock: previousBlockNumber + 1n,
272
- toBlock: blockNumber,
273
- } as unknown as GetLogsParameters)
274
- } else {
275
- logs = []
286
+ // RPC Providers limit `eth_getLogs` by block range, log count or response
287
+ // size. `size` is the most blocks to request at once: it starts with all
288
+ // new blocks and halves whenever a request fails.
289
+ let size = blockNumber - previousBlockNumber
290
+ while (previousBlockNumber < blockNumber) {
291
+ const from = previousBlockNumber + 1n
292
+ const end: bigint = previousBlockNumber + size
293
+ const to = end < blockNumber ? end : blockNumber
294
+
295
+ const logs = await getLogsInRange(from, to).catch((error) => {
296
+ // A single block cannot be split, and a smaller range does not
297
+ // help when the RPC Provider is unreachable or rejects the client.
298
+ if (from === to || !isRangeError(error)) throw error
299
+ })
300
+ if (!active) return
301
+ if (!logs) {
302
+ size = (to - from + 1n) / 2n
303
+ continue
276
304
  }
277
- previousBlockNumber = blockNumber
278
- }
279
305
 
280
- if (logs.length === 0) return
281
- if (batch) emit.onLogs(logs as any)
282
- else for (const log of logs) emit.onLogs([log] as any)
306
+ // Only move past blocks whose logs were fetched, so none are skipped.
307
+ previousBlockNumber = to
308
+ emitLogs(logs)
309
+ }
283
310
  } catch (err) {
284
311
  // If a filter has been set and gets uninstalled, providers will throw an InvalidInput error.
285
312
  // Reinitialize the filter when this occurs
@@ -295,6 +322,7 @@ export function watchEvent<
295
322
  )
296
323
 
297
324
  return async () => {
325
+ active = false
298
326
  if (filter)
299
327
  await getAction(
300
328
  client,
@@ -391,3 +419,19 @@ export function watchEvent<
391
419
 
392
420
  return enablePolling ? pollEvent() : subscribeEvent()
393
421
  }
422
+
423
+ /** Returns whether a failed `eth_getLogs` request may succeed with a smaller block range. */
424
+ function isRangeError(error: unknown) {
425
+ if (!(error instanceof BaseError)) return true
426
+ const cause = error.walk(
427
+ (err) => err instanceof HttpRequestError || err instanceof RpcRequestError,
428
+ ) as HttpRequestError | RpcRequestError | null
429
+ if (!cause) return true
430
+ // Rate limited.
431
+ if (cause instanceof RpcRequestError && cause.code === 429) return false
432
+ // Unreachable.
433
+ if (cause instanceof HttpRequestError && cause.status === undefined)
434
+ return false
435
+ // Unauthorized, forbidden or rate limited.
436
+ return cause.status !== 401 && cause.status !== 403 && cause.status !== 429
437
+ }
@@ -137,7 +137,7 @@ export async function sendCalls<
137
137
  : call.data
138
138
 
139
139
  return {
140
- data: call.dataSuffix && data ? concat([data, call.dataSuffix]) : data,
140
+ data: call.dataSuffix ? concat([data ?? '0x', call.dataSuffix]) : data,
141
141
  to: call.to,
142
142
  value: call.value ? numberToHex(call.value) : undefined,
143
143
  }
@@ -0,0 +1,18 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const molibra = /*#__PURE__*/ defineChain({
4
+ id: 20226,
5
+ name: 'Molibra',
6
+ nativeCurrency: { name: 'Molibra', symbol: 'MOLI', decimals: 18 },
7
+ rpcUrls: {
8
+ default: {
9
+ http: ['https://molibra.org'],
10
+ },
11
+ },
12
+ blockExplorers: {
13
+ default: {
14
+ name: 'Moliscan',
15
+ url: 'https://molibra.org/molibra/moliscan',
16
+ },
17
+ },
18
+ })
@@ -0,0 +1,20 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ /** ValueChain mainnet. */
4
+ export const valuechain = /*#__PURE__*/ defineChain({
5
+ id: 286_623,
6
+ name: 'ValueChain',
7
+ blockTime: 2_000,
8
+ nativeCurrency: { name: 'SOSO', symbol: 'SOSO', decimals: 18 },
9
+ rpcUrls: {
10
+ default: {
11
+ http: ['https://mainnet.valuechain.xyz'],
12
+ },
13
+ },
14
+ blockExplorers: {
15
+ default: {
16
+ name: 'ValueChain Explorer',
17
+ url: 'https://main-scan.valuechain.xyz',
18
+ },
19
+ },
20
+ })
@@ -0,0 +1,21 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ /** ValueChain testnet. */
4
+ export const valuechainTestnet = /*#__PURE__*/ defineChain({
5
+ id: 138_565,
6
+ name: 'ValueChain Testnet',
7
+ blockTime: 2_000,
8
+ nativeCurrency: { name: 'SOSO', symbol: 'SOSO', decimals: 18 },
9
+ rpcUrls: {
10
+ default: {
11
+ http: ['https://testnet.valuechain.xyz'],
12
+ },
13
+ },
14
+ blockExplorers: {
15
+ default: {
16
+ name: 'ValueChain Testnet Explorer',
17
+ url: 'https://test-scan.valuechain.xyz',
18
+ },
19
+ },
20
+ testnet: true,
21
+ })
package/chains/index.ts CHANGED
@@ -434,6 +434,7 @@ export { mitosisTestnet } from './definitions/mitosisTestnet.js'
434
434
  export { mizuhikiTestnetAwaji } from './definitions/mizuhikiTestnetAwaji.js'
435
435
  export { mode } from './definitions/mode.js'
436
436
  export { modeTestnet } from './definitions/modeTestnet.js'
437
+ export { molibra } from './definitions/molibra.js'
437
438
  export { monad } from './definitions/monad.js'
438
439
  export { monadTestnet } from './definitions/monadTestnet.js'
439
440
  export { moonbaseAlpha } from './definitions/moonbaseAlpha.js'
@@ -699,6 +700,10 @@ export { unique } from './definitions/unique.js'
699
700
  export { uniqueOpal } from './definitions/uniqueOpal.js'
700
701
  export { uniqueQuartz } from './definitions/uniqueQuartz.js'
701
702
  export { unreal } from './definitions/unreal.js'
703
+ /** ValueChain mainnet. */
704
+ export { valuechain } from './definitions/valuechain.js'
705
+ /** ValueChain testnet. */
706
+ export { valuechainTestnet } from './definitions/valuechainTestnet.js'
702
707
  export { valygoNft } from './definitions/valygoNft.js'
703
708
  export { valygoSmartchain } from './definitions/valygoSmartchain.js'
704
709
  export { vana } from './definitions/vana.js'
@@ -1954,6 +1954,9 @@ export type PublicActions<
1954
1954
  * - Calls [`eth_getBlockByNumber`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getblockbynumber) and extracts the transactions
1955
1955
  * - Checks if one of the Transactions is a replacement
1956
1956
  * - If so, calls [`eth_getTransactionReceipt`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getTransactionReceipt).
1957
+ * - If the Transaction is not found and `replacement` is provided:
1958
+ * - Calls `eth_getTransactionBySenderAndNonce` to find the Transaction in its nonce slot
1959
+ * - If it is a replacement, calls [`eth_getTransactionReceipt`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getTransactionReceipt).
1957
1960
  *
1958
1961
  * @remarks
1959
1962
  * The `waitForTransactionReceipt` action additionally supports Replacement detection (e.g. sped up Transactions).
@@ -2080,7 +2083,7 @@ export type PublicActions<
2080
2083
  * @remarks
2081
2084
  * This Action will batch up all the event logs found within the [`pollingInterval`](https://viem.sh/docs/contract/watchContractEvent#pollinginterval-optional), and invoke them via [`onLogs`](https://viem.sh/docs/contract/watchContractEvent#onLogs).
2082
2085
  *
2083
- * `watchContractEvent` will attempt to create an [Event Filter](https://viem.sh/docs/contract/createContractEventFilter) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchContractEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs) instead.
2086
+ * `watchContractEvent` will attempt to create an [Event Filter](https://viem.sh/docs/contract/createContractEventFilter) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchContractEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs) instead. If `getLogs` fails for a block range, `watchContractEvent` will retry with smaller block ranges and may call `onLogs` more than once per polling interval.
2084
2087
  *
2085
2088
  * @param args - {@link WatchContractEventParameters}
2086
2089
  * @returns A function that can be invoked to stop watching for new event logs. {@link WatchContractEventReturnType}
@@ -2122,7 +2125,7 @@ export type PublicActions<
2122
2125
  * @remarks
2123
2126
  * This Action will batch up all the Event Logs found within the [`pollingInterval`](https://viem.sh/docs/actions/public/watchEvent#pollinginterval-optional), and invoke them via [`onLogs`](https://viem.sh/docs/actions/public/watchEvent#onLogs).
2124
2127
  *
2125
- * `watchEvent` will attempt to create an [Event Filter](https://viem.sh/docs/actions/public/createEventFilter) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs) instead.
2128
+ * `watchEvent` will attempt to create an [Event Filter](https://viem.sh/docs/actions/public/createEventFilter) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs) instead. If `getLogs` fails for a block range, `watchEvent` will retry with smaller block ranges and may call `onLogs` more than once per polling interval.
2126
2129
  *
2127
2130
  * @param args - {@link WatchEventParameters}
2128
2131
  * @returns A function that can be invoked to stop watching for new Event Logs. {@link WatchEventReturnType}
@@ -170,7 +170,12 @@ export function http<
170
170
  }),
171
171
  ]
172
172
 
173
- const [{ error, result }] = await fn(body)
173
+ const [{ error, result }] = await fn(body).catch((err) => {
174
+ // Raw transports also return JSON-RPC errors from non-2xx responses.
175
+ if (raw && err instanceof RpcRequestError)
176
+ return [{ error: err.cause, result: undefined }]
177
+ throw err
178
+ })
174
179
 
175
180
  if (raw) return { error, result }
176
181
  if (error)
package/errors/node.ts CHANGED
@@ -151,7 +151,7 @@ export type InsufficientFundsErrorType = InsufficientFundsError & {
151
151
  }
152
152
  export class InsufficientFundsError extends BaseError {
153
153
  static nodeMessage =
154
- /insufficient funds|exceeds transaction sender account balance/
154
+ /insufficient funds|exceeds transaction sender account balance|outoffunds/
155
155
  constructor({ cause }: { cause?: BaseError | undefined } = {}) {
156
156
  super(
157
157
  [
package/errors/request.ts CHANGED
@@ -96,24 +96,38 @@ export type RpcRequestErrorType = RpcRequestError & {
96
96
  export class RpcRequestError extends BaseError {
97
97
  code: number
98
98
  data?: unknown
99
+ /** Response headers, when the error came from a non-2xx HTTP response. */
100
+ headers?: Headers | undefined
101
+ /** Response status, when the error came from a non-2xx HTTP response. */
102
+ status?: number | undefined
99
103
  url: string
100
104
  constructor({
101
105
  body,
102
106
  error,
107
+ headers,
108
+ status,
103
109
  url,
104
110
  }: {
105
111
  body: { [x: string]: unknown } | { [y: string]: unknown }[]
106
112
  error: { code: number; data?: unknown; message: string }
113
+ headers?: Headers | undefined
114
+ status?: number | undefined
107
115
  url: string
108
116
  }) {
109
117
  super('RPC Request failed.', {
110
118
  cause: error as any,
111
119
  details: error.message,
112
- metaMessages: [`URL: ${getUrl(url)}`, `Request body: ${stringify(body)}`],
120
+ metaMessages: [
121
+ status && `Status: ${status}`,
122
+ `URL: ${getUrl(url)}`,
123
+ `Request body: ${stringify(body)}`,
124
+ ].filter(Boolean) as string[],
113
125
  name: 'RpcRequestError',
114
126
  })
115
127
  this.code = error.code
116
128
  this.data = error.data
129
+ this.headers = headers
130
+ this.status = status
117
131
  this.url = url
118
132
  }
119
133
  }
@@ -38,7 +38,9 @@ export type InvalidStructTypeErrorType = InvalidStructTypeError & {
38
38
  export class InvalidStructTypeError extends BaseError {
39
39
  constructor({ type }: { type: string }) {
40
40
  super(`Struct type "${type}" is invalid.`, {
41
- metaMessages: ['Struct type must not be a Solidity type.'],
41
+ metaMessages: [
42
+ 'Struct type must contain only letters, digits, "_" and "$", and must not be a Solidity type.',
43
+ ],
42
44
  name: 'InvalidStructTypeError',
43
45
  })
44
46
  }
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.57.11'
1
+ export const version = '2.57.13'
package/op-stack/abis.ts CHANGED
@@ -479,6 +479,58 @@ export const l2ToL1MessagePasserAbi = [
479
479
  ] as const
480
480
 
481
481
  export const disputeGameAbi = [
482
+ {
483
+ type: 'function',
484
+ name: 'createdAt',
485
+ inputs: [],
486
+ outputs: [
487
+ {
488
+ name: '',
489
+ type: 'uint64',
490
+ internalType: 'uint64',
491
+ },
492
+ ],
493
+ stateMutability: 'view',
494
+ },
495
+ {
496
+ type: 'function',
497
+ name: 'expectedResolution',
498
+ inputs: [],
499
+ outputs: [
500
+ {
501
+ name: '',
502
+ type: 'uint64',
503
+ internalType: 'uint64',
504
+ },
505
+ ],
506
+ stateMutability: 'view',
507
+ },
508
+ {
509
+ type: 'function',
510
+ name: 'maxClockDuration',
511
+ inputs: [],
512
+ outputs: [
513
+ {
514
+ name: 'maxClockDuration_',
515
+ type: 'uint64',
516
+ internalType: 'uint64',
517
+ },
518
+ ],
519
+ stateMutability: 'view',
520
+ },
521
+ {
522
+ type: 'function',
523
+ name: 'resolvedAt',
524
+ inputs: [],
525
+ outputs: [
526
+ {
527
+ name: '',
528
+ type: 'uint64',
529
+ internalType: 'uint64',
530
+ },
531
+ ],
532
+ stateMutability: 'view',
533
+ },
482
534
  {
483
535
  type: 'function',
484
536
  name: 'l2SequenceNumber',
@@ -2,10 +2,14 @@ import {
2
2
  type MulticallErrorType,
3
3
  multicall,
4
4
  } from '../../actions/public/multicall.js'
5
- import { readContract } from '../../actions/public/readContract.js'
5
+ import {
6
+ type ReadContractErrorType,
7
+ readContract,
8
+ } from '../../actions/public/readContract.js'
6
9
  import type { Client } from '../../clients/createClient.js'
7
10
  import type { Transport } from '../../clients/transports/createTransport.js'
8
11
  import { BaseError } from '../../errors/base.js'
12
+ import { ContractFunctionRevertedError } from '../../errors/contract.js'
9
13
  import type { ErrorType } from '../../errors/utils.js'
10
14
  import type { Account } from '../../types/account.js'
11
15
  import type {
@@ -14,7 +18,12 @@ import type {
14
18
  GetChainParameter,
15
19
  } from '../../types/chain.js'
16
20
  import type { Hash } from '../../types/misc.js'
17
- import { l2OutputOracleAbi, portal2Abi, portalAbi } from '../abis.js'
21
+ import {
22
+ disputeGameAbi,
23
+ l2OutputOracleAbi,
24
+ portal2Abi,
25
+ portalAbi,
26
+ } from '../abis.js'
18
27
  import type { GetContractAddressParameter } from '../types/contract.js'
19
28
  import { getPortalVersion } from './getPortalVersion.js'
20
29
 
@@ -27,14 +36,17 @@ export type GetTimeToFinalizeParameters<
27
36
  withdrawalHash: Hash
28
37
  }
29
38
  export type GetTimeToFinalizeReturnType = {
30
- /** The finalization period (in seconds). */
39
+ /** The proof maturity delay (in seconds). */
31
40
  period: number
32
41
  /** Seconds until the withdrawal can be finalized. */
33
42
  seconds: number
34
43
  /** Timestamp of when the withdrawal can be finalized. */
35
44
  timestamp: number
36
45
  }
37
- export type GetTimeToFinalizeErrorType = MulticallErrorType | ErrorType
46
+ export type GetTimeToFinalizeErrorType =
47
+ | MulticallErrorType
48
+ | ReadContractErrorType
49
+ | ErrorType
38
50
 
39
51
  const buffer = 10
40
52
 
@@ -142,7 +154,7 @@ export async function getTimeToFinalize<
142
154
  args: [withdrawalHash, numProofSubmitters - 1n],
143
155
  }).catch(() => undefined)
144
156
 
145
- const [[_disputeGameProxy, proveTimestamp], proofMaturityDelaySeconds] =
157
+ const [[disputeGameProxy, proveTimestamp], proofMaturityDelaySeconds] =
146
158
  await Promise.all([
147
159
  proofSubmitter
148
160
  ? readContract(client, {
@@ -151,7 +163,7 @@ export async function getTimeToFinalize<
151
163
  functionName: 'provenWithdrawals',
152
164
  args: [withdrawalHash, proofSubmitter],
153
165
  })
154
- : Promise.resolve(['0x', 0n]),
166
+ : Promise.resolve(['0x', 0n] as const),
155
167
  readContract(client, {
156
168
  abi: portal2Abi,
157
169
  address: portalAddress,
@@ -162,14 +174,81 @@ export async function getTimeToFinalize<
162
174
  if (proveTimestamp === 0n)
163
175
  throw new BaseError('Withdrawal has not been proven on L1.')
164
176
 
165
- const secondsSinceProven = Date.now() / 1000 - Number(proveTimestamp)
166
- const secondsToFinalize =
167
- Number(proofMaturityDelaySeconds) - secondsSinceProven
177
+ // The withdrawal can only be finalized once the proof's dispute game is
178
+ // resolved and its finality delay has passed, so also read the game.
179
+ const [
180
+ resolvedAt,
181
+ createdAt,
182
+ expectedResolution,
183
+ maxClockDuration,
184
+ disputeGameFinalityDelaySeconds,
185
+ ] = await Promise.all([
186
+ readContract(client, {
187
+ abi: disputeGameAbi,
188
+ address: disputeGameProxy,
189
+ functionName: 'resolvedAt',
190
+ }),
191
+ readContract(client, {
192
+ abi: disputeGameAbi,
193
+ address: disputeGameProxy,
194
+ functionName: 'createdAt',
195
+ }),
196
+ // Only some game types implement `expectedResolution` (e.g. `AggregateVerifier`).
197
+ readContract(client, {
198
+ abi: disputeGameAbi,
199
+ address: disputeGameProxy,
200
+ functionName: 'expectedResolution',
201
+ }).catch(unsupported),
202
+ // Only some game types implement `maxClockDuration` (e.g. `FaultDisputeGame`).
203
+ readContract(client, {
204
+ abi: disputeGameAbi,
205
+ address: disputeGameProxy,
206
+ functionName: 'maxClockDuration',
207
+ }).catch(unsupported),
208
+ readContract(client, {
209
+ abi: portal2Abi,
210
+ address: portalAddress,
211
+ functionName: 'disputeGameFinalityDelaySeconds',
212
+ }),
213
+ ])
214
+
215
+ const now = Date.now() / 1000
216
+
217
+ // When the game is not resolved yet, estimate when it will be: the expected
218
+ // resolution reported by the game, or the end of an unchallenged root claim's clock.
219
+ // An unresolved game cannot have resolved in the past, so the estimate is at least `now`.
220
+ const gameResolvedAt = (() => {
221
+ if (resolvedAt > 0n) return Number(resolvedAt)
222
+ const estimate = (() => {
223
+ if (typeof expectedResolution === 'bigint') return expectedResolution
224
+ if (typeof maxClockDuration === 'bigint')
225
+ return createdAt + maxClockDuration
226
+ return undefined
227
+ })()
228
+ // Without an estimate, only the proof maturity delay applies.
229
+ if (estimate === undefined) return 0
230
+ return Math.max(Number(estimate), now)
231
+ })()
232
+
233
+ const secondsToProofMaturity =
234
+ Number(proofMaturityDelaySeconds) - (now - Number(proveTimestamp))
235
+ const secondsToGameFinality =
236
+ gameResolvedAt + Number(disputeGameFinalityDelaySeconds) - now
237
+ const secondsToFinalize = Math.max(
238
+ secondsToProofMaturity,
239
+ secondsToGameFinality,
240
+ )
168
241
 
169
242
  const seconds = Math.floor(
170
- secondsToFinalize < 0n ? 0 : secondsToFinalize + buffer,
243
+ secondsToFinalize < 0 ? 0 : secondsToFinalize + buffer,
171
244
  )
172
245
  const timestamp = Date.now() + seconds * 1000
173
246
 
174
247
  return { period: Number(proofMaturityDelaySeconds), seconds, timestamp }
175
248
  }
249
+
250
+ /** Returns `undefined` when the game does not implement the getter, and rethrows other errors. */
251
+ function unsupported(error: ReadContractErrorType) {
252
+ if (error.cause instanceof ContractFunctionRevertedError) return undefined
253
+ throw error
254
+ }
@@ -1,3 +1,7 @@
1
+ import {
2
+ type ReadContractErrorType,
3
+ readContract,
4
+ } from '../../actions/public/readContract.js'
1
5
  import type { Client } from '../../clients/createClient.js'
2
6
  import type { Transport } from '../../clients/transports/createTransport.js'
3
7
  import type { ErrorType } from '../../errors/utils.js'
@@ -9,6 +13,13 @@ import type {
9
13
  } from '../../types/chain.js'
10
14
  import type { TransactionReceipt } from '../../types/transaction.js'
11
15
  import type { OneOf } from '../../types/utils.js'
16
+ import { portal2Abi } from '../abis.js'
17
+ import {
18
+ L2TimestampRequiredError,
19
+ type L2TimestampRequiredErrorType,
20
+ } from '../errors/withdrawal.js'
21
+ import { isSuperGameType } from '../gameTypes.js'
22
+ import type { TargetChain } from '../types/chain.js'
12
23
  import type { GetContractAddressParameter } from '../types/contract.js'
13
24
  import {
14
25
  type GetPortalVersionErrorType,
@@ -62,6 +73,8 @@ export type GetTimeToProveErrorType =
62
73
  | GetPortalVersionErrorType
63
74
  | GetTimeToNextGameErrorType
64
75
  | GetTimeToNextL2OutputErrorType
76
+ | L2TimestampRequiredErrorType
77
+ | ReadContractErrorType
65
78
  | ErrorType
66
79
 
67
80
  /**
@@ -102,7 +115,14 @@ export async function getTimeToProve<
102
115
  client: Client<Transport, chain, account>,
103
116
  parameters: GetTimeToProveParameters<chain, chainOverride>,
104
117
  ): Promise<GetTimeToProveReturnType> {
105
- const { l2Timestamp, receipt } = parameters
118
+ const {
119
+ chain = client.chain,
120
+ l2Timestamp,
121
+ receipt,
122
+ targetChain: targetChain_,
123
+ } = parameters
124
+
125
+ const targetChain = targetChain_ as unknown as TargetChain
106
126
 
107
127
  const portalVersion = await getPortalVersion(
108
128
  client,
@@ -116,8 +136,29 @@ export async function getTimeToProve<
116
136
  l2BlockNumber: l2Timestamp ?? receipt.blockNumber,
117
137
  } as GetTimeToNextL2OutputParameters)
118
138
 
139
+ const portalAddress = (() => {
140
+ if (parameters.portalAddress) return parameters.portalAddress
141
+ if (chain) return targetChain.contracts.portal[chain.id].address
142
+ return Object.values(targetChain.contracts.portal)[0].address
143
+ })()
144
+
145
+ // Super-root games anchor on L2 timestamps instead of L2 block numbers.
146
+ const l2BlockNumber = await (async () => {
147
+ if (typeof l2Timestamp === 'bigint') return l2Timestamp
148
+ const gameType = await readContract(client, {
149
+ abi: portal2Abi,
150
+ address: portalAddress,
151
+ functionName: 'respectedGameType',
152
+ })
153
+ if (!isSuperGameType(gameType)) return receipt.blockNumber
154
+ const timestamp = receipt.logs[0]?.blockTimestamp
155
+ if (typeof timestamp !== 'bigint')
156
+ throw new L2TimestampRequiredError({ gameType })
157
+ return timestamp
158
+ })()
159
+
119
160
  return getTimeToNextGame(client, {
120
161
  ...parameters,
121
- l2BlockNumber: l2Timestamp ?? receipt.blockNumber,
162
+ l2BlockNumber,
122
163
  } as GetTimeToNextGameParameters)
123
164
  }