Skip to content

Commit

Permalink
Merge pull request #22 from OlympusDAO/deployment-scripts
Browse files Browse the repository at this point in the history
Improved deployment and proposal scripts
  • Loading branch information
0xJem authored Nov 13, 2024
2 parents 2afc390 + b121dc0 commit 273e6db
Show file tree
Hide file tree
Showing 16 changed files with 581 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
cache/
node_modules/
.env
.env.*
remappings.txt
broadcast/
src/test/sim/in/*.json
Expand All @@ -12,3 +13,4 @@ src/test/sim/sims/*.t.sol
docs/
coverage/
/solidity-metrics.html
dependencies/
1 change: 1 addition & 0 deletions .markdownlintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ docs/
cache/
coverage/
lib/
dependencies/
83 changes: 83 additions & 0 deletions ROLES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# ROLES

This document describes the roles that are used in the Olympus protocol.

## Role Definitions

| Role | Policy | Actions |
|------|----------|-------------|
| bondmanager_admin | BondManager | Create/close bond markets, set parameters |
| bridge_admin | CrossChainBridge | Allows configuring the CrossChainBridge |
| callback_admin | BondCallback | Administers the policy |
| callback_whitelist | BondCallback | Whitelists/blacklists tellers for callback |
| cooler_overseer | Clearinghouse | Allows activating the Clearinghouse |
| custodian | TreasuryCustodian | Deposit/withdraw reserves and grant/revoke approvals |
| distributor_admin | Distributor | Set reward rate, bounty, and other parameters |
| emergency_restart | Emergency | Reactivates the TRSRY and/or MINTR modules |
| emergency_shutdown | Clearinghouse | Allows shutting down the protocol in an emergency |
| emergency_shutdown | Emergency | Deactivates the TRSRY and/or MINTR modules |
| heart | Operator | Call the operate() function |
| heart | ReserveMigrator | Allows migrating reserves from one reserve token to another |
| heart | YieldRepurchaseFacility | Creates a new YRF market |
| heart_admin | Heart | Allows configuring heart parameters and activation/deactivation |
| loop_daddy | YieldRepurchaseFacility | Activate/deactivate the functionality |
| operator_admin | Operator | Activate/deactivate the functionality |
| operator_policy | Operator | Set spreads, threshold factor, and cushion factor |
| operator_reporter | Operator | Report bond purchases |
| poly_admin | pOLY | Allows migrating pOLY terms to another contract |

## Role Allocations

```json
{
"0x0AE561226896dA978EaDA0Bec4a7d3CfAE04f506": [ // Current Operator contract
"callback_whitelist"
],
"0x245cc372C84B3645Bf0Ffe6538620B04a217988B": [ // DAO MS
"operator_operate",
"operator_admin",
"callback_admin",
"price_admin",
"custodian",
"emergency_restart",
"bridge_admin",
"heart_admin",
"cooler_overseer",
"operator_policy",
"bondmanager_admin",
"loop_daddy"
],
"0x73df08CE9dcC8d74d22F23282c4d49F13b4c795E": [ // Current BondCallback contract
"operator_reporter"
],
"0x953EA3223d2dd3c1A91E9D6cca1bf7Af162C9c39": [ // OCG Timelock
"cooler_overseer",
"emergency_admin",
"emergency_shutdown",
"operator_admin",
"callback_admin",
"price_admin",
"custodian",
"emergency_restart",
"bridge_admin",
"heart_admin",
"operator_policy",
"loop_daddy",
"contract_registry_admin",
"loan_consolidator_admin"
],
"0xda9fEDBcAF319Ecf8AB11fe874Fb1AbFc2181766": [ // pOly MS
"poly_admin"
],
"0xa8A6ff2606b24F61AFA986381D8991DFcCCd2D55": [ // Emergency MS
"emergency_shutdown",
"emergency_admin"
],
"0x39F6AA3d445e6Dd8eC232c6Bd589889A88E3034d": [ // Current Heart contract
"heart",
"operator_operate"
]
}
```

The current role allocations can be determined by running the [role-viewer](https://github.com/OlympusDAO/role-viewer/) tool.
8 changes: 7 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ optimizer_runs = 10
chain_id = 1

[fuzz]
runs = 256
runs = 256

[soldeer]
remappings_generate = false

[dependencies]
surl = { version = "1.0.0", git = "https://github.com/memester-xyz/surl.git", rev = "034c912ae9b5e707a5afd21f145b452ad8e800df" }
1 change: 1 addition & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ openzeppelin-contracts/=lib/openzeppelin-contracts/
openzeppelin/=lib/forge-proposal-simulator/lib/openzeppelin-contracts/contracts/
solidity-code-metrics/=node_modules/solidity-code-metrics/
solidity-examples/=lib/solidity-examples/contracts/
surl-1.0.0/=dependencies/surl-1.0.0/src/
74 changes: 52 additions & 22 deletions shell/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,38 +1,68 @@
#!/bin/bash

# Deploys a sequence of contracts.
#
# Usage:
# ./deploy.sh <deploy-file> <broadcast=false> <verify=false> <resume=false>
# ./deploy.sh --sequence <sequence-file> --broadcast <false> --verify <false> --resume <false> --env <env-file>
#
# Environment variables:
# RPC_URL
# PRIVATE_KEY
# GAS_PRICE
# ETHERSCAN_KEY (only needed if verify is true)
# VERIFIER_URL (only needed for a custom verifier or on a fork)

# Load environment variables, but respect overrides
curenv=$(declare -p -x)
source .env
eval "$curenv"
# Exit if any error occurs
set -e

# Get command-line arguments
DEPLOY_FILE=$1
BROADCAST=${2:-false}
VERIFY=${3:-false}
RESUME=${4:-false}
# Iterate through named arguments
# Source: https://unix.stackexchange.com/a/388038
while [ $# -gt 0 ]; do
if [[ $1 == *"--"* ]]; then
v="${1/--/}"
declare $v="$2"
fi

shift
done

# Get the name of the .env file or use the default
ENV_FILE=${env:-".env"}
echo "Sourcing environment variables from $ENV_FILE"

# Load environment file
set -a # Automatically export all variables
source $ENV_FILE
set +a # Disable automatic export

# Set sane defaults
BROADCAST=${broadcast:-false}
VERIFY=${verify:-false}
RESUME=${resume:-false}

# Check if sequence is set
if [ -z "$sequence" ]
then
echo "No deployment sequence specified. Provide the relative path after the --sequence flag."
exit 1
fi

# Check if DEPLOY_FILE is set
if [ -z "$DEPLOY_FILE" ]
# Check if the sequence file exists
if [ ! -f "$sequence" ]
then
echo "No deploy file specified. Provide the relative path after the command."
echo "Deployment sequence ($sequence) not found. Provide the correct relative path after the --sequence flag."
exit 1
fi

# Check if DEPLOY_FILE exists
if [ ! -f "$DEPLOY_FILE" ]
# Check if CHAIN is set
if [ -z "$CHAIN" ]
then
echo "Deploy file ($DEPLOY_FILE) not found. Provide the correct relative path after the command."
echo "No chain specified. Specify the CHAIN in the $ENV_FILE file."
exit 1
fi

echo "Deploying $DEPLOY_FILE"
echo "Deployment sequence: $sequence"
echo "Chain: $CHAIN"
echo "Guardian: $GUARDIAN_ADDRESS"
echo "Policy: $POLICY_ADDRESS"
echo "Emergency: $EMERGENCY_ADDRESS"
echo "Using RPC at URL: $RPC_URL"

# Set BROADCAST_FLAG based on BROADCAST
Expand All @@ -51,7 +81,7 @@ if [ "$VERIFY" = "true" ] || [ "$VERIFY" = "TRUE" ]; then
# Check if ETHERSCAN_KEY is set
if [ -z "$ETHERSCAN_KEY" ]
then
echo "No Etherscan API key found. Provide the key in .env or disable verification."
echo "No Etherscan API key found. Provide the key in $ENV_FILE or disable verification."
exit 1
fi

Expand Down Expand Up @@ -79,7 +109,7 @@ fi

# Deploy using script
forge script ./src/scripts/deploy/DeployV2.sol:OlympusDeploy \
--sig "deploy(string,string)()" $CHAIN $DEPLOY_FILE \
--sig "deploy(string,string)()" $CHAIN $sequence \
--rpc-url $RPC_URL --private-key $PRIVATE_KEY --slow -vvv \
--with-gas-price $GAS_PRICE \
$BROADCAST_FLAG \
Expand Down
3 changes: 3 additions & 0 deletions shell/full_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ cd lib/solidity-examples/ && git checkout a4954e5747baca5e7fd2b62c639e7600ad388a
cd lib/solmate/ && git checkout fadb2e2778adbf01c80275bfb99e5c14969d964b && cd ../..
cd lib/forge-proposal-simulator && git checkout 864b357b650f9dc7b2fb1ae23562454815d51def && cd ../..

echo "*** Running forge soldeer update"
forge soldeer update

echo "*** Running forge build"
forge build
5 changes: 5 additions & 0 deletions soldeer.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[[dependencies]]
name = "surl"
version = "1.0.0"
git = "https://github.com/memester-xyz/surl.git"
rev = "034c912ae9b5e707a5afd21f145b452ad8e800df"
73 changes: 73 additions & 0 deletions src/scripts/ops/OlyBatch.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ pragma solidity 0.8.15;

import {BatchScript} from "./lib/BatchScript.sol";
import {stdJson} from "forge-std/StdJson.sol";
import {console2} from "forge-std/console2.sol";
import {Surl} from "surl-1.0.0/Surl.sol";

abstract contract OlyBatch is BatchScript {
using stdJson for string;
using Surl for *;

string internal env;
string internal chain;
Expand Down Expand Up @@ -81,4 +84,74 @@ abstract contract OlyBatch is BatchScript {
}

function loadEnv() internal virtual;

function executeBatch(bool send_) internal override {
bool isTestnet = vm.envOr("TESTNET", false);

if (isTestnet && send_) {
console2.log("Sending batch on testnet");
_sendTestnetBatch();
return;
}

super.executeBatch(send_);
}

function _sendTestnetBatch() private {
// Get the testnet RPC URL and access key
string memory TENDERLY_ACCOUNT_SLUG = vm.envString("TENDERLY_ACCOUNT_SLUG");
string memory TENDERLY_PROJECT_SLUG = vm.envString("TENDERLY_PROJECT_SLUG");
string memory TENDERLY_VNET_ID = vm.envString("TENDERLY_VNET_ID");
string memory TENDERLY_ACCESS_KEY = vm.envString("TENDERLY_ACCESS_KEY");

// Iterate over the proposal actions and execute them
for (uint256 i; i < actionsTo.length; i++) {
console2.log("Preparing batch action ", i + 1);

// Construct the API call
string[] memory headers = new string[](3);
headers[0] = "Accept: application/json";
headers[1] = "Content-Type: application/json";
headers[2] = string.concat("X-Access-Key: ", TENDERLY_ACCESS_KEY);

string memory url = string.concat(
"https://api.tenderly.co/api/v1/account/",
TENDERLY_ACCOUNT_SLUG,
"/project/",
TENDERLY_PROJECT_SLUG,
"/vnets/",
TENDERLY_VNET_ID,
"/transactions"
);

// Execute the API call
// solhint-disable quotes
console2.log("Executing batch action ", i + 1);
(uint256 status, bytes memory response) = url.post(
headers,
string.concat(
"{",
'"callArgs": {',
'"from": "',
vm.toString(daoMS),
'", "to": "',
vm.toString(actionsTo[i]),
'", "gas": "0x7a1200", "gasPrice": "0x10", "value": "0x0", ',
'"data": "',
vm.toString(actionsData[i]),
'"',
"}}"
)
);
// solhint-enable quotes

string memory responseString = string(response);
console2.log("Response: ", responseString);

// If the response contains "error", exit
if (status >= 400 || vm.keyExists(responseString, ".error")) {
revert("Error executing batch action");
}
}
}
}
13 changes: 13 additions & 0 deletions src/scripts/ops/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Batch Scripts

This directory contains batch scripts for the Olympus DAO multisig.

## Fork Testing

To run the scripts on a testnet/forked chain, provide the `--testnet` flag to the `batch.sh` script. This requires certain environment variables to be set, which are documented in the `batch.sh` file.

For example:

```bash
./batch.sh --contract ContractRegistryInstall --batch script1_install --broadcast true --testnet true --env .env.testnet
```
Loading

0 comments on commit 273e6db

Please sign in to comment.