viem 2.21.60 → 2.22.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 (55) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/_cjs/actions/index.js +4 -2
  3. package/_cjs/actions/index.js.map +1 -1
  4. package/_cjs/actions/public/simulate.js +112 -0
  5. package/_cjs/actions/public/simulate.js.map +1 -0
  6. package/_cjs/chains/definitions/mainnet.js +1 -1
  7. package/_cjs/chains/definitions/mainnet.js.map +1 -1
  8. package/_cjs/clients/decorators/public.js +2 -0
  9. package/_cjs/clients/decorators/public.js.map +1 -1
  10. package/_cjs/errors/version.js +1 -1
  11. package/_cjs/errors/version.js.map +1 -1
  12. package/_cjs/index.js.map +1 -1
  13. package/_cjs/types/eip1193.js.map +1 -1
  14. package/_esm/actions/index.js +1 -0
  15. package/_esm/actions/index.js.map +1 -1
  16. package/_esm/actions/public/simulate.js +152 -0
  17. package/_esm/actions/public/simulate.js.map +1 -0
  18. package/_esm/chains/definitions/mainnet.js +1 -1
  19. package/_esm/chains/definitions/mainnet.js.map +1 -1
  20. package/_esm/clients/decorators/public.js +2 -0
  21. package/_esm/clients/decorators/public.js.map +1 -1
  22. package/_esm/errors/version.js +1 -1
  23. package/_esm/errors/version.js.map +1 -1
  24. package/_esm/index.js.map +1 -1
  25. package/_esm/types/eip1193.js.map +1 -1
  26. package/_types/actions/index.d.ts +1 -0
  27. package/_types/actions/index.d.ts.map +1 -1
  28. package/_types/actions/public/createAccessList.d.ts +3 -3
  29. package/_types/actions/public/createAccessList.d.ts.map +1 -1
  30. package/_types/actions/public/simulate.d.ts +114 -0
  31. package/_types/actions/public/simulate.d.ts.map +1 -0
  32. package/_types/chains/definitions/mainnet.d.ts +1 -1
  33. package/_types/clients/decorators/public.d.ts +44 -0
  34. package/_types/clients/decorators/public.d.ts.map +1 -1
  35. package/_types/errors/version.d.ts +1 -1
  36. package/_types/errors/version.d.ts.map +1 -1
  37. package/_types/index.d.ts +1 -0
  38. package/_types/index.d.ts.map +1 -1
  39. package/_types/types/calls.d.ts +9 -4
  40. package/_types/types/calls.d.ts.map +1 -1
  41. package/_types/types/eip1193.d.ts +36 -0
  42. package/_types/types/eip1193.d.ts.map +1 -1
  43. package/_types/types/multicall.d.ts +9 -7
  44. package/_types/types/multicall.d.ts.map +1 -1
  45. package/actions/index.ts +6 -0
  46. package/actions/public/createAccessList.ts +3 -3
  47. package/actions/public/simulate.ts +290 -0
  48. package/chains/definitions/mainnet.ts +1 -1
  49. package/clients/decorators/public.ts +51 -0
  50. package/errors/version.ts +1 -1
  51. package/index.ts +4 -0
  52. package/package.json +2 -2
  53. package/types/calls.ts +20 -11
  54. package/types/eip1193.ts +38 -0
  55. package/types/multicall.ts +29 -10
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.21.60",
4
+ "version": "2.22.0",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -177,7 +177,7 @@
177
177
  "@scure/bip39": "1.5.0",
178
178
  "abitype": "1.0.7",
179
179
  "isows": "1.0.6",
180
- "ox": "0.4.4",
180
+ "ox": "0.6.0",
181
181
  "webauthn-p256": "0.0.10",
182
182
  "ws": "8.18.0"
183
183
  },
package/types/calls.ts CHANGED
@@ -3,31 +3,40 @@ import type { Hex } from './misc.js'
3
3
  import type { GetMulticallContractParameters } from './multicall.js'
4
4
  import type { OneOf, Prettify } from './utils.js'
5
5
 
6
- export type Call<call = unknown> = OneOf<
7
- | {
6
+ export type Call<
7
+ call = unknown,
8
+ extraProperties extends Record<string, unknown> = {},
9
+ > = OneOf<
10
+ | (extraProperties & {
8
11
  data?: Hex | undefined
9
12
  to: Address
10
13
  value?: bigint | undefined
11
- }
12
- | (Omit<
13
- GetMulticallContractParameters<call, AbiStateMutability>,
14
- 'address'
15
- > & {
16
- to: Address
17
- value?: bigint | undefined
18
14
  })
15
+ | (extraProperties &
16
+ (Omit<
17
+ GetMulticallContractParameters<call, AbiStateMutability>,
18
+ 'address'
19
+ > & {
20
+ to: Address
21
+ value?: bigint | undefined
22
+ }))
19
23
  >
20
24
 
21
25
  export type Calls<
22
26
  calls extends readonly unknown[],
27
+ extraProperties extends Record<string, unknown> = {},
23
28
  ///
24
29
  result extends readonly any[] = [],
25
30
  > = calls extends readonly [] // no calls, return empty
26
31
  ? readonly []
27
32
  : calls extends readonly [infer call] // one call left before returning `result`
28
- ? readonly [...result, Prettify<Call<call>>]
33
+ ? readonly [...result, Prettify<Call<call, extraProperties>>]
29
34
  : calls extends readonly [infer call, ...infer rest] // grab first call and recurse through `rest`
30
- ? Calls<[...rest], [...result, Prettify<Call<call>>]>
35
+ ? Calls<
36
+ [...rest],
37
+ extraProperties,
38
+ [...result, Prettify<Call<call, extraProperties>>]
39
+ >
31
40
  : readonly unknown[] extends calls
32
41
  ? calls
33
42
  : // If `calls` is *some* array but we couldn't assign `unknown[]` to it, then it must hold some known/homogenous type!
package/types/eip1193.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { Address } from 'abitype'
2
2
 
3
+ import type * as BlockOverrides from 'ox/BlockOverrides'
3
4
  import type {
4
5
  RpcEstimateUserOperationGasReturnType,
5
6
  RpcGetUserOperationByHashReturnType,
@@ -1124,6 +1125,43 @@ export type PublicRpcSchema = [
1124
1125
  Parameters: [signedTransaction: Hex]
1125
1126
  ReturnType: Hash
1126
1127
  },
1128
+ /**
1129
+ * @description Simulates execution of a set of calls with optional block and state overrides.
1130
+ * @example
1131
+ * provider.request({ method: 'eth_simulateV1', params: [{ blockStateCalls: [{ calls: [{ from: '0x...', to: '0x...', value: '0x...', data: '0x...' }] }] }, 'latest'] })
1132
+ * // => { ... }
1133
+ */
1134
+ {
1135
+ Method: 'eth_simulateV1'
1136
+ Parameters: [
1137
+ {
1138
+ blockStateCalls: readonly {
1139
+ blockOverrides?: BlockOverrides.Rpc | undefined
1140
+ calls?: readonly ExactPartial<TransactionRequest>[] | undefined
1141
+ stateOverrides?: RpcStateOverride | undefined
1142
+ }[]
1143
+ returnFullTransactions?: boolean | undefined
1144
+ traceTransfers?: boolean | undefined
1145
+ validation?: boolean | undefined
1146
+ },
1147
+ BlockNumber | BlockTag,
1148
+ ]
1149
+ ReturnType: readonly (Block & {
1150
+ calls: readonly {
1151
+ error?:
1152
+ | {
1153
+ data?: Hex | undefined
1154
+ code: number
1155
+ message: string
1156
+ }
1157
+ | undefined
1158
+ logs?: readonly Log[] | undefined
1159
+ gasUsed: Hex
1160
+ returnData: Hex
1161
+ status: Hex
1162
+ }[]
1163
+ })[]
1164
+ },
1127
1165
  /**
1128
1166
  * @description Destroys a filter based on filter ID
1129
1167
  * @link https://eips.ethereum.org/EIPS/eip-1474
@@ -68,9 +68,10 @@ export type MulticallResults<
68
68
  contracts extends readonly unknown[] = readonly ContractFunctionParameters[],
69
69
  allowFailure extends boolean = true,
70
70
  options extends {
71
- error?: Error
71
+ error?: Error | undefined
72
+ extraProperties?: Record<string, unknown> | undefined
72
73
  mutability: AbiStateMutability
73
- } = { error: Error; mutability: AbiStateMutability },
74
+ } = { error: Error; extraProperties: {}; mutability: AbiStateMutability },
74
75
  ///
75
76
  result extends any[] = [],
76
77
  > = contracts extends readonly [] // no contracts, return empty
@@ -81,7 +82,8 @@ export type MulticallResults<
81
82
  MulticallResponse<
82
83
  GetMulticallContractReturnType<contract, options['mutability']>,
83
84
  options['error'],
84
- allowFailure
85
+ allowFailure,
86
+ options['extraProperties']
85
87
  >,
86
88
  ]
87
89
  : contracts extends readonly [infer contract, ...infer rest] // grab first contract and recurse through `rest`
@@ -94,12 +96,18 @@ export type MulticallResults<
94
96
  MulticallResponse<
95
97
  GetMulticallContractReturnType<contract, options['mutability']>,
96
98
  options['error'],
97
- allowFailure
99
+ allowFailure,
100
+ options['extraProperties']
98
101
  >,
99
102
  ]
100
103
  >
101
104
  : readonly unknown[] extends contracts
102
- ? MulticallResponse<unknown, options['error'], allowFailure>[]
105
+ ? MulticallResponse<
106
+ unknown,
107
+ options['error'],
108
+ allowFailure,
109
+ options['extraProperties']
110
+ >[]
103
111
  : // If `contracts` is *some* array but we couldn't assign `unknown[]` to it, then it must hold some known/homogenous type!
104
112
  // use this to infer the param types in the case of Array.map() argument
105
113
  contracts extends readonly (infer contract extends
@@ -107,23 +115,34 @@ export type MulticallResults<
107
115
  ? MulticallResponse<
108
116
  GetMulticallContractReturnType<contract, options['mutability']>,
109
117
  options['error'],
110
- allowFailure
118
+ allowFailure,
119
+ options['extraProperties']
111
120
  >[]
112
121
  : // Fallback
113
- MulticallResponse<unknown, options['error'], allowFailure>[]
122
+ MulticallResponse<
123
+ unknown,
124
+ options['error'],
125
+ allowFailure,
126
+ options['extraProperties']
127
+ >[]
114
128
 
115
129
  export type MulticallResponse<
116
130
  result = unknown,
117
131
  error = unknown,
118
132
  allowFailure extends boolean = true,
133
+ extraProperties extends Record<string, unknown> | undefined = {},
119
134
  > = allowFailure extends true
120
135
  ?
121
- | { error?: undefined; result: result; status: 'success' }
122
- | {
136
+ | (extraProperties & {
137
+ error?: undefined
138
+ result: result
139
+ status: 'success'
140
+ })
141
+ | (extraProperties & {
123
142
  error: unknown extends error ? Error : error
124
143
  result?: undefined
125
144
  status: 'failure'
126
- }
145
+ })
127
146
  : result
128
147
 
129
148
  // infer contract parameters from `unknown`