Class: Solace::Instructions::SplToken::MintToInstruction

Inherits:
Object
  • Object
show all
Defined in:
lib/solace/instructions/spl_token/mint_to_instruction.rb

Overview

A class to build the MintTo instruction for the SPL Token Program.

Constant Summary collapse

INSTRUCTION_INDEX =
[7].freeze

Class Method Summary collapse

Class Method Details

.build(amount:, mint_index:, mint_authority_index:, destination_index:, program_index:) ⇒ Solace::Instruction

Builds a MintTo instruction.

Parameters:

  • amount (Integer)

    The amount of tokens to mint.

  • mint_index (Integer)

    The index of the mint account.

  • destination_index (Integer)

    The index of the token account to mint to.

  • mint_authority_index (Integer)

    The index of the mint authority account.

  • program_index (Integer)

    The index of the SPL Token Program.

Returns:



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/solace/instructions/spl_token/mint_to_instruction.rb', line 20

def self.build(
  amount:,
  mint_index:,
  mint_authority_index:,
  destination_index:,
  program_index:
)
  Solace::Instruction.new.tap do |ix|
    ix.program_index = program_index
    ix.accounts = [mint_index, destination_index, mint_authority_index]
    ix.data = data(amount)
  end
end

.data(amount) ⇒ Array

Builds the data for a MintTo instruction.

The BufferLayout is:

- [Instruction Index (1 byte)]
- [Amount (8 bytes)]

Parameters:

  • amount (Integer)

    The amount of tokens to mint.

Returns:

  • (Array)

    1-byte instruction index + 8-byte amount



42
43
44
# File 'lib/solace/instructions/spl_token/mint_to_instruction.rb', line 42

def self.data(amount)
  INSTRUCTION_INDEX + Solace::Utils::Codecs.encode_le_u64(amount).bytes
end