viem 2.58.2 → 2.58.4

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 (109) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/_cjs/actions/public/createEventFilter.js +2 -12
  3. package/_cjs/actions/public/createEventFilter.js.map +1 -1
  4. package/_cjs/actions/public/estimateFeesPerGas.js +16 -16
  5. package/_cjs/actions/public/estimateFeesPerGas.js.map +1 -1
  6. package/_cjs/actions/public/getLogs.js +6 -12
  7. package/_cjs/actions/public/getLogs.js.map +1 -1
  8. package/_cjs/actions/public/internal/encodeEventFilterTopics.js +19 -0
  9. package/_cjs/actions/public/internal/encodeEventFilterTopics.js.map +1 -0
  10. package/_cjs/actions/public/simulateBlocks.js +1 -0
  11. package/_cjs/actions/public/simulateBlocks.js.map +1 -1
  12. package/_cjs/actions/public/watchEvent.js +2 -12
  13. package/_cjs/actions/public/watchEvent.js.map +1 -1
  14. package/_cjs/celo/parsers.js +8 -2
  15. package/_cjs/celo/parsers.js.map +1 -1
  16. package/_cjs/errors/version.js +1 -1
  17. package/_cjs/op-stack/actions/getGames.js +0 -6
  18. package/_cjs/op-stack/actions/getGames.js.map +1 -1
  19. package/_cjs/op-stack/formatters.js +7 -0
  20. package/_cjs/op-stack/formatters.js.map +1 -1
  21. package/_cjs/op-stack/gameTypes.js +1 -1
  22. package/_cjs/op-stack/gameTypes.js.map +1 -1
  23. package/_cjs/tempo/actions/simulate.js +1 -0
  24. package/_cjs/tempo/actions/simulate.js.map +1 -1
  25. package/_cjs/tempo/internal/replacement.js.map +1 -1
  26. package/_cjs/utils/ccip.js +6 -2
  27. package/_cjs/utils/ccip.js.map +1 -1
  28. package/_cjs/utils/siwe/validateSiweMessage.js +1 -1
  29. package/_cjs/utils/siwe/validateSiweMessage.js.map +1 -1
  30. package/_cjs/utils/stateOverride.js +5 -2
  31. package/_cjs/utils/stateOverride.js.map +1 -1
  32. package/_cjs/utils/transaction/parseTransaction.js +1 -0
  33. package/_cjs/utils/transaction/parseTransaction.js.map +1 -1
  34. package/_esm/actions/public/createEventFilter.js +2 -13
  35. package/_esm/actions/public/createEventFilter.js.map +1 -1
  36. package/_esm/actions/public/estimateFeesPerGas.js +16 -16
  37. package/_esm/actions/public/estimateFeesPerGas.js.map +1 -1
  38. package/_esm/actions/public/getLogs.js +6 -13
  39. package/_esm/actions/public/getLogs.js.map +1 -1
  40. package/_esm/actions/public/internal/encodeEventFilterTopics.js +22 -0
  41. package/_esm/actions/public/internal/encodeEventFilterTopics.js.map +1 -0
  42. package/_esm/actions/public/simulateBlocks.js +1 -0
  43. package/_esm/actions/public/simulateBlocks.js.map +1 -1
  44. package/_esm/actions/public/watchEvent.js +2 -13
  45. package/_esm/actions/public/watchEvent.js.map +1 -1
  46. package/_esm/celo/parsers.js +9 -3
  47. package/_esm/celo/parsers.js.map +1 -1
  48. package/_esm/errors/version.js +1 -1
  49. package/_esm/op-stack/actions/getGames.js +3 -7
  50. package/_esm/op-stack/actions/getGames.js.map +1 -1
  51. package/_esm/op-stack/formatters.js +7 -0
  52. package/_esm/op-stack/formatters.js.map +1 -1
  53. package/_esm/op-stack/gameTypes.js +4 -2
  54. package/_esm/op-stack/gameTypes.js.map +1 -1
  55. package/_esm/tempo/actions/simulate.js +1 -0
  56. package/_esm/tempo/actions/simulate.js.map +1 -1
  57. package/_esm/tempo/internal/replacement.js +3 -1
  58. package/_esm/tempo/internal/replacement.js.map +1 -1
  59. package/_esm/utils/ccip.js +7 -2
  60. package/_esm/utils/ccip.js.map +1 -1
  61. package/_esm/utils/siwe/validateSiweMessage.js +2 -1
  62. package/_esm/utils/siwe/validateSiweMessage.js.map +1 -1
  63. package/_esm/utils/stateOverride.js +5 -2
  64. package/_esm/utils/stateOverride.js.map +1 -1
  65. package/_esm/utils/transaction/parseTransaction.js +1 -1
  66. package/_esm/utils/transaction/parseTransaction.js.map +1 -1
  67. package/_types/actions/public/createEventFilter.d.ts +1 -1
  68. package/_types/actions/public/createEventFilter.d.ts.map +1 -1
  69. package/_types/actions/public/getLogs.d.ts +1 -1
  70. package/_types/actions/public/getLogs.d.ts.map +1 -1
  71. package/_types/actions/public/internal/encodeEventFilterTopics.d.ts +14 -0
  72. package/_types/actions/public/internal/encodeEventFilterTopics.d.ts.map +1 -0
  73. package/_types/actions/public/simulateBlocks.d.ts.map +1 -1
  74. package/_types/actions/public/watchEvent.d.ts.map +1 -1
  75. package/_types/celo/parsers.d.ts.map +1 -1
  76. package/_types/errors/version.d.ts +1 -1
  77. package/_types/op-stack/actions/getGames.d.ts.map +1 -1
  78. package/_types/op-stack/formatters.d.ts.map +1 -1
  79. package/_types/op-stack/gameTypes.d.ts +3 -1
  80. package/_types/op-stack/gameTypes.d.ts.map +1 -1
  81. package/_types/op-stack/types/transaction.d.ts +2 -0
  82. package/_types/op-stack/types/transaction.d.ts.map +1 -1
  83. package/_types/tempo/actions/simulate.d.ts.map +1 -1
  84. package/_types/tempo/internal/replacement.d.ts +3 -1
  85. package/_types/tempo/internal/replacement.d.ts.map +1 -1
  86. package/_types/utils/ccip.d.ts.map +1 -1
  87. package/_types/utils/siwe/validateSiweMessage.d.ts.map +1 -1
  88. package/_types/utils/stateOverride.d.ts.map +1 -1
  89. package/_types/utils/transaction/parseTransaction.d.ts +4 -1
  90. package/_types/utils/transaction/parseTransaction.d.ts.map +1 -1
  91. package/actions/public/createEventFilter.ts +4 -19
  92. package/actions/public/estimateFeesPerGas.ts +18 -18
  93. package/actions/public/getLogs.ts +8 -19
  94. package/actions/public/internal/encodeEventFilterTopics.ts +32 -0
  95. package/actions/public/simulateBlocks.ts +1 -0
  96. package/actions/public/watchEvent.ts +2 -18
  97. package/celo/parsers.ts +13 -2
  98. package/errors/version.ts +1 -1
  99. package/op-stack/actions/getGames.ts +3 -6
  100. package/op-stack/formatters.ts +8 -0
  101. package/op-stack/gameTypes.ts +4 -2
  102. package/op-stack/types/transaction.ts +2 -0
  103. package/package.json +1 -1
  104. package/tempo/actions/simulate.ts +1 -0
  105. package/tempo/internal/replacement.ts +3 -1
  106. package/utils/ccip.ts +6 -2
  107. package/utils/siwe/validateSiweMessage.ts +2 -1
  108. package/utils/stateOverride.ts +4 -2
  109. package/utils/transaction/parseTransaction.ts +1 -1
@@ -10,14 +10,10 @@ import type {
10
10
  MaybeExtractEventArgsFromAbi,
11
11
  } from '../../types/contract.js'
12
12
  import type { Log } from '../../types/log.js'
13
- import type { Hash, LogTopic } from '../../types/misc.js'
13
+ import type { Hash } from '../../types/misc.js'
14
14
  import type { RpcLog } from '../../types/rpc.js'
15
15
  import type { DecodeEventLogErrorType } from '../../utils/abi/decodeEventLog.js'
16
- import {
17
- type EncodeEventTopicsErrorType,
18
- type EncodeEventTopicsParameters,
19
- encodeEventTopics,
20
- } from '../../utils/abi/encodeEventTopics.js'
16
+ import type { EncodeEventTopicsErrorType } from '../../utils/abi/encodeEventTopics.js'
21
17
  import { parseEventLogs } from '../../utils/abi/parseEventLogs.js'
22
18
  import type { RequestErrorType } from '../../utils/buildRequest.js'
23
19
  import {
@@ -29,6 +25,7 @@ import {
29
25
  formatLog,
30
26
  } from '../../utils/formatters/log.js'
31
27
  import type { GetBlockErrorType } from './getBlock.js'
28
+ import { encodeEventFilterTopics } from './internal/encodeEventFilterTopics.js'
32
29
  import { type IterateLogsParameters, iterateLogs } from './iterateLogs.js'
33
30
 
34
31
  export type GetLogsParameters<
@@ -203,19 +200,11 @@ export async function getLogs<
203
200
  const strict = strict_ ?? false
204
201
  const events = events_ ?? (event ? [event] : undefined)
205
202
 
206
- let topics: LogTopic[] = []
207
- if (events) {
208
- const encoded = (events as AbiEvent[]).flatMap((event) =>
209
- encodeEventTopics({
210
- abi: [event],
211
- eventName: (event as AbiEvent).name,
212
- args: events_ ? undefined : args,
213
- } as EncodeEventTopicsParameters),
214
- )
215
- // TODO: Clean up type casting
216
- topics = [encoded as LogTopic]
217
- if (event) topics = topics[0] as LogTopic[]
218
- }
203
+ const topics = encodeEventFilterTopics({
204
+ args: events_ ? undefined : args,
205
+ event,
206
+ events: events_,
207
+ })
219
208
 
220
209
  let logs: RpcLog[]
221
210
  if (blockHash) {
@@ -0,0 +1,32 @@
1
+ import type { AbiEvent } from 'abitype'
2
+
3
+ import type { LogTopic } from '../../../types/misc.js'
4
+ import {
5
+ type EncodeEventTopicsParameters,
6
+ encodeEventTopics,
7
+ } from '../../../utils/abi/encodeEventTopics.js'
8
+
9
+ /**
10
+ * Encodes the `topics` of a log filter from an `event` or `events` option.
11
+ *
12
+ * A single `event` encodes to its topic list. Otherwise, the topics of every
13
+ * event in `events` are flattened into the first topic position.
14
+ */
15
+ export function encodeEventFilterTopics(parameters: {
16
+ args?: unknown | undefined
17
+ event?: AbiEvent | undefined
18
+ events?: readonly unknown[] | undefined
19
+ }): LogTopic[] {
20
+ const { args, event } = parameters
21
+ const events = parameters.events ?? (event ? [event] : undefined)
22
+ if (!events) return []
23
+ const encoded = (events as AbiEvent[]).flatMap((event) =>
24
+ encodeEventTopics({
25
+ abi: [event],
26
+ eventName: event.name,
27
+ args,
28
+ } as EncodeEventTopicsParameters),
29
+ )
30
+ if (event) return encoded as LogTopic[]
31
+ return [encoded as LogTopic]
32
+ }
@@ -264,6 +264,7 @@ export async function simulateBlocks<
264
264
  abi && status === 'success' && data !== '0x'
265
265
  ? decodeFunctionResult({
266
266
  abi,
267
+ args,
267
268
  data,
268
269
  functionName,
269
270
  })
@@ -18,16 +18,11 @@ import type {
18
18
  } from '../../types/contract.js'
19
19
  import type { Filter } from '../../types/filter.js'
20
20
  import type { Log } from '../../types/log.js'
21
- import type { LogTopic } from '../../types/misc.js'
22
21
  import type { GetPollOptions } from '../../types/transport.js'
23
22
  import {
24
23
  AbiEventAmbiguityError,
25
24
  decodeEventLog,
26
25
  } from '../../utils/abi/decodeEventLog.js'
27
- import {
28
- type EncodeEventTopicsParameters,
29
- encodeEventTopics,
30
- } from '../../utils/abi/encodeEventTopics.js'
31
26
  import { formatLog } from '../../utils/formatters/log.js'
32
27
  import { getAction } from '../../utils/getAction.js'
33
28
  import { type ObserveErrorType, observe } from '../../utils/observe.js'
@@ -40,6 +35,7 @@ import {
40
35
  import { getBlockNumber } from './getBlockNumber.js'
41
36
  import { getFilterChanges } from './getFilterChanges.js'
42
37
  import { type GetLogsParameters, getLogs } from './getLogs.js'
38
+ import { encodeEventFilterTopics } from './internal/encodeEventFilterTopics.js'
43
39
  import { isRangeError } from './internal/isRangeError.js'
44
40
  import {
45
41
  getSubscriptionTransport,
@@ -339,19 +335,7 @@ export function watchEvent<
339
335
  const transport = getSubscriptionTransport(client)
340
336
 
341
337
  const events_ = events ?? (event ? [event] : undefined)
342
- let topics: LogTopic[] = []
343
- if (events_) {
344
- const encoded = (events_ as AbiEvent[]).flatMap((event) =>
345
- encodeEventTopics({
346
- abi: [event],
347
- eventName: (event as AbiEvent).name,
348
- args,
349
- } as EncodeEventTopicsParameters),
350
- )
351
- // TODO: Clean up type casting
352
- topics = [encoded as LogTopic]
353
- if (event) topics = topics[0] as LogTopic[]
354
- }
338
+ const topics = encodeEventFilterTopics({ args, event, events })
355
339
 
356
340
  const { unsubscribe: unsubscribe_ } = await transport.subscribe({
357
341
  params: ['logs', { address, topics }],
package/celo/parsers.ts CHANGED
@@ -11,6 +11,7 @@ import type { GetSerializedTransactionType } from '../utils/transaction/getSeria
11
11
  import {
12
12
  type ParseTransactionReturnType as ParseTransactionReturnType_,
13
13
  parseAccessList,
14
+ parseEIP155Signature,
14
15
  toTransactionArray,
15
16
  } from '../utils/transaction/parseTransaction.js'
16
17
  import {
@@ -129,7 +130,12 @@ function parseTransactionCIP42(
129
130
 
130
131
  assertTransactionCIP42(transaction as TransactionSerializableCIP42)
131
132
 
132
- return transaction as TransactionSerializableCIP42
133
+ const signature =
134
+ transactionArray.length === 15
135
+ ? parseEIP155Signature(transactionArray as RecursiveArray<Hex>)
136
+ : undefined
137
+
138
+ return { ...signature, ...transaction } as TransactionSerializableCIP42
133
139
  }
134
140
 
135
141
  function parseTransactionCIP64(
@@ -200,5 +206,10 @@ function parseTransactionCIP64(
200
206
 
201
207
  assertTransactionCIP64(transaction as TransactionSerializableCIP64)
202
208
 
203
- return transaction as TransactionSerializableCIP64
209
+ const signature =
210
+ transactionArray.length === 13
211
+ ? parseEIP155Signature(transactionArray as RecursiveArray<Hex>)
212
+ : undefined
213
+
214
+ return { ...signature, ...transaction } as TransactionSerializableCIP64
204
215
  }
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.58.2'
1
+ export const version = '2.58.4'
@@ -103,12 +103,9 @@ export async function getGames<
103
103
  const disputeGameFactoryAddress = await (async () => {
104
104
  if (parameters.disputeGameFactoryAddress)
105
105
  return parameters.disputeGameFactoryAddress
106
- const disputeGameFactory = targetChain?.contracts.disputeGameFactory
107
- const address = chain
108
- ? disputeGameFactory?.[chain.id]?.address
109
- : Object.values(disputeGameFactory ?? {})[0]?.address
110
- if (address) return address
111
- // The target chain has no factory for this L1, so read it from the portal.
106
+ // Read the factory from the portal rather than the chain definition: the
107
+ // portal only accepts games from its current factory, and a chain's factory
108
+ // can change (for example when chains move to a shared factory for interop).
112
109
  return withCache(
113
110
  () =>
114
111
  readContract(client, {
@@ -77,6 +77,14 @@ export const formatters = {
77
77
  ...(args.depositReceiptVersion
78
78
  ? { depositReceiptVersion: hexToNumber(args.depositReceiptVersion) }
79
79
  : {}),
80
+ ...(args.opGasRefund !== undefined
81
+ ? {
82
+ opGasRefund:
83
+ args.opGasRefund === null
84
+ ? null
85
+ : hexToBigInt(args.opGasRefund),
86
+ }
87
+ : {}),
80
88
  l1GasPrice: args.l1GasPrice ? hexToBigInt(args.l1GasPrice) : null,
81
89
  l1GasUsed: args.l1GasUsed ? hexToBigInt(args.l1GasUsed) : null,
82
90
  l1Fee: args.l1Fee ? hexToBigInt(args.l1Fee) : null,
@@ -1,8 +1,10 @@
1
1
  /**
2
2
  * Super dispute game type IDs from the OP Stack contracts
3
- * (`contracts-bedrock/src/dispute/lib/Types.sol:99-103`).
3
+ * (`GameTypes.isSuperGame` in `contracts-bedrock/src/dispute/lib/Types.sol`):
4
+ * `SUPER_CANNON` (4), `SUPER_PERMISSIONED` (5), `SUPER_ASTERISC_KONA` (7),
5
+ * `SUPER_CANNON_KONA` (9) and `ZK_DISPUTE_GAME` (10).
4
6
  */
5
- export const superGameTypes = new Set([4, 5, 7, 9]) as ReadonlySet<number>
7
+ export const superGameTypes = new Set([4, 5, 7, 9, 10]) as ReadonlySet<number>
6
8
 
7
9
  export function isSuperGameType(gameType: number): boolean {
8
10
  return superGameTypes.has(gameType)
@@ -39,6 +39,7 @@ export type OpStackRpcTransaction<pending extends boolean = boolean> = OneOf<
39
39
  export type OpStackRpcTransactionReceiptOverrides = {
40
40
  depositNonce?: Quantity | undefined
41
41
  depositReceiptVersion?: Quantity | undefined
42
+ opGasRefund?: Quantity | null | undefined
42
43
  l1GasPrice: Hex | null
43
44
  l1GasUsed: Hex | null
44
45
  l1Fee: Hex | null
@@ -73,6 +74,7 @@ export type OpStackTransaction<pending extends boolean = boolean> =
73
74
  export type OpStackTransactionReceiptOverrides = {
74
75
  depositNonce?: bigint | undefined
75
76
  depositReceiptVersion?: number | undefined
77
+ opGasRefund?: bigint | null | undefined
76
78
  l1GasPrice: bigint | null
77
79
  l1GasUsed: bigint | null
78
80
  l1Fee: bigint | null
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.58.2",
4
+ "version": "2.58.4",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -204,6 +204,7 @@ export async function simulateBlocks<
204
204
  abi && status === 'success' && data !== '0x'
205
205
  ? decodeFunctionResult({
206
206
  abi,
207
+ args,
207
208
  data,
208
209
  functionName,
209
210
  })
@@ -32,7 +32,9 @@ export const transactionReplacement = {
32
32
  /**
33
33
  * Returns the expiring nonce hash of a Tempo transaction:
34
34
  * `keccak256(encodeForSigning(tx) || sender)`. It excludes the fee payer
35
- * signature and fee token, so it is invariant to sponsorship.
35
+ * signature, and for sponsored transactions also the fee token, since the
36
+ * sender does not sign it. Re-sponsoring a transaction keeps its hash, but
37
+ * unsponsored transactions that differ only in fee token hash differently.
36
38
  *
37
39
  * @internal
38
40
  */
package/utils/ccip.ts CHANGED
@@ -304,10 +304,14 @@ export async function ccipRequest({
304
304
  )
305
305
 
306
306
  let result: any
307
+ let message: string | undefined
307
308
  if (
308
309
  response.headers.get('Content-Type')?.startsWith('application/json')
309
310
  ) {
310
- result = JSON.parse(responseBody).data
311
+ const json = JSON.parse(responseBody)
312
+ result = json.data
313
+ // EIP-3668 gateways describe 4xx and 5xx errors as `{ message: string }`.
314
+ if (typeof json.message === 'string') message = json.message
311
315
  } else {
312
316
  result = responseBody
313
317
  }
@@ -317,7 +321,7 @@ export async function ccipRequest({
317
321
  body,
318
322
  details: result?.error
319
323
  ? stringify(result.error)
320
- : response.statusText,
324
+ : (message ?? response.statusText),
321
325
  headers: response.headers,
322
326
  status: response.status,
323
327
  url,
@@ -55,7 +55,8 @@ export function validateSiweMessage(
55
55
 
56
56
  if (domain && message.domain !== domain) return false
57
57
  if (nonce && message.nonce !== nonce) return false
58
- if (scheme && message.scheme !== scheme) return false
58
+ // EIP-4361: if `scheme` is not specified, HTTPS is assumed by default.
59
+ if (scheme && (message.scheme ?? 'https') !== scheme) return false
59
60
 
60
61
  // EIP-4361 requires `nonce = 8*( ALPHA / DIGIT )` and `version = "1"`.
61
62
  if (message.nonce !== undefined && !nonceRegex.test(message.nonce))
@@ -90,11 +90,13 @@ export function serializeStateOverride(
90
90
  ): RpcStateOverride | undefined {
91
91
  if (!parameters) return undefined
92
92
  const rpcStateOverride: RpcStateOverride = {}
93
+ const addresses = new Set<string>()
93
94
  for (const { address, ...accountState } of parameters) {
94
95
  if (!isAddress(address, { strict: false }))
95
96
  throw new InvalidAddressError({ address })
96
- if (rpcStateOverride[address])
97
- throw new AccountStateConflictError({ address: address })
97
+ const key = address.toLowerCase()
98
+ if (addresses.has(key)) throw new AccountStateConflictError({ address })
99
+ addresses.add(key)
98
100
  rpcStateOverride[address] = serializeAccountStateOverride(accountState)
99
101
  }
100
102
  return rpcStateOverride
@@ -624,7 +624,7 @@ type ParseEIP155SignatureErrorType =
624
624
  | PadHexErrorType
625
625
  | ErrorType
626
626
 
627
- function parseEIP155Signature(
627
+ export function parseEIP155Signature(
628
628
  transactionArray: RecursiveArray<Hex>,
629
629
  ): Signature & { yParity: number } {
630
630
  const signature = transactionArray.slice(-3)