viem 2.22.16 → 2.22.19

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 (98) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/_cjs/actions/public/simulate.js +1 -1
  3. package/_cjs/actions/public/simulate.js.map +1 -1
  4. package/_cjs/chains/definitions/forta.js +25 -0
  5. package/_cjs/chains/definitions/forta.js.map +1 -0
  6. package/_cjs/chains/definitions/sidra.js +25 -0
  7. package/_cjs/chains/definitions/sidra.js.map +1 -0
  8. package/_cjs/chains/definitions/songbird.js +6 -0
  9. package/_cjs/chains/definitions/songbird.js.map +1 -1
  10. package/_cjs/chains/definitions/wmcTestnet.js +22 -0
  11. package/_cjs/chains/definitions/wmcTestnet.js.map +1 -0
  12. package/_cjs/chains/index.js +14 -8
  13. package/_cjs/chains/index.js.map +1 -1
  14. package/_cjs/clients/transports/fallback.js +2 -0
  15. package/_cjs/clients/transports/fallback.js.map +1 -1
  16. package/_cjs/errors/version.js +1 -1
  17. package/_cjs/experimental/erc7821/actions/execute.js +36 -26
  18. package/_cjs/experimental/erc7821/actions/execute.js.map +1 -1
  19. package/_cjs/experimental/erc7821/actions/executeBatches.js +80 -0
  20. package/_cjs/experimental/erc7821/actions/executeBatches.js.map +1 -0
  21. package/_cjs/experimental/erc7821/actions/supportsExecutionMode.js +11 -3
  22. package/_cjs/experimental/erc7821/actions/supportsExecutionMode.js.map +1 -1
  23. package/_cjs/experimental/erc7821/constants.js +1 -0
  24. package/_cjs/experimental/erc7821/constants.js.map +1 -1
  25. package/_cjs/experimental/erc7821/decorators/erc7821.js +2 -0
  26. package/_cjs/experimental/erc7821/decorators/erc7821.js.map +1 -1
  27. package/_cjs/experimental/erc7821/index.js +3 -1
  28. package/_cjs/experimental/erc7821/index.js.map +1 -1
  29. package/_esm/actions/public/simulate.js +1 -1
  30. package/_esm/actions/public/simulate.js.map +1 -1
  31. package/_esm/chains/definitions/forta.js +22 -0
  32. package/_esm/chains/definitions/forta.js.map +1 -0
  33. package/_esm/chains/definitions/sidra.js +22 -0
  34. package/_esm/chains/definitions/sidra.js.map +1 -0
  35. package/_esm/chains/definitions/songbird.js +6 -0
  36. package/_esm/chains/definitions/songbird.js.map +1 -1
  37. package/_esm/chains/definitions/wmcTestnet.js +19 -0
  38. package/_esm/chains/definitions/wmcTestnet.js.map +1 -0
  39. package/_esm/chains/index.js +3 -0
  40. package/_esm/chains/index.js.map +1 -1
  41. package/_esm/clients/transports/fallback.js +2 -0
  42. package/_esm/clients/transports/fallback.js.map +1 -1
  43. package/_esm/errors/version.js +1 -1
  44. package/_esm/experimental/erc7821/actions/execute.js +36 -26
  45. package/_esm/experimental/erc7821/actions/execute.js.map +1 -1
  46. package/_esm/experimental/erc7821/actions/executeBatches.js +168 -0
  47. package/_esm/experimental/erc7821/actions/executeBatches.js.map +1 -0
  48. package/_esm/experimental/erc7821/actions/supportsExecutionMode.js +11 -3
  49. package/_esm/experimental/erc7821/actions/supportsExecutionMode.js.map +1 -1
  50. package/_esm/experimental/erc7821/constants.js +1 -0
  51. package/_esm/experimental/erc7821/constants.js.map +1 -1
  52. package/_esm/experimental/erc7821/decorators/erc7821.js +2 -0
  53. package/_esm/experimental/erc7821/decorators/erc7821.js.map +1 -1
  54. package/_esm/experimental/erc7821/index.js +1 -1
  55. package/_esm/experimental/erc7821/index.js.map +1 -1
  56. package/_types/actions/public/simulate.d.ts.map +1 -1
  57. package/_types/chains/definitions/forta.d.ts +37 -0
  58. package/_types/chains/definitions/forta.d.ts.map +1 -0
  59. package/_types/chains/definitions/sidra.d.ts +37 -0
  60. package/_types/chains/definitions/sidra.d.ts.map +1 -0
  61. package/_types/chains/definitions/songbird.d.ts +6 -10
  62. package/_types/chains/definitions/songbird.d.ts.map +1 -1
  63. package/_types/chains/definitions/wmcTestnet.d.ts +37 -0
  64. package/_types/chains/definitions/wmcTestnet.d.ts.map +1 -0
  65. package/_types/chains/index.d.ts +3 -0
  66. package/_types/chains/index.d.ts.map +1 -1
  67. package/_types/clients/transports/fallback.d.ts.map +1 -1
  68. package/_types/errors/version.d.ts +1 -1
  69. package/_types/experimental/erc7821/actions/execute.d.ts +2 -0
  70. package/_types/experimental/erc7821/actions/execute.d.ts.map +1 -1
  71. package/_types/experimental/erc7821/actions/executeBatches.d.ts +124 -0
  72. package/_types/experimental/erc7821/actions/executeBatches.d.ts.map +1 -0
  73. package/_types/experimental/erc7821/actions/supportsExecutionMode.d.ts +1 -1
  74. package/_types/experimental/erc7821/actions/supportsExecutionMode.d.ts.map +1 -1
  75. package/_types/experimental/erc7821/constants.d.ts +1 -0
  76. package/_types/experimental/erc7821/constants.d.ts.map +1 -1
  77. package/_types/experimental/erc7821/decorators/erc7821.d.ts +93 -0
  78. package/_types/experimental/erc7821/decorators/erc7821.d.ts.map +1 -1
  79. package/_types/experimental/erc7821/index.d.ts +1 -1
  80. package/_types/experimental/erc7821/index.d.ts.map +1 -1
  81. package/_types/types/calls.d.ts +21 -0
  82. package/_types/types/calls.d.ts.map +1 -1
  83. package/actions/public/simulate.ts +8 -7
  84. package/chains/definitions/forta.ts +22 -0
  85. package/chains/definitions/sidra.ts +22 -0
  86. package/chains/definitions/songbird.ts +6 -0
  87. package/chains/definitions/wmcTestnet.ts +19 -0
  88. package/chains/index.ts +3 -0
  89. package/clients/transports/fallback.ts +2 -0
  90. package/errors/version.ts +1 -1
  91. package/experimental/erc7821/actions/execute.ts +48 -36
  92. package/experimental/erc7821/actions/executeBatches.ts +254 -0
  93. package/experimental/erc7821/actions/supportsExecutionMode.ts +22 -9
  94. package/experimental/erc7821/constants.ts +2 -0
  95. package/experimental/erc7821/decorators/erc7821.ts +109 -0
  96. package/experimental/erc7821/index.ts +6 -1
  97. package/package.json +1 -1
  98. package/types/calls.ts +18 -0
@@ -0,0 +1,254 @@
1
+ import type { Abi, Address, Narrow } from 'abitype'
2
+ import * as AbiError from 'ox/AbiError'
3
+ import * as AbiParameters from 'ox/AbiParameters'
4
+
5
+ import {
6
+ type SendTransactionErrorType,
7
+ sendTransaction,
8
+ } from '../../../actions/wallet/sendTransaction.js'
9
+ import type { Client } from '../../../clients/createClient.js'
10
+ import type { Transport } from '../../../clients/transports/createTransport.js'
11
+ import type { BaseError } from '../../../errors/base.js'
12
+ import type { ErrorType } from '../../../errors/utils.js'
13
+ import type { Account, GetAccountParameter } from '../../../types/account.js'
14
+ import type { Batches, Call } from '../../../types/calls.js'
15
+ import type {
16
+ Chain,
17
+ DeriveChain,
18
+ GetChainParameter,
19
+ } from '../../../types/chain.js'
20
+ import type { Hex } from '../../../types/misc.js'
21
+ import type { UnionEvaluate, UnionPick } from '../../../types/utils.js'
22
+ import {
23
+ type DecodeErrorResultErrorType,
24
+ decodeErrorResult,
25
+ } from '../../../utils/abi/decodeErrorResult.js'
26
+ import {
27
+ type EncodeFunctionDataErrorType,
28
+ encodeFunctionData,
29
+ } from '../../../utils/abi/encodeFunctionData.js'
30
+ import {
31
+ type GetContractErrorReturnType,
32
+ getContractError,
33
+ } from '../../../utils/errors/getContractError.js'
34
+ import type { FormattedTransactionRequest } from '../../../utils/formatters/transactionRequest.js'
35
+ import { withCache } from '../../../utils/promise/withCache.js'
36
+ import { abi, executionMode } from '../constants.js'
37
+ import {
38
+ ExecuteUnsupportedError,
39
+ FunctionSelectorNotRecognizedError,
40
+ } from '../errors.js'
41
+ import { encodeCalls } from './execute.js'
42
+ import { supportsExecutionMode } from './supportsExecutionMode.js'
43
+
44
+ /** @internal */
45
+ export type Batch = { calls: readonly unknown[]; opData?: Hex | undefined }
46
+
47
+ export type ExecuteBatchesParameters<
48
+ batches extends readonly Batch[] = readonly Batch[],
49
+ chain extends Chain | undefined = Chain | undefined,
50
+ account extends Account | undefined = Account | undefined,
51
+ chainOverride extends Chain | undefined = Chain | undefined,
52
+ _derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
53
+ > = UnionEvaluate<
54
+ UnionPick<
55
+ FormattedTransactionRequest<_derivedChain>,
56
+ | 'authorizationList'
57
+ | 'gas'
58
+ | 'gasPrice'
59
+ | 'maxFeePerGas'
60
+ | 'maxPriorityFeePerGas'
61
+ >
62
+ > &
63
+ GetAccountParameter<account, Account | Address, true, true> &
64
+ GetChainParameter<chain, chainOverride> & {
65
+ /** Address that will execute the calls. */
66
+ address: Address
67
+ /** Batches to execute. */
68
+ batches: Batches<Narrow<batches>, { opData?: Hex | undefined }>
69
+ /** Additional data to include for execution. */
70
+ opData?: Hex | undefined
71
+ }
72
+
73
+ export type ExecuteBatchesReturnType = Hex
74
+
75
+ export type ExecuteBatchesErrorType =
76
+ | DecodeErrorResultErrorType
77
+ | GetContractErrorReturnType
78
+ | EncodeFunctionDataErrorType
79
+ | SendTransactionErrorType
80
+ | ErrorType
81
+
82
+ /**
83
+ * Executes batches of call(s) using "batch of batches" mode on an [ERC-7821-compatible contract](https://eips.ethereum.org/EIPS/eip-7821).
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * import { createClient, http, parseEther } from 'viem'
88
+ * import { privateKeyToAccount } from 'viem/accounts'
89
+ * import { mainnet } from 'viem/chains'
90
+ * import { executeBatches } from 'viem/experimental/erc7821'
91
+ *
92
+ * const account = privateKeyToAccount('0x...')
93
+ *
94
+ * const client = createClient({
95
+ * chain: mainnet,
96
+ * transport: http(),
97
+ * })
98
+ *
99
+ * const hash = await executeBatches(client, {
100
+ * account,
101
+ * batches: [
102
+ * {
103
+ * calls: [
104
+ * {
105
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
106
+ * value: parseEther('1'),
107
+ * },
108
+ * ],
109
+ * },
110
+ * {
111
+ * calls: [
112
+ * {
113
+ * to: '0xcb98643b8786950F0461f3B0edf99D88F274574D',
114
+ * value: parseEther('2'),
115
+ * },
116
+ * {
117
+ * data: '0xdeadbeef',
118
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
119
+ * },
120
+ * ],
121
+ * },
122
+ * ],
123
+ * to: account.address,
124
+ * })
125
+ * ```
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * // Account Hoisting
130
+ * import { createClient, http, parseEther } from 'viem'
131
+ * import { privateKeyToAccount } from 'viem/accounts'
132
+ * import { mainnet } from 'viem/chains'
133
+ * import { executeBatches } from 'viem/experimental/erc7821'
134
+ *
135
+ * const account = privateKeyToAccount('0x...')
136
+ *
137
+ * const client = createClient({
138
+ * chain: mainnet,
139
+ * transport: http(),
140
+ * })
141
+ *
142
+ * const hash = await executeBatches(client, {
143
+ * batches: [
144
+ * {
145
+ * calls: [
146
+ * {
147
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
148
+ * value: parseEther('1'),
149
+ * },
150
+ * ],
151
+ * },
152
+ * {
153
+ * calls: [
154
+ * {
155
+ * to: '0xcb98643b8786950F0461f3B0edf99D88F274574D',
156
+ * value: parseEther('2'),
157
+ * },
158
+ * {
159
+ * data: '0xdeadbeef',
160
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
161
+ * },
162
+ * ],
163
+ * },
164
+ * ],
165
+ * to: account.address,
166
+ * })
167
+ * ```
168
+ *
169
+ * @param client - Client to use.
170
+ * @param parameters - {@link ExecuteBatchesParameters}
171
+ * @returns Transaction hash. {@link ExecuteBatchesReturnType}
172
+ */
173
+ export async function executeBatches<
174
+ batches extends readonly Batch[],
175
+ chain extends Chain | undefined,
176
+ account extends Account | undefined,
177
+ chainOverride extends Chain | undefined = undefined,
178
+ >(
179
+ client: Client<Transport, chain, account>,
180
+ parameters: ExecuteBatchesParameters<batches, chain, account, chainOverride>,
181
+ ): Promise<ExecuteBatchesReturnType> {
182
+ const { authorizationList, batches } = parameters
183
+
184
+ const address = authorizationList?.[0]?.contractAddress ?? parameters.address
185
+ const encodedBatches = AbiParameters.encode(AbiParameters.from('bytes[]'), [
186
+ batches.map((b) => {
187
+ const batch = b as Batch
188
+ return encodeCalls(batch.calls, batch.opData)
189
+ }),
190
+ ])
191
+
192
+ const supported = await withCache(
193
+ () =>
194
+ supportsExecutionMode(client, {
195
+ address,
196
+ mode: 'batchOfBatches',
197
+ }),
198
+ {
199
+ cacheKey: `supportsExecutionMode.${client.uid}.${address}.batchOfBatches`,
200
+ },
201
+ )
202
+ if (!supported) throw new ExecuteUnsupportedError()
203
+
204
+ try {
205
+ return await sendTransaction(client, {
206
+ ...parameters,
207
+ to: parameters.address,
208
+ data: encodeFunctionData({
209
+ abi,
210
+ functionName: 'execute',
211
+ args: [executionMode.batchOfBatches, encodedBatches],
212
+ }),
213
+ } as any)
214
+ } catch (e) {
215
+ const error = (e as BaseError).walk((e) => 'data' in (e as Error)) as
216
+ | (BaseError & { data?: Hex | undefined })
217
+ | undefined
218
+
219
+ if (!error?.data) throw e
220
+ if (
221
+ error.data ===
222
+ AbiError.getSelector(AbiError.from('error FnSelectorNotRecognized()'))
223
+ )
224
+ throw new FunctionSelectorNotRecognizedError()
225
+
226
+ let matched: Call | null = null
227
+ for (const b of parameters.batches) {
228
+ const batch = b as Batch
229
+ for (const c of batch.calls) {
230
+ const call = c as Call
231
+ if (!call.abi) continue
232
+ try {
233
+ const matches = Boolean(
234
+ decodeErrorResult({
235
+ abi: call.abi,
236
+ data: error.data!,
237
+ }),
238
+ )
239
+ if (!matches) continue
240
+ matched = call
241
+ } catch {}
242
+ }
243
+ }
244
+ if (!matched) throw e
245
+
246
+ throw getContractError(error as BaseError, {
247
+ abi: matched.abi as Abi,
248
+ address: matched.to,
249
+ args: matched.args,
250
+ docsPath: '/experimental/erc7821/executeBatches',
251
+ functionName: matched.functionName,
252
+ })
253
+ }
254
+ }
@@ -5,17 +5,24 @@ import type { Transport } from '../../../clients/transports/createTransport.js'
5
5
  import type { ErrorType } from '../../../errors/utils.js'
6
6
  import type { Chain } from '../../../types/chain.js'
7
7
  import type { Hex } from '../../../types/misc.js'
8
+ import { withCache } from '../../../utils/promise/withCache.js'
8
9
  import { abi, executionMode } from '../constants.js'
9
10
 
10
11
  export type SupportsExecutionModeParameters = {
11
12
  address: Address
12
- opData?: Hex | undefined
13
+ mode?: 'default' | 'opData' | 'batchOfBatches' | Hex
13
14
  }
14
15
 
15
16
  export type SupportsExecutionModeReturnType = boolean
16
17
 
17
18
  export type SupportsExecutionModeErrorType = ErrorType
18
19
 
20
+ const toSerializedMode = {
21
+ default: executionMode.default,
22
+ opData: executionMode.opData,
23
+ batchOfBatches: executionMode.batchOfBatches,
24
+ } as const
25
+
19
26
  /**
20
27
  * Checks if the contract supports the ERC-7821 execution mode.
21
28
  *
@@ -45,15 +52,21 @@ export async function supportsExecutionMode<
45
52
  client: Client<Transport, chain>,
46
53
  parameters: SupportsExecutionModeParameters,
47
54
  ): Promise<SupportsExecutionModeReturnType> {
48
- const { address, opData } = parameters
49
- const mode = opData ? executionMode.opData : executionMode.default
55
+ const { address, mode: m = 'default' } = parameters
56
+ const mode = m.startsWith('0x') ? m : (toSerializedMode as any)[m]
50
57
  try {
51
- return await readContract(client, {
52
- abi,
53
- address,
54
- functionName: 'supportsExecutionMode',
55
- args: [mode],
56
- })
58
+ return await withCache(
59
+ () =>
60
+ readContract(client, {
61
+ abi,
62
+ address,
63
+ functionName: 'supportsExecutionMode',
64
+ args: [mode],
65
+ }),
66
+ {
67
+ cacheKey: `supportsExecutionMode.${address}.${mode}`,
68
+ },
69
+ )
57
70
  } catch {
58
71
  return false
59
72
  }
@@ -59,4 +59,6 @@ export const abi = [
59
59
  export const executionMode = {
60
60
  default: '0x0100000000000000000000000000000000000000000000000000000000000000',
61
61
  opData: '0x0100000000007821000100000000000000000000000000000000000000000000',
62
+ batchOfBatches:
63
+ '0x0100000000007821000200000000000000000000000000000000000000000000',
62
64
  } as const
@@ -7,6 +7,12 @@ import {
7
7
  type ExecuteReturnType,
8
8
  execute,
9
9
  } from '../actions/execute.js'
10
+ import {
11
+ type Batch,
12
+ type ExecuteBatchesParameters,
13
+ type ExecuteBatchesReturnType,
14
+ executeBatches,
15
+ } from '../actions/executeBatches.js'
10
16
  import {
11
17
  type SupportsExecutionModeParameters,
12
18
  type SupportsExecutionModeReturnType,
@@ -91,6 +97,108 @@ export type Erc7821Actions<
91
97
  >(
92
98
  parameters: ExecuteParameters<calls, chain, account, chainOverride>,
93
99
  ) => Promise<ExecuteReturnType>
100
+ /**
101
+ * Executes batches of call(s) using "batch of batches" mode on an [ERC-7821-compatible contract](https://eips.ethereum.org/EIPS/eip-7821).
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * import { createClient, http, parseEther } from 'viem'
106
+ * import { privateKeyToAccount } from 'viem/accounts'
107
+ * import { mainnet } from 'viem/chains'
108
+ * import { erc7821Actions } from 'viem/experimental'
109
+ *
110
+ * const account = privateKeyToAccount('0x...')
111
+ *
112
+ * const client = createClient({
113
+ * chain: mainnet,
114
+ * transport: http(),
115
+ * }).extend(erc7821Actions())
116
+ *
117
+ * const hash = await client.executeBatches({
118
+ * account,
119
+ * batches: [
120
+ * {
121
+ * calls: [
122
+ * {
123
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
124
+ * value: parseEther('1'),
125
+ * },
126
+ * ],
127
+ * },
128
+ * {
129
+ * calls: [
130
+ * {
131
+ * to: '0xcb98643b8786950F0461f3B0edf99D88F274574D',
132
+ * value: parseEther('2'),
133
+ * },
134
+ * {
135
+ * data: '0xdeadbeef',
136
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
137
+ * },
138
+ * ],
139
+ * },
140
+ * ],
141
+ * to: account.address,
142
+ * })
143
+ * ```
144
+ *
145
+ * @example
146
+ * ```ts
147
+ * // Account Hoisting
148
+ * import { createClient, http, parseEther } from 'viem'
149
+ * import { privateKeyToAccount } from 'viem/accounts'
150
+ * import { mainnet } from 'viem/chains'
151
+ * import { erc7821Actions } from 'viem/experimental'
152
+ *
153
+ * const account = privateKeyToAccount('0x...')
154
+ *
155
+ * const client = createClient({
156
+ * chain: mainnet,
157
+ * transport: http(),
158
+ * }).extend(erc7821Actions())
159
+ *
160
+ * const hash = await client.executeBatches({
161
+ * batches: [
162
+ * {
163
+ * calls: [
164
+ * {
165
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
166
+ * value: parseEther('1'),
167
+ * },
168
+ * ],
169
+ * },
170
+ * {
171
+ * calls: [
172
+ * {
173
+ * to: '0xcb98643b8786950F0461f3B0edf99D88F274574D',
174
+ * value: parseEther('2'),
175
+ * },
176
+ * {
177
+ * data: '0xdeadbeef',
178
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
179
+ * },
180
+ * ],
181
+ * },
182
+ * ],
183
+ * to: account.address,
184
+ * })
185
+ * ```
186
+ *
187
+ * @param client - Client to use.
188
+ * @param parameters - {@link ExecuteBatchesParameters}
189
+ * @returns Transaction hash. {@link ExecuteBatchesReturnType}
190
+ */
191
+ executeBatches: <
192
+ const batches extends readonly Batch[],
193
+ chainOverride extends Chain | undefined = undefined,
194
+ >(
195
+ parameters: ExecuteBatchesParameters<
196
+ batches,
197
+ chain,
198
+ account,
199
+ chainOverride
200
+ >,
201
+ ) => Promise<ExecuteBatchesReturnType>
94
202
  /**
95
203
  * Checks if the contract supports the ERC-7821 execution mode.
96
204
  *
@@ -142,6 +250,7 @@ export function erc7821Actions() {
142
250
  ): Erc7821Actions<chain, account> => {
143
251
  return {
144
252
  execute: (parameters) => execute(client, parameters),
253
+ executeBatches: (parameters) => executeBatches(client, parameters),
145
254
  supportsExecutionMode: (parameters) =>
146
255
  supportsExecutionMode(client, parameters),
147
256
  }
@@ -1,4 +1,3 @@
1
- /** */
2
1
  // biome-ignore lint/performance/noBarrelFile: entrypoint
3
2
  export {
4
3
  type ExecuteErrorType,
@@ -6,6 +5,12 @@ export {
6
5
  type ExecuteReturnType,
7
6
  execute,
8
7
  } from './actions/execute.js'
8
+ export {
9
+ type ExecuteBatchesErrorType,
10
+ type ExecuteBatchesParameters,
11
+ type ExecuteBatchesReturnType,
12
+ executeBatches,
13
+ } from './actions/executeBatches.js'
9
14
  export {
10
15
  type SupportsExecutionModeErrorType,
11
16
  type SupportsExecutionModeParameters,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.22.16",
4
+ "version": "2.22.19",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
package/types/calls.ts CHANGED
@@ -45,3 +45,21 @@ export type Calls<
45
45
  ? readonly Prettify<call>[]
46
46
  : // Fallback
47
47
  readonly OneOf<Call>[]
48
+
49
+ export type Batches<
50
+ batches extends readonly { calls: readonly unknown[] }[],
51
+ properties extends Record<string, any> = {},
52
+ ///
53
+ result extends readonly any[] = [],
54
+ > = batches extends readonly [infer batch extends { calls: readonly unknown[] }]
55
+ ? [...result, { calls: Calls<batch['calls']> } & properties]
56
+ : batches extends readonly [
57
+ infer batch extends { calls: readonly unknown[] },
58
+ ...infer rest extends readonly { calls: readonly unknown[] }[],
59
+ ]
60
+ ? Batches<
61
+ [...rest],
62
+ properties,
63
+ [...result, { calls: Calls<batch['calls']> } & properties]
64
+ >
65
+ : batches