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
@@ -0,0 +1,60 @@
|
|
1
|
+
import type { Address } from '../../../accounts/index.js'
|
2
|
+
import { readContract } from '../../../actions/public/readContract.js'
|
3
|
+
import type { Client } from '../../../clients/createClient.js'
|
4
|
+
import type { Transport } from '../../../clients/transports/createTransport.js'
|
5
|
+
import type { ErrorType } from '../../../errors/utils.js'
|
6
|
+
import type { Chain } from '../../../types/chain.js'
|
7
|
+
import type { Hex } from '../../../types/misc.js'
|
8
|
+
import { abi, executionMode } from '../constants.js'
|
9
|
+
|
10
|
+
export type SupportsExecutionModeParameters = {
|
11
|
+
address: Address
|
12
|
+
opData?: Hex | undefined
|
13
|
+
}
|
14
|
+
|
15
|
+
export type SupportsExecutionModeReturnType = boolean
|
16
|
+
|
17
|
+
export type SupportsExecutionModeErrorType = ErrorType
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Checks if the contract supports the ERC-7821 execution mode.
|
21
|
+
*
|
22
|
+
* @example
|
23
|
+
* ```ts
|
24
|
+
* import { createClient, http } from 'viem'
|
25
|
+
* import { mainnet } from 'viem/chains'
|
26
|
+
* import { supportsExecutionMode } from 'viem/experimental/erc7821'
|
27
|
+
*
|
28
|
+
* const client = createClient({
|
29
|
+
* chain: mainnet,
|
30
|
+
* transport: http(),
|
31
|
+
* })
|
32
|
+
*
|
33
|
+
* const supported = await supportsExecutionMode(client, {
|
34
|
+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
35
|
+
* })
|
36
|
+
* ```
|
37
|
+
*
|
38
|
+
* @param client - Client to use.
|
39
|
+
* @param parameters - {@link SupportsExecutionModeParameters}
|
40
|
+
* @returns If the execution mode is supported. {@link SupportsExecutionModeReturnType}
|
41
|
+
*/
|
42
|
+
export async function supportsExecutionMode<
|
43
|
+
chain extends Chain | undefined = Chain | undefined,
|
44
|
+
>(
|
45
|
+
client: Client<Transport, chain>,
|
46
|
+
parameters: SupportsExecutionModeParameters,
|
47
|
+
): Promise<SupportsExecutionModeReturnType> {
|
48
|
+
const { address, opData } = parameters
|
49
|
+
const mode = opData ? executionMode.opData : executionMode.default
|
50
|
+
try {
|
51
|
+
return await readContract(client, {
|
52
|
+
abi,
|
53
|
+
address,
|
54
|
+
functionName: 'supportsExecutionMode',
|
55
|
+
args: [mode],
|
56
|
+
})
|
57
|
+
} catch {
|
58
|
+
return false
|
59
|
+
}
|
60
|
+
}
|
@@ -0,0 +1,62 @@
|
|
1
|
+
export const abi = [
|
2
|
+
{
|
3
|
+
type: 'fallback',
|
4
|
+
stateMutability: 'payable',
|
5
|
+
},
|
6
|
+
{
|
7
|
+
type: 'receive',
|
8
|
+
stateMutability: 'payable',
|
9
|
+
},
|
10
|
+
{
|
11
|
+
type: 'function',
|
12
|
+
name: 'execute',
|
13
|
+
inputs: [
|
14
|
+
{
|
15
|
+
name: 'mode',
|
16
|
+
type: 'bytes32',
|
17
|
+
internalType: 'bytes32',
|
18
|
+
},
|
19
|
+
{
|
20
|
+
name: 'executionData',
|
21
|
+
type: 'bytes',
|
22
|
+
internalType: 'bytes',
|
23
|
+
},
|
24
|
+
],
|
25
|
+
outputs: [],
|
26
|
+
stateMutability: 'payable',
|
27
|
+
},
|
28
|
+
{
|
29
|
+
type: 'function',
|
30
|
+
name: 'supportsExecutionMode',
|
31
|
+
inputs: [
|
32
|
+
{
|
33
|
+
name: 'mode',
|
34
|
+
type: 'bytes32',
|
35
|
+
internalType: 'bytes32',
|
36
|
+
},
|
37
|
+
],
|
38
|
+
outputs: [
|
39
|
+
{
|
40
|
+
name: 'result',
|
41
|
+
type: 'bool',
|
42
|
+
internalType: 'bool',
|
43
|
+
},
|
44
|
+
],
|
45
|
+
stateMutability: 'view',
|
46
|
+
},
|
47
|
+
{
|
48
|
+
type: 'error',
|
49
|
+
name: 'FnSelectorNotRecognized',
|
50
|
+
inputs: [],
|
51
|
+
},
|
52
|
+
{
|
53
|
+
type: 'error',
|
54
|
+
name: 'UnsupportedExecutionMode',
|
55
|
+
inputs: [],
|
56
|
+
},
|
57
|
+
] as const
|
58
|
+
|
59
|
+
export const executionMode = {
|
60
|
+
default: '0x0100000000000000000000000000000000000000000000000000000000000000',
|
61
|
+
opData: '0x0100000000007821000100000000000000000000000000000000000000000000',
|
62
|
+
} as const
|
@@ -0,0 +1,149 @@
|
|
1
|
+
import type { Client } from '../../../clients/createClient.js'
|
2
|
+
import type { Transport } from '../../../clients/transports/createTransport.js'
|
3
|
+
import type { Account } from '../../../types/account.js'
|
4
|
+
import type { Chain } from '../../../types/chain.js'
|
5
|
+
import {
|
6
|
+
type ExecuteParameters,
|
7
|
+
type ExecuteReturnType,
|
8
|
+
execute,
|
9
|
+
} from '../actions/execute.js'
|
10
|
+
import {
|
11
|
+
type SupportsExecutionModeParameters,
|
12
|
+
type SupportsExecutionModeReturnType,
|
13
|
+
supportsExecutionMode,
|
14
|
+
} from '../actions/supportsExecutionMode.js'
|
15
|
+
|
16
|
+
export type Erc7821Actions<
|
17
|
+
chain extends Chain | undefined = Chain | undefined,
|
18
|
+
account extends Account | undefined = Account | undefined,
|
19
|
+
> = {
|
20
|
+
/**
|
21
|
+
* Executes call(s) using the `execute` function on an [ERC-7821-compatible contract](https://eips.ethereum.org/EIPS/eip-7821).
|
22
|
+
*
|
23
|
+
* @example
|
24
|
+
* ```ts
|
25
|
+
* import { createClient, http } from 'viem'
|
26
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
27
|
+
* import { mainnet } from 'viem/chains'
|
28
|
+
* import { erc7821Actions } from 'viem/experimental'
|
29
|
+
*
|
30
|
+
* const account = privateKeyToAccount('0x...')
|
31
|
+
*
|
32
|
+
* const client = createClient({
|
33
|
+
* chain: mainnet,
|
34
|
+
* transport: http(),
|
35
|
+
* }).extend(erc7821Actions())
|
36
|
+
*
|
37
|
+
* const hash = await client.execute({
|
38
|
+
* account,
|
39
|
+
* calls: [{
|
40
|
+
* {
|
41
|
+
* data: '0xdeadbeef',
|
42
|
+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
43
|
+
* },
|
44
|
+
* {
|
45
|
+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
46
|
+
* value: 69420n,
|
47
|
+
* },
|
48
|
+
* }],
|
49
|
+
* to: account.address,
|
50
|
+
* })
|
51
|
+
* ```
|
52
|
+
*
|
53
|
+
* @example
|
54
|
+
* ```ts
|
55
|
+
* // Account Hoisting
|
56
|
+
* import { createClient, http } from 'viem'
|
57
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
58
|
+
* import { mainnet } from 'viem/chains'
|
59
|
+
* import { erc7821Actions } from 'viem/experimental'
|
60
|
+
*
|
61
|
+
* const account = privateKeyToAccount('0x...')
|
62
|
+
*
|
63
|
+
* const client = createClient({
|
64
|
+
* account,
|
65
|
+
* chain: mainnet,
|
66
|
+
* transport: http(),
|
67
|
+
* }).extend(erc7821Actions())
|
68
|
+
*
|
69
|
+
* const hash = await client.execute({
|
70
|
+
* calls: [{
|
71
|
+
* {
|
72
|
+
* data: '0xdeadbeef',
|
73
|
+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
74
|
+
* },
|
75
|
+
* {
|
76
|
+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
77
|
+
* value: 69420n,
|
78
|
+
* },
|
79
|
+
* }],
|
80
|
+
* to: account.address,
|
81
|
+
* })
|
82
|
+
* ```
|
83
|
+
*
|
84
|
+
* @param client - Client to use.
|
85
|
+
* @param parameters - {@link ExecuteParameters}
|
86
|
+
* @returns Transaction hash. {@link ExecuteReturnType}
|
87
|
+
*/
|
88
|
+
execute: <
|
89
|
+
const calls extends readonly unknown[],
|
90
|
+
chainOverride extends Chain | undefined = undefined,
|
91
|
+
>(
|
92
|
+
parameters: ExecuteParameters<chain, account, chainOverride, calls>,
|
93
|
+
) => Promise<ExecuteReturnType>
|
94
|
+
/**
|
95
|
+
* Checks if the contract supports the ERC-7821 execution mode.
|
96
|
+
*
|
97
|
+
* @example
|
98
|
+
* ```ts
|
99
|
+
* import { createClient, http } from 'viem'
|
100
|
+
* import { mainnet } from 'viem/chains'
|
101
|
+
* import { erc7821Actions } from 'viem/experimental'
|
102
|
+
*
|
103
|
+
* const client = createClient({
|
104
|
+
* chain: mainnet,
|
105
|
+
* transport: http(),
|
106
|
+
* }).extend(erc7821Actions())
|
107
|
+
*
|
108
|
+
* const supported = await supportsExecutionMode(client, {
|
109
|
+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
110
|
+
* })
|
111
|
+
* ```
|
112
|
+
*
|
113
|
+
* @param client - Client to use.
|
114
|
+
* @param parameters - {@link SupportsExecutionModeParameters}
|
115
|
+
* @returns If the execution mode is supported. {@link SupportsExecutionModeReturnType}
|
116
|
+
*/
|
117
|
+
supportsExecutionMode: (
|
118
|
+
parameters: SupportsExecutionModeParameters,
|
119
|
+
) => Promise<SupportsExecutionModeReturnType>
|
120
|
+
}
|
121
|
+
|
122
|
+
/**
|
123
|
+
* A suite of Actions for [ERC-7821](https://eips.ethereum.org/EIPS/eip-7821).
|
124
|
+
*
|
125
|
+
* @example
|
126
|
+
* import { createClient, http } from 'viem'
|
127
|
+
* import { mainnet } from 'viem/chains'
|
128
|
+
* import { erc7821Actions } from 'viem/experimental'
|
129
|
+
*
|
130
|
+
* const client = createClient({
|
131
|
+
* chain: mainnet,
|
132
|
+
* transport: http(),
|
133
|
+
* }).extend(erc7821Actions())
|
134
|
+
*/
|
135
|
+
export function erc7821Actions() {
|
136
|
+
return <
|
137
|
+
transport extends Transport,
|
138
|
+
chain extends Chain | undefined = Chain | undefined,
|
139
|
+
account extends Account | undefined = Account | undefined,
|
140
|
+
>(
|
141
|
+
client: Client<transport, chain, account>,
|
142
|
+
): Erc7821Actions<chain, account> => {
|
143
|
+
return {
|
144
|
+
execute: (parameters) => execute(client, parameters),
|
145
|
+
supportsExecutionMode: (parameters) =>
|
146
|
+
supportsExecutionMode(client, parameters),
|
147
|
+
}
|
148
|
+
}
|
149
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { BaseError } from '../../errors/base.js'
|
2
|
+
|
3
|
+
export type ExecuteUnsupportedErrorType = ExecuteUnsupportedError & {
|
4
|
+
name: 'ExecuteUnsupportedError'
|
5
|
+
}
|
6
|
+
export class ExecuteUnsupportedError extends BaseError {
|
7
|
+
constructor() {
|
8
|
+
super('ERC-7821 execution is not supported.', {
|
9
|
+
name: 'ExecuteUnsupportedError',
|
10
|
+
})
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
export type FunctionSelectorNotRecognizedErrorType =
|
15
|
+
FunctionSelectorNotRecognizedError & {
|
16
|
+
name: 'FunctionSelectorNotRecognizedError'
|
17
|
+
}
|
18
|
+
export class FunctionSelectorNotRecognizedError extends BaseError {
|
19
|
+
constructor() {
|
20
|
+
super('Function is not recognized.', {
|
21
|
+
metaMessages: [
|
22
|
+
'This could be due to any of the following:',
|
23
|
+
' - The contract does not have the function,',
|
24
|
+
' - The address is not a contract.',
|
25
|
+
],
|
26
|
+
name: 'FunctionSelectorNotRecognizedError',
|
27
|
+
})
|
28
|
+
}
|
29
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/** */
|
2
|
+
// biome-ignore lint/performance/noBarrelFile: entrypoint
|
3
|
+
export {
|
4
|
+
type ExecuteErrorType,
|
5
|
+
type ExecuteParameters,
|
6
|
+
type ExecuteReturnType,
|
7
|
+
execute,
|
8
|
+
} from './actions/execute.js'
|
9
|
+
export {
|
10
|
+
type SupportsExecutionModeErrorType,
|
11
|
+
type SupportsExecutionModeParameters,
|
12
|
+
type SupportsExecutionModeReturnType,
|
13
|
+
supportsExecutionMode,
|
14
|
+
} from './actions/supportsExecutionMode.js'
|
15
|
+
|
16
|
+
export {
|
17
|
+
ExecuteUnsupportedError,
|
18
|
+
type ExecuteUnsupportedErrorType,
|
19
|
+
FunctionSelectorNotRecognizedError,
|
20
|
+
type FunctionSelectorNotRecognizedErrorType,
|
21
|
+
} from './errors.js'
|
22
|
+
|
23
|
+
export { type Erc7821Actions, erc7821Actions } from './decorators/erc7821.js'
|
package/experimental/index.ts
CHANGED
@@ -111,6 +111,11 @@ export {
|
|
111
111
|
erc7739Actions,
|
112
112
|
} from './erc7739/decorators/erc7739.js'
|
113
113
|
|
114
|
+
export {
|
115
|
+
type Erc7821Actions,
|
116
|
+
erc7821Actions,
|
117
|
+
} from './erc7821/decorators/erc7821.js'
|
118
|
+
|
114
119
|
export {
|
115
120
|
/** @deprecated This is no longer experimental – use `import type { ParseErc6492SignatureErrorType } from 'viem'` instead. */
|
116
121
|
type ParseErc6492SignatureErrorType,
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "viem",
|
3
3
|
"description": "TypeScript Interface for Ethereum",
|
4
|
-
"version": "2.21.
|
4
|
+
"version": "2.21.60",
|
5
5
|
"main": "./_cjs/index.js",
|
6
6
|
"module": "./_esm/index.js",
|
7
7
|
"types": "./_types/index.d.ts",
|
@@ -69,6 +69,11 @@
|
|
69
69
|
"import": "./_esm/experimental/erc7739/index.js",
|
70
70
|
"default": "./_cjs/experimental/erc7739/index.js"
|
71
71
|
},
|
72
|
+
"./experimental/erc7821": {
|
73
|
+
"types": "./_types/experimental/erc7821/index.d.ts",
|
74
|
+
"import": "./_esm/experimental/erc7821/index.js",
|
75
|
+
"default": "./_cjs/experimental/erc7821/index.js"
|
76
|
+
},
|
72
77
|
"./linea": {
|
73
78
|
"types": "./_types/linea/index.d.ts",
|
74
79
|
"import": "./_esm/linea/index.js",
|
package/types/calls.ts
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
import type { AbiStateMutability, Address } from 'abitype'
|
2
|
+
import type { Hex } from './misc.js'
|
3
|
+
import type { GetMulticallContractParameters } from './multicall.js'
|
4
|
+
import type { OneOf, Prettify } from './utils.js'
|
5
|
+
|
6
|
+
export type Call<call = unknown> = OneOf<
|
7
|
+
| {
|
8
|
+
data?: Hex | undefined
|
9
|
+
to: Address
|
10
|
+
value?: bigint | undefined
|
11
|
+
}
|
12
|
+
| (Omit<
|
13
|
+
GetMulticallContractParameters<call, AbiStateMutability>,
|
14
|
+
'address'
|
15
|
+
> & {
|
16
|
+
to: Address
|
17
|
+
value?: bigint | undefined
|
18
|
+
})
|
19
|
+
>
|
20
|
+
|
21
|
+
export type Calls<
|
22
|
+
calls extends readonly unknown[],
|
23
|
+
///
|
24
|
+
result extends readonly any[] = [],
|
25
|
+
> = calls extends readonly [] // no calls, return empty
|
26
|
+
? readonly []
|
27
|
+
: calls extends readonly [infer call] // one call left before returning `result`
|
28
|
+
? readonly [...result, Prettify<Call<call>>]
|
29
|
+
: calls extends readonly [infer call, ...infer rest] // grab first call and recurse through `rest`
|
30
|
+
? Calls<[...rest], [...result, Prettify<Call<call>>]>
|
31
|
+
: readonly unknown[] extends calls
|
32
|
+
? calls
|
33
|
+
: // If `calls` is *some* array but we couldn't assign `unknown[]` to it, then it must hold some known/homogenous type!
|
34
|
+
// use this to infer the param types in the case of Array.map() argument
|
35
|
+
calls extends readonly (infer call extends OneOf<Call>)[]
|
36
|
+
? readonly Prettify<call>[]
|
37
|
+
: // Fallback
|
38
|
+
readonly OneOf<Call>[]
|
package/types/eip1193.ts
CHANGED
@@ -22,6 +22,7 @@ import type {
|
|
22
22
|
RpcTransactionRequest as TransactionRequest,
|
23
23
|
RpcUncle as Uncle,
|
24
24
|
} from './rpc.js'
|
25
|
+
import type { AccessList } from './transaction.js'
|
25
26
|
import type { ExactPartial, OneOf, PartialBy, Prettify } from './utils.js'
|
26
27
|
|
27
28
|
//////////////////////////////////////////////////
|
@@ -644,6 +645,26 @@ export type PublicRpcSchema = [
|
|
644
645
|
]
|
645
646
|
ReturnType: Hex
|
646
647
|
},
|
648
|
+
/**
|
649
|
+
* @description Executes a new message call immediately without submitting a transaction to the network
|
650
|
+
*
|
651
|
+
* @example
|
652
|
+
* provider.request({ method: 'eth_call', params: [{ to: '0x...', data: '0x...' }] })
|
653
|
+
* // => '0x...'
|
654
|
+
*/
|
655
|
+
{
|
656
|
+
Method: 'eth_createAccessList'
|
657
|
+
Parameters:
|
658
|
+
| [transaction: ExactPartial<TransactionRequest>]
|
659
|
+
| [
|
660
|
+
transaction: ExactPartial<TransactionRequest>,
|
661
|
+
block: BlockNumber | BlockTag | BlockIdentifier,
|
662
|
+
]
|
663
|
+
ReturnType: {
|
664
|
+
accessList: AccessList
|
665
|
+
gasUsed: Quantity
|
666
|
+
}
|
667
|
+
},
|
647
668
|
/**
|
648
669
|
* @description Returns the chain ID associated with the current network
|
649
670
|
* @example
|
@@ -7,7 +7,10 @@ import type { Transport } from '../../clients/transports/createTransport.js'
|
|
7
7
|
import type { ErrorType } from '../../errors/utils.js'
|
8
8
|
import type { ContractConstructorArgs } from '../../types/contract.js'
|
9
9
|
import type { Hash, Hex } from '../../types/misc.js'
|
10
|
-
import {
|
10
|
+
import {
|
11
|
+
contract2FactoryAddress,
|
12
|
+
contractDeployerAddress,
|
13
|
+
} from '../constants/address.js'
|
11
14
|
import type { ChainEIP712 } from '../types/chain.js'
|
12
15
|
import type { ContractDeploymentType } from '../types/contract.js'
|
13
16
|
import {
|
@@ -45,7 +48,7 @@ export type DeployContractErrorType =
|
|
45
48
|
*
|
46
49
|
* - Docs: https://viem.sh/docs/contract/deployContract
|
47
50
|
*
|
48
|
-
* @param
|
51
|
+
* @param walletClient - Client to use
|
49
52
|
* @param parameters - {@link DeployContractParameters}
|
50
53
|
* @returns The [Transaction](https://viem.sh/docs/glossary/terms#transaction) hash. {@link DeployContractReturnType}
|
51
54
|
*
|
@@ -97,7 +100,10 @@ export function deployContract<
|
|
97
100
|
return sendEip712Transaction(walletClient, {
|
98
101
|
...request,
|
99
102
|
data,
|
100
|
-
to:
|
103
|
+
to:
|
104
|
+
deploymentType === 'create2' || deploymentType === 'create2Account'
|
105
|
+
? contract2FactoryAddress
|
106
|
+
: contractDeployerAddress,
|
101
107
|
} as unknown as SendEip712TransactionParameters<
|
102
108
|
chain,
|
103
109
|
account,
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import type { Address } from '../../accounts/index.js'
|
2
|
+
import { readContract } from '../../actions/public/readContract.js'
|
3
|
+
import type { Client } from '../../clients/createClient.js'
|
4
|
+
import type { Transport } from '../../clients/transports/createTransport.js'
|
5
|
+
import type { Account } from '../../types/account.js'
|
6
|
+
import type { Chain } from '../../types/chain.js'
|
7
|
+
import { isAddressEqual } from '../../utils/index.js'
|
8
|
+
import { l2SharedBridgeAbi } from '../constants/abis.js'
|
9
|
+
import { legacyEthAddress } from '../constants/address.js'
|
10
|
+
import { getDefaultBridgeAddresses } from './getDefaultBridgeAddresses.js'
|
11
|
+
|
12
|
+
export type GetL1TokenAddressParameters = {
|
13
|
+
/** The address of the token on L2. */
|
14
|
+
token: Address
|
15
|
+
}
|
16
|
+
|
17
|
+
export type GetL1TokenAddressReturnType = Address
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Returns the L1 token address equivalent for a L2 token address as they are not equal.
|
21
|
+
* ETH address is set to zero address.
|
22
|
+
*
|
23
|
+
* @remarks Only works for tokens bridged on default ZKsync Era bridges.
|
24
|
+
*
|
25
|
+
* @param client - Client to use
|
26
|
+
* @param parameters - {@link GetL1TokenAddressParameters}
|
27
|
+
* @returns The L1 token address equivalent for a L2 token address.
|
28
|
+
*
|
29
|
+
*
|
30
|
+
* @example
|
31
|
+
* import { createPublicClient, http } from 'viem'
|
32
|
+
* import { zksync } from 'viem/chains'
|
33
|
+
*
|
34
|
+
* const client = createPublicClient({
|
35
|
+
* chain: zksync,
|
36
|
+
* transport: http(),
|
37
|
+
* })
|
38
|
+
*
|
39
|
+
* const address = await getL1TokenAddress(client, {token: '0x...'});
|
40
|
+
*/
|
41
|
+
export async function getL1TokenAddress<
|
42
|
+
chain extends Chain | undefined,
|
43
|
+
account extends Account | undefined,
|
44
|
+
>(
|
45
|
+
client: Client<Transport, chain, account>,
|
46
|
+
parameters: GetL1TokenAddressParameters,
|
47
|
+
): Promise<Address> {
|
48
|
+
const { token } = parameters
|
49
|
+
if (isAddressEqual(token, legacyEthAddress)) return legacyEthAddress
|
50
|
+
|
51
|
+
const bridgeAddress = (await getDefaultBridgeAddresses(client)).sharedL2
|
52
|
+
|
53
|
+
return await readContract(client, {
|
54
|
+
address: bridgeAddress,
|
55
|
+
abi: l2SharedBridgeAbi,
|
56
|
+
functionName: 'l1TokenAddress',
|
57
|
+
args: [token],
|
58
|
+
})
|
59
|
+
}
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import type { Address } from '../../accounts/index.js'
|
2
|
+
import { readContract } from '../../actions/public/readContract.js'
|
3
|
+
import type { Client } from '../../clients/createClient.js'
|
4
|
+
import type { Transport } from '../../clients/transports/createTransport.js'
|
5
|
+
import type { Account } from '../../types/account.js'
|
6
|
+
import type { Chain } from '../../types/chain.js'
|
7
|
+
import { isAddressEqual } from '../../utils/index.js'
|
8
|
+
import { l2SharedBridgeAbi } from '../constants/abis.js'
|
9
|
+
import {
|
10
|
+
ethAddressInContracts,
|
11
|
+
l2BaseTokenAddress,
|
12
|
+
legacyEthAddress,
|
13
|
+
} from '../constants/address.js'
|
14
|
+
import { getBaseTokenL1Address } from './getBaseTokenL1Address.js'
|
15
|
+
import { getDefaultBridgeAddresses } from './getDefaultBridgeAddresses.js'
|
16
|
+
|
17
|
+
export type GetL2TokenAddressParameters = {
|
18
|
+
/** The address of the token on L1. */
|
19
|
+
token: Address
|
20
|
+
/** The address of custom bridge, which will be used to get l2 token address. */
|
21
|
+
bridgeAddress?: Address | undefined
|
22
|
+
}
|
23
|
+
|
24
|
+
export type GetL2TokenAddressReturnType = Address
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Returns the L2 token address equivalent for a L1 token address as they are not equal.
|
28
|
+
* ETH address is set to zero address.
|
29
|
+
*
|
30
|
+
* @remarks Only works for tokens bridged on default ZKsync Era bridges.
|
31
|
+
*
|
32
|
+
* @param client - Client to use
|
33
|
+
* @param parameters - {@link GetL2TokenAddressParameters}
|
34
|
+
* @returns The L2 token address equivalent for a L1 token address.
|
35
|
+
*
|
36
|
+
*
|
37
|
+
* @example
|
38
|
+
* import { createPublicClient, http } from 'viem'
|
39
|
+
* import { zksync } from 'viem/chains'
|
40
|
+
* import { publicActionsL2 } from 'viem/zksync'
|
41
|
+
*
|
42
|
+
* const client = createPublicClient({
|
43
|
+
* chain: zksync,
|
44
|
+
* transport: http(),
|
45
|
+
* }).extend(publicActionsL2())
|
46
|
+
*
|
47
|
+
* const address = await getL2TokenAddress(client, {token: '0x...'});
|
48
|
+
*/
|
49
|
+
export async function getL2TokenAddress<
|
50
|
+
chain extends Chain | undefined,
|
51
|
+
account extends Account | undefined,
|
52
|
+
>(
|
53
|
+
client: Client<Transport, chain, account>,
|
54
|
+
parameters: GetL2TokenAddressParameters,
|
55
|
+
): Promise<Address> {
|
56
|
+
let { token, bridgeAddress } = parameters
|
57
|
+
if (isAddressEqual(token, legacyEthAddress)) token = ethAddressInContracts
|
58
|
+
|
59
|
+
const baseToken = await getBaseTokenL1Address(client)
|
60
|
+
if (isAddressEqual(token, baseToken)) return l2BaseTokenAddress
|
61
|
+
|
62
|
+
bridgeAddress ??= (await getDefaultBridgeAddresses(client)).sharedL2
|
63
|
+
|
64
|
+
return await readContract(client, {
|
65
|
+
address: bridgeAddress,
|
66
|
+
abi: l2SharedBridgeAbi,
|
67
|
+
functionName: 'l2TokenAddress',
|
68
|
+
args: [token],
|
69
|
+
})
|
70
|
+
}
|
@@ -92,13 +92,15 @@ export async function sendEip712Transaction<
|
|
92
92
|
request
|
93
93
|
>,
|
94
94
|
): Promise<SendEip712TransactionReturnType> {
|
95
|
-
const { chain = client.chain } =
|
95
|
+
const { account: account_ = client.account, chain = client.chain } =
|
96
|
+
parameters
|
96
97
|
|
97
|
-
|
98
|
+
const account = account_ ? parseAccount(account_) : client.account
|
99
|
+
|
100
|
+
if (!account)
|
98
101
|
throw new AccountNotFoundError({
|
99
102
|
docsPath: '/docs/actions/wallet/sendTransaction',
|
100
103
|
})
|
101
|
-
const account = parseAccount(parameters.account)
|
102
104
|
|
103
105
|
try {
|
104
106
|
assertEip712Request(parameters)
|
@@ -53,6 +53,8 @@ export type SignEip712TransactionErrorType = SignTransactionErrorType
|
|
53
53
|
/**
|
54
54
|
* Signs an EIP712 transaction.
|
55
55
|
*
|
56
|
+
*
|
57
|
+
* @param client - Client to use
|
56
58
|
* @param args - {@link SignTransactionParameters}
|
57
59
|
* @returns The signed serialized transaction. {@link SignTransactionReturnType}
|
58
60
|
*
|
@@ -102,11 +104,12 @@ export async function signEip712Transaction<
|
|
102
104
|
...transaction
|
103
105
|
} = args
|
104
106
|
|
105
|
-
|
107
|
+
const account = account_ ? parseAccount(account_) : client.account
|
108
|
+
|
109
|
+
if (!account)
|
106
110
|
throw new AccountNotFoundError({
|
107
111
|
docsPath: '/docs/actions/wallet/signTransaction',
|
108
112
|
})
|
109
|
-
const account = parseAccount(account_)
|
110
113
|
|
111
114
|
assertEip712Request({
|
112
115
|
account,
|