Skip to content

Commit

Permalink
Feat: add Phase 1d scripts (#29)
Browse files Browse the repository at this point in the history
* feat: add USDS -> SPK farm scripts

* feat: add SKY -> SPK farm scripts

* feat: add SPK -> SKY farm scripts

* refactor: move phase-1d testnet to different chain ID
  • Loading branch information
amusingaxl authored Oct 4, 2024
1 parent 1e419c6 commit 45a533c
Show file tree
Hide file tree
Showing 25 changed files with 1,276 additions and 1 deletion.
124 changes: 124 additions & 0 deletions script/dependencies/phase-1d/SkySpkFarmingInit.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// 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.16;

import {StakingRewardsInit, StakingRewardsInitParams} from "../StakingRewardsInit.sol";
import {VestedRewardsDistributionInit, VestedRewardsDistributionInitParams} from "../VestedRewardsDistributionInit.sol";
import {VestInit, VestCreateParams} from "../VestInit.sol";

struct SkySpkFarmingInitParams {
address sky;
address spk;
address rewards;
bytes32 rewardsKey; // Chainlog key
address dist;
bytes32 distKey; // Chainlog key
address vest;
uint256 vestTot;
uint256 vestBgn;
uint256 vestTau;
}

struct SkySpkFarmingInitResult {
uint256 vestId;
}

library SkySpkFarmingInit {
ChainlogLike internal constant chainlog = ChainlogLike(0xdA0Ab1e0017DEbCd72Be8599041a2aa3bA7e740F);

function init(SkySpkFarmingInitParams memory p) internal returns (SkySpkFarmingInitResult memory r) {
require(DssVestWithGemLike(p.vest).gem() == p.spk, "SkySpkFarmingInit/vest-gem-mismatch");

require(
StakingRewardsLike(p.rewards).stakingToken() == p.sky,
"SkySpkFarmingInit/rewards-staking-token-mismatch"
);
require(
StakingRewardsLike(p.rewards).rewardsToken() == p.spk,
"SkySpkFarmingInit/rewards-rewards-token-mismatch"
);
require(StakingRewardsLike(p.rewards).rewardRate() == 0, "SkySpkFarmingInit/reward-rate-not-zero");
require(
StakingRewardsLike(p.rewards).rewardsDistribution() == address(0),
"SkySpkFarmingInit/rewards-distribution-already-set"
);
require(
StakingRewardsLike(p.rewards).owner() == chainlog.getAddress("MCD_PAUSE_PROXY"),
"SkySpkFarmingInit/invalid-owner"
);

require(VestedRewardsDistributionLike(p.dist).gem() == p.spk, "SkySpkFarmingInit/dist-gem-mismatch");
require(VestedRewardsDistributionLike(p.dist).dssVest() == p.vest, "SkySpkFarmingInit/dist-dss-vest-mismatch");
require(
VestedRewardsDistributionLike(p.dist).stakingRewards() == p.rewards,
"SkySpkFarmingInit/dist-staking-rewards-mismatch"
);

// `vest` is expected to be an instance of `DssVestMintable`.
// Check if minting rights on `spk` were granted to `vest`.
require(WardsLike(p.spk).wards(p.vest) == 1, "SkySpkFarmingInit/missing-spk-rely-vest");
// Set `dist` with `rewardsDistribution` role in `rewards`.
StakingRewardsInit.init(p.rewards, StakingRewardsInitParams({dist: p.dist}));

// Create the proper vesting stream for rewards distribution.
uint256 vestId = VestInit.create(
p.vest,
VestCreateParams({usr: p.dist, tot: p.vestTot, bgn: p.vestBgn, tau: p.vestTau, eta: 0})
);

// Set the `vestId` in `dist`
VestedRewardsDistributionInit.init(p.dist, VestedRewardsDistributionInitParams({vestId: vestId}));

r.vestId = vestId;

chainlog.setAddress(p.rewardsKey, p.rewards);
chainlog.setAddress(p.distKey, p.dist);
}
}

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

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

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

function rewardRate() external view returns (uint256);

function rewardsDistribution() external view returns (address);

function rewardsToken() external view returns (address);

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

interface VestedRewardsDistributionLike {
function dssVest() external view returns (address);

function gem() external view returns (address);

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

interface ChainlogLike {
function getAddress(bytes32 key) external view returns (address);

function setAddress(bytes32 key, address addr) external;
}
124 changes: 124 additions & 0 deletions script/dependencies/phase-1d/SpkSkyFarmingInit.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// 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.16;

import {StakingRewardsInit, StakingRewardsInitParams} from "../StakingRewardsInit.sol";
import {VestedRewardsDistributionInit, VestedRewardsDistributionInitParams} from "../VestedRewardsDistributionInit.sol";
import {VestInit, VestCreateParams} from "../VestInit.sol";

struct SpkSkyFarmingInitParams {
address spk;
address sky;
address rewards;
bytes32 rewardsKey; // Chainlog key
address dist;
bytes32 distKey; // Chainlog key
address vest;
uint256 vestTot;
uint256 vestBgn;
uint256 vestTau;
}

struct SpkSkyFarmingInitResult {
uint256 vestId;
}

library SpkSkyFarmingInit {
ChainlogLike internal constant chainlog = ChainlogLike(0xdA0Ab1e0017DEbCd72Be8599041a2aa3bA7e740F);

function init(SpkSkyFarmingInitParams memory p) internal returns (SpkSkyFarmingInitResult memory r) {
require(DssVestWithGemLike(p.vest).gem() == p.sky, "SpkSkyFarmingInit/vest-gem-mismatch");

require(
StakingRewardsLike(p.rewards).stakingToken() == p.spk,
"SpkSkyFarmingInit/rewards-staking-token-mismatch"
);
require(
StakingRewardsLike(p.rewards).rewardsToken() == p.sky,
"SpkSkyFarmingInit/rewards-rewards-token-mismatch"
);
require(StakingRewardsLike(p.rewards).rewardRate() == 0, "SpkSkyFarmingInit/reward-rate-not-zero");
require(
StakingRewardsLike(p.rewards).rewardsDistribution() == address(0),
"SpkSkyFarmingInit/rewards-distribution-already-set"
);
require(
StakingRewardsLike(p.rewards).owner() == chainlog.getAddress("MCD_PAUSE_PROXY"),
"SpkSkyFarmingInit/invalid-owner"
);

require(VestedRewardsDistributionLike(p.dist).gem() == p.sky, "SpkSkyFarmingInit/dist-gem-mismatch");
require(VestedRewardsDistributionLike(p.dist).dssVest() == p.vest, "SpkSkyFarmingInit/dist-dss-vest-mismatch");
require(
VestedRewardsDistributionLike(p.dist).stakingRewards() == p.rewards,
"SpkSkyFarmingInit/dist-staking-rewards-mismatch"
);

// `vest` is expected to be an instance of `DssVestMintable`.
// Check if minting rights on `sky` were granted to `vest`.
require(WardsLike(p.sky).wards(p.vest) == 1, "SpkSkyFarmingInit/missing-sky-rely-vest");
// Set `dist` with `rewardsDistribution` role in `rewards`.
StakingRewardsInit.init(p.rewards, StakingRewardsInitParams({dist: p.dist}));

// Create the proper vesting stream for rewards distribution.
uint256 vestId = VestInit.create(
p.vest,
VestCreateParams({usr: p.dist, tot: p.vestTot, bgn: p.vestBgn, tau: p.vestTau, eta: 0})
);

// Set the `vestId` in `dist`
VestedRewardsDistributionInit.init(p.dist, VestedRewardsDistributionInitParams({vestId: vestId}));

r.vestId = vestId;

chainlog.setAddress(p.rewardsKey, p.rewards);
chainlog.setAddress(p.distKey, p.dist);
}
}

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

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

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

function rewardRate() external view returns (uint256);

function rewardsDistribution() external view returns (address);

function rewardsToken() external view returns (address);

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

interface VestedRewardsDistributionLike {
function dssVest() external view returns (address);

function gem() external view returns (address);

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

interface ChainlogLike {
function getAddress(bytes32 key) external view returns (address);

function setAddress(bytes32 key, address addr) external;
}
124 changes: 124 additions & 0 deletions script/dependencies/phase-1d/UsdsSpkFarmingInit.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// 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.16;

import {StakingRewardsInit, StakingRewardsInitParams} from "../StakingRewardsInit.sol";
import {VestedRewardsDistributionInit, VestedRewardsDistributionInitParams} from "../VestedRewardsDistributionInit.sol";
import {VestInit, VestCreateParams} from "../VestInit.sol";

struct UsdsSpkFarmingInitParams {
address usds;
address spk;
address rewards;
bytes32 rewardsKey; // Chainlog key
address dist;
bytes32 distKey; // Chainlog key
address vest;
uint256 vestTot;
uint256 vestBgn;
uint256 vestTau;
}

struct UsdsSpkFarmingInitResult {
uint256 vestId;
}

library UsdsSpkFarmingInit {
ChainlogLike internal constant chainlog = ChainlogLike(0xdA0Ab1e0017DEbCd72Be8599041a2aa3bA7e740F);

function init(UsdsSpkFarmingInitParams memory p) internal returns (UsdsSpkFarmingInitResult memory r) {
require(DssVestWithGemLike(p.vest).gem() == p.spk, "UsdsSpkFarmingInit/vest-gem-mismatch");

require(
StakingRewardsLike(p.rewards).stakingToken() == p.usds,
"UsdsSpkFarmingInit/rewards-staking-token-mismatch"
);
require(
StakingRewardsLike(p.rewards).rewardsToken() == p.spk,
"UsdsSpkFarmingInit/rewards-rewards-token-mismatch"
);
require(StakingRewardsLike(p.rewards).rewardRate() == 0, "UsdsSpkFarmingInit/reward-rate-not-zero");
require(
StakingRewardsLike(p.rewards).rewardsDistribution() == address(0),
"UsdsSpkFarmingInit/rewards-distribution-already-set"
);
require(
StakingRewardsLike(p.rewards).owner() == chainlog.getAddress("MCD_PAUSE_PROXY"),
"UsdsSpkFarmingInit/invalid-owner"
);

require(VestedRewardsDistributionLike(p.dist).gem() == p.spk, "UsdsSpkFarmingInit/dist-gem-mismatch");
require(VestedRewardsDistributionLike(p.dist).dssVest() == p.vest, "UsdsSpkFarmingInit/dist-dss-vest-mismatch");
require(
VestedRewardsDistributionLike(p.dist).stakingRewards() == p.rewards,
"UsdsSpkFarmingInit/dist-staking-rewards-mismatch"
);

// `vest` is expected to be an instance of `DssVestMintable`.
// Check if minting rights on `spk` were granted to `vest`.
require(WardsLike(p.spk).wards(p.vest) == 1, "UsdsSpkFarmingInit/missing-spk-rely-vest");
// Set `dist` with `rewardsDistribution` role in `rewards`.
StakingRewardsInit.init(p.rewards, StakingRewardsInitParams({dist: p.dist}));

// Create the proper vesting stream for rewards distribution.
uint256 vestId = VestInit.create(
p.vest,
VestCreateParams({usr: p.dist, tot: p.vestTot, bgn: p.vestBgn, tau: p.vestTau, eta: 0})
);

// Set the `vestId` in `dist`
VestedRewardsDistributionInit.init(p.dist, VestedRewardsDistributionInitParams({vestId: vestId}));

r.vestId = vestId;

chainlog.setAddress(p.rewardsKey, p.rewards);
chainlog.setAddress(p.distKey, p.dist);
}
}

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

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

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

function rewardRate() external view returns (uint256);

function rewardsDistribution() external view returns (address);

function rewardsToken() external view returns (address);

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

interface VestedRewardsDistributionLike {
function dssVest() external view returns (address);

function gem() external view returns (address);

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

interface ChainlogLike {
function getAddress(bytes32 key) external view returns (address);

function setAddress(bytes32 key, address addr) external;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"usds": "address: the address of USDS",
"vest": "address: the address of a DssVestMintable contract for SKY",
"rewards": "[OPTIONAL] address: the address of the StakingRewards contract",
"dist": "[OPTIONAL ]address: the address of the VestedRewardsDistrubution contract"
"dist": "[OPTIONAL] address: the address of the VestedRewardsDistrubution contract"
}
1 change: 1 addition & 0 deletions script/input/1/phase-1d/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Script inputs for Mainnet for `phase-1d`.
7 changes: 7 additions & 0 deletions script/input/1/phase-1d/template-sky-spk-farming-deploy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sky": "address: the address of SKY",
"spk": "address: the address of SPK",
"vest": "address: the address of a DssVestMintable contract for SPK",
"rewards": "[OPTIONAL] address: the address of the StakingRewards contract",
"dist": "[OPTIONAL] address: the address of the VestedRewardsDistrubution contract"
}
7 changes: 7 additions & 0 deletions script/input/1/phase-1d/template-spk-sky-farming-deploy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"spk": "address: the address of SPK",
"sky": "address: the address of SKY",
"vest": "address: the address of a DssVestMintable contract for SKY",
"rewards": "[OPTIONAL] address: the address of the StakingRewards contract",
"dist": "[OPTIONAL] address: the address of the VestedRewardsDistrubution contract"
}
Loading

0 comments on commit 45a533c

Please sign in to comment.