Skip to content

Commit

Permalink
Update scripts for zkSync
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolev-igor committed Jul 28, 2023
1 parent e1326f9 commit 6dd2c08
Show file tree
Hide file tree
Showing 10 changed files with 12,180 additions and 17,028 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ node_modules/
build/
site/
coverage
artifacts
cache
artifacts*
cache*
coverage.json
.log
.env
Expand Down
15 changes: 15 additions & 0 deletions deploy/1_deploy_router_zksync_era.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";

import dotenv from 'dotenv';
dotenv.config();

import deployContractZkSyncEra from './deployContractZkSyncEra';

export default async function (hre: HardhatRuntimeEnvironment) {
try {
await deployContractZkSyncEra(hre, 'router/', 'Router');
} catch (error) {
console.error(error);
process.exit(1);
}
}
16 changes: 16 additions & 0 deletions deploy/2_deploy_simple_caller_zksync_era.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

import { HardhatRuntimeEnvironment } from "hardhat/types";

import dotenv from 'dotenv';
dotenv.config();

import deployContractZkSyncEra from './deployContractZkSyncEra';

export default async function (hre: HardhatRuntimeEnvironment) {
try {
await deployContractZkSyncEra(hre, 'callers/', 'SimpleCaller');
} catch (error) {
console.error(error);
process.exit(1);
}
}
47 changes: 47 additions & 0 deletions deploy/3_setup_router_fee_zksync_era.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Provider } from "zksync-web3";
import * as ethers from 'ethers';

import dotenv from 'dotenv';
dotenv.config();

import deploymentAddresses from '../scripts/deployment';
import * as ContractArtifact from "../artifacts-zk/contracts/router/Router.sol/Router.json";

export default async function (hre: HardhatRuntimeEnvironment) {
try {
// @ts-ignore
const provider = new Provider(hre.userConfig.networks?.zkSyncEra?.url);

const PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY || "";
const signer = new ethers.Wallet(PRIVATE_KEY, provider);

// Initialize contract instance
const chainIdHex = await hre.network.provider.request({ method: 'eth_chainId' });
// @ts-ignore
const chainId = [parseInt(chainIdHex.toString(), 16).toString()];
const router = new ethers.Contract(
deploymentAddresses.router[chainId],
ContractArtifact.abi,
signer
);

console.log(`Working with chainId ${chainId}`);

const feeSignerTx = await router.functions.setProtocolFeeSigner(
'0x1e126951a7CB895543E4E4c7B2D1398b3C3d09fC',
);
console.log(`Setting fee signer tx hash: ${feeSignerTx.hash}`);

const feeDefaultTx = await router.functions.setProtocolFeeDefault(
[
'5000000000000000',
deploymentAddresses.feeBeneficiaries[chainId],
],
);
console.log(`Setting fee defaults tx hash: ${feeDefaultTx.hash}`);
} catch (error) {
console.error(error);
process.exit(1);
}
}
37 changes: 37 additions & 0 deletions deploy/deployContractZkSyncEra.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Wallet } from "zksync-web3";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";

async function deployAsyncZkSyncEra(hre, path, contractName) {
// // load wallet private key from env file
const PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY || "";

// // Initialize the wallet.
const wallet = new Wallet(PRIVATE_KEY);

// // Create deployer object and load the artifact of the contract you want to deploy.
const deployer = new Deployer(hre, wallet);
const artifact = await deployer.loadArtifact(contractName);

const contract = await deployer.deploy(artifact);

console.log(`${contractName} deployed to: ${contract.address}`);

// Contract MUST be fully qualified name (e.g. path/sourceName:contractName)
const contractFullyQualifedName = `contracts/${path}${contractName}.sol:${contractName}`;

// Verify contract programmatically
await hre.run("verify:verify", {
address: contract.address,
contract: contractFullyQualifedName,
constructorArguments: [],
bytecode: artifact.bytecode,
});

return contract.address;
}

const deployContractZkSyncEra = (hre, path, contractName) => {
return deployAsyncZkSyncEra(hre, path, contractName);
};

export default deployContractZkSyncEra;
18 changes: 17 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ require('regenerator-runtime/runtime');
require('dotenv').config();
import { HardhatUserConfig } from 'hardhat/config';
import '@nomiclabs/hardhat-waffle';
import '@nomiclabs/hardhat-etherscan';
import '@nomicfoundation/hardhat-verify';
import 'hardhat-tracer';
import 'hardhat-docgen';
import 'solidity-coverage';
import '@matterlabs/hardhat-zksync-deploy';
import '@matterlabs/hardhat-zksync-solc';
import '@matterlabs/hardhat-zksync-verify';


const config: HardhatUserConfig = {
solidity: {
Expand All @@ -19,7 +23,17 @@ const config: HardhatUserConfig = {
},
},
},
zksolc: {
version: "latest", // Uses latest available in https://github.com/matter-labs/zksolc-bin/
settings: {},
},
networks: {
zkSyncEra: {
zksync: true,
url: 'https://mainnet.era.zksync.io',
ethNetwork: 'mainnet',
verifyURL: 'https://explorer.zksync.io/contracts/verify',
},
hardhat: {
forking: {
url: `https://mainnet.infura.io/v3/${process.env.INFURA_API_KEY}`,
Expand Down Expand Up @@ -56,9 +70,11 @@ const config: HardhatUserConfig = {
},
optimisticEthereum: {
url: 'https://mainnet.optimism.io',
zksync: false,
},
arbitrumOne: {
url: 'https://arb1.arbitrum.io/rpc',
zksync: false,
},
polygon: {
url: 'https://polygon-rpc.com',
Expand Down
Loading

0 comments on commit 6dd2c08

Please sign in to comment.