Skip to content

Commit

Permalink
fix(zksync): enable contract and account deployment using create2 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
danijelTxFusion authored Dec 29, 2024
1 parent cbf3875 commit c35a01b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-needles-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Provided deployment of accounts and contracts using `create2`
13 changes: 12 additions & 1 deletion src/zksync/actions/deployContract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { privateKeyToAccount } from '../../accounts/privateKeyToAccount.js'

import { deployContract } from './deployContract.js'

import { anvilZksync } from '../../../test/src/anvil.js'
import { anvilZksync } from '~test/src/anvil.js'
import type { EIP1193RequestFn } from '../../index.js'
import type { DeployContractParameters } from './deployContract.js'

Expand Down Expand Up @@ -51,3 +51,14 @@ test('args: factoryDeps', async () => {
`"0x9afe47f3d95eccfc9210851ba5f877f76d372514a26b48bad848a07f77c33b87"`,
)
})

test('create2', async () => {
expect(
await deployContract(client, {
...base,
deploymentType: 'create2',
}),
).toMatchInlineSnapshot(
`"0x9afe47f3d95eccfc9210851ba5f877f76d372514a26b48bad848a07f77c33b87"`,
)
})
12 changes: 9 additions & 3 deletions src/zksync/actions/deployContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { ContractConstructorArgs } from '../../types/contract.js'
import type { Hash, Hex } from '../../types/misc.js'
import { contractDeployerAddress } from '../constants/address.js'
import {
contract2FactoryAddress,
contractDeployerAddress,
} from '../constants/address.js'
import type { ChainEIP712 } from '../types/chain.js'
import type { ContractDeploymentType } from '../types/contract.js'
import {
Expand Down Expand Up @@ -45,7 +48,7 @@ export type DeployContractErrorType =
*
* - Docs: https://viem.sh/docs/contract/deployContract
*
* @param client - Client to use
* @param walletClient - Client to use
* @param parameters - {@link DeployContractParameters}
* @returns The [Transaction](https://viem.sh/docs/glossary/terms#transaction) hash. {@link DeployContractReturnType}
*
Expand Down Expand Up @@ -97,7 +100,10 @@ export function deployContract<
return sendEip712Transaction(walletClient, {
...request,
data,
to: contractDeployerAddress,
to:
deploymentType === 'create2' || deploymentType === 'create2Account'
? contract2FactoryAddress
: contractDeployerAddress,
} as unknown as SendEip712TransactionParameters<
chain,
account,
Expand Down
3 changes: 3 additions & 0 deletions src/zksync/constants/address.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export const contractDeployerAddress =
'0x0000000000000000000000000000000000008006' as const

export const contract2FactoryAddress =
'0x0000000000000000000000000000000000010000' as const

export const legacyEthAddress =
'0x0000000000000000000000000000000000000000' as const

Expand Down

0 comments on commit c35a01b

Please sign in to comment.