feat(treasury): implement Treasury Management Module (SC-012) - #419
Open
VeronicDev wants to merge 2 commits into
Open
feat(treasury): implement Treasury Management Module (SC-012)#419VeronicDev wants to merge 2 commits into
VeronicDev wants to merge 2 commits into
Conversation
Implement the V2 Treasury Management Module as the single source of truth for all protocol-owned assets. The treasury manages seven independent reserve pools with deterministic accounting, role-based access control, governance controls, and emergency pause mechanisms. Key changes: - Add ITreasuryManagement interface and TreasuryManagement contract with seven reserve pools (staking, rewards, slashing, fees, governance, ecosystem, emergency) - Implement deposit, withdrawal, internal transfer, and emergency functions with full event emission and record tracking - Add per-block and percentage-based withdrawal limits - Add governance-controlled parameter updates and emergency pause/unpause - Add MockTreasuryManagement for downstream module testing - Add comprehensive test suite (74 tests covering deposits, withdrawals, slashing, transfers, governance, emergency controls, invariants, records, snapshots, security, and gas benchmarks) Bug fixes: - Fix recordSlashDeposit missing totalWithdrawn update on staking reserve - Fix depositToPool wrong fromPool in record creation - Complete per-block withdrawal tracking implementation - Fix _findEmergencySource unreliable fallback logic - Fix hardcoded toPool in withdrawal records Pre-existing compilation fixes: - Add virtual to GovernanceOwnable.emergencyUnpause() for override support - Fix ClaimRegistry bytes32/uint256 error type mismatch - Fix TimelockOwnedProxyAdmin OZ v5 ProxyAdmin constructor/override issues - Replace @deprecated NatSpec tags (invalid for functions in 0.8.28) 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SC-012 — Treasury Management Module
Summary
Implements the V2 Treasury Management Module as the single source of truth for all protocol-owned assets. The treasury manages seven independent reserve pools with deterministic accounting, role-based access control, governance controls, and emergency pause mechanisms.
What Changed
Core Contracts:
contracts/treasury/ITreasuryManagement.sol— V2 Treasury Management interfacecontracts/treasury/TreasuryManagement.sol— V2 Treasury Management implementation (918 lines)contracts/mocks/MockTreasuryManagement.sol— Lightweight mock for downstream module testingTests:
test/TreasuryManagement.test.ts— 74 comprehensive test cases, all passingArchitecture
Seven independent reserve pools, each fully auditable on-chain:
Invariant: `sum(poolBalances) == protocolToken.balanceOf(treasury)`
Security
Bug Fixes
Pre-existing Compilation Fixes
Fixed compilation errors in other files to enable full project compilation:
Test Coverage
Gas Benchmarks
Closes #292