viem 2.50.4 → 2.51.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 (197) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/_cjs/actions/index.js +5 -3
  3. package/_cjs/actions/index.js.map +1 -1
  4. package/_cjs/actions/public/createAccessList.js +3 -0
  5. package/_cjs/actions/public/createAccessList.js.map +1 -1
  6. package/_cjs/actions/public/getBlockReceipts.js +19 -0
  7. package/_cjs/actions/public/getBlockReceipts.js.map +1 -0
  8. package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
  9. package/_cjs/chains/definitions/somnia.js +7 -0
  10. package/_cjs/chains/definitions/somnia.js.map +1 -1
  11. package/_cjs/chains/definitions/somniaTestnet.js +3 -2
  12. package/_cjs/chains/definitions/somniaTestnet.js.map +1 -1
  13. package/_cjs/clients/decorators/public.js +2 -0
  14. package/_cjs/clients/decorators/public.js.map +1 -1
  15. package/_cjs/errors/version.js +1 -1
  16. package/_cjs/index.js.map +1 -1
  17. package/_cjs/op-stack/actions/buildProveWithdrawal.js +10 -2
  18. package/_cjs/op-stack/actions/buildProveWithdrawal.js.map +1 -1
  19. package/_cjs/op-stack/actions/getGame.js.map +1 -1
  20. package/_cjs/op-stack/actions/getGames.js +3 -1
  21. package/_cjs/op-stack/actions/getGames.js.map +1 -1
  22. package/_cjs/op-stack/actions/getTimeToProve.js +3 -3
  23. package/_cjs/op-stack/actions/getTimeToProve.js.map +1 -1
  24. package/_cjs/op-stack/actions/getWithdrawalStatus.js +1 -1
  25. package/_cjs/op-stack/actions/getWithdrawalStatus.js.map +1 -1
  26. package/_cjs/op-stack/actions/waitToProve.js +4 -3
  27. package/_cjs/op-stack/actions/waitToProve.js.map +1 -1
  28. package/_cjs/op-stack/gameTypes.js +9 -0
  29. package/_cjs/op-stack/gameTypes.js.map +1 -0
  30. package/_cjs/op-stack/index.js +7 -1
  31. package/_cjs/op-stack/index.js.map +1 -1
  32. package/_cjs/op-stack/utils/getL2BlockNumberAtTimestamp.js +29 -0
  33. package/_cjs/op-stack/utils/getL2BlockNumberAtTimestamp.js.map +1 -0
  34. package/_cjs/tempo/Abis.js +477 -11
  35. package/_cjs/tempo/Abis.js.map +1 -1
  36. package/_cjs/tempo/Account.js +27 -1
  37. package/_cjs/tempo/Account.js.map +1 -1
  38. package/_cjs/tempo/Decorator.js +17 -0
  39. package/_cjs/tempo/Decorator.js.map +1 -1
  40. package/_cjs/tempo/Transaction.js +10 -2
  41. package/_cjs/tempo/Transaction.js.map +1 -1
  42. package/_cjs/tempo/actions/channel.js +377 -0
  43. package/_cjs/tempo/actions/channel.js.map +1 -0
  44. package/_cjs/tempo/actions/index.js +2 -1
  45. package/_cjs/tempo/actions/index.js.map +1 -1
  46. package/_cjs/tempo/actions/token.js +57 -27
  47. package/_cjs/tempo/actions/token.js.map +1 -1
  48. package/_cjs/tempo/index.js +2 -1
  49. package/_cjs/tempo/index.js.map +1 -1
  50. package/_cjs/utils/formatters/transactionRequest.js.map +1 -1
  51. package/_cjs/utils/index.js.map +1 -1
  52. package/_esm/actions/index.js +1 -0
  53. package/_esm/actions/index.js.map +1 -1
  54. package/_esm/actions/public/createAccessList.js +3 -0
  55. package/_esm/actions/public/createAccessList.js.map +1 -1
  56. package/_esm/actions/public/getBlockReceipts.js +39 -0
  57. package/_esm/actions/public/getBlockReceipts.js.map +1 -0
  58. package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
  59. package/_esm/chains/definitions/somnia.js +7 -0
  60. package/_esm/chains/definitions/somnia.js.map +1 -1
  61. package/_esm/chains/definitions/somniaTestnet.js +3 -2
  62. package/_esm/chains/definitions/somniaTestnet.js.map +1 -1
  63. package/_esm/clients/decorators/public.js +2 -0
  64. package/_esm/clients/decorators/public.js.map +1 -1
  65. package/_esm/errors/version.js +1 -1
  66. package/_esm/index.js.map +1 -1
  67. package/_esm/op-stack/actions/buildProveWithdrawal.js +10 -2
  68. package/_esm/op-stack/actions/buildProveWithdrawal.js.map +1 -1
  69. package/_esm/op-stack/actions/getGame.js.map +1 -1
  70. package/_esm/op-stack/actions/getGames.js +3 -1
  71. package/_esm/op-stack/actions/getGames.js.map +1 -1
  72. package/_esm/op-stack/actions/getTimeToProve.js +3 -3
  73. package/_esm/op-stack/actions/getTimeToProve.js.map +1 -1
  74. package/_esm/op-stack/actions/getWithdrawalStatus.js +1 -1
  75. package/_esm/op-stack/actions/getWithdrawalStatus.js.map +1 -1
  76. package/_esm/op-stack/actions/waitToProve.js +4 -3
  77. package/_esm/op-stack/actions/waitToProve.js.map +1 -1
  78. package/_esm/op-stack/gameTypes.js +9 -0
  79. package/_esm/op-stack/gameTypes.js.map +1 -0
  80. package/_esm/op-stack/index.js +2 -0
  81. package/_esm/op-stack/index.js.map +1 -1
  82. package/_esm/op-stack/utils/getL2BlockNumberAtTimestamp.js +33 -0
  83. package/_esm/op-stack/utils/getL2BlockNumberAtTimestamp.js.map +1 -0
  84. package/_esm/tempo/Abis.js +476 -10
  85. package/_esm/tempo/Abis.js.map +1 -1
  86. package/_esm/tempo/Account.js +27 -2
  87. package/_esm/tempo/Account.js.map +1 -1
  88. package/_esm/tempo/Decorator.js +17 -0
  89. package/_esm/tempo/Decorator.js.map +1 -1
  90. package/_esm/tempo/Transaction.js +16 -11
  91. package/_esm/tempo/Transaction.js.map +1 -1
  92. package/_esm/tempo/actions/channel.js +736 -0
  93. package/_esm/tempo/actions/channel.js.map +1 -0
  94. package/_esm/tempo/actions/index.js +1 -0
  95. package/_esm/tempo/actions/index.js.map +1 -1
  96. package/_esm/tempo/actions/token.js +61 -28
  97. package/_esm/tempo/actions/token.js.map +1 -1
  98. package/_esm/tempo/index.js +1 -1
  99. package/_esm/tempo/index.js.map +1 -1
  100. package/_esm/utils/formatters/transactionRequest.js.map +1 -1
  101. package/_esm/utils/index.js.map +1 -1
  102. package/_types/actions/index.d.ts +1 -0
  103. package/_types/actions/index.d.ts.map +1 -1
  104. package/_types/actions/public/createAccessList.d.ts +2 -1
  105. package/_types/actions/public/createAccessList.d.ts.map +1 -1
  106. package/_types/actions/public/getBlockReceipts.d.ts +53 -0
  107. package/_types/actions/public/getBlockReceipts.d.ts.map +1 -0
  108. package/_types/actions/wallet/prepareTransactionRequest.d.ts +4 -5
  109. package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
  110. package/_types/chains/definitions/somnia.d.ts +7 -10
  111. package/_types/chains/definitions/somnia.d.ts.map +1 -1
  112. package/_types/chains/definitions/somniaTestnet.d.ts +3 -3
  113. package/_types/chains/definitions/somniaTestnet.d.ts.map +1 -1
  114. package/_types/clients/decorators/public.d.ts +23 -0
  115. package/_types/clients/decorators/public.d.ts.map +1 -1
  116. package/_types/errors/version.d.ts +1 -1
  117. package/_types/index.d.ts +2 -1
  118. package/_types/index.d.ts.map +1 -1
  119. package/_types/op-stack/actions/buildProveWithdrawal.d.ts +2 -1
  120. package/_types/op-stack/actions/buildProveWithdrawal.d.ts.map +1 -1
  121. package/_types/op-stack/actions/getGame.d.ts +7 -0
  122. package/_types/op-stack/actions/getGame.d.ts.map +1 -1
  123. package/_types/op-stack/actions/getGames.d.ts +7 -0
  124. package/_types/op-stack/actions/getGames.d.ts.map +1 -1
  125. package/_types/op-stack/actions/getTimeToProve.d.ts +4 -0
  126. package/_types/op-stack/actions/getTimeToProve.d.ts.map +1 -1
  127. package/_types/op-stack/actions/getWithdrawalStatus.d.ts +4 -0
  128. package/_types/op-stack/actions/getWithdrawalStatus.d.ts.map +1 -1
  129. package/_types/op-stack/actions/waitToProve.d.ts +4 -0
  130. package/_types/op-stack/actions/waitToProve.d.ts.map +1 -1
  131. package/_types/op-stack/gameTypes.d.ts +7 -0
  132. package/_types/op-stack/gameTypes.d.ts.map +1 -0
  133. package/_types/op-stack/index.d.ts +2 -0
  134. package/_types/op-stack/index.d.ts.map +1 -1
  135. package/_types/op-stack/utils/getL2BlockNumberAtTimestamp.d.ts +21 -0
  136. package/_types/op-stack/utils/getL2BlockNumberAtTimestamp.d.ts.map +1 -0
  137. package/_types/tempo/Abis.d.ts +3784 -2271
  138. package/_types/tempo/Abis.d.ts.map +1 -1
  139. package/_types/tempo/Account.d.ts +32 -1
  140. package/_types/tempo/Account.d.ts.map +1 -1
  141. package/_types/tempo/Decorator.d.ts +246 -1
  142. package/_types/tempo/Decorator.d.ts.map +1 -1
  143. package/_types/tempo/Transaction.d.ts.map +1 -1
  144. package/_types/tempo/actions/accessKey.d.ts +339 -0
  145. package/_types/tempo/actions/accessKey.d.ts.map +1 -1
  146. package/_types/tempo/actions/channel.d.ts +4390 -0
  147. package/_types/tempo/actions/channel.d.ts.map +1 -0
  148. package/_types/tempo/actions/dex.d.ts +140 -0
  149. package/_types/tempo/actions/dex.d.ts.map +1 -1
  150. package/_types/tempo/actions/fee.d.ts +0 -48
  151. package/_types/tempo/actions/fee.d.ts.map +1 -1
  152. package/_types/tempo/actions/index.d.ts +1 -0
  153. package/_types/tempo/actions/index.d.ts.map +1 -1
  154. package/_types/tempo/actions/reward.d.ts +74 -18
  155. package/_types/tempo/actions/reward.d.ts.map +1 -1
  156. package/_types/tempo/actions/token.d.ts +629 -141
  157. package/_types/tempo/actions/token.d.ts.map +1 -1
  158. package/_types/tempo/actions/virtualAddress.d.ts +11 -0
  159. package/_types/tempo/actions/virtualAddress.d.ts.map +1 -1
  160. package/_types/tempo/index.d.ts +1 -1
  161. package/_types/tempo/index.d.ts.map +1 -1
  162. package/_types/types/eip1193.d.ts +13 -0
  163. package/_types/types/eip1193.d.ts.map +1 -1
  164. package/_types/utils/formatters/transactionRequest.d.ts +6 -1
  165. package/_types/utils/formatters/transactionRequest.d.ts.map +1 -1
  166. package/_types/utils/index.d.ts +1 -1
  167. package/_types/utils/index.d.ts.map +1 -1
  168. package/actions/index.ts +6 -0
  169. package/actions/public/createAccessList.ts +4 -0
  170. package/actions/public/getBlockReceipts.ts +101 -0
  171. package/actions/wallet/prepareTransactionRequest.ts +7 -10
  172. package/chains/definitions/somnia.ts +7 -0
  173. package/chains/definitions/somniaTestnet.ts +3 -2
  174. package/clients/decorators/public.ts +30 -0
  175. package/errors/version.ts +1 -1
  176. package/index.ts +6 -0
  177. package/op-stack/actions/buildProveWithdrawal.ts +17 -2
  178. package/op-stack/actions/getGame.ts +7 -0
  179. package/op-stack/actions/getGames.ts +10 -1
  180. package/op-stack/actions/getTimeToProve.ts +7 -3
  181. package/op-stack/actions/getWithdrawalStatus.ts +6 -1
  182. package/op-stack/actions/waitToProve.ts +8 -3
  183. package/op-stack/gameTypes.ts +9 -0
  184. package/op-stack/index.ts +7 -1
  185. package/op-stack/utils/getL2BlockNumberAtTimestamp.ts +57 -0
  186. package/package.json +2 -2
  187. package/tempo/Abis.ts +477 -10
  188. package/tempo/Account.ts +67 -2
  189. package/tempo/Decorator.ts +299 -1
  190. package/tempo/Transaction.ts +18 -11
  191. package/tempo/actions/channel.ts +1197 -0
  192. package/tempo/actions/index.ts +1 -0
  193. package/tempo/actions/token.ts +85 -26
  194. package/tempo/index.ts +1 -0
  195. package/types/eip1193.ts +13 -0
  196. package/utils/formatters/transactionRequest.ts +13 -1
  197. package/utils/index.ts +1 -0
@@ -7,6 +7,7 @@ import {
7
7
  } from '../../accounts/utils/parseAccount.js'
8
8
  import type { Client } from '../../clients/createClient.js'
9
9
  import type { Transport } from '../../clients/transports/createTransport.js'
10
+ import { BaseError, type BaseErrorType } from '../../errors/base.js'
10
11
  import type { ErrorType } from '../../errors/utils.js'
11
12
  import type { BlockTag } from '../../types/block.js'
12
13
  import type { Chain } from '../../types/chain.js'
@@ -66,6 +67,7 @@ export type CreateAccessListReturnType = Prettify<{
66
67
  export type CreateAccessListErrorType = GetCallErrorReturnType<
67
68
  | ParseAccountErrorType
68
69
  | AssertRequestErrorType
70
+ | BaseErrorType
69
71
  | NumberToHexErrorType
70
72
  | FormatTransactionRequestErrorType
71
73
  | RequestErrorType
@@ -149,6 +151,8 @@ export async function createAccessList<chain extends Chain | undefined>(
149
151
  method: 'eth_createAccessList',
150
152
  params: [request as ExactPartial<RpcTransactionRequest>, block],
151
153
  })
154
+ if (response.error)
155
+ throw new BaseError(response.error, { details: response.error })
152
156
  return {
153
157
  accessList: response.accessList,
154
158
  gasUsed: BigInt(response.gasUsed),
@@ -0,0 +1,101 @@
1
+ import type { Client } from '../../clients/createClient.js'
2
+ import type { Transport } from '../../clients/transports/createTransport.js'
3
+ import {
4
+ BlockNotFoundError,
5
+ type BlockNotFoundErrorType,
6
+ } from '../../errors/block.js'
7
+ import type { ErrorType } from '../../errors/utils.js'
8
+ import type { BlockTag } from '../../types/block.js'
9
+ import type { Chain } from '../../types/chain.js'
10
+ import type { Hash } from '../../types/misc.js'
11
+ import type { RequestErrorType } from '../../utils/buildRequest.js'
12
+ import {
13
+ type NumberToHexErrorType,
14
+ numberToHex,
15
+ } from '../../utils/encoding/toHex.js'
16
+ import {
17
+ type FormattedTransactionReceipt,
18
+ formatTransactionReceipt,
19
+ } from '../../utils/formatters/transactionReceipt.js'
20
+
21
+ export type GetBlockReceiptsParameters =
22
+ | {
23
+ /** Hash of the block. */
24
+ blockHash?: Hash | undefined
25
+ blockNumber?: undefined
26
+ blockTag?: undefined
27
+ }
28
+ | {
29
+ blockHash?: undefined
30
+ /** The block number. */
31
+ blockNumber?: bigint | undefined
32
+ blockTag?: undefined
33
+ }
34
+ | {
35
+ blockHash?: undefined
36
+ blockNumber?: undefined
37
+ /** The block tag. Defaults to 'latest'. */
38
+ blockTag?: BlockTag | undefined
39
+ }
40
+
41
+ export type GetBlockReceiptsReturnType<
42
+ chain extends Chain | undefined = undefined,
43
+ > = FormattedTransactionReceipt<chain>[]
44
+
45
+ export type GetBlockReceiptsErrorType =
46
+ | BlockNotFoundErrorType
47
+ | NumberToHexErrorType
48
+ | RequestErrorType
49
+ | ErrorType
50
+
51
+ /**
52
+ * Returns the transaction receipts of a block at a block number, hash, or tag.
53
+ *
54
+ * - Docs: https://viem.sh/docs/actions/public/getBlockReceipts
55
+ * - JSON-RPC Methods: [`eth_getBlockReceipts`](https://ethereum.github.io/execution-apis/api/methods/eth_getBlockReceipts/)
56
+ *
57
+ * @param client - Client to use
58
+ * @param parameters - {@link GetBlockReceiptsParameters}
59
+ * @returns The transaction receipts. {@link GetBlockReceiptsReturnType}
60
+ *
61
+ * @example
62
+ * import { createPublicClient, http } from 'viem'
63
+ * import { mainnet } from 'viem/chains'
64
+ * import { getBlockReceipts } from 'viem/public'
65
+ *
66
+ * const client = createPublicClient({
67
+ * chain: mainnet,
68
+ * transport: http(),
69
+ * })
70
+ * const receipts = await getBlockReceipts(client, {
71
+ * blockNumber: 69420n,
72
+ * })
73
+ */
74
+ export async function getBlockReceipts<chain extends Chain | undefined>(
75
+ client: Client<Transport, chain>,
76
+ {
77
+ blockHash,
78
+ blockNumber,
79
+ blockTag = client.experimental_blockTag ?? 'latest',
80
+ }: GetBlockReceiptsParameters = {},
81
+ ): Promise<GetBlockReceiptsReturnType<chain>> {
82
+ const blockNumberHex =
83
+ blockNumber !== undefined ? numberToHex(blockNumber) : undefined
84
+
85
+ const receipts = await client.request(
86
+ {
87
+ method: 'eth_getBlockReceipts',
88
+ params: [blockHash || blockNumberHex || blockTag],
89
+ },
90
+ { dedupe: Boolean(blockHash || blockNumberHex) },
91
+ )
92
+
93
+ if (!receipts) throw new BlockNotFoundError({ blockHash, blockNumber })
94
+
95
+ const format =
96
+ client.chain?.formatters?.transactionReceipt?.format ||
97
+ formatTransactionReceipt
98
+ return receipts.map((receipt) =>
99
+ format(receipt, 'getBlockReceipts'),
100
+ ) as GetBlockReceiptsReturnType<chain>
101
+ }
@@ -50,7 +50,10 @@ import { blobsToCommitments } from '../../utils/blob/blobsToCommitments.js'
50
50
  import { blobsToProofs } from '../../utils/blob/blobsToProofs.js'
51
51
  import { commitmentsToVersionedHashes } from '../../utils/blob/commitmentsToVersionedHashes.js'
52
52
  import { toBlobSidecars } from '../../utils/blob/toBlobSidecars.js'
53
- import type { FormattedTransactionRequest } from '../../utils/formatters/transactionRequest.js'
53
+ import type {
54
+ ExtractFormattedTransactionRequest,
55
+ FormattedTransactionRequest,
56
+ } from '../../utils/formatters/transactionRequest.js'
54
57
  import { getAction } from '../../utils/getAction.js'
55
58
  import { LruMap } from '../../utils/lru.js'
56
59
  import type { NonceManager } from '../../utils/nonceManager.js'
@@ -98,12 +101,6 @@ type ParameterTypeToParameters<
98
101
  > = parameterType extends 'fees'
99
102
  ? 'maxFeePerGas' | 'maxPriorityFeePerGas' | 'gasPrice'
100
103
  : parameterType
101
- type ExtractTransactionRequest<transactionRequest, transactionType> =
102
- transactionRequest extends { type?: infer type | undefined }
103
- ? Extract<transactionType, type> extends never
104
- ? never
105
- : transactionRequest
106
- : never
107
104
 
108
105
  export type PrepareTransactionRequestRequest<
109
106
  chain extends Chain | undefined = Chain | undefined,
@@ -164,9 +161,9 @@ export type PrepareTransactionRequestReturnType<
164
161
  : GetTransactionType<request> extends 'legacy'
165
162
  ? unknown
166
163
  : GetTransactionType<request>,
167
- _transactionRequest = ExtractTransactionRequest<
168
- UnionOmit<FormattedTransactionRequest<_derivedChain>, 'from'>,
169
- _transactionType
164
+ _transactionRequest = ExtractFormattedTransactionRequest<
165
+ _derivedChain,
166
+ { type?: _transactionType extends string ? _transactionType : undefined }
170
167
  >,
171
168
  > = Prettify<
172
169
  UnionRequiredBy<
@@ -4,6 +4,7 @@ export const somnia = /*#__PURE__*/ defineChain({
4
4
  id: 5031,
5
5
  name: 'Somnia',
6
6
  nativeCurrency: { name: 'Somnia', symbol: 'SOMI', decimals: 18 },
7
+ blockTime: 100,
7
8
  rpcUrls: {
8
9
  default: {
9
10
  http: ['https://api.infra.mainnet.somnia.network'],
@@ -16,5 +17,11 @@ export const somnia = /*#__PURE__*/ defineChain({
16
17
  apiUrl: 'https://explorer.somnia.network/api',
17
18
  },
18
19
  },
20
+ contracts: {
21
+ multicall3: {
22
+ address: '0x5e44F178E8cF9B2F5409B6f18ce936aB817C5a11',
23
+ blockCreated: 38516341,
24
+ },
25
+ },
19
26
  testnet: false,
20
27
  })
@@ -4,15 +4,16 @@ export const somniaTestnet = /*#__PURE__*/ defineChain({
4
4
  id: 50312,
5
5
  name: 'Somnia Testnet',
6
6
  nativeCurrency: { name: 'STT', symbol: 'STT', decimals: 18 },
7
+ blockTime: 100,
7
8
  rpcUrls: {
8
9
  default: {
9
- http: ['https://dream-rpc.somnia.network'],
10
+ http: ['https://api.infra.testnet.somnia.network'],
10
11
  },
11
12
  },
12
13
  blockExplorers: {
13
14
  default: {
14
15
  name: 'Somnia Testnet Explorer',
15
- url: 'https://shannon-explorer.somnia.network/',
16
+ url: 'https://shannon-explorer.somnia.network',
16
17
  apiUrl: 'https://shannon-explorer.somnia.network/api',
17
18
  },
18
19
  },
@@ -97,6 +97,11 @@ import {
97
97
  type GetBlockNumberReturnType,
98
98
  getBlockNumber,
99
99
  } from '../../actions/public/getBlockNumber.js'
100
+ import {
101
+ type GetBlockReceiptsParameters,
102
+ type GetBlockReceiptsReturnType,
103
+ getBlockReceipts,
104
+ } from '../../actions/public/getBlockReceipts.js'
100
105
  import {
101
106
  type GetBlockTransactionCountParameters,
102
107
  type GetBlockTransactionCountReturnType,
@@ -671,6 +676,30 @@ export type PublicActions<
671
676
  >(
672
677
  args?: GetBlockParameters<includeTransactions, blockTag> | undefined,
673
678
  ) => Promise<GetBlockReturnType<chain, includeTransactions, blockTag>>
679
+ /**
680
+ * Returns the transaction receipts of a block at a block number, hash, or tag.
681
+ *
682
+ * - Docs: https://viem.sh/docs/actions/public/getBlockReceipts
683
+ * - JSON-RPC Methods: [`eth_getBlockReceipts`](https://ethereum.github.io/execution-apis/api/methods/eth_getBlockReceipts/)
684
+ *
685
+ * @param args - {@link GetBlockReceiptsParameters}
686
+ * @returns The transaction receipts. {@link GetBlockReceiptsReturnType}
687
+ *
688
+ * @example
689
+ * import { createPublicClient, http } from 'viem'
690
+ * import { mainnet } from 'viem/chains'
691
+ *
692
+ * const client = createPublicClient({
693
+ * chain: mainnet,
694
+ * transport: http(),
695
+ * })
696
+ * const receipts = await client.getBlockReceipts({
697
+ * blockNumber: 69420n,
698
+ * })
699
+ */
700
+ getBlockReceipts: (
701
+ args?: GetBlockReceiptsParameters | undefined,
702
+ ) => Promise<GetBlockReceiptsReturnType<chain>>
674
703
  /**
675
704
  * Returns the number of the most recent block seen.
676
705
  *
@@ -2086,6 +2115,7 @@ export function publicActions<
2086
2115
  getBlobBaseFee: () => getBlobBaseFee(client),
2087
2116
  getBlock: (args) => getBlock(client, args),
2088
2117
  getBlockNumber: (args) => getBlockNumber(client, args),
2118
+ getBlockReceipts: (args) => getBlockReceipts(client, args),
2089
2119
  getBlockTransactionCount: (args) => getBlockTransactionCount(client, args),
2090
2120
  getBytecode: (args) => getCode(client, args),
2091
2121
  getChainId: () => getChainId(client),
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.50.4'
1
+ export const version = '2.51.0'
package/index.ts CHANGED
@@ -168,6 +168,11 @@ export type {
168
168
  GetBlockNumberParameters,
169
169
  GetBlockNumberReturnType,
170
170
  } from './actions/public/getBlockNumber.js'
171
+ export type {
172
+ GetBlockReceiptsErrorType,
173
+ GetBlockReceiptsParameters,
174
+ GetBlockReceiptsReturnType,
175
+ } from './actions/public/getBlockReceipts.js'
171
176
  export type {
172
177
  GetBlockTransactionCountErrorType,
173
178
  GetBlockTransactionCountParameters,
@@ -1635,6 +1640,7 @@ export {
1635
1640
  export {
1636
1641
  type DefineTransactionRequestErrorType,
1637
1642
  defineTransactionRequest,
1643
+ type ExtractFormattedTransactionRequest,
1638
1644
  type FormatTransactionRequestErrorType,
1639
1645
  type FormattedTransactionRequest,
1640
1646
  formatTransactionRequest,
@@ -27,6 +27,10 @@ import { toRlp } from '../../utils/encoding/toRlp.js'
27
27
  import { keccak256 } from '../../utils/hash/keccak256.js'
28
28
  import { contracts } from '../contracts.js'
29
29
  import type { Withdrawal } from '../types/withdrawal.js'
30
+ import {
31
+ type GetL2BlockNumberAtTimestampErrorType,
32
+ getL2BlockNumberAtTimestamp,
33
+ } from '../utils/getL2BlockNumberAtTimestamp.js'
30
34
  import {
31
35
  type GetWithdrawalHashStorageSlotErrorType,
32
36
  getWithdrawalHashStorageSlot,
@@ -73,6 +77,7 @@ export type BuildProveWithdrawalReturnType<
73
77
  export type BuildProveWithdrawalErrorType =
74
78
  | GetBlockErrorType
75
79
  | GetProofErrorType
80
+ | GetL2BlockNumberAtTimestampErrorType
76
81
  | GetWithdrawalHashStorageSlotErrorType
77
82
  | ErrorType
78
83
 
@@ -120,19 +125,29 @@ export async function buildProveWithdrawal<
120
125
 
121
126
  const { withdrawalHash } = withdrawal
122
127
  const { l2BlockNumber } = game ?? output
128
+ const blockNumber = game?.usesSuperRoots
129
+ ? await getL2BlockNumberAtTimestamp(client, {
130
+ timestamp: game.l2BlockNumber,
131
+ })
132
+ : l2BlockNumber
123
133
 
124
134
  const slot = getWithdrawalHashStorageSlot({ withdrawalHash })
125
135
  const [proof, block] = await Promise.all([
126
136
  getProof(client, {
127
137
  address: contracts.l2ToL1MessagePasser.address,
128
138
  storageKeys: [slot],
129
- blockNumber: l2BlockNumber,
139
+ blockNumber,
130
140
  }),
131
141
  getBlock(client, {
132
- blockNumber: l2BlockNumber,
142
+ blockNumber,
133
143
  }),
134
144
  ])
135
145
 
146
+ if (game?.usesSuperRoots && block.timestamp !== game.l2BlockNumber)
147
+ throw new Error(
148
+ `L2 block timestamp ${block.timestamp} does not match dispute game timestamp ${game.l2BlockNumber}.`,
149
+ )
150
+
136
151
  return {
137
152
  account,
138
153
  l2OutputIndex: game?.index ?? output?.outputIndex,
@@ -42,7 +42,14 @@ export type GetGameParameters<
42
42
  strategy?: 'latest' | 'random'
43
43
  }
44
44
  export type GetGameReturnType = Game & {
45
+ /**
46
+ * L2 block number anchored by the dispute game. For super-root games, this
47
+ * value is the L2 timestamp instead. Check `usesSuperRoots` to distinguish
48
+ * the unit.
49
+ */
45
50
  l2BlockNumber: bigint
51
+ /** Whether the dispute game anchors on super roots. */
52
+ usesSuperRoots: boolean
46
53
  }
47
54
 
48
55
  export type GetGameErrorType =
@@ -17,6 +17,7 @@ import type {
17
17
  GetChainParameter,
18
18
  } from '../../types/chain.js'
19
19
  import { disputeGameAbi, disputeGameFactoryAbi, portal2Abi } from '../abis.js'
20
+ import { isSuperGameType } from '../gameTypes.js'
20
21
  import type { GetContractAddressParameter } from '../types/contract.js'
21
22
  import type { Game } from '../types/withdrawal.js'
22
23
 
@@ -40,7 +41,14 @@ export type GetGamesParameters<
40
41
  limit?: number | undefined
41
42
  }
42
43
  export type GetGamesReturnType = (Game & {
44
+ /**
45
+ * L2 block number anchored by the dispute game. For super-root games, this
46
+ * value is the L2 timestamp instead. Check `usesSuperRoots` to distinguish
47
+ * the unit.
48
+ */
43
49
  l2BlockNumber: bigint
50
+ /** Whether the dispute game anchors on super roots. */
51
+ usesSuperRoots: boolean
44
52
  })[]
45
53
  export type GetGamesErrorType =
46
54
  | ReadContractErrorType
@@ -133,11 +141,12 @@ export async function getGames<
133
141
  })),
134
142
  })
135
143
 
144
+ const usesSuperRoots = isSuperGameType(gameType)
136
145
  const games = rawGames
137
146
  .map((game, i) => {
138
147
  const blockNumber = l2SequenceNumbers[i] as bigint
139
148
  return !l2BlockNumber || blockNumber > l2BlockNumber
140
- ? { ...game, l2BlockNumber: blockNumber }
149
+ ? { ...game, l2BlockNumber: blockNumber, usesSuperRoots }
141
150
  : null
142
151
  })
143
152
  .filter(Boolean) as GetGamesReturnType
@@ -47,6 +47,10 @@ export type GetTimeToProveParameters<
47
47
  intervalBuffer?:
48
48
  | GetTimeToNextL2OutputParameters['intervalBuffer']
49
49
  | undefined
50
+ /**
51
+ * L2 timestamp of the withdrawal. Required for super-root dispute games.
52
+ */
53
+ l2Timestamp?: bigint | undefined
50
54
  receipt: TransactionReceipt
51
55
  }
52
56
 
@@ -98,7 +102,7 @@ export async function getTimeToProve<
98
102
  client: Client<Transport, chain, account>,
99
103
  parameters: GetTimeToProveParameters<chain, chainOverride>,
100
104
  ): Promise<GetTimeToProveReturnType> {
101
- const { receipt } = parameters
105
+ const { l2Timestamp, receipt } = parameters
102
106
 
103
107
  const portalVersion = await getPortalVersion(
104
108
  client,
@@ -109,11 +113,11 @@ export async function getTimeToProve<
109
113
  if (portalVersion.major < 3)
110
114
  return getTimeToNextL2Output(client, {
111
115
  ...parameters,
112
- l2BlockNumber: receipt.blockNumber,
116
+ l2BlockNumber: l2Timestamp ?? receipt.blockNumber,
113
117
  } as GetTimeToNextL2OutputParameters)
114
118
 
115
119
  return getTimeToNextGame(client, {
116
120
  ...parameters,
117
- l2BlockNumber: receipt.blockNumber,
121
+ l2BlockNumber: l2Timestamp ?? receipt.blockNumber,
118
122
  } as GetTimeToNextGameParameters)
119
123
  }
@@ -64,6 +64,10 @@ export type GetWithdrawalStatusParameters<
64
64
  * @default 100
65
65
  */
66
66
  gameLimit?: number
67
+ /**
68
+ * L2 timestamp of the withdrawal. Required for super-root dispute games.
69
+ */
70
+ l2Timestamp?: bigint | undefined
67
71
  } & OneOf<
68
72
  | {
69
73
  /**
@@ -160,7 +164,8 @@ export async function getWithdrawalStatus<
160
164
  return Object.values(targetChain.contracts.portal)[0].address
161
165
  })()
162
166
 
163
- const l2BlockNumber = receipt?.blockNumber ?? parameters.l2BlockNumber
167
+ const l2BlockNumber =
168
+ parameters.l2Timestamp ?? receipt?.blockNumber ?? parameters.l2BlockNumber
164
169
 
165
170
  const withdrawal = (() => {
166
171
  if (receipt) {
@@ -49,6 +49,10 @@ export type WaitToProveParameters<
49
49
  * @default 100
50
50
  */
51
51
  gameLimit?: number | undefined
52
+ /**
53
+ * L2 timestamp of the withdrawal. Required for super-root dispute games.
54
+ */
55
+ l2Timestamp?: bigint | undefined
52
56
  receipt: TransactionReceipt
53
57
  /**
54
58
  * Polling frequency (in ms). Defaults to Client's pollingInterval config.
@@ -105,7 +109,7 @@ export async function waitToProve<
105
109
  client: Client<Transport, chain, account>,
106
110
  parameters: WaitToProveParameters<chain, chainOverride>,
107
111
  ): Promise<WaitToProveReturnType> {
108
- const { gameLimit, receipt } = parameters
112
+ const { gameLimit, l2Timestamp, receipt } = parameters
109
113
 
110
114
  const [withdrawal] = getWithdrawals(receipt)
111
115
 
@@ -123,7 +127,7 @@ export async function waitToProve<
123
127
  if (portalVersion.major < 3) {
124
128
  const output = await waitForNextL2Output(client, {
125
129
  ...parameters,
126
- l2BlockNumber: receipt.blockNumber,
130
+ l2BlockNumber: l2Timestamp ?? receipt.blockNumber,
127
131
  } as WaitForNextL2OutputParameters)
128
132
  return {
129
133
  game: {
@@ -133,6 +137,7 @@ export async function waitToProve<
133
137
  metadata: '0x',
134
138
  rootClaim: output.outputRoot,
135
139
  timestamp: output.timestamp,
140
+ usesSuperRoots: false,
136
141
  },
137
142
  output,
138
143
  withdrawal,
@@ -142,7 +147,7 @@ export async function waitToProve<
142
147
  const game = await waitForNextGame(client, {
143
148
  ...parameters,
144
149
  limit: gameLimit,
145
- l2BlockNumber: receipt.blockNumber,
150
+ l2BlockNumber: l2Timestamp ?? receipt.blockNumber,
146
151
  } as WaitForNextGameParameters)
147
152
  return {
148
153
  game,
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Super dispute game type IDs from the OP Stack contracts
3
+ * (`contracts-bedrock/src/dispute/lib/Types.sol:99-103`).
4
+ */
5
+ export const superGameTypes = new Set([4, 5, 7, 9]) as ReadonlySet<number>
6
+
7
+ export function isSuperGameType(gameType: number): boolean {
8
+ return superGameTypes.has(gameType)
9
+ }
package/op-stack/index.ts CHANGED
@@ -207,7 +207,6 @@ export {
207
207
  export { chainConfig } from './chainConfig.js'
208
208
 
209
209
  export * from './chains.js'
210
-
211
210
  export {
212
211
  type PublicActionsL1,
213
212
  publicActionsL1,
@@ -224,6 +223,7 @@ export {
224
223
  type WalletActionsL2,
225
224
  walletActionsL2,
226
225
  } from './decorators/walletL2.js'
226
+ export { isSuperGameType, superGameTypes } from './gameTypes.js'
227
227
 
228
228
  export {
229
229
  type ParseTransactionErrorType,
@@ -266,6 +266,12 @@ export {
266
266
  type ExtractWithdrawalMessageLogsReturnType,
267
267
  extractWithdrawalMessageLogs,
268
268
  } from './utils/extractWithdrawalMessageLogs.js'
269
+ export {
270
+ type GetL2BlockNumberAtTimestampErrorType,
271
+ type GetL2BlockNumberAtTimestampParameters,
272
+ type GetL2BlockNumberAtTimestampReturnType,
273
+ getL2BlockNumberAtTimestamp,
274
+ } from './utils/getL2BlockNumberAtTimestamp.js'
269
275
  export {
270
276
  type GetL2TransactionHashErrorType,
271
277
  type GetL2TransactionHashParameters,
@@ -0,0 +1,57 @@
1
+ import {
2
+ type GetBlockErrorType,
3
+ getBlock,
4
+ } from '../../actions/public/getBlock.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 { Account } from '../../types/account.js'
9
+ import type { Chain } from '../../types/chain.js'
10
+
11
+ export type GetL2BlockNumberAtTimestampParameters = {
12
+ /** L2 block timestamp. */
13
+ timestamp: bigint
14
+ }
15
+
16
+ export type GetL2BlockNumberAtTimestampReturnType = bigint
17
+
18
+ export type GetL2BlockNumberAtTimestampErrorType = GetBlockErrorType | ErrorType
19
+
20
+ /**
21
+ * Gets the L2 block number for a timestamp using the latest L2 block and its parent.
22
+ *
23
+ * @param client - Client to use.
24
+ * @param parameters - {@link GetL2BlockNumberAtTimestampParameters}
25
+ * @returns L2 block number.
26
+ */
27
+ export async function getL2BlockNumberAtTimestamp(
28
+ client: Client<Transport, Chain | undefined, Account | undefined>,
29
+ parameters: GetL2BlockNumberAtTimestampParameters,
30
+ ): Promise<GetL2BlockNumberAtTimestampReturnType> {
31
+ const latest = await getBlock(client)
32
+ if (latest.number === null)
33
+ throw new Error('Latest L2 block number is unavailable.')
34
+ if (latest.timestamp === undefined)
35
+ throw new Error('Latest L2 block timestamp is unavailable.')
36
+ if (latest.number === 0n)
37
+ throw new Error('Cannot derive L2 block time from genesis block.')
38
+
39
+ const parent = await getBlock(client, { blockNumber: latest.number - 1n })
40
+ if (parent.timestamp === undefined)
41
+ throw new Error('Parent L2 block timestamp is unavailable.')
42
+
43
+ const blockTime = latest.timestamp - parent.timestamp
44
+ if (blockTime === 0n) throw new Error('L2 block time is zero.')
45
+
46
+ const timeDiff = latest.timestamp - parameters.timestamp
47
+ if (timeDiff < 0n)
48
+ throw new Error('Timestamp is in the future relative to L2 head.')
49
+ if (timeDiff % blockTime !== 0n)
50
+ throw new Error('Timestamp does not align with the L2 block time.')
51
+
52
+ const blocksToLookBack = timeDiff / blockTime
53
+ if (blocksToLookBack > latest.number)
54
+ throw new Error('Timestamp predates L2 genesis.')
55
+
56
+ return latest.number - blocksToLookBack
57
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.50.4",
4
+ "version": "2.51.0",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -230,7 +230,7 @@
230
230
  "@scure/bip39": "1.6.0",
231
231
  "abitype": "1.2.3",
232
232
  "isows": "1.0.7",
233
- "ox": "0.14.22",
233
+ "ox": "https://pkg.pr.new/ox@386a3439fe1ce76d237930f8c6e6bb493746069a",
234
234
  "ws": "8.20.1"
235
235
  },
236
236
  "license": "MIT",