Skip to content

Commit

Permalink
Mainnet spell 2024-10-17 (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
SidestreamColdMelon authored Oct 18, 2024
1 parent 36f0dc5 commit 460b178
Show file tree
Hide file tree
Showing 27 changed files with 9,961 additions and 1,377 deletions.
411 changes: 411 additions & 0 deletions archive/2024-10-17-DssSpell/DssSpell.sol

Large diffs are not rendered by default.

3,178 changes: 3,178 additions & 0 deletions archive/2024-10-17-DssSpell/DssSpell.t.base.sol

Large diffs are not rendered by default.

1,021 changes: 1,021 additions & 0 deletions archive/2024-10-17-DssSpell/DssSpell.t.sol

Large diffs are not rendered by default.

211 changes: 211 additions & 0 deletions archive/2024-10-17-DssSpell/dependencies/dss-flappers/FlapperInit.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
// 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 { DssInstance } from "dss-test/MCD.sol";
import { SplitterInstance } from "./SplitterInstance.sol";

interface FlapperUniV2Like {
function pip() external view returns (address);
function spotter() external view returns (address);
function usds() external view returns (address);
function gem() external view returns (address);
function receiver() external view returns (address);
function pair() external view returns (address);
function rely(address) external;
function file(bytes32, uint256) external;
function file(bytes32, address) external;
}

interface SplitterMomLike {
function splitter() external view returns (address);
function setAuthority(address) external;
}

interface OracleWrapperLike {
function pip() external view returns (address);
function divisor() external view returns (uint256);
}

interface PipLike {
function kiss(address) external;
}

interface PairLike {
function token0() external view returns (address);
function token1() external view returns (address);
}

interface UsdsJoinLike {
function dai() external view returns (address); // TODO: Replace when new join is ready by the new getter
}

interface SplitterLike {
function live() external view returns (uint256);
function vat() external view returns (address);
function usdsJoin() external view returns (address);
function hop() external view returns (uint256);
function rely(address) external;
function file(bytes32, uint256) external;
function file(bytes32, address) external;
}

interface FarmLike {
function rewardsToken() external view returns (address);
function setRewardsDistribution(address) external;
function setRewardsDuration(uint256) external;
}

struct FlapperUniV2Config {
uint256 want;
address pip;
address pair;
address usds;
address splitter;
bytes32 prevChainlogKey;
bytes32 chainlogKey;
}

struct FarmConfig {
address splitter;
address usdsJoin;
uint256 hop;
bytes32 prevChainlogKey;
bytes32 chainlogKey;
}

struct SplitterConfig {
uint256 hump;
uint256 bump;
uint256 hop;
uint256 burn;
address usdsJoin;
bytes32 splitterChainlogKey;
bytes32 prevMomChainlogKey;
bytes32 momChainlogKey;
}

library FlapperInit {
uint256 constant WAD = 10 ** 18;
uint256 constant RAY = 10 ** 27;

function initFlapperUniV2(
DssInstance memory dss,
address flapper_,
FlapperUniV2Config memory cfg
) internal {
FlapperUniV2Like flapper = FlapperUniV2Like(flapper_);

// Sanity checks
require(flapper.spotter() == address(dss.spotter), "Flapper spotter mismatch");
require(flapper.usds() == cfg.usds, "Flapper usds mismatch");
require(flapper.pair() == cfg.pair, "Flapper pair mismatch");
require(flapper.receiver() == dss.chainlog.getAddress("MCD_PAUSE_PROXY"), "Flapper receiver mismatch");

PairLike pair = PairLike(flapper.pair());
(address pairUsds, address pairGem) = pair.token0() == cfg.usds ? (pair.token0(), pair.token1())
: (pair.token1(), pair.token0());
require(pairUsds == cfg.usds, "Usds mismatch");
require(pairGem == flapper.gem(), "Gem mismatch");

require(cfg.want >= WAD * 90 / 100, "want too low");

flapper.file("want", cfg.want);
flapper.file("pip", cfg.pip);
flapper.rely(cfg.splitter);

SplitterLike(cfg.splitter).file("flapper", flapper_);

if (cfg.prevChainlogKey != bytes32(0)) dss.chainlog.removeAddress(cfg.prevChainlogKey);
dss.chainlog.setAddress(cfg.chainlogKey, flapper_);
}

function initDirectOracle(address flapper) internal {
PipLike(FlapperUniV2Like(flapper).pip()).kiss(flapper);
}

function initOracleWrapper(
DssInstance memory dss,
address wrapper_,
uint256 divisor,
bytes32 clKey
) internal {
OracleWrapperLike wrapper = OracleWrapperLike(wrapper_);
require(wrapper.divisor() == divisor, "Wrapper divisor mismatch"); // Sanity check
PipLike(wrapper.pip()).kiss(wrapper_);
dss.chainlog.setAddress(clKey, wrapper_);
}

function setFarm(
DssInstance memory dss,
address farm_,
FarmConfig memory cfg
) internal {
FarmLike farm = FarmLike(farm_);
SplitterLike splitter = SplitterLike(cfg.splitter);

require(farm.rewardsToken() == UsdsJoinLike(cfg.usdsJoin).dai(), "Farm rewards not usds");
// Staking token is checked in the Lockstake script

// The following two checks enforce the initSplitter function has to be called first
require(cfg.hop >= 5 minutes, "hop too low");
require(cfg.hop == splitter.hop(), "hop mismatch");

splitter.file("farm", farm_);

farm.setRewardsDistribution(cfg.splitter);
farm.setRewardsDuration(cfg.hop);

if (cfg.prevChainlogKey != bytes32(0)) dss.chainlog.removeAddress(cfg.prevChainlogKey);
dss.chainlog.setAddress(cfg.chainlogKey, farm_);
}

function initSplitter(
DssInstance memory dss,
SplitterInstance memory splitterInstance,
SplitterConfig memory cfg
) internal {
SplitterLike splitter = SplitterLike(splitterInstance.splitter);
SplitterMomLike mom = SplitterMomLike(splitterInstance.mom);

// Sanity checks
require(splitter.live() == 1, "Splitter not live");
require(splitter.vat() == address(dss.vat), "Splitter vat mismatch");
require(splitter.usdsJoin() == cfg.usdsJoin, "Splitter usdsJoin mismatch");
require(mom.splitter() == splitterInstance.splitter, "Mom splitter mismatch");

require(cfg.hump > 0, "hump too low");
require(cfg.bump % RAY == 0, "bump not multiple of RAY");
require(cfg.hop >= 5 minutes, "hop too low");
require(cfg.burn <= WAD, "burn too high");

splitter.file("hop", cfg.hop);
splitter.file("burn", cfg.burn);
splitter.rely(address(mom));
splitter.rely(address(dss.vow));

dss.vow.file("flapper", splitterInstance.splitter);
dss.vow.file("hump", cfg.hump);
dss.vow.file("bump", cfg.bump);

mom.setAuthority(dss.chainlog.getAddress("MCD_ADM"));

dss.chainlog.setAddress(cfg.splitterChainlogKey, splitterInstance.splitter);
if (cfg.prevMomChainlogKey != bytes32(0)) dss.chainlog.removeAddress(cfg.prevMomChainlogKey);
dss.chainlog.setAddress(cfg.momChainlogKey, address(mom));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: © 2022 Dai Foundation <www.daifoundation.org>
// 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
Expand All @@ -16,7 +16,7 @@

pragma solidity >=0.8.0;

struct D3MCoreInstance {
address hub;
struct SplitterInstance {
address splitter;
address mom;
}
Loading

0 comments on commit 460b178

Please sign in to comment.