Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zkSync diamond support #522

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gergelyhegykozi
Copy link

@gergelyhegykozi gergelyhegykozi commented Mar 15, 2024

Fixes #453 and #462

Problem:

  • ZkSync requires a different deployment process so we cant reuse the same artifacts.
  • {init} argument can't be used for Diamond _initializations.
  • Any contract deployment fails on zkSync if it was already deployed (invalid rlp data).

Solution:

  • Add optional defaultLoupeFacet parameter, so Diamond facets can be fully defined from outside.
  • Use array instead of object for _initializations.
  • Compare transaction.data the regular way.

Deployment:

1. step

npm i --save-dev @matterlabs/hardhat-zksync-deploy

2. step

Add these to hardhat config:

import '@matterlabs/hardhat-zksync-deploy';
import '@matterlabs/hardhat-zksync-solc';

Add ethereum and zksync to the networks in hardhat-config.

Example for zksync:

zkSyncMainnet: {
    accounts: ...,
    chainId: 324,
    url: ...,
    ethNetwork: ...,
    zksync: true,
},

3. step

Clone https://github.com/safe-global/safe-singleton-factory and fill out env. Run yarn compile:zk then yarn submit

4. step

Use the generated artifacts and define the deterministicDeployment based on this description: https://github.com/wighawag/hardhat-deploy?tab=readme-ov-file#4-deterministicdeployment-ability-to-specify-a-deployment-factory

5. step

Set contracts path in hardhat config to diamond contracts or create a copy of them.

6. step

In deploy script:

if (['zkSyncTestnet', 'zkSyncMainnet'].includes(hre.network.name)) {
    await hre.deployments.diamond.deploy('YourDiamondName', {
        from: deployer,
        owner: deployer,
        defaultCutFacet: false,
        defaultOwnershipFacet: false,
        defaultLoupeFacet: false,
        diamondContract: 'Diamond',
        facets: [
            facets,
            ['DiamondCutFacet', 'OwnershipFacet', 'DiamondLoupeFacet'],
        ].flat(),
        execute: {
            contract: 'DiamondERC165Init',
            methodName: 'setERC165',
            args: [['0x48e2b093', '0x1f931c1c', '0x7f5828d0'], []],
        },
        diamondContractArgs: ['{owner}', '{facetCuts}', '{init}'],
    });
} else {
    await hre.deployments.diamond.deploy('YourDiamondName', {
      from: deployer,
      owner: deployer,
      facets,
    });  
}

Problem:

- ZkSync requires a different deployment process so we cant reuse the same artifacts.
- {init} argument can't be used for Diamond _initializations.
- Any contract deployment fails on zkSync if it was already deployed (invalid rlp data).

Solution:

- Add optional defaultLoupeFacet parameter, so Diamond facets can be fully defined from outside.
- Use array instead of object for _initializations.
- Compare transaction.data the regular way.
@AlissonRS
Copy link

Add optional defaultLoupeFacet parameter, so Diamond facets can be fully defined from outside.

Being able to provide my own loupe implementation would be very nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deploying proxy contract on zkSync got this error: "The bytecode length in bytes must be divisible by 32"
2 participants