Maker Protocol Technical Docs
  • MakerDAO Technical Docs
  • Getting Started
    • Maker Protocol 101
  • Smart Contract Modules
    • Dai Module
      • Dai - Detailed Documentation
    • Core Module
      • Vat - Detailed Documentation
      • Spot - Detailed Documentation
    • Collateral Module
      • Join - Detailed Documentation
    • Liquidation 2.0 Module
    • System Stabilizer Module
      • Flapper - Detailed Documentation
      • Flopper - Detailed Documentation
      • Vow - Detailed Documentation
    • Oracle Module
      • Oracle Security Module (OSM) - Detailed Documentation
      • Median - Detailed Documentation
    • MKR Module
    • Governance Module
      • Spell - Detailed Documentation
      • Pause - Detailed Documentation
      • Chief - Detailed Documentation
    • Rates Module
      • Pot - Detailed Documentation
      • Jug - Detailed Documentation
    • Proxy Module
      • Proxy Actions - Detailed Documentation
      • Vote Proxy - Detailed Documentation
      • CDP Manager - Detailed Documentation
      • DSR Manager - Detailed Documentation
    • Flash Mint Module
    • Maker Protocol Emergency Shutdown
      • Emergency Shutdown for Partners
      • The Emergency Shutdown Process for Multi-Collateral Dai (MCD)
      • End - Detailed Documentation
      • ESM - Detailed Documentation
  • Glossary
    • MCD Glossaries
    • Smart Contract Annotations
  • Deployment Addresses
    • Maker Protocol Deployments
  • Security
    • Security for the Maker Protocol
  • Building on top of the Maker Protocol
    • Developer Guides and Tutorials
    • The Dai Javascript Library of the Maker Protocol
      • Getting started
      • Configuration
        • Plugins
      • Vault manager
      • Collateral types
      • Dai Savings Rate
      • Currency units
      • System data
      • Advanced
        • Transaction manager
        • DSProxy
        • Events
        • Using multiple accounts
        • Adding a new service
      • Single-Collateral Sai
        • Collateralized Debt Position
        • CDP Service
        • Price Service
        • System Status
        • Tokens
        • Token Conversion
        • Exchange Service
    • Pymaker
  • Keepers
    • The Auctions of the Maker Protocol
    • Auction Keepers
      • Auction Keeper Bot Setup Guide
    • Market Maker Keepers
      • Market Maker Keeper Bot Setup Guide
    • Cage Keeper
    • Simple Arbitrage Keeper
    • Chief Keeper
  • Command-line Interfaces
    • Seth
    • Multi Collateral Dai (MCD) CLI
    • Dai and Collateral Redemption during Emergency Shutdown
    • Emergency Shutdown (ES) CLI
  • Miscellaneous
    • Liquidations 1.2 System (Deprecated)
      • Cat - Detailed Documentation
      • Flipper - Detailed Documentation
    • SCD <> MCD Migration
    • Upgrading to Multi-Collateral Dai Guide
Powered by GitBook
On this page
  • Properties
  • id
  • Methods
  • getDebtValue
  • getGovernanceFee
  • getCollateralizationRatio
  • getLiquidationPrice
  • getCollateralValue
  • isSafe
  • enoughMkrToWipe
  • lockEth
  • drawSai
  • wipeSai
  • freePeth
  • give
  • shut
  • bite
Export as PDF
  1. Building on top of the Maker Protocol
  2. The Dai Javascript Library of the Maker Protocol
  3. Single-Collateral Sai

Collateralized Debt Position

PreviousSingle-Collateral SaiNextCDP Service

Last updated 5 years ago

💡Note that this page applies only to Single-Collateral Sai.

After or , you can use the returned cdp object to call functions on it.

Properties

id

This is the ID of the CDP object. You can pass this ID to .

Methods

getDebtValue

  • Params: (optional)

  • 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 , but can return the equivalent in USD if the first argument is Maker.USD.

const daiDebt = await cdp.getDebtValue();
const usdDebt = await cdp.getDebtValue(Maker.USD);

getGovernanceFee

  • Params: (optional)

  • Returns: promise (resolves to the value of the accrued governance fee in USD)

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);

getCollateralizationRatio

  • Params: none

  • 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. 2.5.

const ratio = await cdp.getCollateralizationRatio();

getLiquidationPrice

  • Params: none

  • Returns: promise (resolves to the liquidation price)

    const ratio = await cdp.getLiquidationPrice();

getCollateralValue

  • Returns: promise (resolves to collateral amount)

const ethCollateral = await cdp.getCollateralValue();
const pethCollateral = await cdp.getCollateralValue(Maker.PETH);
const usdCollateral = await cdp.getCollateralValue(Maker.USD);

isSafe

  • Params: none

  • 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();

enoughMkrToWipe

  • 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);

lockEth

  • 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.

return await cdp.lockEth(10000000000000000000, ETH.wei);
// or equivalently
return await cdp.lockEth(100, ETH);

drawSai

  • 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 equivalently
return await cdp.drawSai(100, SAI);

wipeSai

  • 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 equivalently
return await cdp.wipeSai(100, SAI);

freePeth

  • 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 equivalently
return await cdp.freePeth(10000000000000000000, PETH.wei);

give

  • 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');

shut

  • Params: none

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();

bite

  • Params: none

cdp.bite() will initiate the liquidation process of an undercollateralized CDP

return await cdp.bite();

cdp.getGovernanceFee() returns the value of the accrued governance fee. By default it returns the amount of MKR as a , but can return the equivalent in USD if the first argument is Maker.USD.

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 .

Params: (optional)

cdp.getCollateralValue() returns the value of the collateral in the CDP. By default it returns the amount of ETH as a , but can return the equivalent in PETH or USD depending on the first argument.

Returns: promise (resolves to once mined)

Note: this process is not atomic, so it's possible for some of the transactions to succeed but not all three. See for executing multiple transactions atomically.

Returns: promise (resolves to once mined)

Returns: promise (resolves to once mined)

Returns: promise (resolves to once mined)

Returns: promise (resolves to once mined)

Returns: promise (resolves to once mined)

Returns: promise (resolves to once mined)

currency unit
price unit
currency unit
currency unit
transactionObject
Using DsProxy
transactionObject
transactionObject
transactionObject
transactionObject
transactionObject
transactionObject
Maker.getCdp
currency unit
currency unit
currency unit
opening a new CDP
getting an existing one