Skip to content

Conversation

@m2ux
Copy link
Contributor

@m2ux m2ux commented Jan 28, 2026

Summary

Add treasury initialization to genesis generation, enabling the Midnight mainnet treasury to be funded from observed cNight deposits in the ICS contract on Cardano.

🎫 PM-20981


Motivation

The Midnight treasury must be initialized at genesis with Night tokens corresponding to cNight locked in the ICS (Illiquid Circulation Supply) contract on Cardano. This is a one-off operation that establishes the initial treasury balance based on verified Cardano UTxOs.

Without this capability, the genesis block cannot correctly reflect the treasury state required for mainnet launch.


Changes

  • Treasury Configuration Module (util/toolkit/src/treasury_config.rs) - Introduces CnightTreasuryConfig struct containing the ICS contract address (illiquid_circulation_supply_validator_address), a list of UTxOs representing cNight deposits, and a total Night amount. Includes validation to ensure the configured total matches the sum of UTxO amounts, with overflow detection.

  • Genesis Generator Integration (util/toolkit/src/genesis_generator.rs) - Adds fund_treasury() method that initializes the treasury using a two-step transfer via the block reward pool. Accepts optional CnightTreasuryConfig to specify the treasury funding amount at genesis time.

  • CLI Argument (util/toolkit/src/commands/generate_genesis.rs) - New --cnight-treasury-config flag that accepts a path to a JSON configuration file, enabling treasury initialization during genesis generation.

  • Network Configuration Files - Adds cnight-treasury-config.json for each network environment:

    • res/dev/ and res/preview/ - Placeholder address (addr_test1placeholderaddr) with zero amounts
    • res/devnet/ and res/govnet/ - Real ICS contract addresses from deployed reserve contracts
  • Test Coverage - 8 unit tests covering configuration parsing, total validation, mismatch detection, overflow handling, and edge cases. 1 integration test verifying treasury is correctly funded during genesis generation.


📌 Submission Checklist

  • Changes are backward-compatible (or flagged if breaking)
  • Pull request description explains why the change is needed
  • Self-reviewed the diff
  • I have included a change file, or skipped for this reason:
  • If the changes introduce a new feature, I have bumped the node minor version
  • Update documentation (if relevant)
  • Updated AGENTS.md if build commands, architecture, or workflows changed
  • No new todos introduced

🔱 Fork Strategy

  • Node Runtime Update
  • Node Client Update
  • Other
  • N/A

🗹 TODO before merging

  • Ready for review

m2ux added 2 commits January 28, 2026 16:58
Add change file documenting the upcoming treasury initialization feature
for the mainnet genesis block.

JIRA: PM-20981
@m2ux m2ux self-assigned this Jan 28, 2026
m2ux added 4 commits January 29, 2026 14:28
Add support for initializing the Midnight treasury from observed cNight
deposits in the ICS (Illiquid Circulation Supply) contract on Cardano.

- Add CnightTreasuryConfig type with validation for config files
- Add --cnight-treasury-config CLI argument to generate-genesis command
- Add fund_treasury() method using DistributeReserve and PayBlockRewardsToTreasury
- Integrate treasury funding early in genesis flow (before wallet distribution)
- Add example config files for dev and preview environments
Add #[allow(clippy::too_many_arguments)] to init() method. The parameter
count is a pre-existing issue; refactoring to a config struct is deferred.
Add test_genesis_with_treasury_config that verifies end-to-end treasury
funding during genesis generation. The test creates a treasury config
with multiple UTxOs, passes it to GenesisGenerator, and verifies the
resulting state.treasury contains the expected NIGHT balance.
Merged ledger-parameters-config feature with treasury-config feature.
Both CLI arguments are now supported:
- --cnight-treasury-config: Initialize treasury from ICS observations
- --ledger-parameters-config: Custom ledger parameters
@github-actions
Copy link
Contributor

github-actions bot commented Jan 29, 2026

kics-logo

KICS version: v2.1.16

Category Results
CRITICAL CRITICAL 0
HIGH HIGH 0
MEDIUM MEDIUM 94
LOW LOW 12
INFO INFO 83
TRACE TRACE 0
TOTAL TOTAL 189
Metric Values
Files scanned placeholder 28
Files parsed placeholder 28
Files failed to scan placeholder 0
Total executed queries placeholder 73
Queries failed to execute placeholder 0
Execution time placeholder 6

m2ux added 2 commits January 29, 2026 17:11
Updated treasury.json to cnight-treasury-config.json to match
the actual implementation.
@m2ux m2ux marked this pull request as ready for review January 29, 2026 17:12
@m2ux m2ux requested a review from a team as a code owner January 29, 2026 17:12
m2ux added 7 commits January 29, 2026 17:15
Removed 4 tests that provided minimal value:
- test_error_message_total_mismatch: only tests Display impl
- test_treasury_amount: trivial accessor test
- test_validate_total_matches_sum: redundant with test_parse_valid_config
- test_validate_zero_total_empty_utxos: trivial edge case

Remaining tests (3 unit + 1 integration) cover critical paths.
- Added #[allow(clippy::too_many_arguments)] to GenesisGenerator::new()
- Removed 4 low-value tests from treasury_config.rs
The ICS contract address is already stored in pc-chain-config.json
(cardano_addresses.bridge.illiquid_circulation_supply_validator_address).
Removes the duplication to maintain a single source of truth.

The genesis tool does not currently use the ICS address for validation -
when UTxO validation is implemented per acceptance criteria, the address
can be read from pc-chain-config.json.

JIRA: PM-20981
@m2ux m2ux requested a review from rsporny January 30, 2026 13:22
…easury config

The ICS address values in pc-chain-config.json are now deprecated,
so cnight-treasury-config.json becomes the source of truth for ICS
contract addresses. Re-adds the field with consistent naming.

PR: #563
@m2ux m2ux marked this pull request as draft January 30, 2026 15:36
m2ux added 3 commits January 30, 2026 16:00
Extend CnightTreasuryConfig with mandatory fields for Cardano
verification per ADR-0023:
- reference_block_hash: block at which to verify UTxOs
- cnight_policy_id: policy ID for cNight asset verification

Add CNIGHT_ASSET_NAME constant (empty string per Cardano convention).

Add db-sync dependencies to toolkit:
- partner-chains-db-sync-data-sources
- sidechain-domain

Update all network config files with required fields.

JIRA: PM-20981
Implement TreasuryVerifier to verify treasury configuration against
Cardano db-sync per ADR-0023 requirements:

- Query db-sync for reference block existence
- Verify each UTxO exists at the expected address
- Verify each UTxO contains cNight with expected amount
- Comprehensive error types for all failure scenarios

JIRA: PM-20981
Add --db-sync-url and --skip-cardano-verification arguments to the
generate-genesis command. When treasury config contains UTxOs:

- Verification is required by default (fails if no db-sync-url)
- --skip-cardano-verification bypasses for testing
- DB_SYNC_URL env var supported as alternative to CLI arg

JIRA: PM-20981
Copy link
Contributor

@NachoPal NachoPal left a comment

Choose a reason for hiding this comment

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

I don't think "reference_block_hash" should be a hardcoded value per contract configuration, it should be a dynamic input of the Generation/Validation tool.

Checking with @kapke to make sure we are aligned.

Also, in order to align with Genesis generation, better to add new Node subcommands instead of adding it as node-toolkit commands.

Refactor TreasuryVerifier to use TreasuryDataSource trait for testability:

- TreasuryDataSource trait abstracts database operations
- DbSyncDataSource implements trait for production db-sync queries
- MockTreasuryDataSource provides in-memory mock for tests

Add comprehensive mock tests covering:
- Block not found, UTxO not found, wrong address, amount mismatch
- Success cases for single and multiple UTxOs
- Empty UTxO list handling

JIRA: PM-20981
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.

4 participants