Back
+40 XP
11/12
DeFi Vault Simulator
Build a simplified DeFi vault that tracks deposits, shares, and exchange rates.
Your vault accepts deposits of an underlying token and mints vault shares. As the vault generates yield, the exchange rate between shares and underlying increases. Users can redeem shares for their proportional amount of underlying assets.
Key concepts:
- Track total underlying assets and total shares issued
- Calculate exchange rate when depositing and withdrawing
- Ensure the first depositor doesn't get unfair advantages
This is the core mechanic behind yield aggregators like Francium and Tulip Protocol.
Test Cases
First deposit of 100 should return 100 shares
Input:
'alice', 100Expected: typeof result === 'number' && result === 100Deposit should return positive share amount
Input:
'alice', 200Expected: typeof result === 'number' && result > 0