Extensions

Token Extensionsとは何ですか?

Token Extensions Program(Token 2022)は、エクステンションと呼ばれる追加の命令を通じてより多くの機能を提供します。エクステンションはトークンミントまたはトークンアカウントに追加できるオプション機能です。これらのエクステンション命令の実装はToken Extensions Programのソースコードで確認できます。

各エクステンションは、通常ミントまたはトークンアカウントの作成時に初期化される特定の状態を追加します。どちらのアカウントを初期化する際も、異なる機能のために特定のエクステンションを同時に有効にすることができます。ほとんどのエクステンションはアカウントが初期化された後に追加することはできません。これはトークンを設計する際の重要な考慮事項であり、トークンがサポートしたい機能を事前に計画する必要があります。各エクステンションの統合ガイドはToken Extensions開発者ドキュメントで利用可能です。

一部のエクステンションは互いに互換性がなく、同じトークンミントやトークンアカウントで同時に有効にすることはできません。例えば、_rsNonTransferable_エクステンションと_rsTransferFeeConfig_エクステンションは、互いに競合する動作を持つため組み合わせることができません。

Token Extensions Programは、トークンミントまたはトークンアカウントに追加できるすべての利用可能なエクステンションをリストするExtensionType列挙型を定義しています。各バリアントは、固有の機能を持つ異なるエクステンションを表しています。

*rsExtensionType*列挙型は次のように定義されています:

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,
}

各エクステンションは、ミントまたはトークンアカウントに追加の状態を含めることで、特殊な機能を追加します。すべてのエクステンション固有の状態は、基本アカウントデータ型に続くtlv_dataフィールドに格納されます。そのアカウントで有効になっている特定のエクステンションタイプに従って、tlv_data(エクステンション状態を含む)をさらにデシリアライズする必要があります。

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?

目次

ページを編集