Class: Solace::Composers::SplTokenProgramTransferComposer
- Defined in:
- lib/solace/composers/spl_token_program_transfer_composer.rb
Overview
Composer for creating a SPL Token Program Transfer instruction.
This composer resolves and orders the required accounts for a ‘Transfer` instruction, sets up their access permissions, and delegates construction to the appropriate instruction builder (`Instructions::SplToken::TransferInstruction`).
It is used for transferring SPL tokens with decimal precision and validation checks.
Required accounts:
-
Owner: token account owner (writable, signer)
-
Source: source token account (writable, non-signer)
-
Destination: destination token account (writable, non-signer)
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#amount ⇒ Integer
Returns the lamports to transfer.
-
#build_instruction(account_context) ⇒ Solace::Instruction
Build instruction with resolved account indices.
-
#destination ⇒ String
Extracts the destination associated token address from the params.
-
#owner ⇒ String
Extracts the owner address from the params.
-
#setup_accounts ⇒ void
Setup accounts required for transfer instruction Called automatically during initialization.
-
#source ⇒ String
Extracts the source associated token address from the params.
-
#spl_token_program ⇒ String
Returns the spl token program id.
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
60 61 62 |
# File 'lib/solace/composers/spl_token_program_transfer_composer.rb', line 60 def amount params[:amount] end |
#build_instruction(account_context) ⇒ Solace::Instruction
Build instruction with resolved account indices
79 80 81 82 83 84 85 86 87 |
# File 'lib/solace/composers/spl_token_program_transfer_composer.rb', line 79 def build_instruction(account_context) Instructions::SplToken::TransferInstruction.build( amount: amount, owner_index: account_context.index_of(owner), source_index: account_context.index_of(source), destination_index: account_context.index_of(destination), program_index: account_context.index_of(spl_token_program) ) end |
#destination ⇒ String
Extracts the destination associated token address from the params
46 47 48 |
# File 'lib/solace/composers/spl_token_program_transfer_composer.rb', line 46 def destination params[:destination].to_s end |
#owner ⇒ String
Extracts the owner address from the params
32 33 34 |
# File 'lib/solace/composers/spl_token_program_transfer_composer.rb', line 32 def owner params[:owner].to_s end |
#setup_accounts ⇒ void
This method returns an undefined value.
Setup accounts required for transfer instruction Called automatically during initialization
68 69 70 71 72 73 |
# File 'lib/solace/composers/spl_token_program_transfer_composer.rb', line 68 def setup_accounts account_context.add_writable_signer(owner) account_context.add_writable_nonsigner(source) account_context.add_writable_nonsigner(destination) account_context.add_readonly_nonsigner(spl_token_program) end |
#source ⇒ String
Extracts the source associated token address from the params
39 40 41 |
# File 'lib/solace/composers/spl_token_program_transfer_composer.rb', line 39 def source params[:source].to_s end |
#spl_token_program ⇒ String
Returns the spl token program id
53 54 55 |
# File 'lib/solace/composers/spl_token_program_transfer_composer.rb', line 53 def spl_token_program Constants::TOKEN_PROGRAM_ID.to_s end |