Class: Solace::Composers::SplTokenProgramTransferComposer

Inherits:
Base
  • Object
show all
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)

Examples:

Compose and build a transfer instruction

composer = SplTokenProgramTransferComposer.new(
  amount: 1_000_000,
  owner: owner_address,
  source: source_address,
  destination: destination_address,
)

See Also:

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

Returns the lamports to transfer

Returns:

  • (Integer)

    The lamports to transfer

Since:

  • 0.1.0



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

Parameters:

Returns:

Since:

  • 0.1.0



79
80
81
82
83
84
85
86
87
# File 'lib/solace/composers/spl_token_program_transfer_composer.rb', line 79

def build_instruction()
  Instructions::SplToken::TransferInstruction.build(
    amount: amount,
    owner_index: .index_of(owner),
    source_index: .index_of(source),
    destination_index: .index_of(destination),
    program_index: .index_of(spl_token_program)
  )
end

#destinationString

Extracts the destination associated token address from the params

Returns:

  • (String)

    The destination associated token address

Since:

  • 0.1.0



46
47
48
# File 'lib/solace/composers/spl_token_program_transfer_composer.rb', line 46

def destination
  params[:destination].to_s
end

#ownerString

Extracts the owner address from the params

Returns:

  • (String)

    The owner address

Since:

  • 0.1.0



32
33
34
# File 'lib/solace/composers/spl_token_program_transfer_composer.rb', line 32

def owner
  params[:owner].to_s
end

#setup_accountsvoid

This method returns an undefined value.

Setup accounts required for transfer instruction Called automatically during initialization

Since:

  • 0.1.0



68
69
70
71
72
73
# File 'lib/solace/composers/spl_token_program_transfer_composer.rb', line 68

def setup_accounts
  .add_writable_signer(owner)
  .add_writable_nonsigner(source)
  .add_writable_nonsigner(destination)
  .add_readonly_nonsigner(spl_token_program)
end

#sourceString

Extracts the source associated token address from the params

Returns:

  • (String)

    The source associated token address

Since:

  • 0.1.0



39
40
41
# File 'lib/solace/composers/spl_token_program_transfer_composer.rb', line 39

def source
  params[:source].to_s
end

#spl_token_programString

Returns the spl token program id

Returns:

  • (String)

    The spl token program id

Since:

  • 0.1.0



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