From 834cdbf5bbf81b6bb389ee3b7d7767494010e60e Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Tue, 28 May 2024 17:56:10 +0530 Subject: [PATCH] chore(deployments): update deployments script (#6) --- .gas-snapshot | 2 +- README.md | 14 +++++++++++--- envCheck.sh | 13 +++++++++++++ foundry.toml | 17 +---------------- package.json | 4 +++- script/Deploy.s.sol | 3 +-- script/DeploymentConfig.s.sol | 6 ++++++ test/WakuRlnV2.t.sol | 2 +- 8 files changed, 37 insertions(+), 24 deletions(-) create mode 100755 envCheck.sh diff --git a/.gas-snapshot b/.gas-snapshot index a67299a..c6bc706 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -7,7 +7,7 @@ WakuRlnV2Test:test__InvalidRegistration__InvalidIdCommitment__LargerThanField() WakuRlnV2Test:test__InvalidRegistration__InvalidIdCommitment__Zero() (gas: 9139) WakuRlnV2Test:test__InvalidRegistration__InvalidUserMessageLimit__LargerThanMax() (gas: 10147) WakuRlnV2Test:test__InvalidRegistration__InvalidUserMessageLimit__Zero() (gas: 9242) -WakuRlnV2Test:test__ValidPaginationQuery(uint32) (runs: 1002, μ: 403497, ~: 136269) +WakuRlnV2Test:test__ValidPaginationQuery(uint32) (runs: 1001, μ: 394880, ~: 136269) WakuRlnV2Test:test__ValidPaginationQuery__OneElement() (gas: 128461) WakuRlnV2Test:test__ValidRegistration(uint256,uint32) (runs: 1001, μ: 133518, ~: 133518) WakuRlnV2Test:test__ValidRegistration__kats() (gas: 108902) \ No newline at end of file diff --git a/README.md b/README.md index 030cffd..486a37f 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ $ forge coverage ### Deploy -Deploy to Anvil: +#### Deploy to Anvil: ```sh $ forge script script/Deploy.s.sol --broadcast --fork-url http://localhost:8545 @@ -65,8 +65,16 @@ $ forge script script/Deploy.s.sol --broadcast --fork-url http://localhost:8545 For this script to work, you need to have a `MNEMONIC` environment variable set to a valid [BIP39 mnemonic](https://iancoleman.io/bip39/). -For instructions on how to deploy to a testnet or mainnet, check out the -[Solidity Scripting](https://book.getfoundry.sh/tutorials/solidity-scripting.html) tutorial. +#### Deploy to Sepolia: + +Ensure that you use the [cast wallet](https://book.getfoundry.sh/reference/cast/cast-wallet) to store private keys that +will be used in deployments. + +```sh +$ export RPC_URL= +$ export ACCOUNT= +$ pnpm deploy:sepolia +``` ### Format diff --git a/envCheck.sh b/envCheck.sh new file mode 100755 index 0000000..eee36dc --- /dev/null +++ b/envCheck.sh @@ -0,0 +1,13 @@ +# This script is used to assert if require env vars are present for deployment +# RPC_URL: RPC URL for the network +# ACCOUNT: Accessed with `cast wallet` command + +if [ -z "$RPC_URL" ]; then + echo "RPC_URL is required" + exit 1 +fi + +if [ -z "$ACCOUNT" ]; then + echo "ACCOUNT is required" + exit 1 +fi diff --git a/foundry.toml b/foundry.toml index 1df6815..fd3568d 100644 --- a/foundry.toml +++ b/foundry.toml @@ -25,14 +25,7 @@ max_test_rejects = 128_000 verbosity = 4 [etherscan] - arbitrum = { key = "${API_KEY_ARBISCAN}" } - avalanche = { key = "${API_KEY_SNOWTRACE}" } - bnb_smart_chain = { key = "${API_KEY_BSCSCAN}" } - gnosis_chain = { key = "${API_KEY_GNOSISSCAN}" } - goerli = { key = "${API_KEY_ETHERSCAN}" } mainnet = { key = "${API_KEY_ETHERSCAN}" } - optimism = { key = "${API_KEY_OPTIMISTIC_ETHERSCAN}" } - polygon = { key = "${API_KEY_POLYGONSCAN}" } sepolia = { key = "${API_KEY_ETHERSCAN}" } [fmt] @@ -46,13 +39,5 @@ max_test_rejects = 128_000 wrap_comments = true [rpc_endpoints] - arbitrum = "https://arbitrum-mainnet.infura.io/v3/${API_KEY_INFURA}" - avalanche = "https://avalanche-mainnet.infura.io/v3/${API_KEY_INFURA}" - bnb_smart_chain = "https://bsc-dataseed.binance.org" - gnosis_chain = "https://rpc.gnosischain.com" - goerli = "https://goerli.infura.io/v3/${API_KEY_INFURA}" localhost = "http://localhost:8545" - mainnet = "https://eth-mainnet.g.alchemy.com/v2/${API_KEY_ALCHEMY}" - optimism = "https://optimism-mainnet.infura.io/v3/${API_KEY_INFURA}" - polygon = "https://polygon-mainnet.infura.io/v3/${API_KEY_INFURA}" - sepolia = "https://sepolia.infura.io/v3/${API_KEY_INFURA}" + sepolia = "https://eth-sepolia.g.alchemy.com/v2/${API_KEY_ALCHEMY}" diff --git a/package.json b/package.json index aaa5b04..05942b1 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,8 @@ "prettier:write": "prettier --write **/*.{json,md,yml} --ignore-path=.prettierignore", "gas-report": "forge test --gas-report 2>&1 | (tee /dev/tty | awk '/Test result:/ {found=1; buffer=\"\"; next} found && !/Ran/ {buffer=buffer $0 ORS} /Ran/ {found=0} END {printf \"%s\", buffer}' > .gas-report)", "release": "commit-and-tag-version", - "adorno": "pnpm prettier:write && forge fmt && forge snapshot && pnpm gas-report" + "adorno": "pnpm prettier:write && forge fmt && forge snapshot && pnpm gas-report", + "deploy:sepolia": "./envCheck.sh && forge script --chain sepolia script/Deploy.s.sol:Deploy --rpc-url $RPC_URL --broadcast --verify -vv --account $ACCOUNT --legacy", + "deploy:localhost": "./envCheck.sh && forge script script/Deploy.s.sol:Deploy --rpc-url $RPC_URL --broadcast -vv --account $ACCOUNT" } } diff --git a/script/Deploy.s.sol b/script/Deploy.s.sol index 9a53463..0409996 100644 --- a/script/Deploy.s.sol +++ b/script/Deploy.s.sol @@ -6,8 +6,7 @@ import { BaseScript } from "./Base.s.sol"; import { DeploymentConfig } from "./DeploymentConfig.s.sol"; contract Deploy is BaseScript { - function run() public returns (WakuRlnV2 w, DeploymentConfig deploymentConfig) { - deploymentConfig = new DeploymentConfig(broadcaster); + function run() public broadcast returns (WakuRlnV2 w) { w = new WakuRlnV2(20); } } diff --git a/script/DeploymentConfig.s.sol b/script/DeploymentConfig.s.sol index 371b7d8..7e6ad10 100644 --- a/script/DeploymentConfig.s.sol +++ b/script/DeploymentConfig.s.sol @@ -21,6 +21,8 @@ contract DeploymentConfig is Script { deployer = _broadcaster; if (block.chainid == 31_337) { activeNetworkConfig = getOrCreateAnvilEthConfig(); + } else if (block.chainid == 11_155_111) { + activeNetworkConfig = getOrCreateSepoliaConfig(); } else { revert DeploymentConfig_NoConfigForChain(block.chainid); } @@ -30,6 +32,10 @@ contract DeploymentConfig is Script { return NetworkConfig({ deployer: deployer }); } + function getOrCreateSepoliaConfig() public view returns (NetworkConfig memory) { + return NetworkConfig({ deployer: deployer }); + } + // This function is a hack to have it excluded by `forge coverage` until // https://github.com/foundry-rs/foundry/issues/2988 is fixed. // See: https://github.com/foundry-rs/foundry/issues/2988#issuecomment-1437784542 diff --git a/test/WakuRlnV2.t.sol b/test/WakuRlnV2.t.sol index 280ed01..8f28c66 100644 --- a/test/WakuRlnV2.t.sol +++ b/test/WakuRlnV2.t.sol @@ -20,7 +20,7 @@ contract WakuRlnV2Test is Test { function setUp() public virtual { Deploy deployment = new Deploy(); - (w, deploymentConfig) = deployment.run(); + w = deployment.run(); } function test__ValidRegistration__kats() external {