1/5
## Mint pool shares In this lesson, we'll cover a common problem faced when working with Uniswap V2 liquidity pools: how to calculate the number of shares to mint for a new liquidity provider. We'll imagine a simple smart contract that accepts a single token (let's say USDC). This smart contract can invest the USDC to earn yield, lend it out to other users, or perform other functions. The key point is that the USDC balance within the contract will likely fluctuate over time. Our goal is to understand how to determine the correct number of shares to mint for a new liquidity provider, given the current USDC balance and the total number of shares already in existence. Let's start with a concrete example: **Example:** * **User 1:** Deposits $300 USDC and receives 300 shares. * **User 2:** Deposits $500 USDC and receives 500 shares. * **User 3:** Deposits $200 USDC and receives 200 shares. At this point, the pool holds a total of $1000 USDC and has minted 1000 shares. This means that each share is currently worth $1. **The Problem:** Now, let's say the smart contract has earned some yield, and the USDC balance has increased to $1100. **A new user (User 4) comes along and deposits $110 USDC. How many shares should the smart contract mint for them?** **The Solution:** The answer lies in a simple equation: ``` s = (L1 - L0) / T ``` Where: * **s:** The number of shares to mint for the new user * **L1:** The total USDC balance in the pool **after** the new deposit * **L0:** The total USDC balance in the pool **before** the new deposit * **T:** The total number of shares currently outstanding **Applying the Equation:** In our example: * **L1:** $1210 * **L0:** $1100 * **T:** 1000 Therefore: ``` s = (1210 - 1100) / 1000 s = 110 / 1000 s = 0.11 ``` The smart contract should mint **0.11 shares** for User 4. **Important Note:** This simple scenario illustrates the core concept. In a real-world Uniswap V2 pool, the calculation is similar, but it involves two tokens (e.g., ETH and USDC). The underlying logic, however, remains the same.
A simple explanation of how Uniswap V2 mints pool shares - This lesson helps understand how Uniswap V2 works, specifically in the context of how a pool mints shares when users deposit tokens. It illustrates how the pool uses a simple equation to determine how many shares to mint based on the existing token pool and the tokens a user deposits.
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