Skip to content

feat: ✨ Standardize currency system to HAVE token with Wei-based units#130

Merged
ahmadkaouk merged 9 commits intomainfrom
sde/runtime-params-config
Aug 18, 2025
Merged

feat: ✨ Standardize currency system to HAVE token with Wei-based units#130
ahmadkaouk merged 9 commits intomainfrom
sde/runtime-params-config

Conversation

@stiiifff
Copy link
Copy Markdown
Contributor

@stiiifff stiiifff commented Aug 13, 2025

Summary

This PR modernizes DataHaven's currency system by standardizing all three runtimes (mainnet, stagenet, testnet) to use Ethereum-compatible Wei-based units with HAVE as the native token name.

Key Changes

🔄 Currency Unit Standardization

  • Migrated from decimal-based to Wei-based system (18 decimals)
  • Wei units: WEI → KILOWEI → MEGAWEI → GIGAWEI
  • HAVE units: MICROHAVE → MILLIHAVE → HAVE → KILOHAVE
  • Zero Existential Deposit: Enables dust account support with insecure_zero_ed feature

🏷️ Token Naming

  • UNIT → HAVE: Native token renamed to reflect DataHaven branding
  • Consistent terminology: All constants, comments, and documentation updated
  • Supply factors preserved: Mainnet (100x), Stagenet/Testnet (1x)

⚖️ Block Weights & Gas Configuration

  • Solochain-optimized: Updated MAX_POV_SIZE and block weight parameters
  • EVM compatibility: Fixed GasLimitPovSizeRatio (u32 → u64) and storage growth ratios
  • Proper fee structure: Aligned with Ethereum standards

🧪 Test Updates

  • Treasury tests fixed: Updated to handle zero existential deposit behavior
  • All tests passing: Currency references updated across all runtime tests
  • Storage hub parameters: Updated to use HAVE token terminology

Breaking Changes

⚠️ Currency precision changed from 12 to 18 decimals

  • Applications using currency constants must update to new HAVE-based naming
  • ExistentialDeposit now 0 (was previously enforced minimum balance)

Runtime Coverage

  • Mainnet runtime (supply factor: 100)
  • Stagenet runtime (supply factor: 1)
  • Testnet runtime (supply factor: 1)
  • Storage hub parameters (runtime params updated)

Technical Details

Fee Structure

pub const TRANSACTION_BYTE_FEE: Balance = 1 * GIGAWEI * SUPPLY_FACTOR;
pub const STORAGE_BYTE_FEE: Balance = 100 * MICROHAVE * SUPPLY_FACTOR;
pub const WEIGHT_FEE: Balance = 50 * KILOWEI * SUPPLY_FACTOR / 4;

Block Configuration

pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
    WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2),
    MAX_POV_SIZE as u64,
);

Test Plan

  • All runtime builds compile successfully
  • All unit tests pass across three runtimes
  • Treasury fee handling verified with zero existential deposit
  • Storage hub parameter compatibility confirmed
  • EVM gas limit calculations validated

Files Modified

27 files changed, 728 insertions(+), 342 deletions(-)

  • Runtime lib.rs files (currency module definitions)
  • Cargo.toml files (insecure_zero_ed feature)
  • Configuration modules (block weights, gas limits)
  • Test suites (currency constant references)
  • Storage hub runtime parameters

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Introduced a unified currency module with HAVE units (18 decimals), fees, and a deposit helper.
    • Adopted dynamic block weight/length configuration (5 MB blocks) and re-exported gas-to-weight constants.
  • Improvements

    • Switched all runtimes and pricing parameters from UNIT/NANO_UNIT to HAVE/GIGAWEI.
    • Updated deposits, fees, and rewards to HAVE-based values across modules (including StorageHub and Snowbridge).
    • Made existential deposit runtime-configurable; enabled zero-ED mode on selected networks.
    • Updated metadata hash and token metadata to reference HAVE (symbol wHAVE, 18 decimals).

stiiifff and others added 2 commits August 13, 2025 11:58
- Switch from decimal-based units to Ethereum-compatible Wei units (18 decimals)
- Set ExistentialDeposit to 0 for dust account support
- Configure proper block weights and gas limits for solochain operation
- Update fee structure to align with Ethereum standards
- Fix treasury tests to handle zero existential deposit behavior

BREAKING CHANGE: Currency units changed from 12 to 18 decimals

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Rename UNIT → HAVE across all three runtimes (mainnet, stagenet, testnet)
- Rename KILOUNIT → KILOHAVE, MILLIUNIT → MILLIHAVE, MICROUNIT → MICROHAVE
- Update storage hub parameters and comments to use HAVE terminology
- Update all tests to reference HAVE instead of UNIT
- Preserve supply factor differences: mainnet=100, stagenet/testnet=1

The native token is now consistently called HAVE throughout the codebase.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@stiiifff stiiifff changed the title refactor: Standardize currency system to HAVE token with Wei-based units feat: ✨ Standardize currency system to HAVE token with Wei-based units Aug 13, 2025
@stiiifff stiiifff requested a review from ahmadkaouk August 13, 2025 09:58
@stiiifff
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 13, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 13, 2025

Walkthrough

Refactors runtimes to a HAVE-based currency unit system, replaces static existential-deposit constants with parameterized Get types, introduces centralized currency modules and dynamic BlockWeights, updates EVM/gas/fees wiring, adjusts metadata-hash denominations, and migrates tests and configs across mainnet, stagenet, and testnet to the new units and weight model.

Changes

Cohort / File(s) Summary
Existential Deposit & balances features
operator/node/src/command.rs
Replace constant EXISTENTIAL_DEPOSIT with ExistentialDeposit::get() in stagenet benchmark extrinsic path.
Balances feature flag (insecure_zero_ed)
operator/runtime/mainnet/Cargo.toml, operator/runtime/stagenet/Cargo.toml, operator/runtime/testnet/Cargo.toml
Enable pallet-balances feature insecure_zero_ed for all networks.
Wasm metadata hash denomination
operator/runtime/mainnet/build.rs, operator/runtime/stagenet/build.rs, operator/runtime/testnet/build.rs
Change enable_metadata_hash args from ("UNIT", 12) to ("HAVE", 18) under std+metadata-hash.
Mainnet runtime core config
operator/runtime/mainnet/src/lib.rs, operator/runtime/mainnet/src/configs/mod.rs
Add currency module, expose WEIGHT_PER_GAS, define weight/length constants, parameterize ExistentialDeposit, introduce BlockWeights::get(), update HAVE-based fees/units, adjust imports/exports and time constants.
Mainnet tests update
operator/runtime/mainnet/tests/common.rs, .../tests/lib.rs, .../tests/native_token_transfer.rs, .../tests/treasury.rs
Switch UNIT/MILLI_UNIT to HAVE/MILLIHAVE; use ExistentialDeposit::get(); update asset metadata (symbol), balances, fees, and assertions; add dead_code allows.
Stagenet runtime core config
operator/runtime/stagenet/src/lib.rs, operator/runtime/stagenet/src/configs/mod.rs
Add currency module and weight constants; parameterize ExistentialDeposit; introduce BlockWeights::get(); update HAVE-based economic params, GasLimitPovSizeRatio type u64, EVM wiring.
Stagenet storage-hub params
operator/runtime/stagenet/src/configs/runtime_params.rs, operator/runtime/stagenet/src/configs/storagehub/mod.rs
Rename units to HAVE/GIGAWEI; update deposit/pricing constants and docs; replace UNIT multipliers with HAVE.
Stagenet tests update
operator/runtime/stagenet/tests/common.rs, .../tests/lib.rs, .../tests/native_token_transfer.rs, .../tests/treasury.rs
Migrate tests to HAVE/MILLIHAVE; use ExistentialDeposit::get(); update metadata (symbol), balances, fees, and assertions; add dead_code allows.
Testnet runtime core config
operator/runtime/testnet/src/lib.rs, operator/runtime/testnet/src/configs/mod.rs
Add currency module, expose WEIGHT_PER_GAS, add weight constants and BlockWeights::get(); parameterize ExistentialDeposit; add additional public helpers/types and EVM/Snowbridge wiring; HAVE-based pricing.
Testnet tests update
operator/runtime/testnet/tests/common.rs, .../tests/lib.rs, .../tests/native_token_transfer.rs, .../tests/treasury.rs
Replace UNIT with HAVE across balances/fees; use ExistentialDeposit::get(); update metadata (symbol/decimals), assertions, and fee handling; add dead_code allows.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Extrinsic
  participant Runtime
  participant Currency as currency module
  participant Weights as BlockWeights
  participant Balances
  participant EVM
  participant Treasury

  User->>Extrinsic: Submit transaction
  Extrinsic->>Runtime: Dispatch call
  Runtime->>Weights: BlockWeights::get()
  Runtime->>Currency: WEIGHT_PER_GAS, fees, units (HAVE)
  alt EVM call
    Runtime->>EVM: Gas price via TransactionPaymentAsGasPrice
    EVM->>Treasury: Base fee portion
  else Substrate call
    Runtime->>Balances: Charge fee (WeightToFee using MILLIHAVE)
    Balances->>Treasury: Fees/tips per DealWithFees
  end
  Runtime->>Balances: Check ExistentialDeposit::get()
  Runtime-->>User: Apply result
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

A hare taps keys with nimble cheer,
Swapping UNITs for HAVEs this year.
Weights now dance, deposits “Get!”,
Gas and fees are neatly set.
Blocks grow strong, the tests all pass—
Thump-thump! I sign it with my paw and glass. 🥕🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Free

📥 Commits

Reviewing files that changed from the base of the PR and between 1f0cd6d and 9812381.

📒 Files selected for processing (27)
  • operator/node/src/command.rs (1 hunks)
  • operator/runtime/mainnet/Cargo.toml (1 hunks)
  • operator/runtime/mainnet/build.rs (1 hunks)
  • operator/runtime/mainnet/src/configs/mod.rs (9 hunks)
  • operator/runtime/mainnet/src/lib.rs (4 hunks)
  • operator/runtime/mainnet/tests/common.rs (6 hunks)
  • operator/runtime/mainnet/tests/lib.rs (2 hunks)
  • operator/runtime/mainnet/tests/native_token_transfer.rs (4 hunks)
  • operator/runtime/mainnet/tests/treasury.rs (10 hunks)
  • operator/runtime/stagenet/Cargo.toml (1 hunks)
  • operator/runtime/stagenet/build.rs (1 hunks)
  • operator/runtime/stagenet/src/configs/mod.rs (9 hunks)
  • operator/runtime/stagenet/src/configs/runtime_params.rs (6 hunks)
  • operator/runtime/stagenet/src/configs/storagehub/mod.rs (5 hunks)
  • operator/runtime/stagenet/src/lib.rs (7 hunks)
  • operator/runtime/stagenet/tests/common.rs (6 hunks)
  • operator/runtime/stagenet/tests/lib.rs (2 hunks)
  • operator/runtime/stagenet/tests/native_token_transfer.rs (4 hunks)
  • operator/runtime/stagenet/tests/treasury.rs (10 hunks)
  • operator/runtime/testnet/Cargo.toml (1 hunks)
  • operator/runtime/testnet/build.rs (1 hunks)
  • operator/runtime/testnet/src/configs/mod.rs (9 hunks)
  • operator/runtime/testnet/src/lib.rs (4 hunks)
  • operator/runtime/testnet/tests/common.rs (6 hunks)
  • operator/runtime/testnet/tests/lib.rs (2 hunks)
  • operator/runtime/testnet/tests/native_token_transfer.rs (4 hunks)
  • operator/runtime/testnet/tests/treasury.rs (11 hunks)

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Join our Discord community for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@ahmadkaouk ahmadkaouk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be an issue with the benchmarks of the pallet balances after this change

@stiiifff
Copy link
Copy Markdown
Contributor Author

@ahmadkaouk Good catch. I will create a separate ticket for this. It will be fixed by paritytech/polkadot-sdk#7379 when we upgrade to Polkadot SDK stable2503.

Updated all proxy test files across mainnet, stagenet, and testnet runtimes
to use HAVE instead of UNIT, aligning with the native token naming convention.
@ahmadkaouk ahmadkaouk merged commit 780d69a into main Aug 18, 2025
16 checks passed
@ahmadkaouk ahmadkaouk deleted the sde/runtime-params-config branch August 18, 2025 11:26
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.

2 participants