4.9 KiB
Test Checklist for DeFi Collateral Simulation
Pre-Generation Checklist
- Python script syntax verified (no compilation errors)
- xlsxwriter installed (
pip install xlsxwriter) - Python 3.7+ available
Generation
Run:
python generate_defi_simulation.py
Expected output:
Generating DeFi_Collateral_Simulation.xlsx...
✅ Successfully generated DeFi_Collateral_Simulation.xlsx
- Assets sheet: 4 assets
- Summary sheet: Portfolio totals and HF
- Simulation sheet: 11 rounds (0-10)
- Redeploy sheet: Advanced asset-level redeploy
- Help sheet: Test cases and documentation
Verification Tests
Test 1: Baseline (Round 0)
- Open
DeFi_Collateral_Simulation.xlsx - Go to Assets sheet
- Verify default values:
- ETH: 10 @ $2,000 = $20,000
- wBTC: 1 @ $60,000 = $60,000
- stETH: 0 @ $2,000 = $0
- USDC: 5,000 @ $1 = $5,000
- All assets should have ✅ in Collateral ON/OFF
- Go to Summary sheet
- Verify:
- Total Collateral Value = $85,000
- Total Max Borrowable = $20,0000.80 + $60,0000.70 + $00.75 + $5,0000.90 = $16,000 + $42,000 + $0 + $4,500 = $62,500
- Borrowed (input) = $25,000 (default)
- Portfolio LTV = $25,000 / $85,000 = 0.2941 (29.41%)
- Health Factor = $62,500 / $25,000 = 2.50
- Status = ✅ Safe
- Go to Simulation sheet, Round 0
- Verify Round 0 matches Summary sheet values
Test 2: Swap Only (Round 1)
- In Simulation sheet, Round 1
- Enter Swap Volatile → Stable = $4,000
- Leave Repay Amount = 0
- Verify:
- Borrowed_1 = $25,000 (unchanged, no repay)
- New Collateral Value_1 = $85,000 (same total, but mix changed)
- Volatile assets (ETH, wBTC) should have reduced values pro-rata
- USDC should have increased by $4,000
- Max Borrow_1 should be recomputed from new asset mix
- HF_1 should increase (more stable collateral = higher LTV = higher Max Borrow)
Test 3: Repay Only (Round 1)
- Reset Round 1: Set Swap = 0, Repay Amount = $3,000
- Verify:
- Borrowed_1 = $25,000 - $3,000 = $22,000
- New Collateral Value_1 = $85,000 (unchanged, no swap)
- Max Borrow_1 = $62,500 (unchanged, no swap)
- HF_1 = $62,500 / $22,000 = 2.84 (increased from 2.50)
- Status = ✅ Safe
Test 4: Combined (Round 1)
- Set Repay Amount = $2,000, Swap = $3,000
- Verify:
- Borrowed_1 = $25,000 - $2,000 = $23,000
- New Collateral Value_1 = $85,000 (total unchanged, but mix changed)
- Max Borrow_1 recomputed from new asset mix (should increase due to more stable)
- HF_1 should be higher than Round 0
- LTV_1 should be lower than Round 0
Test 5: Optimizer
- In Simulation sheet, set Optimization On/Off = ✅
- Set Max Repay per Round = $3,000
- Set Max Swap per Round = $4,000
- If Round 0 HF < 2.0, check Round 1 Suggested Repay and Suggested Swap
- Verify suggestions are within caps
- Verify suggestions would bring HF_1 to approximately 2.0
Test 6: Zero Borrowed
- In Summary sheet, set Borrowed (input) = 0
- Verify:
- HF = 999 (large number)
- Status = ✅ Safe
- In Simulation sheet, verify Round 0 reflects this
Test 7: Conditional Formatting
- In Summary sheet, verify HF cell:
- Green background if HF ≥ 2
- Red background if HF < 2
- In Simulation sheet, verify HF column (G):
- Green background for all rounds with HF ≥ 2
- Red background for rounds with HF < 2
Test 8: Extensibility
- Edit
generate_defi_simulation.py - Add a new asset to
DEFAULT_ASSETS:{'name': 'USDT', 'amount': 1000, 'price': 1, 'ltv': 0.90, 'liq_th': 0.92, 'is_stable': True} - Regenerate workbook
- Verify new asset appears in all sheets
- Verify all formulas still work correctly
Known Limitations
-
Advanced Redeploy Sheet: Currently a placeholder structure. Full integration with Simulation sheet swap logic would require additional formula work.
-
Optimizer Heuristic: Uses simplified calculations. For production use, consider:
- More sophisticated optimization algorithms
- Consideration of gas costs
- Multi-round optimization (not just single-round)
-
Swap Price Impact: Currently assumes 1:1 value transfer. Real-world swaps have:
- Price impact
- Slippage
- Fees
-
Asset Amount Updates: The swap mechanics adjust values but don't automatically update the Amount column in Assets sheet. This is by design (helper block approach), but users should be aware.
Success Criteria
✅ All test cases pass ✅ Formulas calculate correctly ✅ Conditional formatting works ✅ Named ranges are accessible ✅ Workbook opens without errors in Excel/LibreOffice ✅ Round 0 matches Summary sheet ✅ Per-round recomputation works (Max Borrow changes after swaps) ✅ Optimizer provides reasonable suggestions