Token Metadata extension to form standard#2439
Token Metadata extension to form standard#2439afa7789 wants to merge 113 commits into0xMiden:nextfrom
Conversation
55282e1 to
b1dba96
Compare
|
We should also consider adding the corresponding metadata and the new constructor to the network fungible faucets: https://github.com/afa7789/miden-base/blob/f7426116833b1f76da3195738ccb838a52880f80/crates/miden-standards/src/account/faucets/network_fungible.rs#L93-L101 |
|
@afa7789 we should also add a flag and procedure to change max_supply. It's basically similar to have we have done in |
In this branch ? pr ? |
Yes, it would be better if you can have this in this PR. |
|
@bobbinth @mmagician this is ready for review :) |
bobbinth
left a comment
There was a problem hiding this comment.
Not a review - but I left a couple of comments inline. The main one is about how we can handle returning large amounts of data from account interface procedures.
|
@afa7789 Additionally, as this discussion #2423 (comment) has been concluded, you can update the PR with the following:
For
|
5548bd5 to
609b355
Compare
| /// - Slot 12–17: logo_uri (6 Words) | ||
| /// - Slot 18–23: external_link (6 Words) | ||
| #[derive(Debug, Clone, Default)] | ||
| pub struct Info { |
There was a problem hiding this comment.
Why is this not part of TokenMetadata directly?
It feels very closely related, so I would consider including it. Making it a separate component means users always need to remember to include it in their account next to TokenMetadata and need to decode both TokenMetadata and Info to get all the related data, so this pushes some complexity up the stack.
It would also be nice if we could set mutability flags directly via the mentioned TokenMetadataBuilder, e.g. TokenMetadataBuilder::new(...).description("abc").mutable_description().build().
Related, I think Info does not be an AccountComponent, since it does not have any code. This suggests it is a set of standard storage slots but not a full account component (a combination of functionality / code and storage). So in the same way as TokenMetadata is not an account component (but more like a standardized storage slot), we could make Info a reusable set of storage slots. I would then include it in TokenMetadata, which in turn is included in BasicFungibleFaucet (a proper account component). Notably, this does not prevent reusing Info for other purposes in the future (such as for NFTs).
Naming: I think this is more aptly described as TokenMetadata. This is more generic metadata than what is currently called TokenMetadata which is specific to fungible assets. So maybe it is better to rename the current TokenMetadata to FungibleTokenMetadata to free up that name for this.
|
@PhilippGackstatter I did most of the mentioned things. |
ebcbd2e to
671a9dc
Compare
ecf267b to
2e50884
Compare
|
I rolled back the agglayer code and left a residue of TokenMetadata as before to try and touch it as little as possible. We can them in a future PR adapt it. To make easier reviewing this, since it's too big, we can close this or rebase this if needed. |
PhilippGackstatter
left a comment
There was a problem hiding this comment.
Thanks for the updates!
I left a few more comments, but am still in the process of getting through everything.
| const METADATA_SLOT=word("miden::standards::fungible_faucets::metadata") | ||
| # Note: this slot name should match TOKEN_METADATA_SLOT in metadata/fungible_faucet.masm. | ||
| const METADATA_SLOT=word("miden::standards::metadata::fungible_faucet::token_metadata") |
There was a problem hiding this comment.
We should be able to remove this, make the slot in crates/miden-standards/asm/standards/metadata/fungible_faucet.masm public and then import it here.
crates/miden-standards/asm/standards/metadata/fungible_faucet.masm
Outdated
Show resolved
Hide resolved
crates/miden-standards/asm/standards/metadata/fungible_faucet.masm
Outdated
Show resolved
Hide resolved
crates/miden-standards/asm/standards/metadata/fungible_faucet.masm
Outdated
Show resolved
Hide resolved
crates/miden-standards/src/account/metadata/token_metadata/fungible_token/mod.rs
Outdated
Show resolved
Hide resolved
| if max_supply.as_canonical_u64() > FungibleAsset::MAX_AMOUNT { | ||
| return Err(FungibleFaucetError::MaxSupplyTooLarge { | ||
| actual: max_supply.as_canonical_u64(), | ||
| max: FungibleAsset::MAX_AMOUNT, | ||
| }); | ||
| } | ||
| if token_supply.as_canonical_u64() > max_supply.as_canonical_u64() { | ||
| return Err(FungibleFaucetError::TokenSupplyExceedsMaxSupply { |
There was a problem hiding this comment.
We now have new_validated, could we now call it here instead of reimplementing the checks?
Self::new_validated(
symbol,
decimals,
max_supply,
token_supply,
metadata.name.ok_or_else(todo!()),
metadata.description,
metadata.logo_uri,
metadata.external_link,
);
crates/miden-standards/src/account/metadata/token_metadata/fungible_token/mod.rs
Outdated
Show resolved
Hide resolved
crates/miden-standards/src/account/metadata/token_metadata/fungible_token/mod.rs
Outdated
Show resolved
Hide resolved
crates/miden-standards/asm/standards/metadata/fungible_faucet.masm
Outdated
Show resolved
Hide resolved
PhilippGackstatter
left a comment
There was a problem hiding this comment.
I think the last merge commit broke a few things like removing some comments in faucets/mod.masm and deleting most of the changelog. Might be best to remove this commit and re-do the merge.
I left a few more comments to simplify the encoding/decoding logic and some structural comments, but overall I think we can soon merge.
I have yet to take a look at most the tests, though.
crates/miden-standards/src/account/metadata/token_metadata/fungible_token/mod.rs
Outdated
Show resolved
Hide resolved
crates/miden-standards/src/account/metadata/token_metadata/mod.rs
Outdated
Show resolved
Hide resolved
crates/miden-standards/src/account/metadata/token_metadata/mod.rs
Outdated
Show resolved
Hide resolved
crates/miden-standards/src/account/metadata/token_metadata/mod.rs
Outdated
Show resolved
Hide resolved
crates/miden-standards/src/account/metadata/token_metadata/mod.rs
Outdated
Show resolved
Hide resolved
crates/miden-standards/src/account/metadata/token_metadata/mod.rs
Outdated
Show resolved
Hide resolved
PhilippGackstatter
left a comment
There was a problem hiding this comment.
I left a few comments to remove duplicate tests or using more concise setups. Tests look good overall, thank you for setting them up in a well-structured way!
The size of the PR and the number of reviews made it tricky to keep track, so I'm not convinced I reviewed every single detail of the PR, but I think it can be merged, and so I'll approve it.
crates/miden-standards/src/account/metadata/token_metadata/fungible_token/builder.rs
Outdated
Show resolved
Hide resolved
|
Okay, @PhilippGackstatter , I will implement this changes above as soon as possible. :) |
Move max_supply validation and Felt conversion into new_validated so the check lives in exactly one place. Builder token_supply field is now u64 for API consistency, removing the Felt::new() with SAFETY comment.
Replace silent fallback to empty TokenName with ? operator so test failures surface the actual error instead of hiding it.
Use FungibleTokenMetadata::try_from(storage) to verify stored values instead of raw Felt::new comparisons on individual storage word elements.
Remove basic_faucet_name_readable_from_masm and network_faucet_name_readable_from_masm which are functionally equivalent to get_name_from_masm.
Already covered by basic_faucet_with_max_name_and_full_description which builds an account with a 32-byte name and verifies storage round-trip.
Delete name_33_bytes_rejected (already covered by token_name_too_long) and description_7_words_full_capacity from integration tests. Add description_7_words_full_capacity as a pure unit test in miden-standards using into_storage_slots() instead of building a full Account.
Replace manual Vec of cases with rstest #[case] attributes using build_faucet_metadata() + with_*_mutable() for conciseness. No content fields needed since these tests only check the flag bit.
Remove .add_note_script() from owner-succeeds test since notes already have code via .code(). Simplify non-owner-fails test by removing hash push and advice_map since the auth check fires before data is touched.
Change token name from "POL" (3 bytes, single word chunk) to "Polygon Token" (13 bytes) so both name_chunk_0 and name_chunk_1 are non-zero, exercising both storage slots.
The push.0 padding between successive call-convention getter invocations was unnecessary — call already pads the stack to 16 elements. Verified the test passes without them.
|
@PhilippGackstatter , you can do a last check before we merge I think so. |
PhilippGackstatter
left a comment
There was a problem hiding this comment.
Updates look great, thank you!
Unified metadata: One place for account/faucet metadata: token (symbol, decimals, max_supply), owner, name, and content URI. Slot names live under miden::standards::metadata::* (and ownable for owner).
Layout: Token metadata and owner in slots 0–1; name in 2 words (name_0, name_1); content URI in 6 words (content_uri_0..5). Same layout in Rust and MASM.
Faucets: Basic and network fungible faucets support optional name and content URI; both re-export metadata getters (get_name, get_content_uri, get_token_metadata, get_max_supply, get_decimals, get_token_symbol; network also get_owner).
Standalone Info: Non-faucet accounts can use the metadata Info component (name + content URI) for future use (e.g. NFTs).
Testing: Unit tests in miden-standards (metadata storage, recovery); integration tests in miden-testing (MASM getters, faucet + metadata).