Class: Solace::Instructions::SplToken::InitializeMintInstruction

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

Constant Summary collapse

INSTRUCTION_INDEX =

Instruction index for Initialize Mint

[0].freeze

Class Method Summary collapse

Class Method Details

.build(decimals:, mint_authority:, rent_sysvar_index:, mint_account_index:, freeze_authority: nil, program_index: 2) ⇒ Solace::Instruction

Builds a Solace::Instruction for initializing an SPL Token Program mint

The BufferLayout is:

- [Instruction Index (1 byte)]
- [Decimals (1 byte)]
- [Mint authority (32 bytes)]
- [Freeze authority option (1 byte)]
- [Freeze authority (32 bytes)]

Parameters:

  • decimals (Integer)

    Number of decimals for the token

  • mint_authority (String)

    Public key of the mint authority

  • freeze_authority (String, nil) (defaults to: nil)

    Public key of the freeze authority

  • rent_sysvar_index (Integer)

    Index of the rent sysvar in the transaction’s accounts

  • mint_account_index (Integer)

    Index of the mint account in the transaction’s accounts

  • program_index (Integer) (defaults to: 2)

    Index of the SPL Token Program in the transaction’s accounts (default: 3)

Returns:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/solace/instructions/spl_token/initialize_mint_instruction.rb', line 26

def self.build(
  decimals:,
  mint_authority:,
  rent_sysvar_index:,
  mint_account_index:,
  freeze_authority: nil,
  program_index: 2
)
  Solace::Instruction.new.tap do |ix|
    ix.program_index = program_index
    ix.accounts = [, rent_sysvar_index]
    ix.data = data(decimals, mint_authority, freeze_authority)
  end
end

.data(decimals, mint_authority, freeze_authority) ⇒ Array

Instruction data for an initialize mint instruction

The BufferLayout is:

- [Instruction Index (1 byte)]
- [Decimals (1 byte)]
- [Mint authority (32 bytes)]
- [Freeze authority option (33 byte)]

Parameters:

  • decimals (Integer)

    Number of decimals for the token

  • mint_authority (String)

    Public key of the mint authority

  • freeze_authority (String, nil)

    Public key of the freeze authority

Returns:

  • (Array)

    1-byte instruction index + 1-byte decimals + 32-byte mint authority + 1-byte freeze authority option + 32-byte freeze authority



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/solace/instructions/spl_token/initialize_mint_instruction.rb', line 53

def self.data(decimals, mint_authority, freeze_authority)
  INSTRUCTION_INDEX +
    [decimals] +
    Solace::Utils::Codecs.base58_to_bytes(mint_authority) +
    (
      if freeze_authority
        [1] + Solace::Utils::Codecs.base58_to_bytes(freeze_authority)
      else
        [0]
      end
    )
end