Skip to content

Commit 5795c5b

Browse files
committed
chore: knip
1 parent d6388d7 commit 5795c5b

File tree

4 files changed

+148
-3
lines changed

4 files changed

+148
-3
lines changed

src/experimental/erc7821/actions/executeBatches.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ import {
4141
import { encodeCalls } from './execute.js'
4242
import { supportsExecutionMode } from './supportsExecutionMode.js'
4343

44-
type Batch = { calls: readonly unknown[]; opData?: Hex | undefined }
44+
/** @internal */
45+
export type Batch = { calls: readonly unknown[]; opData?: Hex | undefined }
4546

4647
export type ExecuteBatchesParameters<
4748
batches extends readonly Batch[] = readonly Batch[],

src/experimental/erc7821/decorators/erc7821.test.ts

+31-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { anvilMainnet } from '../../../../test/src/anvil.js'
55
import { accounts } from '../../../../test/src/constants.js'
66
import { deploy } from '../../../../test/src/utils.js'
77
import { privateKeyToAccount } from '../../../accounts/privateKeyToAccount.js'
8+
import { mine } from '../../../actions/index.js'
89
import { signAuthorization } from '../../eip7702/actions/signAuthorization.js'
910
import { erc7821Actions } from './erc7821.js'
1011

@@ -16,13 +17,15 @@ test('default', async () => {
1617
expect(erc7821Actions()(client)).toMatchInlineSnapshot(`
1718
{
1819
"execute": [Function],
20+
"executeBatches": [Function],
1921
"supportsExecutionMode": [Function],
2022
}
2123
`)
2224
})
2325

2426
describe('smoke test', () => {
2527
test('execute', async () => {
28+
await mine(client, { blocks: 1 })
2629
const { contractAddress } = await deploy(client, {
2730
abi: ERC7821Example.abi,
2831
bytecode: ERC7821Example.bytecode.object,
@@ -44,11 +47,38 @@ describe('smoke test', () => {
4447
})
4548
})
4649

50+
test('executeBatches', async () => {
51+
await mine(client, { blocks: 1 })
52+
const { contractAddress } = await deploy(client, {
53+
abi: ERC7821Example.abi,
54+
bytecode: ERC7821Example.bytecode.object,
55+
})
56+
57+
const authorization = await signAuthorization(client, {
58+
contractAddress: contractAddress!,
59+
})
60+
await client.executeBatches({
61+
authorizationList: [authorization],
62+
address: client.account.address,
63+
batches: [
64+
{
65+
calls: [
66+
{
67+
to: '0x0000000000000000000000000000000000000000',
68+
data: '0x',
69+
value: 0n,
70+
},
71+
],
72+
},
73+
],
74+
})
75+
})
76+
4777
test('supportsExecutionMode', async () => {
4878
expect(
4979
await client.supportsExecutionMode({
5080
address: client.account.address,
5181
}),
52-
).toBe(false)
82+
).toBe(true)
5383
})
5484
})

src/experimental/erc7821/decorators/erc7821.ts

+109
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import {
77
type ExecuteReturnType,
88
execute,
99
} from '../actions/execute.js'
10+
import {
11+
type Batch,
12+
type ExecuteBatchesParameters,
13+
type ExecuteBatchesReturnType,
14+
executeBatches,
15+
} from '../actions/executeBatches.js'
1016
import {
1117
type SupportsExecutionModeParameters,
1218
type SupportsExecutionModeReturnType,
@@ -91,6 +97,108 @@ export type Erc7821Actions<
9197
>(
9298
parameters: ExecuteParameters<calls, chain, account, chainOverride>,
9399
) => 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>
94202
/**
95203
* Checks if the contract supports the ERC-7821 execution mode.
96204
*
@@ -142,6 +250,7 @@ export function erc7821Actions() {
142250
): Erc7821Actions<chain, account> => {
143251
return {
144252
execute: (parameters) => execute(client, parameters),
253+
executeBatches: (parameters) => executeBatches(client, parameters),
145254
supportsExecutionMode: (parameters) =>
146255
supportsExecutionMode(client, parameters),
147256
}

src/experimental/erc7821/index.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
/** */
21
// biome-ignore lint/performance/noBarrelFile: entrypoint
32
export {
43
type ExecuteErrorType,
54
type ExecuteParameters,
65
type ExecuteReturnType,
76
execute,
87
} from './actions/execute.js'
8+
export {
9+
type ExecuteBatchesErrorType,
10+
type ExecuteBatchesParameters,
11+
type ExecuteBatchesReturnType,
12+
executeBatches,
13+
} from './actions/executeBatches.js'
914
export {
1015
type SupportsExecutionModeErrorType,
1116
type SupportsExecutionModeParameters,

0 commit comments

Comments
 (0)