Summary: The DssCdpManager (aka manager) was created to enable a formalized process for CDPs to be transferred between owners. In short, the manager works by having a dss wrapper that allows users to interact with their CDPs in an easy way, treating them as non-fungible tokens (NFTs).
cdpAllow(uint cdp, address usr, uint ok): Allow/Disallow (ok)usrto managecdp.urnAllow(address usr, uint ok): Allow/Disallow (ok)usrto accessmsg.senderspace (for sending a position inquit).open(bytes32 ilk, address usr): Opens a new CDP forusrto be used for anilkcollateral type.give(uint cdp, address dst): Transferscdptodst.frob(uint cdp, int dink, int dart): Increments/decrements thedinkamount of collateral locked and increments/decrements thedartamount of debt in thecdpdepositing the generated DAI or collateral freed in thecdpaddress.flux(bytes32 ilk, uint cdp, address dst, uint wad): Moveswad(precision 18) amount of collateralilkfromcdptodst.flux(uint cdp, address dst, uint wad): Moveswadamount ofcdpcollateral fromcdptodst.move(uint cdp, address dst, uint rad): Movesrad(precision 45) amount of DAI fromcdptodst.quit(uint cdp, address dst): Moves the collateral locked and debt generated fromcdptodst.enter(address src, uint cdp): Moves the collateral locked and debt generated fromsrctocdp.shift(uint cdpSrc, uint cdpDst): Moves the collateral locked and debt generated fromcdpSrctocdpDst.
Note: dst refers to the destination address.
vat: core contract address that holds the CDPs.cdpi: Auto incremental id.urns: MappingCDPId => UrnHandlerlist: MappingCDPId => Prev & Next CDPIds(double linked list)owns: MappingCDPId => Ownerilks: MappingCDPId => Ilk(collateral type)first: MappingOwner => First CDPIdlast: MappingOwner => Last CDPIdcount: MappingOwner => Amount of CDPscdpCan: MappingOwner => CDPId => Allowed Addr => True/FalseurnCan: MappingUrn => Allowed Addr => True/False
The CDP manager was created as a way to enable CDPs to be treated more like assets that can be exchanged as non-fungible tokens (NFT) would. Originally when created, the dss core contracts did not have the functionality to enable the transfer of CDP positions, hence the CDP manager was created to wrap this functionality and enable transferring between users. Since then, the core contracts have also implemented a native transfer functionality called fork which allows the transferring of a CDP to another address. However, there is a restriction, which is that the address owner that will be receiving the CDP needs to provide authorization that they do in fact want to receive it. This was created for the situation when a user is transferring the collateral that is locked as well as the debt generated. If you are simply moving collateral to another address, there is no issue but in the case that you are also transferring the debt generated, there is a chance of putting a perfectly safe CDP in a risky position. This makes the contract functionality a little more restrictive. Therefore, the CDP manager is a good option to keep a simple way of transferring CDPs and recognizing them via a numeric Id.
- The
managerreceives thevataddress in its creation and acts as an interface contract between it and the users. - The
managerkeeps an internal registry ofid => ownerandid => urnallowing for theownerto executevatfunctions for theirurnvia themanager. - The
managerkeeps a double linked list structure that allows the retrieval of all the CDPs that anownerhas via on-chain calls.- In short, this is what the
GetCdpsis for. This contract is a helper contract that allows the fetching of all the CDPs in just one call.
- In short, this is what the
- A User executes
openand gets aCDPIdin return. - After this, the
CDPIdgets associated with anurnwithmanager.urns(cdpId)and thenjoin's collateral to it. - After the user executes
frob, the generated DAI will remain in the CDP'surn. Then the user canmoveit at a later point in time.- Note that this is the same process for collateral that is freed after
frob. The user canfluxit to another address at a later time.
- Note that this is the same process for collateral that is freed after
- In the case where a user wants to abandon the
manager, they can usequitas a way to migrate their position of their CDP to anotherdstaddress.
- For the developers who want to integrate with the
manager, they will need to understand that the CDP actions are still in theurnenvironment. Regardless of this, themanagertries to abstract theurnusage by aCDPId. This means that developers will need to get theurn(urn = manager.urns(cdpId)) to allow thejoining of collateral to that CDP. - As the
managerassigns a specificilkperCDPIdand doesn't allow others to use it for theirs, there is a secondfluxfunction which expects anilkparameter. This function has the simple purpose of taking out collateral that was wrongly sent to a CDP that can't handle it/is incompatible. - Frob Function:
- When you
frobin the CDP manager, you generate new DAI in thevatvia the CDP manager which is then deposited in theurnthat the CDP manager manages. - You would need to manually use the
fluxormovefunctions to get the DAI or collateral out.
- When you
When open is executed, a new urn is created and a cdpId is assigned to it for a specific owner. If the user uses join to add collateral to the urn immediately after the transaction is mined, there is a chance that a reorganization of the chain occurs. This would result in the user losing the ownership of that cdpId/urn pair, therefore losing their collateral. However, this issue can only arise when avoiding the use of the proxy functions (https://github.com/makerdao/dss-proxy-actions) via a profile proxy (https://github.com/dapphub/ds-proxy) as the user will open the cdp and join collateral in the same transaction.