Consider a simple staking contract where rewards are calculated as 5% of the staked amount per epoch. What will be the total reward after 3 epochs if a user stakes 100 tokens?
def calculate_rewards(staked_amount, epochs): reward_rate = 0.05 total_reward = 0 for _ in range(epochs): total_reward += staked_amount * reward_rate return total_reward print(calculate_rewards(100, 3))
Multiply the staked amount by the reward rate for each epoch and sum it up.
The reward per epoch is 5% of 100, which is 5 tokens. Over 3 epochs, total reward is 5 * 3 = 15.0 tokens.
In blockchain staking, which mechanism ensures tokens cannot be used for other transactions while staked?
Think about what stops tokens from moving during staking.
Token Locking locks tokens so they cannot be spent or transferred, preventing double-spending during staking.
The function below is intended to calculate compounded staking rewards per epoch. What error will it cause when run?
def compounded_rewards(staked_amount, epochs, rate): total = staked_amount for _ in range(epochs): total = total + total * rate return total print(compounded_rewards(100, 3, 0.05))
Check if the formula correctly compounds the reward.
The function correctly compounds the reward each epoch: 100 * (1.05)^3 = 115.7625.
This code maps delegators to validators and sums total delegated tokens per validator. What is the output?
delegations = [
{'delegator': 'Alice', 'validator': 'Val1', 'amount': 50},
{'delegator': 'Bob', 'validator': 'Val2', 'amount': 30},
{'delegator': 'Charlie', 'validator': 'Val1', 'amount': 20},
{'delegator': 'Dave', 'validator': 'Val3', 'amount': 40}
]
validator_totals = {}
for d in delegations:
validator_totals[d['validator']] = validator_totals.get(d['validator'], 0) + d['amount']
print(validator_totals)Sum amounts for each validator key.
Val1 has 50 + 20 = 70 tokens, Val2 has 30, Val3 has 40.
Among these staking mechanisms, which one allows users to earn rewards while maintaining token liquidity?
Think about staking that lets you trade or use tokens while still earning rewards.
Liquid staking issues derivative tokens representing staked assets, allowing liquidity while securing the network.