Class: Solace::Composers::Token2022ProgramTransferComposer

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

Overview

Composer for creating a Token-2022 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::Token2022::TransferInstruction`).

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 = Token2022ProgramTransferComposer.new(
  amount: 1_000_000,
  owner: owner_address,
  source: source_address,
  destination: destination_address,
)

See Also:

Since:

  • 0.1.5

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.5



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

def amount
  params[:amount]
end

#build_instruction(account_context) ⇒ Solace::Instruction

Build instruction with resolved account indices

Parameters:

Returns:

Since:

  • 0.1.5



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

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

#destinationString

Extracts the destination associated token address from the params

Returns:

  • (String)

    The destination associated token address

Since:

  • 0.1.5



44
45
46
# File 'lib/solace/composers/token_2022_program_transfer_composer.rb', line 44

def destination
  params[:destination].to_s
end

#ownerString

Extracts the owner address from the params

Returns:

  • (String)

    The owner address

Since:

  • 0.1.5



30
31
32
# File 'lib/solace/composers/token_2022_program_transfer_composer.rb', line 30

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.5



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

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

#sourceString

Extracts the source associated token address from the params

Returns:

  • (String)

    The source associated token address

Since:

  • 0.1.5



37
38
39
# File 'lib/solace/composers/token_2022_program_transfer_composer.rb', line 37

def source
  params[:source].to_s
end

#token_2022_programString

Returns The Token-2022 program id.

Returns:

  • (String)

    The Token-2022 program id.

Since:

  • 0.1.5



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

def token_2022_program
  Constants::TOKEN_2022_PROGRAM_ID.to_s
end