#interface #metadata #token #instructions #mint #authority #token-metadata

solarti-token-metadata-interface

Solarti Program Library Token Metadata Interface

5 releases

0.2.4 Mar 29, 2024
0.2.3 Dec 24, 2023
0.2.2 Nov 19, 2023
0.2.1 Nov 18, 2023
0.2.0 Nov 15, 2023

#304 in Magic Beans

Download history 149/week @ 2024-01-01 269/week @ 2024-01-08 209/week @ 2024-01-15 118/week @ 2024-01-22 240/week @ 2024-01-29 352/week @ 2024-02-05 270/week @ 2024-02-12 287/week @ 2024-02-19 452/week @ 2024-02-26 201/week @ 2024-03-04 210/week @ 2024-03-11 395/week @ 2024-03-18 439/week @ 2024-03-25 267/week @ 2024-04-01 126/week @ 2024-04-08 149/week @ 2024-04-15

991 downloads per month
Used in 67 crates (4 directly)

Apache-2.0

155KB
2.5K SLoC

Token-Metadata Interface

An interface describing the instructions required for a program to implement to be considered a "token-metadata" program for Solarti token mints. The interface can be implemented by any program.

With a common interface, any wallet, dapp, or on-chain program can read the metadata, and any tool that creates or modifies metadata will just work with any program that implements the interface.

There is also a TokenMetadata struct that may optionally be implemented, but is not required because of the Emit instruction, which indexers and other off-chain users can call to get metadata.

Example program

Coming soon!

Motivation

Token creators on Solana need all sorts of functionality for their token-metadata, and the Metaplex Token-Metadata program has been the one place for all metadata needs, leading to a feature-rich program that still might not serve all needs.

At its base, token-metadata is a set of data fields associated to a particular token mint, so we propose an interface that serves the simplest base case with some compatibility with existing solutions.

With this proposal implemented, fungible and non-fungible token creators will have two options:

  • implement the interface in their own program, so they can eventually extend it with new functionality or even other interfaces
  • use a reference program that implements the simplest case

Required Instructions

All of the following instructions are listed in greater detail in the source code. Once the interface is decided, the information in the source code will be copied here.

Initialize

Initializes the token-metadata TLV entry in an account with an update authority, name, symbol, and URI.

Must provide an Solarti token mint and be signed by the mint authority.

Update Field

Updates a field in a token-metadata account. This may be an existing or totally new field.

Must be signed by the update authority.

Remove Key

Unsets a key-value pair, clearing an existing entry.

Must be signed by the update authority.

Update Authority

Sets or unsets the token-metadata update authority, which signs any future updates to the metadata.

Must be signed by the update authority.

Emit

Emits token-metadata in the expected TokenMetadata state format. Although implementing a struct that uses the exact state is optional, this instruction is required.

(Optional) State

A program that implements the interface may write the following data fields into a type-length-value entry into an account:

type Pubkey = [u8; 32];
type OptionalNonZeroPubkey = Pubkey; // if all zeroes, interpreted as `None`

pub struct TokenMetadata {
    /// The authority that can sign to update the metadata
    pub update_authority: OptionalNonZeroPubkey,
    /// The associated mint, used to counter spoofing to be sure that metadata
    /// belongs to a particular mint
    pub mint: Pubkey,
    /// The longer name of the token
    pub name: String,
    /// The shortened symbol for the token
    pub symbol: String,
    /// The URI pointing to richer metadata
    pub uri: String,
    /// Any additional metadata about the token as key-value pairs. The program
    /// must avoid storing the same key twice.
    pub additional_metadata: Vec<(String, String)>,
}

By storing the metadata in a TLV structure, a developer who implements this interface in their program can freely add any other data fields in a different TLV entry.

You can find more information about TLV / type-length-value structures at the solarti-type-length-value repo.

Dependencies

~21–30MB
~475K SLoC