Extensions

Token Extensions nedir?

Token Extensions Program (Token 2022), uzantılar olarak adlandırılan ekstra talimatlar aracılığıyla daha fazla özellik sunar. Uzantılar, bir token mint'ine veya token hesabına ekleyebileceğiniz isteğe bağlı özelliklerdir. Bu uzantı talimatlarının uygulamasını Token Extensions Program kaynak kodunda bulabilirsiniz.

Her uzantı, genellikle mint veya token hesabı oluşturma sırasında başlatılan belirli bir durum ekler. Her iki hesabı başlatırken de, farklı işlevsellik için belirli uzantıları aynı anda etkinleştirebilirsiniz. Çoğu uzantı, bir hesap başlatıldıktan sonra eklenemez. Bu, tokeninizi tasarlarken önemli bir husustur, çünkü tokeninizin hangi özellikleri desteklemesini istediğinizi önceden planlamanız gerekecektir. Her uzantı için entegrasyon kılavuzları Token Extensions geliştirici belgelerinde mevcuttur.

Bazı uzantılar birbiriyle uyumsuzdur ve aynı token mint'inde veya token hesabında aynı anda etkinleştiremezsiniz. Örneğin, NonTransferable uzantısını TransferFeeConfig uzantısıyla birleştiremezsiniz, çünkü çakışan davranışlara sahiptirler.

Token Extensions Program, bir token mint'ine veya token hesabına ekleyebileceğiniz tüm mevcut uzantıları listeleyen bir ExtensionType enum'u tanımlar. Her varyant, benzersiz işlevselliğe sahip farklı bir uzantıyı temsil eder.

ExtensionType enum'u aşağıdaki gibi tanımlanmıştır:

Token Extensions
/// 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
/// multisig
Uninitialized,
/// Includes transfer fee rate info and accompanying authorities to withdraw
/// and set the fee
TransferFeeConfig,
/// Includes withheld transfer fees
TransferFeeAmount,
/// Includes an optional mint close authority
MintCloseAuthority,
/// Auditor configuration for confidential transfers
ConfidentialTransferMint,
/// State for confidential transfers
ConfidentialTransferAccount,
/// Specifies the default Account::state for new Accounts
DefaultAccountState,
/// Indicates that the Account owner authority cannot be changed
ImmutableOwner,
/// Require inbound transfers to have memo
MemoTransfer,
/// Indicates that the tokens from this mint can't be transferred
NonTransferable,
/// Tokens accrue interest over time,
InterestBearingConfig,
/// Locks privileged token operations from happening via CPI
CpiGuard,
/// Includes an optional permanent delegate
PermanentDelegate,
/// Indicates that the tokens in this account belong to a non-transferable
/// mint
NonTransferableAccount,
/// Mint requires a CPI to a program implementing the "transfer hook"
/// interface
TransferHook,
/// Indicates that the tokens in this account belong to a mint with a
/// transfer hook
TransferHookAccount,
/// Includes encrypted withheld fees and the encryption public that they are
/// encrypted under
ConfidentialTransferFeeConfig,
/// Includes confidential withheld transfer fees
ConfidentialTransferFeeAmount,
/// Mint contains a pointer to another account (or the same account) that
/// holds metadata
MetadataPointer,
/// Mint contains token-metadata
TokenMetadata,
/// Mint contains a pointer to another account (or the same account) that
/// holds group configurations
GroupPointer,
/// Mint contains token group configurations
TokenGroup,
/// Mint contains a pointer to another account (or the same account) that
/// holds group member configurations
GroupMemberPointer,
/// Mint contains token group member configurations
TokenGroupMember,
/// Mint allowing the minting and burning of confidential tokens
ConfidentialMintBurn,
/// Tokens whose UI amount is scaled by a given amount
ScaledUiAmount,
/// Tokens where minting / burning / transferring can be paused
Pausable,
/// Indicates that the account belongs to a pausable mint
PausableAccount,
/// 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,
}

Her uzantı, bir mint'e veya token hesabına ekstra durum ekleyerek özel işlevsellik katar. Tüm uzantıya özgü durum, temel hesap veri türünü takip eden tlv_data alanında saklanır. tlv_data (uzantı durumunu içeren) öğesini, o hesap için etkinleştirilen belirli uzantı türlerine göre daha fazla seri durumdan çıkarmanız gerekir.

Token Extensions
/// 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 data
pub base: &'data S,
/// Slice of data containing all TLV data, deserialized on demand
tlv_data: &'data [u8],
}

Is this page helpful?

İçindekiler

Sayfayı Düzenle