viem 2.22.17 → 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.
- package/CHANGELOG.md +20 -0
- package/_cjs/actions/public/simulate.js +1 -1
- package/_cjs/actions/public/simulate.js.map +1 -1
- package/_cjs/chains/definitions/forta.js +25 -0
- package/_cjs/chains/definitions/forta.js.map +1 -0
- package/_cjs/chains/definitions/sidra.js +25 -0
- package/_cjs/chains/definitions/sidra.js.map +1 -0
- package/_cjs/chains/definitions/songbird.js +6 -0
- package/_cjs/chains/definitions/songbird.js.map +1 -1
- package/_cjs/chains/definitions/wmcTestnet.js +22 -0
- package/_cjs/chains/definitions/wmcTestnet.js.map +1 -0
- package/_cjs/chains/index.js +14 -8
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/experimental/erc7821/actions/execute.js +36 -26
- package/_cjs/experimental/erc7821/actions/execute.js.map +1 -1
- package/_cjs/experimental/erc7821/actions/executeBatches.js +80 -0
- package/_cjs/experimental/erc7821/actions/executeBatches.js.map +1 -0
- package/_cjs/experimental/erc7821/actions/supportsExecutionMode.js +11 -3
- package/_cjs/experimental/erc7821/actions/supportsExecutionMode.js.map +1 -1
- package/_cjs/experimental/erc7821/constants.js +1 -0
- package/_cjs/experimental/erc7821/constants.js.map +1 -1
- package/_cjs/experimental/erc7821/decorators/erc7821.js +2 -0
- package/_cjs/experimental/erc7821/decorators/erc7821.js.map +1 -1
- package/_cjs/experimental/erc7821/index.js +3 -1
- package/_cjs/experimental/erc7821/index.js.map +1 -1
- package/_esm/actions/public/simulate.js +1 -1
- package/_esm/actions/public/simulate.js.map +1 -1
- package/_esm/chains/definitions/forta.js +22 -0
- package/_esm/chains/definitions/forta.js.map +1 -0
- package/_esm/chains/definitions/sidra.js +22 -0
- package/_esm/chains/definitions/sidra.js.map +1 -0
- package/_esm/chains/definitions/songbird.js +6 -0
- package/_esm/chains/definitions/songbird.js.map +1 -1
- package/_esm/chains/definitions/wmcTestnet.js +19 -0
- package/_esm/chains/definitions/wmcTestnet.js.map +1 -0
- package/_esm/chains/index.js +3 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/experimental/erc7821/actions/execute.js +36 -26
- package/_esm/experimental/erc7821/actions/execute.js.map +1 -1
- package/_esm/experimental/erc7821/actions/executeBatches.js +168 -0
- package/_esm/experimental/erc7821/actions/executeBatches.js.map +1 -0
- package/_esm/experimental/erc7821/actions/supportsExecutionMode.js +11 -3
- package/_esm/experimental/erc7821/actions/supportsExecutionMode.js.map +1 -1
- package/_esm/experimental/erc7821/constants.js +1 -0
- package/_esm/experimental/erc7821/constants.js.map +1 -1
- package/_esm/experimental/erc7821/decorators/erc7821.js +2 -0
- package/_esm/experimental/erc7821/decorators/erc7821.js.map +1 -1
- package/_esm/experimental/erc7821/index.js +1 -1
- package/_esm/experimental/erc7821/index.js.map +1 -1
- package/_types/actions/public/simulate.d.ts.map +1 -1
- package/_types/chains/definitions/forta.d.ts +37 -0
- package/_types/chains/definitions/forta.d.ts.map +1 -0
- package/_types/chains/definitions/sidra.d.ts +37 -0
- package/_types/chains/definitions/sidra.d.ts.map +1 -0
- package/_types/chains/definitions/songbird.d.ts +6 -10
- package/_types/chains/definitions/songbird.d.ts.map +1 -1
- package/_types/chains/definitions/wmcTestnet.d.ts +37 -0
- package/_types/chains/definitions/wmcTestnet.d.ts.map +1 -0
- package/_types/chains/index.d.ts +3 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/experimental/erc7821/actions/execute.d.ts +2 -0
- package/_types/experimental/erc7821/actions/execute.d.ts.map +1 -1
- package/_types/experimental/erc7821/actions/executeBatches.d.ts +124 -0
- package/_types/experimental/erc7821/actions/executeBatches.d.ts.map +1 -0
- package/_types/experimental/erc7821/actions/supportsExecutionMode.d.ts +1 -1
- package/_types/experimental/erc7821/actions/supportsExecutionMode.d.ts.map +1 -1
- package/_types/experimental/erc7821/constants.d.ts +1 -0
- package/_types/experimental/erc7821/constants.d.ts.map +1 -1
- package/_types/experimental/erc7821/decorators/erc7821.d.ts +93 -0
- package/_types/experimental/erc7821/decorators/erc7821.d.ts.map +1 -1
- package/_types/experimental/erc7821/index.d.ts +1 -1
- package/_types/experimental/erc7821/index.d.ts.map +1 -1
- package/_types/types/calls.d.ts +21 -0
- package/_types/types/calls.d.ts.map +1 -1
- package/actions/public/simulate.ts +8 -7
- package/chains/definitions/forta.ts +22 -0
- package/chains/definitions/sidra.ts +22 -0
- package/chains/definitions/songbird.ts +6 -0
- package/chains/definitions/wmcTestnet.ts +19 -0
- package/chains/index.ts +3 -0
- package/errors/version.ts +1 -1
- package/experimental/erc7821/actions/execute.ts +48 -36
- package/experimental/erc7821/actions/executeBatches.ts +254 -0
- package/experimental/erc7821/actions/supportsExecutionMode.ts +22 -9
- package/experimental/erc7821/constants.ts +2 -0
- package/experimental/erc7821/decorators/erc7821.ts +109 -0
- package/experimental/erc7821/index.ts +6 -1
- package/package.json +1 -1
- package/types/calls.ts +18 -0
@@ -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
|
-
|
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,
|
49
|
-
const mode =
|
55
|
+
const { address, mode: m = 'default' } = parameters
|
56
|
+
const mode = m.startsWith('0x') ? m : (toSerializedMode as any)[m]
|
50
57
|
try {
|
51
|
-
return await
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
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
|