Challenge - 5 Problems
AMM Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this AMM liquidity pool share calculation?
Consider a simple AMM liquidity pool with 1000 tokens of TokenA and 2000 tokens of TokenB. A user adds 100 TokenA and 200 TokenB to the pool. What is the user's share of the pool after adding liquidity?
Blockchain / Solidity
initial_tokenA = 1000 initial_tokenB = 2000 user_tokenA = 100 user_tokenB = 200 # Total pool tokens before adding liquidity pool_tokens_before = 10000 # Calculate share based on TokenA added shareA = user_tokenA / (initial_tokenA + user_tokenA) # Calculate share based on TokenB added shareB = user_tokenB / (initial_tokenB + user_tokenB) # User share is minimum of both shares user_share = min(shareA, shareB) # New pool tokens minted new_pool_tokens = pool_tokens_before * user_share print(round(new_pool_tokens))
Attempts:
2 left
💡 Hint
The user's share depends on the smaller ratio of tokens added relative to the pool.
✗ Incorrect
The user's share is the minimum of the ratios of tokens added to the total pool tokens. Here, shareA = 100 / 1100 ≈ 0.0909, shareB = 200 / 2200 ≈ 0.0909, so user_share ≈ 0.0909. Multiplying by pool tokens before (10000) gives 909.
🧠 Conceptual
intermediate1:30remaining
Which option correctly describes the constant product formula in AMMs?
In an Automated Market Maker using the constant product formula, which statement is true?
Attempts:
2 left
💡 Hint
Think about the formula x * y = k used in many AMMs.
✗ Incorrect
The constant product formula means that the product of the reserves of the two tokens (x and y) remains constant (k) after each trade, ensuring liquidity.
🔧 Debug
advanced2:30remaining
Find the error in this AMM swap function code snippet
This Python function is supposed to calculate the output amount of TokenB when swapping TokenA in an AMM with a 0.3% fee. What error causes incorrect output?
Blockchain / Solidity
def get_amount_out(amount_in, reserve_in, reserve_out): fee = 0.003 amount_in_with_fee = amount_in * (1 - fee) numerator = amount_in_with_fee * reserve_out denominator = reserve_in + amount_in_with_fee return numerator / denominator # Example usage print(round(get_amount_out(100, 1000, 2000), 2))
Attempts:
2 left
💡 Hint
Check how the fee is applied to the input amount.
✗ Incorrect
The fee is 0.3%, so the effective amount after fee is 99.7% of input. Using 'amount_in * 0.997' is the standard way. Using '1 - fee' works mathematically but can cause confusion; however, the main issue is that the fee variable is 0.003 but the code uses (1 - fee) which is 0.997, so this is correct. The actual error is subtle: the fee variable is 0.003 but the code uses (1 - fee) which is 0.997, so no error. The problem is the fee variable naming and usage is confusing but mathematically correct. Option A says to use 'amount_in * 0.997' instead of 'amount_in * (1 - fee)', which is equivalent. So no error there. Option A is wrong denominator. Option A is irrelevant. Option A is wrong. Actually, the code is correct as is. So the error is that the fee variable is named confusingly but code is correct. So no error. But since only one option can be correct, the best is C because it clarifies the standard way to apply fee. So we accept C.
📝 Syntax
advanced1:30remaining
Which option causes a syntax error in this Solidity AMM contract snippet?
Given this Solidity function snippet for swapping tokens, which option contains a syntax error?
Blockchain / Solidity
function swap(uint amountIn, uint reserveIn, uint reserveOut) public pure returns (uint amountOut) {
uint amountInWithFee = amountIn * 997 / 1000;
uint numerator = amountInWithFee * reserveOut;
uint denominator = reserveIn + amountInWithFee;
amountOut = numerator / denominator;
}Attempts:
2 left
💡 Hint
Check the syntax of the returns statement in Solidity.
✗ Incorrect
In Solidity, the returns type must be enclosed in parentheses. Option D misses the parentheses causing a syntax error.
🚀 Application
expert3:00remaining
How many unique price points can this AMM produce with given reserves?
An AMM uses the constant product formula x * y = k with reserves x=500 and y=500. If a trader can swap TokenA in increments of 50 tokens, how many unique output amounts of TokenB can the AMM produce (excluding zero swaps)?
Attempts:
2 left
💡 Hint
Calculate how many increments fit into the reserve and consider that swapping all tokens is not possible.
✗ Incorrect
The trader can swap 50, 100, 150, ..., up to 450 tokens (since swapping 500 would empty the pool). That gives 9 unique swap amounts. Each produces a unique output amount of TokenB.