Class: Solace::Composers::SplTokenProgramMintToComposer

Inherits:
Base
  • Object
show all
Defined in:
lib/solace/composers/spl_token_program_mint_to_composer.rb

Overview

Composer for creating a MintTo instruction for the SPL Token Program.

This composer builds a MintTo instruction that can be added to a transaction to mint tokens to a specified token account. It is used to mint new tokens for a given mint and destination account.

Required accounts:

- **Mint**: The mint account (writable, non-signer)
- **Destination**: The token account to mint to (writable, non-signer)
- **Mint Authority**: The mint authority account (readonly, signer)

Examples:

Build a MintTo instruction

composer = Solace::Composers::SplTokenProgramMintToComposer.new(
  mint: mint,
  destination: destination,
  mint_authority: mint_authority,
  amount: 100
)

Since:

  • 0.1.0

Instance Attribute Summary

Attributes inherited from Base

#account_context, #params

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Solace::Composers::Base

Instance Method Details

#amountInteger

Extracts the amount from the params

Returns:

  • (Integer)

    The amount

Since:

  • 0.1.0



56
57
58
# File 'lib/solace/composers/spl_token_program_mint_to_composer.rb', line 56

def amount
  params[:amount].to_i
end

#build_instruction(account_context) ⇒ Solace::Instruction

Build instruction with resolved account indices

Parameters:

Returns:

Since:

  • 0.1.0



75
76
77
78
79
80
81
82
83
# File 'lib/solace/composers/spl_token_program_mint_to_composer.rb', line 75

def build_instruction()
  Instructions::SplToken::MintToInstruction.build(
    amount: amount,
    mint_index: .index_of(mint),
    destination_index: .index_of(destination),
    mint_authority_index: .index_of(mint_authority),
    program_index: .index_of(spl_token_program)
  )
end

#destinationString

Extracts the destination address from the params

Returns:

  • (String)

    The destination address

Since:

  • 0.1.0



35
36
37
# File 'lib/solace/composers/spl_token_program_mint_to_composer.rb', line 35

def destination
  params[:destination].to_s
end

#mintString

Extracts the mint address from the params

Returns:

  • (String)

    The mint address

Since:

  • 0.1.0



28
29
30
# File 'lib/solace/composers/spl_token_program_mint_to_composer.rb', line 28

def mint
  params[:mint].to_s
end

#mint_authorityString

Extracts the mint authority address from the params

Returns:

  • (String)

    The mint authority address

Since:

  • 0.1.0



42
43
44
# File 'lib/solace/composers/spl_token_program_mint_to_composer.rb', line 42

def mint_authority
  params[:mint_authority].to_s
end

#setup_accountsvoid

This method returns an undefined value.

Setup accounts required for MintTo instruction Called automatically during initialization

Since:

  • 0.1.0



64
65
66
67
68
69
# File 'lib/solace/composers/spl_token_program_mint_to_composer.rb', line 64

def setup_accounts
  .add_writable_nonsigner(mint)
  .add_writable_nonsigner(destination)
  .add_readonly_signer(mint_authority)
  .add_readonly_nonsigner(spl_token_program)
end

#spl_token_programString

Returns the spl token program id

Returns:

  • (String)

    The spl token program id

Since:

  • 0.1.0



49
50
51
# File 'lib/solace/composers/spl_token_program_mint_to_composer.rb', line 49

def spl_token_program
  Constants::TOKEN_PROGRAM_ID.to_s
end