Skip to content

Replace magic numbers with named constants - #121

Closed
Uchechukwu-Ekezie wants to merge 1 commit into
MettaChain:mainfrom
OpenSourceCOntr:fix/issue-102-magic-numbers
Closed

Replace magic numbers with named constants#121
Uchechukwu-Ekezie wants to merge 1 commit into
MettaChain:mainfrom
OpenSourceCOntr:fix/issue-102-magic-numbers

Conversation

@Uchechukwu-Ekezie

Copy link
Copy Markdown
Contributor

Description

Create centralized constants module and replace hardcoded values.

Changes

  • Create contracts/traits/src/constants.rs with documented named constants for:
    • Oracle: staleness (3600s), min sources (2), outlier threshold (2), reputation scores
    • Bridge: gas multiplier (100), confirmation blocks (6), base gas (100000)
    • IPFS: file sizes, property sizes, document limits
    • Token: scaling factor (1e12)
    • Analytics: basis points denominator (10000)
  • Replace inline magic numbers in oracle and bridge constructors with constant references
  • Export constants module from traits crate

How to test

  • cargo build --workspace compiles cleanly
  • Constants are documented with purpose and valid ranges

Closes #102

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
@drips-wave

drips-wave Bot commented Mar 26, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

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.

Magic Numbers and Hardcoded Values

1 participant