0/5
## Defining Pool Value We're going to cover how we can define the value of a pool. We can do this in a couple of ways, we're going to cover both. The first way we can define the value of the pool is to say that the function _F_ which takes in the amount of tokens in the pool _X_ and _Y_ is equal to twice the amount of _X_ in the pool. ``` F(X, Y) = 2 * X = Value of pool in token X ``` This is just one way to define it. We could do it as twice _Y_ as well. The other way to define the value of the pool is to say that the function _F_ which takes in the amount of tokens in the pool _X_ and _Y_ is equal to twice the amount of _X_ in the pool. We are trying to measure the amount of token _X_ in the AMM and the amount of token _Y_ in the pool when we convert it into terms of token _X_. For example, let's say that we have an AMM with 6 million DAI and 3,000 ETH. We'll measure the value of this pool in terms of DAI by first saying _X0_ , which is the amount of DAI in the pool, plus _Y0_. _Y0_ is the amount of ETH in the pool. So we'll somehow need to convert this number in terms of DAI. ``` Motivation X0 = 6,000,000 DAI Y0 = 3000 ETH F(X0, Y0) = X0 + Y0 ``` We call this the *spot price of Y in terms of X*. This is equal to _Y_ divided by _X_. ``` X/Y = Spot price of Y in terms of X ``` So if we flip this around, _X_ divided by _Y_ would be the spot price of token _Y_ in terms of token _X_. Now we can use this to convert this _Y0_ in terms of token _X_. We multiply _Y0_ by the spot price of _Y0_. ``` F(X0, Y0) = X0 + Y0 * (X0/Y0) ``` The _Y0_ on the top and the _Y0_ on the bottom cancel out, and this turns out to be 2 times _X0_. ``` F(X0, Y0) = X0 + Y0 * (X0/Y0) = 2 * X0 ``` So this is the motivation for saying that _F_ of _X_ and _Y_ is equal to 2_X_. We are measuring the value of this AMM in terms of token _X_. The first term simply comes from the amount of token _X_ that is inside the pool. And the second term comes from converting the amount of token _Y_ in terms of token _X_. Let's go over an example. _X0_ is 6 million DAI and _Y0_ is 3,000 ETH. ``` F(X0, Y0) = X0 + Y0 * (X0/Y0) = 2 * X0 = 6,000,000 DAI + 6,000,000 DAI/3000 ETH * 3000 ETH = 12,000,000 DAI ``` Next, using this definition as the value of the pool, let's calculate _L1_ minus _L0_ over _L0_. ``` L1-L0 / L0 = ``` Let's start with _L1_. Again, _L1_ will be the value of the pool after adding liquidity. After adding _dX_ and _dY_ amounts of tokens, by definition this is equal to _F_ of _X0_ plus _dX_ , _Y0_ plus _dY_. ``` L1-L0 / L0 = F(X0 + dX, Y0 + dY) - F(X0, Y0) / F(X0, Y0) ``` _L0_ is liquidity before adding liquidity. This is simply _F_ of _X0_ and _Y0_. ``` L1-L0 / L0 = F(X0 + dX, Y0 + dY) - F(X0, Y0) / F(X0, Y0) = 2 * (X0 + dX) - 2 * X0 / 2 * X0 ``` The 2s cancel out and the _X0_ on the top cancel out, and we are left with _dX_ divided by _X0_. ``` L1-L0 / L0 = F(X0 + dX, Y0 + dY) - F(X0, Y0) / F(X0, Y0) = 2 * (X0 + dX) - 2 * X0 / 2 * X0 = dX/X0 ``` So this shows that when we define the pool value function as 2_X_, then _L1_ minus _L0_ divided by _L0_ is equal to _dX_ divided by _X0_. Now we can do something similar and define _F_ of _X_ and _Y_ to be 2 times _Y_. And we will get that _L1_ minus _L0_ over _L0_ is equal to _dY_ divided by _Y0_. ``` F(X, Y) = 2 * Y = Value of pool in token X ```
An advanced guide to liquidity impermanent loss - This lesson covers two approaches to calculating liquidity impermanent loss. First, the lesson uses a function that takes in the amounts of each token in the pool and returns a value based on one of the tokens in the pool. Next, the lesson goes over a method of calculating the difference in liquidity before and after adding liquidity to a pool by using the function defined in the first part of the lesson.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
How to use Uniswap v2 dex and contracts
Interacting with the Uniswap v2 router and factory
How to create Uniswap v2 liquidity pools
How to add liquidity to Uniswap v2 pools
Swaps, flash swaps, flash swap arbitrage, and time-weighted average price (TWAP)
Security researcher
$49,999 - $120,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on October 9, 2024
Solidity Developer
Uniswap V2Duration: 14min
Duration: 1h 20min
Duration: 10min
Duration: 54min
Duration: 25min
Duration: 26min
Duration: 1h 03min
Duration: 59min
Course Overview
About the course
How to use Uniswap v2 dex and contracts
Interacting with the Uniswap v2 router and factory
How to create Uniswap v2 liquidity pools
How to add liquidity to Uniswap v2 pools
Swaps, flash swaps, flash swap arbitrage, and time-weighted average price (TWAP)
Security researcher
$49,999 - $120,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on October 9, 2024
Testimonials
Read what our students have to say about this course.
Chainlink
Chainlink
Gustavo Gonzalez
Solutions Engineer at OpenZeppelin
Francesco Andreoli
Lead Devrel at Metamask
Albert Hu
DeForm Founding Engineer
Radek
Senior Developer Advocate at Ceramic
Boidushya
WalletConnect
Idris
Developer Relations Engineer at Axelar