1/5
### Exercise In this lesson, we'll explore how to extract the spot price from a Uniswap V3 pool contract. We will be using the USDC-WETH pool as our example. Our objective is to determine the price of WETH in terms of USDC, with the result formatted to 18 decimal places. To accomplish this, we will leverage the `FullMath` library, and more specifically, its `mulDiv` function. This function is essential for preventing overflow when multiplying and dividing `uint256` numbers. The function will allow us to safely perform the calculation when multiplying `sqrtPriceX96` with `sqrtPriceX96` Below is a code snippet demonstrating the function signature of our test function. ```javascript function test_spot_price_from_sqrtPriceX96() public { uint256 price = 0; IUniswapV3Pool.Slot0 memory slot0 = pool.slot0(); ``` This is where we'll add our logic for calculating the spot price. Be sure to maintain the existing comments and refrain from altering any other code in the function. Good Luck!
A beginner's guide to calculating spot prices from a Uniswap V3 pool contract. The lesson covers the basics of Uniswap V3 pool functions, including obtaining reserve values, and the use of the FullMath.mulDiv library for calculating spot price.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Concentrated liquidity and derive its equations
Uniswap V3 math
How to calculate the spot price of tokens
Single and multi position swapping
Factory contract architecture
How to calculate liquidity requirements
Uniswap V3 fee algorithm
Flash loans
TWAP price oracle
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Blockchain Financial Analyst
$100,000 - $150,000 (avg. salary)
DeFi Developer
$75,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 May 15, 2025
DeFi Developer
Uniswap V3Duration: 3min
Duration: 35min
Duration: 25min
Duration: 22min
Duration: 1h 43min
Duration: 11min
Duration: 1h 03min
Duration: 12min
Duration: 51min
Duration: 41min
Duration: 10min
Duration: 7min
Course Overview
About the course
Concentrated liquidity and derive its equations
Uniswap V3 math
How to calculate the spot price of tokens
Single and multi position swapping
Factory contract architecture
How to calculate liquidity requirements
Uniswap V3 fee algorithm
Flash loans
TWAP price oracle
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Blockchain Financial Analyst
$100,000 - $150,000 (avg. salary)
DeFi Developer
$75,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 May 15, 2025