💡Note that this page applies only to Single-Collateral Sai.
This is the ID of the CDP object. You can pass this ID to Maker.getCdp.
Returns: promise (resolves to the amount of outstanding debt)
cdp.getDebtValue() returns the amount of debt that has been borrowed against the collateral in the CDP. By default it returns the amount of Dai as a currency unit, but can return the equivalent in USD if the first argument is
const daiDebt = await cdp.getDebtValue();const usdDebt = await cdp.getDebtValue(Maker.USD);
Returns: promise (resolves to the value of the accrued governance fee in USD)
cdp.getGovernanceFee() returns the value of the accrued governance fee. By default it returns the amount of MKR as a currency unit, but can return the equivalent in USD if the first argument is
Note: this is often referred to as the
Stability Fee, even though technically the
Stability Fee is the fee that is paid in Dai, and the
Governance Fee is the fee that is paid in MKR. But since fees are only paid in MKR in Single-Collateral Dai, and only paid in Dai in Multi-Collateral Dai, the fee in Single-Collateral Dai is often referred to as the
Stability Fee to be consistent with the term that will be used in Multi-Collateral Dai and to avoid unduly confusing regular users.
const mkrFee = await cdp.getGovernanceFee();const usdFee = await cdp.getGovernanceFee(Maker.USD);
Returns: promise (resolves to the collateralization ratio)
cdp.getCollateralizationRatio() returns the USD value of the collateral in the CDP divided by the USD value of the Dai debt for the CDP, e.g.
const ratio = await cdp.getCollateralizationRatio();
Returns: promise (resolves to the liquidation price)
cdp.getLiquidationPrice() returns the price of Ether in USD that causes the CDP to become unsafe (able to be liquidated), all other factors constant. It returns a
USD_ETH price unit.
const ratio = await cdp.getLiquidationPrice();
Returns: promise (resolves to collateral amount)
cdp.getCollateralValue() returns the value of the collateral in the CDP. By default it returns the amount of ETH as a currency unit, but can return the equivalent in PETH or USD depending on the first argument.
const ethCollateral = await cdp.getCollateralValue();const pethCollateral = await cdp.getCollateralValue(Maker.PETH);const usdCollateral = await cdp.getCollateralValue(Maker.USD);
Returns: promise (resolves to boolean)
cdp.isSafe() returns true if the cdp is safe, that is, if the USD value of its collateral is greater than or equal to USD value of the its debt multiplied by the liquidation ratio.
const ratio = await cdp.isSafe();
Params: amount of Sai to wipe
Returns: promise (resolves to boolean)
cdp.enoughMkrToWipe(dai) returns true if the current account owns enough MKR to wipe the specified amount of Sai from the CDP.
const enoughMkrToWipe = await cdp.enoughMkrToWipe(10000000000000000000, SAI.wei);
Params: amount to lock in the CDP, in units defined by the price service.
cdp.lockEth(eth) abstracts the token conversions needed to lock collateral in a CDP. It first converts the ETH to WETH, then converts the WETH to PETH, then locks the PETH in the CDP.
Note: this process is not atomic, so it's possible for some of the transactions to succeed but not all three. See Using DsProxy for executing multiple transactions atomically.
return await cdp.lockEth(10000000000000000000, ETH.wei);// or equivalentlyreturn await cdp.lockEth(100, ETH);
Params: amount to draw (in Sai, as string)
cdp.drawSai(sai) withdraws the specified amount of Sai as a loan against the collateral in the CDP. As such, it will fail if the CDP doesn't have enough PETH locked in it to remain at least 150% collateralized.
return await cdp.drawSai(10000000000000000000, SAI.wei);// or equivalentlyreturn await cdp.drawSai(100, SAI);
Params: amount to repay (in Sai, as string)
cdp.wipeSai(sai) sends Sai back to the CDP in order to repay some (or all) of its outstanding debt.
Note: CDPs accumulate MKR governance debt over their lifetime. This must be paid when wiping sai debt, and thus MKR must be acquired before calling this method.
return await cdp.wipeSai(10000000000000000000, SAI.wei);// or equivalentlyreturn await cdp.wipeSai(100, SAI);
Params: amount of Peth collateral to free from the CDP, in units defined by the price service.
cdp.freePeth(peth) withdraws the specified amount of PETH and returns it to the owner's address. As such, the contract will only allow you to free PETH that's locked in excess of 150% of the CDP's outstanding debt.
return await cdp.freePeth(100, PETH);// or equivalentlyreturn await cdp.freePeth(10000000000000000000, PETH.wei);
Params: Ethereum address (string)
cdp.give(address) transfers ownership of the CDP from the current owner to the address you provide as an argument.
return await cdp.give('0x046ce6b8ecb159645d3a605051ee37ba93b6efcc');
cdp.shut() wipes all remaining sai, frees all remaining collateral, and deletes the CDP. This will fail if the caller does not have enough DAI to wipe all the sai debt and enough MKR to pay for all the accrued stability fee
return await cdp.shut();
cdp.bite() will initiate the liquidation process of an undercollateralized CDP
return await cdp.bite();