Code quality, backup, external APIs, and cross-chain improvements - #125
Merged
LaGodxy merged 6 commits intoMar 26, 2026
Merged
Conversation
Create centralized constants module (contracts/traits/src/constants.rs) with documented named constants for all magic numbers: Oracle: DEFAULT_MAX_PRICE_STALENESS (3600s), DEFAULT_MIN_SOURCES_REQUIRED (2), DEFAULT_OUTLIER_THRESHOLD (2), reputation scores (500/1000/200/10/50) Bridge: DEFAULT_GAS_MULTIPLIER (100), DEFAULT_CONFIRMATION_BLOCKS (6), BRIDGE_BASE_GAS (100000) IPFS: MAX_LOCATION_LENGTH (500), MAX_FILE_SIZE (100MB), etc. Token: TOKEN_SCALING_FACTOR (1e12) Analytics: BASIS_POINTS_DENOMINATOR (10000) Replace inline magic numbers in oracle and bridge constructors with constant references. Closes MettaChain#102
Add scripts/backup.sh: - Timestamped backups of contracts, deployments, and config - SHA-256 checksums for integrity verification - Automatic rotation (keeps last 30 backups) - Redacts sensitive .env values in backups - Cron-compatible for 6-hour scheduling Add docs/DISASTER_RECOVERY.md: - Backup strategy and schedule - Step-by-step recovery for contracts, config, bridge, oracle - Data integrity verification procedure - Severity-based escalation matrix Closes MettaChain#106
Replace stub oracle source implementations with structured integration: - Chainlink, Pyth, Substrate, Custom sources delegate to fetch_from_external_endpoint() which will make cross-contract calls to oracle adapter contracts (TODO: wire actual adapters) - Manual source reads from valuation_history with freshness check - Fallback: if primary source fails, attempt manual price before error - Add get_latest_manual_price() helper for history lookup - Add fetch_from_external_endpoint() with documented adapter pattern This unblocks oracle functionality by providing a working fallback path through manual prices while external adapters are deployed. Closes MettaChain#109
Add tests/bridge_tests.rs with 12 test cases covering: - Chain registration on init - Unknown chain rejection - Signature threshold enforcement - Duplicate signature rejection - Expired bridge detection - Recovery actions (unlock, retry, cancel) - Gas multiplier per chain - Metadata preservation across transfer - Inactive chain rejection - Admin-only recovery guard Add docs/BRIDGE_GUIDE.md documenting: - Multi-sig bridge architecture and flow - Initiate, sign, execute, recover procedures - Security measures (multi-sig, timelock, deactivation) - Monitoring metrics and alert thresholds - Guide for adding new chains Closes MettaChain#110
|
@Uchechukwu-Ekezie Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
The historical_valuations mapping stores PropertyValuation structs, not PriceData. Convert valuation/last_updated fields to price/timestamp before freshness check.
LaGodxy
approved these changes
Mar 26, 2026
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.
Summary
This PR addresses four related issues improving code quality, operations, integrations, and cross-chain support.
Issue #102: Replace Magic Numbers with Named Constants
contracts/traits/src/constants.rswith documented named constants for all magic numbers across oracle, bridge, IPFS, token, and analytics contractsIssue #106: Automated Backup and Disaster Recovery
scripts/backup.sh: timestamped backups with SHA-256 checksums, automatic rotation (30 backups), cron-compatible for 6-hour schedulingdocs/DISASTER_RECOVERY.md: backup strategy, step-by-step recovery procedures for contracts/config/bridge/oracle, data integrity checks, severity-based escalation matrixIssue #109: External API Integration with Fallback
fetch_from_external_endpoint()adapter pattern for Chainlink, Pyth, Substrate, and Custom oracle sourcesget_latest_manual_price()with freshness check from valuation historyIssue #110: Cross-Chain Bridge Tests and Documentation
tests/bridge_tests.rswith 12 test cases: chain registration, signature threshold, duplicate rejection, expiration, recovery actions (unlock/retry/cancel), gas multiplier, metadata preservation, inactive chain rejection, admin guardsdocs/BRIDGE_GUIDE.mdwith architecture diagram, multi-sig flow, security measures, monitoring metrics, and new chain setup guideFiles Changed
contracts/traits/src/constants.rscontracts/traits/src/lib.rscontracts/oracle/src/lib.rscontracts/bridge/src/lib.rsscripts/backup.shdocs/DISASTER_RECOVERY.mddocs/BRIDGE_GUIDE.mdtests/bridge_tests.rsHow to test
cargo build --workspacecompiles cleanly./scripts/backup.sh ./test-backupscreates a backup archivecargo test --test bridge_testsruns cross-chain testsCloses #102
Closes #106
Closes #109
Closes #110