PE-805

Created Diff never expires
1 removal
587 lines
6 additions
591 lines
/**
*Submitted for verification at Etherscan.io on 2022-01-14
*/

// hevm: flattened sources of src/DssSpell.sol
// hevm: flattened sources of src/DssSpell.sol
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity =0.6.12 >=0.6.12 <0.7.0;
pragma solidity =0.6.12 >=0.6.12 <0.7.0;
pragma experimental ABIEncoderV2;
// pragma experimental ABIEncoderV2;


////// lib/dss-exec-lib/src/CollateralOpts.sol
////// lib/dss-exec-lib/src/CollateralOpts.sol
/* pragma solidity ^0.6.12; */
/* pragma solidity ^0.6.12; */


struct CollateralOpts {
struct CollateralOpts {
bytes32 ilk;
bytes32 ilk;
address gem;
address gem;
address join;
address join;
address clip;
address clip;
address calc;
address calc;
address pip;
address pip;
bool isLiquidatable;
bool isLiquidatable;
bool isOSM;
bool isOSM;
bool whitelistOSM;
bool whitelistOSM;
uint256 ilkDebtCeiling;
uint256 ilkDebtCeiling;
uint256 minVaultAmount;
uint256 minVaultAmount;
uint256 maxLiquidationAmount;
uint256 maxLiquidationAmount;
uint256 liquidationPenalty;
uint256 liquidationPenalty;
uint256 ilkStabilityFee;
uint256 ilkStabilityFee;
uint256 startingPriceFactor;
uint256 startingPriceFactor;
uint256 breakerTolerance;
uint256 breakerTolerance;
uint256 auctionDuration;
uint256 auctionDuration;
uint256 permittedDrop;
uint256 permittedDrop;
uint256 liquidationRatio;
uint256 liquidationRatio;
uint256 kprFlatReward;
uint256 kprFlatReward;
uint256 kprPctReward;
uint256 kprPctReward;
}
}


////// lib/dss-exec-lib/src/DssExecLib.sol
////// lib/dss-exec-lib/src/DssExecLib.sol
//
//
// DssExecLib.sol -- MakerDAO Executive Spellcrafting Library
// DssExecLib.sol -- MakerDAO Executive Spellcrafting Library
//
//
// Copyright (C) 2020 Maker Ecosystem Growth Holdings, Inc.
// Copyright (C) 2020 Maker Ecosystem Growth Holdings, Inc.
//
//
// This program is free software: you can redistribute it and/or modify
// 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
// 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
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// (at your option) any later version.
//
//
// This program is distributed in the hope that it will be useful,
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
// GNU Affero General Public License for more details.
//
//
// You should have received a copy of the GNU Affero General Public License
// 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/>.
// along with this program. If not, see <https://www.gnu.org/licenses/>.
/* pragma solidity ^0.6.12; */
/* pragma solidity ^0.6.12; */
/* pragma experimental ABIEncoderV2; */
/* pragma experimental ABIEncoderV2; */


/* import { CollateralOpts } from "./CollateralOpts.sol"; */
/* import { CollateralOpts } from "./CollateralOpts.sol"; */


interface Initializable {
interface Initializable {
function init(bytes32) external;
function init(bytes32) external;
}
}


interface Authorizable {
interface Authorizable {
function rely(address) external;
function rely(address) external;
function deny(address) external;
function deny(address) external;
function setAuthority(address) external;
function setAuthority(address) external;
}
}


interface Fileable {
interface Fileable {
function file(bytes32, address) external;
function file(bytes32, address) external;
function file(bytes32, uint256) external;
function file(bytes32, uint256) external;
function file(bytes32, bytes32, uint256) external;
function file(bytes32, bytes32, uint256) external;
function file(bytes32, bytes32, address) external;
function file(bytes32, bytes32, address) external;
}
}


interface Drippable {
interface Drippable {
function drip() external returns (uint256);
function drip() external returns (uint256);
function drip(bytes32) external returns (uint256);
function drip(bytes32) external returns (uint256);
}
}


interface Pricing {
interface Pricing {
function poke(bytes32) external;
function poke(bytes32) external;
}
}


interface ERC20 {
interface ERC20 {
function decimals() external returns (uint8);
function decimals() external returns (uint8);
}
}


interface DssVat {
interface DssVat {
function hope(address) external;
function hope(address) external;
function nope(address) external;
function nope(address) external;
function ilks(bytes32) external returns (uint256 Art, uint256 rate, uint256 spot, uint256 line, uint256 dust);
function ilks(bytes32) external returns (uint256 Art, uint256 rate, uint256 spot, uint256 line, uint256 dust);
function Line() external view returns (uint256);
function Line() external view returns (uint256);
function suck(address, address, uint) external;
function suck(address, address, uint) external;
}
}


interface ClipLike {
interface ClipLike {
function vat() external returns (address);
function vat() external returns (address);
function dog() external returns (address);
function dog() external returns (address);
function spotter() external view returns (address);
function spotter() external view returns (address);
function calc() external view returns (address);
function calc() external view returns (address);
function ilk() external returns (bytes32);
function ilk() external returns (bytes32);
}
}


interface DogLike {
interface DogLike {
function ilks(bytes32) external returns (address clip, uint256 chop, uint256 hole, uint256 dirt);
function ilks(bytes32) external returns (address clip, uint256 chop, uint256 hole, uint256 dirt);
}
}


interface JoinLike {
interface JoinLike {
function vat() external returns (address);
function vat() external returns (address);
function ilk() external returns (bytes32);
function ilk() external returns (bytes32);
function gem() external returns (address);
function gem() external returns (address);
function dec() external returns (uint256);
function dec() external returns (uint256);
function join(address, uint) external;
function join(address, uint) external;
function exit(address, uint) external;
function exit(address, uint) external;
}
}


// Includes Median and OSM functions
// Includes Median and OSM functions
interface OracleLike_2 {
interface OracleLike_2 {
function src() external view returns (address);
function src() external view returns (address);
function lift(address[] calldata) external;
function lift(address[] calldata) external;
function drop(address[] calldata) external;
function drop(address[] calldata) external;
function setBar(uint256) external;
function setBar(uint256) external;
function kiss(address) external;
function kiss(address) external;
function diss(address) external;
function diss(address) external;
function kiss(address[] calldata) external;
function kiss(address[] calldata) external;
function diss(address[] calldata) external;
function diss(address[] calldata) external;
function orb0() external view returns (address);
function orb0() external view returns (address);
function orb1() external view returns (address);
function orb1() external view returns (address);
}
}


interface MomLike {
interface MomLike {
function setOsm(bytes32, address) external;
function setOsm(bytes32, address) external;
function setPriceTolerance(address, uint256) external;
function setPriceTolerance(address, uint256) external;
}
}


interface RegistryLike {
interface RegistryLike {
function add(address) external;
function add(address) external;
function xlip(bytes32) external view returns (address);
function xlip(bytes32) external view returns (address);
}
}


// https://github.com/makerdao/dss-chain-log
// https://github.com/makerdao/dss-chain-log
interface ChainlogLike {
interface ChainlogLike {
function setVersion(string calldata) external;
function setVersion(string calldata) external;
function setIPFS(string calldata) external;
function setIPFS(string calldata) external;
function setSha256sum(string calldata) external;
function setSha256sum(string calldata) external;
function getAddress(bytes32) external view returns (address);
function getAddress(bytes32) external view returns (address);
function setAddress(bytes32, address) external;
function setAddress(bytes32, address) external;
function removeAddress(bytes32) external;
function removeAddress(bytes32) external;
}
}


interface IAMLike {
interface IAMLike {
function ilks(bytes32) external view returns (uint256,uint256,uint48,uint48,uint48);
function ilks(bytes32) external view returns (uint256,uint256,uint48,uint48,uint48);
function setIlk(bytes32,uint256,uint256,uint256) external;
function setIlk(bytes32,uint256,uint256,uint256) external;
function remIlk(bytes32) external;
function remIlk(bytes32) external;
function exec(bytes32) external returns (uint256);
function exec(bytes32) external returns (uint256);
}
}


interface LerpFactoryLike {
interface LerpFactoryLike {
function newLerp(bytes32 name_, address target_, bytes32 what_, uint256 startTime_, uint256 start_, uint256 end_, uint256 duration_) external returns (address);
function newLerp(bytes32 name_, address target_, bytes32 what_, uint256 startTime_, uint256 start_, uint256 end_, uint256 duration_) external returns (address);
function newIlkLerp(bytes32 name_, address target_, bytes32 ilk_, bytes32 what_, uint256 startTime_, uint256 start_, uint256 end_, uint256 duration_) external returns (address);
function newIlkLerp(bytes32 name_, address target_, bytes32 ilk_, bytes32 what_, uint256 startTime_, uint256 start_, uint256 end_, uint256 duration_) external returns (address);
}
}


interface LerpLike {
interface LerpLike {
function tick() external returns (uint256);
function tick() external returns (uint256);
}
}




library DssExecLib {
library DssExecLib {


/*****************/
/*****************/
/*** Constants ***/
/*** Constants ***/
/*****************/
/*****************/
address constant public LOG = 0xdA0Ab1e0017DEbCd72Be8599041a2aa3bA7e740F;
address constant public LOG = 0xdA0Ab1e0017DEbCd72Be8599041a2aa3bA7e740F;


uint256 constant internal WAD = 10 ** 18;
uint256 constant internal WAD = 10 ** 18;
uint256 constant internal RAY = 10 ** 27;
uint256 constant internal RAY = 10 ** 27;
uint256 constant internal RAD = 10 ** 45;
uint256 constant internal RAD = 10 ** 45;
uint256 constant internal THOUSAND = 10 ** 3;
uint256 constant internal THOUSAND = 10 ** 3;
uint256 constant internal MILLION = 10 ** 6;
uint256 constant internal MILLION = 10 ** 6;


uint256 constant internal BPS_ONE_PCT = 100;
uint256 constant internal BPS_ONE_PCT = 100;
uint256 constant internal BPS_ONE_HUNDRED_PCT = 100 * BPS_ONE_PCT;
uint256 constant internal BPS_ONE_HUNDRED_PCT = 100 * BPS_ONE_PCT;
uint256 constant internal RATES_ONE_HUNDRED_PCT = 1000000021979553151239153027;
uint256 constant internal RATES_ONE_HUNDRED_PCT = 1000000021979553151239153027;


/**********************/
/**********************/
/*** Math Functions ***/
/*** Math Functions ***/
/**********************/
/**********************/
function add(uint256 x, uint256 y) internal pure returns (uint256 z) {
function add(uint256 x, uint256 y) internal pure returns (uint256 z) {
require((z = x + y) >= x);
require((z = x + y) >= x);
}
}
function sub(uint256 x, uint256 y) internal pure returns (uint256 z) {
function sub(uint256 x, uint256 y) internal pure returns (uint256 z) {
require((z = x - y) <= x);
require((z = x - y) <= x);
}
}
function mul(uint256 x, uint256 y) internal pure returns (uint256 z) {
function mul(uint256 x, uint256 y) internal pure returns (uint256 z) {
require(y == 0 || (z = x * y) / y == x);
require(y == 0 || (z = x * y) / y == x);
}
}
function wmul(uint256 x, uint256 y) internal pure returns (uint256 z) {
function wmul(uint256 x, uint256 y) internal pure returns (uint256 z) {
z = add(mul(x, y), WAD / 2) / WAD;
z = add(mul(x, y), WAD / 2) / WAD;
}
}
function rmul(uint256 x, uint256 y) internal pure returns (uint256 z) {
function rmul(uint256 x, uint256 y) internal pure returns (uint256 z) {
z = add(mul(x, y), RAY / 2) / RAY;
z = add(mul(x, y), RAY / 2) / RAY;
}
}
function wdiv(uint256 x, uint256 y) internal pure returns (uint256 z) {
function wdiv(uint256 x, uint256 y) internal pure returns (uint256 z) {
z = add(mul(x, WAD), y / 2) / y;
z = add(mul(x, WAD), y / 2) / y;
}
}
function rdiv(uint256 x, uint256 y) internal pure returns (uint256 z) {
function rdiv(uint256 x, uint256 y) internal pure returns (uint256 z) {
z = add(mul(x, RAY), y / 2) / y;
z = add(mul(x, RAY), y / 2) / y;
}
}


/****************************/
/****************************/
/*** Core Address Helpers ***/
/*** Core Address Helpers ***/
/****************************/
/****************************/
function dai() public view returns (address) { return getChangelogAddress("MCD_DAI"); }
function dai() public view returns (address) { return getChangelogAddress("MCD_DAI"); }
function mkr() public view returns (address) { return getChangelogAddress("MCD_GOV"); }
function mkr() public view returns (address) { return getChangelogAddress("MCD_GOV"); }
function vat() public view returns (address) { return getChangelogAddress("MCD_VAT"); }
function vat() public view returns (address) { return getChangelogAddress("MCD_VAT"); }
function cat() public view returns (address) { return getChangelogAddress("MCD_CAT"); }
function cat() public view returns (address) { return getChangelogAddress("MCD_CAT"); }
function dog() public view returns (address) { return getChangelogAddress("MCD_DOG"); }
function dog() public view returns (address) { return getChangelogAddress("MCD_DOG"); }
function jug() public view returns (address) { return getChangelogAddress("MCD_JUG"); }
function jug() public view returns (address) { return getChangelogAddress("MCD_JUG"); }
function pot() public view returns (address) { return getChangelogAddress("MCD_POT"); }
function pot() public view returns (address) { return getChangelogAddress("MCD_POT"); }
function vow() public view returns (address) { return getChangelogAddress("MCD_VOW"); }
function vow() public view returns (address) { return getChangelogAddress("MCD_VOW"); }
function end() public view returns (address) { return getChangelogAddress("MCD_END"); }
function end() public view returns (address) { return getChangelogAddress("MCD_END"); }
function esm() public view returns (address) { return getChangelogAddress("MCD_ESM"); }
function esm() public view returns (address) { return getChangelogAddress("MCD_ESM"); }
function reg() public view returns (address) { return getChangelogAddress("ILK_REGISTRY"); }
function reg() public view returns (address) { return getChangelogAddress("ILK_REGISTRY"); }
function spotter() public view returns (address) { return getChangelogAddress("MCD_SPOT"); }
function spotter() public view returns (address) { return getChangelogAddress("MCD_SPOT"); }
function flap() public view returns (address) { return getChangelogAddress("MCD_FLAP"); }
function flap() public view returns (address) { return getChangelogAddress("MCD_FLAP"); }
function flop() public view returns (address) { return getChangelogAddress("MCD_FLOP"); }
function flop() public view returns (address) { return getChangelogAddress("MCD_FLOP"); }
function osmMom() public view returns (address) { return getChangelogAddress("OSM_MOM"); }
function osmMom() public view returns (address) { return getChangelogAddress("OSM_MOM"); }
function govGuard() public view returns (address) { return getChangelogAddress("GOV_GUARD"); }
function govGuard() public view returns (address) { return getChangelogAddress("GOV_GUARD"); }
function flipperMom() public view returns (address) { return getChangelogAddress("FLIPPER_MOM"); }
function flipperMom() public view returns (address) { return getChangelogAddress("FLIPPER_MOM"); }
function clipperMom() public view returns (address) { return getChangelogAddress("CLIPPER_MOM"); }
function clipperMom() public view returns (address) { return getChangelogAddress("CLIPPER_MOM"); }
function pauseProxy() public view returns (address) { return getChangelogAddress("MCD_PAUSE_PROXY"); }
function pauseProxy() public view returns (address) { return getChangelogAddress("MCD_PAUSE_PROXY"); }
function autoLine() public view returns (address) { return getChangelogAddress("MCD_IAM_AUTO_LINE"); }
function autoLine() public view returns (address) { return getChangelogAddress("MCD_IAM_AUTO_LINE"); }
function daiJoin() public view returns (address) { return getChangelogAddress("MCD_JOIN_DAI"); }
function daiJoin() public view returns (address) { return getChangelogAddress("MCD_JOIN_DAI"); }
function lerpFab() public view returns (address) { return getChangelogAddress("LERP_FAB"); }
function lerpFab() public view returns (address) { return getChangelogAddress("LERP_FAB"); }


function clip(bytes32 _ilk) public view returns (address _clip) {
function clip(bytes32 _ilk) public view returns (address _clip) {
_clip = RegistryLike(reg()).xlip(_ilk);
_clip = RegistryLike(reg()).xlip(_ilk);
}
}


function flip(bytes32 _ilk) public view returns (address _flip) {
function flip(bytes32 _ilk) public view returns (address _flip) {
_flip = RegistryLike(reg()).xlip(_ilk);
_flip = RegistryLike(reg()).xlip(_ilk);
}
}


function calc(bytes32 _ilk) public view returns (address _calc) {
function calc(bytes32 _ilk) public view returns (address _calc) {
_calc = ClipLike(clip(_ilk)).calc();
_calc = ClipLike(clip(_ilk)).calc();
}
}


function getChangelogAddress(bytes32 _key) public view returns (address) {
function getChangelogAddress(bytes32 _key) public view returns (address) {
return ChainlogLike(LOG).getAddress(_key);
return ChainlogLike(LOG).getAddress(_key);
}
}


/****************************/
/****************************/
/*** Changelog Management ***/
/*** Changelog Management ***/
/****************************/
/****************************/
/**
/**
@dev Set an address in the MCD on-chain changelog.
@dev Set an address in the MCD on-chain changelog.
@param _key Access key for the address (e.g. "MCD_VAT")
@param _key Access key for the address (e.g. "MCD_VAT")
@param _val The address associated with the _key
@param _val The address associated with the _key
*/
*/
function setChangelogAddress(bytes32 _key, address _val) public {
function setChangelogAddress(bytes32 _key, address _val) public {
ChainlogLike(LOG).setAddress(_key, _val);
ChainlogLike(LOG).setAddress(_key, _val);
}
}


/**
/**
@dev Set version in the MCD on-chain changelog.
@dev Set version in the MCD on-chain changelog.
@param _version Changelog version (e.g. "1.1.2")
@param _version Changelog version (e.g. "1.1.2")
*/
*/
function setChangelogVersion(string memory _version) public {
function setChangelogVersion(string memory _version) public {
ChainlogLike(LOG).setVersion(_version);
ChainlogLike(LOG).setVersion(_version);
}
}
/**
/**
@dev Set IPFS hash of IPFS changelog in MCD on-chain changelog.
@dev Set IPFS hash of IPFS changelog in MCD on-chain changelog.
@param _ipfsHash IPFS hash (e.g. "QmefQMseb3AiTapiAKKexdKHig8wroKuZbmLtPLv4u2YwW")
@param _ipfsHash IPFS hash (e.g. "QmefQMseb3AiTapiAKKexdKHig8wroKuZbmLtPLv4u2YwW")
*/
*/
function setChangelogIPFS(string memory _ipfsHash) public {
function setChangelogIPFS(string memory _ipfsHash) public {
ChainlogLike(LOG).setIPFS(_ipfsHash);
ChainlogLike(LOG).setIPFS(_ipfsHash);
}
}
/**
/**
@dev Set SHA256 hash in MCD on-chain changelog.
@dev Set SHA256 hash in MCD on-chain changelog.
@param _SHA256Sum SHA256 hash (e.g. "e42dc9d043a57705f3f097099e6b2de4230bca9a020c797508da079f9079e35b")
@param _SHA256Sum SHA256 hash (e.g. "e42dc9d043a57705f3f097099e6b2de4230bca9a020c797508da079f9079e35b")
*/
*/
function setChangelogSHA256(string memory _SHA256Sum) public {
function setChangelogSHA256(string memory _SHA256Sum) public {
ChainlogLike(LOG).setSha256sum(_SHA256Sum);
ChainlogLike(LOG).setSha256sum(_SHA256Sum);
}
}




/**********************/
/**********************/
/*** Authorizations ***/
/*** Authorizations ***/
/**********************/
/**********************/
/**
/**
@dev Give an address authorization to perform auth actions on the contract.
@dev Give an address authorization to perform auth actions on the contract.
@param _base The address of the contract where the authorization will be set
@param _base The address of the contract where the authorization will be set
@param _ward Address to be authorized
@param _ward Address to be authorized
*/
*/
function authorize(address _base, address _ward) public {
function authorize(address _base, address _ward) public {
Authorizable(_base).rely(_ward);
Authorizable(_base).rely(_ward);
}
}
/**
/**
@dev Revoke contract authorization from an address.
@dev Revoke contract authorization from an address.
@param _base The address of the contract where the authorization will be revoked
@param _base The address of the contract where the authorization will be revoked
@param _ward Address to be deauthorized
@param _ward Address to be deauthorized
*/
*/
function deauthorize(address _base, address _ward) public {
function deauthorize(address _base, address _ward) public {
Authorizable(_base).deny(_ward);
Authorizable(_base).deny(_ward);
}
}
/**
/**
@dev Give an address authorization to perform auth actions on the contract.
@dev Give an address authorization to perform auth actions on the contract.
@param _base The address of the contract with a `setAuthority` pattern
@param _base The address of the contract with a `setAuthority` pattern
@param _authority Address to be authorized
@param _authority Address to be authorized
*/
*/
function setAuthority(address _base, address _authority) public {
function setAuthority(address _base, address _authority) public {
Authorizable(_base).setAuthority(_authority);
Authorizable(_base).setAuthority(_authority);
}
}
/**
/**
@dev Delegate vat authority to the specified address.
@dev Delegate vat authority to the specified address.
@param _usr Address to be authorized
@param _usr Address to be authorized
*/
*/
function delegateVat(address _usr) public {
function delegateVat(address _usr) public {
DssVat(vat()).hope(_usr);
DssVat(vat()).hope(_usr);
}
}
/**
/**
@dev Revoke vat authority to the specified address.
@dev Revoke vat authority to the specified address.
@param _usr Address to be deauthorized
@param _usr Address to be deauthorized
*/
*/
function undelegateVat(address _usr) public {
function undelegateVat(address _usr) public {
DssVat(vat()).nope(_usr);
DssVat(vat()).nope(_usr);
}
}


/******************************/
/******************************/
/*** OfficeHours Management ***/
/*** OfficeHours Management ***/
/******************************/
/******************************/


/**
/**
@dev Returns true if a time is within office hours range
@dev Returns true if a time is within office hours range
@param _ts The timestamp to check, usually block.timestamp
@param _ts The timestamp to check, usually block.timestamp
@param _officeHours true if office hours is enabled.
@param _officeHours true if office hours is enabled.
@return true if time is in castable range
@return true if time is in castable range
*/
*/
function canCast(uint40 _ts, bool _officeHours) public pure returns (bool) {
function canCast(uint40 _ts, bool _officeHours) public pure returns (bool) {
if (_officeHours) {
if (_officeHours) {
uint256 day = (_ts / 1 days + 3) % 7;
uint256 day = (_ts / 1 days + 3) % 7;
if (day >= 5) { return false; } // Can only be cast on a weekday
if (day >= 5) { return false; } // Can only be cast on a weekday
uint256 hour = _ts / 1 hours % 24;
uint256 hour = _ts / 1 hours % 24;
if (hour < 14 || hour >= 21) { return false; } // Outside office hours
if (hour < 14 || hour >= 21) { return false; } // Outside office hours
}
}
return true;
return true;
}
}


/**
/**
@dev Calculate the next available cast time in epoch seconds
@dev Calculate the next available cast time in epoch seconds
@param _eta The scheduled time of the spell plus the pause delay
@param _eta The scheduled time of the spell plus the pause delay
@param _ts The current timestamp, usually block.timestamp
@param _ts The current timestamp, usually block.timestamp
@param _officeHours true if office hours is enabled.
@param _officeHours true if office hours is enabled.
@return castTime The next available cast timestamp
@return castTime The next available cast timestamp
*/
*/
function nextCastTime(uint40 _eta, uint40 _ts, bool _officeHours) public pure returns (uint256 castTime) {
function nextCastTime(uint40 _eta, uint40 _ts, bool _officeHours) public pure returns (uint256 castTime) {
require(_eta != 0); // "DssExecLib/invalid eta"
require(_eta != 0); // "DssExecLib/invalid eta"
require(_ts != 0); // "DssExecLib/invalid ts"
require(_ts != 0); // "DssExecLib/invalid ts"
castTime = _ts > _eta ? _ts : _eta; // Any day at XX:YY
castTime = _ts > _eta ? _ts : _eta; // Any day at XX:YY


if (_officeHours) {
if (_officeHours) {
uint256 day = (castTime / 1 days + 3) % 7;
uint256 day = (castTime / 1 days + 3) % 7;
uint256 hour = castTime / 1 hours % 24;
uint256 hour = castTime / 1 hours % 24;
uint256 minute = castTime / 1 minutes % 60;
uint256 minute = castTime / 1 minutes % 60;
uint256 second = castTime % 60;
uint256 second = castTime % 60;


if (day >= 5) {
if (day >= 5) {
castTime += (6 - day) * 1 days; // Go to Sunday XX:YY
castTime += (6 - day) * 1 days; // Go to Sunday XX:YY
castTime += (24 - hour + 14) * 1 hours; // Go to 14:YY UTC Monday
castTime += (24 - hour + 14) * 1 hours; // Go to 14:YY UTC Monday
castTime -= minute * 1 minutes + second; // Go to 14:00 UTC
castTime -= minute * 1 minutes + second; // Go to 14:00 UTC
} else {
} else {
if (hour >= 21) {
if (hour >= 21) {
if (day == 4) castTime += 2 days; // If Friday, fast forward to Sunday XX:YY
if (day == 4) castTime += 2 days; // If Friday, fast forward to Sunday XX:YY
castTime += (24 - hour + 14) * 1 hours; // Go to 14:YY UTC next day
castTime += (24 - hour + 14) * 1 hours; // Go to 14:YY UTC next day
castTime -= minute * 1 minutes + second; // Go to 14:00 UTC
castTime -= minute * 1 minutes + second; // Go to 14:00 UTC
} else if (hour < 14) {
} else if (hour < 14) {
castTime += (14 - hour) * 1 hours; // Go to 14:YY UTC same day
castTime += (14 - hour) * 1 hours; // Go to 14:YY UTC same day
castTime -= minute * 1 minutes + second; // Go to 14:00 UTC
castTime -= minute * 1 minutes + second; // Go to 14:00 UTC
}
}
}
}
}
}
}
}


/**************************/
/**************************/
/*** Accumulating Rates ***/
/*** Accumulating Rates ***/
/**************************/
/**************************/
/**
/**
@dev Update rate accumulation for the Dai Savings Rate (DSR).
@dev Update rate accumulation for the Dai Savings Rate (DSR).
*/
*/
function accumulateDSR() public {
function accumulateDSR() public {
Drippable(pot()).drip();
Drippable(pot()).drip();
}
}
/**
/**
@dev Update rate accumulation for the stability fees of a given collateral type.
@dev Update rate accumulation for the stability fees of a given collateral type.
@param _ilk Collateral type
@param _ilk Collateral type
*/
*/
function accumulateCollateralStabilityFees(bytes32 _ilk) public {
function accumulateCollateralStabilityFees(bytes32 _ilk) public {
Drippable(jug()).drip(_ilk);
Drippable(jug()).drip(_ilk);
}
}


/*********************/
/*********************/
/*** Price Updates ***/
/*** Price Updates ***/
/*********************/
/*********************/
/**
/**
@dev Update price of a given collateral type.
@dev Update price of a given collateral type.
@param _ilk Collateral type
@param _ilk Collateral type
*/
*/
function updateCollateralPrice(bytes32 _ilk) public {
function updateCollateralPrice(bytes32 _ilk) public {
Pricing(spotter()).poke(_ilk);
Pricing(spotter()).poke(_ilk);
}
}


/****************************/
/****************************/
/*** System Configuration ***/
/*** System Configuration ***/
/****************************/
/****************************/
/**
/**
@dev Set a contract in another contract, defining the relationship (ex. set a new Calc contract in Clip)
@dev Set a contract in another contract, defining the relationship (ex. set a new Calc contract in Clip)
@param _base The address of the contract where the new contract address will be filed
@param _base The address of the contract where the new contract address will be filed
@param _what Name of contract to file
@param _what Name of contract to file
@param _addr Address of contract to file
@param _addr Address of contract to file
*/
*/
function setContract(address _base, bytes32 _what, address _addr) public {
function setContract(address _base, bytes32 _what, address _addr) public {
Fileable(_base).file(_what, _addr);
Fileable(_base).file(_what, _addr);
}
}
/**
/**
@dev Set a contract in another contract, defining the relationship (ex. set a new Calc contract in a Clip)
@dev Set a contract in another contract, defining the relationship (ex. set a new Calc contract in a Clip)
@param _base The address of the contract where the new contract address will be filed
@param _base The address of the contract where the new contract address will be filed
@param _ilk Collateral type
@param _ilk Collateral type
@param _what Name of contract to file
@param _what Name of contract to file
@param _addr Address of contract to file
@param _addr Address of contract to file
*/
*/
function setContract(address _base, bytes32 _ilk, bytes32 _what, address _addr) public {
function setContract(address _base, bytes32 _ilk, bytes32 _what, address _addr) public {
Fileable(_base).file(_ilk, _what, _addr);
Fileable(_base).file(_ilk, _what, _addr);
}
}
/**
/**
@dev Set a value in a contract, via a governance authorized File pattern.
@dev Set a value in a contract, via a governance authorized File pattern.
@param _base The address of the contract where the new contract address will be filed
@param _base The address of the contract where the new contract address will be filed
@param _what Name of tag for the value (e.x. "Line")
@param _what Name of tag for the value (e.x. "Line")
@param _amt The value to set or update
@param _amt The value to set or update
*/
*/
function setValue(address _base, bytes32 _what, uint256 _amt) public {
function setValue(address _base, bytes32 _what, uint256 _amt) public {
Fileable(_base).file(_what, _amt);
Fileable(_base).file(_what, _amt);
}
}
/**
/**
@dev Set an ilk-specific value in a contract, via a governance authorized File pattern.
@dev Set an ilk-specific value in a contract, via a governance authorized File pattern.
@param _base The address of the contract where the new value will be filed
@param _base The address of the contract where the new value will be filed
@param _ilk Collateral type
@param _ilk Collateral type
@param _what Name of tag for the value (e.x. "Line")
@param _what Name of tag for the value (e.x. "Line")
@param _amt The value to set or update
@param _amt The value to set or update
*/
*/
function setValue(address _base, bytes32 _ilk, bytes32 _what, uint256 _amt) public {
function setValue(address _base, bytes32 _ilk, bytes32 _what, uint256 _amt) public {
Fileable(_base).file(_ilk, _what, _amt);
Fileable(_base).file(_ilk, _what, _amt);
}
}


/******************************/
/******************************/
/*** System Risk Parameters ***/
/*** System Risk Parameters ***/
/******************************/
/******************************/
// function setGlobalDebtCeiling(uint256 _amount) public { setGlobalDebtCeiling(vat(), _amount); }
// function setGlobalDebtCeiling(uint256 _amount) public { setGlobalDebtCeiling(vat(), _amount); }
/**
/**
@dev Set the global debt ceiling. Amount will be converted to the correct internal precision.
@dev Set the global debt ceiling. Amount will be converted to the correct internal precision.
@param _amount The amount to set in DAI (ex. 10m DAI amount == 10000000)
@param _amount The amount to set in DAI (ex. 10m DAI amount == 10000000)
*/
*/
function setGlobalDebtCeiling(uint256 _amount) public {
function setGlobalDebtCeiling(uint256 _amount) public {
require(_amount < WAD); // "LibDssExec/incorrect-global-Line-precision"
require(_amount < WAD); // "LibDssExec/incorrect-global-Line-precision"
setValue(vat(), "Line", _amount * RAD);
setValue(vat(), "Line", _amount * RAD);
}
}
/**
/**
@dev Increase the global debt ceiling by a specific amount. Amount will be converted to the correct internal precision.
@dev Increase the global debt ceiling by a specific amount. Amount will be converted to the correct internal precision.
@param _amount The amount to add in DAI (ex. 10m DAI amount == 10000000)
@param _amount The amount to add in DAI (ex. 10m DAI amount == 10000000)
*/
*/
function increaseGlobalDebtCeiling(uint256 _amount) public {
function increaseGlobalDebtCeiling(uint256 _amount) public {
require(_amount < WAD); // "LibDssExec/incorrect-Line-increase-precision"
require(_amount < WAD); // "LibDssExec/incorrect-Line-increase-precision"
address _vat = vat();
address _vat = vat();
setValue(_vat, "Line", add(DssVat(_vat).Line(), _amount * RAD));
setValue(_vat, "Line", add(DssVat(_vat).Line(), _amount * RAD));
}
}
/**
/**
@dev Decrease the global debt ceiling by a specific amount. Amount will be converted to the correct internal precision.
@dev Decrease the global debt ceiling by a specific amount. Amount will be converted to the correct internal precision.
@param _amount The amount to reduce in DAI (ex. 10m DAI amount == 10000000)
@param _amount The amount to reduce in DAI (ex. 10m DAI amount == 10000000)
*/
*/
function decreaseGlobalDebtCeiling(uint256 _amount) public {
function decreaseGlobalDebtCeiling(uint256 _amount) public {
require(_amount < WAD); // "LibDssExec/incorrect-Line-decrease-precision"
require(_amount < WAD); // "LibDssExec/incorrect-Line-decrease-precision"
address _vat = vat();
address _vat = vat();
setValue(_vat, "Line", sub(DssVat(_vat).Line(), _amount * RAD));
setValue(_vat, "Line", sub(DssVat(_vat).Line(), _amount * RAD));
}
}
/**
/**
@dev Set the Dai Savings Rate. See: docs/rates.txt
@dev Set the Dai Savings Rate. See: docs/rates.txt
@param _rate The accumulated rate (ex. 4% => 1000000001243680656318820312)
@param _rate The accumulated rate (ex. 4% => 1000000001243680656318820312)
@param _doDrip `true` to accumulate interest owed
@param _doDrip `true` to accumulate interest owed
*/
*/
function setDSR(uint256 _rate, bool _doDrip) public {
function setDSR(uint256 _rate, bool _doDrip) public {
require((_rate >= RAY) && (_rate <= RATES_ONE_HUNDRED_PCT)); // "LibDssExec/dsr-out-of-bounds"
require((_rate >= RAY) && (_rate <= RATES_ONE_HUNDRED_PCT)); // "LibDssExec/dsr-out-of-bounds"
if (_doDrip) Drippable(pot()).drip();
if (_doDrip) Drippable(pot()).drip();
setValue(pot(), "dsr", _rate);
setValue(pot(), "dsr", _rate);
}
}
/**
/**
@dev Set the DAI amount for system surplus auctions. Amount will be converted to the correct internal precision.
@dev Set the DAI amount for system surplus auctions. Amount will be converted to the correct internal precision.
@param _amount The amount to set in DAI (ex. 10m DAI amount == 10000000)
@param _amount The amount to set in DAI (ex. 10m DAI amount == 10000000)
*/
*/
function setSurplusAuctionAmount(uint256 _amount) public {
function setSurplusAuctionAmount(uint256 _amount) public {
require(_amount < WAD); // "LibDssExec/incorrect-vow-bump-precision"
require(_amount < WAD); // "LibDssExec/incorrect-vow-bump-precision"
setValue(vow(), "bump", _amount * RAD);
setValue(vow(), "bump", _amount * RAD);
}
}
/**
/**
@dev Set the DAI amount for system surplus buffer, must be exceeded before surplus auctions start. Amount will be converted to the correct internal precision.
@dev Set the DAI amount for system surplus buffer, must be exceeded before surplus auctions start. Amount will be converted to the correct internal precision.
@param _amount The amount to set in DAI (ex. 10m DAI amount == 10000000)
@param _amount The amount to set in DAI (ex. 10m DAI amount == 10000000)
*/
*/
function setSurplusBuffer(uint256 _amount) public {
function setSurplusBuffer(uint256 _amount) public {
require(_amount < WAD); // "LibDssExec/incorrect-vow-hump-precision"
require(_amount < WAD); // "LibDssExec/incorrect-vow-hump-precision"
setValue(vow(), "hump", _amount * RAD);
setValue(vow(), "hump", _amount * RAD);
}
}
/**
/**
@dev Set minimum bid increase for surplus auctions. Amount will be converted to the correct internal precision.
@dev Set minimum bid increase for surplus auctions. Amount will be converted to the correct internal precision.
@dev Equation used for conversion is (1 + pct / 10,000) * WAD
@dev Equation used for conversion is (1 + pct / 10,000) * WAD
@param _pct_bps The pct, in basis points, to set in integer form (x100). (ex. 5% = 5 * 100 = 500)
@param _pct_bps The pct, in basis points, to set in integer form (x100). (ex. 5% = 5 * 100 = 500)
*/
*/
function setMinSurplusAuctionBidIncrease(uint256 _pct_bps) public {
function setMinSurplusAuctionBidIncrease(uint256 _pct_bps) public {
require(_pct_bps < BPS_ONE_HUNDRED_PCT); // "LibDssExec/incorrect-flap-beg-precision"
require(_pct_bps < BPS_ONE_HUNDRED_PCT); // "LibDssExec/incorrect-flap-beg-precision"
setValue(flap(), "beg", add(WAD, wdiv(_pct_bps, BPS_ONE_HUNDRED_PCT)));
setValue(flap(), "beg", add(WAD, wdiv(_pct_bps, BPS_ONE_HUNDRED_PCT)));
}
}
/**
/**
@dev Set bid duration for surplus auctions.
@dev Set bid duration for surplus auctions.
@param _duration Amount of time for bids. (in seconds)
@param _duration Amount of time for bids. (in seconds)
*/
*/
function setSurplusAuctionBidDuration(uint256 _duration) public {
function setSurplusAuctionBidDuration(uint256 _duration) public {
setValue(flap(), "ttl", _duration);
setValue(flap(), "ttl", _duration);
}
}
/**
/**
@dev Set total auction duration for surplus auctions.
@dev Set total auction duration for surplus auctions.
@param _duration Amount of time for auctions. (in seconds)
@param _duration Amount of time for auctions. (in seconds)
*/
*/
function setSurplusAuctionDuration(uint256 _duration) public {
function setSurplusAuctionDuration(uint256 _duration) public {
setValue(flap(), "tau", _duration);
setValue(flap(), "tau", _duration);
}
}
/**
/**
@dev Set the number of seconds that pass before system debt is auctioned for MKR tokens.
@dev Set the number of seconds that pass before system debt is auctioned for MKR tokens.
@param _duration Duration in seconds
@param _duration Duration in seconds
*/
*/
function setDebtAuctionDelay(uint256 _duration) public {
function setDebtAuctionDelay(uint256 _duration) public {
setValue(vow(), "wait", _duration);
setValue(vow(), "wait", _duration);
}
}
/**
/**
@dev Set the DAI amount for system debt to be covered by each debt auction. Amount will be converted to the correct internal precision.
@dev Set the DAI amount for system debt to be covered by each debt auction. Amount will be converted to the correct internal precision.
@param _amount The amount to set in DAI (ex. 10m DAI amount == 10000000)
@param _amount The amount to set in DAI (ex. 10m DAI amount == 10000000)
*/
*/
function setDebtAuctionDAIAmount(uint256 _amount) public {
function setDebtAuctionDAIAmount(uint256 _amount) public {
require(_amount < WAD); // "LibDssExec/incorrect-vow-sump-precision"
require(_amount < WAD); // "LibDssExec/incorrect-vow-sump-precision"
setValue(vow(), "sump", _amount * RAD);
setValue(vow(), "sump", _amount * RAD);
}
}
/**
/**
@dev Set the starting MKR amount to be auctioned off to cover system debt in debt auctions. Amount will be converted to the correct internal precision.
@dev Set the starting MKR amount to be auctioned off to cover system debt in debt auctions. Amount will be converted to the correct internal precision.
@param _amount The amount to set in MKR (ex. 250 MKR amount == 250)
@param _amount The amount to set in MKR (ex. 250 MKR amount == 250)
*/
*/
function setDebtAuctionMKRAmount(uint256 _amount) public {
function setDebtAuctionMKRAmount(uint256 _amount) public {
require(_amount < WAD); // "LibDssExec/incorrect-vow-dump-precision"
require(_amount < WAD); // "LibDssExec/incorrect-vow-dump-precision"
setValue(vow(), "dump", _amount * WAD);
setValue(vow(), "dump", _amount * WAD);
}
}
/**
/**
@dev Set minimum bid increase for debt auctions. Amount will be converted to the correct internal precision.
@dev Set minimum bid increase for debt auctions. Amount will be converted to the correct internal precision.
@dev Equation used for conversion is (1 + pct / 10,000) * WAD
@dev Equation used for conversion is (1 + pct / 10,000) * WAD
@param _pct_bps The pct, in basis points, to set in integer form (x100). (ex. 5% = 5 * 100 = 500)
@param _pct_bps The pct, in basis points, to set in integer form (x100). (ex. 5% = 5 * 100 = 500)
*/
*/
function setMinDebtAuctionBidIncrease(uint256 _pct_bps) public {
function setMinDebtAuctionBidIncrease(uint256 _pct_bps) public {
require(_pct_bps < BPS_ONE_HUNDRED_PCT); // "LibDssExec/incorrect-flap-beg-precision"
require(_pct_bps < BPS_ONE_HUNDRED_PCT); // "LibDssExec/incorrect-flap-beg-precision"
setValue(flop(), "beg", add(WAD, wdiv(_pct_bps, BPS_ONE_HUNDRED_PCT)));
setValue(flop(), "beg", add(WAD, wdiv(_pct_bps, BPS_ONE_HUNDRED_PCT)));
}
}
/**
/**
@dev Set bid duration for debt auctions.
@dev Set bid duration for debt auctions.
@param _duration Amount of time for bids.
@param _duration Amount of time for bids.
*/
*/
function setDebtAuctionBidDuration(uint256 _duration) public {
function setDebtAuctionBidDuration(uint256 _duration) public {
setValue(flop(), "ttl", _duration);
setValue(flop(), "ttl", _duration);
}
}
/**
/**
@dev Set total auction duration for debt auctions.
@dev Set total auction duration for debt auctions.
@param _duration Amount of time for auctions.
@param _duration Amount of time for auctions.
*/
*/
function setDebtAuctionDuration(uint256 _duration) public {
function setDebtAuctionDuration(uint256 _duration) public {
setValue(flop(), "tau", _duration);
setValue(flop(), "tau", _duration);
}
}
/**
/**
@dev Set the rate of increasing amount of MKR out for auction during debt auctions. Amount will be converted to the correct internal precision.
@dev Set the rate of increasing amount of MKR out for auction during debt auctions. Amount will be converted to the correct internal precision.
@dev MKR amount is increased by this rate every "tick" (if auction duration has passed and no one has bid on the MKR)
@dev MKR amount is increased by this rate every "tick" (if auction duration has passed and no one has bid on the MKR)
@dev Equation used for conversion is (1 + pct / 10,000) * WAD
@dev Equation used for conversion is (1 + pct / 10,000) * WAD
@param _pct_bps The pct, in basis points, to set in integer form (x100). (ex. 5% = 5 * 100 = 500)
@param _pct_bps The pct, in basis points, to set in integer form (x100). (ex. 5% = 5 * 100 = 500)
*/
*/
function setDebtAuctionMKRIncreaseRate(uint256 _pct_bps) public {
function setDebtAuctionMKRIncreaseRate(uint256 _pct_bps) public {
setValue(flop(), "pad", add(WAD, wdiv(_pct_bps, BPS_ONE_HUNDRED_PCT)));
setValue(flop(), "pad", add(WAD, wdiv(_pct_bps, BPS_ONE_HUNDRED_PCT)));
}
}
/**
/**
@dev Set the maximum total DAI amount that can be out for liquidation in the system at any point. Amount will be converted to the correct internal pr
@dev Set the maximum total DAI amount that can be out for liquidation in the sy