--- id: TASK-2 title: Port RiskTrancheManager to Solidity status: To Do assignee: [] created_date: '2026-04-03 21:38' labels: - solidity - core - risk dependencies: - TASK-1 references: - /home/jeffe/Github/myco-bonding-curve/src/primitives/risk_tranching.py - /home/jeffe/Github/myco-bonding-curve/param_sweep_v2.csv priority: high --- ## Description Translate src/primitives/risk_tranching.py to Solidity. Core functions to implement: - deposit_collateral() — accept ERC-20 collateral into system - mint_tranche(tier, amount) — mint Senior/Mez/Junior tranche tokens - redeem_tranche(tier, amount) — burn tranche tokens, return collateral - distribute_yield(amount) — waterfall: Senior target first → Mez → Junior residual - apply_loss(amount) — reverse waterfall: Junior absorbs first → Mez → Senior - apply_collateral_change(new_total) — route gains/losses through proper waterfalls - check_liquidation() — flag tranches below min CR - rebalance_collateral() — redistribute backing across tranches Key design decisions: - Each tranche is a separate ERC-20 (myUSD-S, myUSD-M, $MYCO-J) - Fixed-point math via WAD (1e18) — no floating point - Parameter sweep results: optimal SR=1.5, MZ=1.2 for medium vol - Storage: TrancheState struct per tier, total_collateral, cumulative yield/loss tracking - Access control: only authorized contracts (bonding curve, CCIP receiver) can call state-changing functions ## Acceptance Criteria - [ ] #1 Senior/Mez/Junior tranche minting respects collateral ratios - [ ] #2 Yield waterfall distributes Senior-first correctly - [ ] #3 Loss absorption follows Junior-first correctly - [ ] #4 Liquidation flags trigger at correct CR thresholds - [ ] #5 100+ Foundry fuzz tests pass - [ ] #6 Gas benchmarks documented