A library for crafting spells in DSS more efficiently, predictably, and easily.
(v0.0.0) Kovan: TBD
(v0.0.0) Mainnet: TBD
Provides a list of functions to call to perform commonly used actions in spells in DSS.
Here is an example of a SpellAction.sol
file that uses the deployed library (from spells-mainnet
repo):
import {DssAction} from "lib/dss-exec-lib/src/DssAction.sol";
contract SpellAction is DssAction {
constructor(address lib, bool officeHours) DssAction(lib, officeHours) public {}
uint256 constant MILLION = 10 ** 6;
function actions() public override {
setGlobalDebtCeiling(1500 * MILLION);
setIlkDebtCeiling("ETH-A", 10 * MILLION);
}
}
The SpellAction.sol
file must always inherit DssAction
from lib/dss-exec-lib
.
The developer must override the actions()
function and place all spell actions within. This is called by the execute()
function in the pause, which is subject to an optional limiter for office hours.
Note: All variables within the SpellAction MUST be defined as constants, or assigned at runtime inside of the actions()
function. Variable memory storage is not available within a Spell Action due to the underlying delegatecall mechanisms.
The spell itself is deployed as follows:
new DssExec(
"A test dss exec spell", // Description
now + 30 days, // Expiration
address(new SpellAction())
);
Below is an outline of how all variables are accounted for for precision based on name.
NOTE: DSSExecLib.sol
has NatSpec comments above every function definition that provides a comprehensive definition of the function, its parameters, and any precision calculations that are made.
amount
: Integer amount, (e.g., 10m DAI amount == 10000000)rate
: Rate value expressed as value corresponding to percent from this list (e.g., 4% => 1000000001243680656318820312)duration
: Time, in seconds.pct_bps
: Percentage, in basis points (e.g., 5% = 5 * 100 = 500).value
: Decimal value, expressed as 1000x (e.g., $1.025 == 1025)
Below is an outline of all functions used in the library.
dai()
: Dai ERC20 Contractmkr()
: MKR ERC20 Contractvat()
: MCD Core Accountingcat()
: MCD Liquidation Agentjug()
: MCD Rates Modulepot()
: MCD Savings Rates Modulevow()
: MCD System Stabilizer Moduleend()
: MCD Shutdown Coordinatorreg()
: Ilk Registryspotter()
: MCD Oracle Liasonflap()
: MCD Surplus Auction Moduleflop()
: MCD Debt Auction ModuleosmMom()
: OSM Circuit BreakergovGuard()
: MKR AuthorityflipperMom()
: Flipper Governance InterfacepauseProxy()
: Governance AuthorityautoLine()
: Debt Ceiling Auto AdjustmentdaiJoin()
: MCD Join adapter for Daiflip(bytes32 _ilk)
: Collateral Auction Module (per ilk)
getChangelogAddress(bytes32 _key)
: Get MCD address from key from MCD on-chain changelog.setChangelogAddress(bytes32 _key, address _val)
: Set an address in the MCD on-chain changelog.setChangelogVersion(string memory _version)
: Set version in the MCD on-chain changelog.setChangelogIPFS(string memory _ipfsHash)
: Set IPFS hash of IPFS changelog in MCD on-chain changelog.setChangelogSHA256(string memory _SHA256Sum)
: Set SHA256 hash in MCD on-chain changelog.
authorize(address _base, address _ward)
: Give an address authorization to perform auth actions on the contract.deauthorize(address _base, address _ward)
: Revoke contract authorization from an address.delegateVat(address _usr)
: Delegate vat authority to the specified address.undelegateVat(address _usr)
: Revoke vat authority to the specified address.
accumulateDSR()
: Update rate accumulation for the Dai Savings Rate (DSR).accumulateCollateralStabilityFees(bytes32 _ilk)
: Update rate accumulation for the stability fees of a given collateral type.
updateCollateralPrice(bytes32 _ilk)
: Update price of a given collateral type.
setContract(address _base, bytes32 _what, address _addr)
: Set a contract in another contract, defining the relationship (ex. set a new Cat contract in the Vat)setContract(address _base, bytes32 _ilk, bytes32 _what, address _addr)
: Set a contract in another contract, defining the relationship for a given ilk.
setGlobalDebtCeiling(uint256 _amount)
: Set the global debt ceiling.increaseGlobalDebtCeiling(uint256 _amount)
: Increase the global debt ceiling.decreaseGlobalDebtCeiling(uint256 _amount)
: Decrease the global debt ceiling.setDSR(uint256 _rate, bool _doDrip)
: Set the Dai Savings Rate.setSurplusAuctionAmount(uint256 _amount)
: Set the DAI amount for system surplus auctions.setSurplusBuffer(uint256 _amount)
: Set the DAI amount for system surplus buffer, must be exceeded before surplus auctions start.setMinSurplusAuctionBidIncrease(uint256 _pct_bps)
: Set minimum bid increase for surplus auctions.setSurplusAuctionBidDuration(uint256 _length)
: Set bid duration for surplus auctions.setSurplusAuctionDuration(uint256 _length)
: Set total auction duration for surplus auctions.setDebtAuctionDelay(uint256 _length)
: Set the number of seconds that pass before system debt is auctioned for MKR tokens.setDebtAuctionDAIAmount(uint256 _amount)
: Set the DAI amount for system debt to be covered by each debt auction.setDebtAuctionMKRAmount(uint256 _amount)
: Set the starting MKR amount to be auctioned off to cover system debt in debt auctions.setMinDebtAuctionBidIncrease(uint256 _pct_bps)
: Set minimum bid increase for debt auctions.setDebtAuctionBidDuration(uint256 _length)
: Set bid duration for debt auctions.setDebtAuctionDuration(uint256 _length)
: Set total auction duration for debt auctions.setDebtAuctionMKRIncreaseRate(uint256 _pct_bps)
: Set the rate of increasing amount of MKR out for auction during debt auctions. MKR amount is increased by this rate every "tick" (if auction duration has passed and no one has bid on the MKR).setMaxTotalDAILiquidationAmount(uint256 _amount)
: Set the maximum total DAI amount that can be out for liquidation in the system at any point.setEmergencyShutdownProcessingTime(uint256 _length)
: Set the length of time that has to pass during emergency shutdown before collateral can start being claimed by DAI holders.setGlobalStabilityFee(uint256 _rate)
: Set the global stability fee (not typically used, currently is 0).setDAIReferenceValue(uint256 _amount)
: Set the value of DAI in the reference asset (e.g. $1 per DAI).
setIlkDebtCeiling(bytes32 _ilk, uint256 _amount)
: Set a collateral debt ceiling.increaseIlkDebtCeiling(bytes32 _ilk, uint256 _amount, bool _global)
: Raise the debt ceiling of a particular ilk.decreaseIlkDebtCeiling(bytes32 _ilk, uint256 _amount, bool _global)
: Lower the debt ceiling of a particular ilk.setIlkAutoLineParameters(bytes32 _ilk, uint256 _amount, uint256 _gap, uint256 _ttl)
: Configure the parameters for the Debt Ceiling auto line module for a particluar ilk.setIlkAutoLineDebtCeiling(bytes32 _ilk, uint256 _amount)
: Adjust the debt ceiling in the auto line module.removeIlkFromAutoLine(bytes32 _ilk)
: Remove the management of an ilk by the debt ceiling auto line module.setIlkMinVaultAmount(bytes32 _ilk, uint256 _amount)
: Set a collateral minimum vault amount.setIlkLiquidationPenalty(bytes32 _ilk, uint256 _pct_bps)
: Set a collateral liquidation penalty.setIlkMaxLiquidationAmount(bytes32 _ilk, uint256 _amount)
: Set max DAI amount for liquidation per vault for a collateral type.setIlkLiquidationRatio(bytes32 _ilk, uint256 _pct_bps)
: Set a collateral liquidation ratio.setIlkMinAuctionBidIncrease(bytes32 _ilk, uint256 _pct_bps)
: Set minimum bid increase for collateral.setIlkBidDuration(bytes32 _ilk, uint256 _length)
: Set bid duration for a collateral type.setIlkAuctionDuration(bytes32 _ilk, uint256 _length)
: Set auction duration for a collateral type.setIlkStabilityFee(bytes32 _ilk, uint256 _rate)
: Set the stability fee for a given ilk.
updateCollateralAuctionContract(bytes32 _ilk, address _newFlip, address _oldFlip)
: Update collateral auction contracts.updateSurplusAuctionContract(address _newFlap, address _oldFlap)
: Update surplus auction contracts.updateDebtAuctionContract(address _newFlop, address _oldFlop)
: Update debt auction contracts.
addWritersToMedianWhitelist(address _median, address[] memory _feeds)
: Adds oracle feeds to the Median's writer whitelist, allowing the feeds to write prices.removeWritersFromMedianWhitelist(address _median, address[] memory _feeds)
: Removes oracle feeds to the Median's writer whitelist, disallowing the feeds to write prices.addReadersToMedianWhitelist(address _median, address[] memory _readers)
: Adds addresses to the Median's reader whitelist, allowing the addresses to read prices from the median.addReaderToMedianWhitelist(address _median, address _reader)
: Adds an address to the Median's reader whitelist, allowing the address to read prices from the median.removeReadersFromMedianWhitelist(address _median, address[] memory _readers)
: Removes addresses from the Median's reader whitelist, disallowing the addresses to read prices from the median.removeReaderFromMedianWhitelist(address _median, address _reader)
: Removes an address to the Median's reader whitelist, disallowing the address to read prices from the median.setMedianWritersQuorum(address _median, uint256 _minQuorum)
: Sets the minimum number of valid messages from whitelisted oracle feeds needed to update median price.addReaderToOSMWhitelist(address _osm, address _reader)
: Adds an address to the Median's reader whitelist, allowing the address to read prices from the OSM.removeReaderFromOSMWhitelist(address _osm, address _reader)
: Removes an address to the Median's reader whitelist, disallowing the address to read prices from the OSM.allowOSMFreeze(address _osm, bytes32 _ilk)
: Add OSM address to OSM mom, allowing it to be frozen by governance.
In order to onboard new collateral to the Maker protocol, the following must be done before the spell is prepared:
- Deploy a GemJoin contract
- Rely the
MCD_PAUSE_PROXY
address - Deny the deployer address
- Rely the
- Deploy a Flip contract
- Rely the
MCD_PAUSE_PROXY
address - Deny the deployer address
- Rely the
- Deploy a Pip contract
Once these actions are done, add the following code (below is an example) to the execute()
function in the spell. The setChangelogAddress
function calls are required to add the collateral to the on-chain changelog. They must follow the following convention:
- GEM:
TOKEN
- JOIN:
MCD_JOIN_TOKEN
- FLIP:
MCD_FLIP_TOKEN
- PIP:
PIP_TOKEN
import "src/CollateralOpts.sol";
CollateralOpts memory XMPL_A = CollateralOpts({
ilk: "XMPL-A",
gem: 0xCE4F3774620764Ea881a8F8840Cbe0F701372283,
join: 0xa30925910067a2d9eB2a7358c017E6075F660842,
flip: 0x32c6DF17f8E94694977aa41A595d8dc583836A51,
pip: 0x9eb923339c24c40Bef2f4AF4961742AA7C23EF3a,
isLiquidatable: true,
isOSM: true,
whitelistOSM: true,
ilkDebtCeiling: 3 * MILLION,
minVaultAmount: 100,
maxLiquidationAmount: 50000,
liquidationPenalty: 1300,
ilkStabilityFee: 1000000000705562181084137268,
bidIncrease: 300,
bidDuration: 6 hours,
auctionDuration: 6 hours,
liquidationRatio: 15000
});
addNewCollateral(XMPL_A);
DssExecLib.setChangelogAddress("XMPL", 0xCE4F3774620764Ea881a8F8840Cbe0F701372283);
DssExecLib.setChangelogAddress("PIP_XMPL", 0x9eb923339c24c40Bef2f4AF4961742AA7C23EF3a);
DssExecLib.setChangelogAddress("MCD_JOIN_XMPL", 0xa30925910067a2d9eB2a7358c017E6075F660842);
DssExecLib.setChangelogAddress("MCD_FLIP_XMPL", 0x32c6DF17f8E94694977aa41A595d8dc583836A51);
ilk
: Collateral typegem
: Address of collateral tokenjoin
: Address of GemJoin contractflip
: Address of Flip contractpip
: Address of Pip contractisLiquidatable
: Boolean indicating whether liquidations are enabled for collateralisOsm
: Boolean indicating whether pip address used is an OSM contractwhitelistOsm
: Boolean indicating whether median is src in OSM.ilkDebtCeiling
: Debt ceiling for new collateralminVaultAmount
: Minimum DAI vault amount required for new collateralmaxLiquidationAmount
: Max DAI amount per vault for liquidation for new collateralliquidationPenalty
: Percent liquidation penalty for new collateral [ex. 13.5% == 1350]ilkStabilityFee
: Percent stability fee for new collateral [ex. 4% == 1000000001243680656318820312]bidIncrease
: Percent bid increase for new collateral [ex. 13.5% == 1350]bidDuration
: Bid period duration for new collateralauctionDuration
: Total auction duration for new collateralliquidationRatio
: Percent liquidation ratio for new collateral [ex. 150% == 15000]
sendPaymentFromSurplusBuffer(address _target, uint256 _amount)
: Send a payment in ERC20 DAI from the surplus buffer.
$ dapp update
$ make test