Monitor your Maker CDP Debt Ratio in 5 minutes

Don’t get caught with your pants down on liquidations

Michael Coon
BUIDLHub
7 min readMar 17, 2020

--

Disclaimer: BUIDLHub’s workflow tools optimize experience interacting with blockchain networks. Use our brand new low-code, no-code solution to integrate blockchain data-driven events into your project for FREE at https://buidlhub.com

For anyone who had a Maker Vault during the latest crypto sell-off (week of 9–13 March 2020), you may have been surprised to find that your vault had been liquidated without warning. For many, this meant the vault was sold off at auction and they lost all their collateral in the process. Today, we’re going to cover how to know when the CDP is getting dangerously close to the automatic liquidation point using the latest MakerDAO extension in BUIDLHub.

This is what we’ll be making today.

Maker Protocol Review

Let’s cover briefly how the Maker protocol works and it will hopefully shed light on how liquidation happens. When you create a Maker Vault, you stake ETH or BAT in a kind of escrow contract called a Vault (Maker also refers to it as an urn). Once staked, you can borrow DAI, using your staked assets as collateral. Like any collateralized loan, there is a buffer or margin between the collateral and borrowed asset values, and in Maker-speak, this is referred to as the CDP or Collateralized Debt Position. The Maker protocol requires that all vaults maintain a minimum of 150% CDP — meaning the total debt you take on cannot go below 150% of your collateral value. So if you lock 10 ETH in a vault, and the price of ETH is $200, you can borrow up to 1333 DAI and maintain a 150% CDP ((10eth*$200)/1.5 == 1333 DAI). Clearly, the price of ETH has a pretty significant impact on the CDP.

If the price of ETH were to drop to, say, $102, then the max you could borrow would only be 680 DAI ((10eth*$102/1.5 == 680 DAI). If, for example, you already borrowed 900 DAI to invest elsewhere, your CDP would suddenly drop to 1.13%, below the 150% minimum, and it would be liquidated.

What does it mean to be liquidated? Well, that’s where things get a little fuzzy.

When you look over the documentation, it kind of implies that you’ll be hit with a 13% penalty and you’ll get your ETH back (at that reduced rate). But that’s not actually what happens. Instead, liquidation means your ENTIRE vault immediately goes to auction. Unless you are running a Keeper bot to look for your vault and outbid others, you lose ALL of your ETH! We will cover running a Keeper bot in another article; for now, let’s see how BUIDLHub can automatically notify you when things are getting close to that 150% liquidation threshold.

We recently added some MakerDAO functionality as an extension in BUIDLHub. Specifically, the extension allows you to subscribe to proposal submissions and easily query for your vault’s CDP. We were hoping that it would be an easy case of adding an App to BUIDLHub and calling on-chain to get the CDP. But it’s not that simple. There are several RPC calls that have to happen to compute the CDP. And those calls are made across two of Maker’s contracts: CDPManager and the Vat.

Reading Contracts for CDP

The first step is to get the vault’s address. Each vault is represented as a smart contract itself but the address isn’t obvious anywhere on Maker’s dashboards — you have to look it up separately on-chain. Once you have the vault address, you can query for the various bits of information you need to compute the CDP. Below is a snippet from the BUIDLHub extension processing code. Note: it doesn’t have to be this complicated 😉

Anyone wanting to perform the simple task of knowing what their current debt ratio is could write this up in a Node.js script and get the CDP. This could be run periodically and you could notify yourself when that ratio falls below a certain level.

Alternatively, you could let BUIDLHub do that for you in a couple of clicks.

Current CDP Debt Ratio

First, head to BUIDLHub.com. We recommend you create an account—don’t worry, there’s no paywall.

When you’re inside the app, click “Design a Flow” and then click “Create a Flow” if prompted.

Okay, we’re now in Flow Designer in a blank template.

First, we’ll add a Timer trigger that periodically starts an event flow. We’ll set the timer to trigger hourly.

Next, we will query the Maker extension to get the CDP for a Vault.

In the second step in our flow, you can query the current CDP

Within the 2nd step, first, input “MakerDAO” as the action source and “Get CDP” as the specific action. Second, for required parameters, you’re asked to provide the Vault Number and the Collateral. The Vault Number is a number, a counter originating from the contract that increments by one with each new vault. The address is determined from the vault number. Collateral is either ETH-A or BAT-A.

6700 is an arbitrary number put in for now to represent the Vault number.
The flow after the first two steps should look like this.

Next, we will filter the CDP for a specific threshold. Note: if there is no DAI borrowed against the vault, the CDP will default to 0. So we need to filter for that as well.

For the third step, add Filter as the action source and “Filter Input” as the specific action.

Select Filter as the step action type

When applying filters in step 3, choose to “Add Filter” and select collateralDebtRatio. Here, we set it to 300, which reflects a 300% CDP. We’ll be filtering the contract for when this query returns less than that 300%. You’ll manually have to add the < and input the amount.

Note: Select ‘ALL’ (meaning logical AND). Add a filter for the collateral debt ratio being less than a specific percentage.

Finally, if the filter passes it means we’re getting too close for comfort and should send ourselves a message to go and payback DAI or add collateral. In Step 4, we selected Email (you could also choose Discord).

Select email option for the last step
Enter a subject and message related to the debt ratio being low. Use the “+” to quickly add the ${ctx.outputs.step3.collateralDebtRatio} value.

Enter a subject and a message body, and then bingo! You’re all set.

Recommendations

What would be really nice is on the Maker/Oasis dashboard to be able to subscribe to a certain threshold and be notified accordingly. BUIDLHub could provide an initial implementation and then we can come up with a more decentralized mechanism for users to run their own notification bots. If you like that or have other ideas, head over to our new BUIDLHub Colony and propose a suggestion!

Looking forward to what these next few months hold in store for us. Share us some of your love ❤️ in our chats to give us new ideas or reach out to us by email to suggest new integrations!

Use Eventflow for FREE to dramatically reduce the time on blockchain-based event integrations.

Please join our community:

ColonyDAO | Twitter | Medium | LinkedIn | Telegram | Discord

--

--