TokenWrapInstruction

Enum TokenWrapInstruction 

Source
#[repr(u8)]
pub enum TokenWrapInstruction { CreateMint { idempotent: bool, }, Wrap { amount: u64, }, Unwrap { amount: u64, }, CloseStuckEscrow, SyncMetadataToToken2022, SyncMetadataToSplToken, }
Expand description

Instructions supported by the Token Wrap program

Variants§

§

CreateMint

Create a wrapped token mint. Assumes caller has pre-funded wrapped mint and backpointer account. Supports both directions:

  • spl-token to token-2022
  • token-2022 to spl-token
  • token-2022 to token-2022 w/ new extensions

Accounts expected by this instruction:

  1. [w] Unallocated wrapped mint account to create (PDA), address must be: get_wrapped_mint_address(unwrapped_mint_address, wrapped_token_program_id)
  2. [w] Unallocated wrapped backpointer account to create (PDA) get_wrapped_mint_backpointer_address(wrapped_mint_address)
  3. [] Existing unwrapped mint
  4. [] System program
  5. [] SPL Token program for wrapped mint

Fields

§idempotent: bool

If true, idempotent creation. If false, fail if the mint already exists.

§

Wrap

Wrap tokens

Move a user’s unwrapped tokens into an escrow account and mint the same number of wrapped tokens into the provided account.

Accounts expected by this instruction:

  1. [w] Recipient wrapped token account
  2. [w] Wrapped mint, must be initialized, address must be: get_wrapped_mint_address(unwrapped_mint_address, wrapped_token_program_id)
  3. [] Wrapped mint authority, address must be: get_wrapped_mint_authority(wrapped_mint)
  4. [] SPL Token program for unwrapped mint
  5. [] SPL Token program for wrapped mint
  6. [w] Unwrapped token account to wrap get_wrapped_mint_authority(wrapped_mint_address)
  7. [] Unwrapped token mint
  8. [w] Escrow of unwrapped tokens, address must be an ATA: get_escrow_address(unwrapped_mint, unwrapped_token_program, wrapped_token_program)
  9. [s] Transfer authority on unwrapped token account. Not required to be a signer if it’s a multisig.
  10. ..8+M [s] (Optional) M multisig signers on unwrapped token account.

Fields

§amount: u64

little-endian u64 representing the amount to wrap

§

Unwrap

Unwrap tokens

Burn user wrapped tokens and transfer the same amount of unwrapped tokens from the escrow account to the provided account.

Accounts expected by this instruction: 0. [w] Escrow of unwrapped tokens, address must be an ATA: get_escrow_address(unwrapped_mint, unwrapped_token_program, wrapped_token_program)

  1. [w] Recipient unwrapped tokens
  2. [] Wrapped mint authority, address must be: get_wrapped_mint_authority(wrapped_mint)
  3. [] Unwrapped token mint
  4. [] SPL Token program for wrapped mint
  5. [] SPL Token program for unwrapped mint
  6. [w] Wrapped token account to unwrap
  7. [w] Wrapped mint, address must be: get_wrapped_mint_address(unwrapped_mint_address, wrapped_token_program_id)
  8. [s] Transfer authority on wrapped token account
  9. ..8+M [s] (Optional) M multisig signers on wrapped token account

Fields

§amount: u64

little-endian u64 representing the amount to unwrap

§

CloseStuckEscrow

Closes a stuck escrow ATA. This is for the edge case where an unwrapped mint with a close authority is closed and then a new mint is created at the same address but with a different size, leaving the escrow ATA in a bad state.

This instruction will close the old escrow ATA, returning the lamports to the destination account. It will only work if the current escrow has different extensions than the mint. The client is then responsible for calling create_associated_token_account to recreate it.

Accounts expected by this instruction:

  1. [w] Escrow account to close (ATA)
  2. [w] Destination for lamports from closed account
  3. [] Unwrapped mint
  4. [] Wrapped mint
  5. [] Wrapped mint authority (PDA)
  6. [] Token-2022 program
§

SyncMetadataToToken2022

This instruction copies the metadata fields from an unwrapped mint to its wrapped mint TokenMetadata extension.

Supports (unwrapped to wrapped):

  • Token-2022 to Token-2022
  • SPL-token to Token-2022

If source mint is a Token-2022, it must have a MetadataPointer and the account it points to must be provided. If source mint is an SPL-Token, the Metaplex PDA must be provided.

If the TokenMetadata extension on the wrapped mint if not present, it will initialize it. The client is responsible for funding the wrapped mint account with enough lamports to cover the rent for the additional space required by the TokenMetadata extension and/or metadata sync.

Accounts expected by this instruction:

  1. [w] Wrapped mint
  2. [] Wrapped mint authority PDA
  3. [] Unwrapped mint
  4. [] Token-2022 program
  5. [] (Optional) Source metadata account. Required if metadata pointer indicates external account.
  6. [] (Optional) Owner program. Required when metadata account is owned by a third-party program.
§

SyncMetadataToSplToken

This instruction copies the metadata fields from an unwrapped mint to its wrapped mint Metaplex metadata account.

Supports (unwrapped to wrapped):

  • Token-2022 to SPL-token
  • SPL-token to SPL-token

This instruction will create the Metaplex metadata account if it doesn’t exist, or update it if it does. The wrapped_mint_authority PDA must be pre-funded with enough lamports to cover the rent for the Metaplex metadata account’s creation or updates, as it will act as the payer for the Metaplex program CPI.

If source mint is a Token-2022, it must have a MetadataPointer and the account it points to must be provided. If source mint is an SPL-Token, the Metaplex PDA must be provided.

Accounts expected by this instruction:

  1. [w] Metaplex metadata account
  2. [w] Wrapped mint authority (PDA)
  3. [] Wrapped SPL Token mint
  4. [] Unwrapped mint
  5. [] Metaplex Token Metadata Program
  6. [] System program
  7. [] Rent sysvar
  8. [] (Optional) Source metadata account. Required if unwrapped mint is an SPL-Token or, if a Token-2022, its metadata pointer indicates an external account.
  9. [] (Optional) Owner program. Required when metadata account is owned by a third-party program.

Implementations§

Source§

impl TokenWrapInstruction

Source

pub fn pack(&self) -> Vec<u8>

Packs a TokenWrapInstruction into a byte array.

Source

pub fn unpack(input: &[u8]) -> Result<Self, ProgramError>

Unpacks a byte array into a TokenWrapInstruction.

Trait Implementations§

Source§

impl Clone for TokenWrapInstruction

Source§

fn clone(&self) -> TokenWrapInstruction

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TokenWrapInstruction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for TokenWrapInstruction

Source§

fn eq(&self, other: &TokenWrapInstruction) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for TokenWrapInstruction

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V