Class: Solace::Composers::SplTokenProgramCloseAccountComposer

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

Overview

Composer for creating a SPL Token Program CloseAccount instruction.

This composer resolves and orders the required accounts for a ‘CloseAccount` instruction, sets up their access permissions, and delegates construction to the appropriate instruction builder.

The CloseAccount instruction closes a token account and transfers remaining lamports to a destination account. The account must have a balance of zero tokens.

Required accounts:

  • Account: token account to close (writable, non-signer)

  • Destination: account to receive lamports (writable, non-signer)

  • Authority: account authority (non-writable, signer)

Examples:

Compose and build a close account instruction

composer = SplTokenProgramCloseAccountComposer.new(
  account: ,
  destination: destination_address,
  authority: authority_address
)

Since:

  • 0.1.2

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

#accountString

Extracts the token account address from the params

Returns:

  • (String)

    The token account address

Since:

  • 0.1.2



31
32
33
# File 'lib/solace/composers/spl_token_program_close_account_composer.rb', line 31

def 
  params[:account].to_s
end

#authorityString

Extracts the authority address from the params

Returns:

  • (String)

    The authority address

Since:

  • 0.1.2



45
46
47
# File 'lib/solace/composers/spl_token_program_close_account_composer.rb', line 45

def authority
  params[:authority].to_s
end

#build_instruction(account_context) ⇒ Solace::Instruction

Build instruction with resolved account indices

Parameters:

Returns:

Since:

  • 0.1.2



71
72
73
74
75
76
77
78
# File 'lib/solace/composers/spl_token_program_close_account_composer.rb', line 71

def build_instruction()
  Instructions::SplToken::CloseAccountInstruction.build(
    account_index: .index_of(),
    authority_index: .index_of(authority),
    destination_index: .index_of(destination),
    program_index: .index_of(spl_token_program)
  )
end

#destinationString

Extracts the destination address from the params

Returns:

  • (String)

    The destination address

Since:

  • 0.1.2



38
39
40
# File 'lib/solace/composers/spl_token_program_close_account_composer.rb', line 38

def destination
  params[:destination].to_s
end

#setup_accountsvoid

This method returns an undefined value.

Setup accounts required for close account instruction Called automatically during initialization

Since:

  • 0.1.2



60
61
62
63
64
65
# File 'lib/solace/composers/spl_token_program_close_account_composer.rb', line 60

def setup_accounts
  .add_writable_nonsigner()
  .add_writable_nonsigner(destination)
  .add_readonly_signer(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.2



52
53
54
# File 'lib/solace/composers/spl_token_program_close_account_composer.rb', line 52

def spl_token_program
  Constants::TOKEN_PROGRAM_ID.to_s
end