You are on page 1of 52

Decentralized lending

News this week: Hard year for crypto (tabb)


2022 crypto winter: 2 trillion worth of assets wiped out equal to 1.5 Australian GDP from Terra-Luna to FTX.
Integrity: Remaining crypto actors need to work hard to regain regulatory trust but regulators and legislators
must avoid suffocating the innovation
Issues but possibilities: Innovation rife with risks but leading in transparent, unalterable and discoverable
financial activity.
Flourishing industry: Crypto forensics and crime fighting industry developed rapidly with blockchain
innovation making illegal activity impractical in many cases .
On-ramp security: Virtual asset service provider (VASPs) have implemented a host of collective defense
approaches
Collaboration: Consolidation of risk and financial integrity by sharing information across well-regulated actors
Challenge: Jurisdictions (Singapore, Hongkong, and Japan) adopt their own regulation which can cause “flight”
from regulatory stringency and problematic differences in regulatory framework.
Solution: Regulation should be adopted depending on jurisdictional risk. Allowing “passporting” VASP
registration from weak to strong jurisdictions.
Recap from last week
- Let’s revisit the decentralized exchange
Invariants: What do you see?
Constant sum invariant:
• No slippage: Fixed token pair price
• Vulnerable to extreme extreme movements
• Produces liquidity for a narrow range

Constant product invariant


• Liquidity over much larger price range
• Less vulnerable to extreme price movements
• Slippage: Token pair price not fixed

Hybrid formula
• Advantages of both approaches
• Liquidity in extreme cases
• Resilience to extreme movements
Lehar and Parlour (2021) focus on constant
product invariant
• I hope you:
1. Had a go at the paper
2. Tried creating your own spread sheet
3. Had a look at my spread sheet
Post trade tokens in pool E T

• Trader trades ETH for tokens


• Exchange collects fee for liquidity providers (0.3% at Uniswap)
• Effective ETH traded is then
• Post trade, before fee liquidity pool balance:
• If
• Then

+ T is token in pool before trade: More token before, more token after
- e is ETH sent to pool: the more e the more you deplete the pools supply of token T
Post trade token balance
+ is the fee: Higher fee reduces purchasing power of trader (ability to deplete tokens)
+ E is ETH in pool before trade: Traders ETH is worth less (lower purchasing power)
Note: You can find my file, “BondingCurveWithFeesLogic_upload,” in LMS
Trader receives tokens
• Trader receives the pool outflow, E T

t is the number of tokens trader receives


- E is ETH in pool before trade: T expensive, trader’s purchasing power reduced
+ T is token in pool before trade: T cheap, trader’s purchasing power increased
+ e is ETH sent to pool: Send more eth, receive more token
- is the fee: Fee lowers the traders purchasing power

Derivations in notes
Price for tokens (in eth)
• Trade price (e/t) given by: E T

is the price of tokens


+ e is ETH sent to pool: Send more eth, make a larger price impact
+ is the fee: The fee is a cost that increases the overall price to the trader
+ E is ETH in pool before trade: More ETH in pool means token is relatively more (in demand) expensive
- T is token in pool before trade: More token in pool means token is less (in demand) expensive

Derivations in notes
Liquidity fee
• Suppose fundamental token value is
• If pool is in equilibrium then
• Liquidity fee is then when setting e to 0

• Token buyers therefore pay and Task:

• Token sellers pay

Higher fee, means sellers Higher fee, means


receive lower price higher price for buyers 1. Make an excel sheet that codes in the formula.
2. Note the effect of changing (increasing/decreasing) the numbers.
Derivations in notes 3. Note why an increase in each variable has the noted effect on T’
Zoom in on  > 20,000 digital assets, but highly concentrated
value distribution skewed to major public blockchains
blockchains, (BTC and ETH dominate)
stablecoins, and DeFi
Decentralized lending platforms
• Centralized lending
• Based on credit worthiness (higher credit score = eligible for higher loan)
• Loans are undercollateralized and lender must be compensated for this risk (expensive)
through their rents.

• Decentralized lending
• Over collateralized; in event of default the loan can be recuperated (no need for credit
score).
• Collateralized debt positions (CDP): Creating new tokens using collateral
• Collateralized debt markets:
• Pooled collateralized debt markets
• Peer-to-peer collateralized debt markets
• Under collateralization
Decentralized lending platforms
• We will talk about collateralized debt positions and collateralized
markets
• Collateralized debt positions
• Users “lock” crypto assets in the smart contract to get newly issued tokens
• User keeps market exposure (through their locked asset) and receive a newly
minted (and liquid) asset.
Example: MakerDao
1. User deposits ETH creating a collateralized debt position (CDP)
2. User call contract function to receive DAI and lock their collateral
3. MakerDao requires 150% collateral threshold

𝐶𝑜𝑙𝑙𝑎𝑡𝑒𝑟𝑎𝑙 𝑣𝑎𝑙𝑢𝑒
< 150 %
𝐵𝑜𝑟𝑟𝑜𝑤𝑒𝑑 𝑣𝑎𝑙𝑢𝑒
Example: MakerDao
1. The user pays a fee set by a community of governance token (MKR)
holders
2. Two things can then happen
1. The user returns the DAI and receives their (ETH) collateral
2. The value of the collateral drops below the threshold and is auctioned off
3. MRK holders are rewarded for carrying risk extreme ETH price
movements:
1. Compensation: Interest payments “burn” MRK tokens increasing their value
2. Risk: If ETH falls below certain value, the collateral will not cover the loan and
the protocol will mint and auction off at discounted value reducing the MKR
token value
Lending and borrowing

Here’s I want a new


liquidity loan!
Principal Loan

Liquidity
Collateral
Lender Principal + pool Borrower
interest

Lender: deposits crypto to pool for interest


Borrower: borrows from pool and deposits collateral Pricing
Oracle: provides accurate pricing
Oracle
Terminology
• Collateral:
• Assets staked as a security deposit. This ensures that if you go broke the liquidity pool can
claim your assets.

• Over-collateralization:
• Collateral staked exceeds loan: Value(collateral) < Value(loan)

• Under-collateralization:
• Loan exceeds collateral staked: Value(collateral) > Value(loan)

• Liquidation:
• If Value(loan) >= Value(collateral) * 150% initiates liquidation of loan
Dollar value of the How far the value of our

Health factor collateral locked in the


smart contract
collateral can decrease before
liquidation commences

•,

Value of borrowed
• Where amount

• The debt position can be liquidated if the health factor falls below 1
• How does Value(collateral), liquidation threshold, and value of debt affect the
risk of liquidation?
How does the threshold relate to the health
factor?

For example, if you have a high liquidation threshold, say 1, then your
health factor stays above (or equal) to 1 if you maintain at least $1
collateral for every $1 borrowed.
if you have a low liquidation threshold, say 0.1, then your health factor
stays above (or equal) to 1 if you keep $10 collateral for every $1
borrowed.
As you will always need at least $1 collateral per $1 debt.
Example: Liquidity threshold 0.8

• To avoid liquidation (health factor <= 1) we must keep / at 1/0.8 =


1.25 or above ()
• The exchange rate between Dai and Eth is currently 2000 Dai/Eth
• We believe that Dai will rise in value and therefore put 1 Ethereum as
collateral for 1000 Dai
Example: Liquidity threshold 0.8

• Dai/Eth = 2000

2000

1500
1 ETH in collateral with value
$2000
1000 2000

500
1200 Value of Dai loan is $1200

0
Debt Collateral
Q: What is the health factor?
At what collateral value will we face liquidation?

• Dai/Eth = 2000 Let’s isolate this

2000

1500

1000 2000

1200
500

0
Debt Collateral
What happens if Dai/Eth drops to 1400?

• Dai/Eth = 1400

2000

1500
1500
1000
1400
1400
1200
500

0
Debt Collateral
Gudgeon et. al. 2021
The liquidator
Liquidator

Here’s
I want a loan!
liquidity
Principal Loan

Liquidity pool
Lender Principal + Collateral Borrower
interest

Lender: deposits crypto to pool for interest


Borrower: borrows from pool and deposits collateral Pricing
Oracle: provides accurate pricing
Liquidator: Liquidates (sells) lender’s collateral Oracle
Value of collateral decreases below threshold.
What happens?
A loan can be made available for liquidation by the smart contract.
1. Liquidators then pay back the debt in exchange for receiving the
collateral at a discount (i.e., liquidation spread), or the collateral is
liquidated through an auction.
2. Debt can also be rescued by “topping up” the collateral, such that
the loan is sufficiently collateralized.
3. Finally, the borrower can repay parts of their debt.
Liquidation mechanisms: Auction
• Auction liquidation
1. Loan becomes eligible for liquidation (health factor < 1).
2. Liquidator starts the auction process (several hours).
3. Liquidators provide bids: Highest bid receives the loan collateral.

More on this later…


Liquidation mechanisms: Fixed spread
• Fixed spread liquidation
• Loan liquidated instantly with predetermined discount (a liquidation spread):
Aave allows up to 15% discount of mkt price.
• Advantage: Avoids long (duration) and costly (transaction fees) auction
• Liquidators can use atomic flash loans: Costly in terms of transaction costs
but reduce currency exposure risk as liquidators don’t need to hold the
asset required for liquidation
The liquidator: Some terminology

• Liquidation: Selling collateral from borrower


• When does this happen?

• Liquidation spread (LS): Bonus/discount that liquidator collects


when liquidating collateral. LS can be fixed or variable (auction
based).
𝑉𝑎𝑙𝑢𝑒 𝑜𝑓 𝑐𝑜𝑙𝑙𝑎𝑡𝑒𝑟𝑎𝑙 𝑡𝑜𝑐𝑙𝑎𝑖𝑚=𝑉𝑎𝑙𝑢𝑒 𝑜𝑓 𝑑𝑒𝑏𝑡 𝑜𝑢𝑡𝑠𝑡𝑎𝑛𝑑𝑖𝑛𝑔∗(1+ 𝐿𝑆)

• Close factor (CF): Maximum proportion of the debt that is


allowed to be repaid in a single fixed spread liquidation

𝑉𝑎𝑙𝑢𝑒 𝑜𝑓 𝑑𝑒𝑏𝑡 𝑡𝑜 𝑟𝑒𝑝𝑎𝑦 < 𝐶𝐹 ∗ 𝑇𝑜𝑡𝑎𝑙 𝑣𝑎𝑙𝑢𝑒 𝑜𝑓 𝑑𝑒𝑏𝑡𝑠


Over/under collateralization
Liquidator

Here’s
I want a loan!
liquidity
Principal Loan

Liquidity pool
Lender Principal + Collateral Borrower
interest

Let’s focus on
the borrower for
a moment
Lender: deposits crypto to pool for interest
Borrower: borrows from pool and deposits collateral Pricing
Oracle: provides accurate pricing
Liquidator: Liquidates (sells) lender’s collateral Oracle
Over-collateralization

Loan

Liquidity pool
Collateral Borrower

• The lender collateralizes Eth for Dai


• The value of Eth (collateral) exceeds the value of Dai (loan):

• Because the loan is over-collaterlized (probability of repayment is high)


the borrower can use the Dai freely
Over-collateralization: the steps (3)

1) Borrower pays collateral, in this case in eth

2) Borrower takes overcollateralized loan, in this case in Dai:

Borrower repays loan and receives collateral


3)
Under-collateralization

Loan

Liquidity pool
Collateral Borrower

• The lender collateralizes Eth for Dai


• The value of Dai (loan) exceeds the value of Eth (collateral):

• Because the loan is under-collateralized (repayment is more risky)


and the borrower can’t use the Dai freely
• The vault remains in control of all assets and the Dai are restricted to
be used with pre-designed smart contracts.
Lets go back to the liquidator Let’s take a look
at the liquidator
Liquidator

Here’s
I want a loan!
liquidity
Principal Loan

Liquidity pool
Lender Principal + Collateral Borrower
interest

Lender: deposits crypto to pool for interest


Borrower: borrows from pool and deposits collateral Pricing
Oracle: provides accurate pricing
Liquidator: Liquidates (sells) lender’s collateral Oracle
Liquidation: The process

Loan Borrower

Liquidity pool
Collateral Liquidator

• Now the liquidator takes care of repaying the loan, and receives the
collateral
• The liquidator acquires the collateral at a discounted price (5%-15%)
Our situation from before:

• Dai/Eth = 1400

2000

1500
1500
1000
1400
1400
1200
500

0
Debt Collateral
Fixed spread liquidator What does this mean?

• Dai/Eth = 1400
• Close factor (CF) = 0.5
• Liquidation spread = 5% Debt repaid Collateral
2000
by liquidator liquidator receives
2000

1500 1500

1000 1000 630


600
1400
1200
500 500
600 770
What’s the
0 0 health factor
Debt Collateral
1400 770 Debt Collateral
now?
𝐻𝐹 = ∗ 0 . 8=𝟎 .𝟗𝟑 → 𝑳𝒊𝒒𝒖𝒊𝒅𝒂𝒕𝒂𝒃𝒍𝒆 𝐻𝐹 = ∗ 0 . 8=𝟏 . 𝟎𝟑 → 𝑯𝒆𝒂𝒍𝒕𝒉𝒚
1200 600
Fixed spread liquidation example (1/2)
1. Currency value: 3,500 USD/ETH
2. Collateral deposit:
• User deposits 3 ETH ($10,500) worth of collateral
• If liquidation threshold (LT) is 0.8 then borrowing capacity (BC) of user is

3. User borrows to the limit of their BC = 8,400 USDC


4. Value of ETH drops to 3,300 USD/ETH and price oracle delivers new ETH price to
smart contract which calculates:

1. Borrowing capacity updates to

2. Results: Collateral eligible for liquidation


Fixed spread liquidation example (2/2)
1. Liquidator steps in and submits transaction to repay 50% of loan
(4,200 USDC).
2. With 10% liquidation spread (LS) liquidator receives collateral at
price:
3. At this price the liquidator gets
4. Liquidator profit is then
Gudgeon et. al. 2021
• Focus on Aave, Compound, MakerDAO, and dYdX, which
collectively represent over 85% of the lending market on Ethereum.
• Systematize the prevalent liquidation mechanisms
• Quantify instability of lending protocols.
• Key findings:
• Liquidation designs incentivize liquidators well
• Liquidators sell excessive amounts of discounted collateral at borrowers'
expense
Contributions: Mechanism favors liquidators
• Liquidation Models and Insights (Systematize liquidation design)
• MakerDao uses auction-based liquidation
• Aave, Compound, and dYdX uses fixed spread liquidation model
• Data Analytics (2 years)
• 2,011 unique addresses
• 28,138 liquidation events
• 641 not profitable for liquidator
• 43% reduction in ETH price would engender liquiditable collateral volume of 1.07B USD on MakerDAO
• Objective Liquidation Mechanism Comparison
• Show whether liquidation mechanisms favor borrower or liquidator
• Fixed spread liquidator favors liquidators over borrowers: More collateral than necessary liquidated
• Optimal Fixed Spread Liquidation Strategy
• Show optimal fixed spread liquidation strategy that further benefits liquidators (at the expense of borrowers)
to the tune of 1.36% increase in liquidation profits.
Liquidation can also happen in auctions
• Multiple liquidators bid over time until the auction terminates
• The liquidator includes a bid on the debt (D) they’ll pay and the
collateral they require (C)
• This requires multiple blockchain transactions
• Two auction types are relevant for our setting:
• English auction: Bidders outbid each other
• Dutch auction: Price is set high and lowers until the auction terminates
MarkerDAO english auction

Dent phase

End
Tend phase
Start

• Tend phase: At the tend phase liquidators compete on the debt they are
willing to cover. Each bid must exceed the next so that debt bid, .

• Dent phase: When the dent phase ends, the debt that must be repaid is set and
the liquidators compete on the collateral they require. Each bid must be
lower than the previous so that collateral bid,
The example from before

Debt Collateral

Dent phase

End
Tend phase
Start

B: I’ll cover 800


B: I require 1400
A: I’ll cover 850
A: I want 1300
B: I’ll cover 1000
B: I’m happy with 1250
A: I’ll cover it all, 1200

Result:
Bob pays 1200 of the
debt and receives 1250
Perez et. al. 2021
1. Examine Compound, one of the most widely used protocols for loanable funds (PLFs), from
its conception to September 2020.
2. Analyze participants' behavior and risk-appetite
3. Recent changes in the dynamics of the protocol: Variations of only 3% in an asset's dollar
price can result in over 10m USD becoming liquidable.
4. Liquidators’ efficiency has improved significantly over time, with currently over 70% of
liquidable positions being immediately liquidated (within one block).
5. Discussion on how a false sense of security fostered by a misconception of the stability of
non-custodial stablecoins, increases the overall liquidation risk faced by Compound
participants.
6. Concentration: Despite the increase in number of suppliers and borrowers over time, the total
amount of funds supplied and borrowed remain extremely concentrated among a small set of
participants.
Borrowers and suppliers

• Borrowers exceeding suppliers and


borrowers themselves become supplies.
• The majority of borrowing and supplying is
concentrated among few users.
• Supply
• Top users supplies 27% of funds
• Top ten users supply 49% of funds
• Borrow
• Top users supplies 37% of funds
• Top ten users supply 60% of funds
• Not due to accounts being pools:
Only one of the top 10 suppliers is a
pool and none for borrowers.
Leveraging spiral: An answer to concentration

• B: Volatile asset held by user


• : Initial capital held by user in B
• A: Borrowed stable asset (against ) to increase
exposure in B
• Collateralized ratio for exposeure ()

• User invest in B with initial capital


• borrows A with B as collateral
• exchange A for B
• collateralizes B…
• ...borrows more A
• exchange A for B
• collateralizes B…
• ...borrows more A
• exchange A for B
• Etc…
Leveraging spirals: In the data

• Top suppliers deposited 342 mil USD and


borrowed 247 mil USD.
• However, only 16% (55 mil USD) are the users
own funds. The rest of minted funds are part of
the leveraging spiral.
• 2,141 accounts use leveraging spiral technique
equaling half (600 mil USD) of the total funds
supplied to the protocol .
Comp governance token
• COMP launched June 15, 2020
• Allows for holders to participate in voting, create proposals, and
delegate voting rights
• COMP minted every block and distributed among borrowers and
suppliers
• July 2, 2020:
• Before COMP distributed proportionately to accrued interest in each market
• After COMP distributed proportionately to borrowed and supplied amounts
• Total locked > total supplied (Fig 3b): User incentive to increase borrowing
position as long as borrowing cost do not exceed COMP earnings.
Liquidation risk

• Concern: Increase in total funds


borrowed/supplied and decrease in liquidity
relative to total borrowers
• Since July 2020, 350m to 600m withing 5%
range of becoming liquiditable
• However maybe 5% isn’t all that bad: Dependent
on the volatility of the asset put in collateral

• Launch of COMP token marked by line


• After launch of COMP token 3-5% decreases in
DAI (major stable coin used as collateral) make
collateral liquidable.
• 3% decrease would turn 10 million USD
liquidable
Liquidation and liquidators

• Historical liquidations:
• Black Thursday (March 12, 2020): Global
stock markets suffered the greatest single-
day fall since the 1987 stock market crash
• July 29, 2020: DAI deviating from peg
significantly
• Early September 2020: ETH price dropping
substantially
• Liquidators becoming more efficient:
• 60% of liquidations occur within one block
of collateral becoming liquidable
suggesting bot activity
• 85% liquidations within 2 blocks (half a
minute)
Gudgeon et. al. 2020
1. Lending protocols consist of 76 percent of market shares (April 15th)
2. Feasibility of attacking makerDao’s governance design
3. Create strategy using a two transaction flash loan
4. “Approximately two weeks after we disclosed the attack details,
Maker modified the governance parameters mitigating the attack
vectors.”
5. Create a lending protocol and “stress test” it. Find that drying up
liquidity in a protocol with debt of $400M can become
undercollateralized in 19 days.
Qin et. al. 2021
• Show quantitatively how transaction atomicity increases the arbitrage
revenue.
• Analyze two existing attacks with ROIs beyond 500k%
• Show how malicious adversaries can efficiently maximize an attack
profit and hence damage the DeFi ecosystem further.
• Previously executed attacks can be “boosted” to result in a profit of
829.5k USD and 1.1M USD, respectively, which is a boost of
2.37× and 1.73×, respectively.
Gudgeon et. al. 2020
• Review the methodologies used to set interest rates on three prominent
DeFi PLFs, namely Compound, Aave and dYdX.
• Provide an empirical examination of how these interest rate rules have
behaved since their inception in response to differing degrees of
liquidity
• Investigate the market efficiency and inter-connectedness between
multiple protocols

You might also like