Class: Solace::Composers::Token2022ProgramTransferCheckedComposer

Inherits:
Base
  • Object
show all
Defined in:
lib/solace/composers/token_2022_program_transfer_checked_composer.rb

Overview

Composer for creating a Token-2022 Program ‘TransferChecked` instruction.

This composer resolves and orders the required accounts for a ‘TransferChecked` instruction, sets up their access permissions, and delegates construction to the appropriate instruction builder (`Instructions::Token2022::TransferCheckedInstruction`).

Required accounts:

  • From: source token account (writable, non-signer)

  • To: destination token account (writable, non-signer)

  • Mint: mint address (readonly, non-signer)

  • Authority: token owner (writable, signer)

  • Program: Token-2022 program (readonly, non-signer)

Examples:

Compose and build a transfer_checked instruction

composer = Token2022ProgramTransferCheckedComposer.new(
  from: from_address,
  to: to_address,
  mint: mint_address,
  authority: authority_pubkey,
  amount: 1_000_000,
  decimals: 6
)

See Also:

Since:

  • 0.1.5

Instance Attribute Summary

Attributes inherited from Base

#account_context, #params

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Solace::Composers::Base

Instance Method Details

#amountInteger

Returns the amount to transfer

Returns:

  • (Integer)

    The amount to transfer

Since:

  • 0.1.5



69
70
71
# File 'lib/solace/composers/token_2022_program_transfer_checked_composer.rb', line 69

def amount
  params[:amount]
end

#authorityString

Extracts the authority address from the params

The authority is the owner of the token account

Returns:

  • (String)

    The authority address

Since:

  • 0.1.5



50
51
52
# File 'lib/solace/composers/token_2022_program_transfer_checked_composer.rb', line 50

def authority
  params[:authority].to_s
end

#build_instruction(account_context) ⇒ Solace::Instruction

Build instruction with resolved account indices

Parameters:

Returns:

Since:

  • 0.1.5



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/solace/composers/token_2022_program_transfer_checked_composer.rb', line 96

def build_instruction()
  Instructions::Token2022::TransferCheckedInstruction.build(
    amount: amount,
    decimals: decimals,
    to_index: .index_of(to),
    from_index: .index_of(from),
    mint_index: .index_of(mint),
    authority_index: .index_of(authority),
    program_index: .index_of(token_2022_program)
  )
end

#decimalsInteger

Returns the decimals for the mint of the token

Returns:

  • (Integer)

    The decimals for the mint

Since:

  • 0.1.5



76
77
78
# File 'lib/solace/composers/token_2022_program_transfer_checked_composer.rb', line 76

def decimals
  params[:decimals]
end

#fromString

Extracts the from address from the params

Returns:

  • (String)

    The from address

Since:

  • 0.1.5



41
42
43
# File 'lib/solace/composers/token_2022_program_transfer_checked_composer.rb', line 41

def from
  params[:from].to_s
end

#mintString

Extracts the mint address from the params

Returns:

  • (String)

    The mint address

Since:

  • 0.1.5



57
58
59
# File 'lib/solace/composers/token_2022_program_transfer_checked_composer.rb', line 57

def mint
  params[:mint].to_s
end

#setup_accountsvoid

This method returns an undefined value.

Setup accounts required for transfer instruction Called automatically during initialization

Since:

  • 0.1.5



84
85
86
87
88
89
90
# File 'lib/solace/composers/token_2022_program_transfer_checked_composer.rb', line 84

def setup_accounts
  .add_writable_signer(authority)
  .add_writable_nonsigner(to)
  .add_writable_nonsigner(from)
  .add_readonly_nonsigner(mint)
  .add_readonly_nonsigner(token_2022_program)
end

#toString

Extracts the to address from the params

Returns:

  • (String)

    The to address

Since:

  • 0.1.5



34
35
36
# File 'lib/solace/composers/token_2022_program_transfer_checked_composer.rb', line 34

def to
  params[:to].to_s
end

#token_2022_programString

Returns The Token-2022 program id.

Returns:

  • (String)

    The Token-2022 program id.

Since:

  • 0.1.5



62
63
64
# File 'lib/solace/composers/token_2022_program_transfer_checked_composer.rb', line 62

def token_2022_program
  Constants::TOKEN_2022_PROGRAM_ID.to_s
end