Lending and Borrowing Instructors: Dan Boneh, Arthur ...
Transcript of Lending and Borrowing Instructors: Dan Boneh, Arthur ...
![Page 1: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/1.jpg)
Decentralized Finance
Instructors: Dan Boneh, Arthur Gervais, Andrew Miller, Christine Parlour, Dawn Song
Lending and Borrowing
![Page 2: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/2.jpg)
Why lending?
2
![Page 3: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/3.jpg)
How the “Economic Machine” works?
3Ray Dalio - https://www.youtube.com/watch?v=PHe0bXAIuk0
![Page 4: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/4.jpg)
How the “Economic Machine” works?
4Ray Dalio - https://www.youtube.com/watch?v=PHe0bXAIuk0
![Page 5: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/5.jpg)
On-Chain Lending & Borrowing
Vault
Price Oracle
Lender
Borrower
Liquidator
Deposit principal
Redeem principal + interest
Collateralize
Borrow
Liquidate
Report prices
5
![Page 6: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/6.jpg)
Leverage == A debt multiplier
6
![Page 7: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/7.jpg)
Terminology
https://defi-learning.org
![Page 8: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/8.jpg)
Terminology
▪ Collateral▪ Assets that serve as a security deposit
▪ Over-collateralization▪ Borrower has to provide
value(collateral assets) > value(granted loan)
▪ Under-collateralization▪ value(collateral) < value(debt)
▪ Liquidation▪ If value(collateral) <= 150% x value(debt)▪ Anyone can liquidate the debt position
8
![Page 9: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/9.jpg)
Health Factor
Borrowing Capacity
9
![Page 10: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/10.jpg)
Health Factor
Debt
Collateral
Borrowing Capacity
10
![Page 11: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/11.jpg)
Terminology
11
![Page 12: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/12.jpg)
Over-collateralized Borrowing
https://defi-learning.org
![Page 13: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/13.jpg)
Over-collateralized Borrowing
13
▪ E.g., the borrower collateralizes ETH and borrows DAI
▪ The value of ETH exceeds the value of DAI
▪ The borrower can use the borrowed DAI arbitrarily/freely
![Page 14: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/14.jpg)
Over-collateralized Borrowing
14
Aave Dashboard Screenshot
DAI is deposited as collateral
UNI is borrowedThe borrowing interests the borrower needs to pay
In Aave, the collteral is also lent out. Hence the borrower can also earn interests.
![Page 15: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/15.jpg)
Over-collateralized Borrowing
15
Stablecoin
Step 1
Step 2
Step 3
ETH deposited to open CDP
Draw DAI
Pay back DAI to unlock ETH
MakerDAO
Debt
Collateral
![Page 16: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/16.jpg)
Under-collateralized Borrowing
https://defi-learning.org
![Page 17: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/17.jpg)
Under-collateralized Borrowing
17
▪ E.g., the borrower collateralizes ETH and borrows DAI
▪ The value of DAI (debt) can exceed the value of ETH (collateral)
▪ The collateralized ETH and borrowed DAI are restricted to be used with pre-designed smart contracts. Those are typically farming contracts.
▪ The vault remains in control of all assets.
![Page 18: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/18.jpg)
Under-collateralized Borrowing
18
Alpha Homora Dashboard Screenshot
![Page 19: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/19.jpg)
Under-collateralized Borrowing
19
Alpha Homora All Positions
![Page 20: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/20.jpg)
AH Statistics
20
▪ Opened Positions (October 2020 – August 2021)▪ 3800 borrowers▪ 10,430 leverage positions
▪ Leverage multipliers▪ AHv1: 2.01x▪ AHv2: 3.07x
▪ Stablecoin leverage multipliers▪ 5.39x
![Page 21: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/21.jpg)
How are borrowers choosing leverage multipliers?
21
▪ Distributions of leverage multipliers in Alpha Homora V2 (2581 positions).
![Page 22: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/22.jpg)
APY under Leverage
22
![Page 23: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/23.jpg)
APY under Leverage
23
Why does leverage not amplify APY in practice?
leverage multiplierrevenue
borrowing interest
impermanent loss
liquidation risk
![Page 24: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/24.jpg)
Liquidation
https://defi-learning.org
![Page 25: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/25.jpg)
What could go wrong?
25
![Page 26: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/26.jpg)
Liquidation
26
▪ Liquidation == Selling collateral from the borrower
▪ Liquidation Spread▪ Bonus, or discount for liquidator▪ Fixed spread, or variable (auction based)
![Page 27: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/27.jpg)
Liquidation in Traditional Finance
27
![Page 28: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/28.jpg)
Fixed Spread Liquidation
Liquidator
Repay debt
Acquire collateralVault
completed in one blockchain transaction
▪ Repays the debts of a borrowing position
▪ Acquires the collateral at a discounted price from the position in return▪ Typical discounts are e.g., 5-15% in Aave
28
![Page 29: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/29.jpg)
Fixed Spread Liquidation
Debt
Collateral
Borrowing Capacity
A fixed spread liquidation
29
![Page 30: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/30.jpg)
Auction Liquidation
Liquidator A Liquidator B
Bid A1 Bid B1 Bid A2 Bid B2
▪ Various liquidators bid over time until the auction terminates
▪ Requires multiple blockchain transactions.
Auction starts Auction terminates
timeline
30
![Page 31: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/31.jpg)
Auction Liquidation
31
▪ English Auction▪ bidders outbid each other increasingly
▪ Dutch Auction▪ auction begins with a high asking price and the
price lowers until the auction terminates
![Page 32: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/32.jpg)
Auction Liquidation
32
MakerDAO tend-dent English auction (Day one ─ April 2021)
Initiate Terminate
auction length
tend dent
debt to repay, collateral to claimBid ──
![Page 33: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/33.jpg)
Auction Liquidation
33
MakerDAO Dutch auction (April 2021 ─ Present)
▪ Instant Settlement▪ Unlike English auction which are operated in multiple transactions, the
MakerDAO Dutch auction is settled instantly in one atomic transaction.
▪ Flash Lending of Collateral▪ No upfront DAI (i.e., the debt) is required (i.e., a flash loan used
specifically for MakerDAO liquidations).
▪ Price as a Function of Time▪ Collateral price decreases over time 🡪 nobody can get the collateral for
free by accident
![Page 34: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/34.jpg)
Liquidation Statistics
▪ April 2019 - April 2021 (2 years)
▪ Aave (V1 & V2), Compound, dYdX, and MakerDAO
▪ 28138 successful liquidations
▪ 807.46M USD of collateral sold through liquidations
34
![Page 35: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/35.jpg)
Liquidation Statistics
▪ Total profit: 63.59M USD
▪ MakerDAO outlier in March 2020, caused by bot failure.
35
![Page 36: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/36.jpg)
Liquidation Statistics
▪ Liquidators typically pay significant gas fees, indicating severe competition.
36
![Page 37: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/37.jpg)
Liquidation Statistics
▪ Liquidation Sensitivity▪ liquidated collateral upon a hypothetical price decline.
37
Aave Compound
dYdX MakerDAO
![Page 38: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/38.jpg)
Liquidation Case Study & Insights
https://defi-learning.org
![Page 39: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/39.jpg)
Maker DAO Bot Failure
39
Market Collapse
Gas Price Increase
Liquidation Opportunities
MakerDAO bots issue transactions
Transactions are not mined
![Page 40: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/40.jpg)
Liquidation Insights
Optimal Fixed Spread Liquidation Algorithm▪ Health Factor▪ A fixed spread liquidation does not
necessarily increase the health factor
▪ Over-liquidation▪ Liquidations sell excessive amounts of
borrower’s collateral
▪ Optimal Liquidation strategy▪ Liquidating up to the close factor is
not necessarily the best strategy.▪ Instead, two successive liquidations
might offer more profits. 👉40
![Page 41: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/41.jpg)
Liquidation Insights
41
Comparison of liquidation mechanisms
▪ Metrics: the ratio between monthly liquidation profit and volume
▪ Data suggests that auction liquidations might be more borrower friendly
▪ dYdX does not have a close factor
![Page 42: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/42.jpg)
Liquidation Insights
42
▪ Deleveraging Spiral
LiquidationCollateral Price
DeclineFurther
Liquidation
Is liquidation a good solution to secure lending pools?
![Page 43: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/43.jpg)
Case Study: Optimal Fixed Spread Liquidation
Token Collateral DebtPrice (USD)
Block 11333036 After price update
DAI 108.51M 93.22M 1.08 1.095299
USDC 17.88M 506.64K 1 1
Total Collateral (USD) 135.07M 136.73M
Borrowing Capacity (USD) 101.30M 102.55M
Total Debt (USD) 101.18M 102.61M
Healthy Liquidatable43
![Page 44: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/44.jpg)
Case Study: Optimal Fixed Spread Liquidation
Original liquidation
Repay 46.14M USD
Receive 49.83M DAI
Profit 3.69M DAI
Up-to-close-factor strategy
Repay 46.61 DAI
Receive 50.34M DAI
Profit 3.73M DAI
Optimal strategy
Liquidation 1 Liquidation 2
Repay 296.61K DAI Repay 46.46M DAI
Receive 320.34K DAI Receive 50.18M DAI
Profit 23.73K DAI Profit 3.72M DAI
44Optimal strategy yields 3.743M DAI instead of 3.69M DAI
![Page 45: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/45.jpg)
What ideas do you have to avoid liquidations?
45
![Page 46: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/46.jpg)
Flash Loans
https://defi-learning.org
![Page 47: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/47.jpg)
47
What if Bart can grant a loan to Bob,
without the risk of Bob defaulting on the debt?
![Page 48: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/48.jpg)
48
1. Take flash loan
2. go-Wild(loan);
3. Repay loan + interest
Flash Loan
![Page 49: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/49.jpg)
Flash Loan
49
Asset X
smart contract pool
Add liquidity X
Loan + Repay X
+ fee for Alice
In a single, atomic
transaction
Flash loans are a special form of lending. A flash loan should be taken and repaid in one single transaction.
![Page 50: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/50.jpg)
Flash Loan Pools
50
▪ Uniswap – 0.3% fees▪ V2 - 5B USD▪ V3 - 2.2B USD
▪ Aave – 0.3% fees▪ 10B USD
▪ dYdX – constant fee of 1 Wei▪ about 100M USD
![Page 51: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/51.jpg)
Flash Loan Sizes
51
January 2020 October 2020
![Page 52: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/52.jpg)
Flash Loan Use Cases
52
▪ DeFi attacks▪ Price Oracle Manipulation▪ Pump and Dump
▪ (Risk-free) Arbitrage▪ Washtrading▪ Flash Minting▪ Collateral swapping
![Page 53: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/53.jpg)
Flash Loan Arbitrage
53
![Page 54: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/54.jpg)
Flash Loan Based Liquidation
54
▪ When a liquidator does not have the cryptocurrency upfront to repay
▪ Only works when the liquidation completes in one transaction
Given a liquidatable borrowing position with a debt of 2000 DAI collateralized by 2 ETH
2000 DAI 2 ETH
![Page 55: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/55.jpg)
Flash Loan Based Liquidation
55
▪ When a liquidator does not have the cryptocurrency upfront to repay
▪ Only works when the liquidation completes in one transaction
Given a liquidatable borrowing position with a debt of 2000 DAI collateralized by 2 ETH
1000 DAI
1.5 ETH
1000 DAI 0.5 ETH
1000 DAI
![Page 56: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/56.jpg)
Flash Loan Based Liquidation
56
▪ When a liquidator does not have the cryptocurrency upfront to repay
▪ Only works when the liquidation completes in one transaction
Given a liquidatable borrowing position with a debt of 2000 DAI collateralized by 2 ETH
1.5 ETH
1500 DAI1000 DAI
500 DAI
![Page 57: Lending and Borrowing Instructors: Dan Boneh, Arthur ...](https://reader031.fdocuments.us/reader031/viewer/2022012500/61799de9bd567947a1558f49/html5/thumbnails/57.jpg)
Collateral Swap
57
-1000 DAI+1 ETH
-1000 DAI+2000 USDC
1. Take a flash loan of 1000 DAI2. Repay 1000 DAI3. Redeem 1 ETH4. Swap 1 ETH to 2000 USDC5. Collateralize 2000 USDC6. Borrow 1000 DAI
Dept Position Dept Position