Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
chore: extend deploy and upgrade of proxy with deployment type and sa…
Browse files Browse the repository at this point in the history
…lt (#1060)

Co-authored-by: Marko Arambasic <makiarambasic@gmail.com>
Co-authored-by: Dustin Brickwood <dustinbrickwood204@gmail.com>
Co-authored-by: Antonio <aug@matterlabs.dev>
Co-authored-by: Antonio <tonioufa@gmail.com>
  • Loading branch information
5 people authored Jun 6, 2024
1 parent 5bace37 commit c19878c
Showing 1 changed file with 88 additions and 10 deletions.
98 changes: 88 additions & 10 deletions docs/build/tooling/hardhat/hardhat-zksync-upgradable.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ Examples are adopted for plugin version **>=1.0.0**
Current version of the upgradable plugin does not support the latest version of the `@openzeppelin/upgrades-core` package.
:::

:::warning @openzeppelin/contracts and @openzeppelin/contracts-upgradeable versions

The plugin is not yet compatible with the latest versions of OpenZeppelin (v5). In the meantime, please use the previous version (OpenZeppelin v4) by specifying it in your `package.json`.

```
"@openzeppelin/contracts": "^4.9.5",
"@openzeppelin/contracts-upgradeable": "^4.9.5",
```

:::

[@matterlabs/hardhat-zksync-upgradable](https://www.npmjs.com/package/@matterlabs/hardhat-zksync-upgradable)

Add the latest version of this plugin to your project with the following command:
Expand Down Expand Up @@ -212,15 +223,29 @@ npx hardhat run SCRIPT_FILE
- This provider is configured in the hardhat config file, by stating the RPC url of the network to connect to.
:::

### Openzeppelin Version
Additionally, in the options section optionally include the folowing arguments to configure the deployment of the proxy and implementation with different deployment types and salts:

The plugin does not work with the latest versions due to a blocker on the `@matterlab/zksync-contracts` package.The solution is to change the development dependencies to the previous version in your `package.json`.
- `deploymentTypeImpl`
- `saltImpl`
- `deploymentTypeProxy`
- `saltProxy`

```
"@openzeppelin/contracts": "^4.9.5",
"@openzeppelin/contracts-upgradeable": "^4.9.5",
const box = await hre.zkUpgrades.deployProxy(deployer.zkWallet, contract, [42],
{ initializer: "initialize",
saltImpl: "0x4273795673417857416686492163276941983664248508133571812215241323",
deploymentTypeImpl: "create2",
saltProxy: "0x5273795673417857416686492163276941983664248508133571812215241323",
deploymentTypeProxy: "create2"
}
);
```

:::info
Allowed values for the deployment type include `create`, `create2`, `createAccount`, and `create2Account`. If this parameter is omitted, the default value will be `create`.
If the salt parameters are omitted, the default value will be `0x0000000000000000000000000000000000000000000000000000000000000000`.
:::

### Hardhat config

```typescript
Expand Down Expand Up @@ -412,6 +437,27 @@ npx hardhat run SCRIPT_FILE
:::
Additionally, in the options section optionally include the `deploymentType` and `salt` arguments to configure deployment type and salt.
```
const beacon = await hre.zkUpgrades.deployBeacon(deployer.zkWallet, boxContract, {
deploymentType: 'create2',
salt: '0x5273795673417857416686492163276941983664248508133571812215241323'
});
await beacon.waitForDeployment();

const box = await hre.zkUpgrades.deployBeaconProxy(deployer.zkWallet, await beacon.getAddress(), boxContract, [42], {
deploymentType: 'create2',
salt: '0x6273795673417857416686492163276941983664248508133571812215241323'
});
await box.waitForDeployment();
```
:::info
Allowed values for the deployment type include `create`, `create2`, `createAccount`, and `create2Account`. If this parameter is omitted, the default value will be `create`.
If the salt parameters are omitted, the default value will be `0x0000000000000000000000000000000000000000000000000000000000000000`.
:::
## Implementation addresses check
Once you deploy the proxy contract, all interactions with your implementation contract go through it.
Expand Down Expand Up @@ -498,11 +544,22 @@ To upgrade the implementation of the transparent upgradeable contract, use the `
await hre.zkUpgrades.upgradeProxy(deployer.zkWallet, <PROXY_ADDRESS>, BoxV2);
```
`upgradeProxy` receives 3 arguments:
`upgradeProxy` receives 4 arguments:
- A zkSync Era wallet.
- The address of the previously deployed box proxy.
- The artifact containing the new `Box2` implementation.
- Other options
Optionally in the other options section include `deploymentType` and `salt` to configure deployment type and salt for deploy of the new implementation.
```
const myContractV2 = await deployer.loadArtifact('BoxV2');
await hre.zkUpgrades.upgradeProxy(deployer.zkWallet, <PROXY_ADDRESS>, BoxV2, {
deploymentType: 'create2',
salt: '0x6273795673417857416686492163276941983664248508133571812215241323'
});
```
## Upgrade UUPS proxy
Expand Down Expand Up @@ -648,6 +705,16 @@ npx hardhat run SCRIPT_FILE
:::
Optionally in the other options section include `deploymentType` and `salt` to configure deployment type and salt for deploy of the new implementation.
```
const myContractV2 = await deployer.loadArtifact('contractV2');
await hre.zkUpgrades.upgradeBeacon(deployer.zkWallet, <BEACON_PROXY_ADDRESS>, myContractV2 {
deploymentType: 'create2',
salt: '0x6273795673417857416686492163276941983664248508133571812215241323'
});
```
# Proxy verification
::: warning
Expand Down Expand Up @@ -803,19 +870,19 @@ const config: HardhatUserConfig = {
## Command list
`yarn hardhat deploy-zksync:proxy --contract-name <contract name or FQN> [<constructor arguments>] [--constructor-args <javascript module name>] [--deployment-type <deployment type>] [--initializer <initialize method>] [--no-compile]`
`yarn hardhat deploy-zksync:proxy --contract-name <contract name or FQN> [<constructor arguments>] [--constructor-args <javascript module name>] [--initializer <initialize method>] [--deployment-type-impl <deployment type>] [--salt-impl <salt>] [--deployment-type-proxy <deployment type>] [--salt-proxy <salt>] [--no-compile]`
Automatically determine whether the deployment requires a Transparent or UUPS proxy, and deploy all necessary contracts accordingly. If the Transparent proxy is chosen, the deployment will include the implementation, admin, and proxy. Alternatively, selecting the UUPS proxy will result in deploying the implementation and proxy.
`yarn hardhat upgrade-zksync:proxy --contract-name <contract name or FQN> --proxy-address <proxy address> [--deployment-type <deployment type>] [--no-compile]`
`yarn hardhat upgrade-zksync:proxy --contract-name <contract name or FQN> --proxy-address <proxy address> [--deployment-type <deployment type>] [--salt <salt>] [--no-compile]`
Upgrade UUPS or Transparent implementation on the specified network.
`yarn hardhat deploy-zksync:beacon --contract-name <contract name or FQN> [<constructor arguments>] [--constructor-args <javascript module name>] [--deployment-type <deployment type>] [--initializer <initialize method>] [--no-compile]`
`yarn hardhat deploy-zksync:beacon --contract-name <contract name or FQN> [<constructor arguments>] [--constructor-args <javascript module name>] [--initializer <initialize method>] [--deployment-type-impl <deployment type>] [--salt-impl <salt>] [--deployment-type-proxy <deployment type>] [--salt-proxy <salt>] [--no-compile]`
Initiates the deployment of the specified implementation, beacon, and proxy on the specified network.
`yarn hardhat upgrade-zksync:beacon --contract-name <contract name or FQN> --beacon-address <beacon address> [--deployment-type <deployment type>] [--no-compile]`
`yarn hardhat upgrade-zksync:beacon --contract-name <contract name or FQN> --beacon-address <beacon address> [--deployment-type <deployment type>] [--salt <salt>] [--no-compile]`
Upgrade beacon implementation on the specified network.
Expand All @@ -839,6 +906,17 @@ module.exports = [
- `--proxy-address <proxy address>` - deployed proxy contract address, e.g. `yarn hardhat upgrade-zksync:proxy --contract-name BoxV2 --proxy-address 0x4bbeEB066eD09B7AEd07bF39EEe0460DFa261520`.
- `--initializer <initializer method>` - initializer method name present in the contract, e.g. `hardhat deploy-zksync:proxy --contract-name Contract --initializer store`. If this parameter is omitted, the default value will be `initialize`.
- `--no-compile`- skip the compilation process, e.g. `hardhat deploy-zksync:beacon --contract-name Contract --no-compile`.
- `--deployment-type` - specify which deployer smart contract function will be called. Permissible values for this parameter include `create`, `create2`, `createAccount`, and `create2Account`. If this parameter is omitted, the default value will be `create`, e.g. `hardhat deploy-zksync:beacon --contract-name Greeter 'Hello' --deployment-type create2`.
- `--deployment-type-proxy` - specify which deployer smart contract function will be called for proxy, e.g. `hardhat deploy-zksync:beacon --contract-name Greeter 'Hello' --deployment-type-proxy create2`.
- `--deployment-type-impl` - specify which deployer smart contract function will be called for implementation, e.g. `hardhat deploy-zksync:beacon --contract-name Greeter 'Hello' --deployment-type-impl create2`.
- `--salt-proxy` - specify which salt will be used in deployment of the proxy, e.g. `hardhat deploy-zksync:beacon --contract-name Greeter 'Hello' --salt-proxy 0x42737956734178574166864921632769419836642485081335718122152413290`.
- `--salt-impl` - specify which salt will be used in deployment of the implementation, e.g. `hardhat deploy-zksync:beacon --contract-name Greeter 'Hello' --salt-impl 0x42737956734178574166864921632769419836642485081335718122152413290`.
- When utilizing the `upgrade-zksync:beacon` or `upgrade-zksync:proxy` tasks, specify the deployment type and salt using the `--deployment-type` and `--salt` arguments respectively.
:::info
Allowed values for the deployment type include `create`, `create2`, `createAccount`, and `create2Account`. If this parameter is omitted, the default value will be `create`.
If the salt parameters are omitted, the default value will be `0x0000000000000000000000000000000000000000000000000000000000000000`.
:::
:::info
The account used for deployment will be the one specified by the `deployerAccount` configuration within the `hardhat.config.ts` file. If no such configuration is present, the account with index `0` will be used.
:::

0 comments on commit c19878c

Please sign in to comment.