viem 2.21.58 → 2.21.60
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 +18 -0
- package/_cjs/account-abstraction/actions/bundler/estimateUserOperationGas.js.map +1 -1
- package/_cjs/account-abstraction/actions/bundler/prepareUserOperation.js +1 -1
- package/_cjs/account-abstraction/actions/bundler/prepareUserOperation.js.map +1 -1
- package/_cjs/account-abstraction/actions/bundler/sendUserOperation.js.map +1 -1
- package/_cjs/account-abstraction/index.js.map +1 -1
- package/_cjs/account-abstraction/utils/errors/getUserOperationError.js.map +1 -1
- package/_cjs/actions/index.js +4 -2
- package/_cjs/actions/index.js.map +1 -1
- package/_cjs/actions/public/createAccessList.js +49 -0
- package/_cjs/actions/public/createAccessList.js.map +1 -0
- package/_cjs/clients/decorators/public.js +2 -0
- package/_cjs/clients/decorators/public.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/experimental/erc7821/actions/execute.js +78 -0
- package/_cjs/experimental/erc7821/actions/execute.js.map +1 -0
- package/_cjs/experimental/erc7821/actions/supportsExecutionMode.js +21 -0
- package/_cjs/experimental/erc7821/actions/supportsExecutionMode.js.map +1 -0
- package/_cjs/experimental/erc7821/constants.js +65 -0
- package/_cjs/experimental/erc7821/constants.js.map +1 -0
- package/_cjs/experimental/erc7821/decorators/erc7821.js +14 -0
- package/_cjs/experimental/erc7821/decorators/erc7821.js.map +1 -0
- package/_cjs/experimental/erc7821/errors.js +26 -0
- package/_cjs/experimental/erc7821/errors.js.map +1 -0
- package/_cjs/experimental/erc7821/index.js +13 -0
- package/_cjs/experimental/erc7821/index.js.map +1 -0
- package/_cjs/experimental/index.js +3 -1
- package/_cjs/experimental/index.js.map +1 -1
- package/_cjs/types/calls.js +3 -0
- package/_cjs/types/calls.js.map +1 -0
- package/_cjs/types/eip1193.js.map +1 -1
- package/_cjs/zksync/actions/deployContract.js +3 -1
- package/_cjs/zksync/actions/deployContract.js.map +1 -1
- package/_cjs/zksync/actions/getL1TokenAddress.js +21 -0
- package/_cjs/zksync/actions/getL1TokenAddress.js.map +1 -0
- package/_cjs/zksync/actions/getL2TokenAddress.js +25 -0
- package/_cjs/zksync/actions/getL2TokenAddress.js.map +1 -0
- package/_cjs/zksync/actions/sendEip712Transaction.js +3 -3
- package/_cjs/zksync/actions/sendEip712Transaction.js.map +1 -1
- package/_cjs/zksync/actions/signEip712Transaction.js +2 -2
- package/_cjs/zksync/actions/signEip712Transaction.js.map +1 -1
- package/_cjs/zksync/constants/abis.js +185 -1
- package/_cjs/zksync/constants/abis.js.map +1 -1
- package/_cjs/zksync/constants/address.js +2 -1
- package/_cjs/zksync/constants/address.js.map +1 -1
- package/_cjs/zksync/decorators/publicL2.js +4 -0
- package/_cjs/zksync/decorators/publicL2.js.map +1 -1
- package/_cjs/zksync/index.js +5 -1
- package/_cjs/zksync/index.js.map +1 -1
- package/_esm/account-abstraction/actions/bundler/estimateUserOperationGas.js.map +1 -1
- package/_esm/account-abstraction/actions/bundler/prepareUserOperation.js +1 -1
- package/_esm/account-abstraction/actions/bundler/prepareUserOperation.js.map +1 -1
- package/_esm/account-abstraction/actions/bundler/sendUserOperation.js.map +1 -1
- package/_esm/account-abstraction/index.js.map +1 -1
- package/_esm/account-abstraction/utils/errors/getUserOperationError.js.map +1 -1
- package/_esm/actions/index.js +1 -0
- package/_esm/actions/index.js.map +1 -1
- package/_esm/actions/public/createAccessList.js +72 -0
- package/_esm/actions/public/createAccessList.js.map +1 -0
- package/_esm/clients/decorators/public.js +2 -0
- package/_esm/clients/decorators/public.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/experimental/erc7821/actions/execute.js +143 -0
- package/_esm/experimental/erc7821/actions/execute.js.map +1 -0
- package/_esm/experimental/erc7821/actions/supportsExecutionMode.js +41 -0
- package/_esm/experimental/erc7821/actions/supportsExecutionMode.js.map +1 -0
- package/_esm/experimental/erc7821/constants.js +62 -0
- package/_esm/experimental/erc7821/constants.js.map +1 -0
- package/_esm/experimental/erc7821/decorators/erc7821.js +24 -0
- package/_esm/experimental/erc7821/decorators/erc7821.js.map +1 -0
- package/_esm/experimental/erc7821/errors.js +21 -0
- package/_esm/experimental/erc7821/errors.js.map +1 -0
- package/_esm/experimental/erc7821/index.js +7 -0
- package/_esm/experimental/erc7821/index.js.map +1 -0
- package/_esm/experimental/index.js +1 -0
- package/_esm/experimental/index.js.map +1 -1
- package/_esm/types/calls.js +2 -0
- package/_esm/types/calls.js.map +1 -0
- package/_esm/types/eip1193.js.map +1 -1
- package/_esm/zksync/actions/deployContract.js +5 -3
- package/_esm/zksync/actions/deployContract.js.map +1 -1
- package/_esm/zksync/actions/getL1TokenAddress.js +40 -0
- package/_esm/zksync/actions/getL1TokenAddress.js.map +1 -0
- package/_esm/zksync/actions/getL2TokenAddress.js +45 -0
- package/_esm/zksync/actions/getL2TokenAddress.js.map +1 -0
- package/_esm/zksync/actions/sendEip712Transaction.js +3 -3
- package/_esm/zksync/actions/sendEip712Transaction.js.map +1 -1
- package/_esm/zksync/actions/signEip712Transaction.js +4 -2
- package/_esm/zksync/actions/signEip712Transaction.js.map +1 -1
- package/_esm/zksync/constants/abis.js +184 -0
- package/_esm/zksync/constants/abis.js.map +1 -1
- package/_esm/zksync/constants/address.js +1 -0
- package/_esm/zksync/constants/address.js.map +1 -1
- package/_esm/zksync/decorators/publicL2.js +4 -0
- package/_esm/zksync/decorators/publicL2.js.map +1 -1
- package/_esm/zksync/index.js +2 -0
- package/_esm/zksync/index.js.map +1 -1
- package/_types/account-abstraction/actions/bundler/estimateUserOperationGas.d.ts +3 -2
- package/_types/account-abstraction/actions/bundler/estimateUserOperationGas.d.ts.map +1 -1
- package/_types/account-abstraction/actions/bundler/prepareUserOperation.d.ts +3 -2
- package/_types/account-abstraction/actions/bundler/prepareUserOperation.d.ts.map +1 -1
- package/_types/account-abstraction/actions/bundler/sendUserOperation.d.ts +3 -2
- package/_types/account-abstraction/actions/bundler/sendUserOperation.d.ts.map +1 -1
- package/_types/account-abstraction/index.d.ts +1 -1
- package/_types/account-abstraction/index.d.ts.map +1 -1
- package/_types/account-abstraction/types/userOperation.d.ts +2 -30
- package/_types/account-abstraction/types/userOperation.d.ts.map +1 -1
- package/_types/account-abstraction/utils/errors/getUserOperationError.d.ts.map +1 -1
- package/_types/actions/index.d.ts +1 -0
- package/_types/actions/index.d.ts.map +1 -1
- package/_types/actions/public/createAccessList.d.ts +61 -0
- package/_types/actions/public/createAccessList.d.ts.map +1 -0
- package/_types/clients/decorators/public.d.ts +25 -0
- package/_types/clients/decorators/public.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/experimental/erc7821/actions/execute.d.ts +94 -0
- package/_types/experimental/erc7821/actions/execute.d.ts.map +1 -0
- package/_types/experimental/erc7821/actions/supportsExecutionMode.d.ts +37 -0
- package/_types/experimental/erc7821/actions/supportsExecutionMode.d.ts.map +1 -0
- package/_types/experimental/erc7821/constants.d.ts +48 -0
- package/_types/experimental/erc7821/constants.d.ts.map +1 -0
- package/_types/experimental/erc7821/decorators/erc7821.d.ts +116 -0
- package/_types/experimental/erc7821/decorators/erc7821.d.ts.map +1 -0
- package/_types/experimental/erc7821/errors.d.ts +14 -0
- package/_types/experimental/erc7821/errors.d.ts.map +1 -0
- package/_types/experimental/erc7821/index.d.ts +6 -0
- package/_types/experimental/erc7821/index.d.ts.map +1 -0
- package/_types/experimental/index.d.ts +1 -0
- package/_types/experimental/index.d.ts.map +1 -1
- package/_types/types/calls.d.ts +14 -0
- package/_types/types/calls.d.ts.map +1 -0
- package/_types/types/eip1193.d.ts +19 -0
- package/_types/types/eip1193.d.ts.map +1 -1
- package/_types/zksync/actions/deployContract.d.ts +1 -1
- package/_types/zksync/actions/deployContract.d.ts.map +1 -1
- package/_types/zksync/actions/getL1TokenAddress.d.ts +34 -0
- package/_types/zksync/actions/getL1TokenAddress.d.ts.map +1 -0
- package/_types/zksync/actions/getL2TokenAddress.d.ts +37 -0
- package/_types/zksync/actions/getL2TokenAddress.d.ts.map +1 -0
- package/_types/zksync/actions/sendEip712Transaction.d.ts.map +1 -1
- package/_types/zksync/actions/signEip712Transaction.d.ts +2 -0
- package/_types/zksync/actions/signEip712Transaction.d.ts.map +1 -1
- package/_types/zksync/constants/abis.d.ts +143 -0
- package/_types/zksync/constants/abis.d.ts.map +1 -1
- package/_types/zksync/constants/address.d.ts +1 -0
- package/_types/zksync/constants/address.d.ts.map +1 -1
- package/_types/zksync/decorators/publicL2.d.ts +46 -0
- package/_types/zksync/decorators/publicL2.d.ts.map +1 -1
- package/_types/zksync/index.d.ts +2 -0
- package/_types/zksync/index.d.ts.map +1 -1
- package/account-abstraction/actions/bundler/estimateUserOperationGas.ts +2 -4
- package/account-abstraction/actions/bundler/prepareUserOperation.ts +6 -10
- package/account-abstraction/actions/bundler/sendUserOperation.ts +2 -4
- package/account-abstraction/index.ts +0 -2
- package/account-abstraction/types/userOperation.ts +2 -72
- package/account-abstraction/utils/errors/getUserOperationError.ts +10 -16
- package/actions/index.ts +6 -0
- package/actions/public/createAccessList.ts +159 -0
- package/clients/decorators/public.ts +32 -0
- package/errors/version.ts +1 -1
- package/experimental/erc7821/actions/execute.ts +232 -0
- package/experimental/erc7821/actions/supportsExecutionMode.ts +60 -0
- package/experimental/erc7821/constants.ts +62 -0
- package/experimental/erc7821/decorators/erc7821.ts +149 -0
- package/experimental/erc7821/errors.ts +29 -0
- package/experimental/erc7821/index.ts +23 -0
- package/experimental/index.ts +5 -0
- package/package.json +6 -1
- package/types/calls.ts +38 -0
- package/types/eip1193.ts +21 -0
- package/zksync/actions/deployContract.ts +9 -3
- package/zksync/actions/getL1TokenAddress.ts +59 -0
- package/zksync/actions/getL2TokenAddress.ts +70 -0
- package/zksync/actions/sendEip712Transaction.ts +5 -3
- package/zksync/actions/signEip712Transaction.ts +5 -2
- package/zksync/constants/abis.ts +185 -0
- package/zksync/constants/address.ts +3 -0
- package/zksync/decorators/publicL2.ts +62 -0
- package/zksync/index.ts +10 -0
@@ -12,8 +12,8 @@ import type { Client } from '../../../clients/createClient.js'
|
|
12
12
|
import type { Transport } from '../../../clients/transports/createTransport.js'
|
13
13
|
import { AccountNotFoundError } from '../../../errors/account.js'
|
14
14
|
import type { ErrorType } from '../../../errors/utils.js'
|
15
|
+
import type { Call, Calls } from '../../../types/calls.js'
|
15
16
|
import type { Chain } from '../../../types/chain.js'
|
16
|
-
import type { ContractFunctionParameters } from '../../../types/contract.js'
|
17
17
|
import type { Hex } from '../../../types/misc.js'
|
18
18
|
import type { StateOverride } from '../../../types/stateOverride.js'
|
19
19
|
import type {
|
@@ -42,8 +42,6 @@ import type {
|
|
42
42
|
} from '../../types/entryPointVersion.js'
|
43
43
|
import type {
|
44
44
|
UserOperation,
|
45
|
-
UserOperationCall,
|
46
|
-
UserOperationCalls,
|
47
45
|
UserOperationRequest,
|
48
46
|
} from '../../types/userOperation.js'
|
49
47
|
import {
|
@@ -154,7 +152,7 @@ export type PrepareUserOperationRequest<
|
|
154
152
|
EntryPointVersion = DeriveEntryPointVersion<_derivedAccount>,
|
155
153
|
> = Assign<
|
156
154
|
UserOperationRequest<_derivedVersion>,
|
157
|
-
OneOf<{ calls:
|
155
|
+
OneOf<{ calls: Calls<Narrow<calls>> } | { callData: Hex }> & {
|
158
156
|
parameters?: readonly PrepareUserOperationParameterType[] | undefined
|
159
157
|
paymaster?:
|
160
158
|
| Address
|
@@ -367,16 +365,14 @@ export async function prepareUserOperation<
|
|
367
365
|
if (parameters.calls)
|
368
366
|
return account.encodeCalls(
|
369
367
|
parameters.calls.map((call_) => {
|
370
|
-
const call = call_ as
|
371
|
-
|
372
|
-
| (ContractFunctionParameters & { to: Address; value: bigint })
|
373
|
-
if ('abi' in call)
|
368
|
+
const call = call_ as Call
|
369
|
+
if (call.abi)
|
374
370
|
return {
|
375
371
|
data: encodeFunctionData(call),
|
376
372
|
to: call.to,
|
377
373
|
value: call.value,
|
378
|
-
} as
|
379
|
-
return call as
|
374
|
+
} as Call
|
375
|
+
return call as Call
|
380
376
|
}),
|
381
377
|
)
|
382
378
|
return parameters.callData
|
@@ -5,6 +5,7 @@ import type { Transport } from '../../../clients/transports/createTransport.js'
|
|
5
5
|
import { AccountNotFoundError } from '../../../errors/account.js'
|
6
6
|
import type { BaseError } from '../../../errors/base.js'
|
7
7
|
import type { ErrorType } from '../../../errors/utils.js'
|
8
|
+
import type { Calls } from '../../../types/calls.js'
|
8
9
|
import type { Chain } from '../../../types/chain.js'
|
9
10
|
import type { Hex } from '../../../types/misc.js'
|
10
11
|
import type { Assign, MaybeRequired, OneOf } from '../../../types/utils.js'
|
@@ -22,7 +23,6 @@ import type {
|
|
22
23
|
} from '../../types/entryPointVersion.js'
|
23
24
|
import type {
|
24
25
|
UserOperation,
|
25
|
-
UserOperationCalls,
|
26
26
|
UserOperationRequest,
|
27
27
|
} from '../../types/userOperation.js'
|
28
28
|
import { getUserOperationError } from '../../utils/errors/getUserOperationError.js'
|
@@ -53,9 +53,7 @@ export type SendUserOperationParameters<
|
|
53
53
|
| Assign<
|
54
54
|
// Accept a partially-formed User Operation (UserOperationRequest) to be filled.
|
55
55
|
UserOperationRequest<_derivedVersion>,
|
56
|
-
OneOf<
|
57
|
-
{ calls: UserOperationCalls<Narrow<calls>> } | { callData: Hex }
|
58
|
-
> & {
|
56
|
+
OneOf<{ calls: Calls<Narrow<calls>> } | { callData: Hex }> & {
|
59
57
|
paymaster?:
|
60
58
|
| Address
|
61
59
|
| true
|
@@ -1,10 +1,8 @@
|
|
1
|
-
import type {
|
2
|
-
import type { ContractFunctionParameters } from '../../types/contract.js'
|
1
|
+
import type { Address } from 'abitype'
|
3
2
|
import type { Log } from '../../types/log.js'
|
4
3
|
import type { Hash, Hex } from '../../types/misc.js'
|
5
|
-
import type { GetMulticallContractParameters } from '../../types/multicall.js'
|
6
4
|
import type { TransactionReceipt } from '../../types/transaction.js'
|
7
|
-
import type { OneOf,
|
5
|
+
import type { OneOf, UnionPartialBy } from '../../types/utils.js'
|
8
6
|
import type { EntryPointVersion } from './entryPointVersion.js'
|
9
7
|
|
10
8
|
/** @link https://eips.ethereum.org/EIPS/eip-4337#-eth_estimateuseroperationgas */
|
@@ -192,71 +190,3 @@ export type UserOperationReceipt<
|
|
192
190
|
/** Hash of the user operation. */
|
193
191
|
userOpHash: Hash
|
194
192
|
}
|
195
|
-
|
196
|
-
export type UserOperationCall = {
|
197
|
-
to: Hex
|
198
|
-
data?: Hex | undefined
|
199
|
-
value?: bigint | undefined
|
200
|
-
}
|
201
|
-
|
202
|
-
export type UserOperationCalls<
|
203
|
-
calls extends readonly unknown[],
|
204
|
-
///
|
205
|
-
result extends readonly any[] = [],
|
206
|
-
> = calls extends readonly [] // no calls, return empty
|
207
|
-
? readonly []
|
208
|
-
: calls extends readonly [infer call] // one call left before returning `result`
|
209
|
-
? readonly [
|
210
|
-
...result,
|
211
|
-
Prettify<
|
212
|
-
OneOf<
|
213
|
-
| (Omit<
|
214
|
-
GetMulticallContractParameters<call, AbiStateMutability>,
|
215
|
-
'address'
|
216
|
-
> & {
|
217
|
-
to: Address
|
218
|
-
value?: bigint | undefined
|
219
|
-
})
|
220
|
-
| UserOperationCall
|
221
|
-
>
|
222
|
-
>,
|
223
|
-
]
|
224
|
-
: calls extends readonly [infer call, ...infer rest] // grab first call and recurse through `rest`
|
225
|
-
? UserOperationCalls<
|
226
|
-
[...rest],
|
227
|
-
[
|
228
|
-
...result,
|
229
|
-
Prettify<
|
230
|
-
OneOf<
|
231
|
-
| (Omit<
|
232
|
-
GetMulticallContractParameters<call, AbiStateMutability>,
|
233
|
-
'address'
|
234
|
-
> & {
|
235
|
-
to: Address
|
236
|
-
value?: bigint | undefined
|
237
|
-
})
|
238
|
-
| UserOperationCall
|
239
|
-
>
|
240
|
-
>,
|
241
|
-
]
|
242
|
-
>
|
243
|
-
: readonly unknown[] extends calls
|
244
|
-
? calls
|
245
|
-
: // If `calls` is *some* array but we couldn't assign `unknown[]` to it, then it must hold some known/homogenous type!
|
246
|
-
// use this to infer the param types in the case of Array.map() argument
|
247
|
-
calls extends readonly (infer call extends OneOf<
|
248
|
-
| (Omit<ContractFunctionParameters, 'address'> & {
|
249
|
-
to: Address
|
250
|
-
value?: bigint | undefined
|
251
|
-
})
|
252
|
-
| UserOperationCall
|
253
|
-
>)[]
|
254
|
-
? readonly Prettify<call>[]
|
255
|
-
: // Fallback
|
256
|
-
readonly OneOf<
|
257
|
-
| (Omit<ContractFunctionParameters, 'address'> & {
|
258
|
-
to: Address
|
259
|
-
value?: bigint | undefined
|
260
|
-
})
|
261
|
-
| UserOperationCall
|
262
|
-
>[]
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { Address } from 'abitype'
|
1
|
+
import type { Abi, Address } from 'abitype'
|
2
2
|
import { BaseError } from '../../../errors/base.js'
|
3
3
|
import {
|
4
4
|
ContractFunctionExecutionError,
|
@@ -6,9 +6,8 @@ import {
|
|
6
6
|
ContractFunctionZeroDataError,
|
7
7
|
} from '../../../errors/contract.js'
|
8
8
|
import type { ErrorType } from '../../../errors/utils.js'
|
9
|
-
import type {
|
9
|
+
import type { Call } from '../../../types/calls.js'
|
10
10
|
import type { Hex } from '../../../types/misc.js'
|
11
|
-
import type { OneOf } from '../../../types/utils.js'
|
12
11
|
import { decodeErrorResult } from '../../../utils/abi/decodeErrorResult.js'
|
13
12
|
import type { GetContractErrorReturnType } from '../../../utils/errors/getContractError.js'
|
14
13
|
import { ExecutionRevertedError } from '../../errors/bundler.js'
|
@@ -16,22 +15,12 @@ import {
|
|
16
15
|
UserOperationExecutionError,
|
17
16
|
type UserOperationExecutionErrorType,
|
18
17
|
} from '../../errors/userOperation.js'
|
19
|
-
import type {
|
20
|
-
UserOperation,
|
21
|
-
UserOperationCall,
|
22
|
-
} from '../../types/userOperation.js'
|
18
|
+
import type { UserOperation } from '../../types/userOperation.js'
|
23
19
|
import {
|
24
20
|
type GetBundlerErrorParameters,
|
25
21
|
getBundlerError,
|
26
22
|
} from './getBundlerError.js'
|
27
23
|
|
28
|
-
type Call = OneOf<
|
29
|
-
| UserOperationCall
|
30
|
-
| (ContractFunctionParameters & {
|
31
|
-
to: Address
|
32
|
-
})
|
33
|
-
>
|
34
|
-
|
35
24
|
type GetNodeErrorReturnType = ErrorType
|
36
25
|
|
37
26
|
export type GetUserOperationErrorParameters = UserOperation & {
|
@@ -106,7 +95,7 @@ function getContractError(parameters: {
|
|
106
95
|
const { abi, functionName, args, to } = (() => {
|
107
96
|
const contractCalls = calls?.filter((call) =>
|
108
97
|
Boolean(call.abi),
|
109
|
-
) as readonly
|
98
|
+
) as readonly Call[]
|
110
99
|
|
111
100
|
if (contractCalls.length === 1) return contractCalls[0]
|
112
101
|
|
@@ -133,7 +122,12 @@ function getContractError(parameters: {
|
|
133
122
|
args: undefined,
|
134
123
|
to: undefined,
|
135
124
|
}
|
136
|
-
})()
|
125
|
+
})() as {
|
126
|
+
abi: Abi
|
127
|
+
functionName: string
|
128
|
+
args: unknown[]
|
129
|
+
to: Address
|
130
|
+
}
|
137
131
|
|
138
132
|
const cause = (() => {
|
139
133
|
if (revertData === '0x')
|
package/actions/index.ts
CHANGED
@@ -46,6 +46,12 @@ export {
|
|
46
46
|
type CallReturnType,
|
47
47
|
call,
|
48
48
|
} from './public/call.js'
|
49
|
+
export {
|
50
|
+
type CreateAccessListErrorType,
|
51
|
+
type CreateAccessListParameters,
|
52
|
+
type CreateAccessListReturnType,
|
53
|
+
createAccessList,
|
54
|
+
} from './public/createAccessList.js'
|
49
55
|
export {
|
50
56
|
type CreateBlockFilterErrorType,
|
51
57
|
type CreateBlockFilterReturnType,
|
@@ -0,0 +1,159 @@
|
|
1
|
+
import type { Address } from 'abitype'
|
2
|
+
|
3
|
+
import type { Account } from '../../accounts/types.js'
|
4
|
+
import {
|
5
|
+
type ParseAccountErrorType,
|
6
|
+
parseAccount,
|
7
|
+
} from '../../accounts/utils/parseAccount.js'
|
8
|
+
import type { Client } from '../../clients/createClient.js'
|
9
|
+
import type { Transport } from '../../clients/transports/createTransport.js'
|
10
|
+
import type { ErrorType } from '../../errors/utils.js'
|
11
|
+
import type { BlockTag } from '../../types/block.js'
|
12
|
+
import type { Chain } from '../../types/chain.js'
|
13
|
+
import type { RpcTransactionRequest } from '../../types/rpc.js'
|
14
|
+
import type { AccessList, TransactionRequest } from '../../types/transaction.js'
|
15
|
+
import type { ExactPartial, UnionOmit } from '../../types/utils.js'
|
16
|
+
import type { RequestErrorType } from '../../utils/buildRequest.js'
|
17
|
+
import {
|
18
|
+
type NumberToHexErrorType,
|
19
|
+
numberToHex,
|
20
|
+
} from '../../utils/encoding/toHex.js'
|
21
|
+
import {
|
22
|
+
type GetCallErrorReturnType,
|
23
|
+
getCallError,
|
24
|
+
} from '../../utils/errors/getCallError.js'
|
25
|
+
import { extract } from '../../utils/formatters/extract.js'
|
26
|
+
import {
|
27
|
+
type FormatTransactionRequestErrorType,
|
28
|
+
type FormattedTransactionRequest,
|
29
|
+
formatTransactionRequest,
|
30
|
+
} from '../../utils/formatters/transactionRequest.js'
|
31
|
+
import { assertRequest } from '../../utils/transaction/assertRequest.js'
|
32
|
+
import type {
|
33
|
+
AssertRequestErrorType,
|
34
|
+
AssertRequestParameters,
|
35
|
+
} from '../../utils/transaction/assertRequest.js'
|
36
|
+
|
37
|
+
export type CreateAccessListParameters<
|
38
|
+
chain extends Chain | undefined = Chain | undefined,
|
39
|
+
> = UnionOmit<
|
40
|
+
FormattedTransactionRequest<chain>,
|
41
|
+
'from' | 'nonce' | 'accessList'
|
42
|
+
> & {
|
43
|
+
/** Account attached to the call (msg.sender). */
|
44
|
+
account?: Account | Address | undefined
|
45
|
+
} & (
|
46
|
+
| {
|
47
|
+
/** The balance of the account at a block number. */
|
48
|
+
blockNumber?: bigint | undefined
|
49
|
+
blockTag?: undefined
|
50
|
+
}
|
51
|
+
| {
|
52
|
+
blockNumber?: undefined
|
53
|
+
/**
|
54
|
+
* The balance of the account at a block tag.
|
55
|
+
* @default 'latest'
|
56
|
+
*/
|
57
|
+
blockTag?: BlockTag | undefined
|
58
|
+
}
|
59
|
+
)
|
60
|
+
|
61
|
+
export type CreateAccessListReturnType = {
|
62
|
+
accessList: AccessList
|
63
|
+
gasUsed: bigint
|
64
|
+
}
|
65
|
+
|
66
|
+
export type CreateAccessListErrorType = GetCallErrorReturnType<
|
67
|
+
| ParseAccountErrorType
|
68
|
+
| AssertRequestErrorType
|
69
|
+
| NumberToHexErrorType
|
70
|
+
| FormatTransactionRequestErrorType
|
71
|
+
| RequestErrorType
|
72
|
+
>
|
73
|
+
|
74
|
+
/**
|
75
|
+
* Creates an EIP-2930 access list.
|
76
|
+
*
|
77
|
+
* - Docs: https://viem.sh/docs/actions/public/createAccessList
|
78
|
+
* - JSON-RPC Methods: `eth_createAccessList`
|
79
|
+
*
|
80
|
+
* @param client - Client to use
|
81
|
+
* @param parameters - {@link CreateAccessListParameters}
|
82
|
+
* @returns The access list. {@link CreateAccessListReturnType}
|
83
|
+
*
|
84
|
+
* @example
|
85
|
+
* import { createPublicClient, http } from 'viem'
|
86
|
+
* import { mainnet } from 'viem/chains'
|
87
|
+
* import { createAccessList } from 'viem/public'
|
88
|
+
*
|
89
|
+
* const client = createPublicClient({
|
90
|
+
* chain: mainnet,
|
91
|
+
* transport: http(),
|
92
|
+
* })
|
93
|
+
* const data = await createAccessList(client, {
|
94
|
+
* account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
|
95
|
+
* data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
96
|
+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
97
|
+
* })
|
98
|
+
*/
|
99
|
+
export async function createAccessList<chain extends Chain | undefined>(
|
100
|
+
client: Client<Transport, chain>,
|
101
|
+
args: CreateAccessListParameters<chain>,
|
102
|
+
): Promise<CreateAccessListReturnType> {
|
103
|
+
const {
|
104
|
+
account: account_ = client.account,
|
105
|
+
blockNumber,
|
106
|
+
blockTag = 'latest',
|
107
|
+
blobs,
|
108
|
+
data,
|
109
|
+
gas,
|
110
|
+
gasPrice,
|
111
|
+
maxFeePerBlobGas,
|
112
|
+
maxFeePerGas,
|
113
|
+
maxPriorityFeePerGas,
|
114
|
+
to,
|
115
|
+
value,
|
116
|
+
...rest
|
117
|
+
} = args
|
118
|
+
const account = account_ ? parseAccount(account_) : undefined
|
119
|
+
|
120
|
+
try {
|
121
|
+
assertRequest(args as AssertRequestParameters)
|
122
|
+
|
123
|
+
const blockNumberHex = blockNumber ? numberToHex(blockNumber) : undefined
|
124
|
+
const block = blockNumberHex || blockTag
|
125
|
+
|
126
|
+
const chainFormat = client.chain?.formatters?.transactionRequest?.format
|
127
|
+
const format = chainFormat || formatTransactionRequest
|
128
|
+
|
129
|
+
const request = format({
|
130
|
+
// Pick out extra data that might exist on the chain's transaction request type.
|
131
|
+
...extract(rest, { format: chainFormat }),
|
132
|
+
from: account?.address,
|
133
|
+
blobs,
|
134
|
+
data,
|
135
|
+
gas,
|
136
|
+
gasPrice,
|
137
|
+
maxFeePerBlobGas,
|
138
|
+
maxFeePerGas,
|
139
|
+
maxPriorityFeePerGas,
|
140
|
+
to,
|
141
|
+
value,
|
142
|
+
} as TransactionRequest) as TransactionRequest
|
143
|
+
|
144
|
+
const response = await client.request({
|
145
|
+
method: 'eth_createAccessList',
|
146
|
+
params: [request as ExactPartial<RpcTransactionRequest>, block],
|
147
|
+
})
|
148
|
+
return {
|
149
|
+
accessList: response.accessList,
|
150
|
+
gasUsed: BigInt(response.gasUsed),
|
151
|
+
}
|
152
|
+
} catch (err) {
|
153
|
+
throw getCallError(err as ErrorType, {
|
154
|
+
...args,
|
155
|
+
account,
|
156
|
+
chain: client.chain,
|
157
|
+
})
|
158
|
+
}
|
159
|
+
}
|
@@ -30,6 +30,11 @@ import {
|
|
30
30
|
type CallReturnType,
|
31
31
|
call,
|
32
32
|
} from '../../actions/public/call.js'
|
33
|
+
import {
|
34
|
+
type CreateAccessListParameters,
|
35
|
+
type CreateAccessListReturnType,
|
36
|
+
createAccessList,
|
37
|
+
} from '../../actions/public/createAccessList.js'
|
33
38
|
import {
|
34
39
|
type CreateBlockFilterReturnType,
|
35
40
|
createBlockFilter,
|
@@ -285,6 +290,32 @@ export type PublicActions<
|
|
285
290
|
* })
|
286
291
|
*/
|
287
292
|
call: (parameters: CallParameters<chain>) => Promise<CallReturnType>
|
293
|
+
/**
|
294
|
+
* Creates an EIP-2930 access list that you can include in a transaction.
|
295
|
+
*
|
296
|
+
* - Docs: https://viem.sh/docs/actions/public/createAccessList
|
297
|
+
* - JSON-RPC Methods: `eth_createAccessList`
|
298
|
+
*
|
299
|
+
* @param args - {@link CreateAccessListParameters}
|
300
|
+
* @returns The call data. {@link CreateAccessListReturnType}
|
301
|
+
*
|
302
|
+
* @example
|
303
|
+
* import { createPublicClient, http } from 'viem'
|
304
|
+
* import { mainnet } from 'viem/chains'
|
305
|
+
*
|
306
|
+
* const client = createPublicClient({
|
307
|
+
* chain: mainnet,
|
308
|
+
* transport: http(),
|
309
|
+
* })
|
310
|
+
*
|
311
|
+
* const data = await client.createAccessList({
|
312
|
+
* data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
313
|
+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
314
|
+
* })
|
315
|
+
*/
|
316
|
+
createAccessList: (
|
317
|
+
parameters: CreateAccessListParameters<chain>,
|
318
|
+
) => Promise<CreateAccessListReturnType>
|
288
319
|
/**
|
289
320
|
* Creates a Filter to listen for new block hashes that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges).
|
290
321
|
*
|
@@ -1833,6 +1864,7 @@ export function publicActions<
|
|
1833
1864
|
): PublicActions<transport, chain, account> {
|
1834
1865
|
return {
|
1835
1866
|
call: (args) => call(client, args),
|
1867
|
+
createAccessList: (args) => createAccessList(client, args),
|
1836
1868
|
createBlockFilter: () => createBlockFilter(client),
|
1837
1869
|
createContractEventFilter: (args) =>
|
1838
1870
|
createContractEventFilter(client, args),
|
package/errors/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = '2.21.
|
1
|
+
export const version = '2.21.60'
|
@@ -0,0 +1,232 @@
|
|
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 { Call, Calls } 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 { abi, executionMode } from '../constants.js'
|
36
|
+
import {
|
37
|
+
ExecuteUnsupportedError,
|
38
|
+
FunctionSelectorNotRecognizedError,
|
39
|
+
} from '../errors.js'
|
40
|
+
import { supportsExecutionMode } from './supportsExecutionMode.js'
|
41
|
+
|
42
|
+
export type ExecuteParameters<
|
43
|
+
chain extends Chain | undefined = Chain | undefined,
|
44
|
+
account extends Account | undefined = Account | undefined,
|
45
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
46
|
+
calls extends readonly unknown[] = readonly unknown[],
|
47
|
+
_derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
|
48
|
+
> = UnionEvaluate<
|
49
|
+
UnionPick<
|
50
|
+
FormattedTransactionRequest<_derivedChain>,
|
51
|
+
| 'authorizationList'
|
52
|
+
| 'gas'
|
53
|
+
| 'gasPrice'
|
54
|
+
| 'maxFeePerGas'
|
55
|
+
| 'maxPriorityFeePerGas'
|
56
|
+
>
|
57
|
+
> &
|
58
|
+
GetAccountParameter<account, Account | Address, true, true> &
|
59
|
+
GetChainParameter<chain, chainOverride> & {
|
60
|
+
/** Address that will execute the calls. */
|
61
|
+
address: Address
|
62
|
+
/** Calls to execute. */
|
63
|
+
calls: Calls<Narrow<calls>>
|
64
|
+
/** Additional data to include for execution. */
|
65
|
+
opData?: Hex | undefined
|
66
|
+
}
|
67
|
+
|
68
|
+
export type ExecuteReturnType = Hex
|
69
|
+
|
70
|
+
export type ExecuteErrorType =
|
71
|
+
| DecodeErrorResultErrorType
|
72
|
+
| GetContractErrorReturnType
|
73
|
+
| EncodeFunctionDataErrorType
|
74
|
+
| SendTransactionErrorType
|
75
|
+
| ErrorType
|
76
|
+
|
77
|
+
/**
|
78
|
+
* Executes call(s) using the `execute` function on an [ERC-7821-compatible contract](https://eips.ethereum.org/EIPS/eip-7821).
|
79
|
+
*
|
80
|
+
* @example
|
81
|
+
* ```ts
|
82
|
+
* import { createClient, http } from 'viem'
|
83
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
84
|
+
* import { mainnet } from 'viem/chains'
|
85
|
+
* import { execute } from 'viem/experimental/erc7821'
|
86
|
+
*
|
87
|
+
* const account = privateKeyToAccount('0x...')
|
88
|
+
*
|
89
|
+
* const client = createClient({
|
90
|
+
* chain: mainnet,
|
91
|
+
* transport: http(),
|
92
|
+
* })
|
93
|
+
*
|
94
|
+
* const hash = await execute(client, {
|
95
|
+
* account,
|
96
|
+
* calls: [{
|
97
|
+
* {
|
98
|
+
* data: '0xdeadbeef',
|
99
|
+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
100
|
+
* },
|
101
|
+
* {
|
102
|
+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
103
|
+
* value: 69420n,
|
104
|
+
* },
|
105
|
+
* }],
|
106
|
+
* to: account.address,
|
107
|
+
* })
|
108
|
+
* ```
|
109
|
+
*
|
110
|
+
* @example
|
111
|
+
* ```ts
|
112
|
+
* // Account Hoisting
|
113
|
+
* import { createClient, http } from 'viem'
|
114
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
115
|
+
* import { mainnet } from 'viem/chains'
|
116
|
+
* import { execute } from 'viem/experimental/erc7821'
|
117
|
+
*
|
118
|
+
* const account = privateKeyToAccount('0x...')
|
119
|
+
*
|
120
|
+
* const client = createClient({
|
121
|
+
* account,
|
122
|
+
* chain: mainnet,
|
123
|
+
* transport: http(),
|
124
|
+
* })
|
125
|
+
*
|
126
|
+
* const hash = await execute(client, {
|
127
|
+
* calls: [{
|
128
|
+
* {
|
129
|
+
* data: '0xdeadbeef',
|
130
|
+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
131
|
+
* },
|
132
|
+
* {
|
133
|
+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
134
|
+
* value: 69420n,
|
135
|
+
* },
|
136
|
+
* }],
|
137
|
+
* to: account.address,
|
138
|
+
* })
|
139
|
+
* ```
|
140
|
+
*
|
141
|
+
* @param client - Client to use.
|
142
|
+
* @param parameters - {@link ExecuteParameters}
|
143
|
+
* @returns Transaction hash. {@link ExecuteReturnType}
|
144
|
+
*/
|
145
|
+
export async function execute<
|
146
|
+
const calls extends readonly unknown[],
|
147
|
+
chain extends Chain | undefined,
|
148
|
+
account extends Account | undefined,
|
149
|
+
chainOverride extends Chain | undefined = undefined,
|
150
|
+
>(
|
151
|
+
client: Client<Transport, chain, account>,
|
152
|
+
parameters: ExecuteParameters<chain, account, chainOverride, calls>,
|
153
|
+
): Promise<ExecuteReturnType> {
|
154
|
+
const { address, authorizationList, opData } = parameters
|
155
|
+
|
156
|
+
const calls = parameters.calls.map((call_) => {
|
157
|
+
const call = call_ as Call
|
158
|
+
return {
|
159
|
+
data: call.abi ? encodeFunctionData(call) : (call.data ?? '0x'),
|
160
|
+
value: call.value ?? 0n,
|
161
|
+
target: call.to,
|
162
|
+
}
|
163
|
+
})
|
164
|
+
const mode = opData ? executionMode.opData : executionMode.default
|
165
|
+
|
166
|
+
const encodedCalls = AbiParameters.encode(
|
167
|
+
AbiParameters.from([
|
168
|
+
'struct Call { address target; uint256 value; bytes data; }',
|
169
|
+
'Call[] calls',
|
170
|
+
...(opData ? ['bytes opData'] : []),
|
171
|
+
]),
|
172
|
+
[calls, ...(opData ? [opData] : [])] as any,
|
173
|
+
)
|
174
|
+
|
175
|
+
const supported = await supportsExecutionMode(client, {
|
176
|
+
address: authorizationList?.[0]?.contractAddress ?? address,
|
177
|
+
opData,
|
178
|
+
})
|
179
|
+
if (!supported) throw new ExecuteUnsupportedError()
|
180
|
+
|
181
|
+
try {
|
182
|
+
return await sendTransaction(client, {
|
183
|
+
...parameters,
|
184
|
+
to: address,
|
185
|
+
data: encodeFunctionData({
|
186
|
+
abi,
|
187
|
+
functionName: 'execute',
|
188
|
+
args: [mode, encodedCalls],
|
189
|
+
}),
|
190
|
+
} as any)
|
191
|
+
} catch (e) {
|
192
|
+
const error = (e as BaseError).walk((e) => 'data' in (e as Error)) as
|
193
|
+
| (BaseError & { data?: Hex | undefined })
|
194
|
+
| undefined
|
195
|
+
|
196
|
+
if (!error?.data) throw e
|
197
|
+
if (
|
198
|
+
error.data ===
|
199
|
+
AbiError.getSelector(AbiError.from('error FnSelectorNotRecognized()'))
|
200
|
+
)
|
201
|
+
throw new FunctionSelectorNotRecognizedError()
|
202
|
+
|
203
|
+
const matched = parameters.calls.find((call_) => {
|
204
|
+
const call = call_ as Call
|
205
|
+
if (!call.abi) return false
|
206
|
+
try {
|
207
|
+
return Boolean(
|
208
|
+
decodeErrorResult({
|
209
|
+
abi: call.abi,
|
210
|
+
data: error.data!,
|
211
|
+
}),
|
212
|
+
)
|
213
|
+
} catch {
|
214
|
+
return false
|
215
|
+
}
|
216
|
+
}) as {
|
217
|
+
abi: Abi
|
218
|
+
functionName: string
|
219
|
+
args: unknown[]
|
220
|
+
to: Address
|
221
|
+
} | null
|
222
|
+
if (!matched) throw e
|
223
|
+
|
224
|
+
throw getContractError(error as BaseError, {
|
225
|
+
abi: matched.abi,
|
226
|
+
address: matched.to,
|
227
|
+
args: matched.args,
|
228
|
+
docsPath: '/experimental/erc7821/execute',
|
229
|
+
functionName: matched.functionName,
|
230
|
+
})
|
231
|
+
}
|
232
|
+
}
|