Extensions
Що таке Token Extensions?
Token Extensions Program (Token 2022) надає більше можливостей через додаткові інструкції, які називаються розширеннями. Extensions — це додаткові функції, які можна додати до токен-мінту або токен-рахунку. Ви можете знайти реалізацію цих інструкцій розширення у вихідному коді Token Extensions Program source code.
Кожне розширення додає специфічний стан, який зазвичай ініціалізується під час створення мінту або токен-рахунку. При ініціалізації будь-якого рахунку ви можете одночасно активувати конкретні розширення для різних функцій. Більшість розширень не можна додати після ініціалізації рахунку. Це важливий фактор при розробці вашого токена, оскільки вам потрібно заздалегідь планувати, які функції ви хочете підтримувати у своєму токені. Посібники з інтеграції для кожного розширення доступні в документації для розробників Token Extensions.
Деякі розширення несумісні між собою, і ви не можете активувати їх одночасно
на одному токен-мінті або токен-рахунку. Наприклад, ви не можете поєднувати
розширення NonTransferable
з розширенням TransferFeeConfig
,
оскільки вони мають конфліктуючу поведінку.
Token Extensions Program визначає
ExtensionType
перелік, який містить усі доступні розширення, які можна додати до токен-мінту
або токен- рахунку. Кожен варіант представляє різне розширення з унікальною
функціональністю.
Перелік ExtensionType
визначається наступним чином:
/// 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,}
Кожне розширення додає спеціалізовану функціональність, включаючи додатковий
стан до мінту або токен-рахунку. Весь специфічний для розширення стан
зберігається в полі
tlv_data
,
яке слідує за базовим типом даних рахунку. Ви повинні додатково десеріалізувати
tlv_data
(що містить стан розширення) відповідно до конкретних типів
розширення, активованих для цього рахунку.
/// 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?