Class: Solace::Composers::Token2022ProgramCloseAccountComposer

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

Overview

Composer for creating a Token-2022 Program CloseAccount instruction.

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 = Token2022ProgramCloseAccountComposer.new(
  account: ,
  destination: destination_address,
  authority: authority_address
)

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

#accountString

Extracts the token account address from the params

Returns:

  • (String)

    The token account address

Since:

  • 0.1.5



27
28
29
# File 'lib/solace/composers/token_2022_program_close_account_composer.rb', line 27

def 
  params[:account].to_s
end

#authorityString

Extracts the authority address from the params

Returns:

  • (String)

    The authority address

Since:

  • 0.1.5



41
42
43
# File 'lib/solace/composers/token_2022_program_close_account_composer.rb', line 41

def authority
  params[:authority].to_s
end

#build_instruction(account_context) ⇒ Solace::Instruction

Build instruction with resolved account indices

Parameters:

Returns:

Since:

  • 0.1.5



65
66
67
68
69
70
71
72
# File 'lib/solace/composers/token_2022_program_close_account_composer.rb', line 65

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

#destinationString

Extracts the destination address from the params

Returns:

  • (String)

    The destination address

Since:

  • 0.1.5



34
35
36
# File 'lib/solace/composers/token_2022_program_close_account_composer.rb', line 34

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



54
55
56
57
58
59
# File 'lib/solace/composers/token_2022_program_close_account_composer.rb', line 54

def setup_accounts
  .add_writable_nonsigner()
  .add_writable_nonsigner(destination)
  .add_readonly_signer(authority)
  .add_readonly_nonsigner(token_2022_program)
end

#token_2022_programString

Returns The Token-2022 program id.

Returns:

  • (String)

    The Token-2022 program id.

Since:

  • 0.1.5



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

def token_2022_program
  Constants::TOKEN_2022_PROGRAM_ID.to_s
end