Back
+40 XP
6/12
Token Math Challenge
Master the essential mathematical operations for working with SPL tokens on Solana.
In this challenge, you'll implement three critical token math functions:
- Unit Conversion: Convert between base units (smallest indivisible units) and display units using decimals
- Price Calculation: Calculate token prices from liquidity pool reserves
- LP Share Calculation: Compute a user's percentage share of a liquidity pool
These calculations are fundamental to every DeFi protocol. Understanding token math ensures you handle user funds correctly and display accurate information.
Test Cases
1000000000 base units with 9 decimals = 1 display unit
Input:
1000000000, 9Expected: result === 12000000000 base units with 9 decimals = 2 display units
Input:
2000000000, 9Expected: result === 2