3 unstable releases

0.2.3 Mar 28, 2024
0.2.2 Mar 28, 2024
0.1.1 Feb 5, 2024
0.1.0 Oct 24, 2023

#1752 in Magic Beans

Download history 12189/week @ 2024-01-05 12293/week @ 2024-01-12 17494/week @ 2024-01-19 10434/week @ 2024-01-26 17212/week @ 2024-02-02 11169/week @ 2024-02-09 14059/week @ 2024-02-16 15555/week @ 2024-02-23 16630/week @ 2024-03-01 17992/week @ 2024-03-08 19770/week @ 2024-03-15 19972/week @ 2024-03-22 39759/week @ 2024-03-29 59944/week @ 2024-04-05 33481/week @ 2024-04-12 26392/week @ 2024-04-19

163,368 downloads per month
Used in 373 crates (8 directly)

Apache-2.0

81KB
1.5K SLoC

Token-Group Interface

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

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

This interface is compatible with any program that implements the SPL Token interface. However, other program implementations that are not SPL Token programs may still be compatible with an SPL Token Group program should that program's token standard support the proper components such as mint and mint authority accounts (see Required Instructions).

There are also structs for TokenGroup and TokenGroupMember that may optionally be implemented, but are not required.

Example program

An example program demonstrating how to implement the SPL Token-Group Interface can be found in the example directory alongside this interface's directory.

In addition to demonstrating what a token-group program might look like, it also provides some reference examples for using the SPL Type Length Value library to manage TLV-encoded data within account data.

For more information on SPL Type Length Value you can reference the library's source code.

Motivation

As developers have engineered more creative ways to customize tokens and use them to power applications, communities, and more, the reliance on tokens that are intrinsically related through on-chain mapping has continued to strengthen.

Token-group provides developers with the minimum necessary interface components required to create these relational mappings, allowing for reliable composability as well as the freedom to customize these groups of tokens however one might please.

By implementing token-group, on-chain programs can build brand-new kinds of token groups, which can all overlap with each other and share common tooling.

Required Instructions

All of the following instructions are listed in greater detail in the source code.

Initialize Group

Initializes a token-group TLV entry in an account for group configurations with a provided maximum group size and update authority.

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

Update Group Max Size

Updates the maximum size limit of a group.

Must be signed by the update authority.

Update Group Authority

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

Must be signed by the update authority.

Initialize Member

Initializes a token-group TLV entry in an account for group member configurations.

Must provide an SPL token mint for both the group and the group member.

Must be signed by the member mint's mint authority and the group's update authority.

(Optional) State

A program that implements the interface may write the following data fields into a type-length-value entry into an account. Note the type discriminants for each.

For a group:

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

/// Type discriminant: [214, 15, 63, 132, 49, 119, 209, 40]
/// First 8 bytes of `hash("spl_token_group_interface:group")`
pub struct TokenGroup {
    /// The authority that can sign to update the group
    pub update_authority: OptionalNonZeroPubkey,
    /// The associated mint, used to counter spoofing to be sure that group
    /// belongs to a particular mint
    pub mint: Pubkey,
    /// The current number of group members
    pub size: PodU32,
    /// The maximum number of group members
    pub max_size: PodU32,
}

For a group member:

/// Type discriminant: [254, 50, 168, 134, 88, 126, 100, 186]
/// First 8 bytes of `hash("spl_token_group_interface:member")`
pub struct TokenGroupMember {
    /// The associated mint, used to counter spoofing to be sure that member
    /// belongs to a particular mint
    pub mint: Pubkey,
    /// The pubkey of the `TokenGroup`
    pub group: Pubkey,
    /// The member number
    pub member_number: PodU32,
}

By storing the configurations for either groups or group members in a TLV structure, a developer who implements this interface can freely add any other data fields in a different TLV entry.

As mentioned previously, you can find more information about TLV / type-length-value structures at the spl-type-length-value repo.

Dependencies

~21–29MB
~473K SLoC