Add timelock mechanism for risk configuration updates#261
Open
pashap9990 wants to merge 1 commit intostader-labs:mainfrom
Open
Add timelock mechanism for risk configuration updates#261pashap9990 wants to merge 1 commit intostader-labs:mainfrom
pashap9990 wants to merge 1 commit intostader-labs:mainfrom
Conversation
Implements a 1-day timelock for updating risk configuration parameters to enhance security and provide time for review before changes take effect. Changes: - Split risk config updates into queueRiskConfig and applyRiskConfig functions - Added RISK_CONFIG_APPLY constant (1 day delay) - Added pendingRiskConfig and riskConfigProposeTime state variables - Added cancelQueuedRiskConfig function for emergency cancellations - Added RiskConfigQueued and RiskConfigCancelled events - Fixed emit bug in _updateRiskConfig to use actual parameters - Added validation to prevent applying config before timelock period - Reset timelock after applying to prevent replay - Updated tests with additional coverage for cancellation
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.
Add Timelock Mechanism for Risk Configuration Updates
🎯 Motivation
The
SDUtilityPoolcontract manages critical risk parameters (RiskConfig) that directly impact:Currently, these parameters can be updated instantly by the admin role. While this provides flexibility, it introduces potential risks:
💡 Solution: Two-Step Timelock Pattern
This PR implements a battle-tested governance pattern used by major DeFi protocols (Compound, Uniswap, Aave) to add a mandatory delay between proposing and applying risk configuration changes.
🔧 Technical Changes
New Functions
queueRiskConfig()- Proposes new risk parameters with validationRiskConfigQueuedevent for transparencyapplyRiskConfig()- Applies queued configuration after timelockcancelQueuedRiskConfig()- Emergency cancellationConstants
RISK_CONFIG_APPLY = 1 days- Timelock delay periodState Variables
pendingRiskConfig- Stores queued configurationriskConfigProposeTime- Tracks when configuration was proposedEvents
RiskConfigQueued- Emitted when new config is proposedRiskConfigCancelled- Emitted when pending config is cancelled🔐 Security Improvements
📊 Impact Assessment
Gas Costs
Breaking Changes
updateRiskConfig()function removedqueueRiskConfig()thenapplyRiskConfig()after 1 dayBackward Compatibility
🧪 Testing
Added comprehensive test coverage:
test_UpdateRiskConfig()- Validates full queue → wait → apply flowtest_CancelQueuedRiskConfig()- Validates cancellation mechanismAll tests passing:
📖 Usage Example
🎯 Benefits
🔄 Alignment with Industry Standards
This pattern is considered best practice in DeFi:
📝 Files Changed
contracts/SDUtilityPool.sol- Core implementationcontracts/interfaces/ISDUtilityPool.sol- Interface updates with new eventstest/foundry_tests/SDUtilityPool.t.sol- Test coverage🚀 Deployment Notes
When deploying this upgrade:
RiskConfigQueuedevents🔍 Security Considerations
Related Issues: N/A
Type: Enhancement - Security & Governance
Breaking Change: Yes (admin scripts need updates)
Requires Documentation Update: Yes