0
0
Blockchain / Solidityprogramming~10 mins

Yield farming concepts 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 function that returns the annual percentage yield (APY) given a simple interest rate.

Blockchain / Solidity
function calculateAPY(rate) {
  return (1 + [1]) ** 1 - 1;
}
Drag options to blanks, or click blank then click option'
Arate
Brate * 100
Crate / 100
Drate + 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using the rate directly without dividing by 100 causes wrong APY calculation.
2fill in blank
medium

Complete the code to calculate the total rewards earned by multiplying staked tokens by the reward rate.

Blockchain / Solidity
function calculateRewards(stakedTokens, rewardRate) {
  return stakedTokens [1] rewardRate;
}
Drag options to blanks, or click blank then click option'
A/
B+
C-
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition or subtraction instead of multiplication.
3fill in blank
hard

Fix the error in the code that calculates compounded yield over multiple periods.

Blockchain / Solidity
function compoundedYield(principal, rate, periods) {
  return principal * (1 + [1]) ** periods;
}
Drag options to blanks, or click blank then click option'
Arate / 100
Brate * 100
Crate + 1
Drate - 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using the rate directly without conversion causes incorrect yield.
4fill in blank
hard

Fill both blanks to create a filtered object that maps token names to their staked amounts if the amount is greater than zero.

Blockchain / Solidity
const stakedTokens = Object.fromEntries(Object.entries(tokens).filter(([[1], [2]]) => [2] > 0 ));
Drag options to blanks, or click blank then click option'
Atoken
Bamount
Ctokens
Dtoken.toUpperCase()
Attempts:
3 left
💡 Hint
Common Mistakes
Using the whole tokens object as key or value.
5fill in blank
hard

Fill all three blanks to create a function that returns a filtered object of tokens with APY greater than a threshold.

Blockchain / Solidity
function filterHighAPY(tokens, threshold) {
  return Object.fromEntries(Object.entries(tokens).filter(([[1], [2]]) => [3] > threshold));
}
Drag options to blanks, or click blank then click option'
Atoken
Bapy
Camount
Drate
Attempts:
3 left
💡 Hint
Common Mistakes
Using amount or rate instead of apy for filtering.