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

Feat: Introduce zkSync #10

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ cache
artifacts
deployments

cache-zk
artifacts-zk
deployments-zk

typechain-types
yarn-error.log
.DS_Store
45 changes: 44 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import "hardhat-gas-reporter"
import "solidity-coverage"
import dotenv from "dotenv"
import type { HttpNetworkUserConfig } from "hardhat/types"
import "@matterlabs/hardhat-zksync-solc"
import "@matterlabs/hardhat-zksync-deploy"
import "@matterlabs/hardhat-zksync-verify"

dotenv.config()

import "./tasks/deploy-zksync"
import "./tasks/deploy-mastercopies"
import "./tasks/deploy-mastercopy"
import "./tasks/extract-mastercopy"
Expand Down Expand Up @@ -43,11 +47,26 @@ const config = {
viaIR: true,
},
},
zksolc: {
version: "1.5.7",
compilerSource: "binary",
settings: {
optimizer: {
enabled: true,
runs: 10000,
},
libraries: { // GENERATED BY hardhat deploy-zksync:libraries --network zkSyncSepoliaTestnet
"contracts/MultisendEncoder.sol": {
MultisendEncoder: "0xfdb2bC5e8d27c339C2aC34692A448d2C7dBF2388",
},
},
},
},
sourcify: {
enabled: true,
},
networks: {
hardhat: { tags: ["moduleProxy"] },
hardhat: { zksync: true },
mainnet: {
...sharedNetworkConfig,
url: `https://mainnet.infura.io/v3/${process.env.INFURA_KEY}`,
Expand All @@ -65,6 +84,20 @@ const config = {
url: `https://sepolia.infura.io/v3/${process.env.INFURA_KEY}`,
tags: ["moduleMastercopy"],
},
zkSyncMainnet: {
url: "https://mainnet.era.zksync.io",
ethNetwork: "mainnet",
zksync: true,
accounts: sharedNetworkConfig.accounts,
verifyURL: "https://zksync2-mainnet-explorer.zksync.io/contract_verification",
},
zkSyncSepoliaTestnet: {
url: "https://sepolia.era.zksync.dev",
ethNetwork: "sepolia",
accounts: sharedNetworkConfig.accounts,
zksync: true,
verifyURL: "https://explorer.sepolia.era.zksync.dev/contract_verification",
},
},

namedAccounts: {
Expand All @@ -78,6 +111,16 @@ const config = {
},
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY,
customChains: [
{
network: "zkSyncSepoliaTestnet",
chainId: 300,
urls: {
apiURL: "https://explorer.sepolia.era.zksync.dev/contract_verification",
browserURL: "https://zksync2-testnet.zkscan.io/",
},
},
],
},
}

Expand Down
35 changes: 20 additions & 15 deletions mastercopies.json

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"deploy": "hardhat deploy",
"reconstruct:mastercopy": "yarn run build && yarn hardhat mastercopy:reconstruct --network",
"extract:mastercopy": "yarn run build && yarn hardhat extract:mastercopy",
"deploy:mastercopies": "yarn hardhat deploy:mastercopies --network",
"deploy:zksync": "yarn hardhat deploy:zksync --network",
"deploy:mastercopies": "yarn hardhat deploy:mastercopies ",
"deploy:mastercopy": "yarn hardhat deploy:mastercopy --network",
"verify:mastercopies": "yarn hardhat verify:mastercopies --network",
"verify:mastercopy": "yarn hardhat verify:mastercopy --network",
Expand All @@ -39,6 +40,8 @@
"devDependencies": {
"@gnosis-guild/zodiac-core": "^2.0.4",
"@gnosis.pm/safe-contracts": "^1.3.0",
"@matterlabs/hardhat-zksync-deploy": "^1.6.0",
"@matterlabs/hardhat-zksync-verify": "^1.7.0",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.7",
"@nomicfoundation/hardhat-ethers": "^3.0.6",
"@nomicfoundation/hardhat-ignition": "^0.15.5",
Expand Down Expand Up @@ -73,11 +76,13 @@
"solidity-coverage": "^0.8.12",
"ts-node": "^10.7.0",
"typechain": "^8.1.1",
"typescript": "5.5.4"
"typescript": "5.5.4",
"zksync-ethers": "^6.11.2"
},
"dependencies": {
"@openzeppelin/contracts": "^4.5.0",
"@openzeppelin/contracts-upgradeable": "4.9.3",
"hardhat-contract-sizer": "^2.6.1"
"hardhat-contract-sizer": "^2.6.1",
"zksync-web3": "^0.17.1"
}
}
4 changes: 2 additions & 2 deletions tasks/deploy-mastercopies.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { task } from "hardhat/config"

import { readMastercopies, deployMastercopy } from "@gnosis-guild/zodiac-core"
import { deployMastercopy, readMastercopies } from "@gnosis-guild/zodiac-core"
import { createEIP1193 } from "./create-EIP1193"

task(
Expand All @@ -22,6 +21,7 @@ task(
console.log(`⏳ ${contractName}@${contractVersion}: Deployment starting...`)
},
})

if (noop) {
console.log(`🔄 ${contractName}@${contractVersion}: Already deployed at ${address}`)
} else {
Expand Down
73 changes: 73 additions & 0 deletions tasks/deploy-zksync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { task } from "hardhat/config"

import { Deployer } from "@matterlabs/hardhat-zksync-deploy"
import { Wallet } from "zksync-ethers"
import { ethers } from "ethers"
import { ZkSyncArtifact } from "@matterlabs/hardhat-zksync-deploy/dist/types"
import { HardhatRuntimeEnvironment } from "hardhat/types"

const ERC_CONTRACT_ARGS = ["0x0000000000000000000000000000000000000001", "0x", "0x"]

// 🚀 MultisendEncoder: Deployed at 0xD9920581E8DabbC358A616BE09b88de8cADFfAeF
// ⏳ ERC20Votes: Deployment starting...
// The deployment is estimated to cost 0.0009026994 ETH
// 🚀 ERC20Votes: Deployed at 0x7a81046A24A40B5e6FEB0285ebBc3236749EF2fC
// ⏳ ERC721Votes: Deployment starting...
// The deployment is estimated to cost 0.0009923398 ETH
// 🚀 ERC721Votes: Deployed at 0x2E5AC7989A9194F425D0F2fa92A48381810E8F6B
// ⏳ OZGovernorModule: Deployment starting...
// The deployment is estimated to cost 0.00176351265 ETH
// 🚀 OZGovernorModule: Deployed at 0x2F7faFB5CAA3Aa3BD96A0F359f5a20Acb512241A
const deployContact = async (
hre: HardhatRuntimeEnvironment,
deployer: Deployer,
artifact: ZkSyncArtifact,
constructorArguments: any[],
) => {
console.log(`⏳ ${artifact.contractName}: Deployment starting...`)
const deploymentFee = await deployer.estimateDeployFee(artifact, constructorArguments)
const parsedFee = ethers.formatEther(deploymentFee)
console.log(`The deployment is estimated to cost ${parsedFee} ETH`)
const contract = await deployer.deploy(artifact, constructorArguments)
const contractAddress = await contract.getAddress()
console.log(`🚀 ${artifact.contractName}: Deployed at ${contractAddress}`)
// const verificationId = await hre.run("verify:verify", {
// address: contractAddress,
// contract: `contracts/${artifact.contractName}.sol:${artifact.contractName}`,
// constructorArguments,
// })
// console.log(`🚀 ${artifact.contractName}: VerificationId ${verificationId}`)
return contractAddress
}

task("deploy:zksync", "TODO").setAction(async (_, hre) => {
const zkWallet = new Wallet(process.env.PRIVATE_KEY!)
const deployerZkSync = new Deployer(hre, zkWallet)

//Deploy MultisendEncoder
const multisendEncoderArtifact = await deployerZkSync.loadArtifact("MultisendEncoder")
const multisendAddress = await deployContact(hre, deployerZkSync, multisendEncoderArtifact, [])

// Deploy ERC20Votes
const erc20VotesArtifact = await deployerZkSync.loadArtifact("ERC20Votes")
const erc20Address = await deployContact(hre, deployerZkSync, erc20VotesArtifact, ERC_CONTRACT_ARGS)

// Deploy ERC721Votes
const erc721VotesArtifact = await deployerZkSync.loadArtifact("ERC721Votes")
await deployContact(hre, deployerZkSync, erc721VotesArtifact, ERC_CONTRACT_ARGS)

// Deploy OZGovernorModule
const ozModuleArtifact = await deployerZkSync.loadArtifact("OZGovernorModule")
await deployContact(hre, deployerZkSync, ozModuleArtifact, [
"0x0000000000000000000000000000000000000001",
"0x0000000000000000000000000000000000000001",
"0x0000000000000000000000000000000000000001",
erc20Address,
"",
0,
100,
0,
10,
0,
])
})
14 changes: 13 additions & 1 deletion tasks/extract-mastercopy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ task("extract:mastercopy", "Extracts and persists current mastercopy build artif
sourceName: "contracts/OZGovernorModule.sol",
})

// address _owner,
// address _target,
// address _multisend,
// address _token,
// string memory _name,
// uint256 _votingDelay,
// uint256 _votingPeriod,

// uint256 _proposalThreshold,
// uint256 _quorum,
// uint64 _initialVoteExtension
console.log("HELLO " + erc20VotesAddress)
writeMastercopyFromBuild({
contractVersion: packageJson.version,
contractName: "OZGovernorModule",
Expand All @@ -68,7 +80,7 @@ task("extract:mastercopy", "Extracts and persists current mastercopy build artif
"uint256",
"uint64",
],
values: [AddressOne, AddressOne, AddressOne, erc20VotesAddress, "", 0, 100, 0, 0, 0],
values: [AddressOne, AddressOne, AddressOne, erc20VotesAddress, "", 0, 100, 0, 10, 0],
},
salt: "0x0000000000000000000000000000000000000000000000000000000000000000",
})
Expand Down
Loading
Loading