Watch Latest Shows & Videos on Our Official YouTube Channel – BLOCKBYTES

Facebook Twitter Youtube Instagram Tiktok Linkedin Spotify
Blockbytes
  • Home
  • Shows
    • Across The Chains
    • Beyond the Block
    • Featured By Blockbytes
    • The Workflow
    • Byte Sized Videos
    • Quickflip Polygon
    • Legacy Content
  • Articles
    • News
    • Getting Started
    • Project Overviews
    • DeFi
    • NFTs
    • Networks
      • Polygon
      • Iota + Shimmer
      • Fantom
      • Aurora
  • BlockBytes Weekly
  • Meet the Team
    • About Us
    • Contact
Reading: Modeling DeFi II: Lending
Share

  • bitcoinBitcoin(BTC)$16,787.14
  • ethereumEthereum(ETH)$1,210.10
  • tetherTether(USDT)$1.00
  • usd-coinUSD Coin(USDC)$1.00
  • binancecoinBNB(BNB)$247.45
  • binance-usdBinance USD(BUSD)$1.00
  • rippleXRP(XRP)$0.344393
  • dogecoinDogecoin(DOGE)$0.073311
  • cardanoCardano(ADA)$0.250973
  • matic-networkPolygon(MATIC)$0.79

Aa
Blockbytes
  • Home
  • Shows
  • Articles
  • BlockBytes Weekly
  • Meet the Team
Search
  • Home
  • Shows
    • Across The Chains
    • Beyond the Block
    • Featured By Blockbytes
    • The Workflow
    • Byte Sized Videos
    • Quickflip Polygon
    • Legacy Content
  • Articles
    • News
    • Getting Started
    • Project Overviews
    • DeFi
    • NFTs
    • Networks
  • BlockBytes Weekly
  • Meet the Team
    • About Us
    • Contact
Have an existing account? Sign In
Follow US
Facebook Twitter Youtube Instagram Tiktok Linkedin Spotify
Blockbytes > Blog > Article > Series > Modeling DeFi II: Lending
Series

Modeling DeFi II: Lending

kickflip
Last updated: 2022/07/19 at 12:53 PM
kickflip Published July 19, 2022
Share

Welcome back, everyone! Kickflip is here to do some more modeling for us 📷😎. While the previous entry in the modeling DeFi series isn\’t mandatory for understanding this entry, it is a good read! Check it out! But, if you\’re unfamiliar with lending, this is a must-read!

Contents
Lending and LiquidationFirst Step: Price ImpactSecond Step: Collateral, Borrowing, LiquidationSurf’s UpRisky BusinessThanks

Lending and Liquidation

Given the recent liquidation cascades on FTM and other networks, I wanted to learn more about the mechanics of these cascades. Sure, we all know; price goes down, user gets liquidated, price goes down more. But I want to dive a little deeper into the nuance of DeFi lending and introduce some risk considerations.

I modeled price impact equations, a collateral and loan to value (LTV) framework, and a liquidation event. Some of you may have seen my Twitter thread on the topic, but I hope to provide a more detailed explanation of the model and outcomes in this installment. I will take readers through the equations that govern price impact and look at some parameter sensitivities in liquidations. The underlying concept of price impact is how LPs rebalance, and arbitrage becomes possible. I will offer prompts throughout, but I challenge readers to think critically about how LP rebalancing and arbitrage work. They are topics for a separate discussion.

Like last time, please note that this article may become quite technical, so feel free to follow along with a pen and write the equations yourself to help build your understanding. Alternatively, reach out to the community to help you understand bits and pieces.

First Step: Price Impact

Start with some kind of liquidity pool that has two tokens in it. One of token A and one of token B, both tokens are worth 1. In mathematical modeling, we call this normalizing. In reality, the LP I described is ridiculous, but the variables are irrelevant to what we are modeling, so we can call them all one and see how they change as a percentage.

In most AMMs, Price Impact is governed by the Constant Product (CP) equation:

\"\"

That is, the product of the quantities of the two tokens remains constant. If there are 50 of each token, the CP is 2500. This equation governs price impact but also scales with deposits and withdrawals. If a swap is conducted, the CP holds constant, and if liquidity is added or removed, the CP increases or decreases accordingly.

The case of adding or removing liquidity is fairly intuitive, but I will present a quick example of a swap. If FTM were valued at $3 (those were the days), then an LP may contain 1000 FTM and 3000 USDC. The constant product is therefore 3000000.

Now, if someone were to swap 200 USDC for FTM, they would deposit their 200 USDC and get back some FTM. When their USDC goes in, there is 3200 USDC in the pool. It’s a swap, so CP holds. Therefore, the pool rebalances according to 3000000/3200=937.5 FTM. The seller will receive 62.5 FTM (the entire 1000 FTM is accounted for). Notice that they didn’t receive 66.67 FTM? Their swap was a large percentage of the initial pool, so there has been a significant price impact! The price of FTM in the transaction was $3.2 (6.67% price impact).

If the pool were much larger, the price impact would have been much smaller. Hence the importance of ‘deep liquidity.’

Back to the model; we have 1 of each token, so in our case, CP = 1.

Second Step: Collateral, Borrowing, Liquidation

If we offer collateral, we need to have a means of liquidating, so we will not provide more collateral than 1 of either token because there is only 1 of each token in the LP. We also want to control LTV. LTV describes the amount you can borrow relative to your collateral. For example, if you provide 1 unit value of collateral, at 50% LTV, you can borrow up to 0.5 units value of another asset. The more you borrow, the more you risk approaching the liquidation threshold if price action is unfavorable.

For this model, I looked at every combination of Token A collateral between 0 and 1 and Token B LTV between 0 and 1 to see the price impact if liquidated. To have a detailed enough look between 0 and 1, I discretized the range into 100 steps, meaning there are 100 points between 0 and 1 to be modeled. The more points, the more detail, but it requires more computing power, and the detail becomes unnecessary.

We have liquidity, we have collateral (Token A), and we have borrowed assets (Token B). There are a few things to consider in this modeled liquidation event. The model ignores price action and treats liquidation as instantaneous. When you borrow, prices have to change for liquidation to occur, so consider that prices have changed to the conditions in the model, so we can look at what happens.

Surf’s Up

This is called a surface plot, and in this case, it demonstrates the price impact of liquidation under the borrowing conditions I described earlier.

\"\"/

The plot is 3-dimensional, so I can rotate it and look around in the model. I think this view is pretty good for this discussion. The X- and Y- axes represent LTV and the number of assets loaned compared to the quantity in the LP. The Z- axis represents the price impact of liquidation. As you’d expect, when we borrow more, the price impact is higher, but we can also look at sensitivities (how quickly the price impact changes when we change the loan amount and LTV in this case). Note that this model presumes partial liquidation, meaning not all of the collateral is liquidated. Instead, enough collateral to cover the loan based on LTV. In the case of a maximum loan (collateral 1, LTV 1, therefore Qty Loaned 1), there is a 50% price impact. Recall that if we have 1 of each token in the LP (CP: 1*1=1) and we add 1 of Token A (1+1=2), we will receive 0.5 of Token B (CP: 2*0.5=1). So the more collateral the system needs to liquidate, the trickier it becomes to recover borrowed assets.

Risky Business

This all lends itself to the relationship between lending and liquidity in DeFi. Lending protocols that genuinely care about their ecosystems should carefully select collaterals and allocate LTVs based on available liquidity to ensure the system can handle price impacts from liquidation.

In theory, a lending protocol that monitors market liquidity and current lending/ borrowing statistics could manage risk by altering offered LTV to control price impact from liquidation concerning price action (Collateralisation Ratios can also provide a buffer for price impact). That’s quite a mouthful, but it makes sense in my mind. Expect more price action for volatile assets and adjust risk parameters accordingly. The same goes for less volatile assets and again for stablecoins. Reality is more nuanced and merits considerable discussion, but that is for another time.

Thanks

Once again, if you made it to the end, thank you. I hope you learned something from this write-up. Please reach out and let me know if this piece was useful (or if you think I made any mistakes). I’d also like to hear from you if there are any concepts you would like to explore. I’ll see if I can figure it out.

Pop pop,

kickflip

You Might Also Like

Iron Bank vs Alpha Homora – Protocol Exploits Protocol

0VIX Protocol

Modeling DeFi, Part 8 – Boosted Pools

Modeling DeFi VII: – RoboVault Delta-Neutral Strategies

TAGGED: Lending, Modeling

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.

By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share this Article
Facebook Twitter Email Copy Link Print
Previous Article Multi-Strategy Vaults Mean More Money
Next Article Granary Integrates Chainlink Price Feeds To Help Secure Their Peer-to-Peer Lending Platform
- Subscribe Us-
Ad image
Popular News
Arbitrum Top 5
Five Arbitrum Projects to Watch in 2023
Thena
THE Thena Overview
Signature Bank
The Latest Crypto Bank Closure – Signature Bank joins SVB and Silvergate Bank
Silvergate
The First Domino – The End of Silvergate Bank
USDC DEPEG
USDC DEPEG: CIRCLE’S ROLLERCOASTER OF A WEEKEND

Latest News

Arbitrum Top 5
FeaturedNetworks

Five Arbitrum Projects to Watch in 2023

March 24, 2023
Thena
Project Overviews

THE Thena Overview

March 24, 2023
Signature Bank
Editor's PicksNews

The Latest Crypto Bank Closure – Signature Bank joins SVB and Silvergate Bank

March 14, 2023
Silvergate
Editor's PicksNews

The First Domino – The End of Silvergate Bank

March 14, 2023

Stay Connected

Twitter Youtube

Subscribe

Removed from reading list

Undo
Welcome Back!

Sign in to your account

Register Lost your password?