Complete the code to define a function that returns the annual percentage yield (APY) given a simple interest rate.
function calculateAPY(rate) {
return (1 + [1]) ** 1 - 1;
}The interest rate must be converted from a percentage to a decimal by dividing by 100 before calculating APY.
Complete the code to calculate the total rewards earned by multiplying staked tokens by the reward rate.
function calculateRewards(stakedTokens, rewardRate) {
return stakedTokens [1] rewardRate;
}Rewards are calculated by multiplying the amount staked by the reward rate.
Fix the error in the code that calculates compounded yield over multiple periods.
function compoundedYield(principal, rate, periods) {
return principal * (1 + [1]) ** periods;
}The rate must be converted from a percentage to a decimal by dividing by 100 before compounding.
Fill both blanks to create a filtered object that maps token names to their staked amounts if the amount is greater than zero.
const stakedTokens = Object.fromEntries(Object.entries(tokens).filter(([[1], [2]]) => [2] > 0 ));
The object maps each token name to its staked amount, filtering only positive amounts.
Fill all three blanks to create a function that returns a filtered object of tokens with APY greater than a threshold.
function filterHighAPY(tokens, threshold) {
return Object.fromEntries(Object.entries(tokens).filter(([[1], [2]]) => [3] > threshold));
}The function filters tokens by checking if their APY is greater than the threshold.