Skip to content

feat: introduce TokenMetadata type for fungible faucet metadata#2380

Merged
PhilippGackstatter merged 5 commits into0xMiden:nextfrom
Farukest:feat/issue-2344-token-metadata
Feb 5, 2026
Merged

feat: introduce TokenMetadata type for fungible faucet metadata#2380
PhilippGackstatter merged 5 commits into0xMiden:nextfrom
Farukest:feat/issue-2344-token-metadata

Conversation

@Farukest
Copy link
Contributor

Summary

  • Introduces TokenMetadata struct to encapsulate fungible faucet metadata (token_supply, max_supply, decimals, symbol)
  • Implements conversion traits: From<TokenMetadata> for Word, From<TokenMetadata> for StorageSlot, TryFrom<&StorageSlot>, TryFrom<&AccountStorage>
  • Refactors BasicFungibleFaucet and NetworkFungibleFaucet to use TokenMetadata internally, reducing code duplication

Test plan

  • All existing faucet tests pass (66 tests in miden-standards, 17 faucet tests in miden-testing)
  • Added unit tests for TokenMetadata validation and conversions
  • Clippy and format checks pass

Closes #2344

@PhilippGackstatter
Copy link
Contributor

Thank you very much for the PR @Farukest. Could you update this PR to latest next now that #2335 is merged? It introduced a new token_supply field in the BasicFungibleFaucet that needs to be propagated to TokenMetadata.

This adds a new TokenMetadata struct that encapsulates the metadata
associated with fungible faucet accounts (token_supply, max_supply,
decimals, symbol).

The struct provides:
- Constructors: new() and with_supply()
- Accessors: token_supply(), max_supply(), decimals(), symbol()
- Conversions: From<TokenMetadata> for Word and StorageSlot
- Parsing: TryFrom<&StorageSlot> and TryFrom<&AccountStorage>

BasicFungibleFaucet and NetworkFungibleFaucet have been refactored
to use TokenMetadata internally, reducing code duplication.

Closes 0xMiden#2344
@Farukest Farukest force-pushed the feat/issue-2344-token-metadata branch from 051da4e to 3e470d6 Compare February 3, 2026 14:56
@Farukest
Copy link
Contributor Author

Farukest commented Feb 3, 2026

Thank you very much for the PR @Farukest. Could you update this PR to latest next now that #2335 is merged? It introduced a new token_supply field in the BasicFungibleFaucet that needs to be propagated to TokenMetadata.

All done. thank you @PhilippGackstatter 👍

Copy link
Contributor

@PhilippGackstatter PhilippGackstatter left a comment

Choose a reason for hiding this comment

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

Great work! I left a few suggestions.

Comment on lines +10 to +21
/// Token metadata for fungible faucet accounts.
///
/// This struct encapsulates the metadata associated with a fungible token faucet:
/// - `token_supply`: The current amount of tokens issued by the faucet.
/// - `max_supply`: The maximum amount of tokens that can be issued.
/// - `decimals`: The number of decimal places for token amounts.
/// - `symbol`: The token symbol.
///
/// The metadata is stored in a single storage slot as:
/// `[token_supply, max_supply, decimals, symbol]`
#[derive(Debug, Clone, Copy)]
pub struct TokenMetadata {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is now documented here, I would remove the docs from BasicFungibleFaucet and instead link to TokenMetadata, something like:

/// ## Storage Layout
///
/// - [`Self::metadata_slot`]: Stores [`TokenMetadata`]

Comment on lines 190 to 192
/// Tries to create [`TokenMetadata`] from a storage slot.
fn try_from(slot: &StorageSlot) -> Result<Self, Self::Error> {
TokenMetadata::try_from_word(slot.value())
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also validate that the slot name matches.

// TRAIT IMPLEMENTATIONS
// ================================================================================================

impl From<TokenMetadata> for Word {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would also be fine to publicly implement TryFrom<Word> for TokenMetadata.

Comment on lines +6 to +8

// TOKEN METADATA
// ================================================================================================
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's move static METADATA_SLOT_NAME into this file since it's only used here now.

Comment on lines +187 to +188
impl TryFrom<&StorageSlot> for TokenMetadata {
type Error = FungibleFaucetError;
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's make use of this implementation and replace NetworkFungibleFaucet::try_from(&faucet)?.token_supply() in crates/miden-testing/tests/agglayer/bridge_out.rs with decoding the TokenMetadata from faucet.storage().

Same in crates/miden-testing/tests/scripts/faucet.rs, including replacing BasicFungibleFaucet::try_from.

- Move METADATA_SLOT_NAME constant to token_metadata.rs
- Update BasicFungibleFaucet docs to reference TokenMetadata
- Add slot name validation in TryFrom<&StorageSlot> for TokenMetadata
- Implement TryFrom<Word> for TokenMetadata (public trait)
- Replace NetworkFungibleFaucet/BasicFungibleFaucet::try_from with TokenMetadata in tests
@Farukest Farukest force-pushed the feat/issue-2344-token-metadata branch from c420686 to 2c4bdd6 Compare February 5, 2026 04:51
Copy link
Contributor

@PhilippGackstatter PhilippGackstatter left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@PhilippGackstatter PhilippGackstatter merged commit a23059f into 0xMiden:next Feb 5, 2026
15 checks passed
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.

Implement standard TokenMetadata storage slot

2 participants