-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: resolve issues pointed out by ChainSecurity's audit report (#12)
* fix(SubProxyInit): rely on `MCD_ESM` instead of `MCD_END` * refactor: separate `StakingRewards` deploy and init scripts * feat: make deploy and init scripts configurable through env vars * chore: update .env.example with the required config * fix: remove duplicate entry from .env.example
- Loading branch information
1 parent
2a9215e
commit 5efa2ca
Showing
14 changed files
with
240 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
export FOUNDRY_ETH_FROM='string: wallet address' | ||
# ./bash/* config | ||
export FOUNDRY_ETH_KEYSTORE_DIR='string: keystore directory' | ||
export FOUNDRY_ETH_PASSWORD_FILE='string: keystore file password' | ||
export FOUNDRY_ETH_FROM='address: the msg.sender address for scripts' | ||
|
||
# ScriptTools config | ||
export FOUNDRY_EXPORTS_OVERWRITE_LATEST='boolean: whether to overwrite the *-latest.json when running scripts. Should be set to `true`.' | ||
export FOUNDRY_ROOT_CHAINID='number: the chain ID where the script should run' | ||
|
||
# General config | ||
export ETH_RPC_URL='string: the JSON RPC provider URL' | ||
export ETHERSCAN_API_KEY='string: API key' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {Reader} from "./helpers/Reader.sol"; | ||
import {StakingRewardsInit, StakingRewardsInitParams} from "./dependencies/StakingRewardsInit.sol"; | ||
import { | ||
VestedRewardsDistributionInit, | ||
VestedRewardsDistributionInitParams | ||
} from "./dependencies/VestedRewardsDistributionInit.sol"; | ||
import {VestInit, VestInitParams, VestCreateParams} from "./dependencies/VestInit.sol"; | ||
|
||
interface RelyLike { | ||
function rely(address who) external; | ||
} | ||
|
||
interface WithGemLike { | ||
function gem() external view returns (address); | ||
} | ||
|
||
interface StakingRewardsLike { | ||
function rewardsToken() external view returns (address); | ||
} | ||
|
||
contract Phase0StakingRewardsInitScript is Script { | ||
using stdJson for string; | ||
using ScriptTools for string; | ||
|
||
string internal constant NAME = "Phase0StakingRewardsInit"; | ||
|
||
function run() external { | ||
Reader deps = new Reader(ScriptTools.loadDependencies()); | ||
|
||
address ngt = deps.envOrReadAddress(".ngt", "FOUNDRY_NGT"); | ||
address dist = deps.envOrReadAddress(".dist", "FOUNDRY_DIST"); | ||
address farm = deps.envOrReadAddress(".farm", "FOUNDRY_FARM"); | ||
address vest = deps.envOrReadAddress(".vest", "FOUNDRY_VEST"); | ||
|
||
Reader config = new Reader(ScriptTools.loadConfig()); | ||
|
||
uint256 vestCap = config.readUint(".vestCap"); | ||
uint256 vestTot = config.readUint(".vestTot"); | ||
uint256 vestBgn = config.readUint(".vestBgn"); | ||
uint256 vestTau = config.readUint(".vestTau"); | ||
|
||
require(WithGemLike(dist).gem() == ngt, "VestedRewardsDistribution/invalid-gem"); | ||
require(WithGemLike(vest).gem() == ngt, "DssVest/invalid-gem"); | ||
require(StakingRewardsLike(farm).rewardsToken() == ngt, "StakingRewards/invalid-rewards-token"); | ||
|
||
vm.startBroadcast(); | ||
|
||
// Grant minting rights on `ngt` to `vest`. | ||
RelyLike(ngt).rely(vest); | ||
|
||
// Define global max vesting ratio on `vest`. | ||
VestInit.init(vest, VestInitParams({cap: vestCap})); | ||
|
||
// Set `dist` with `rewardsDistribution` role in `farm`. | ||
StakingRewardsInit.init(farm, StakingRewardsInitParams({dist: dist})); | ||
|
||
// Create the proper vesting stream for rewards distribution. | ||
uint256 vestId = VestInit.create( | ||
vest, | ||
VestCreateParams({usr: dist, tot: vestTot, bgn: vestBgn, tau: vestTau, eta: 0}) | ||
); | ||
|
||
// Set the `vestId` in `dist` | ||
VestedRewardsDistributionInit.init(dist, VestedRewardsDistributionInitParams({vestId: vestId})); | ||
|
||
vm.stopBroadcast(); | ||
|
||
ScriptTools.exportContract(NAME, "ngt", ngt); | ||
ScriptTools.exportContract(NAME, "dist", dist); | ||
ScriptTools.exportContract(NAME, "farm", farm); | ||
ScriptTools.exportContract(NAME, "vest", vest); | ||
ScriptTools.exportContract(NAME, "vestId", address(uint160(vestId))); | ||
ScriptTools.exportContract(NAME, "vestTot", address(uint160(vestTot))); | ||
ScriptTools.exportContract(NAME, "vestBgn", address(uint160(vestBgn))); | ||
ScriptTools.exportContract(NAME, "vestTau", address(uint160(vestTau))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.