|
| 1 | +// SPDX-FileCopyrightText: © 2025 Dai Foundation <www.daifoundation.org> |
| 2 | +// SPDX-License-Identifier: AGPL-3.0-or-later |
| 3 | +// |
| 4 | +// This program is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU Affero General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// This program is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU Affero General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU Affero General Public License |
| 15 | +// along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +pragma solidity >=0.8.0; |
| 18 | + |
| 19 | +import {DssInstance} from "dss-test/MCD.sol"; |
| 20 | + |
| 21 | +interface HyperBurnerLike { |
| 22 | + function psm() external view returns (address); |
| 23 | + function vat() external view returns (address); |
| 24 | + function daiJoin() external view returns (address); |
| 25 | + function dai() external view returns (address); |
| 26 | + function usdc() external view returns (address); |
| 27 | + function vow() external view returns (address); |
| 28 | + function gemTo18ConversionFactor() external view returns (uint256); |
| 29 | + function file(bytes32 what, address data) external; |
| 30 | + function file(bytes32 what, uint256 data) external; |
| 31 | + function wards(address usr) external view returns (uint256); |
| 32 | +} |
| 33 | + |
| 34 | +interface PSMLike { |
| 35 | + function to18ConversionFactor() external view returns (uint256); |
| 36 | + function kiss(address usr) external; |
| 37 | +} |
| 38 | + |
| 39 | +struct HyperBurnerInitConfig { |
| 40 | + address bot; |
| 41 | + address freezer; |
| 42 | + address psm; |
| 43 | + uint256 bump; |
| 44 | + uint256 hump; |
| 45 | + uint256 hop; |
| 46 | + bytes32 hyperBurnerKey; |
| 47 | +} |
| 48 | + |
| 49 | +library HyperBurnerInit { |
| 50 | + uint256 constant internal RAD = 10**45; |
| 51 | + |
| 52 | + /// @notice Initializes HyperBurner contract with the specified configuration. |
| 53 | + /// @dev Sets up permissions and configures parameters. |
| 54 | + /// @param dss The DSS (MakerDAO) instance containing core contract references. |
| 55 | + /// @param hyperBurner_ The HyperBurner contract address to initialize. |
| 56 | + /// @param cfg The configuration parameters for HyperBurner. |
| 57 | + function init( |
| 58 | + DssInstance memory dss, |
| 59 | + address hyperBurner_, |
| 60 | + HyperBurnerInitConfig memory cfg |
| 61 | + ) internal { |
| 62 | + HyperBurnerLike hyperBurner = HyperBurnerLike(hyperBurner_); |
| 63 | + PSMLike psm = PSMLike(cfg.psm); |
| 64 | + |
| 65 | + // Sanity checks |
| 66 | + require(cfg.bot != address(0), "HyperBurnerInit: zero bot"); |
| 67 | + require(cfg.bump >= RAD, "HyperBurnerInit: bump too low"); |
| 68 | + require(cfg.hump >= RAD, "HyperBurnerInit: hump too low"); |
| 69 | + require(cfg.hop > 0, "HyperBurnerInit: zero hop"); |
| 70 | + require(cfg.psm == hyperBurner.psm(), "HyperBurnerInit: PSM mismatch"); |
| 71 | + require(hyperBurner.wards(dss.chainlog.getAddress("MCD_PAUSE_PROXY")) == 1, "HyperBurnerInit: MCD_PAUSE_PROXY not relied"); |
| 72 | + require(psm.to18ConversionFactor() == hyperBurner.gemTo18ConversionFactor(), "HyperBurnerInit: gemTo18ConversionFactor mismatch"); |
| 73 | + require(hyperBurner.daiJoin() == dss.chainlog.getAddress("MCD_JOIN_DAI"), "HyperBurnerInit: DaiJoin mismatch"); |
| 74 | + require(hyperBurner.dai() == address(dss.dai), "HyperBurnerInit: Dai mismatch"); |
| 75 | + require(hyperBurner.vat() == address(dss.vat), "HyperBurnerInit: Vat mismatch"); |
| 76 | + require(hyperBurner.vow() == address(dss.vow), "HyperBurnerInit: Vow mismatch"); |
| 77 | + |
| 78 | + // Approve the HyperBurner contract to swap without fee on PSM |
| 79 | + psm.kiss(address(hyperBurner)); |
| 80 | + |
| 81 | + // Authorize HyperBurner to vat |
| 82 | + dss.vat.rely(hyperBurner_); |
| 83 | + |
| 84 | + // Set bot |
| 85 | + hyperBurner.file("bot", cfg.bot); |
| 86 | + // Set freezer |
| 87 | + hyperBurner.file("freezer", cfg.freezer); |
| 88 | + // Set bump |
| 89 | + hyperBurner.file("bump", cfg.bump); |
| 90 | + // Set hump |
| 91 | + hyperBurner.file("hump", cfg.hump); |
| 92 | + // Set hop |
| 93 | + hyperBurner.file("hop", cfg.hop); |
| 94 | + |
| 95 | + // Add HyperBurner address to chainlog |
| 96 | + dss.chainlog.setAddress(cfg.hyperBurnerKey, hyperBurner_); |
| 97 | + } |
| 98 | +} |
0 commit comments