From 1ace8d71071dbf089fc9298475c4c343a8da2301 Mon Sep 17 00:00:00 2001 From: truefibot Date: Wed, 25 Jan 2023 14:53:39 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=97=20Add=20deployment=20script=20for?= =?UTF-8?q?=20MinimumDepositController=20(#554)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ller.sol => IMinimumDepositController.sol} | 2 +- .../MinimumDepositController.sol | 4 +- deployments-optimism_goerli.json | 9 ++ package.json | 8 +- scripts/deploy.ts | 9 ++ scripts/guardedRun.sh | 83 +++++++++++++++++++ scripts/saveCanary.sh | 6 ++ 7 files changed, 116 insertions(+), 5 deletions(-) rename contracts/MinimumDepositController/{IDepositController.sol => IMinimumDepositController.sol} (99%) create mode 100644 deployments-optimism_goerli.json create mode 100644 scripts/deploy.ts create mode 100644 scripts/guardedRun.sh create mode 100644 scripts/saveCanary.sh diff --git a/contracts/MinimumDepositController/IDepositController.sol b/contracts/MinimumDepositController/IMinimumDepositController.sol similarity index 99% rename from contracts/MinimumDepositController/IDepositController.sol rename to contracts/MinimumDepositController/IMinimumDepositController.sol index 2af8648..172f3d5 100644 --- a/contracts/MinimumDepositController/IDepositController.sol +++ b/contracts/MinimumDepositController/IMinimumDepositController.sol @@ -10,7 +10,7 @@ import {DepositAllowed} from "../carbon/interfaces/IDepositController.sol"; * @title Contract for managing deposit related settings * @dev Used by TrancheVault contract */ -interface IDepositController { +interface IMinimumDepositController { /** * @notice Event emitted when new ceiling is set * @param newCeiling New ceiling value diff --git a/contracts/MinimumDepositController/MinimumDepositController.sol b/contracts/MinimumDepositController/MinimumDepositController.sol index 620aab1..060037e 100644 --- a/contracts/MinimumDepositController/MinimumDepositController.sol +++ b/contracts/MinimumDepositController/MinimumDepositController.sol @@ -7,11 +7,11 @@ import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.s import {AccessControlEnumerable} from "@openzeppelin/contracts/access/AccessControlEnumerable.sol"; import {ILenderVerifier, Status, DepositAllowed} from "../carbon/interfaces/IDepositController.sol"; import {ITrancheVault} from "../carbon/interfaces/ITrancheVault.sol"; -import {IDepositController} from "./IDepositController.sol"; +import {IMinimumDepositController} from "./IMinimumDepositController.sol"; uint256 constant BASIS_PRECISION = 10000; -contract MinimumDepositController is IDepositController, Initializable, AccessControlEnumerable { +contract MinimumDepositController is IMinimumDepositController, Initializable, AccessControlEnumerable { /// @dev Manager role used for access control bytes32 public constant MANAGER_ROLE = keccak256("MANAGER_ROLE"); ILenderVerifier public lenderVerifier; diff --git a/deployments-optimism_goerli.json b/deployments-optimism_goerli.json new file mode 100644 index 0000000..f411872 --- /dev/null +++ b/deployments-optimism_goerli.json @@ -0,0 +1,9 @@ +{ + "optimism_goerli": { + "minimumDepositController": { + "txHash": "0x162d7b478390cc8444a7b8564f770e13b67d596bb071a84785945f0afea61f23", + "address": "0xb7DaEb7232795C7e59A8CC2fb0e6A1CEe43DBD5F", + "multisig": false + } + } +} diff --git a/package.json b/package.json index bc74ef5..8363d6c 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,9 @@ "preinstall": "npx only-allow pnpm", "build:hardhat": "hardhat compile", "build:typechain": "typechain --target ethers-v5 --out-dir build/types 'build/*.json'", - "build": "pnpm clean && pnpm build:hardhat && pnpm build:typechain", + "build:mars": "pnpm exec mars", + "build:save-canary": "bash ./scripts/saveCanary.sh", + "build": "pnpm clean && pnpm build:hardhat && pnpm build:typechain && pnpm build:save-canary && pnpm build:mars", "clean": "rm -rf ./build && hardhat clean", "lint:prettier": "prettier './{contracts,test,features}/**/*.{ts,sol}' --cache", "lint:sol": "solhint 'contracts/**/*.sol'", @@ -15,7 +17,8 @@ "lint": "pnpm run lint:sol && pnpm run lint:prettier --check --loglevel error && pnpm run lint:ts", "test:unit": "mocha 'test/**/*.test.ts'", "test": "pnpm test:unit", - "test:ci": "pnpm run test" + "test:ci": "pnpm run test", + "deploy:contracts": "bash ./scripts/guardedRun.sh" }, "prettier": "prettier-config-archblock/contracts.json", "dependencies": { @@ -34,6 +37,7 @@ "@types/node": "^17.0.12", "chai": "^4.3.6", "eslint-config-archblock": "workspace:*", + "ethereum-mars": "0.2.6-dev.eb75a27", "ethereum-waffle": "4.0.7", "ethers": "^5.7.1", "hardhat": "^2.11.2", diff --git a/scripts/deploy.ts b/scripts/deploy.ts new file mode 100644 index 0000000..2a92a6f --- /dev/null +++ b/scripts/deploy.ts @@ -0,0 +1,9 @@ +import { MinimumDepositController } from '../build/artifacts' +import { contract, deploy } from 'ethereum-mars' + +export function deployContract() { + const minimumDepositController = contract(MinimumDepositController) + return { minimumDepositController } +} + +deploy({ verify: true }, deployContract) diff --git a/scripts/guardedRun.sh b/scripts/guardedRun.sh new file mode 100644 index 0000000..11fe30d --- /dev/null +++ b/scripts/guardedRun.sh @@ -0,0 +1,83 @@ +#!/bin/bash +set -eu + +# Setting Infura or Alchemy key to use for convenience here +#export INFURA_KEY="f88abc181a4a45a6bc47bdda05a94944" +export ALCHEMY_KEY="fbS06B9gi4kYSsliFu_Hj5gamIShXt9I" + +# Example usage: +# $ scripts/deployment/guardedRun.sh --network goerli --dry-run +# PRIVATE_KEY=0x123..64 + +network='mainnet' +args="$@" +dry_run='false' +force='false' + +while [[ "$@" ]]; do + case "$1" in + --network) + if [ "$2" ]; then + network="$2" + shift 1 + fi + ;; + --dry-run) + dry_run='true' + ;; + --force) + force='true' + ;; + -?) + # ignore + ;; + esac + shift 1 +done + +# Setting Etherscan key to use for convenience here +if [[ $network == optimism* ]]; then + export ETHERSCAN_KEY="RPKYAHCE6R2YI7TRV51WS5N8R885RRNXG3" # Use for Optimism & optimistic testnets +else + export ETHERSCAN_KEY="XQPPJGFR4J3I6PEISYEG4JPETFZ2EF56EX" # Use for Ethereum & testnets +fi + +if [[ "${dry_run}" == 'false' ]]; then + if [[ "$(git status --porcelain)" ]]; then + echo "Error: git working directory must be empty to run deploy script." + exit 1 + fi + + if [[ "$(git log --pretty=format:'%H' -n 1)" != "$(cat ./build/canary.hash)" ]]; then + echo "Error: Build canary does not match current commit hash. Please run pnpm run build." + exit 1 + fi +fi + +# Skip prompt if PRIVATE_KEY variable already exists +if [[ -z "${PRIVATE_KEY:-}" ]]; then + # Prompt the user for a PRIVATE_KEY without echoing to bash output. + # Then export PRIVATE_KEY to an environment variable that won't get + # leaked to bash history. + # + # WARNING: environment variables are still leaked to the process table + # while a process is running, and hence visible in a call to `ps -E`. + echo "Enter a private key (0x{64 hex chars}) for contract deployment," + echo "or leave blank if performing a dry run without authorization." + read -s -p "PRIVATE_KEY=" PRIVATE_KEY + export PRIVATE_KEY +fi + +# Log file name +network_log="-${network}" +dry_run_log='' +if [[ "${dry_run}" == 'true' ]]; then + dry_run_log='-dry-run' +fi +timestamp_log="-$(date +%s)" + +ts-node ./scripts/deploy.ts \ + --waffle-config ./waffle.json \ + ${args} \ + --out-file "deployments-${network}.json" \ + --log "./cache/deploy${network_log}${dry_run_log}${timestamp_log}.log" diff --git a/scripts/saveCanary.sh b/scripts/saveCanary.sh new file mode 100644 index 0000000..d649bb4 --- /dev/null +++ b/scripts/saveCanary.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +if [[ -z "$(git status --porcelain)" ]]; then + echo "Build canary stored in ./build/canary.hash" + git log --pretty=format:'%H' -n 1 > ./build/canary.hash +fi