Challenge - 5 Problems
DeFi Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Solidity function for DeFi interest calculation?
Consider this Solidity function that calculates simple interest for a DeFi lending protocol. What is the output when principal = 1000, rate = 5, and time = 2?
Blockchain / Solidity
function calculateInterest(uint principal, uint rate, uint time) public pure returns (uint) {
return (principal * rate * time) / 100;
}
// Inputs: principal=1000, rate=5, time=2Attempts:
2 left
💡 Hint
Remember simple interest formula: (P * R * T) / 100
✗ Incorrect
The function returns (1000 * 5 * 2) / 100 = 10000 / 100 = 100.
🧠 Conceptual
intermediate1:30remaining
Which feature of DeFi removes the need for traditional banks?
DeFi uses blockchain technology to replace traditional financial intermediaries. Which feature best explains this?
Attempts:
2 left
💡 Hint
Think about how trust is managed without banks.
✗ Incorrect
Smart contracts automate transactions without needing banks or middlemen, enabling trustless finance.
🔧 Debug
advanced2:30remaining
What error does this Solidity code produce when deploying a DeFi token?
This Solidity snippet tries to create a token but has a bug. What error will the compiler show?
Blockchain / Solidity
contract Token {
string public name = "DeFiToken";
uint public totalSupply = 1000;
mapping(address => uint) balances;
constructor() public {
balances[msg.sender] = totalSupply;
}
}Attempts:
2 left
💡 Hint
Check how constructors are declared in recent Solidity versions.
✗ Incorrect
Since Solidity 0.7.0, constructors must use the 'constructor' keyword, not the contract name.
📝 Syntax
advanced2:00remaining
Which JavaScript snippet correctly interacts with a DeFi smart contract using ethers.js?
You want to call the 'balanceOf' function on a DeFi token contract. Which code snippet is correct?
Blockchain / Solidity
const contractAddress = '0x123...'; const abi = ["function balanceOf(address) view returns (uint)"]; const provider = new ethers.providers.JsonRpcProvider(); const contract = new ethers.Contract(contractAddress, abi, provider); const address = '0xabc...';
Attempts:
2 left
💡 Hint
Remember that contract calls returning promises need 'await'.
✗ Incorrect
Option D correctly awaits the promise and converts the BigNumber to string for display.
🚀 Application
expert3:00remaining
How many unique liquidity pools are created by this Uniswap-like pair factory code?
Given this simplified factory code snippet that creates liquidity pools for token pairs, how many unique pools exist after these calls?
factory.createPair('TokenA', 'TokenB');
factory.createPair('TokenB', 'TokenA');
factory.createPair('TokenA', 'TokenC');
factory.createPair('TokenC', 'TokenA');
factory.createPair('TokenB', 'TokenC');
Blockchain / Solidity
class Factory { constructor() { this.pairs = new Set(); } createPair(token1, token2) { const sorted = [token1, token2].sort(); const key = sorted.join('-'); this.pairs.add(key); } getPairCount() { return this.pairs.size; } } const factory = new Factory(); factory.createPair('TokenA', 'TokenB'); factory.createPair('TokenB', 'TokenA'); factory.createPair('TokenA', 'TokenC'); factory.createPair('TokenC', 'TokenA'); factory.createPair('TokenB', 'TokenC'); const count = factory.getPairCount();
Attempts:
2 left
💡 Hint
Pairs with tokens in different order count as the same pool.
✗ Incorrect
Pairs are sorted before adding, so 'TokenA-TokenB' and 'TokenB-TokenA' are the same. Unique pairs are: A-B, A-C, B-C → 3 pools.