Instructor: Katya Malinova
Course : F741 Fall 2023
A quick recap
blockchain=
an infrastructure for digital resource transfers
software protocols that allow multiple parties to operate under shared assumptions and data
without trusting each other.
Updates are packaged into “blocks” and are “chained” together cryptographically to allow an audit of the prior history
cryptocurrency =
internal payment mechanism to pay for operation of a blockchain
Consensus Protocol =
a set of rules that determine what kinds of blocks can become part of the chain and become the “truth”.
Source: Cambridge Bitcoin Energy Consumption Index https://cbeci.org/
Proof of work protocol: unsustainable amount of energy
Ethereum power usage before the Sept 15, 2022 Merge
Why is this idea powerful?
payments
stocks, bonds, and options
swaps, CDS, MBS, CDOs
insurance contracts
A blockchain is a
What makes DeFi different from TradFi
decentralized finance =
provision of financial service functionality without the necessary involvement of a traditional financial intermediary like a bank or broker-dealer*
digital media =
provision of information service functionality without the necessary involvement of a traditional information intermediary like a publisher, library, or newagency
*my take: applies to only commoditizable services
payments network
Stock Exchange
Clearing House
custodian
custodian
beneficial ownership record
seller
buyer
Broker
Broker
Sources of savings:
Possible transaction cost savings in cash equities: \(\approx\) 30%
Source: "Learning from DeFi: Would Automated Market Makers Improve Equity Trading?" working paper, Malinova & Park 2023
UniSwap Lab supports development
a website app accesses the code
token holders control contact features
don't own the code
operation = decentral
control = decentral
anyone can use the baseline code
core code runs on the blockchain
tokens used as rewards
Application: Decentralized Borrowing & Lending
borrow
provide collateral
The Flow of Event: Normal Times
The Flow of Event: Collateral Liquidation
1. flash-borrow DAI
5. repay DAI
3. receive the collateral (ETH) at a discount
4. convert ETH to DAI
2. liquidate ETH-collaterilized loan with DAI
Loan liquidation opportunity
New tools: flash loan
Many automated DeFi products are emerging
Obvious Smart Contract Application: Automate Investment Strategies
"yield aggregator:" push capital where rate of return is highest
Crypto Trading
Broker
Exchange
Internalizer
Wholeseller
Darkpool
Venue
Settlement
Centralized Trading
BTC/USD
ask: 7,600
bid: 7,550
BTC/USD
ask: 7,500
bid: 7,450
buy BTC
sell BTC
move BTC to Kraken
Crypto Wash Trading, Lin William Cong, Xi Li, Ke Tang, Yang Yang
What is pump and dump?
arranged via Telegram Channels
IS BITCOIN REALLY UN-TETHERED? JOHN M. GRIFFIN and AMIN SHAMS
Journal of Finance 2020
Figure 1. Aggregate Flow of Tether between Major Addresses
August 2016
Nov 8
The FTX Implosion
Recurring Core problem
In a regulatory vaccum re: custody
Decentralized Trading
Turns out ...
Decentralized Exchanges (DEX)
Idea:
\(\to\) simply connect with MetaMask (or similar wallet)
New institutions!
AMM Pricing
Key Components
\(X-Q\)
\(X\)
\(Y+P(Q))\)
\(Y\)
\(c=X\cdot Y\)
Price mechanism:
Prices
invariant \(k=4\times4=16\)
Instantaneous exchange rate:
1 = 1
Contract deposit:
sell 4 DAI for how many USDC?
1
0.5
=
invariant \(k=100\times100=10,000\)
Contract deposit:
Problem: large "slippage" (or price impact)
"Deep liquidity" helps minimize this.
\(100\times\)
\(100\times\)
sell 4 DAI for how many USDC?
\(100\times\)
\(100\times\)
\(3.85\times\)
\(-3.85\times\)
1
0.9625
=
\(\to\) the more money is in the contracts, the lower the price impact
front-running
transactions enter mem-pool
\(\to\) all visible there
arbitrageur make instant-swap trade at higher gas price
\(\to\) trade instead of original trade
"fix" (not a proper solution): set a max slippage (a range of prices that willing to trade at)
Uniswap V3
Stopped here in lecture 3
DEX: Quick Recap
Liquidity providers
Liquidity demander
Liquidity Pool
AMM pricing is mechanical:
USDC
Quiz: Quick Recap
Consider a DEX (decentralized exchange) that prices securities according to the constant product rule discussed in lecture. The initial deposits in the liquidity pool are 200 ETH and 300,000 USDC. You want to buy ETH.
Note: buy ETH = sell USDC
After you buy 1 ETH in exchange for y USDC, the pool will have
\(\Rightarrow 200 \times 300,000= (300,000 + y) \times (200-1) \)
\(\to y = 1,508\)
Quiz: Quick Recap
After you buy 10 ETH and sell y USDC, the pool will have
\(\Rightarrow 200 \times 300,000= (300,000 + y) \times (200-10) \)
\(\to y = 15,789\) -- cost of 10 ETH!
\(\to 1,578.9\) per 1 ETH
front-running
transactions enter mem-pool
\(\to\) all visible there
arbitrageur make instant-swap trade at higher gas price
\(\to\) trade instead of original trade
"fix" (not a proper solution): set a max slippage (a range of prices that willing to trade at)
Uniswap V3
Transaction Processing in DeFi
Transaction Visualization
transactions
decentralized applications
tokens
The
"Mem-Pool"
a
b
c
d
e
f
g
A Simple Overview
a
b
c
d
e
f
g
The reality is more complicated
Consequence 1: Extract Value from Users
"Ethereum is a Dark Forest"
The charts are for pre-merge, see https://transparency.flashbots.net for post-merge stats
Consequence 2: Excess Gas Prices ("Priority Gas Auctions")
One resolution:
Flashbots Protocol
Idea of Flashbots
Flashbots does not prevent MEV!
@katyamalinova
malinovk@mcmaster.ca
slides.com/kmalinova
https://sites.google.com/site/katyamalinova/
Illustration
Transactions Send to Searchers
NB: the relay is a security measure: it has high capacity and can distinguish garbage from real transactions
Bundles come to Miners
NB: miners could still manipulate, front-run etc, but Flashbots monitors them and would cut them off if they misbehave
Is it used?
81% of validators have signed on with Flashbots (>880,000 total)
Does Flashbots Prevent MEV? No!
Does Flashbots Prevent MEV?
Flashbot 3.0 Transaction Privacy