viem 2.22.19 → 2.22.20

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 (76) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/_cjs/chains/definitions/berachain.js +24 -0
  3. package/_cjs/chains/definitions/berachain.js.map +1 -0
  4. package/_cjs/chains/definitions/donatuz.js +29 -0
  5. package/_cjs/chains/definitions/donatuz.js.map +1 -0
  6. package/_cjs/chains/index.js +15 -11
  7. package/_cjs/chains/index.js.map +1 -1
  8. package/_cjs/errors/version.js +1 -1
  9. package/_cjs/experimental/erc7821/actions/execute.js +4 -58
  10. package/_cjs/experimental/erc7821/actions/execute.js.map +1 -1
  11. package/_cjs/experimental/erc7821/actions/executeBatches.js +5 -52
  12. package/_cjs/experimental/erc7821/actions/executeBatches.js.map +1 -1
  13. package/_cjs/experimental/erc7821/index.js +9 -1
  14. package/_cjs/experimental/erc7821/index.js.map +1 -1
  15. package/_cjs/experimental/erc7821/utils/encodeCalls.js +21 -0
  16. package/_cjs/experimental/erc7821/utils/encodeCalls.js.map +1 -0
  17. package/_cjs/experimental/erc7821/utils/encodeExecuteBatchesData.js +22 -0
  18. package/_cjs/experimental/erc7821/utils/encodeExecuteBatchesData.js.map +1 -0
  19. package/_cjs/experimental/erc7821/utils/encodeExecuteData.js +17 -0
  20. package/_cjs/experimental/erc7821/utils/encodeExecuteData.js.map +1 -0
  21. package/_cjs/experimental/erc7821/utils/getExecuteError.js +40 -0
  22. package/_cjs/experimental/erc7821/utils/getExecuteError.js.map +1 -0
  23. package/_esm/chains/definitions/berachain.js +21 -0
  24. package/_esm/chains/definitions/berachain.js.map +1 -0
  25. package/_esm/chains/definitions/donatuz.js +26 -0
  26. package/_esm/chains/definitions/donatuz.js.map +1 -0
  27. package/_esm/chains/index.js +2 -0
  28. package/_esm/chains/index.js.map +1 -1
  29. package/_esm/errors/version.js +1 -1
  30. package/_esm/experimental/erc7821/actions/execute.js +6 -60
  31. package/_esm/experimental/erc7821/actions/execute.js.map +1 -1
  32. package/_esm/experimental/erc7821/actions/executeBatches.js +6 -53
  33. package/_esm/experimental/erc7821/actions/executeBatches.js.map +1 -1
  34. package/_esm/experimental/erc7821/index.js +4 -0
  35. package/_esm/experimental/erc7821/index.js.map +1 -1
  36. package/_esm/experimental/erc7821/utils/encodeCalls.js +18 -0
  37. package/_esm/experimental/erc7821/utils/encodeCalls.js.map +1 -0
  38. package/_esm/experimental/erc7821/utils/encodeExecuteBatchesData.js +19 -0
  39. package/_esm/experimental/erc7821/utils/encodeExecuteBatchesData.js.map +1 -0
  40. package/_esm/experimental/erc7821/utils/encodeExecuteData.js +14 -0
  41. package/_esm/experimental/erc7821/utils/encodeExecuteData.js.map +1 -0
  42. package/_esm/experimental/erc7821/utils/getExecuteError.js +37 -0
  43. package/_esm/experimental/erc7821/utils/getExecuteError.js.map +1 -0
  44. package/_types/chains/definitions/berachain.d.ts +37 -0
  45. package/_types/chains/definitions/berachain.d.ts.map +1 -0
  46. package/_types/chains/definitions/donatuz.d.ts +33 -0
  47. package/_types/chains/definitions/donatuz.d.ts.map +1 -0
  48. package/_types/chains/index.d.ts +2 -0
  49. package/_types/chains/index.d.ts.map +1 -1
  50. package/_types/errors/version.d.ts +1 -1
  51. package/_types/experimental/erc7821/actions/execute.d.ts +3 -6
  52. package/_types/experimental/erc7821/actions/execute.d.ts.map +1 -1
  53. package/_types/experimental/erc7821/actions/executeBatches.d.ts +3 -6
  54. package/_types/experimental/erc7821/actions/executeBatches.d.ts.map +1 -1
  55. package/_types/experimental/erc7821/index.d.ts +4 -0
  56. package/_types/experimental/erc7821/index.d.ts.map +1 -1
  57. package/_types/experimental/erc7821/utils/encodeCalls.d.ts +8 -0
  58. package/_types/experimental/erc7821/utils/encodeCalls.d.ts.map +1 -0
  59. package/_types/experimental/erc7821/utils/encodeExecuteBatchesData.d.ts +21 -0
  60. package/_types/experimental/erc7821/utils/encodeExecuteBatchesData.d.ts.map +1 -0
  61. package/_types/experimental/erc7821/utils/encodeExecuteData.d.ts +16 -0
  62. package/_types/experimental/erc7821/utils/encodeExecuteData.d.ts.map +1 -0
  63. package/_types/experimental/erc7821/utils/getExecuteError.d.ts +12 -0
  64. package/_types/experimental/erc7821/utils/getExecuteError.d.ts.map +1 -0
  65. package/chains/definitions/berachain.ts +20 -0
  66. package/chains/definitions/donatuz.ts +26 -0
  67. package/chains/index.ts +2 -0
  68. package/errors/version.ts +1 -1
  69. package/experimental/erc7821/actions/execute.ts +15 -88
  70. package/experimental/erc7821/actions/executeBatches.ts +15 -75
  71. package/experimental/erc7821/index.ts +22 -0
  72. package/experimental/erc7821/utils/encodeCalls.ts +38 -0
  73. package/experimental/erc7821/utils/encodeExecuteBatchesData.ts +48 -0
  74. package/experimental/erc7821/utils/encodeExecuteData.ts +42 -0
  75. package/experimental/erc7821/utils/getExecuteError.ts +66 -0
  76. package/package.json +1 -1
@@ -1,6 +1,4 @@
1
- import type { Abi, Address, Narrow } from 'abitype'
2
- import * as AbiError from 'ox/AbiError'
3
- import * as AbiParameters from 'ox/AbiParameters'
1
+ import type { Address, Narrow } from 'abitype'
4
2
 
5
3
  import {
6
4
  type SendTransactionErrorType,
@@ -11,7 +9,7 @@ import type { Transport } from '../../../clients/transports/createTransport.js'
11
9
  import type { BaseError } from '../../../errors/base.js'
12
10
  import type { ErrorType } from '../../../errors/utils.js'
13
11
  import type { Account, GetAccountParameter } from '../../../types/account.js'
14
- import type { Batches, Call } from '../../../types/calls.js'
12
+ import type { Batches, Calls } from '../../../types/calls.js'
15
13
  import type {
16
14
  Chain,
17
15
  DeriveChain,
@@ -19,26 +17,17 @@ import type {
19
17
  } from '../../../types/chain.js'
20
18
  import type { Hex } from '../../../types/misc.js'
21
19
  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
20
  import type { FormattedTransactionRequest } from '../../../utils/formatters/transactionRequest.js'
35
21
  import { withCache } from '../../../utils/promise/withCache.js'
36
- import { abi, executionMode } from '../constants.js'
22
+ import { ExecuteUnsupportedError } from '../errors.js'
23
+ import {
24
+ type EncodeExecuteBatchesDataErrorType,
25
+ encodeExecuteBatchesData,
26
+ } from '../utils/encodeExecuteBatchesData.js'
37
27
  import {
38
- ExecuteUnsupportedError,
39
- FunctionSelectorNotRecognizedError,
40
- } from '../errors.js'
41
- import { encodeCalls } from './execute.js'
28
+ type GetExecuteErrorReturnType,
29
+ getExecuteError,
30
+ } from '../utils/getExecuteError.js'
42
31
  import { supportsExecutionMode } from './supportsExecutionMode.js'
43
32
 
44
33
  /** @internal */
@@ -66,16 +55,13 @@ export type ExecuteBatchesParameters<
66
55
  address: Address
67
56
  /** Batches to execute. */
68
57
  batches: Batches<Narrow<batches>, { opData?: Hex | undefined }>
69
- /** Additional data to include for execution. */
70
- opData?: Hex | undefined
71
58
  }
72
59
 
73
60
  export type ExecuteBatchesReturnType = Hex
74
61
 
75
62
  export type ExecuteBatchesErrorType =
76
- | DecodeErrorResultErrorType
77
- | GetContractErrorReturnType
78
- | EncodeFunctionDataErrorType
63
+ | GetExecuteErrorReturnType
64
+ | EncodeExecuteBatchesDataErrorType
79
65
  | SendTransactionErrorType
80
66
  | ErrorType
81
67
 
@@ -182,12 +168,6 @@ export async function executeBatches<
182
168
  const { authorizationList, batches } = parameters
183
169
 
184
170
  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
171
 
192
172
  const supported = await withCache(
193
173
  () =>
@@ -205,50 +185,10 @@ export async function executeBatches<
205
185
  return await sendTransaction(client, {
206
186
  ...parameters,
207
187
  to: parameters.address,
208
- data: encodeFunctionData({
209
- abi,
210
- functionName: 'execute',
211
- args: [executionMode.batchOfBatches, encodedBatches],
212
- }),
188
+ data: encodeExecuteBatchesData({ batches }),
213
189
  } as any)
214
190
  } 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
- })
191
+ const calls = batches.flatMap((b) => b.calls) as Calls<Narrow<batches>>
192
+ throw getExecuteError(e as BaseError, { calls })
253
193
  }
254
194
  }
@@ -26,3 +26,25 @@ export {
26
26
  } from './errors.js'
27
27
 
28
28
  export { type Erc7821Actions, erc7821Actions } from './decorators/erc7821.js'
29
+
30
+ export {
31
+ type EncodeCallsErrorType,
32
+ encodeCalls,
33
+ } from './utils/encodeCalls.js'
34
+ export {
35
+ type EncodeExecuteBatchesDataErrorType,
36
+ type EncodeExecuteBatchesDataParameters,
37
+ type EncodeExecuteBatchesDataReturnType,
38
+ encodeExecuteBatchesData,
39
+ } from './utils/encodeExecuteBatchesData.js'
40
+ export {
41
+ type EncodeExecuteDataErrorType,
42
+ type EncodeExecuteDataParameters,
43
+ type EncodeExecuteDataReturnType,
44
+ encodeExecuteData,
45
+ } from './utils/encodeExecuteData.js'
46
+ export {
47
+ type GetExecuteErrorParameters,
48
+ type GetExecuteErrorReturnType,
49
+ getExecuteError,
50
+ } from './utils/getExecuteError.js'
@@ -0,0 +1,38 @@
1
+ import * as AbiParameters from 'ox/AbiParameters'
2
+
3
+ import type { ErrorType } from '../../../errors/utils.js'
4
+ import type { Call, Calls } from '../../../types/calls.js'
5
+ import type { Hex } from '../../../types/misc.js'
6
+ import {
7
+ type EncodeFunctionDataErrorType,
8
+ encodeFunctionData,
9
+ } from '../../../utils/abi/encodeFunctionData.js'
10
+
11
+ export type EncodeCallsErrorType =
12
+ | AbiParameters.encode.ErrorType
13
+ | AbiParameters.from.ErrorType
14
+ | EncodeFunctionDataErrorType
15
+ | ErrorType
16
+
17
+ export function encodeCalls(
18
+ calls_: Calls<readonly unknown[]>,
19
+ opData?: Hex | undefined,
20
+ ) {
21
+ const calls = calls_.map((call_) => {
22
+ const call = call_ as Call
23
+ return {
24
+ data: call.abi ? encodeFunctionData(call) : (call.data ?? '0x'),
25
+ value: call.value ?? 0n,
26
+ target: call.to,
27
+ }
28
+ })
29
+
30
+ return AbiParameters.encode(
31
+ AbiParameters.from([
32
+ 'struct Call { address target; uint256 value; bytes data; }',
33
+ 'Call[] calls',
34
+ ...(opData ? ['bytes opData'] : []),
35
+ ]),
36
+ [calls, ...(opData ? [opData] : [])] as any,
37
+ )
38
+ }
@@ -0,0 +1,48 @@
1
+ import type { Narrow } from 'abitype'
2
+ import * as AbiParameters from 'ox/AbiParameters'
3
+ import type { ErrorType } from '../../../errors/utils.js'
4
+
5
+ import type { Batches } from '../../../types/calls.js'
6
+ import type { Hex } from '../../../types/misc.js'
7
+ import {
8
+ type EncodeFunctionDataErrorType,
9
+ encodeFunctionData,
10
+ } from '../../../utils/abi/encodeFunctionData.js'
11
+ import { abi, executionMode } from '../constants.js'
12
+ import { type EncodeCallsErrorType, encodeCalls } from './encodeCalls.js'
13
+
14
+ /** @internal */
15
+ export type Batch = { calls: readonly unknown[]; opData?: Hex | undefined }
16
+
17
+ export type EncodeExecuteBatchesDataParameters<
18
+ batches extends readonly Batch[] = readonly Batch[],
19
+ > = {
20
+ /** Batches to execute. */
21
+ batches: Batches<Narrow<batches>, { opData?: Hex | undefined }>
22
+ }
23
+
24
+ export type EncodeExecuteBatchesDataReturnType = Hex
25
+
26
+ export type EncodeExecuteBatchesDataErrorType =
27
+ | EncodeCallsErrorType
28
+ | EncodeFunctionDataErrorType
29
+ | ErrorType
30
+
31
+ export function encodeExecuteBatchesData<batches extends readonly Batch[]>(
32
+ parameters: EncodeExecuteBatchesDataParameters<batches>,
33
+ ): EncodeExecuteBatchesDataReturnType {
34
+ const { batches } = parameters
35
+
36
+ const encodedBatches = AbiParameters.encode(AbiParameters.from('bytes[]'), [
37
+ batches.map((b) => {
38
+ const batch = b as Batch
39
+ return encodeCalls(batch.calls, batch.opData)
40
+ }),
41
+ ])
42
+
43
+ return encodeFunctionData({
44
+ abi,
45
+ functionName: 'execute',
46
+ args: [executionMode.batchOfBatches, encodedBatches],
47
+ })
48
+ }
@@ -0,0 +1,42 @@
1
+ import type { Narrow } from 'abitype'
2
+
3
+ import type { ErrorType } from '../../../errors/utils.js'
4
+ import type { Calls } from '../../../types/calls.js'
5
+ import type { Hex } from '../../../types/misc.js'
6
+ import {
7
+ type EncodeFunctionDataErrorType,
8
+ encodeFunctionData,
9
+ } from '../../../utils/abi/encodeFunctionData.js'
10
+ import { abi, executionMode } from '../constants.js'
11
+ import { type EncodeCallsErrorType, encodeCalls } from './encodeCalls.js'
12
+
13
+ export type EncodeExecuteDataParameters<
14
+ calls extends readonly unknown[] = readonly unknown[],
15
+ > = {
16
+ /** Calls to execute. */
17
+ calls: Calls<Narrow<calls>>
18
+ /** Additional data to include for execution. */
19
+ opData?: Hex | undefined
20
+ }
21
+
22
+ export type EncodeExecuteDataReturnType = Hex
23
+
24
+ export type EncodeExecuteDataErrorType =
25
+ | EncodeCallsErrorType
26
+ | EncodeFunctionDataErrorType
27
+ | ErrorType
28
+
29
+ export function encodeExecuteData<const calls extends readonly unknown[]>(
30
+ parameters: EncodeExecuteDataParameters<calls>,
31
+ ): EncodeExecuteDataReturnType {
32
+ const { calls, opData } = parameters
33
+
34
+ const encodedCalls = encodeCalls(calls, opData)
35
+ const mode = opData ? executionMode.opData : executionMode.default
36
+
37
+ return encodeFunctionData({
38
+ abi,
39
+ functionName: 'execute',
40
+ args: [mode, encodedCalls],
41
+ })
42
+ }
@@ -0,0 +1,66 @@
1
+ import type { Abi, Narrow } from 'abitype'
2
+ import * as AbiError from 'ox/AbiError'
3
+
4
+ import type { BaseError } from '../../../errors/base.js'
5
+ import type { Call, Calls } from '../../../types/calls.js'
6
+ import type { Hex } from '../../../types/misc.js'
7
+ import { decodeErrorResult } from '../../../utils/abi/decodeErrorResult.js'
8
+ import {
9
+ type GetContractErrorReturnType,
10
+ getContractError,
11
+ } from '../../../utils/errors/getContractError.js'
12
+ import {
13
+ FunctionSelectorNotRecognizedError,
14
+ type FunctionSelectorNotRecognizedErrorType,
15
+ } from '../errors.js'
16
+
17
+ export type GetExecuteErrorParameters<
18
+ calls extends readonly unknown[] = readonly unknown[],
19
+ > = {
20
+ /** Calls to execute. */
21
+ calls: Calls<Narrow<calls>>
22
+ }
23
+
24
+ export type GetExecuteErrorReturnType =
25
+ | FunctionSelectorNotRecognizedErrorType
26
+ | GetContractErrorReturnType
27
+
28
+ export function getExecuteError<const calls extends readonly unknown[]>(
29
+ e: BaseError,
30
+ parameters: GetExecuteErrorParameters<calls>,
31
+ ): GetExecuteErrorReturnType {
32
+ const error = e.walk((e) => 'data' in (e as Error)) as
33
+ | (BaseError & { data?: Hex | undefined })
34
+ | undefined
35
+
36
+ if (!error?.data) throw e
37
+ if (
38
+ error.data ===
39
+ AbiError.getSelector(AbiError.from('error FnSelectorNotRecognized()'))
40
+ )
41
+ return new FunctionSelectorNotRecognizedError() as never
42
+
43
+ let matched: Call | null = null
44
+ for (const c of parameters.calls) {
45
+ const call = c as Call
46
+ if (!call.abi) continue
47
+ try {
48
+ const matches = Boolean(
49
+ decodeErrorResult({
50
+ abi: call.abi,
51
+ data: error.data!,
52
+ }),
53
+ )
54
+ if (!matches) continue
55
+ matched = call
56
+ } catch {}
57
+ }
58
+ if (!matched) throw e
59
+
60
+ return getContractError(error as BaseError, {
61
+ abi: matched.abi as Abi,
62
+ address: matched.to,
63
+ args: matched.args,
64
+ functionName: matched.functionName,
65
+ })
66
+ }
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.19",
4
+ "version": "2.22.20",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",