Commit graph

34 commits

Author SHA1 Message Date
Gonza Montiel
82c581d495
feat: Add datahaven native transfer precompile (#309)
## DataHaven Native Transfer Precompile

Implements EVM precompile at address
`0x00000000000000000000000000000007F5` (2073) to expose
`pallet-datahaven-native-transfer` functionality to the EVM layer.

### Features
- **Transfer to Ethereum**: Locks native tokens and sends them via
Snowbridge to Ethereum addresses
- **Pause/Unpause**: Admin controls to halt/resume transfers
- **View Functions**: Query paused state, total locked balance, and
sovereign account address

### Implementation
- Precompile using `#[precompile_utils::precompile]` macro with proper
gas accounting
- 15+ test cases covering success/failure scenarios
- Solidity interface with NatSpec documentation for contract integration

Enables seamless cross-chain transfers of DataHaven native tokens to
Ethereum L1.

---------

Co-authored-by: Steve Degosserie <723552+stiiifff@users.noreply.github.com>
Co-authored-by: Ahmad Kaouk <56095276+ahmadkaouk@users.noreply.github.com>
2025-12-02 13:57:40 +01:00
Facundo Farall
ae9eef7307
build: ⬆️ Upgrade to StorageHub release 0.1.4 (#298)
Upgrades to StorageHub release
[v0.1.4](https://github.com/Moonsong-Labs/storage-hub/releases/tag/v0.1.4).

## ⚠️ Breaking Changes ⚠️
- A DB migration for the indexer DB. Should be auto-applied by the
indexer node on startup, if this is not disabled by the env var
`SH_INDEXER_DB_AUTO_MIGRATE`. By default, it applies them.
- A new runtime API (`shp_tx_implicits_runtime_api::TxImplicitsApi`)
needed for StorageHub's Blockchain Service to build transactions using
the runtime spec version from the currently run runtime.

---------

Co-authored-by: Steve Degosserie <723552+stiiifff@users.noreply.github.com>
2025-11-16 16:44:17 +01:00
Steve Degosserie
5a7983f0d8
chore: ♻️ Add missing license header in operator & AVS contracts source code (#285)
Co-authored-by: Ahmad Kaouk <56095276+ahmadkaouk@users.noreply.github.com>
2025-11-10 12:56:41 +01:00
Facundo Farall
1fd0abccd7
build: ⬆️ Upgrade to SH v0.1.1 (#273)
Upgrade to SH release
[v0.1.1](https://github.com/Moonsong-Labs/storage-hub/releases/tag/v0.1.1)

---------

Co-authored-by: Ahmad Kaouk <56095276+ahmadkaouk@users.noreply.github.com>
Co-authored-by: Ahmad Kaouk <ahmadkaouk.93@gmail.com>
Co-authored-by: Steve Degosserie <723552+stiiifff@users.noreply.github.com>
2025-11-03 15:49:30 +02:00
Gonza Montiel
96c4408682
fix: add missing weights (#271)
### Add missing weights for BABE, GRANDPA, and Randomness

#### Summary
Adds generated weights and wires them into the runtime for the BABE,
GRANDPA, and Randomness pallets to replace defaults and ensure accurate
execution costs across networks.

#### What’s changed
- **New weights added** for `pallet_grandpa`, `pallet_babe` and
`pallet_randomness`
- **Runtime configs updated to use new weights**
  - `operator/runtime/mainnet/src/configs/mod.rs`
  - `operator/runtime/stagenet/src/configs/mod.rs`
  - `operator/runtime/testnet/src/configs/mod.rs`
 
 #### For follow-up PRS
- fix `pallet_identity` failure at running benchmarks
- fix `pallet_collective` benchmarking missmatch (related to
https://github.com/paritytech/polkadot-sdk/pull/6435)
- add `pallet_session_benchmarking` without including `pallet_staking`
(or some workaround)
- add StorageHub weights to our benchmarked pallets (`pallet_nfts`,
`pallet_storage_providers`, `pallet_payment_streams`,
`pallet_proofs_dealer`, `pallet_file_system`, `pallet_bucket_nfts`, etc)
2025-11-02 22:50:55 +02:00
undercover-cactus
f0896907ae
feat: add slashing support (#242)
## 🔨 Add Slashing Support for Runtime

This PR introduces the slashing functionality for the DataHaven runtime,
enabling punitive measures against misbehaving validators.


### Features
- Deferred slashing with configurable veto periods
- Cross-chain slashing message delivery trough Snowbridge
- Governance controls for slashing parameters and emergency cancellation

We introduced the `external-validator-slashes` pallet, which allows to
slash validators that misbehave. The slashing is triggered when an
offence is reported via the offence pallet (which is already
implemented). The message is sent through Snowbrige's outbound queue and
the real slashing happens in the contracts side, which will come in a
follow up PR.

There is a configurable window of time between the time the validator is
being reported, and the time the slash is triggered. This allows that in
case of an error we are still able to cancel the slashing, using a sudo
account.

For convenience, we also have extrinsics for corner cases:

- **`force_inject_slash`**: Root-only function to manually inject
slashes for specific validators with custom percentages. Useful for
emergency situations or governance-directed slashing outside normal
offence detection
- **`cancel_deferred_slash`**: Allows governance to cancel pending
slashes during the defer period by specifying era and slash indices.
Provides safety mechanism against false positives or malicious slash
reports
- **`set_slashing_mode`**: Configurable slashing behavior with three
modes - `Enabled` (normal operation), `LogOnly` (track offences without
applying slashes), and `Disabled` (completely halt slashing). Critical
for emergency response and testing

---------

Co-authored-by: Gonza Montiel <gon.montiel@gmail.com>
Co-authored-by: Gonza Montiel <gonzamontiel@users.noreply.github.com>
2025-10-29 10:43:55 +00:00
Gonza Montiel
1ec56681a5
feat: add referenda precompile (#217)
# Add Referenda Precompile

This PR introduces the referenda precompile from Moonbeam to enable
governance functionality through EVM calls.

## Changes Made

- Added `operator/precompiles/referenda/` with complete implementation
- Updated all runtime configs (mainnet, stagenet, testnet) to include
the referenda precompile
- Adapted track processing logic to work with DataHaven's runtime
configuration
- Adapted tests and mock according to our runtime

---------

Co-authored-by: Steve Degosserie <723552+stiiifff@users.noreply.github.com>
2025-10-11 00:17:21 +02:00
Gonza Montiel
2d6056721a
feat: add preimage precompile (#211)
## Add Preimage Precompile

This PR integrates the Preimage precompile from Moonbeam into the
DataHaven runtime across all three environments (mainnet, stagenet,
testnet).

**Key Changes:**
- Added Preimage precompile implementation at address `2067` in all
runtime configurations
- Updated precompile sets in mainnet, stagenet, and testnet runtimes
- Updated `is_governance_precompile()` for the Preimage precompile
2025-10-09 13:16:46 +02:00
Gonza Montiel
0988ce46d0
feat: add conviction voting precompile (#202)
## Add Conviction Voting Precompile

This PR introduces a new EVM precompile for conviction voting
functionality, enabling smart contracts to interact with the Substrate
conviction voting pallet.

### Key Changes

- **New Precompile**: Added `ConvictionVotingPrecompile` at address
`0x0000000000000000000000000000000000000812` (2066)
- **Solidity Interface**: Complete Solidity interface
(`ConvictionVoting.sol`) with all conviction voting operations
- **Runtime Integration**: Integrated precompile across all runtime
configurations (mainnet, testnet, stagenet)
- **Comprehensive Testing**: Inherits test suite from Moonbeam

### Features

- Vote casting with different conviction levels (None, Locked1x-6x)
- Vote delegation and undelegation
- Poll management and tallying
- Support for all conviction voting pallet operations

---------

Co-authored-by: Ahmad Kaouk <56095276+ahmadkaouk@users.noreply.github.com>
Co-authored-by: Steve Degosserie <723552+stiiifff@users.noreply.github.com>
2025-10-09 10:30:50 +02:00
Gonza Montiel
f7d441d9e5
feat: add collective precompile (#204)
## Add Collective Precompile

Adds the pallet collective precompile to `mainnet`, `stagenet`, and
`testnet` according to Moonbeam's configuration.

### Changes:
- Added `pallet-evm-precompile-collective` dependency to workspace
- Configured collective precompile at address `2064` using
`TreasuryCouncilInstanc`
- Configured collective precompile at address `2068` using
`TechnicalCommitteeInstance`

The precompile provides EVM access to collective governance
functionality including proposal execution, voting, and membership
management.

---------

Co-authored-by: Steve Degosserie <723552+stiiifff@users.noreply.github.com>
2025-10-08 23:16:34 +02:00
Gonza Montiel
65e245a82e
feat: add identity precompile (#205)
## Add Identity Precompile

Adds the pallet Identity precompile to `mainnet`, `stagenet`, and
`testnet` according to Moonbeam's configuration.

### Changes:
- Added `pallet-evm-precompile-identity` dependency to workspace
- Added and configured at address `2072` for all runtimes

The precompile provides a Solidity interface access to the Substrate
Identity pallet functionality.

---------

Co-authored-by: Ahmad Kaouk <56095276+ahmadkaouk@users.noreply.github.com>
Co-authored-by: Steve Degosserie <723552+stiiifff@users.noreply.github.com>
2025-10-08 13:48:17 +00:00
Ahmad Kaouk
ac09a4f2bb
feat: Add SafeMode and TxPause Pallets (#192)
### Overview
This PR integrates the `pallet-safe-mode` and `pallet-tx-pause` from
Polkadot SDK to provide comprehensive emergency governance controls
across all DataHaven runtime networks (mainnet, stagenet, testnet).

### Key Changes

#### 🔧 **Core Integration**
- **Dependencies**: Added `pallet-safe-mode` and `pallet-tx-pause` from
`polkadot-stable2412-6`
- **Runtime Integration**: Integrated both pallets across all three
runtime networks with pallet indices 103 and 104
- **Call Filtering**: Implemented unified `RuntimeCallFilter` that
combines Normal, SafeMode, and TxPause restrictions

#### 🛡️ **SafeMode Pallet Configuration**
- **Duration**: 1 day activation period (`DAYS` constant)
- **Deposits**: Disabled permissionless entry/extension (all `None`)
- **Origins**: Root-only for all force operations (`force_enter`,
`force_exit`, `force_extend`, etc.)
- **Whitelisting**: SafeMode and Sudo calls are immune to restrictions

#### ⏸️ **TxPause Pallet Configuration** 
- **Origins**: Root-only pause/unpause control
- **Whitelisting**: SafeMode and Sudo calls cannot be paused
- **Max Call Name Length**: 256 characters

#### 🏗️ **Architecture**
- **Shared Types**: Created `operator/runtime/common/src/safe_mode.rs`
with reusable configurations
- **Combined Filtering**: `RuntimeCallFilter` applies all three filter
layers (Normal + SafeMode + TxPause)
- **Consistent Config**: Identical configuration across mainnet,
stagenet, and testnet

#### 📊 **Infrastructure Updates**
- **Benchmarking**: Added both pallets to benchmark suites across all
networks
- **Weight Mappings**: Placeholder weights using Substrate defaults
(ready for chain-specific benchmarking)
- **Metadata**: Updated runtime metadata for new pallet exposure

#### 🧪 **Testing Framework**
- **Coverage**: Tests for individual pallet behavior, combined
restrictions, whitelisting, and edge cases

### Emergency Control Capabilities

**SafeMode Pallet** (8 calls):
- User calls: `enter`, `extend`, `release_deposit`
- Force calls: `force_enter`, `force_exit`, `force_extend`,
`force_slash_deposit`, `force_release_deposit`

**TxPause Pallet** (2 calls):
- `pause_call` / `unpause_call` - Granular transaction type pausing

---------

Co-authored-by: Steve Degosserie <723552+stiiifff@users.noreply.github.com>
2025-10-06 17:00:10 +00:00
Steve Degosserie
91e29700a3
feat: Bump client version to v0.2.0 & runtime spec_version to 200 (#194) 2025-09-29 23:35:12 +02:00
Ahmad Kaouk
eb94be1e3f
feat: multi block migration pallet (#180)
## Overview

This PR integrates Substrate's `pallet-migrations` into all DataHaven
runtimes (mainnet, stagenet, testnet) to enable robust multi-block
migration capabilities. This infrastructure allows complex runtime
upgrades to be executed across multiple blocks while maintaining chain
stability and providing governance controls.

## What Changed

### Core Integration
- **Added `pallet-migrations` dependency** across all runtime
configurations
- **Integrated migration pallet** as pallet index 39 in all runtimes  
- **Created shared migration configuration** in
`datahaven-runtime-common`

### Runtime Configuration
- **Mainnet, Stagenet, and Testnet** now include identical migration
configurations
- **MaxServiceWeight** parameter set to 75% of max block weight for safe
migration execution
- **Migration cursor limits** configured (65KB max cursor, 256B max
identifier)
- **Failure handling** configured to freeze the chain on migration
failures (similar to Moonbeam's maintenance mode)

## Future Work

- [ ] Add custom failure handler (safe mode) to replace chain freeze
- [ ] Generate DataHaven-specific benchmarks for migration weights

---------

Co-authored-by: undercover-cactus <lola@moonsonglabs.com>
2025-09-24 12:27:44 +02:00
Gonza Montiel
f8b5706073
feat: add filesystem precompile (#165)
Incorporate `pallet-evm-precompile-file-system` into `stagenet`,
`testnet` and `mainnet`.

---------

Co-authored-by: Steve Degosserie <723552+stiiifff@users.noreply.github.com>
Co-authored-by: Ahmad Kaouk <56095276+ahmadkaouk@users.noreply.github.com>
2025-09-15 10:43:00 +02:00
Ahmad Kaouk
b5a6406470
feat: Add ERC20 Balances precompile (#150)
## Summary
- Introduces an ERC20-compatible precompile backed by `pallet_balances`,
including approvals and EIP-2612 permit.
- Wires the precompile into Mainnet, Testnet, and Stagenet at address
`0x0000000000000000000000000000000000000802` (u64: 2050).
- Adds comprehensive unit tests and a mock runtime.

## Motivation
- Allow EVM contracts and tooling to interact with Substrate balances
via a familiar ERC20 interface.
- Support off-chain approvals via EIP-2612 for gasless approvals and
improved UX.

## Key Changes
- New crate: `operator/precompiles/erc20-balances`
  - Core logic: `src/lib.rs`
  - EIP-2612 helpers and validation: `src/eip2612.rs`
  - Tests + mock runtime: `src/tests.rs`, `src/mock.rs`
- Runtime wiring (all networks): add `Erc20BalancesPrecompile` at
`AddressU64<2050>`
  - `operator/runtime/{mainnet,stagenet,testnet}/src/precompiles.rs`
- Workspace plumbing: include `pallet-evm-precompile-balances-erc20` in
`operator/Cargo.toml`

## Interface
- ERC20: `totalSupply`, `balanceOf`, `allowance`, `approve`, `transfer`,
`transferFrom`, `name`, `symbol`, `decimals`
- Native-only flows: `deposit()` (fallback/payable) and
`withdraw(uint256)`
- EIP-2612: `permit(owner,spender,value,deadline,v,r,s)`,
`nonces(owner)`, `DOMAIN_SEPARATOR()`
- Events: `Transfer`, `Approval`, `Deposit`, `Withdrawal`
- Storage:
- Approvals via `ApprovesStorage` (double map: owner → spender → amount)
  - EIP-2612 nonces via `NoncesStorage` keyed by `H160`
- Instance-aware prefixes to support multiple `pallet_balances`
instances
2025-09-12 08:57:44 +00:00
Ahmad Kaouk
788e5efaa4
feat: Add proxy Precompile (#155) 2025-09-12 09:45:26 +02:00
undercover-cactus
a9d0f7157a
feat: storage hub client (#149)
Co-authored-by: Steve Degosserie <723552+stiiifff@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
2025-09-10 08:15:27 +02:00
Steve Degosserie
479af2e192
feat: Add Moonbeam CallPermit precompile (#140)
## Summary

This PR adds Moonbeam's CallPermit precompile to DataHaven, enabling
gasless meta-transactions through EIP-712 signature-based permissions.
Users can sign transaction permits offline, allowing relayers to execute
transactions on their behalf while maintaining full security and
authentication.

## Key Features

### CallPermit Precompile Functions
- **`dispatch(address from, address to, uint256 value, bytes data,
uint64[] gasLimit, uint256 deadline, uint8 v, bytes32 r, bytes32 s)`**:
Execute permitted calls with signature verification
- **`nonces(address owner)`**: Get current nonce for permit validation

### Technical Implementation
- **Address**: `0x080A` (2058 in decimal)
- **EIP-712 Compliance**: Structured signature validation with proper
domain separation
- **Nonce Management**: Per-user nonce tracking for replay protection
- **Deadline Validation**: Time-bound permits for enhanced security
- **Gas Forwarding**: Proper gas limit enforcement and forwarding

Depends on https://github.com/datahaven-xyz/datahaven/pull/137

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-09-07 15:00:37 +02:00
Steve Degosserie
757a99b7c6
feat: Add Moonbeam Batch precompile (#138)
## Summary

This PR adds Moonbeam's Batch precompile to DataHaven, enabling
efficient batching of multiple EVM transactions in a single call. This
implementation follows Moonbeam's exact architecture and provides
significant gas savings for batch operations.

## Key Features

### Batch Precompile Functions
- **`batchSome(address[], uint256[], bytes[], uint64[])`**: Execute
multiple calls, continuing on failures
- **`batchSomeUntilFailure(address[], uint256[], bytes[], uint64[])`**:
Execute calls until first failure
- **`batchAll(address[], uint256[], bytes[], uint64[])`**: Execute all
calls, reverting if any fail

### Technical Implementation
- **Address**: `0x0808` (2056 in decimal)
- **Access Control**: Restricted nesting with `SubcallWithMaxNesting<2>`
- **Self-recursion**: Only the Batch precompile can call itself
(`OnlyFrom<AddressU64<2056>>`)
- **Gas Management**: Proper gas estimation and refund handling
- **Error Handling**: Comprehensive revert reasons and event logging

Depends on #137

---------

Co-authored-by: Ahmad Kaouk <ahmadkaouk.93@gmail.com>
2025-09-05 19:24:09 +02:00
Steve Degosserie
6886bcbdde
feat: Add Moonbeam EVM Precompile Registry (#137)
## Summary

This PR implements a comprehensive EVM precompile registry system for
DataHaven, following Moonbeam's exact architecture and patterns. The
implementation includes:

- **Registry Precompile**: A new precompile at address `0x0815` (2069)
that manages and queries available precompiles
- **Core Ethereum Precompiles**: Standard Ethereum precompiles
(ECRecover, SHA256, RIPEMD160, Identity, ModExp, BN128Add, BN128Mul,
BN128Pairing, Blake2F, SHA3FIPS)
- **Modular Architecture**: Clean separation following Moonbeam's
structure with dedicated precompile modules per runtime

## Key Features

### Registry Precompile Functions
- `isPrecompile(address)`: Check if an address corresponds to any
precompile (active or inactive)
- `isActivePrecompile(address)`: Check if a precompile is currently
active in the runtime
- `updateAccountCode(address)`: Insert dummy EVM bytecode for Solidity
compatibility

### Runtime Integration
- Integrated across all three runtimes (testnet, stagenet, mainnet)
- Uses Moonbeam's `PrecompileSetBuilder` pattern for composable
precompile management
- Proper gas accounting with database read/write operations
- Access control through `CallableByContract` and `CallableByPrecompile`
traits

---------

Co-authored-by: undercover-cactus <lola@moonsonglabs.com>
2025-09-04 10:25:59 +02:00
Steve Degosserie
d2bea9278c
chore: ♻️ Remove the StorageHub conditional feature from the DataHav… (#146)
…en runtimes (always include SH)
2025-09-03 10:57:57 +02:00
Steve Degosserie
f0b2de3906
feat: Implement Moonbeam-style OpenGov governance (#131)
## 🎯 Overview

This PR implements a comprehensive Moonbeam-inspired OpenGov (Gov2)
governance system across all DataHaven runtime environments (Stagenet,
Testnet, and Mainnet). The implementation provides multi-track
referenda, conviction voting, collective decision-making through dual
councils, and complete benchmarking support.

##  Key Features

### 🗳️ Multi-Track Referendum System
Implements **6 distinct governance tracks** with different thresholds
and parameters:

| Track | Purpose |
|-------|---------|
| **Root (0)** | Critical runtime upgrades |
| **Whitelisted Caller (1)** | Fast-tracked technical proposals |
| **General Admin (2)** | General governance proposals |
| **Referendum Canceller (3)** | Cancel dangerous referenda |
| **Referendum Killer (4)** | Emergency removal of malicious referenda |
| **Fast General Admin (5)** | Expedited administrative decisions |

### 🏛️ Dual Council Structure
- **Technical Committee**: Manages technical proposals with fast-track
powers
- **Treasury Council**: Oversees treasury spending with shorter motion
duration

### 🔐 Custom Origins System
5 specialized permission levels for granular governance control:
- `GeneralAdmin`
- `ReferendumCanceller`
- `ReferendumKiller`
- `WhitelistedCaller`
- `FastGeneralAdmin`

### ⚖️ Conviction Voting
- Vote multipliers from 0.1x to 6x based on lock duration
- Delegation support for proxy voting
- Maximum 20 concurrent votes per account

🤖 Implementation assisted by [Claude Code](https://claude.ai/code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Ahmad Kaouk <56095276+ahmadkaouk@users.noreply.github.com>
2025-09-02 22:46:35 +02:00
undercover-cactus
c661a94014
feat: add storagehub pallets to all the runtimes (#133)
This PR add the storagehub pallets to the `testnet` and `mainnet`
runtime. The storage hub pallets are only build with the runtime if the
`storage-hub` feature is activated.

It is also add minor fixes to the `stagenet` runtime (fix wrong path
dependencies, index collision, etc...).

---------

Co-authored-by: Steve Degosserie <723552+stiiifff@users.noreply.github.com>
2025-09-02 15:05:36 +02:00
Steve Degosserie
780d69ab04
feat: Standardize currency system to HAVE token with Wei-based units (#130)
## 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
```rust
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
```rust
pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
    WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2),
    MAX_POV_SIZE as u64,
);
```

## Test Plan

- [x] All runtime builds compile successfully
- [x] All unit tests pass across three runtimes
- [x] Treasury fee handling verified with zero existential deposit
- [x] Storage hub parameter compatibility confirmed
- [x] 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](https://claude.ai/code)*

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## 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).

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Ahmad Kaouk <ahmadkaouk.93@gmail.com>
2025-08-18 13:26:30 +02:00
Steve Degosserie
2d0af9c572
feat: Integrate Proxy pallet into DataHaven runtimes (#128)
## Summary

This PR integrates the Substrate Proxy pallet into DataHaven runtimes
(testnet, stagenet, mainnet) with comprehensive test coverage. The proxy
pallet enables account delegation functionality, allowing accounts to
authorize other accounts to execute calls on their behalf with
configurable permissions.

## Changes

### Proxy Pallet Integration
- **Added proxy pallet** to all three DataHaven runtimes (testnet,
stagenet, mainnet)
- **Configured custom ProxyType enum** with DataHaven-specific proxy
types:
  - `Any` - Unrestricted proxy access
  - `NonTransfer` - All calls except balance transfers  
  - `Governance` - Governance and utility calls only
  - `Staking` - Staking operations (placeholder)
  - `CancelProxy` - Proxy announcement cancellation
  - `Balances` - Balance transfer operations only
  - `IdentityJudgement` - Identity judgement operations
  - `SudoOnly` - Privileged sudo operations only

### Runtime Configuration
- **Integrated pallet-proxy** into runtime construction macros
- **Configured proxy deposits** (base + per-proxy fees)
- **Set proxy limits** (maximum proxies per account)
- **Implemented InstanceFilter** for call filtering per proxy type
- **Added proxy pallet to runtime APIs** and metadata

### Comprehensive Test Suite
- `operator/runtime/testnet/tests/proxy.rs` - 24 comprehensive proxy
tests
- `operator/runtime/stagenet/tests/proxy.rs` - 24 comprehensive proxy
tests
- `operator/runtime/mainnet/tests/proxy.rs` - 24 comprehensive proxy
tests
- Updated `lib.rs` files in all three runtimes to include proxy test
modules


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- New Features
- Enable account proxies across mainnet, stagenet, and testnet with
configurable types, delays, and per-type call permissions.
- Support anonymous (pure) proxies, proxy announcements with delays, and
deposit/limit parameters for proxy management.
- Tests
- Add comprehensive integration tests covering proxy lifecycle,
filtering, pure proxies, announcements, batching, chaining, multisig,
identity, and sudo paths.
  - Test builder now supports optional sudo setup.
- Chores
  - Add benchmarking, weights, and try-runtime support for proxies.
  - Update internal package metadata version.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Ahmad Kaouk <ahmadkaouk.93@gmail.com>
Co-authored-by: Ahmad Kaouk <56095276+ahmadkaouk@users.noreply.github.com>
2025-08-18 09:46:59 +02:00
Federico Rodríguez
843502d21a
test: init benchmark infra (#110)
* Add `run_benchmarks.sh` script to run runtime benchmarks
* Sets up benchmark configs and directory structure to store weights
(`operator/runtime/<RUNTIME>/weights`)
* (naive) fixes to some benchmarks: 
    * `pallet_datahaven_native_transfer`: 
      * use a mock for `NativeTokenId`
* look at the balance difference of the treasury instead of the total
(this makes the benchmark agnostic to genesis setup)
* `snowbridge_pallet_system` / `snowbridge_pallet_system_v2` use native
token xcm location vs relay chain one. Add missing benchmark methods and
update fixture with valid data.
* `snowbridge_pallet_ethereum_client`: update fixtures with valid data
* `snowbrige_pallet_inbound_queue_v2`: set EthereumGatewayAddress when
initializing storage on benchmark and use a mock message processor ( as
fixture has `CreateAsset` payload which is not supported in the
`EigenLayerMessageProcessor`)
* `snowbridge_pallet_outbound_queue_v2`: add missing
`submit_delivery_receipt` benchmark which required a dedicated fixture
(all copied from the upstream pallet)
* `pallet_treasury`: Use an `ExistentialDeposit` of `1` on benchmark,
else payout fails.
* `pallet_transaction_payment`: Use a custom `WeightToFee` that makes
the Fee small, else account in benchmark cannot pay for fees (It is
funded a multiplier of `ExistentialDeposit` and is expected for that to
be enough, but it's not in our particular setup).
* comment out `pallet_identity` and `pallet_im_online` due to
incompatibilities (to be addressed later)
* Basic benchmark run to set `WeightInfo` from `weights` in configs
(real run should be done later using target hardware)

---------

Co-authored-by: Ahmad Kaouk <ahmadkaouk.93@gmail.com>
Co-authored-by: Tobi Demeco <50408393+TDemeco@users.noreply.github.com>
Co-authored-by: undercover-cactus <lola@moonsonglabs.com>
Co-authored-by: TDemeco <tdemeco@itba.edu.ar>
2025-08-06 13:44:42 +02:00
undercover-cactus
3ea6e57b66
feat: add storage hub runtime (#40)
In this PR we add StorageHub pallets to the runtime. It will only be
added if the `storage-hub` feature is activated.

---------

Co-authored-by: Gonza Montiel <gonzamontiel@users.noreply.github.com>
2025-07-01 14:01:27 +02:00
Steve Degosserie
a6c1cb2ab2
feat: Add Treasury 💰 pallet to DataHaven runtimes (#98)
This PR integrates the Substrate FRAME Treasury pallet across all three
DataHaven runtime environments (`testnet`, `mainnet`, `stagenet`) with a
custom fee allocation mechanism and comprehensive test coverage.

### Key Changes

#### Treasury Pallet Integration:
- Added Treasury pallet to all three runtimes (testnet, mainnet,
stagenet) with 20% fee allocation and 80% burn mechanism.
- Implemented dynamic fee proportion control via
`FeesTreasuryProportion` runtime parameter.
- Integrated treasury with custom fee handlers:
`DealWithEthereumBaseFees`, `DealWithEthereumPriorityFees`, and
`DealWithSubstrateFeesAndTip`.

#### Comprehensive Testing Infrastructure:
- Created robust test architecture with session management and validator
setup across all runtimes
- Added block author management utilities for treasury testing requiring
pallet_authorship integration
  - Implemented 15 total tests (5 tests × 3 runtimes) covering:
    - EVM transaction fee allocation with/without priority fees
    - Substrate fee and tip handling validation
    - Treasury spending functionality via sudo
- Complete fee flow verification with actual network base fee
calculations

#### Technnical Implementation
  Fee Allocation Logic:
  - Base fees: 20% to treasury, 80% burned
  - Priority fees: 100% to block author
  - Substrate tips: 100% to block author

The implementation is based on
https://github.com/moonbeam-foundation/moonbeam/pull/3120 in
[Moonbeam](https://github.com/moonbeam-foundation/moonbeam), and
assisted by Claude Code.
2025-06-25 08:09:26 +02:00
Ahmad Kaouk
2b44f6af57
feat: Native Token Transfer to Ethereum (#88)
### Summary

- Implement native token transfers from DataHaven to Ethereum using
Snowbridge infrastructure
- Add comprehensive datahaven-native-transfer pallet with lock-and-mint
mechanism for cross-chain token representation

  ### Key Features

  **New Pallet: datahaven-native-transfer**

- Cross-chain transfers: Transfer DataHaven native tokens to Ethereum
addresses via `transfer_to_ethereum extrinsic`
- Token locking mechanism: Secure token storage in deterministic
Ethereum sovereign account during transfers
- Fee management: Required fees for all transfers to compensate relayers
and prevent spam
  - Emergency controls: Pause/unpause functionality
- Token registration: Integration with Snowbridge's token registration
for native token identification


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced the DataHaven Native Transfer pallet enabling secure
cross-chain transfers of DataHaven native tokens to and from Ethereum
via Snowbridge.
- Added token locking on DataHaven, minting on Ethereum, and mandatory
fee collection to cover gas costs and incentivize relayers.
- Implemented pause and unpause controls for emergency management of
token transfers.

- **Configuration**
- Integrated the new pallet into mainnet, stagenet, and testnet runtimes
with updated network, account, and treasury settings.
- Added Ethereum sovereign account constants and native token ID support
for optimized cross-chain operations.

- **Documentation**
- Added comprehensive README and inline documentation detailing pallet
features, extrinsics, events, errors, and security considerations.

- **Tests**
- Added extensive unit and integration tests covering token transfers,
native token registration, fee handling, pause functionality, and event
validation across all supported networks.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Steve Degosserie <723552+stiiifff@users.noreply.github.com>
2025-06-12 00:07:36 +02:00
Ahmad Kaouk
d76f70686e
feat(operator): Add External Validators Rewards Pallet (#72)
This PR introduces and integrates the new
`pallet-external-validators-rewards` into the operator runtimes. This
pallet is responsible for managing and distributing rewards to external
validators. The pallet was originally introduced by Tanssi. It was
heavily modified to abstract the message building and sending with
Snowbridge.

### Key Changes Related to `pallet-external-validators-rewards`:

*   **Pallet and Runtime API Addition:**
* The `pallet-external-validators-rewards` has been added to `mainnet`,
`stagenet`, and `testnet` runtimes

* **Runtime Configuration
(`operator/runtime/{mainnet,stagenet,testnet}/src/configs/mod.rs`):**
* **`RewardsRegistryAddress` Parameter:** A new dynamic runtime
parameter `RewardsRegistryAddress` (type `H160`) has been added to
`runtime_params.rs`. This will hold the Ethereum address of the Rewards
Registry contract.
    *   **Author Rewards with `RewardsPoints`:**
* A new struct `RewardsPoints` implements
`pallet_authorship::EventHandler`.
* Its `note_author` function rewards block authors (if they are not
whitelisted validators) by calling
`ExternalValidatorsRewards::reward_by_ids`.
* The `EventHandler` in `pallet_authorship::Config` is updated to
`(RewardsPoints, ImOnline)`.
    *   **Integration with `pallet-external-validators`:**
* The `OnEraStart` and `OnEraEnd` hooks in
`pallet_external_validators::Config` are now set to
`ExternalValidatorsRewards`, allowing the rewards pallet to react to era
changes.
    *   **`RewardsSendAdapter` for Ethereum Communication:**
* A new struct `RewardsSendAdapter` implements
`pallet_external_validators_rewards::types::SendMessage`.
* `build()`: Constructs an `OutboundMessage` to call the
`updateRewardsMerkleRoot(bytes32)` function on the
`RewardsRegistryAddress` on Ethereum. The calldata includes the selector
(hashed from `UpdateRewardsMerkleRootSignature`) and the
`rewards_merkle_root`.
* `validate()` and `deliver()`: Utilize `OutboundQueueV2` for message
validation and delivery.
* A constant `UpdateRewardsMerkleRootSignature` (
`b"updateRewardsMerkleRoot(bytes32)"`) is defined for this purpose.
  
* **Runtime API
(`operator/runtime/{mainnet,stagenet,testnet}/src/lib.rs`):**
* The runtime implements
`pallet_external_validators_rewards_runtime_api::ExternalValidatorsRewardsApi`.
    *   This exposes two functions:
* `generate_rewards_merkle_proof(account_id: AccountId, era_index:
EraIndex) -> Option<MerkleProof>`
* `verify_rewards_merkle_proof(merkle_proof: MerkleProof) -> bool`

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced a rewards system for external validators with era-based
tracking, Merkle proof generation, and verification.
- Added runtime APIs to generate and verify validator rewards Merkle
proofs.
- Enabled rewards distribution via outbound messaging to an external
registry contract.
  - Configured runtime parameters for the rewards registry address.
- Added fixed author reward points and integrated rewards logic into
block authorship events.
- Provided a mock runtime environment and benchmarking support for the
rewards pallet.

- **Tests**
- Added comprehensive tests and benchmarks for validator rewards
distribution and Merkle proof functionality.

- **Chores**
- Integrated new pallets and runtime APIs into mainnet, stagenet, and
testnet configurations.
- Updated dependencies and feature groups to include new rewards-related
pallets.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Facundo Farall <37149322+ffarall@users.noreply.github.com>
2025-05-22 00:51:24 +00:00
Ahmad Kaouk
b548d3ec39
feat(operator): Add external validators Pallet (#65)
This PR replaces `pallet-validator-set` with a new
`pallet-external-validators` pallet from Tanssi.

## Key Changes

- **New ExternalValidators Pallet**
  - Supports whitelisted validators (set by governance, not rewarded)
  - Manages external validators (can be enabled/disabled)
- Implements era-based rotation (eras change after configurable
sessions)

- **Bridge Integration**
- Updated `EigenLayerMessageProcessor` in
`operator/primitives/bridge/src/lib.rs`
  - Replaced the old `SetValidators` command with  
    ```rust
    ReceiveValidators { validators, external_index }
    ```
2025-05-14 11:05:07 +02:00
Tim B
6aeece550b
ci: 🐳 Start Publishing Docker Images (#64) 2025-05-08 20:32:55 -03:00
Steve Degosserie
d6f76f7fa3
feat(operator): Multi-runtime support (#38)
Add support for multiple runtimes: `stagenet`, `testnet` & `mainnet`.

- Moved common types to `datahaven-runtime-common` crate.
- Made the node's command & service code generic over different
runtimes. Each runtime has a `dev` & `local` genesis config preset.
- More types / constants can be moved to the `datahaven-runtime-common`
crate ... this will be done in subsequent PRs.

---------

Co-authored-by: Gonza Montiel <gon.montiel@gmail.com>
Co-authored-by: Gonza Montiel <gonzamontiel@users.noreply.github.com>
Co-authored-by: Facundo Farall <37149322+ffarall@users.noreply.github.com>
2025-05-08 13:14:30 +00:00