Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: deploy scripts #7

Merged
merged 21 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
cb81811
feat: add initial deployment scripts
amusingaxl Jun 14, 2023
7442053
deps: add NST and NGT as dependencies
amusingaxl Jul 13, 2023
d6da759
fix: typo in forge-script.sh helper
amusingaxl Jul 13, 2023
3e72035
chore: enable optimizations for Solidity 0.8.x files
amusingaxl Jul 13, 2023
55e3fe1
refactor: move Exports and Imports struct to the specific script file
amusingaxl Jul 13, 2023
4518ad1
feat(helpers/config): add `readUintOptional`
amusingaxl Jul 13, 2023
0b0e619
WIP
amusingaxl Aug 23, 2023
934bd58
chore: upgrade `solhint`
amusingaxl Aug 23, 2023
e83a12c
refactor: remove deployment of NGT and NST
amusingaxl Aug 23, 2023
1066ece
chore: update solhint rules
amusingaxl Aug 23, 2023
5f4080a
refactor: reorganize FarmDeploy script and dependencies
amusingaxl Aug 23, 2023
8c9112a
refactor: reorganize deploy/init libraries
amusingaxl Aug 23, 2023
9e67d34
chore: remove dependencies to NGT and NST
amusingaxl Aug 23, 2023
c0e9fb6
chore: remove unused input template
amusingaxl Aug 23, 2023
47374dd
refactor: rename deploy script
amusingaxl Aug 23, 2023
9f0ba09
refactor: reorganize StakingRewardsDeploy script
amusingaxl Aug 24, 2023
38da890
feat: add CheckStakingRewardsDeploy script
amusingaxl Aug 24, 2023
362994d
fix: add check for `vestId`
amusingaxl Aug 29, 2023
eb12b32
Merge branch 'master' into feat/deploy-scripts
amusingaxl Sep 11, 2023
aaf7956
refactor: update VestInit return type
amusingaxl Sep 20, 2023
52f313e
refactor(ConfigReader): remove OptionalReader
amusingaxl Sep 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
cache/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/
# Ignores broadcast logs
/broadcast

# Ignores script config
/script/input/*/*.json
!/script/input/*/template-*.json
/script/output/*/*.json

# Docs
docs/
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib-0_6_x/dss-vest"]
path = lib-0_6_x/dss-vest
url = https://github.com/makerdao/dss-vest.git
url = https://github.com/makerdao/dss-vest.git
13 changes: 13 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
{
"printWidth": 120,
"plugins": ["prettier-plugin-solidity"],
"overrides": [
{
"files": ["src/**/*.sol", "script/**/*.sol"],
"options": {
"compiler": "0.8.19"
}
},
{
"files": "src-0_6_x/**/*.sol",
"options": {
"compiler": "0.6.12"
}
},
{
"files": [
"*.json"
Expand Down
10 changes: 6 additions & 4 deletions .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
],
"rules": {
"prettier/prettier": "warn",
"max-line-length": "off",
"check-send-result": "off",
"not-rely-on-time": "off",
"multiple-sends": "off",
"custom-errors": "off",
"compiler-version": "off",
"func-visibility": [
"warn",
{
"ignoreConstructors": true
}
]
],
"max-line-length": "off",
"multiple-sends": "off",
"not-rely-on-time": "off",
"one-contract-per-file": "off"
}
}
10 changes: 7 additions & 3 deletions bash/forge-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ run_script() {

local RESPONSE=
# Log the command being issued, making sure not to expose the password
log "forge script --json --sender "$FOUNDRY_ETH_FROM" --keystore "$FOUNDRY_ETH_KEYSTORE_FILE" $(sed 's/ .*$/ [REDACTED]/' <<<"${PASSWORD_OPT[@]}")" $(printf ' %q' "$@")
log "forge script --sender "$FOUNDRY_ETH_FROM" --keystore "$FOUNDRY_ETH_KEYSTORE_FILE" $(sed 's/ .*$/ [REDACTED]/' <<<"${PASSWORD_OPT[@]}")" $(printf ' %q' "$@")
# Currently `forge create` sends the logs to stdout instead of stderr.
# This makes it hard to compose its output with other commands, so here we are:
# 1. Duplicating stdout to stderr through `tee`
# 2. Extracting only the address of the deployed contract to stdout
RESPONSE=$(forge script --json --sender "$FOUNDRY_ETH_FROM" --keystore "$FOUNDRY_ETH_KEYSTORE_FILE" "${PASSWORD_OPT[@]}" "$@" | tee >(cat 1>&2))
RESPONSE=$(forge script --sender "$FOUNDRY_ETH_FROM" --keystore "$FOUNDRY_ETH_KEYSTORE_FILE" "${PASSWORD_OPT[@]}" "$@" | tee >(cat 1>&2))

jq -Rr 'fromjson?' <<<"$RESPONSE"
if grep -- '--json' <<<"$@" >/dev/null; then
jq -Rr 'fromjson?' <<<"$RESPONSE"
else
echo "$RESPONSE"
fi
}

check-required-etherscan-api-key() {
Expand Down
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ out = 'out'
script = 'script'
libs = ['lib']
solc_version = '0.8.19'
optimizer = false
optimizer = true
fs_permissions = [
{ access = "read", path = "./out/" },
{ access = "read", path = "./script/input/" },
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"prettier": "^2.8.7",
"prettier-plugin-solidity": "^1.1.3",
"prettier-plugin-toml": "^0.3.1",
"solhint": "^3.4.1",
"solhint": "^3.6.2",
"solhint-plugin-prettier": "^0.0.5"
},
"scripts": {
Expand Down
98 changes: 98 additions & 0 deletions script/CheckStakingRewardsDeploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// SPDX-FileCopyrightText: © 2023 Dai Foundation <www.daifoundation.org>
// SPDX-License-Identifier: AGPL-3.0-or-later
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
pragma solidity ^0.8.0;

import {Script} from "forge-std/Script.sol";
import {stdJson} from "forge-std/StdJson.sol";
import {ScriptTools} from "dss-test/ScriptTools.sol";

import {ConfigReader} from "./helpers/Config.sol";

interface WardsLike {
function wards(address who) external view returns (uint256);
}

interface VestedRewardsDistributionLike {
function vestId() external view returns (uint256);
}

interface StakingRewardsLike {
function owner() external view returns (address);

function stakingToken() external view returns (address);

function rewardsToken() external view returns (address);

function rewardsDistribution() external view returns (address);
}

interface DssVestWithGemLike {
function gem() external view returns (address);

function tot(uint256 vestId) external view returns (uint256);

function bgn(uint256 vestId) external view returns (uint256);

function clf(uint256 vestId) external view returns (uint256);

function fin(uint256 vestId) external view returns (uint256);

function usr(uint256 vestId) external view returns (address);

function valid(uint256 _id) external view returns (bool);
}

contract CheckStakingRewardsDeployScript is Script {
using stdJson for string;
using ScriptTools for string;

function run() external returns (bool) {
ConfigReader reader = new ConfigReader(ScriptTools.loadConfig());

address admin = reader.readAddress(".admin");
address ngt = reader.readAddress(".ngt");
address nst = reader.readAddress(".nst");
address dist = reader.readAddress(".dist");
address farm = reader.readAddress(".farm");
address vest = reader.readAddress(".vest");
uint256 vestId = reader.readUint(".vestId");
uint256 vestTot = reader.readUint(".vestTot");
uint256 vestBgn = reader.readUint(".vestBgn");
uint256 vestTau = reader.readUint(".vestTau");
uint256 vestEta = reader.readUint(".vestEta");

require(WardsLike(dist).wards(admin) == 1, "vested-rewards-distribution/pause-proxy-not-relied");
require(VestedRewardsDistributionLike(dist).vestId() == vestId, "vested-rewards-distribution/invalid-vest-id");

require(StakingRewardsLike(farm).owner() == admin, "staking-rewards/pause-proxy-not-owner");
require(StakingRewardsLike(farm).rewardsToken() == ngt, "staking-rewards/invalid-rewards-token");
require(StakingRewardsLike(farm).stakingToken() == nst, "staking-rewards/invalid-rewards-token");
require(StakingRewardsLike(farm).rewardsDistribution() == dist, "staking-rewards/invalid-rewards-distribution");

require(WardsLike(ngt).wards(vest) == 1, "ngt/dss-vest-not-ward");

require(WardsLike(vest).wards(admin) == 1, "dss-vest/pause-proxy-not-relied");
require(DssVestWithGemLike(vest).gem() == ngt, "dss-vest/invalid-gem");
require(DssVestWithGemLike(vest).valid(vestId), "dss-vest/invalid-vest-id");
require(DssVestWithGemLike(vest).usr(vestId) == dist, "dss-vest/wrong-dist");
require(DssVestWithGemLike(vest).tot(vestId) == vestTot, "dss-vest/invalid-tot");
require(DssVestWithGemLike(vest).bgn(vestId) == vestBgn, "dss-vest/invalid-bgn");
require(DssVestWithGemLike(vest).clf(vestId) == vestBgn + vestEta, "dss-vest/invalid-eta");
require(DssVestWithGemLike(vest).fin(vestId) == vestBgn + vestTau, "dss-vest/invalid-tau");

return true;
}
}
41 changes: 0 additions & 41 deletions script/DeploySubProxy.s.sol

This file was deleted.

96 changes: 96 additions & 0 deletions script/StakingRewardsDeploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// SPDX-FileCopyrightText: © 2023 Dai Foundation <www.daifoundation.org>
// SPDX-License-Identifier: AGPL-3.0-or-later
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
pragma solidity ^0.8.0;

import {Script} from "forge-std/Script.sol";
import {stdJson} from "forge-std/StdJson.sol";
import {ScriptTools} from "dss-test/ScriptTools.sol";

import {ConfigReader} from "./helpers/Config.sol";
import {StakingRewardsDeploy, StakingRewardsDeployParams} from "./dependencies/StakingRewardsDeploy.sol";
import {
VestedRewardsDistributionDeploy,
VestedRewardsDistributionDeployParams
} from "./dependencies/VestedRewardsDistributionDeploy.sol";
import {StakingRewardsInit, StakingRewardsInitParams} from "./dependencies/StakingRewardsInit.sol";
import {
VestedRewardsDistributionInit,
VestedRewardsDistributionInitParams
} from "./dependencies/VestedRewardsDistributionInit.sol";
import {VestInit, VestInitParams, VestCreateParams} from "./dependencies/VestInit.sol";

contract StakingRewardsDeployScript is Script {
using stdJson for string;
using ScriptTools for string;

string internal constant NAME = "StakingRewards";

function run() external {
ConfigReader reader = new ConfigReader(ScriptTools.loadConfig());

address admin = reader.readAddress(".admin");
address ngt = reader.readAddress(".ngt");
address nst = reader.readAddress(".nst");
address dist = reader.readAddressOptional(".dist");
address farm = reader.readAddressOptional(".farm");
address vest = reader.readAddressOptional(".vest");
uint256 vestTot = reader.readUintOptional(".vestTot");
uint256 vestBgn = reader.readUintOptional(".vestBgn");
uint256 vestTau = reader.readUintOptional(".vestTau");
uint256 vestEta = reader.readUintOptional(".vestEta");

vm.startBroadcast();

if (vest == address(0)) {
vest = deployCode("DssVest.sol:DssVestMintable", abi.encode(ngt));
VestInit.init(VestInitParams({vest: vest, cap: type(uint256).max}));
}

if (farm == address(0)) {
farm = StakingRewardsDeploy.deploy(
StakingRewardsDeployParams({owner: admin, stakingToken: nst, rewardsToken: ngt})
);
}

if (dist == address(0)) {
dist = VestedRewardsDistributionDeploy.deploy(
VestedRewardsDistributionDeployParams({deployer: msg.sender, owner: admin, vest: vest, farm: farm})
);
}

StakingRewardsInit.init(StakingRewardsInitParams({farm: farm, dist: dist}));

uint256 vestId;

if (vestTot > 0) {
vestId = VestInit.create(
VestCreateParams({vest: vest, usr: dist, tot: vestTot, bgn: vestBgn, tau: vestTau, eta: vestEta})
);

VestedRewardsDistributionInit.init(VestedRewardsDistributionInitParams({dist: dist, vestId: vestId}));
}

vm.stopBroadcast();

ScriptTools.exportContract(NAME, "admin", admin);
ScriptTools.exportContract(NAME, "dist", dist);
ScriptTools.exportContract(NAME, "farm", farm);
ScriptTools.exportContract(NAME, "ngt", ngt);
ScriptTools.exportContract(NAME, "nst", nst);
ScriptTools.exportContract(NAME, "vest", vest);
ScriptTools.exportContract(NAME, "vestId", address(uint160(vestId)));
}
}
32 changes: 32 additions & 0 deletions script/dependencies/SDAODeploy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

pragma solidity ^0.8.0;

import {ScriptTools} from "dss-test/ScriptTools.sol";
import {SDAO} from "../../src/SDAO.sol";

library SDAODeploy {
function deploy(
address deployer,
address owner,
string memory name,
string memory symbol
) internal returns (address token) {
token = address(new SDAO(name, symbol));

ScriptTools.switchOwner(token, deployer, owner);
}
}
Loading