DSR Manager - Detailed Documentation
The simplest way to integrate DSR in smart contracts
The DsrManager provides an easy to use smart contract that allows service providers to deposit/withdraw dai into the DSR contract pot, and activate/deactivate the Dai Savings Rate to start earning savings on a pool of dai in a single function call. To understand the DsrManager, it is necessary to have an understanding of the pot first. The DSR is set by Maker Governance, and will typically be less than the base stability fee to remain sustainable. The purpose of DSR is to offer another incentive for holding Dai.
Deployment Details
Contract Details
Math
wad- some quantity of tokens, as a fixed point integer with 18 decimal places.ray- a fixed point integer, with 27 decimal places.rad- a fixed point integer, with 45 decimal places.mul(uint, uint),rmul(uint, uint),add(uint, uint)&sub(uint, uint)- will revert on overflow or underflowRdiv- Divide tworays and return a newray. Always rounds down. Arayis a decimal number with 27 digits of precision that is being represented as an integer.Rdivup- Divide tworays and return a newray. Always rounds up. Arayis a decimal number with 27 digits of precision that is being represented as an integer.
Storage
pot- stores the contract address of the main Dai Savings Rate contractpot.dai- stores the contract address of dai.daiJoin- stores the contract address of the Dai token adapter.supply- the supply of Dai in the DsrManager.pieOf-mapping (addresses=>uint256)mapping of user addresses and normalized Dai balances (amount of dai / chi) deposited intopot.pie- stores the address'potbalance.chi- the rate accumulator. This is the always increasing value which decides how much dai is given whendrip()is called.vat- an address that conforms to aVatLikeinterface.rho- the last time thatdripis called.
Functions and mechanics
daiBalance(address usr) returns (uint wad)
Calculates and returns the Dai balance of the specified address usr in the DsrManager contract. (Existing Dai balance + accrued dsr)
join(address dst, uint wad)
uint wadthis parameter specifies the amount of Dai that you want to join to the pot. Thewadamount of Dai must be present in the account ofmsg.sender.address
dstspecifies a destination address for the deposited dai in the pot. Allows a hot wallet address (msg.sender) to deposit dai into the pot and transfer ownership of that dai to a cold wallet (or any other address for that matter)The normalized balance
pieis calculated by dividing wad with the rate acumulatorchi.the
dst'spieOfamount is updated to include thepie.The total supply amount is also updated by adding the
pie.wadamount of dai is transferred to the DsrManager contractThe DsrManager contract joins
wadamount of dai into the MCD system through the dai token adapterdaiJoin.The DsrManager contract
joinspieamount of dai to thepot.
exit(address dst, uint wad)
exit()essentially functions as the exact opposite ofjoin().uint wadthis parameter is based on the amount of dai that you want toexitthepot.address
dstspecifies a destination address for the retrieved dai from thepot. Allows a cold wallet address (msg.sender) to retrieve dai from thepotand transfer ownership of that dai to a hot wallet (or any other address for that matter)The normalized balance
pieis calculated by dividing wad with the rate acumulatorchi.The
msg.sender’spieOfamount is updated by subtracting thepie.The total supply amount is also updated by subtracting the
pie.The contract calls exit on the
potcontract.It calculates the amount of dai to retrieve by multiplying
piewithchi.Then exits the dai from the dai token adapter
daiJointo the destination addressdst.
exitAll(address dst)
exitAll()functions like theexitfunction, except it simply looks into the mappingpieOf, to determine how much dai themsg.senderhas, andexits the entire amount of dai, instead of a specified amount.
Gotchas / Integration Concerns
In order to use the
joinfunction, you need toapprovethe contract to transfer Dai from your wallet. You need to callapproveon the Dai token, specifying theDsrManagercontract and the amount that the contract should be able to pull (can be set to-1, if you want to set an unlimited approval)
Last updated