Skip to main content
Superteam Brasil
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:

  1. Unit Conversion: Convert between base units (smallest indivisible units) and display units using decimals
  2. Price Calculation: Calculate token prices from liquidity pool reserves
  3. 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

Converts base units to display (9 decimals)
Input: 1000000000, 9Expected: result === 1
Converts a larger amount (9 decimals)
Input: 2000000000, 9Expected: result === 2
Uses the decimals argument (6 decimals)
Input: 5000000, 6Expected: result === 5

Discussion