0
0
Blockchain / Solidityprogramming~30 mins

Liquidity pools in Blockchain / Solidity - Mini Project: Build & Apply

Choose your learning style9 modes available
Liquidity Pools
📖 Scenario: You are building a simple program to understand how liquidity pools work in blockchain. Liquidity pools hold two types of tokens and allow users to swap between them. Your program will track the amounts of two tokens in the pool and calculate the price ratio.
🎯 Goal: Create a program that sets up a liquidity pool with two tokens and their amounts, defines a fee percentage, calculates the price ratio of the tokens, and prints the result.
📋 What You'll Learn
Create a dictionary called liquidity_pool with keys 'TokenA' and 'TokenB' and values 1000 and 500 respectively
Create a variable called fee_percent and set it to 0.3
Calculate the price ratio of TokenA to TokenB and store it in a variable called price_ratio
Print the price_ratio with a descriptive message
💡 Why This Matters
🌍 Real World
Liquidity pools are used in decentralized finance (DeFi) to enable token swaps without a traditional exchange.
💼 Career
Understanding liquidity pools is important for blockchain developers working on DeFi platforms and smart contracts.
Progress0 / 4 steps
1
DATA SETUP: Create the liquidity pool dictionary
Create a dictionary called liquidity_pool with these exact entries: 'TokenA': 1000 and 'TokenB': 500
Blockchain / Solidity
Need a hint?

Use curly braces to create a dictionary with keys 'TokenA' and 'TokenB' and their amounts.

2
CONFIGURATION: Define the fee percentage
Create a variable called fee_percent and set it to 0.3
Blockchain / Solidity
Need a hint?

Just assign 0.3 to the variable fee_percent.

3
CORE LOGIC: Calculate the price ratio
Calculate the price ratio of TokenA to TokenB by dividing liquidity_pool['TokenB'] by liquidity_pool['TokenA'] and store it in a variable called price_ratio
Blockchain / Solidity
Need a hint?

Divide the amount of TokenB by the amount of TokenA to get the price ratio.

4
OUTPUT: Print the price ratio
Print the price_ratio with the exact message: print(f"Price ratio of TokenB to TokenA: {price_ratio}")
Blockchain / Solidity
Need a hint?

Use an f-string to print the message with the price_ratio variable.