Class: Solace::Composers::SplTokenProgramTransferCheckedComposer

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

Overview

Composer for creating a SPL Token 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::SplToken::TransferCheckedInstruction`).

It is used for transferring SPL tokens with decimal precision and validation checks.

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: SPL Token program (readonly, non-signer)

Examples:

Compose and build a transfer_checked instruction

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

See Also:

Since:

  • 0.0.3

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 lamports to transfer

Returns:

  • (Integer)

    The lamports to transfer

Since:

  • 0.0.3



73
74
75
# File 'lib/solace/composers/spl_token_program_transfer_checked_composer.rb', line 73

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.0.3



52
53
54
# File 'lib/solace/composers/spl_token_program_transfer_checked_composer.rb', line 52

def authority
  params[:authority].to_s
end

#build_instruction(account_context) ⇒ Solace::Instruction

Build instruction with resolved account indices

Parameters:

Returns:

Since:

  • 0.0.3



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/solace/composers/spl_token_program_transfer_checked_composer.rb', line 100

def build_instruction()
  Instructions::SplToken::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(spl_token_program)
  )
end

#decimalsInteger

Returns the decimals for the mint of the token

Returns:

  • (Integer)

    The decimals for the mint

Since:

  • 0.0.3



80
81
82
# File 'lib/solace/composers/spl_token_program_transfer_checked_composer.rb', line 80

def decimals
  params[:decimals]
end

#fromString

Extracts the from address from the params

Returns:

  • (String)

    The from address

Since:

  • 0.0.3



43
44
45
# File 'lib/solace/composers/spl_token_program_transfer_checked_composer.rb', line 43

def from
  params[:from].to_s
end

#mintString

Extracts the mint address from the params

Returns:

  • (String)

    The mint address

Since:

  • 0.0.3



59
60
61
# File 'lib/solace/composers/spl_token_program_transfer_checked_composer.rb', line 59

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.0.3



88
89
90
91
92
93
94
# File 'lib/solace/composers/spl_token_program_transfer_checked_composer.rb', line 88

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

#spl_token_programString

Returns the spl token program id

Returns:

  • (String)

    The spl token program id

Since:

  • 0.0.3



66
67
68
# File 'lib/solace/composers/spl_token_program_transfer_checked_composer.rb', line 66

def spl_token_program
  Constants::TOKEN_PROGRAM_ID.to_s
end

#toString

Extracts the to address from the params

Returns:

  • (String)

    The to address

Since:

  • 0.0.3



36
37
38
# File 'lib/solace/composers/spl_token_program_transfer_checked_composer.rb', line 36

def to
  params[:to].to_s
end