Skip to content

Commit

Permalink
update: added example and ci
Browse files Browse the repository at this point in the history
  • Loading branch information
kiriyaga committed Oct 23, 2023
1 parent db3d764 commit c53a962
Show file tree
Hide file tree
Showing 17 changed files with 324 additions and 208 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,43 @@ jobs:
run: |
cd packages/hardhat-zksync-verify-vyper
yarn test
zksync2js:
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 zksync2js example
run: |
cd packages/hardhat-zksync-zksync2js
yarn hardhat compile
yarn test
- name: Show logs
if: always()
run: |
cat server.log
59 changes: 59 additions & 0 deletions .github/workflows/publish-zksync2js.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Publish zksync2js Plugin

on:
push:
tags:
- '@matterlabs/hardhat-zksync-zksync2js@*'

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: '16'
registry-url: 'https://registry.npmjs.org'
cache: 'yarn'

- name: Setup environment
run: yarn && yarn build

- name: Publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPMJS_NPM_MATTERLABS_AUTOMATION_TOKEN }}
run: |
if [[ ${{ github.ref }} == *"beta"* ]]; then
echo "Publishing package with beta tag"
npm publish @matterlabs/hardhat-zksync-zksync2js --tag beta --workspace=packages/hardhat-zksync-zksync2js --access=public
elif [[ ${{ github.ref }} == *"alpha"* ]]; then
echo "Publishing package with alpha tag"
npm publish @matterlabs/hardhat-zksync-zksync2js --tag alpha --workspace=packages/hardhat-zksync-zksync2js --access=public
else
echo "Publishing package with latest tag"
npm publish @matterlabs/hardhat-zksync-zksync2js --tag latest --workspace=packages/hardhat-zksync-zksync2js --access=public
fi
- name: Create github release from tags
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [[ ${{ github.ref }} != *"beta"* ]] && [[ ${{ github.ref }} != *"alpha"* ]]; then
node scripts/create-release-from-tags/run.js --package hardhat-zksync-zksync2js
else
echo "Skipping github release creation for beta and alpha tags"
fi
- name: Create the MM Message
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh -R matter-labs/hardhat-zksync release view "$GITHUB_REF_NAME" --json tagName,body --template '## {{.tagName}} {{"\n"}}{{.body}}' > ./release_info
jq --null-input --arg text "$(cat ./release_info)" '{"text": $text}' > mattermost.json
- uses: mattermost/action-mattermost-notify@master
env:
MATTERMOST_USERNAME: "Hardhat Release Bot"
MATTERMOST_WEBHOOK_URL: ${{ secrets.MATTERMOST_URL }}

2 changes: 1 addition & 1 deletion config/typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "ES2021",
"target": "ES2017",
"module": "commonjs",
"declaration": true,
"declarationMap": true,
Expand Down
7 changes: 7 additions & 0 deletions examples/zksync2js-example/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: [`${__dirname}/../../config/eslint/eslintrc.js`],
parserOptions: {
project: `${__dirname}/tsconfig.json`,
sourceType: "module",
},
};
3 changes: 3 additions & 0 deletions examples/zksync2js-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cache
artifacts
contracts/tmp
61 changes: 61 additions & 0 deletions examples/zksync2js-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# zkSync 2.0 deploy environment example

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

## Prerequisites

- node.js 14.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 `zkTestnet` and `goerli` used as the underlying layer 1 network:
```ts
import "@matterlabs/hardhat-zksync-deploy";
import { HardhatUserConfig } from 'hardhat/types';

const config: HardhatUserConfig = {
networks: {
goerli: {
url: 'https://goerli.infura.io/v3/<API_KEY>' // you can use either the URL of the Ethereum Web3 RPC, or the identifier of the network (e.g. `mainnet` or `rinkeby`)
},
zkTestnet: {
url: 'https://zksync2-testnet.zksync.dev', // you should use the URL of the zkSync network RPC
ethNetwork: 'goerli',
zksync: true
},
}
};

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 in the `deploy` folder.
- To run a specific script, add the `--script` argument, e.g. `--script 001_deploy.ts`.
- To run on a specific zkSync network, use standard hardhat `--network` argument, e.g. `--network zkTestnet`
(with `zkTestnet` 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.
19 changes: 19 additions & 0 deletions examples/zksync2js-example/contracts/Greeter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;
pragma abicoder v2;

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;
}
}
16 changes: 16 additions & 0 deletions examples/zksync2js-example/deploy/001_deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import chalk from 'chalk';
import { Contract } from 'zksync2-js';

export default async function (hre: HardhatRuntimeEnvironment) {
console.info(chalk.yellow(`Running deploy`));

const greeterFactory = await hre.zksync2js.getContractFactory("Greeter");
const greeter = await greeterFactory.deploy("Hello, world!") as Contract;
await greeter.waitForDeployment();

console.info(chalk.green(`Greeter deployed to: ${await greeter.getAddress()}`));
console.info(chalk.green(`Greeter greeting set to: ${await greeter.greet()}`));
await greeter.setGreeting("Hello, world again!");
console.info(chalk.green(`Greeter greeting set to: ${await greeter.greet()}`));
}
30 changes: 30 additions & 0 deletions examples/zksync2js-example/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import '@matterlabs/hardhat-zksync-deploy';
import '@matterlabs/hardhat-zksync-solc';
import '@matterlabs/hardhat-zksync-zksync2js';

import { HardhatUserConfig, task } from 'hardhat/config';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

const config: HardhatUserConfig = {
zksolc: {
compilerSource: 'binary',
settings: {
isSystem: true,
optimizer: {
enabled: true,
},
}
},
networks: {
hardhat: {
zksync: true,
},
},
// 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;
45 changes: 45 additions & 0 deletions examples/zksync2js-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "harhat-zksync-example-zksync2js",
"version": "0.1.0",
"author": "Matter Labs",
"license": "MIT",
"scripts": {
"lint": "yarn prettier --check && yarn eslint",
"lint:fix": "yarn eslint --fix",
"fmt": "yarn prettier --write",
"eslint": "eslint deploy/*.ts",
"prettier": "prettier deploy/*.ts",
"test": "mocha test/tests.ts --exit",
"build": "tsc --build .",
"clean": "rimraf dist"
},
"devDependencies": {
"@types/node": "^18.11.17",
"@typescript-eslint/eslint-plugin": "4.29.2",
"@typescript-eslint/parser": "5.13.0",
"eslint": "^8.10.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-import": "2.25.4",
"eslint-plugin-prettier": "3.4.0",
"prettier": "2.3.2",
"rimraf": "^3.0.2",
"ts-node": "^10.6.0",
"typescript": "^4.6.2"
},
"dependencies": {
"@matterlabs/hardhat-zksync-deploy": "link:../../packages/hardhat-zksync-deploy",
"@matterlabs/hardhat-zksync-solc": "link:../../packages/hardhat-zksync-solc",
"@matterlabs/hardhat-zksync-zksync2js": "link:../../packages/hardhat-zksync-zksync2js",
"chalk": "4.1.2",
"hardhat": "^2.14.0",
"ethers": "^6.7.1",
"zksync2-js": "^0.2.0-beta.0"
},
"prettier": {
"tabWidth": 4,
"printWidth": 120,
"parser": "typescript",
"singleQuote": true,
"bracketSpacing": true
}
}
18 changes: 18 additions & 0 deletions examples/zksync2js-example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"outDir": "dist"
},
"include": [
"./hardhat.config.ts",
"./scripts",
"./deploy",
"./test",
"typechain/**/*"
]
}
4 changes: 2 additions & 2 deletions packages/hardhat-zksync-verify-vyper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"eslint-config-prettier": "8.4.0",
"eslint-plugin-import": "2.25.4",
"eslint-plugin-prettier": "4.0.0",
"hardhat": "2.14.0",
"hardhat": "^2.14.0",
"mocha": "^9.2.1",
"prettier": "2.5.1",
"rimraf": "^3.0.2",
Expand All @@ -64,7 +64,7 @@
"typescript": "^4.6.2"
},
"peerDependencies": {
"hardhat": "2.14.0"
"hardhat": "^2.14.0"
},
"prettier": {
"tabWidth": 4,
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-zksync-vyper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"eslint-config-prettier": "8.4.0",
"eslint-plugin-import": "2.25.4",
"eslint-plugin-prettier": "4.0.0",
"hardhat": "2.14.0",
"hardhat": "^2.14.0",
"mocha": "^9.2.1",
"prettier": "2.5.1",
"rimraf": "^3.0.2",
Expand All @@ -66,7 +66,7 @@
},
"peerDependencies": {
"@nomiclabs/hardhat-vyper": "^3.0.3",
"hardhat": "2.14.0"
"hardhat": "^2.14.0"
},
"prettier": {
"tabWidth": 4,
Expand Down
10 changes: 5 additions & 5 deletions packages/hardhat-zksync-zksync2js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"homepage": "https://github.com/matter-labs/hardhat-zksync/tree/main/packages/hardhat-zksync-zksync2js",
"author": "Matter Labs",
"license": "MIT",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"keywords": [
"ethereum",
"smart-contracts",
Expand Down Expand Up @@ -50,20 +50,20 @@
"eslint-plugin-import": "2.27.5",
"eslint-plugin-no-only-tests": "3.0.0",
"eslint-plugin-prettier": "3.4.0",
"hardhat": "^2.18.2",
"hardhat": "^2.14.0",
"mocha": "^10.0.0",
"prettier": "2.4.1",
"rimraf": "^5.0.5",
"sinon": "^9.0.0",
"ts-node": "^10.9.1",
"typescript": "~5.0.0",
"zksync2-js": "0.1.0",
"zksync2-js": "^0.2.0-beta.0",
"@typechain/ethers-v6": "^0.5.0",
"rlp": "3.0.0",
"ethers": "^6.7.1"
},
"peerDependencies": {
"zksync2-js": "0.2.0",
"zksync2-js": "^0.2.0-beta.0",
"ethers": "^6.7.1"
},
"prettier": {
Expand Down
Loading

0 comments on commit c53a962

Please sign in to comment.