Extensions
Was sind Token Extensions?
Das Token Extensions Program (Token 2022) bietet mehr Funktionen durch zusätzliche Anweisungen, die als Extensions bezeichnet werden. Extensions sind optionale Funktionen, die Sie einem Token-Mint oder Token-Konto hinzufügen können. Die Implementierung dieser Extension-Anweisungen finden Sie im Token Extensions Program Quellcode.
Jede Extension fügt einen spezifischen Status hinzu, der in der Regel während der Mint- oder Token-Kontoerstellung initialisiert wird. Bei der Initialisierung eines Kontos können Sie bestimmte Extensions gleichzeitig für verschiedene Funktionalitäten aktivieren. Die meisten Extensions können nach der Initialisierung eines Kontos nicht mehr hinzugefügt werden. Dies ist eine wichtige Überlegung bei der Gestaltung Ihres Tokens, da Sie im Voraus planen müssen, welche Funktionen Ihr Token unterstützen soll. Integrationsanleitungen für jede Extension sind in der Token Extensions Entwicklerdokumentation verfügbar.
Einige Extensions sind miteinander inkompatibel und können nicht gleichzeitig
auf demselben Token-Mint oder Token-Konto aktiviert werden. Zum Beispiel
können Sie die NonTransferable
Extension nicht mit der
TransferFeeConfig
Extension kombinieren, da sie widersprüchliche
Verhaltensweisen haben.
Das Token Extensions Program definiert ein
ExtensionType
Enum, das alle verfügbaren Extensions auflistet, die Sie einem Token-Mint oder
Token- Konto hinzufügen können. Jede Variante repräsentiert eine andere
Extension mit einzigartiger Funktionalität.
Das ExtensionType
Enum ist wie folgt definiert:
/// Extensions that can be applied to mints or accounts. Mint extensions must/// only be applied to mint accounts, and account extensions must only be/// applied to token holding accounts.#[repr(u16)]#[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))]#[cfg_attr(feature = "serde-traits", serde(rename_all = "camelCase"))]#[derive(Clone, Copy, Debug, PartialEq, TryFromPrimitive, IntoPrimitive)]pub enum ExtensionType {/// Used as padding if the account size would otherwise be 355, same as a/// multisigUninitialized,/// Includes transfer fee rate info and accompanying authorities to withdraw/// and set the feeTransferFeeConfig,/// Includes withheld transfer feesTransferFeeAmount,/// Includes an optional mint close authorityMintCloseAuthority,/// Auditor configuration for confidential transfersConfidentialTransferMint,/// State for confidential transfersConfidentialTransferAccount,/// Specifies the default Account::state for new AccountsDefaultAccountState,/// Indicates that the Account owner authority cannot be changedImmutableOwner,/// Require inbound transfers to have memoMemoTransfer,/// Indicates that the tokens from this mint can't be transferredNonTransferable,/// Tokens accrue interest over time,InterestBearingConfig,/// Locks privileged token operations from happening via CPICpiGuard,/// Includes an optional permanent delegatePermanentDelegate,/// Indicates that the tokens in this account belong to a non-transferable/// mintNonTransferableAccount,/// Mint requires a CPI to a program implementing the "transfer hook"/// interfaceTransferHook,/// Indicates that the tokens in this account belong to a mint with a/// transfer hookTransferHookAccount,/// Includes encrypted withheld fees and the encryption public that they are/// encrypted underConfidentialTransferFeeConfig,/// Includes confidential withheld transfer feesConfidentialTransferFeeAmount,/// Mint contains a pointer to another account (or the same account) that/// holds metadataMetadataPointer,/// Mint contains token-metadataTokenMetadata,/// Mint contains a pointer to another account (or the same account) that/// holds group configurationsGroupPointer,/// Mint contains token group configurationsTokenGroup,/// Mint contains a pointer to another account (or the same account) that/// holds group member configurationsGroupMemberPointer,/// Mint contains token group member configurationsTokenGroupMember,/// Mint allowing the minting and burning of confidential tokensConfidentialMintBurn,/// Tokens whose UI amount is scaled by a given amountScaledUiAmount,/// Tokens where minting / burning / transferring can be pausedPausable,/// Indicates that the account belongs to a pausable mintPausableAccount,/// Test variable-length mint extension#[cfg(test)]VariableLenMintTest = u16::MAX - 2,/// Padding extension used to make an account exactly Multisig::LEN, used/// for testing#[cfg(test)]AccountPaddingTest,/// Padding extension used to make a mint exactly Multisig::LEN, used for/// testing#[cfg(test)]MintPaddingTest,}
Jede Extension fügt spezialisierte Funktionalität hinzu, indem sie zusätzlichen
Status zu einem Mint oder Token-Konto hinzufügt. Alle extensionsspezifischen
Statusdaten werden im
tlv_data
Feld gespeichert, das auf den Basis-Kontodatentyp folgt. Sie müssen das
tlv_data
(das den Extension-Status enthält) entsprechend den spezifischen
Extension- Typen, die für dieses Konto aktiviert sind, weiter deserialisieren.
/// Encapsulates immutable base state data (mint or account) with possible/// extensions, where the base state is Pod for zero-copy serde.#[derive(Debug, PartialEq)]pub struct PodStateWithExtensions<'data, S: BaseState + Pod> {/// Unpacked base datapub base: &'data S,/// Slice of data containing all TLV data, deserialized on demandtlv_data: &'data [u8],}
Is this page helpful?