Class: Solace::Composers::SplTokenProgramTransferCheckedComposer
- 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)
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#amount ⇒ Integer
Returns the lamports to transfer.
-
#authority ⇒ String
Extracts the authority address from the params.
-
#build_instruction(account_context) ⇒ Solace::Instruction
Build instruction with resolved account indices.
-
#decimals ⇒ Integer
Returns the decimals for the mint of the token.
-
#from ⇒ String
Extracts the from address from the params.
-
#mint ⇒ String
Extracts the mint address from the params.
-
#setup_accounts ⇒ void
Setup accounts required for transfer instruction Called automatically during initialization.
-
#spl_token_program ⇒ String
Returns the spl token program id.
-
#to ⇒ String
Extracts the to address from the params.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Solace::Composers::Base
Instance Method Details
#amount ⇒ Integer
Returns the lamports to transfer
73 74 75 |
# File 'lib/solace/composers/spl_token_program_transfer_checked_composer.rb', line 73 def amount params[:amount] end |
#authority ⇒ String
Extracts the authority address from the params
The authority is the owner of the token account
52 53 54 |
# File 'lib/solace/composers/spl_token_program_transfer_checked_composer.rb', line 52 def params[:authority].to_s end |
#build_instruction(account_context) ⇒ Solace::Instruction
Build instruction with resolved account indices
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(account_context) Instructions::SplToken::TransferCheckedInstruction.build( amount: amount, decimals: decimals, to_index: account_context.index_of(to), from_index: account_context.index_of(from), mint_index: account_context.index_of(mint), authority_index: account_context.index_of(), program_index: account_context.index_of(spl_token_program) ) end |
#decimals ⇒ Integer
Returns the decimals for the mint of the token
80 81 82 |
# File 'lib/solace/composers/spl_token_program_transfer_checked_composer.rb', line 80 def decimals params[:decimals] end |
#from ⇒ String
Extracts the from address from the params
43 44 45 |
# File 'lib/solace/composers/spl_token_program_transfer_checked_composer.rb', line 43 def from params[:from].to_s end |
#mint ⇒ String
Extracts the mint address from the params
59 60 61 |
# File 'lib/solace/composers/spl_token_program_transfer_checked_composer.rb', line 59 def mint params[:mint].to_s end |
#setup_accounts ⇒ void
This method returns an undefined value.
Setup accounts required for transfer instruction Called automatically during initialization
88 89 90 91 92 93 94 |
# File 'lib/solace/composers/spl_token_program_transfer_checked_composer.rb', line 88 def setup_accounts account_context.add_writable_signer() account_context.add_writable_nonsigner(to) account_context.add_writable_nonsigner(from) account_context.add_readonly_nonsigner(mint) account_context.add_readonly_nonsigner(spl_token_program) end |
#spl_token_program ⇒ String
Returns the spl token program id
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 |
#to ⇒ String
Extracts the to address from the params
36 37 38 |
# File 'lib/solace/composers/spl_token_program_transfer_checked_composer.rb', line 36 def to params[:to].to_s end |