-
Notifications
You must be signed in to change notification settings - Fork 63
Add Reserve Fund & Protocol Revenue to Lending Contract #498
Copy link
Copy link
Open
Description
Component: Contracts (Lending) | Effort: 4-5 days | Priority: MEDIUM
Current State
No reserve fund or protocol revenue mechanism. All interest goes to depositors.
Missing Functions
Reserve fund functions:
set_reserve_factor()- Set percentage of interest for reserves (admin)get_reserve_factor()- Get current reserve factorget_reserve_balance()- Get accumulated reserveswithdraw_reserves()- Withdraw reserves (admin/treasury)get_protocol_revenue()- Get total protocol revenueallocate_reserves()- Allocate reserves to insurance fund
Why This Matters
- Sustainability: Protocol needs revenue for operations
- Insurance: Reserves can cover bad debt
- Governance: Revenue funds development and grants
- Standard practice: All lending protocols have reserve factor
Current Gap
The calculate_interest() function at line 385 doesn't split interest between depositors and protocol. All interest goes to pool.
Tasks
- Add reserve_factor storage (e.g., 10% = 1000 bp)
- Implement
set_reserve_factor()(admin only) - Add reserve_balance tracking
- Modify interest calculation to split interest
- Depositor share: interest * (1 - reserve_factor)
- Protocol share: interest * reserve_factor
- Implement
withdraw_reserves()(admin/treasury only) - Add
get_reserve_balance()view - Implement
allocate_reserves()to insurance fund - Track total protocol revenue
- Add ReserveWithdrawn, ReserveAllocated events
- Add tests for reserve calculations
- Document reserve mechanism
Acceptance Criteria
- Reserve factor configurable
- Interest split correctly
- Reserves accumulate properly
- Admin can withdraw reserves
- Tests validate calculations
- Documentation explains reserve model
Reactions are currently unavailable