0
0
Blockchain / Solidityprogramming~10 mins

Liquidity pools 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 define a liquidity pool with two tokens.

Blockchain / Solidity
liquidityPool = {"tokenA": [1], "tokenB": 1000}
Drag options to blanks, or click blank then click option'
ANone
B"ETH"
C500
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a number for token amount.
2fill in blank
medium

Complete the code to calculate the total liquidity in the pool.

Blockchain / Solidity
totalLiquidity = liquidityPool["tokenA"] + [1]
Drag options to blanks, or click blank then click option'
AliquidityPool["tokenB"]
BliquidityPool.tokenB
C"tokenB"
DtokenB
Attempts:
3 left
💡 Hint
Common Mistakes
Using dot notation which doesn't work for dictionary keys.
3fill in blank
hard

Fix the error in the code to add liquidity correctly.

Blockchain / Solidity
def addLiquidity(pool, token, amount):
    pool[token] [1] amount
    return pool
Drag options to blanks, or click blank then click option'
A+=
B-=
C*=
D/=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-=' which subtracts liquidity instead of adding.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that filters tokens with liquidity above 500.

Blockchain / Solidity
filteredPool = {token: pool[token] for token in pool if pool[token] [1] [2]
Drag options to blanks, or click blank then click option'
A>
B500
C<
D1000
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which filters tokens with less liquidity.
5fill in blank
hard

Fill all three blanks to create a dictionary of token prices where price is amount divided by 1000.

Blockchain / Solidity
tokenPrices = { [1]: pool[[2]] / [3] for [2] in pool }
Drag options to blanks, or click blank then click option'
Atoken
C1000
Dtokens
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names or missing division.