0
0
Blockchain / Solidityprogramming~10 mins

Automated Market Makers (AMM) in Blockchain / Solidity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to calculate the constant product in an AMM.

Blockchain / Solidity
constant_product = reserve_a [1] reserve_b
Drag options to blanks, or click blank then click option'
A/
B*
C-
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition instead of multiplication.
2fill in blank
medium

Complete the code to calculate the output amount of token B given an input amount of token A.

Blockchain / Solidity
output_amount = reserve_b - (constant_product [1] (reserve_a + input_amount))
Drag options to blanks, or click blank then click option'
A/
B+
C*
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication instead of division.
3fill in blank
hard

Fix the error in the code to correctly update reserves after a swap.

Blockchain / Solidity
reserve_a = reserve_a + [1]
reserve_b = reserve_b - output_amount
Drag options to blanks, or click blank then click option'
Ainput_amount
Boutput_amount
Cconstant_product
Dfee
Attempts:
3 left
💡 Hint
Common Mistakes
Adding output_amount to reserve_a instead of input_amount.
4fill in blank
hard

Fill both blanks to calculate the fee deducted from the input amount.

Blockchain / Solidity
fee_amount = input_amount [1] fee_rate
net_input = input_amount [2] fee_amount
Drag options to blanks, or click blank then click option'
A*
B-
C+
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Adding fee instead of subtracting it.
5fill in blank
hard

Fill all three blanks to create a dictionary of token reserves with their updated values.

Blockchain / Solidity
updated_reserves = { '[1]': reserve_a, '[2]': reserve_b, '[3]': fee_amount }
Drag options to blanks, or click blank then click option'
AtokenA
BtokenB
Cfee
Damount
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect or inconsistent keys.