viem 0.0.0-main.20240324T200829 → 0.0.0-main.20240324T211636
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/_cjs/chains/zksync/actions/deployContract.js +26 -0
- package/_cjs/chains/zksync/actions/deployContract.js.map +1 -0
- package/_cjs/chains/zksync/constants/abis.js +427 -0
- package/_cjs/chains/zksync/constants/abis.js.map +1 -0
- package/_cjs/chains/zksync/constants/address.js +5 -0
- package/_cjs/chains/zksync/constants/address.js.map +1 -0
- package/_cjs/chains/zksync/constants/contract.js +6 -0
- package/_cjs/chains/zksync/constants/contract.js.map +1 -0
- package/_cjs/chains/zksync/constants/number.js +6 -0
- package/_cjs/chains/zksync/constants/number.js.map +1 -0
- package/_cjs/chains/zksync/decorators/eip712.js +2 -0
- package/_cjs/chains/zksync/decorators/eip712.js.map +1 -1
- package/_cjs/chains/zksync/errors/bytecode.js +41 -0
- package/_cjs/chains/zksync/errors/bytecode.js.map +1 -0
- package/_cjs/chains/zksync/formatters.js +5 -1
- package/_cjs/chains/zksync/formatters.js.map +1 -1
- package/_cjs/chains/zksync/index.js +3 -1
- package/_cjs/chains/zksync/index.js.map +1 -1
- package/_cjs/chains/zksync/types/contract.js +3 -0
- package/_cjs/chains/zksync/types/contract.js.map +1 -0
- package/_cjs/chains/zksync/utils/abi/encodeDeployData.js +68 -0
- package/_cjs/chains/zksync/utils/abi/encodeDeployData.js.map +1 -0
- package/_cjs/chains/zksync/utils/getEip712Domain.js +4 -2
- package/_cjs/chains/zksync/utils/getEip712Domain.js.map +1 -1
- package/_cjs/chains/zksync/utils/hashBytecode.js +36 -0
- package/_cjs/chains/zksync/utils/hashBytecode.js.map +1 -0
- package/_cjs/errors/version.js +1 -1
- package/_esm/chains/zksync/actions/deployContract.js +52 -0
- package/_esm/chains/zksync/actions/deployContract.js.map +1 -0
- package/_esm/chains/zksync/constants/abis.js +425 -0
- package/_esm/chains/zksync/constants/abis.js.map +1 -0
- package/_esm/chains/zksync/constants/address.js +2 -0
- package/_esm/chains/zksync/constants/address.js.map +1 -0
- package/_esm/chains/zksync/constants/contract.js +3 -0
- package/_esm/chains/zksync/constants/contract.js.map +1 -0
- package/_esm/chains/zksync/constants/number.js +3 -0
- package/_esm/chains/zksync/constants/number.js.map +1 -0
- package/_esm/chains/zksync/decorators/eip712.js +2 -0
- package/_esm/chains/zksync/decorators/eip712.js.map +1 -1
- package/_esm/chains/zksync/errors/bytecode.js +35 -0
- package/_esm/chains/zksync/errors/bytecode.js.map +1 -0
- package/_esm/chains/zksync/formatters.js +5 -1
- package/_esm/chains/zksync/formatters.js.map +1 -1
- package/_esm/chains/zksync/index.js +1 -0
- package/_esm/chains/zksync/index.js.map +1 -1
- package/_esm/chains/zksync/types/contract.js +2 -0
- package/_esm/chains/zksync/types/contract.js.map +1 -0
- package/_esm/chains/zksync/utils/abi/encodeDeployData.js +65 -0
- package/_esm/chains/zksync/utils/abi/encodeDeployData.js.map +1 -0
- package/_esm/chains/zksync/utils/getEip712Domain.js +4 -2
- package/_esm/chains/zksync/utils/getEip712Domain.js.map +1 -1
- package/_esm/chains/zksync/utils/hashBytecode.js +36 -0
- package/_esm/chains/zksync/utils/hashBytecode.js.map +1 -0
- package/_esm/errors/version.js +1 -1
- package/_types/chains/zksync/actions/deployContract.d.ts +49 -0
- package/_types/chains/zksync/actions/deployContract.d.ts.map +1 -0
- package/_types/chains/zksync/constants/abis.d.ts +70 -0
- package/_types/chains/zksync/constants/abis.d.ts.map +1 -0
- package/_types/chains/zksync/constants/address.d.ts +2 -0
- package/_types/chains/zksync/constants/address.d.ts.map +1 -0
- package/_types/chains/zksync/constants/contract.d.ts +3 -0
- package/_types/chains/zksync/constants/contract.d.ts.map +1 -0
- package/_types/chains/zksync/constants/number.d.ts +2 -0
- package/_types/chains/zksync/constants/number.d.ts.map +1 -0
- package/_types/chains/zksync/decorators/eip712.d.ts +32 -0
- package/_types/chains/zksync/decorators/eip712.d.ts.map +1 -1
- package/_types/chains/zksync/errors/bytecode.d.ts +30 -0
- package/_types/chains/zksync/errors/bytecode.d.ts.map +1 -0
- package/_types/chains/zksync/formatters.d.ts.map +1 -1
- package/_types/chains/zksync/index.d.ts +1 -0
- package/_types/chains/zksync/index.d.ts.map +1 -1
- package/_types/chains/zksync/types/contract.d.ts +2 -0
- package/_types/chains/zksync/types/contract.d.ts.map +1 -0
- package/_types/chains/zksync/utils/abi/encodeDeployData.d.ts +13 -0
- package/_types/chains/zksync/utils/abi/encodeDeployData.d.ts.map +1 -0
- package/_types/chains/zksync/utils/getEip712Domain.d.ts.map +1 -1
- package/_types/chains/zksync/utils/hashBytecode.d.ts +3 -0
- package/_types/chains/zksync/utils/hashBytecode.d.ts.map +1 -0
- package/_types/errors/version.d.ts +1 -1
- package/chains/zksync/actions/deployContract.ts +100 -0
- package/chains/zksync/constants/abis.ts +424 -0
- package/chains/zksync/constants/address.ts +2 -0
- package/chains/zksync/constants/contract.ts +2 -0
- package/chains/zksync/constants/number.ts +3 -0
- package/chains/zksync/decorators/eip712.ts +47 -0
- package/chains/zksync/errors/bytecode.ts +46 -0
- package/chains/zksync/formatters.ts +7 -1
- package/chains/zksync/index.ts +6 -0
- package/chains/zksync/types/contract.ts +6 -0
- package/chains/zksync/utils/abi/encodeDeployData.ts +120 -0
- package/chains/zksync/utils/getEip712Domain.ts +4 -2
- package/chains/zksync/utils/hashBytecode.ts +48 -0
- package/errors/version.ts +1 -1
- package/package.json +1 -1
@@ -0,0 +1,100 @@
|
|
1
|
+
import type { Abi } from 'abitype'
|
2
|
+
|
3
|
+
import type { Account } from '../../../accounts/types.js'
|
4
|
+
import type { DeployContractParameters as DeployContractParameters_ } from '../../../actions/wallet/deployContract.js'
|
5
|
+
import type { Client } from '../../../clients/createClient.js'
|
6
|
+
import type { Transport } from '../../../clients/transports/createTransport.js'
|
7
|
+
import type { ErrorType } from '../../../errors/utils.js'
|
8
|
+
import type { ContractConstructorArgs } from '../../../types/contract.js'
|
9
|
+
import type { Hash, Hex } from '../../../types/misc.js'
|
10
|
+
import { contractDeployerAddress } from '../constants/address.js'
|
11
|
+
import type { ChainEIP712 } from '../types/chain.js'
|
12
|
+
import type { ContractDeploymentType } from '../types/contract.js'
|
13
|
+
import { encodeDeployData } from '../utils/abi/encodeDeployData.js'
|
14
|
+
import {
|
15
|
+
type SendEip712TransactionErrorType,
|
16
|
+
type SendEip712TransactionParameters,
|
17
|
+
type SendEip712TransactionReturnType,
|
18
|
+
sendEip712Transaction,
|
19
|
+
} from './sendEip712Transaction.js'
|
20
|
+
|
21
|
+
export type DeployContractParameters<
|
22
|
+
abi extends Abi | readonly unknown[] = Abi,
|
23
|
+
chain extends ChainEIP712 | undefined = ChainEIP712 | undefined,
|
24
|
+
account extends Account | undefined = Account | undefined,
|
25
|
+
chainOverride extends ChainEIP712 | undefined = ChainEIP712 | undefined,
|
26
|
+
allArgs = ContractConstructorArgs<abi>,
|
27
|
+
> = DeployContractParameters_<abi, chain, account, chainOverride, allArgs> & {
|
28
|
+
deploymentType?: ContractDeploymentType
|
29
|
+
factoryDeps?: Hex[]
|
30
|
+
salt?: Hash
|
31
|
+
}
|
32
|
+
|
33
|
+
export type DeployContractReturnType = SendEip712TransactionReturnType
|
34
|
+
|
35
|
+
export type DeployContractErrorType = SendEip712TransactionErrorType | ErrorType
|
36
|
+
|
37
|
+
/**
|
38
|
+
* Deploys a contract to the network, given bytecode and constructor arguments using EIP712 transaction.
|
39
|
+
*
|
40
|
+
* - Docs: https://viem.sh/docs/contract/deployContract
|
41
|
+
*
|
42
|
+
* @param client - Client to use
|
43
|
+
* @param parameters - {@link DeployContractParameters}
|
44
|
+
* @returns The [Transaction](https://viem.sh/docs/glossary/terms#transaction) hash. {@link DeployContractReturnType}
|
45
|
+
*
|
46
|
+
* @example
|
47
|
+
* import { createWalletClient, custom } from 'viem'
|
48
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
49
|
+
* import { zkSync } from 'viem/chains'
|
50
|
+
* import { deployContract } from 'viem/zksync'
|
51
|
+
*
|
52
|
+
* const client = createWalletClient({
|
53
|
+
* account: privateKeyToAccount('0x…'),
|
54
|
+
* chain: zksync,
|
55
|
+
* transport: custom(provider),
|
56
|
+
* })
|
57
|
+
* const hash = await deployContract(client, {
|
58
|
+
* abi: [],
|
59
|
+
* account: '0x…,
|
60
|
+
* deploymentType: 'create',
|
61
|
+
* bytecode: '0x608060405260405161083e38038061083e833981016040819052610...',
|
62
|
+
* factoryDeps: ['0x608060405260405161083e38038061083e833981016040819052610...'],
|
63
|
+
* gasPerPubdata: 50000n
|
64
|
+
* })
|
65
|
+
*/
|
66
|
+
export function deployContract<
|
67
|
+
const abi extends Abi | readonly unknown[],
|
68
|
+
chain extends ChainEIP712 | undefined,
|
69
|
+
account extends Account | undefined,
|
70
|
+
chainOverride extends ChainEIP712 | undefined,
|
71
|
+
>(
|
72
|
+
walletClient: Client<Transport, chain, account>,
|
73
|
+
parameters: DeployContractParameters<abi, chain, account, chainOverride>,
|
74
|
+
): Promise<DeployContractReturnType> {
|
75
|
+
const { abi, args, bytecode, deploymentType, salt, ...request } =
|
76
|
+
parameters as DeployContractParameters
|
77
|
+
|
78
|
+
const data = encodeDeployData({
|
79
|
+
abi,
|
80
|
+
args,
|
81
|
+
bytecode,
|
82
|
+
deploymentType,
|
83
|
+
salt,
|
84
|
+
})
|
85
|
+
|
86
|
+
// Add the bytecode to the factoryDeps if it's not already there
|
87
|
+
request.factoryDeps = request.factoryDeps || []
|
88
|
+
if (!request.factoryDeps.includes(bytecode))
|
89
|
+
request.factoryDeps.push(bytecode)
|
90
|
+
|
91
|
+
return sendEip712Transaction(walletClient, {
|
92
|
+
...request,
|
93
|
+
data,
|
94
|
+
to: contractDeployerAddress,
|
95
|
+
} as unknown as SendEip712TransactionParameters<
|
96
|
+
chain,
|
97
|
+
account,
|
98
|
+
chainOverride
|
99
|
+
>)
|
100
|
+
}
|
@@ -0,0 +1,424 @@
|
|
1
|
+
/* [ContractDeployer](https://github.com/matter-labs/era-system-contracts/blob/main/contracts/ContractDeployer.sol) */
|
2
|
+
export const contractDeployerAbi = [
|
3
|
+
{
|
4
|
+
anonymous: false,
|
5
|
+
inputs: [
|
6
|
+
{
|
7
|
+
indexed: true,
|
8
|
+
internalType: 'address',
|
9
|
+
name: 'accountAddress',
|
10
|
+
type: 'address',
|
11
|
+
},
|
12
|
+
{
|
13
|
+
indexed: false,
|
14
|
+
internalType: 'enum IContractDeployer.AccountNonceOrdering',
|
15
|
+
name: 'nonceOrdering',
|
16
|
+
type: 'uint8',
|
17
|
+
},
|
18
|
+
],
|
19
|
+
name: 'AccountNonceOrderingUpdated',
|
20
|
+
type: 'event',
|
21
|
+
},
|
22
|
+
{
|
23
|
+
anonymous: false,
|
24
|
+
inputs: [
|
25
|
+
{
|
26
|
+
indexed: true,
|
27
|
+
internalType: 'address',
|
28
|
+
name: 'accountAddress',
|
29
|
+
type: 'address',
|
30
|
+
},
|
31
|
+
{
|
32
|
+
indexed: false,
|
33
|
+
internalType: 'enum IContractDeployer.AccountAbstractionVersion',
|
34
|
+
name: 'aaVersion',
|
35
|
+
type: 'uint8',
|
36
|
+
},
|
37
|
+
],
|
38
|
+
name: 'AccountVersionUpdated',
|
39
|
+
type: 'event',
|
40
|
+
},
|
41
|
+
{
|
42
|
+
anonymous: false,
|
43
|
+
inputs: [
|
44
|
+
{
|
45
|
+
indexed: true,
|
46
|
+
internalType: 'address',
|
47
|
+
name: 'deployerAddress',
|
48
|
+
type: 'address',
|
49
|
+
},
|
50
|
+
{
|
51
|
+
indexed: true,
|
52
|
+
internalType: 'bytes32',
|
53
|
+
name: 'bytecodeHash',
|
54
|
+
type: 'bytes32',
|
55
|
+
},
|
56
|
+
{
|
57
|
+
indexed: true,
|
58
|
+
internalType: 'address',
|
59
|
+
name: 'contractAddress',
|
60
|
+
type: 'address',
|
61
|
+
},
|
62
|
+
],
|
63
|
+
name: 'ContractDeployed',
|
64
|
+
type: 'event',
|
65
|
+
},
|
66
|
+
{
|
67
|
+
inputs: [
|
68
|
+
{
|
69
|
+
internalType: 'bytes32',
|
70
|
+
name: '_salt',
|
71
|
+
type: 'bytes32',
|
72
|
+
},
|
73
|
+
{
|
74
|
+
internalType: 'bytes32',
|
75
|
+
name: '_bytecodeHash',
|
76
|
+
type: 'bytes32',
|
77
|
+
},
|
78
|
+
{
|
79
|
+
internalType: 'bytes',
|
80
|
+
name: '_input',
|
81
|
+
type: 'bytes',
|
82
|
+
},
|
83
|
+
],
|
84
|
+
name: 'create',
|
85
|
+
outputs: [
|
86
|
+
{
|
87
|
+
internalType: 'address',
|
88
|
+
name: '',
|
89
|
+
type: 'address',
|
90
|
+
},
|
91
|
+
],
|
92
|
+
stateMutability: 'payable',
|
93
|
+
type: 'function',
|
94
|
+
},
|
95
|
+
{
|
96
|
+
inputs: [
|
97
|
+
{
|
98
|
+
internalType: 'bytes32',
|
99
|
+
name: '_salt',
|
100
|
+
type: 'bytes32',
|
101
|
+
},
|
102
|
+
{
|
103
|
+
internalType: 'bytes32',
|
104
|
+
name: '_bytecodeHash',
|
105
|
+
type: 'bytes32',
|
106
|
+
},
|
107
|
+
{
|
108
|
+
internalType: 'bytes',
|
109
|
+
name: '_input',
|
110
|
+
type: 'bytes',
|
111
|
+
},
|
112
|
+
],
|
113
|
+
name: 'create2',
|
114
|
+
outputs: [
|
115
|
+
{
|
116
|
+
internalType: 'address',
|
117
|
+
name: '',
|
118
|
+
type: 'address',
|
119
|
+
},
|
120
|
+
],
|
121
|
+
stateMutability: 'payable',
|
122
|
+
type: 'function',
|
123
|
+
},
|
124
|
+
{
|
125
|
+
inputs: [
|
126
|
+
{
|
127
|
+
internalType: 'bytes32',
|
128
|
+
name: '_salt',
|
129
|
+
type: 'bytes32',
|
130
|
+
},
|
131
|
+
{
|
132
|
+
internalType: 'bytes32',
|
133
|
+
name: '_bytecodeHash',
|
134
|
+
type: 'bytes32',
|
135
|
+
},
|
136
|
+
{
|
137
|
+
internalType: 'bytes',
|
138
|
+
name: '_input',
|
139
|
+
type: 'bytes',
|
140
|
+
},
|
141
|
+
{
|
142
|
+
internalType: 'enum IContractDeployer.AccountAbstractionVersion',
|
143
|
+
name: '_aaVersion',
|
144
|
+
type: 'uint8',
|
145
|
+
},
|
146
|
+
],
|
147
|
+
name: 'create2Account',
|
148
|
+
outputs: [
|
149
|
+
{
|
150
|
+
internalType: 'address',
|
151
|
+
name: '',
|
152
|
+
type: 'address',
|
153
|
+
},
|
154
|
+
],
|
155
|
+
stateMutability: 'payable',
|
156
|
+
type: 'function',
|
157
|
+
},
|
158
|
+
{
|
159
|
+
inputs: [
|
160
|
+
{
|
161
|
+
internalType: 'bytes32',
|
162
|
+
name: '',
|
163
|
+
type: 'bytes32',
|
164
|
+
},
|
165
|
+
{
|
166
|
+
internalType: 'bytes32',
|
167
|
+
name: '_bytecodeHash',
|
168
|
+
type: 'bytes32',
|
169
|
+
},
|
170
|
+
{
|
171
|
+
internalType: 'bytes',
|
172
|
+
name: '_input',
|
173
|
+
type: 'bytes',
|
174
|
+
},
|
175
|
+
{
|
176
|
+
internalType: 'enum IContractDeployer.AccountAbstractionVersion',
|
177
|
+
name: '_aaVersion',
|
178
|
+
type: 'uint8',
|
179
|
+
},
|
180
|
+
],
|
181
|
+
name: 'createAccount',
|
182
|
+
outputs: [
|
183
|
+
{
|
184
|
+
internalType: 'address',
|
185
|
+
name: '',
|
186
|
+
type: 'address',
|
187
|
+
},
|
188
|
+
],
|
189
|
+
stateMutability: 'payable',
|
190
|
+
type: 'function',
|
191
|
+
},
|
192
|
+
{
|
193
|
+
inputs: [
|
194
|
+
{
|
195
|
+
internalType: 'address',
|
196
|
+
name: '_address',
|
197
|
+
type: 'address',
|
198
|
+
},
|
199
|
+
],
|
200
|
+
name: 'extendedAccountVersion',
|
201
|
+
outputs: [
|
202
|
+
{
|
203
|
+
internalType: 'enum IContractDeployer.AccountAbstractionVersion',
|
204
|
+
name: '',
|
205
|
+
type: 'uint8',
|
206
|
+
},
|
207
|
+
],
|
208
|
+
stateMutability: 'view',
|
209
|
+
type: 'function',
|
210
|
+
},
|
211
|
+
{
|
212
|
+
inputs: [
|
213
|
+
{
|
214
|
+
internalType: 'bytes32',
|
215
|
+
name: '_keccak256BytecodeHash',
|
216
|
+
type: 'bytes32',
|
217
|
+
},
|
218
|
+
],
|
219
|
+
name: 'forceDeployKeccak256',
|
220
|
+
outputs: [],
|
221
|
+
stateMutability: 'payable',
|
222
|
+
type: 'function',
|
223
|
+
},
|
224
|
+
{
|
225
|
+
inputs: [
|
226
|
+
{
|
227
|
+
components: [
|
228
|
+
{
|
229
|
+
internalType: 'bytes32',
|
230
|
+
name: 'bytecodeHash',
|
231
|
+
type: 'bytes32',
|
232
|
+
},
|
233
|
+
{
|
234
|
+
internalType: 'address',
|
235
|
+
name: 'newAddress',
|
236
|
+
type: 'address',
|
237
|
+
},
|
238
|
+
{
|
239
|
+
internalType: 'bool',
|
240
|
+
name: 'callConstructor',
|
241
|
+
type: 'bool',
|
242
|
+
},
|
243
|
+
{
|
244
|
+
internalType: 'uint256',
|
245
|
+
name: 'value',
|
246
|
+
type: 'uint256',
|
247
|
+
},
|
248
|
+
{
|
249
|
+
internalType: 'bytes',
|
250
|
+
name: 'input',
|
251
|
+
type: 'bytes',
|
252
|
+
},
|
253
|
+
],
|
254
|
+
internalType: 'struct ContractDeployer.ForceDeployment',
|
255
|
+
name: '_deployment',
|
256
|
+
type: 'tuple',
|
257
|
+
},
|
258
|
+
{
|
259
|
+
internalType: 'address',
|
260
|
+
name: '_sender',
|
261
|
+
type: 'address',
|
262
|
+
},
|
263
|
+
],
|
264
|
+
name: 'forceDeployOnAddress',
|
265
|
+
outputs: [],
|
266
|
+
stateMutability: 'payable',
|
267
|
+
type: 'function',
|
268
|
+
},
|
269
|
+
{
|
270
|
+
inputs: [
|
271
|
+
{
|
272
|
+
components: [
|
273
|
+
{
|
274
|
+
internalType: 'bytes32',
|
275
|
+
name: 'bytecodeHash',
|
276
|
+
type: 'bytes32',
|
277
|
+
},
|
278
|
+
{
|
279
|
+
internalType: 'address',
|
280
|
+
name: 'newAddress',
|
281
|
+
type: 'address',
|
282
|
+
},
|
283
|
+
{
|
284
|
+
internalType: 'bool',
|
285
|
+
name: 'callConstructor',
|
286
|
+
type: 'bool',
|
287
|
+
},
|
288
|
+
{
|
289
|
+
internalType: 'uint256',
|
290
|
+
name: 'value',
|
291
|
+
type: 'uint256',
|
292
|
+
},
|
293
|
+
{
|
294
|
+
internalType: 'bytes',
|
295
|
+
name: 'input',
|
296
|
+
type: 'bytes',
|
297
|
+
},
|
298
|
+
],
|
299
|
+
internalType: 'struct ContractDeployer.ForceDeployment[]',
|
300
|
+
name: '_deployments',
|
301
|
+
type: 'tuple[]',
|
302
|
+
},
|
303
|
+
],
|
304
|
+
name: 'forceDeployOnAddresses',
|
305
|
+
outputs: [],
|
306
|
+
stateMutability: 'payable',
|
307
|
+
type: 'function',
|
308
|
+
},
|
309
|
+
{
|
310
|
+
inputs: [
|
311
|
+
{
|
312
|
+
internalType: 'address',
|
313
|
+
name: '_address',
|
314
|
+
type: 'address',
|
315
|
+
},
|
316
|
+
],
|
317
|
+
name: 'getAccountInfo',
|
318
|
+
outputs: [
|
319
|
+
{
|
320
|
+
components: [
|
321
|
+
{
|
322
|
+
internalType: 'enum IContractDeployer.AccountAbstractionVersion',
|
323
|
+
name: 'supportedAAVersion',
|
324
|
+
type: 'uint8',
|
325
|
+
},
|
326
|
+
{
|
327
|
+
internalType: 'enum IContractDeployer.AccountNonceOrdering',
|
328
|
+
name: 'nonceOrdering',
|
329
|
+
type: 'uint8',
|
330
|
+
},
|
331
|
+
],
|
332
|
+
internalType: 'struct IContractDeployer.AccountInfo',
|
333
|
+
name: 'info',
|
334
|
+
type: 'tuple',
|
335
|
+
},
|
336
|
+
],
|
337
|
+
stateMutability: 'view',
|
338
|
+
type: 'function',
|
339
|
+
},
|
340
|
+
{
|
341
|
+
inputs: [
|
342
|
+
{
|
343
|
+
internalType: 'address',
|
344
|
+
name: '_sender',
|
345
|
+
type: 'address',
|
346
|
+
},
|
347
|
+
{
|
348
|
+
internalType: 'uint256',
|
349
|
+
name: '_senderNonce',
|
350
|
+
type: 'uint256',
|
351
|
+
},
|
352
|
+
],
|
353
|
+
name: 'getNewAddressCreate',
|
354
|
+
outputs: [
|
355
|
+
{
|
356
|
+
internalType: 'address',
|
357
|
+
name: 'newAddress',
|
358
|
+
type: 'address',
|
359
|
+
},
|
360
|
+
],
|
361
|
+
stateMutability: 'pure',
|
362
|
+
type: 'function',
|
363
|
+
},
|
364
|
+
{
|
365
|
+
inputs: [
|
366
|
+
{
|
367
|
+
internalType: 'address',
|
368
|
+
name: '_sender',
|
369
|
+
type: 'address',
|
370
|
+
},
|
371
|
+
{
|
372
|
+
internalType: 'bytes32',
|
373
|
+
name: '_bytecodeHash',
|
374
|
+
type: 'bytes32',
|
375
|
+
},
|
376
|
+
{
|
377
|
+
internalType: 'bytes32',
|
378
|
+
name: '_salt',
|
379
|
+
type: 'bytes32',
|
380
|
+
},
|
381
|
+
{
|
382
|
+
internalType: 'bytes',
|
383
|
+
name: '_input',
|
384
|
+
type: 'bytes',
|
385
|
+
},
|
386
|
+
],
|
387
|
+
name: 'getNewAddressCreate2',
|
388
|
+
outputs: [
|
389
|
+
{
|
390
|
+
internalType: 'address',
|
391
|
+
name: 'newAddress',
|
392
|
+
type: 'address',
|
393
|
+
},
|
394
|
+
],
|
395
|
+
stateMutability: 'view',
|
396
|
+
type: 'function',
|
397
|
+
},
|
398
|
+
{
|
399
|
+
inputs: [
|
400
|
+
{
|
401
|
+
internalType: 'enum IContractDeployer.AccountAbstractionVersion',
|
402
|
+
name: '_version',
|
403
|
+
type: 'uint8',
|
404
|
+
},
|
405
|
+
],
|
406
|
+
name: 'updateAccountVersion',
|
407
|
+
outputs: [],
|
408
|
+
stateMutability: 'nonpayable',
|
409
|
+
type: 'function',
|
410
|
+
},
|
411
|
+
{
|
412
|
+
inputs: [
|
413
|
+
{
|
414
|
+
internalType: 'enum IContractDeployer.AccountNonceOrdering',
|
415
|
+
name: '_nonceOrdering',
|
416
|
+
type: 'uint8',
|
417
|
+
},
|
418
|
+
],
|
419
|
+
name: 'updateNonceOrdering',
|
420
|
+
outputs: [],
|
421
|
+
stateMutability: 'nonpayable',
|
422
|
+
type: 'function',
|
423
|
+
},
|
424
|
+
]
|
@@ -1,8 +1,14 @@
|
|
1
|
+
import type { Abi } from 'abitype'
|
1
2
|
import { writeContract } from '../../../actions/wallet/writeContract.js'
|
2
3
|
import type { Client } from '../../../clients/createClient.js'
|
3
4
|
import type { WalletActions } from '../../../clients/decorators/wallet.js'
|
4
5
|
import type { Transport } from '../../../clients/transports/createTransport.js'
|
5
6
|
import type { Account } from '../../../types/account.js'
|
7
|
+
import {
|
8
|
+
type DeployContractParameters,
|
9
|
+
type DeployContractReturnType,
|
10
|
+
deployContract,
|
11
|
+
} from '../actions/deployContract.js'
|
6
12
|
import {
|
7
13
|
type SendTransactionParameters,
|
8
14
|
type SendTransactionReturnType,
|
@@ -112,6 +118,46 @@ export type Eip712WalletActions<
|
|
112
118
|
signTransaction: <chainOverride extends ChainEIP712 | undefined = undefined>(
|
113
119
|
args: SignTransactionParameters<chain, account, chainOverride>,
|
114
120
|
) => Promise<SignTransactionReturnType>
|
121
|
+
/**
|
122
|
+
* Deploys a contract to the network, given bytecode and constructor arguments using EIP712 transaction.
|
123
|
+
*
|
124
|
+
* - Docs: https://viem.sh/docs/contract/deployContract
|
125
|
+
* - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/contracts/deploying-contracts
|
126
|
+
*
|
127
|
+
* @param args - {@link DeployContractParameters}
|
128
|
+
* @returns The [Transaction](https://viem.sh/docs/glossary/terms#transaction) hash. {@link DeployContractReturnType}
|
129
|
+
*
|
130
|
+
* @example
|
131
|
+
* import { createWalletClient, custom } from 'viem'
|
132
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
133
|
+
* import { zkSync } from 'viem/chains'
|
134
|
+
* import { deployContract } from 'viem/contract'
|
135
|
+
*
|
136
|
+
* const client = createWalletClient({
|
137
|
+
* account: privateKeyToAccount('0x…'),
|
138
|
+
* chain: zksync,
|
139
|
+
* transport: custom(provider),
|
140
|
+
* })
|
141
|
+
* const hash = await client.deployContract(client, {
|
142
|
+
* abi: [],
|
143
|
+
* account: '0x…,
|
144
|
+
* deploymentType: 'create',
|
145
|
+
* bytecode: '0x608060405260405161083e38038061083e833981016040819052610...',
|
146
|
+
* factoryDeps: ['0x608060405260405161083e38038061083e833981016040819052610...'],
|
147
|
+
* gasPerPubdata: 50000n
|
148
|
+
* })
|
149
|
+
*/
|
150
|
+
deployContract: <
|
151
|
+
const abi extends Abi | readonly unknown[],
|
152
|
+
chainOverride extends ChainEIP712 | undefined,
|
153
|
+
>(
|
154
|
+
args: DeployContractParameters<
|
155
|
+
abi,
|
156
|
+
ChainEIP712 | undefined,
|
157
|
+
Account | undefined,
|
158
|
+
chainOverride
|
159
|
+
>,
|
160
|
+
) => Promise<DeployContractReturnType>
|
115
161
|
/**
|
116
162
|
* Executes a write function on a contract.
|
117
163
|
*
|
@@ -175,6 +221,7 @@ export function eip712WalletActions() {
|
|
175
221
|
): Eip712WalletActions<chain, account> => ({
|
176
222
|
sendTransaction: (args) => sendTransaction(client, args),
|
177
223
|
signTransaction: (args) => signTransaction(client, args),
|
224
|
+
deployContract: (args) => deployContract(client, args),
|
178
225
|
writeContract: (args) =>
|
179
226
|
writeContract(
|
180
227
|
Object.assign(client, {
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import { BaseError } from '../../../errors/base.js'
|
2
|
+
|
3
|
+
export type BytecodeLengthExceedsMaxSizeErrorType =
|
4
|
+
BytecodeLengthExceedsMaxSizeError & {
|
5
|
+
name: 'BytecodeLengthExceedsMaxSizeError'
|
6
|
+
}
|
7
|
+
|
8
|
+
export class BytecodeLengthExceedsMaxSizeError extends BaseError {
|
9
|
+
override name = 'BytecodeLengthExceedsMaxSizeError'
|
10
|
+
constructor({
|
11
|
+
givenLength,
|
12
|
+
maxBytecodeSize,
|
13
|
+
}: { givenLength: number; maxBytecodeSize: bigint }) {
|
14
|
+
super(
|
15
|
+
`Bytecode cannot be longer than ${maxBytecodeSize} bytes. Given length: ${givenLength}`,
|
16
|
+
)
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
export type BytecodeLengthInWordsMustBeOddErrorType =
|
21
|
+
BytecodeLengthInWordsMustBeOddError & {
|
22
|
+
name: 'BytecodeLengthInWordsMustBeOddError'
|
23
|
+
}
|
24
|
+
|
25
|
+
export class BytecodeLengthInWordsMustBeOddError extends BaseError {
|
26
|
+
override name = 'BytecodeLengthInWordsMustBeOddError'
|
27
|
+
constructor({ givenLengthInWords }: { givenLengthInWords: number }) {
|
28
|
+
super(
|
29
|
+
`Bytecode length in 32-byte words must be odd. Given length in words: ${givenLengthInWords}`,
|
30
|
+
)
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
export type BytecodeLengthMustBeDivisibleBy32ErrorType =
|
35
|
+
BytecodeLengthMustBeDivisibleBy32Error & {
|
36
|
+
name: 'BytecodeLengthMustBeDivisibleBy32Error'
|
37
|
+
}
|
38
|
+
|
39
|
+
export class BytecodeLengthMustBeDivisibleBy32Error extends BaseError {
|
40
|
+
override name = 'BytecodeLengthMustBeDivisibleBy32Error'
|
41
|
+
constructor({ givenLength }: { givenLength: number }) {
|
42
|
+
super(
|
43
|
+
`The bytecode length in bytes must be divisible by 32. Given length: ${givenLength}`,
|
44
|
+
)
|
45
|
+
}
|
46
|
+
}
|
@@ -134,7 +134,13 @@ export const formatters = {
|
|
134
134
|
},
|
135
135
|
}
|
136
136
|
: {}),
|
137
|
-
...(args.factoryDeps
|
137
|
+
...(args.factoryDeps
|
138
|
+
? {
|
139
|
+
factoryDeps: args.factoryDeps.map((dep) =>
|
140
|
+
Array.from(hexToBytes(dep)),
|
141
|
+
),
|
142
|
+
}
|
143
|
+
: {}),
|
138
144
|
...(args.customSignature
|
139
145
|
? {
|
140
146
|
customSignature: Array.from(hexToBytes(args.customSignature)),
|
package/chains/zksync/index.ts
CHANGED
@@ -22,6 +22,12 @@ export {
|
|
22
22
|
type SignTransactionReturnType,
|
23
23
|
signTransaction,
|
24
24
|
} from './actions/signTransaction.js'
|
25
|
+
export {
|
26
|
+
type DeployContractErrorType,
|
27
|
+
type DeployContractParameters,
|
28
|
+
type DeployContractReturnType,
|
29
|
+
deployContract,
|
30
|
+
} from './actions/deployContract.js'
|
25
31
|
|
26
32
|
export {
|
27
33
|
zkSync,
|