Skip to content

Commit

Permalink
feat: add zksync support to the project
Browse files Browse the repository at this point in the history
  • Loading branch information
mmv08 committed Aug 26, 2024
1 parent af53bdf commit 2891ee8
Show file tree
Hide file tree
Showing 57 changed files with 3,547 additions and 991 deletions.
4 changes: 4 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ SAFE_CONTRACT_UNDER_TEST="Safe"
SOLIDITY_VERSION= # Example: '0.8.19'
# For running coverage tests, `details` section of solidity settings are required, else could be removed.
SOLIDITY_SETTINGS= # Example: '{"viaIR":true,"optimizer":{"enabled":true, "details": {"yul": true, "yulDetails": { "optimizerSteps": ""}}}}'
# Set to 1 to run hardhat in zksync mode. This will enable the ZK compiler and run the hardhat node in zksync mode.
HARDHAT_ENABLE_ZKSYNC=0
# Sets hardhat chain id. In general, you don't need this, it's only used for testing the SafeToL2Setup contract.
HARDHAT_CHAIN_ID=31337
# (Optional) Hardhat-deploy only supports zksync deployment if the private key for the account is provided. Specify the private key here.
ZKSYNC_DEPLOYER_PK="0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110"
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
cache: "npm"
- run: npm ci
- run: npm run lint:ts:prettier
- run: npm run build:ts:dev # runs typecheck
- run: npm run lint:ts

tests:
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
build/
node_modules/
.DS_Store
Expand All @@ -18,4 +19,7 @@ typechain-types
# Certora Formal Verification related files
.certora_internal
.certora_recent_jobs.json
.zip-output-url.txt
.zip-output-url.txt

# zksync era node log
era_test_node.log
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run lint:sol:prettier
npm run lint:ts:prettier
npm run lint:sol
Expand Down
37 changes: 36 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import "@nomicfoundation/hardhat-toolbox";
import type { HardhatUserConfig, HttpNetworkUserConfig } from "hardhat/types";
import "@matterlabs/hardhat-zksync-deploy";
import "@matterlabs/hardhat-zksync-solc";
import "@matterlabs/hardhat-zksync-verify";
import "@matterlabs/hardhat-zksync-ethers";
import "@matterlabs/hardhat-zksync-node";
import "hardhat-deploy";
import dotenv from "dotenv";
import yargs from "yargs";
Expand All @@ -16,7 +21,17 @@ const argv = yargs

// Load environment variables.
dotenv.config();
const { NODE_URL, INFURA_KEY, MNEMONIC, ETHERSCAN_API_KEY, PK, SOLIDITY_VERSION, SOLIDITY_SETTINGS, HARDHAT_CHAIN_ID } = process.env;
const {
NODE_URL,
INFURA_KEY,
MNEMONIC,
ETHERSCAN_API_KEY,
PK,
SOLIDITY_VERSION,
SOLIDITY_SETTINGS,
HARDHAT_ENABLE_ZKSYNC = "0",
HARDHAT_CHAIN_ID = 31337,
} = process.env;

const DEFAULT_MNEMONIC = "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat";

Expand All @@ -36,6 +51,7 @@ if (["mainnet", "rinkeby", "kovan", "goerli", "ropsten", "mumbai", "polygon"].in
import "./src/tasks/local_verify";
import "./src/tasks/deploy_contracts";
import "./src/tasks/show_codesize";
import "./src/tasks/zk";
import { BigNumber } from "@ethersproject/bignumber";
import { DeterministicDeploymentInfo } from "hardhat-deploy/dist/types";

Expand Down Expand Up @@ -73,11 +89,16 @@ const userConfig: HardhatUserConfig = {
solidity: {
compilers: [{ version: primarySolidityVersion, settings: soliditySettings }, { version: defaultSolidityVersion }],
},
zksolc: {
version: "1.5.2",
settings: {},
},
networks: {
hardhat: {
allowUnlimitedContractSize: true,
blockGasLimit: 100000000,
gas: 100000000,
zksync: HARDHAT_ENABLE_ZKSYNC === "1",
chainId: typeof HARDHAT_CHAIN_ID === "string" && !Number.isNaN(parseInt(HARDHAT_CHAIN_ID)) ? parseInt(HARDHAT_CHAIN_ID) : 31337,
},
mainnet: {
Expand Down Expand Up @@ -116,6 +137,20 @@ const userConfig: HardhatUserConfig = {
...sharedNetworkConfig,
url: `https://api.avax.network/ext/bc/C/rpc`,
},
zkSyncMainnet: {
...sharedNetworkConfig,
url: "https://mainnet.era.zksync.io",
ethNetwork: "mainnet",
zksync: true,
verifyURL: "https://zksync2-mainnet-explorer.zksync.io/contract_verification",
},
zkSyncTestnet: {
...sharedNetworkConfig,
url: "https://testnet.era.zksync.dev",
ethNetwork: "goerli",
zksync: true,
verifyURL: "https://zksync2-testnet-explorer.zksync.dev/contract_verification",
},
},
deterministicDeployment,
namedAccounts: {
Expand Down
Loading

0 comments on commit 2891ee8

Please sign in to comment.