1/5
## Mint pool shares When a user adds liquidity to a Uniswap V2 pool, they receive pool shares that represent their ownership of the liquidity. The amount of pool shares they receive is proportional to the value of the liquidity they contribute. To calculate the amount of pool shares that a user will receive when they add liquidity, we use the following equation: ``` S = (L1 - L0) / L0 * T ``` Where: * **S** is the amount of shares to mint * **L0** is the value of the pool before the user adds liquidity * **L1** is the value of the pool after the user adds liquidity * **T** is the total number of pool shares outstanding Let's break down this equation. ### Math We'll start by defining our variables. * **T** = total shares * **S** = shares to mint * **L0** = value of the pool before the user adds liquidity * **L1** = value of the pool after the user adds liquidity We can then express the increase in the pool's value as: ``` L1 / L0 ``` This tells us how much the pool's value increased after the user added liquidity. We can then say that the shares to mint are proportional to this increase, as follows: ``` T + S / T = L1 / L0 ``` In this equation, we are expressing the increase in shares. Before the user added liquidity, there were *T* total shares. After the user adds liquidity, the total shares are *T + S*. We are saying that the ratio of these two values is proportional to the increase in the pool's value. We can solve this equation for *S*, the amount of shares to mint: ```bash T + S / T = L1 / L0 ``` ```bash T + S = L1 / L0 * T ``` ```bash S = L1 / L0 * T - T ``` ```bash S = (L1 - L0) / L0 * T ``` Therefore, the equation we use to calculate the amount of shares to mint is: ``` S = (L1 - L0) / L0 * T ``` When we apply this equation to a practical example, we'll see that the user receives shares in proportion to the liquidity they contribute. This means the user's ownership of the pool accurately reflects their contribution.
A simple equation to calculate mint pool shares - The lesson covers how to calculate the number of shares to mint for a user who deposits USDC into a Uniswap v2 pair contract. The lesson defines the variables used in the equation, derives the equation, and explains how to use the equation to solve for the number of shares to mint.
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