Extensions

Token Extensions란 무엇인가요?

Token Extensions Program(Token 2022)은 확장이라고 불리는 추가 명령을 통해 더 많은 기능을 제공합니다. Extensions는 토큰 민트나 토큰 계정에 추가할 수 있는 선택적 기능입니다. 이러한 확장 명령의 구현은 Token Extensions Program 소스 코드에서 찾을 수 있습니다.

각 확장은 일반적으로 민트나 토큰 계정 생성 중에 초기화되는 특정 상태를 추가합니다. 계정을 초기화할 때 다양한 기능을 위해 특정 확장을 동시에 활성화할 수 있습니다. 대부분의 확장은 계정이 초기화된 후에는 추가할 수 없습니다. 이는 토큰을 설계할 때 중요한 고려사항이므로, 토큰이 지원할 기능을 미리 계획해야 합니다. 각 확장에 대한 통합 가이드는 Token Extensions 개발자 문서에서 확인할 수 있습니다.

일부 확장은 서로 호환되지 않으며 동일한 토큰 민트나 토큰 계정에서 동시에 활성화할 수 없습니다. 예를 들어, NonTransferable 확장과 TransferFeeConfig 확장은 서로 충돌하는 동작을 가지고 있기 때문에 함께 사용할 수 없습니다.

Token Extensions Program은 토큰 민트나 토큰 계정에 추가할 수 있는 모든 사용 가능한 확장을 나열하는 ExtensionType 열거형을 정의합니다. 각 변형은 고유한 기능을 가진 다른 확장을 나타냅니다.

ExtensionType 열거형은 다음과 같이 정의됩니다:

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?

목차

페이지 편집