Class: Solace::Instructions::SplToken::TransferCheckedInstruction
- Inherits:
-
Object
- Object
- Solace::Instructions::SplToken::TransferCheckedInstruction
- Defined in:
- lib/solace/instructions/spl_token/transfer_checked_instruction.rb
Overview
Service object for building an SPL Token Program transfer instruction
Constant Summary collapse
- INSTRUCTION_INDEX =
SPL Token Program instruction index for Transfer Checked
[12].freeze
Class Method Summary collapse
-
.build(amount:, decimals:, to_index:, from_index:, mint_index:, authority_index:, program_index: 3) ⇒ Solace::Instruction
Builds a Solace::Instruction for transferring SPL tokens.
-
.data(amount, decimals) ⇒ Array
Instruction data for a token transfer instruction.
Class Method Details
.build(amount:, decimals:, to_index:, from_index:, mint_index:, authority_index:, program_index: 3) ⇒ Solace::Instruction
Builds a Solace::Instruction for transferring SPL tokens
SPL Token Program transfer instruction layout:
- 1 byte: instruction index (12 for transfer checked)
- 8 bytes: amount (u64, little-endian)
- 8 bytes: decimals (u64, little-endian)
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/solace/instructions/spl_token/transfer_checked_instruction.rb', line 26 def self.build( amount:, decimals:, to_index:, from_index:, mint_index:, authority_index:, program_index: 3 ) Solace::Instruction.new.tap do |ix| ix.program_index = program_index ix.accounts = [from_index, mint_index, to_index, ] ix.data = data(amount, decimals) end end |
.data(amount, decimals) ⇒ Array
Instruction data for a token transfer instruction
The BufferLayout is:
- [Instruction Index (1 byte)]
- [Amount (8 bytes little-endian u64)]
- [Decimals (8 bytes little-endian u64)]
52 53 54 55 56 |
# File 'lib/solace/instructions/spl_token/transfer_checked_instruction.rb', line 52 def self.data(amount, decimals) INSTRUCTION_INDEX + Solace::Utils::Codecs.encode_le_u64(amount).bytes + [decimals] end |