diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 000000000..a641b6450 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,16 @@ +FROM node:18-bullseye + +# Set the working directory +WORKDIR /zkevm-contracts + +# Copy package.json and package-lock.json to the container +COPY package*.json ./ + +# Install zkevm-contracts dependencies +RUN npm install + +# Copy the entire zkevm-contracts +COPY . . + +ENTRYPOINT ["/bin/bash"] +CMD ["./docker/scripts/deploy-contracts.sh"] \ No newline at end of file diff --git a/docker/Dockerfile.geth b/docker/Dockerfile.geth deleted file mode 100644 index bdf560662..000000000 --- a/docker/Dockerfile.geth +++ /dev/null @@ -1,8 +0,0 @@ -FROM ethereum/client-go - -EXPOSE 8545 - -COPY docker/gethData / - -ENTRYPOINT ["geth"] -CMD ["--rpc.allow-unprotected-txs", "--http", "--http.addr", "0.0.0.0","--http.corsdomain", "*", "--http.vhosts" ,"*", "--ws", "--ws.origins", "*", "--ws.addr", "0.0.0.0", "--dev", "--datadir", "/geth_data"] \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 000000000..a417533ef --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,43 @@ +version: "3.5" +networks: + default: + name: zkevm + +services: + zkevm-mock-l1-network: + container_name: zkevm-mock-l1-network + image: ethereum/client-go + ports: + - 8545:8545 + - 8546:8546 + command: + - "--http" + - "--http.api" + - "admin,eth,debug,miner,net,txpool,personal,web3" + - "--http.addr" + - "0.0.0.0" + - "--http.corsdomain" + - "*" + - "--http.vhosts" + - "*" + - "--ws" + - "--ws.origins" + - "*" + - "--ws.addr" + - "0.0.0.0" + - "--dev" + - "--datadir" + - "/geth_data" + - "--syncmode" + - "full" + - "--rpc.allow-unprotected-txs" + + zkevm-contracts: + container_name: zkevm-contracts + image: snapchain/zkevm-contracts + depends_on: + zkevm-mock-l1-network: + condition: service_started + environment: + - JSONRPC_HTTP_URL=http://zkevm-mock-l1-network:8545 + - L2_CHAIN_ID=2955 \ No newline at end of file diff --git a/docker/scripts/build-docker.sh b/docker/scripts/build-docker.sh new file mode 100755 index 000000000..ad91882ef --- /dev/null +++ b/docker/scripts/build-docker.sh @@ -0,0 +1,2 @@ +#!/bin/bash +sudo docker build -t snapchain/zkevm-contracts -f docker/Dockerfile . \ No newline at end of file diff --git a/docker/scripts/deploy-contracts.sh b/docker/scripts/deploy-contracts.sh new file mode 100755 index 000000000..61c53bb1b --- /dev/null +++ b/docker/scripts/deploy-contracts.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -eux + +echo "JSONRPC_HTTP_URL: $JSONRPC_HTTP_URL" +node docker/scripts/fund-accounts.js +echo "Replace with $L2_CHAIN_ID" +sed -i.bak "s//$L2_CHAIN_ID/g" docker/scripts/deploy_parameters_docker.json +cp docker/scripts/deploy_parameters_docker.json deployment/deploy_parameters.json +cp docker/scripts/genesis_docker.json deployment/genesis.json +npx hardhat run deployment/testnet/prepareTestnet.js --network zkevmMockL1Network +npx hardhat run deployment/2_deployPolygonZKEVMDeployer.js --network zkevmMockL1Network +npx hardhat run deployment/3_deployContracts.js --network zkevmMockL1Network +mkdir docker/deploymentOutput +mv deployment/deploy_output.json docker/deploymentOutput \ No newline at end of file diff --git a/docker/scripts/deploy-docker.sh b/docker/scripts/deploy-docker.sh deleted file mode 100755 index 660052bb8..000000000 --- a/docker/scripts/deploy-docker.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -sudo rm -rf docker/gethData/geth_data -DEV_PERIOD=1 docker-compose -f docker/docker-compose.geth.yml up -d geth -sleep 5 -node docker/scripts/fund-accounts.js -cp docker/scripts/deploy_parameters_docker.json deployment/deploy_parameters.json -cp docker/scripts/genesis_docker.json deployment/genesis.json -npx hardhat run deployment/testnet/prepareTestnet.js --network localhost -npx hardhat run deployment/2_deployPolygonZKEVMDeployer.js --network localhost -npx hardhat run deployment/3_deployContracts.js --network localhost -mkdir docker/deploymentOutput -mv deployment/deploy_output.json docker/deploymentOutput -docker-compose -f docker/docker-compose.geth.yml down -sudo docker build -t hermeznetwork/geth-zkevm-contracts -f docker/Dockerfile.geth . -# Let it readable for the multiplatform build coming later! -sudo chmod -R go+rxw docker/gethData diff --git a/docker/scripts/deploy_parameters_docker.json b/docker/scripts/deploy_parameters_docker.json index a07b4df0d..d9568f9ec 100644 --- a/docker/scripts/deploy_parameters_docker.json +++ b/docker/scripts/deploy_parameters_docker.json @@ -4,7 +4,7 @@ "networkName": "zkevm", "version":"0.0.1", "trustedSequencer":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", - "chainID": 1001, + "chainID": , "trustedAggregator":"0x70997970C51812dc3A010C7d01b50e0d17dc79C8", "trustedAggregatorTimeout": 604799, "pendingStateTimeout": 604799, diff --git a/docker/scripts/fund-accounts.js b/docker/scripts/fund-accounts.js index 2ef00f700..6d94405ef 100644 --- a/docker/scripts/fund-accounts.js +++ b/docker/scripts/fund-accounts.js @@ -8,7 +8,8 @@ const DEFAULT_NUM_ACCOUNTS = 20; async function main() { const MNEMONIC = process.env.MNEMONIC || DEFAULT_MNEMONIC; - const currentProvider = new ethers.providers.JsonRpcProvider('http://localhost:8545'); + const JSONRPC_HTTP_URL = process.env.JSONRPC_HTTP_URL || 'http://zkevm-mock-l1-network:8545' + const currentProvider = new ethers.providers.JsonRpcProvider(JSONRPC_HTTP_URL); const signerNode = await currentProvider.getSigner(); const numAccountsToFund = process.env.NUM_ACCOUNTS || DEFAULT_NUM_ACCOUNTS; diff --git a/hardhat.config.js b/hardhat.config.js index ff6d02c08..ad7d37db6 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -111,6 +111,15 @@ module.exports = { count: 20, }, }, + zkevmMockL1Network: { + url: process.env.JSONRPC_HTTP_URL || 'http://zkevm-mock-l1-network:8545', + accounts: { + mnemonic: process.env.MNEMONIC || DEFAULT_MNEMONIC, + path: "m/44'/60'/0'/0", + initialIndex: 0, + count: 20, + }, + }, hardhat: { initialDate: '0', allowUnlimitedContractSize: true, diff --git a/package.json b/package.json index 85cc39c16..3b8d66d16 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "eslint-plugin-mocha": "^9.0.0", "ethereum-waffle": "^3.4.4", "ffjavascript": "^0.2.57", - "hardhat": "^2.13.0", + "hardhat": "^2.17.0", "hardhat-dependency-compiler": "^1.1.3", "hardhat-gas-reporter": "^1.0.9", "prettier": "^2.8.4",