Skip to content

Dynamic Parameter Management (Issue #88)#171

Merged
greatest0fallt1me merged 3 commits into
Predictify-org:masterfrom
ikemHood:feat-config
Sep 27, 2025
Merged

Dynamic Parameter Management (Issue #88)#171
greatest0fallt1me merged 3 commits into
Predictify-org:masterfrom
ikemHood:feat-config

Conversation

@ikemHood

Copy link
Copy Markdown
Contributor

📋 Basic Information

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 📚 Documentation update
  • 🧪 Test addition/update

Related Issues

Closes #88

Priority Level

  • 🟢 Medium

📝 Detailed Description

What does this PR do?

  • Implements a dynamic, admin-governed configuration system for the Predictify Hybrid contract.
  • Adds a centralized ConfigManager providing:
    • Environment presets and storage helpers: store_config(), get_config(), update_config(), reset_to_defaults().
    • Read-only entrypoints: get_current_configuration(), get_configuration_history().
    • Validation-only bulk check: validate_configuration_changes(changes: ConfigChanges).
    • Admin update operations (gated by AdminAccessControl):
      • update_fee_percentage(admin, new_fee: i128)
      • update_dispute_threshold(admin, new_threshold: i128)
      • update_oracle_timeout(admin, timeout_seconds: u32)
      • update_market_limits(admin, limits: MarketLimits)
    • Configuration update audit trail via ConfigUpdateRecord with history capped at 100, persisted under ConfigHistory and events via EventEmitter::emit_config_updated.
  • Exposes contract entrypoints in contracts/predictify-hybrid/src/lib.rs:
    • get_current_configuration()
    • get_configuration_history()
    • validate_configuration_changes()
    • update_fee_percentage()
    • update_dispute_threshold()
    • update_oracle_timeout()
    • update_market_limits()
  • Integrates dynamic config across subsystems:
    • fees.rs: fee calculation/collection pull dynamic params via ConfigManager::get_config().
    • markets.rs: validations use dynamic MarketConfig via ConfigManager::get_config().
    • Governance enforced by admin.rs using AdminAccessControl::validate_admin_for_action() with action strings update_fees and update_config.

Key files and symbols:

  • contracts/predictify-hybrid/src/config.rs
    • Types: ContractConfig, FeeConfig, VotingConfig, MarketConfig, ExtensionConfig, ResolutionConfig, OracleConfig
    • Manager: ConfigManager::{get_*_config, store_config, get_config, update_config, reset_to_defaults, get_current_configuration, get_configuration_history, validate_configuration_changes, update_fee_percentage, update_dispute_threshold, update_oracle_timeout, update_market_limits}
    • Validator: ConfigValidator::{validate_contract_config, validate_fee_config, validate_voting_config, validate_market_config, validate_extension_config, validate_resolution_config, validate_oracle_config}
    • API types: MarketLimits, ConfigChanges, ConfigUpdateRecord
  • contracts/predictify-hybrid/src/lib.rs
    • Public configuration entrypoints listed above
    • Modified initialization to support baseline config storage:
      • New initialize_with_config(env, admin, environment)
      • Updated initialize(env, admin, environment) that delegates to initialize_with_config
  • contracts/predictify-hybrid/src/fees.rs: dynamic fee usage
  • contracts/predictify-hybrid/src/markets.rs: dynamic market validation
  • contracts/predictify-hybrid/src/admin.rs: admin gating for config updates

Why is this change needed?

  • Enables runtime adjustment of fees, dispute thresholds, oracle timeouts, and market limits without redeployments.
  • Adds configuration validation and governance.
  • Provides persistent configuration history and emitted events for auditability.

How was this tested?

  • Unit tests added/updated in config.rs:
    • test_config_manager_default_configs
    • test_config_validator
    • test_config_utils
    • test_config_storage
    • test_config_testing
    • test_configuration_constants
  • These cover environment presets, config validation, utilities, storage round-trip, minimal/custom configs, constant expectations.

Alternative Solutions Considered

  • Directly storing each parameter in storage. Rejected in favor of typed ContractConfig with centralized validation.
  • Compile-time constants only. Rejected; lacks runtime flexibility.

🏗️ Smart Contract Specific

Contract Changes

  • Core contract logic modified
  • New functions added
  • Existing functions modified
  • Storage structure changes (adds ContractConfig, ConfigHistory)
  • Access control changes (uses AdminAccessControl::validate_admin_for_action)
  • Admin functions modified

Oracle Integration

  • Oracle configuration changes (timeouts/retries/freshness in OracleConfig)

Market Resolution Logic

  • Fee structure updated (dynamic fee percentage)

Security Considerations

  • Access control reviewed
  • Input validation
  • Overflow/underflow protection via bounded validators and ranges

🧪 Testing

Screenshot 2025-09-27 at 3 35 54 PM

Test Coverage

  • Unit tests added/updated
  • Edge cases covered (invalid ranges, zero values)
  • Error conditions tested

Test Results

# Paste concrete output after local/CI run
cargo test

Manual Testing Steps

  1. Deploy contract.
  2. Call PredictifyHybrid::initialize(env, admin, Environment::<choice>).
  3. Verify get_current_configuration() works.
  4. Call validate_configuration_changes() with a ConfigChanges subset.
  5. Apply updates:
    • update_fee_percentage(admin, X)
    • update_dispute_threshold(admin, Y)
    • update_oracle_timeout(admin, Z)
    • update_market_limits(admin, limits)
  6. Confirm events and get_configuration_history() reflect changes.

📚 Documentation

Documentation Updates

  • Code comments added/updated

Breaking Changes

None.

Migration note: Ensure a baseline ContractConfig is stored at initialization via the new initialize signature or initialize_with_config.


🔍 Code Quality

Code Review Checklist

  • Follows Rust/Soroban best practices
  • Self-review completed
  • No unnecessary code duplication
  • Appropriate error handling
  • Events for config updates
  • Security considerations addressed
  • Performance considered
  • Readable and well-commented

Performance Impact

  • Gas: Minimal; bounded history Vec (max 100).
  • Storage: Adds ContractConfig and ConfigHistory keys.
  • Complexity: O(1) typical ops; O(n) up to n=100 for history maintenance.

Security Review

  • Access controls enforced
  • Input validation present
  • No sensitive data exposed

🚀 Deployment & Integration

Deployment Notes

  • Network: Testnet or Mainnet
  • Migration: None; use new initialization to set baseline configuration.
  • Special: Ensure admin selection and environment choice are correct.

Integration Points

  • Frontend can read/validate/update config via entrypoints
  • Backward compatibility maintained (feature additive; relies on stored config)

📊 Impact Assessment

User Impact

  • End Users: Tunable fees/timeouts/limits without redeployments; better governance.
  • Developers: Centralized, type-safe configuration with validators and history.
  • Admins: Permission-gated updates with audit trail and events.

Business Impact

  • Revenue: Tunable platform fees.
  • User Experience: Faster changes without downtime.
  • Technical Debt: Reduced by centralizing config logic.

✅ Final Checklist

Pre-Submission

  • Code follows Rust/Soroban best practices
  • No breaking changes (or documented)
  • Ready for review
  • PR description complete and accurate

💬 Notes for Reviewers

Screenshot 2025-09-27 at 3 37 43 PM

@greatest0fallt1me

Copy link
Copy Markdown
Contributor

It looks good to me @ikemHood

@greatest0fallt1me greatest0fallt1me merged commit 8807a57 into Predictify-org:master Sep 27, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create Configurable System for Dynamic Parameter Management

2 participants