Skip to content

Commit

Permalink
🐗 Add deployment script for MinimumDepositController (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
truefibot committed Jan 25, 2023
1 parent a736c0e commit 1ace8d7
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions deployments-optimism_goerli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"optimism_goerli": {
"minimumDepositController": {
"txHash": "0x162d7b478390cc8444a7b8564f770e13b67d596bb071a84785945f0afea61f23",
"address": "0xb7DaEb7232795C7e59A8CC2fb0e6A1CEe43DBD5F",
"multisig": false
}
}
}
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
Expand All @@ -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": {
Expand All @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -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)
83 changes: 83 additions & 0 deletions scripts/guardedRun.sh
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 6 additions & 0 deletions scripts/saveCanary.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1ace8d7

Please sign in to comment.