Blog Banner: 🔍 DeFi behind the scenes | Ep: 2 dYdX Liquidation analysis

🔍 DeFi behind the scenes | Ep: 2 dYdX Liquidation analysis

How does $400,000 of profit per month from #DeFi sound to you? Skeptical? 🤔

That's what dYdX Protocol liquidators made in September 2019 by liquidating undercollateralized loans.

Check out this video analyzing the profitability of various dYdX markets and the nuances of using price feeds.



Ganesh: dYdX lets you open up loans. You put some ETH as a collateral, and then you take out a loan, and then you do margin trading. Sometimes your ETH collateral drops below a certain value, and that means your loan is not liquid. Then some bots go in and liquidate these loans.

Essentially sell a portion of your collateral at a 5% discount to make sure your loan is again at the right level. The spread here, the 5% is the bonus to these bots of these people. Anyone can go in and liquidate. There are these companies doing this liquidation analysis and they wanted the data, so what we did is we just built a liquidation model for them. You can see count broken down by month. Let's see the profit in the gas spent and each transaction. I can actually do it by collateral type and borrow type.

This one row here 7/2019 which will be July for the Wrapper Ether to DAI market, there were 630 liquidations of the loans. The total profit was $200,000. That's a lot of money, just the profit. Of course, the dollar amounts are also available here, but just a profit, the spread was $200,000. Something that's very interesting here is that transaction costs are like crazy because all these bots are actually racing each other. If you look at the actual transaction costs they are 10 times the usual.

Some of these transactions are $100, $200 transaction fee because they want that 5% spread. This is an example.

You can see, I think in September 25/26 there was actually a big crash of ETH, so a lot of loans got liquidated. You can see there's $300,000 in the wrapped ETH to DAI. That's the profit. We have these liquidation models for different collateralized loan platforms – dYdX, Compound, bZx.

What these guys are using is essentially there. You can just download the CSV, or you can create an API endpoint and put it in your Excel spreadsheet. It's always fresh data. Excel and Google Docs has this feature called "importdata". On Google docs you can say =importdata, and then this URL. What happens is, all of your data is always fresh in your Google Sheet, so you can just create whatever formulas you want as always updated. You don't have to download the CSV each time. Excel has that data query capability as well.

Audience: Can you explain why the numbers like you have a lower negative in terms of profits?

Ganesh: Yes. This is rounding error. What we have is our price data is granular on a day level and this is only $76, so it's all rounding errors. Like this is $50, it's like $3.

Audience: I can see this. Okay.

Ganesh: Even like the 5% spread plus or minus, that's it.

Audience: There were very same order then.

Ganesh: Yes, it's only two liquidations for the DAI-USDC because the stablecoins-stablecoin it's never going to change, right? It's never wallet that. You use a stable coin as a collateral and take out a stable coin is a load. Yes, that's why it doesn't--

Audience: Like you have the same for Compound, MakerDAO.

Ganesh: We don't have a MakdeDAO model, but something on our to-do, but if that's interest to you we can collaborate on a MakerDAO model. These models are all less than 100, 150 lines. This is just a simple JSON file.

Audience: All these data come from Ethereum blockchain?

Ganesh: Yes. All of this data is on the--

Audience: Everything's available there?

Ganesh: Everything's available there. The only thing that's not available are the prices. We actually have a volume-weighted price index for all historical prices. Because this is mostly for historical analysis rather than real-time usage of data so far daily granularity of the prices has been enough, but if you want the exact spot price at that time, there are other providers we willing to work with like Nomics has that real-time order book prices. You can definitely tap into that, but once you have the balance then you can just multiply that with whatever that price is. You can do a VLOOKUP, that can always be done outside the platform.

Audience: The profits in dollars are measured through your volume-weighted price average for the day?

Ganesh: Exactly.

Audience: Okay.

Ganesh: Exactly.

Audience: That's why you get these numbers that are negative also because it's not exactly the right price?

Ganesh: Exactly. It's always done in two steps. We do all of the calculations using data on the blockchain. For display purposes, we multiply it with the daily volume-weighted prices to just show the user. Under this thing, there's actually a column here, so like transaction cost ETH, for example, there is no variance in this because that's exactly on the blockchain. The value of ETH will change depending on the source you multiply with.

Audience: For these prices, where do you get them from?

Ganesh: We have crawlers for that.

Audience: Okay.

Ganesh: Yes, that's one example.

[00:06:15] [END OF AUDIO]