Skip to content

Commit

Permalink
feat: support for script tags, order, integrated deployer inside HRE (#…
Browse files Browse the repository at this point in the history
…849)

* feat: support for script tags, order, integrated deployer inside HRE

* chore: rename new project name and update ci noninline library command

* chore: add deploy tests in ci

* chore: update solc and vyper versions in examples

* fix: update deploy cache logic, script load path support for windows

* chore: run lint formatter

* chore: update readme files

---------

Co-authored-by: Marko Arambasic <makiarambasic@gmail.com>
kiriyaga-txfusion and kiriyaga authored Mar 6, 2024

Verified

This commit was signed with the committer’s verified signature.
1 parent 60d7505 commit d8110e1
Showing 59 changed files with 2,999 additions and 614 deletions.
52 changes: 49 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -52,9 +52,9 @@ jobs:
# cd packages/hardhat-zksync-vyper
# yarn test

deploy:
examples:
runs-on: ubuntu-latest
name: deploy
name: examples
steps:
- uses: actions/checkout@v2

@@ -87,6 +87,12 @@ jobs:
cd examples/basic-example
yarn hardhat compile
yarn hardhat deploy-zksync
- name: Test deploy example
run: |
cd examples/deploy-example
yarn hardhat compile
yarn hardhat deploy-zksync
- name: Test node example
run: |
@@ -98,7 +104,7 @@ jobs:
run: |
cd examples/noninline-libraries-example
yarn hardhat compile
yarn hardhat deploy-zksync:libraries --private-key 0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110
yarn hardhat deploy-zksync:libraries --private-key-or-index 0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110
yarn hardhat compile
yarn hardhat deploy-zksync
@@ -232,6 +238,46 @@ jobs:
cd packages/hardhat-zksync-verify
yarn test
deploy:
runs-on: ubuntu-latest
name: deploy
steps:
- uses: actions/checkout@v2

- uses: actions/checkout@v2
with:
repository: matter-labs/local-setup
path: local-setup

- name: Run server
run: |
cd local-setup
./start.sh &>../server.log &
- uses: actions/setup-node@v2
with:
node-version: "16"
cache: yarn

- name: Setup environment
run: |
yarn install
yarn build
- name: Wait until server is up
run: |
while ! curl -s -X POST -d '{"jsonrpc":"2.0","method":"net_version","id":1}' -H 'Content-Type: application/json' 0.0.0.0:3050; do sleep 1; done
- name: Test deploy package
run: |
cd packages/hardhat-zksync-deploy
yarn test
- name: Show logs
if: always()
run: |
cat server.log
node:
runs-on: ubuntu-latest
name: node
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -24,7 +24,8 @@ build-test/
dist
artifacts-zk/
cache-zk/

deployments/
deployments-zk/
# Code coverage artifacts
coverage
.nyc_output
2 changes: 1 addition & 1 deletion examples/basic-example/package.json
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@
},
"dependencies": {
"@matterlabs/hardhat-zksync-deploy": "link:../../packages/hardhat-zksync-deploy",
"@matterlabs/hardhat-zksync-solc": "^1.0.5",
"@matterlabs/hardhat-zksync-solc": "^1.1.4",
"chalk": "4.1.2",
"hardhat": "^2.14.0",
"ethers": "~5.7.2",
7 changes: 7 additions & 0 deletions examples/deploy-example/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: [`${__dirname}/../../config/eslint/eslintrc.cjs`],
parserOptions: {
project: `${__dirname}/tsconfig.json`,
sourceType: "module",
},
};
4 changes: 4 additions & 0 deletions examples/deploy-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cache
artifacts
contracts/tmp
deployments
63 changes: 63 additions & 0 deletions examples/deploy-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# zkSync Era deploy environment example

This project demonstrates how to compile and deploy your contracts in zkSync Era using the Hardhat plugins.

## Prerequisites

- node.js 16.x or later.
- yarn.

## Configuration

Plugin configuration is located in [`hardhat.config.ts`](./hardhat.config.ts).
You should only change the zkSync network configuration.

`hardhat.config.ts` example with zkSync network configured with the name `zkSyncNetwork` and `ethNetwork` used as the underlying layer 1 network:
```ts
import "@matterlabs/hardhat-zksync-deploy";
import { HardhatUserConfig } from 'hardhat/types';

const config: HardhatUserConfig = {
networks: {
ethNetwork: {
url: 'http://0.0.0.0:8545',
},
zkSyncNetwork: {
url: 'http://0.0.0.0:3050',
ethNetwork: 'ethNetwork',
zksync: true,
deployPaths: ['deploy-zkSync', 'deploy'],
accounts: ['0xac1e735be8536c6534bb4f17f06f6afc73b2b5ba84ac2cfb12f7461b20c0bbe3', '0x28a574ab2de8a00364d5dd4b07c4f2f574ef7fcc2a86a197f65abaec836d1959'],
},
}
};

export default config;
```

## Usage

Before using plugins, you need to build them first

```sh
# Run the following in the *root* of the repo.
yarn
yarn build
```

After that you should be able to run plugins:

```sh
# Run the following in `examples/basic-example` folder.
yarn
yarn hardhat compile
yarn hardhat deploy-zksync
```

- `yarn hardhat compile`: compiles all the contracts in the `contracts` folder.
- `yarn hardhat deploy-zksync`: runs all the deploy scripts.
- To run a specific script, add the `--script` argument, e.g. `--script 002_deploy.ts`.
- To run on a specific zkSync network, use standard hardhat `--network` argument, e.g. `--network zkSyncNetworkV2`
(with `zkSyncNetwork` network specified in the `hardhat.config` networks section, with the `zksync` flag set to `true` and `ethNetwork` specified).

If you don't specify zkSync network (`--network`), `local-setup` with <http://localhost:8545> (Ethereum RPC URL) and <http://localhost:3050> (zkSync RPC URL) will be used.
13 changes: 13 additions & 0 deletions examples/deploy-example/contracts/Constant.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;
pragma abicoder v2;

contract Constant {
uint c = 42;
constructor() {}

function getValue() public view returns (uint) {
return c;
}
}
7 changes: 7 additions & 0 deletions examples/deploy-example/contracts/Foo.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

contract Foo {
string public name = "Foo";
}
18 changes: 18 additions & 0 deletions examples/deploy-example/contracts/Greeter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

contract Greeter {
string greeting;
constructor(string memory _greeting) {
greeting = _greeting;
}

function greet() public view returns (string memory) {
return greeting;
}

function setGreeting(string memory _greeting) public {
greeting = _greeting;
}
}
36 changes: 36 additions & 0 deletions examples/deploy-example/deploy-zkSync/000_deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import * as ethers from 'ethers';
import * as zk from 'zksync-ethers';
import chalk from 'chalk';

const deployScript = async function (hre: HardhatRuntimeEnvironment) {
console.info(chalk.yellow(`Running deploy script for the Foo contract`));

const zkWallet = await hre.deployer.getWallet(0);
hre.deployer.setWallet(zkWallet);

// Deposit some funds to L2 in order to be able to perform deposits.
const depositHandle = await zkWallet.deposit({
to: zkWallet.address,
token: zk.utils.ETH_ADDRESS,
amount: ethers.utils.parseEther('0.01'),
});
await depositHandle.wait();

// Load the artifact we want to deploy.
const artifact = await hre.deployer.loadArtifact('Foo');

// Deploy this contract. The returned object will be of a `Contract` type, similarly to ones in `ethers`.
// This contract has no constructor arguments.
const factoryContract = await hre.deployer.deploy(artifact, []);

// Show the contract info.
const contractAddress = factoryContract.address;
console.info(chalk.green(`${artifact.contractName} was deployed to ${contractAddress}!`));
}

export default deployScript;

deployScript.tags = ['second'];
deployScript.dependencies = ['first'];
deployScript.priority = 800;
29 changes: 29 additions & 0 deletions examples/deploy-example/deploy-zkSync/001_deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const chalk = require('chalk');

// An example of a deploy script which will deploy and call a simple contract.
var deployScript = async function (hre) {
console.info(chalk.yellow(`Running deploy script for the Greeter contract`));

// Load the artifact we want to deploy.
const artifact = await deployer.loadArtifact('Greeter');

// Deploy this contract. The returned object will be of a `Contract` type, similarly to ones in `ethers`.
// `greeting` is an argument for contract constructor.
const greeting = 'Hi there!';
const greeterContract = await hre.deployer.deploy(artifact, [greeting], true);

// Show the contract info.
const contractAddress = greeterContract.address;
console.info(chalk.green(`${artifact.contractName} was deployed to ${contractAddress}!`));

// Call the deployed contract.
const greetingFromContract = await greeterContract.greet();
if (greetingFromContract == greeting) {
console.info(chalk.green(`Successful greeting from the contract`));
} else {
throw new Error(`Contract returned unexpected greeting: ${greetingFromContract}`);
}
};

module.exports["default"] = deployScript;
deployScript.priority = 1500;
21 changes: 21 additions & 0 deletions examples/deploy-example/deploy-zkSync/002_deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import chalk from 'chalk';

const deployScript = async function (hre: HardhatRuntimeEnvironment) {
console.info(chalk.yellow(`Running deploy script for the Constant contract`));

// Load the artifact we want to deploy.
const artifact = await hre.deployer.loadArtifact('Constant');

// Deploy this contract. The returned object will be of a `Contract` type, similarly to ones in `ethers`.
// This contract has no constructor arguments.
const factoryContract = await hre.deployer.deploy(artifact, []);

// Show the contract info.
const contractAddress = factoryContract.address;
console.info(chalk.green(`${artifact.contractName} was deployed to ${contractAddress}!`));
}

export default deployScript;

deployScript.tags = ['first'];
21 changes: 21 additions & 0 deletions examples/deploy-example/deploy/003_deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import chalk from 'chalk';

const deployScript = async function (hre: HardhatRuntimeEnvironment) {
console.info(chalk.yellow(`Running deploy script for the Constant contract from deploy folder`));

// Load the artifact we want to deploy.
const artifact = await hre.deployer.loadArtifact('Constant');

// Deploy this contract. The returned object will be of a `Contract` type, similarly to ones in `ethers`.
// This contract has no constructor arguments.
const factoryContract = await hre.deployer.deploy(artifact, []);

// Show the contract info.
const contractAddress = factoryContract.address;
console.info(chalk.green(`${artifact.contractName} was deployed to ${contractAddress}!`));
}

export default deployScript;

deployScript.tags = ['first'];
51 changes: 51 additions & 0 deletions examples/deploy-example/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import '@matterlabs/hardhat-zksync-deploy';
import '@matterlabs/hardhat-zksync-solc';

import { HardhatUserConfig } from 'hardhat/config';

const config: HardhatUserConfig = {
zksolc: {
compilerSource: 'binary',
settings: {
isSystem: true,
optimizer: {
enabled: true,
},
}
},
deployerAccounts: {
'zkSyncNetwork': 1
},
defaultNetwork: "zkSyncNetwork",
networks: {
hardhat: {
zksync: true,
},
ethNetwork: {
url: 'http://0.0.0.0:8545',
},
zkSyncNetwork: {
url: 'http://0.0.0.0:3050',
ethNetwork: 'ethNetwork',
zksync: true,
deployPaths: ['deploy-zkSync', 'deploy'],
accounts: ['0xac1e735be8536c6534bb4f17f06f6afc73b2b5ba84ac2cfb12f7461b20c0bbe3', '0x28a574ab2de8a00364d5dd4b07c4f2f574ef7fcc2a86a197f65abaec836d1959'],
},
zkSyncNetworkV2: {
url: 'http://0.0.0.0:3050',
ethNetwork: 'ethNetwork',
zksync: true,
forceDeploy: false,
accounts: {
mnemonic: 'stuff slice staff easily soup parent arm payment cotton trade scatter struggle'
}
}
},
// Docker image only works for solidity ^0.8.0.
// For earlier versions you need to use binary releases of zksolc.
solidity: {
version: '0.8.17',
},
};

export default config;
Loading

0 comments on commit d8110e1

Please sign in to comment.