0/ #DEXes like @Uniswap are a core piece of the decentralized financial infrastructure on $ETH & beyond✨

but what happens under the hood when you swap tokens on exchanges like $UNI, $SUSHI, $JOE or $BOO?🤔

explainer-🧵 on the constant product #AMM model (0/46)⚖️👇
1/ automated market makers have been one of the most important innovations in DeFi and the overall crypto space. The concept was ideated by @VitalikButerin in 2016 and pioneered by @Bancor & @Uniswap in 2017 & 2018 respectively
2/ the #AMM space has quickly grown into the largest sector within #DeFi & today we find decentralized exchanges using the AMM model in various forms on basically every smart contract L1/L2 (or as app-chain implementations)
3/ some examples include:

- $UNI on $ETH, $OP & #Arbitrum

- $CRV across multiple EVM chains

- $SUSHI on various EVM chains

- $JOE on $AVAX

- $BOO on $FTM

- $GLINT & $STELLA on $GLMR

- $RAY on $SOL

- $OSMO or $RUNE built on #Cosmos
4/ on $ETH, DEX landscape is heavily dominated by $UNI as the 7 day volume shows:

source: @DuneAnalytics
5/ #Uniswap's market share (based on volume) on $ETH amounts to 66%, followed by $CRV with 11% and $DODO at 8.4%

4) $SNX

5) $BAL

6) $SUSHI

source: @DuneAnalytics
6/ while aggregators like $1INCH or $ZRX's @matchaxyz have introduced a layer on top of AMM #DEX protocols to improve UX, the market remains dominated by volume generated directly on AMM DEXes

source: @DuneAnalytics
7/ over $50bn in trading volume have been generated across DEXes on $ETH in the past 30days and over 5m unique addresses have already interacted with DEX protocols on $ETH
8/ but instead of taking a closer look at the AMM #DEX landscape*, today we'll dive into how the basic constant product AMM model works and what happens under the hood when you swap tokens on a DEX like #Uniswap

*) follow-up post coming
9/ let's start with liquidity pools

on an AMM #DEX, there are two liquidity pools for each tradeable pair X and Y. The tokens are deposited by liquidity providers and allow other users to trade
10/ one pool contains a quantity x of token X, the other a quantity y of token Y

x and y are hence referred to as the available liquidity for X and Y
11/ liquidity providers (or market makers) have incentives to provide liquidity. Aside liquidity mining rewards that LPs might ear, LPs earn fees that are generated on the liquidity pools they provide liquiditiy to
12/ on @uniswap for example LPs earn transaction fees paid by other traders that amount to 0.3%. These fees are paid out to market makers, proportionally to the fraction of liquidity they contributed to
13/ while market makers can withdraw liquidity at any time, providing liquidity remains risky, for example due to divergence risk (a.k.a. impermanent loss)

thread covering impermanent loss in more detail will follow soon
14/ so, let's assume Alice holds ∆x > 0 of token X and swaps them for token Y using the #Uniswap protocol

what happens under the hood is that Alice adds her ∆x to the liquidity pool for X and in exchange takes some ∆y from the liquidity pool of token Y
15/ consequently, the liquidity pools now contain:

- token X: x + ∆x

- token Y: y − ∆y
16/ but how many tokens ∆y does Alice get? Or, what is the price of token Y in units of X?

on @Uniswap, pricing is regulated by the constant product formula...

xy = k

...and depends on the amount of available liquidity x & y, as well as the quantity ∆x Alice wants swap
17/ we define the quoted price of X in units of Y as P(XY) = y/x

however, this is a theoretical exchange rate and it's important to understand that one cannot trade at this price
18/ we also define what we refer to as the transaction price of X in units of Y as T(XY) = ∆y/∆x

as opposed to the quoted price, this is the price at which you can swap (sell) ∆x units of X for ∆y, given the currently available liquidity
19/ the constant product formula imposes that the product of the two liquidity pools xy does not change after the swap

in terms of a formula, ignoring the 0.3% transaction fees, we have:

xy = (x+∆x)(y−∆y) = k, where k is a constant
20/ we can hence solve for ∆y and then find the transaction price by computing the ratio T(XY) = ∆y/∆x
21/ starting from the constant-product equation we get:

xy = (x + ∆x)(y − ∆y)

= xy + ∆x∆y − y∆x + x∆y

⇒ ∆y = ∆x*(y/(∆x+x))

We can now compute the transaction price

T(XY) = ∆y/∆x = y/(∆x+x)
22/ so, we have:

- a quoted price P(XY) = y/x

- a transaction price T(XY) = y/(∆x + x)

therefore, if Alice sells token X, the transaction price is lower than the quoted price. The difference is the price impact of the trade
23/ hence, if Alice sells a larger quantity, she gets a worse transaction price. If the size of the trade is small relative to the available liquidity on the other hand, the transaction price approaches the quoted price
24/ @Uniswap provides the price impact Π in percentage terms, depending on available liquidity & trade size

we can easily compute price impact using elementary algebra:

Π = (P(XY)−T(XY))/P(XY) = ∆x/(∆x+x)
25/ the price impact is increasing & concave in the trade size
26/ suppose we want to trade 1k ETH in exchange for wBTC. Based on Oct 2020 prices, trade size is roughly $375'000. According to its Limit Order Book, trading on Bitfinex would result in a price impact of around 0.6%, excluding commissions
27/ on #Uniswap on the other hand, the price impact would only amount to 0.14%, saving a significant 46bps (roughly $1'700)
28/ remember, each swap impacts the available liquidity of X and Y. As a consequence, the quoted price will be updated as follows:

P(XY) = y/x → Q(XY) = (y−∆y)/(x+∆x)
29/ from the requirement (x + ∆x)(y − ∆y) = xy, it follows immediately that the new price after the trade is given by

Q(XY)= xy/(x + ∆x)^2
30/ hence, the new price is lower than the transaction price:

xy/(x+∆x)^2 = (x/(x+∆x))*(y/(x+∆x)) < y/(x+∆x)
31/ the below figure shows the price change corresponding to a swap of ∆x = 100k $ETH in exchange for $UNI

the pricing curve was computed liquidity using data from October 2020 (block 11034508)
32/ trading, listing and liquidity provision on #Uniswap is performed through smart contracts.High-level, the @Uniswap router governs and records swaps between pairs of tokens. The router does not hold any token, it just routes tokens to the correct destination
33/ each trading pair is connected to a specific smart contract & is created when the pair is listed on the #DEX for the first time

remember, a smart contract is formally an account on the $ETH blockchain & can therefore hold tokens
34/ in #Uniswap's case, the contract for the pair X/Y holds the x & y tokens in the corresponding liquidity pools. When a user provides liquidity, tokens are transferred to this contract & when a user swaps, tokens are transferred to and from this contract
35/ if a user wants to list a new trading pair X/Y for the first time, the user needs to create two liquidity pools, containing token quantities x of X & y of Y
36/ the initial ratio y/x chosen by the creator determines the initial relative prices:

- P(XY) =y/x

- PYX =x/y
37/ the emergence of automated market makers has also created major #arbitrage opportunities
38/ an #arbitrage opportunity between two financial assets A and B is a situation in which it is possible to pocket a risk-free profit trading the two assets
39/ classic examples of #arbitrage are:

- different prices for the same asset quoted in different markets

- triangular arbitrage between 3 assets

- mis-pricing of derivative securities with regards to the underlying
40/ in theory, #arbitrage opportunities should quickly disappear since as soon as traders find one, they trade to profit from it and as a consequence, prices adjust making the arbitrage disappear
41/ consistency of #Uniswap prices crucially depend on arbitrage. Assume the same pair X/Y can be traded both on #Uniswap and on other (centralized) exchanges
42/ suppose P(XY), the price on @Uniswap, is different from that on another exchange P'(XY)

the wedge P(XY) − P'(XY) provides an arbitrage opportunity
43/ since prices on an AMM #DEX like #Uniswap are solely determined by the ratio between assets in the liquidity pools, arbitrageurs can exploit the opportunity by executing trades that adjust the ratios in a way that the price converges with the price on other exchanges
44/ based on trading volume in the last 24h, overall #Uniswap volume is dominated by $ETH, followed by $USDC & USDC, $wBTC and $DAI

source: @uniswap
45/ the most active pool in the last 24h was the $USDC/$ETH pool with over $300m in volume

source: @uniswap
46/ thanks for reading if you made it until the end! If you liked this thread, please support me by following & sharing the first post of the thread 🥰✨

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with L2 Gromlin (💙,🧡)

L2 Gromlin (💙,🧡) Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @expctchaos

Sep 12
0/ when analyzing a DEX, it's essential to look at efficiency metrics that provide an indication on how efficiently a DEX is able to generate volume & revenues on its TVL 📊🔍

feat. $UNI, $SUSHI, $JOE, $BOO, $QUICK

🧵 investor's guide on #DEX capital efficiency (0/30)⚖️👇 Image
1/ often people use the TVL (total value locked) metric in order to measure success of decentralized exchanges. However, this metric alone can be very misleading
2/ the goal of a #DEX is to generate volume and subsequently earn trading fees

a better DEX metric than TVL is hence capital efficiency or in different words, how well a DEX is able to maximize utilization of the available liquidity (get volume) & generate revenue on the pools
Read 34 tweets
Sep 12
0/ like #TradFi companies, #DeFi protocols should be profitable & generate more revenue than cost (token emissions), while accruing value to token holders📈

base your investment decisions on fundamental analysis!📚🔍

🧵 investor's guide on #DeFi profitability (0/45)📊👇 Image
1/ #DeFi has grown to become a multi-billion-dollar industry, consisting of a multitude of highly specialized blockchains and entire ecosystems of composable, decentralized finance protocols that are built on top of various smart contract blockchains
2/ like traditional financial services companies, these protocols provide users with a broad array of financial services. #DeFi services today range from payments and non-custodial swaps to lending & on-chain derivatives and are continuously expanding
Read 47 tweets
Sep 12
0/ by providing liquidity on a #DEX like @Uniswap, users can earn trading fees & potential liquidity mining incentives💰

however, if you plan to provide liquidity on $UNI, $SUSHI, $JOE or $BOO & co you need to know about impermanent loss(IL)⚠️

explainer-🧵 on IL (0/24)⚖️👇 Image
1/ I recently introduced AMM mechanics in detail. Before reading this thread, it might be worth checking out how AMM DEXes work:

2/ re-using the #Uniswap example, market makers that provide liquidity to @Uniswap earn 0.3% transaction fees

hence, more trading volume leads to higher profits for LPs, that earn from fees & potential liquidity mining incentives
Read 25 tweets
Sep 10
0/ stablecoin liquidity is a core element of a flourishing, decentralized financial system

let's explore the #stablecoin landscape & have a look at the largest & most innovative stablecoins out there

featuring $USDT, $DAI, $FRAX, $UXD & more

mega-🧵 on stablecoins (0/50)✨👇 Image
1/ stablecoins are #cryptocurrencies the value of which is pegged, or tied, to that of another currency, commodity or financial instrument
2/ most #stablecoins use the the U.S. dollar as their “stable” reserve asset. Stablecoins are designed to reduce volatility relative to unpegged #cryptocurrencies like Bitcoin and bridge the worlds of crypto & fiat currencies
Read 51 tweets
Sep 6
0/ a fundamental look at the state of @arbitrum, the leading optimistic #rollup L2 in the #Ethereum ecosystem!✨

🧵with @aurumcrypto research insights (0/26)👇
1/ @arbitrum has seen a 36% increase in active daily users on #arbitrum one mainnet on a month on month basis, while #ArbitrumOdyssey is still paused📈

source: @tokenterminal 📊

2/ number of active users has been steadily growing since January 2021 and growth has accelerated in recent weeks with #arbitrum one mainnet reaching >32k active daily users on September 5th

source: @tokenterminal 📊
Read 31 tweets
Sep 2
Threαd of threαds α.k.α. the ₿ook of αlphα🧙‍♂️

- DotSαmα ecosystem
- Ξthereum & ΞTH 2.0
- Scaling ΞTH on rollups
- zk-Tech (zkSync, Stαrknet & co)
- Modulαr αrchitecture (Celestiα & co)
- Guides on αirdrops
- DeFi αnαlysis
+++

Thread will be updated, so make sure to bookmark!✨
Read 35 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(