viem 2.8.18 → 2.9.1

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 (254) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/_cjs/chains/definitions/blast.js +5 -1
  3. package/_cjs/chains/definitions/blast.js.map +1 -1
  4. package/_cjs/chains/definitions/blastSepolia.js +2 -1
  5. package/_cjs/chains/definitions/blastSepolia.js.map +1 -1
  6. package/_cjs/chains/definitions/optimismSepolia.js +5 -0
  7. package/_cjs/chains/definitions/optimismSepolia.js.map +1 -1
  8. package/_cjs/chains/definitions/reyaNetwork.js +23 -0
  9. package/_cjs/chains/definitions/reyaNetwork.js.map +1 -0
  10. package/_cjs/chains/index.js +4 -2
  11. package/_cjs/chains/index.js.map +1 -1
  12. package/_cjs/chains/opStack/abis.js +1070 -1
  13. package/_cjs/chains/opStack/abis.js.map +1 -1
  14. package/_cjs/chains/opStack/actions/buildProveWithdrawal.js +3 -3
  15. package/_cjs/chains/opStack/actions/buildProveWithdrawal.js.map +1 -1
  16. package/_cjs/chains/opStack/actions/getGame.js +20 -0
  17. package/_cjs/chains/opStack/actions/getGame.js.map +1 -0
  18. package/_cjs/chains/opStack/actions/getGames.js +56 -0
  19. package/_cjs/chains/opStack/actions/getGames.js.map +1 -0
  20. package/_cjs/chains/opStack/actions/getL2Output.js +12 -0
  21. package/_cjs/chains/opStack/actions/getL2Output.js.map +1 -1
  22. package/_cjs/chains/opStack/actions/getPortalVersion.js +25 -0
  23. package/_cjs/chains/opStack/actions/getPortalVersion.js.map +1 -0
  24. package/_cjs/chains/opStack/actions/getTimeToFinalize.js +52 -26
  25. package/_cjs/chains/opStack/actions/getTimeToFinalize.js.map +1 -1
  26. package/_cjs/chains/opStack/actions/getTimeToNextGame.js +45 -0
  27. package/_cjs/chains/opStack/actions/getTimeToNextGame.js.map +1 -0
  28. package/_cjs/chains/opStack/actions/getTimeToProve.js +9 -1
  29. package/_cjs/chains/opStack/actions/getTimeToProve.js.map +1 -1
  30. package/_cjs/chains/opStack/actions/getWithdrawalStatus.js +79 -28
  31. package/_cjs/chains/opStack/actions/getWithdrawalStatus.js.map +1 -1
  32. package/_cjs/chains/opStack/actions/proveWithdrawal.js +1 -1
  33. package/_cjs/chains/opStack/actions/proveWithdrawal.js.map +1 -1
  34. package/_cjs/chains/opStack/actions/waitForNextGame.js +35 -0
  35. package/_cjs/chains/opStack/actions/waitForNextGame.js.map +1 -0
  36. package/_cjs/chains/opStack/actions/waitForNextL2Output.js.map +1 -1
  37. package/_cjs/chains/opStack/actions/waitToProve.js +34 -3
  38. package/_cjs/chains/opStack/actions/waitToProve.js.map +1 -1
  39. package/_cjs/chains/opStack/decorators/publicL1.js +10 -0
  40. package/_cjs/chains/opStack/decorators/publicL1.js.map +1 -1
  41. package/_cjs/chains/opStack/errors/withdrawal.js +13 -1
  42. package/_cjs/chains/opStack/errors/withdrawal.js.map +1 -1
  43. package/_cjs/chains/opStack/index.js +11 -1
  44. package/_cjs/chains/opStack/index.js.map +1 -1
  45. package/_cjs/chains/zksync/actions/deployContract.js +26 -0
  46. package/_cjs/chains/zksync/actions/deployContract.js.map +1 -0
  47. package/_cjs/chains/zksync/constants/abis.js +427 -0
  48. package/_cjs/chains/zksync/constants/abis.js.map +1 -0
  49. package/_cjs/chains/zksync/constants/address.js +5 -0
  50. package/_cjs/chains/zksync/constants/address.js.map +1 -0
  51. package/_cjs/chains/zksync/constants/contract.js +6 -0
  52. package/_cjs/chains/zksync/constants/contract.js.map +1 -0
  53. package/_cjs/chains/zksync/constants/number.js +6 -0
  54. package/_cjs/chains/zksync/constants/number.js.map +1 -0
  55. package/_cjs/chains/zksync/decorators/eip712.js +2 -0
  56. package/_cjs/chains/zksync/decorators/eip712.js.map +1 -1
  57. package/_cjs/chains/zksync/errors/bytecode.js +41 -0
  58. package/_cjs/chains/zksync/errors/bytecode.js.map +1 -0
  59. package/_cjs/chains/zksync/formatters.js +5 -1
  60. package/_cjs/chains/zksync/formatters.js.map +1 -1
  61. package/_cjs/chains/zksync/index.js +3 -1
  62. package/_cjs/chains/zksync/index.js.map +1 -1
  63. package/_cjs/chains/zksync/types/contract.js +3 -0
  64. package/_cjs/chains/zksync/types/contract.js.map +1 -0
  65. package/_cjs/chains/zksync/utils/abi/encodeDeployData.js +68 -0
  66. package/_cjs/chains/zksync/utils/abi/encodeDeployData.js.map +1 -0
  67. package/_cjs/chains/zksync/utils/getEip712Domain.js +4 -2
  68. package/_cjs/chains/zksync/utils/getEip712Domain.js.map +1 -1
  69. package/_cjs/chains/zksync/utils/hashBytecode.js +36 -0
  70. package/_cjs/chains/zksync/utils/hashBytecode.js.map +1 -0
  71. package/_cjs/errors/version.js +1 -1
  72. package/_cjs/errors/version.js.map +1 -1
  73. package/_esm/chains/definitions/blast.js +5 -1
  74. package/_esm/chains/definitions/blast.js.map +1 -1
  75. package/_esm/chains/definitions/blastSepolia.js +2 -1
  76. package/_esm/chains/definitions/blastSepolia.js.map +1 -1
  77. package/_esm/chains/definitions/optimismSepolia.js +5 -0
  78. package/_esm/chains/definitions/optimismSepolia.js.map +1 -1
  79. package/_esm/chains/definitions/reyaNetwork.js +20 -0
  80. package/_esm/chains/definitions/reyaNetwork.js.map +1 -0
  81. package/_esm/chains/index.js +1 -0
  82. package/_esm/chains/index.js.map +1 -1
  83. package/_esm/chains/opStack/abis.js +1069 -0
  84. package/_esm/chains/opStack/abis.js.map +1 -1
  85. package/_esm/chains/opStack/actions/buildProveWithdrawal.js +4 -3
  86. package/_esm/chains/opStack/actions/buildProveWithdrawal.js.map +1 -1
  87. package/_esm/chains/opStack/actions/getGame.js +40 -0
  88. package/_esm/chains/opStack/actions/getGame.js.map +1 -0
  89. package/_esm/chains/opStack/actions/getGames.js +75 -0
  90. package/_esm/chains/opStack/actions/getGames.js.map +1 -0
  91. package/_esm/chains/opStack/actions/getL2Output.js +12 -0
  92. package/_esm/chains/opStack/actions/getL2Output.js.map +1 -1
  93. package/_esm/chains/opStack/actions/getPortalVersion.js +48 -0
  94. package/_esm/chains/opStack/actions/getPortalVersion.js.map +1 -0
  95. package/_esm/chains/opStack/actions/getTimeToFinalize.js +54 -27
  96. package/_esm/chains/opStack/actions/getTimeToFinalize.js.map +1 -1
  97. package/_esm/chains/opStack/actions/getTimeToNextGame.js +71 -0
  98. package/_esm/chains/opStack/actions/getTimeToNextGame.js.map +1 -0
  99. package/_esm/chains/opStack/actions/getTimeToProve.js +10 -1
  100. package/_esm/chains/opStack/actions/getTimeToProve.js.map +1 -1
  101. package/_esm/chains/opStack/actions/getWithdrawalStatus.js +84 -32
  102. package/_esm/chains/opStack/actions/getWithdrawalStatus.js.map +1 -1
  103. package/_esm/chains/opStack/actions/proveWithdrawal.js +1 -1
  104. package/_esm/chains/opStack/actions/proveWithdrawal.js.map +1 -1
  105. package/_esm/chains/opStack/actions/waitForNextGame.js +61 -0
  106. package/_esm/chains/opStack/actions/waitForNextGame.js.map +1 -0
  107. package/_esm/chains/opStack/actions/waitForNextL2Output.js.map +1 -1
  108. package/_esm/chains/opStack/actions/waitToProve.js +35 -3
  109. package/_esm/chains/opStack/actions/waitToProve.js.map +1 -1
  110. package/_esm/chains/opStack/decorators/publicL1.js +10 -0
  111. package/_esm/chains/opStack/decorators/publicL1.js.map +1 -1
  112. package/_esm/chains/opStack/errors/withdrawal.js +11 -0
  113. package/_esm/chains/opStack/errors/withdrawal.js.map +1 -1
  114. package/_esm/chains/opStack/index.js +5 -0
  115. package/_esm/chains/opStack/index.js.map +1 -1
  116. package/_esm/chains/zksync/actions/deployContract.js +52 -0
  117. package/_esm/chains/zksync/actions/deployContract.js.map +1 -0
  118. package/_esm/chains/zksync/constants/abis.js +425 -0
  119. package/_esm/chains/zksync/constants/abis.js.map +1 -0
  120. package/_esm/chains/zksync/constants/address.js +2 -0
  121. package/_esm/chains/zksync/constants/address.js.map +1 -0
  122. package/_esm/chains/zksync/constants/contract.js +3 -0
  123. package/_esm/chains/zksync/constants/contract.js.map +1 -0
  124. package/_esm/chains/zksync/constants/number.js +3 -0
  125. package/_esm/chains/zksync/constants/number.js.map +1 -0
  126. package/_esm/chains/zksync/decorators/eip712.js +2 -0
  127. package/_esm/chains/zksync/decorators/eip712.js.map +1 -1
  128. package/_esm/chains/zksync/errors/bytecode.js +35 -0
  129. package/_esm/chains/zksync/errors/bytecode.js.map +1 -0
  130. package/_esm/chains/zksync/formatters.js +5 -1
  131. package/_esm/chains/zksync/formatters.js.map +1 -1
  132. package/_esm/chains/zksync/index.js +1 -0
  133. package/_esm/chains/zksync/index.js.map +1 -1
  134. package/_esm/chains/zksync/types/contract.js +2 -0
  135. package/_esm/chains/zksync/types/contract.js.map +1 -0
  136. package/_esm/chains/zksync/utils/abi/encodeDeployData.js +65 -0
  137. package/_esm/chains/zksync/utils/abi/encodeDeployData.js.map +1 -0
  138. package/_esm/chains/zksync/utils/getEip712Domain.js +4 -2
  139. package/_esm/chains/zksync/utils/getEip712Domain.js.map +1 -1
  140. package/_esm/chains/zksync/utils/hashBytecode.js +36 -0
  141. package/_esm/chains/zksync/utils/hashBytecode.js.map +1 -0
  142. package/_esm/errors/version.js +1 -1
  143. package/_esm/errors/version.js.map +1 -1
  144. package/_types/chains/definitions/blast.d.ts +1 -0
  145. package/_types/chains/definitions/blast.d.ts.map +1 -1
  146. package/_types/chains/definitions/blastSepolia.d.ts +2 -1
  147. package/_types/chains/definitions/blastSepolia.d.ts.map +1 -1
  148. package/_types/chains/definitions/optimismSepolia.d.ts +5 -0
  149. package/_types/chains/definitions/optimismSepolia.d.ts.map +1 -1
  150. package/_types/chains/definitions/reyaNetwork.d.ts +36 -0
  151. package/_types/chains/definitions/reyaNetwork.d.ts.map +1 -0
  152. package/_types/chains/index.d.ts +1 -0
  153. package/_types/chains/index.d.ts.map +1 -1
  154. package/_types/chains/opStack/abis.d.ts +824 -0
  155. package/_types/chains/opStack/abis.d.ts.map +1 -1
  156. package/_types/chains/opStack/actions/buildProveWithdrawal.d.ts +6 -2
  157. package/_types/chains/opStack/actions/buildProveWithdrawal.d.ts.map +1 -1
  158. package/_types/chains/opStack/actions/getGame.d.ts +57 -0
  159. package/_types/chains/opStack/actions/getGame.d.ts.map +1 -0
  160. package/_types/chains/opStack/actions/getGames.d.ts +48 -0
  161. package/_types/chains/opStack/actions/getGames.d.ts.map +1 -0
  162. package/_types/chains/opStack/actions/getL2Output.d.ts +8 -1
  163. package/_types/chains/opStack/actions/getL2Output.d.ts.map +1 -1
  164. package/_types/chains/opStack/actions/getPortalVersion.d.ts +46 -0
  165. package/_types/chains/opStack/actions/getPortalVersion.d.ts.map +1 -0
  166. package/_types/chains/opStack/actions/getTimeToFinalize.d.ts.map +1 -1
  167. package/_types/chains/opStack/actions/getTimeToNextGame.d.ts +61 -0
  168. package/_types/chains/opStack/actions/getTimeToNextGame.d.ts.map +1 -0
  169. package/_types/chains/opStack/actions/getTimeToProve.d.ts +6 -3
  170. package/_types/chains/opStack/actions/getTimeToProve.d.ts.map +1 -1
  171. package/_types/chains/opStack/actions/getWithdrawalStatus.d.ts +7 -1
  172. package/_types/chains/opStack/actions/getWithdrawalStatus.d.ts.map +1 -1
  173. package/_types/chains/opStack/actions/proveWithdrawal.d.ts +1 -1
  174. package/_types/chains/opStack/actions/proveWithdrawal.d.ts.map +1 -1
  175. package/_types/chains/opStack/actions/waitForNextGame.d.ts +60 -0
  176. package/_types/chains/opStack/actions/waitForNextGame.d.ts.map +1 -0
  177. package/_types/chains/opStack/actions/waitForNextL2Output.d.ts.map +1 -1
  178. package/_types/chains/opStack/actions/waitToProve.d.ts +10 -2
  179. package/_types/chains/opStack/actions/waitToProve.d.ts.map +1 -1
  180. package/_types/chains/opStack/decorators/publicL1.d.ts +129 -0
  181. package/_types/chains/opStack/decorators/publicL1.d.ts.map +1 -1
  182. package/_types/chains/opStack/errors/withdrawal.d.ts +7 -0
  183. package/_types/chains/opStack/errors/withdrawal.d.ts.map +1 -1
  184. package/_types/chains/opStack/index.d.ts +5 -0
  185. package/_types/chains/opStack/index.d.ts.map +1 -1
  186. package/_types/chains/opStack/types/chain.d.ts +1 -1
  187. package/_types/chains/opStack/types/chain.d.ts.map +1 -1
  188. package/_types/chains/opStack/types/withdrawal.d.ts +7 -0
  189. package/_types/chains/opStack/types/withdrawal.d.ts.map +1 -1
  190. package/_types/chains/zksync/actions/deployContract.d.ts +49 -0
  191. package/_types/chains/zksync/actions/deployContract.d.ts.map +1 -0
  192. package/_types/chains/zksync/constants/abis.d.ts +70 -0
  193. package/_types/chains/zksync/constants/abis.d.ts.map +1 -0
  194. package/_types/chains/zksync/constants/address.d.ts +2 -0
  195. package/_types/chains/zksync/constants/address.d.ts.map +1 -0
  196. package/_types/chains/zksync/constants/contract.d.ts +3 -0
  197. package/_types/chains/zksync/constants/contract.d.ts.map +1 -0
  198. package/_types/chains/zksync/constants/number.d.ts +2 -0
  199. package/_types/chains/zksync/constants/number.d.ts.map +1 -0
  200. package/_types/chains/zksync/decorators/eip712.d.ts +32 -0
  201. package/_types/chains/zksync/decorators/eip712.d.ts.map +1 -1
  202. package/_types/chains/zksync/errors/bytecode.d.ts +30 -0
  203. package/_types/chains/zksync/errors/bytecode.d.ts.map +1 -0
  204. package/_types/chains/zksync/formatters.d.ts.map +1 -1
  205. package/_types/chains/zksync/index.d.ts +1 -0
  206. package/_types/chains/zksync/index.d.ts.map +1 -1
  207. package/_types/chains/zksync/types/contract.d.ts +2 -0
  208. package/_types/chains/zksync/types/contract.d.ts.map +1 -0
  209. package/_types/chains/zksync/utils/abi/encodeDeployData.d.ts +13 -0
  210. package/_types/chains/zksync/utils/abi/encodeDeployData.d.ts.map +1 -0
  211. package/_types/chains/zksync/utils/getEip712Domain.d.ts.map +1 -1
  212. package/_types/chains/zksync/utils/hashBytecode.d.ts +3 -0
  213. package/_types/chains/zksync/utils/hashBytecode.d.ts.map +1 -0
  214. package/_types/errors/version.d.ts +1 -1
  215. package/_types/errors/version.d.ts.map +1 -1
  216. package/chains/definitions/blast.ts +5 -1
  217. package/chains/definitions/blastSepolia.ts +2 -1
  218. package/chains/definitions/optimismSepolia.ts +5 -0
  219. package/chains/definitions/reyaNetwork.ts +20 -0
  220. package/chains/index.ts +1 -0
  221. package/chains/opStack/abis.ts +1071 -0
  222. package/chains/opStack/actions/buildProveWithdrawal.ts +7 -6
  223. package/chains/opStack/actions/getGame.ts +99 -0
  224. package/chains/opStack/actions/getGames.ts +133 -0
  225. package/chains/opStack/actions/getL2Output.ts +44 -3
  226. package/chains/opStack/actions/getPortalVersion.ts +87 -0
  227. package/chains/opStack/actions/getTimeToFinalize.ts +64 -27
  228. package/chains/opStack/actions/getTimeToNextGame.ts +143 -0
  229. package/chains/opStack/actions/getTimeToProve.ts +43 -5
  230. package/chains/opStack/actions/getWithdrawalStatus.ts +130 -38
  231. package/chains/opStack/actions/proveWithdrawal.ts +3 -1
  232. package/chains/opStack/actions/waitForNextGame.ts +122 -0
  233. package/chains/opStack/actions/waitForNextL2Output.ts +5 -1
  234. package/chains/opStack/actions/waitToProve.ts +65 -7
  235. package/chains/opStack/decorators/publicL1.ts +164 -0
  236. package/chains/opStack/errors/withdrawal.ts +10 -0
  237. package/chains/opStack/index.ts +30 -0
  238. package/chains/opStack/types/chain.ts +4 -1
  239. package/chains/opStack/types/withdrawal.ts +8 -0
  240. package/chains/zksync/actions/deployContract.ts +100 -0
  241. package/chains/zksync/constants/abis.ts +424 -0
  242. package/chains/zksync/constants/address.ts +2 -0
  243. package/chains/zksync/constants/contract.ts +2 -0
  244. package/chains/zksync/constants/number.ts +3 -0
  245. package/chains/zksync/decorators/eip712.ts +47 -0
  246. package/chains/zksync/errors/bytecode.ts +46 -0
  247. package/chains/zksync/formatters.ts +7 -1
  248. package/chains/zksync/index.ts +6 -0
  249. package/chains/zksync/types/contract.ts +6 -0
  250. package/chains/zksync/utils/abi/encodeDeployData.ts +120 -0
  251. package/chains/zksync/utils/getEip712Domain.ts +4 -2
  252. package/chains/zksync/utils/hashBytecode.ts +48 -0
  253. package/errors/version.ts +1 -1
  254. package/package.json +1 -1
@@ -8,6 +8,7 @@ import type {
8
8
  GetChainParameter,
9
9
  } from '../../../types/chain.js'
10
10
  import type { TransactionReceipt } from '../../../types/transaction.js'
11
+ import type { OneOf } from '../../../types/utils.js'
11
12
  import { ReceiptContainsNoWithdrawalsError } from '../errors/withdrawal.js'
12
13
  import type { GetContractAddressParameter } from '../types/contract.js'
13
14
  import type { Withdrawal } from '../types/withdrawal.js'
@@ -15,8 +16,18 @@ import {
15
16
  type GetWithdrawalsErrorType,
16
17
  getWithdrawals,
17
18
  } from '../utils/getWithdrawals.js'
19
+ import {
20
+ type GetPortalVersionParameters,
21
+ getPortalVersion,
22
+ } from './getPortalVersion.js'
23
+ import {
24
+ type WaitForNextGameParameters,
25
+ type WaitForNextGameReturnType,
26
+ waitForNextGame,
27
+ } from './waitForNextGame.js'
18
28
  import {
19
29
  type WaitForNextL2OutputErrorType,
30
+ type WaitForNextL2OutputParameters,
20
31
  type WaitForNextL2OutputReturnType,
21
32
  waitForNextL2Output,
22
33
  } from './waitForNextL2Output.js'
@@ -26,7 +37,18 @@ export type WaitToProveParameters<
26
37
  chainOverride extends Chain | undefined = Chain | undefined,
27
38
  _derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
28
39
  > = GetChainParameter<chain, chainOverride> &
29
- GetContractAddressParameter<_derivedChain, 'l2OutputOracle'> & {
40
+ OneOf<
41
+ | GetContractAddressParameter<_derivedChain, 'l2OutputOracle'>
42
+ | GetContractAddressParameter<
43
+ _derivedChain,
44
+ 'disputeGameFactory' | 'portal'
45
+ >
46
+ > & {
47
+ /**
48
+ * Limit of games to extract.
49
+ * @default 100
50
+ */
51
+ gameLimit?: number | undefined
30
52
  receipt: TransactionReceipt
31
53
  /**
32
54
  * Polling frequency (in ms). Defaults to Client's pollingInterval config.
@@ -35,9 +57,11 @@ export type WaitToProveParameters<
35
57
  pollingInterval?: number | undefined
36
58
  }
37
59
  export type WaitToProveReturnType = {
38
- withdrawal: Withdrawal
60
+ game: WaitForNextGameReturnType
39
61
  output: WaitForNextL2OutputReturnType
62
+ withdrawal: Withdrawal
40
63
  }
64
+
41
65
  export type WaitToProveErrorType =
42
66
  | GetWithdrawalsErrorType
43
67
  | WaitForNextL2OutputErrorType
@@ -81,7 +105,7 @@ export async function waitToProve<
81
105
  client: Client<Transport, chain, account>,
82
106
  parameters: WaitToProveParameters<chain, chainOverride>,
83
107
  ): Promise<WaitToProveReturnType> {
84
- const { receipt } = parameters
108
+ const { gameLimit, receipt } = parameters
85
109
 
86
110
  const [withdrawal] = getWithdrawals(receipt)
87
111
 
@@ -90,10 +114,44 @@ export async function waitToProve<
90
114
  hash: receipt.transactionHash,
91
115
  })
92
116
 
93
- const output = await waitForNextL2Output(client, {
117
+ const portalVersion = await getPortalVersion(
118
+ client,
119
+ parameters as GetPortalVersionParameters,
120
+ )
121
+
122
+ // Legacy (Portal < v3)
123
+ if (portalVersion.major < 3) {
124
+ const output = await waitForNextL2Output(client, {
125
+ ...parameters,
126
+ l2BlockNumber: receipt.blockNumber,
127
+ } as WaitForNextL2OutputParameters)
128
+ return {
129
+ game: {
130
+ extraData: '0x',
131
+ index: output.outputIndex,
132
+ l2BlockNumber: output.l2BlockNumber,
133
+ metadata: '0x',
134
+ rootClaim: output.outputRoot,
135
+ timestamp: output.timestamp,
136
+ },
137
+ output,
138
+ withdrawal,
139
+ }
140
+ }
141
+
142
+ const game = await waitForNextGame(client, {
94
143
  ...parameters,
144
+ limit: gameLimit,
95
145
  l2BlockNumber: receipt.blockNumber,
96
- })
97
-
98
- return { output, withdrawal }
146
+ } as WaitForNextGameParameters)
147
+ return {
148
+ game,
149
+ output: {
150
+ l2BlockNumber: game.l2BlockNumber,
151
+ outputIndex: game.index,
152
+ outputRoot: game.rootClaim,
153
+ timestamp: game.timestamp,
154
+ },
155
+ withdrawal,
156
+ }
99
157
  }
@@ -23,16 +23,36 @@ import {
23
23
  type EstimateProveWithdrawalGasReturnType,
24
24
  estimateProveWithdrawalGas,
25
25
  } from '../actions/estimateProveWithdrawalGas.js'
26
+ import {
27
+ type GetGameParameters,
28
+ type GetGameReturnType,
29
+ getGame,
30
+ } from '../actions/getGame.js'
31
+ import {
32
+ type GetGamesParameters,
33
+ type GetGamesReturnType,
34
+ getGames,
35
+ } from '../actions/getGames.js'
26
36
  import {
27
37
  type GetL2OutputParameters,
28
38
  type GetL2OutputReturnType,
29
39
  getL2Output,
30
40
  } from '../actions/getL2Output.js'
41
+ import {
42
+ type GetPortalVersionParameters,
43
+ type GetPortalVersionReturnType,
44
+ getPortalVersion,
45
+ } from '../actions/getPortalVersion.js'
31
46
  import {
32
47
  type GetTimeToFinalizeParameters,
33
48
  type GetTimeToFinalizeReturnType,
34
49
  getTimeToFinalize,
35
50
  } from '../actions/getTimeToFinalize.js'
51
+ import {
52
+ type GetTimeToNextGameParameters,
53
+ type GetTimeToNextGameReturnType,
54
+ getTimeToNextGame,
55
+ } from '../actions/getTimeToNextGame.js'
36
56
  import {
37
57
  type GetTimeToNextL2OutputParameters,
38
58
  type GetTimeToNextL2OutputReturnType,
@@ -48,6 +68,11 @@ import {
48
68
  type GetWithdrawalStatusReturnType,
49
69
  getWithdrawalStatus,
50
70
  } from '../actions/getWithdrawalStatus.js'
71
+ import {
72
+ type WaitForNextGameParameters,
73
+ type WaitForNextGameReturnType,
74
+ waitForNextGame,
75
+ } from '../actions/waitForNextGame.js'
51
76
  import {
52
77
  type WaitForNextL2OutputParameters,
53
78
  type WaitForNextL2OutputReturnType,
@@ -213,6 +238,57 @@ export type PublicActionsL1<
213
238
  chainOverride
214
239
  >,
215
240
  ) => Promise<EstimateFinalizeWithdrawalGasReturnType>
241
+ /**
242
+ * Retrieves a valid dispute game on an L2 that occurred after a provided L2 block number.
243
+ *
244
+ * - Docs: https://viem.sh/op-stack/actions/getGame
245
+ *
246
+ * @param client - Client to use
247
+ * @param parameters - {@link GetGameParameters}
248
+ * @returns A valid dispute game. {@link GetGameReturnType}
249
+ *
250
+ * @example
251
+ * import { createPublicClient, http } from 'viem'
252
+ * import { mainnet, optimism } from 'viem/chains'
253
+ *
254
+ * const publicClientL1 = createPublicClient({
255
+ * chain: mainnet,
256
+ * transport: http(),
257
+ * })
258
+ *
259
+ * const game = await publicClientL1.getGame({
260
+ * l2BlockNumber: 69420n,
261
+ * targetChain: optimism
262
+ * })
263
+ */
264
+ getGame: <chainOverride extends Chain | undefined = undefined>(
265
+ parameters: GetGameParameters<chain, chainOverride>,
266
+ ) => Promise<GetGameReturnType>
267
+ /**
268
+ * Retrieves dispute games for an L2.
269
+ *
270
+ * - Docs: https://viem.sh/op-stack/actions/getGame
271
+ *
272
+ * @param client - Client to use
273
+ * @param parameters - {@link GetGameParameters}
274
+ * @returns Dispute games. {@link GetGameReturnType}
275
+ *
276
+ * @example
277
+ * import { createPublicClient, http } from 'viem'
278
+ * import { mainnet, optimism } from 'viem/chains'
279
+ *
280
+ * const publicClientL1 = createPublicClient({
281
+ * chain: mainnet,
282
+ * transport: http(),
283
+ * })
284
+ *
285
+ * const games = await publicClientL1.getGames({
286
+ * targetChain: optimism
287
+ * })
288
+ */
289
+ getGames: <chainOverride extends Chain | undefined = undefined>(
290
+ parameters: GetGamesParameters<chain, chainOverride>,
291
+ ) => Promise<GetGamesReturnType>
216
292
  /**
217
293
  * Retrieves the first L2 output proposal that occurred after a provided block number. Used for the [Withdrawal](/op-stack/guides/withdrawals) flow.
218
294
  *
@@ -240,6 +316,35 @@ export type PublicActionsL1<
240
316
  getL2Output: <chainOverride extends Chain | undefined = undefined>(
241
317
  parameters: GetL2OutputParameters<chain, chainOverride>,
242
318
  ) => Promise<GetL2OutputReturnType>
319
+ /**
320
+ * Retrieves the current version of the Portal contract.
321
+ *
322
+ * - Docs: https://viem.sh/op-stack/actions/getPortalVersion
323
+ *
324
+ * @param client - Client to use
325
+ * @param parameters - {@link GetPortalVersionParameters}
326
+ * @returns The version object.
327
+ *
328
+ * @example
329
+ * import { createPublicClient, http } from 'viem'
330
+ * import { mainnet } from 'viem/chains'
331
+ *
332
+ * const publicClientL1 = createPublicClient({
333
+ * chain: mainnet,
334
+ * transport: http(),
335
+ * })
336
+ *
337
+ * const version = await publicClientL1.getPortalVersion({
338
+ * targetChain: optimism,
339
+ * })
340
+ *
341
+ * if (version.major > 3)
342
+ * console.log('Fault proofs are enabled on this version of optimism')
343
+ * console.log('Fault proofs are not enabled on this version of optimism')
344
+ */
345
+ getPortalVersion: <chainOverride extends Chain | undefined = undefined>(
346
+ parameters: GetPortalVersionParameters<chain, chainOverride>,
347
+ ) => Promise<GetPortalVersionReturnType>
243
348
  /**
244
349
  * Returns the time until the withdrawal transaction can be finalized. Used for the [Withdrawal](/op-stack/guides/withdrawals) flow.
245
350
  *
@@ -278,6 +383,34 @@ export type PublicActionsL1<
278
383
  getTimeToFinalize: <chainOverride extends Chain | undefined = undefined>(
279
384
  parameters: GetTimeToFinalizeParameters<chain, chainOverride>,
280
385
  ) => Promise<GetTimeToFinalizeReturnType>
386
+ /**
387
+ * Returns the time until the next L2 dispute game (after the provided block number) is submitted.
388
+ * Used for the [Withdrawal](/op-stack/guides/withdrawals) flow.
389
+ *
390
+ * - Docs: https://viem.sh/op-stack/actions/getTimeToNextGame
391
+ *
392
+ * @param client - Client to use
393
+ * @param parameters - {@link GetTimeToNextGameParameters}
394
+ * @returns The L2 transaction hash. {@link GetTimeToNextGameReturnType}
395
+ *
396
+ * @example
397
+ * import { createPublicClient, http } from 'viem'
398
+ * import { getBlockNumber } from 'viem/actions'
399
+ * import { mainnet, optimism } from 'viem/chains'
400
+ *
401
+ * const publicClientL1 = createPublicClient({
402
+ * chain: mainnet,
403
+ * transport: http(),
404
+ * })
405
+ *
406
+ * const { seconds } = await publicClientL1.getTimeToNextGame({
407
+ * l2BlockNumber: 113405763n,
408
+ * targetChain: optimism
409
+ * })
410
+ */
411
+ getTimeToNextGame: <chainOverride extends Chain | undefined = undefined>(
412
+ parameters: GetTimeToNextGameParameters<chain, chainOverride>,
413
+ ) => Promise<GetTimeToNextGameReturnType>
281
414
  /**
282
415
  * Returns the time until the next L2 output (after a provided block number) is submitted. Used for the [Withdrawal](/op-stack/guides/withdrawals) flow.
283
416
  *
@@ -381,6 +514,32 @@ export type PublicActionsL1<
381
514
  getWithdrawalStatus: <chainOverride extends Chain | undefined = undefined>(
382
515
  parameters: GetWithdrawalStatusParameters<chain, chainOverride>,
383
516
  ) => Promise<GetWithdrawalStatusReturnType>
517
+ /**
518
+ * Waits for the next L2 output (after the provided block number) to be submitted.
519
+ *
520
+ * - Docs: https://viem.sh/op-stack/actions/waitForNextGame
521
+ *
522
+ * @param client - Client to use
523
+ * @param parameters - {@link WaitForNextGameParameters}
524
+ * @returns The L2 transaction hash. {@link WaitForNextGameReturnType}
525
+ *
526
+ * @example
527
+ * import { createPublicClient, http } from 'viem'
528
+ * import { optimism } from 'viem/chains'
529
+ *
530
+ * const publicClientL1 = createPublicClient({
531
+ * chain: mainnet,
532
+ * transport: http(),
533
+ * })
534
+ *
535
+ * await publicClientL1.waitForNextGame({
536
+ * l2BlockNumber: 69420n,
537
+ * targetChain: optimism
538
+ * })
539
+ */
540
+ waitForNextGame: <chainOverride extends Chain | undefined = undefined>(
541
+ parameters: WaitForNextGameParameters<chain, chainOverride>,
542
+ ) => Promise<WaitForNextGameReturnType>
384
543
  /**
385
544
  * Waits for the next L2 output (after the provided block number) to be submitted.
386
545
  *
@@ -516,11 +675,16 @@ export function publicActionsL1() {
516
675
  estimateFinalizeWithdrawalGas(client, args),
517
676
  estimateProveWithdrawalGas: (args) =>
518
677
  estimateProveWithdrawalGas(client, args),
678
+ getGame: (args) => getGame(client, args),
679
+ getGames: (args) => getGames(client, args),
519
680
  getL2Output: (args) => getL2Output(client, args),
681
+ getPortalVersion: (args) => getPortalVersion(client, args),
520
682
  getTimeToFinalize: (args) => getTimeToFinalize(client, args),
683
+ getTimeToNextGame: (args) => getTimeToNextGame(client, args),
521
684
  getTimeToNextL2Output: (args) => getTimeToNextL2Output(client, args),
522
685
  getTimeToProve: (args) => getTimeToProve(client, args),
523
686
  getWithdrawalStatus: (args) => getWithdrawalStatus(client, args),
687
+ waitForNextGame: (args) => waitForNextGame(client, args),
524
688
  waitForNextL2Output: (args) => waitForNextL2Output(client, args),
525
689
  waitToFinalize: (args) => waitToFinalize(client, args),
526
690
  waitToProve: (args) => waitToProve(client, args),
@@ -1,6 +1,16 @@
1
1
  import { BaseError } from '../../../errors/base.js'
2
2
  import type { Hex } from '../../../types/misc.js'
3
3
 
4
+ export type GameNotFoundErrorType = GameNotFoundError & {
5
+ name: 'GameNotFoundError'
6
+ }
7
+ export class GameNotFoundError extends BaseError {
8
+ override name = 'GameNotFoundError'
9
+ constructor() {
10
+ super('Dispute game not found.')
11
+ }
12
+ }
13
+
4
14
  export type ReceiptContainsNoWithdrawalsErrorType =
5
15
  ReceiptContainsNoWithdrawalsError & {
6
16
  name: 'ReceiptContainsNoWithdrawalsError'
@@ -52,6 +52,18 @@ export {
52
52
  type EstimateL1FeeParameters,
53
53
  type EstimateL1FeeReturnType,
54
54
  } from './actions/estimateL1Fee.js'
55
+ export {
56
+ getGame,
57
+ type GetGameErrorType,
58
+ type GetGameParameters,
59
+ type GetGameReturnType,
60
+ } from './actions/getGame.js'
61
+ export {
62
+ getGames,
63
+ type GetGamesErrorType,
64
+ type GetGamesParameters,
65
+ type GetGamesReturnType,
66
+ } from './actions/getGames.js'
55
67
  export {
56
68
  getL1BaseFee,
57
69
  type GetL1BaseFeeErrorType,
@@ -88,6 +100,18 @@ export {
88
100
  type GetL2OutputParameters,
89
101
  type GetL2OutputReturnType,
90
102
  } from './actions/getL2Output.js'
103
+ export {
104
+ getPortalVersion,
105
+ type GetPortalVersionErrorType,
106
+ type GetPortalVersionParameters,
107
+ type GetPortalVersionReturnType,
108
+ } from './actions/getPortalVersion.js'
109
+ export {
110
+ getTimeToNextGame,
111
+ type GetTimeToNextGameErrorType,
112
+ type GetTimeToNextGameParameters,
113
+ type GetTimeToNextGameReturnType,
114
+ } from './actions/getTimeToNextGame.js'
91
115
  export {
92
116
  getTimeToFinalize,
93
117
  type GetTimeToFinalizeErrorType,
@@ -124,6 +148,12 @@ export {
124
148
  type ProveWithdrawalParameters,
125
149
  type ProveWithdrawalReturnType,
126
150
  } from './actions/proveWithdrawal.js'
151
+ export {
152
+ waitForNextGame,
153
+ type WaitForNextGameErrorType,
154
+ type WaitForNextGameParameters,
155
+ type WaitForNextGameReturnType,
156
+ } from './actions/waitForNextGame.js'
127
157
  export {
128
158
  waitForNextL2Output,
129
159
  type WaitForNextL2OutputErrorType,
@@ -1,6 +1,9 @@
1
1
  import type { Chain, ChainContract } from '../../../types/chain.js'
2
2
 
3
- export type TargetChain<chain extends Chain, contractName extends string> = {
3
+ export type TargetChain<
4
+ chain extends Chain = Chain,
5
+ contractName extends string = string,
6
+ > = {
4
7
  contracts: {
5
8
  [_ in contractName]: { [_ in chain['id']]: ChainContract }
6
9
  }
@@ -1,6 +1,14 @@
1
1
  import type { Address } from 'abitype'
2
2
  import type { Hex } from '../../../types/misc.js'
3
3
 
4
+ export type Game = {
5
+ index: bigint
6
+ metadata: Hex
7
+ timestamp: bigint
8
+ rootClaim: Hex
9
+ extraData: Hex
10
+ }
11
+
4
12
  export type WithdrawalRequest = {
5
13
  /** Encoded contract method & arguments. */
6
14
  data?: Hex | undefined
@@ -0,0 +1,100 @@
1
+ import type { Abi } from 'abitype'
2
+
3
+ import type { Account } from '../../../accounts/types.js'
4
+ import type { DeployContractParameters as DeployContractParameters_ } from '../../../actions/wallet/deployContract.js'
5
+ import type { Client } from '../../../clients/createClient.js'
6
+ import type { Transport } from '../../../clients/transports/createTransport.js'
7
+ import type { ErrorType } from '../../../errors/utils.js'
8
+ import type { ContractConstructorArgs } from '../../../types/contract.js'
9
+ import type { Hash, Hex } from '../../../types/misc.js'
10
+ import { contractDeployerAddress } from '../constants/address.js'
11
+ import type { ChainEIP712 } from '../types/chain.js'
12
+ import type { ContractDeploymentType } from '../types/contract.js'
13
+ import { encodeDeployData } from '../utils/abi/encodeDeployData.js'
14
+ import {
15
+ type SendEip712TransactionErrorType,
16
+ type SendEip712TransactionParameters,
17
+ type SendEip712TransactionReturnType,
18
+ sendEip712Transaction,
19
+ } from './sendEip712Transaction.js'
20
+
21
+ export type DeployContractParameters<
22
+ abi extends Abi | readonly unknown[] = Abi,
23
+ chain extends ChainEIP712 | undefined = ChainEIP712 | undefined,
24
+ account extends Account | undefined = Account | undefined,
25
+ chainOverride extends ChainEIP712 | undefined = ChainEIP712 | undefined,
26
+ allArgs = ContractConstructorArgs<abi>,
27
+ > = DeployContractParameters_<abi, chain, account, chainOverride, allArgs> & {
28
+ deploymentType?: ContractDeploymentType
29
+ factoryDeps?: Hex[]
30
+ salt?: Hash
31
+ }
32
+
33
+ export type DeployContractReturnType = SendEip712TransactionReturnType
34
+
35
+ export type DeployContractErrorType = SendEip712TransactionErrorType | ErrorType
36
+
37
+ /**
38
+ * Deploys a contract to the network, given bytecode and constructor arguments using EIP712 transaction.
39
+ *
40
+ * - Docs: https://viem.sh/docs/contract/deployContract
41
+ *
42
+ * @param client - Client to use
43
+ * @param parameters - {@link DeployContractParameters}
44
+ * @returns The [Transaction](https://viem.sh/docs/glossary/terms#transaction) hash. {@link DeployContractReturnType}
45
+ *
46
+ * @example
47
+ * import { createWalletClient, custom } from 'viem'
48
+ * import { privateKeyToAccount } from 'viem/accounts'
49
+ * import { zkSync } from 'viem/chains'
50
+ * import { deployContract } from 'viem/zksync'
51
+ *
52
+ * const client = createWalletClient({
53
+ * account: privateKeyToAccount('0x…'),
54
+ * chain: zksync,
55
+ * transport: custom(provider),
56
+ * })
57
+ * const hash = await deployContract(client, {
58
+ * abi: [],
59
+ * account: '0x…,
60
+ * deploymentType: 'create',
61
+ * bytecode: '0x608060405260405161083e38038061083e833981016040819052610...',
62
+ * factoryDeps: ['0x608060405260405161083e38038061083e833981016040819052610...'],
63
+ * gasPerPubdata: 50000n
64
+ * })
65
+ */
66
+ export function deployContract<
67
+ const abi extends Abi | readonly unknown[],
68
+ chain extends ChainEIP712 | undefined,
69
+ account extends Account | undefined,
70
+ chainOverride extends ChainEIP712 | undefined,
71
+ >(
72
+ walletClient: Client<Transport, chain, account>,
73
+ parameters: DeployContractParameters<abi, chain, account, chainOverride>,
74
+ ): Promise<DeployContractReturnType> {
75
+ const { abi, args, bytecode, deploymentType, salt, ...request } =
76
+ parameters as DeployContractParameters
77
+
78
+ const data = encodeDeployData({
79
+ abi,
80
+ args,
81
+ bytecode,
82
+ deploymentType,
83
+ salt,
84
+ })
85
+
86
+ // Add the bytecode to the factoryDeps if it's not already there
87
+ request.factoryDeps = request.factoryDeps || []
88
+ if (!request.factoryDeps.includes(bytecode))
89
+ request.factoryDeps.push(bytecode)
90
+
91
+ return sendEip712Transaction(walletClient, {
92
+ ...request,
93
+ data,
94
+ to: contractDeployerAddress,
95
+ } as unknown as SendEip712TransactionParameters<
96
+ chain,
97
+ account,
98
+ chainOverride
99
+ >)
100
+ }