Class: Solace::Composers::SquadsSmartAccountsCloseSettingsTransactionComposer

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

Overview

Composes a ‘closeSettingsTransaction` instruction for the Squads Smart Account program.

Closes a SettingsTransaction and its Proposal, refunding rent to the respective collectors. No smart-account signer is required — only the fee payer signs. The transaction is closeable once its proposal is terminal (Executed/Rejected/Cancelled) or stale.

Required params:

:settings                   [#to_s] Base58 address of the settings account.
:proposal                   [#to_s] The Proposal PDA to close.
:transaction                [#to_s] The SettingsTransaction PDA to close.
:proposal_rent_collector    [#to_s] Receives the proposal rent.
:transaction_rent_collector [#to_s] Receives the transaction rent (must equal
                                    transaction.rent_collector).

Instance Method Summary collapse

Instance Method Details

#build_instruction(context) ⇒ Solace::Instruction

Builds the instruction with resolved account indices.

Parameters:

  • context (Solace::Utils::AccountContext)

    Merged context from TransactionComposer.

Returns:

  • (Solace::Instruction)


85
86
87
88
89
90
91
92
93
94
95
# File 'lib/solace/squads_smart_accounts/composers/close_settings_transaction_composer.rb', line 85

def build_instruction(context)
  SquadsSmartAccounts::Instructions::CloseSettingsTransactionInstruction.build(
    settings_index:                   context.index_of(settings),
    proposal_index:                   context.index_of(proposal),
    transaction_index:                context.index_of(transaction),
    proposal_rent_collector_index:    context.index_of(proposal_rent_collector),
    transaction_rent_collector_index: context.index_of(transaction_rent_collector),
    system_program_index:             context.index_of(system_program),
    program_index:                    context.index_of(program_id)
  )
end

#program_idString

Returns the Squads Smart Account program id from the constants

Returns:

  • (String)

    The Squads Smart Account program id



59
60
61
# File 'lib/solace/squads_smart_accounts/composers/close_settings_transaction_composer.rb', line 59

def program_id
  SquadsSmartAccounts::PROGRAM_ID
end

#proposalString

Extracts the proposal PDA address from the params

Returns:

  • (String)

    The proposal address



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

def proposal
  params[:proposal].to_s
end

#proposal_rent_collectorString

Extracts the proposal rent collector address from the params

Returns:

  • (String)

    The proposal rent collector address



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

def proposal_rent_collector
  params[:proposal_rent_collector].to_s
end

#settingsString

Extracts the settings address from the params

Returns:

  • (String)

    The settings address



24
25
26
# File 'lib/solace/squads_smart_accounts/composers/close_settings_transaction_composer.rb', line 24

def settings
  params[:settings].to_s
end

#setup_accountsObject

Declares all accounts required by this instruction.



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

def setup_accounts
  .add_readonly_nonsigner(settings)
  .add_writable_nonsigner(proposal)
  .add_writable_nonsigner(transaction)
  .add_writable_nonsigner(proposal_rent_collector)
  .add_writable_nonsigner(transaction_rent_collector)
  .add_readonly_nonsigner(system_program)
  .add_readonly_nonsigner(program_id)
end

#system_programString

Returns the system program id from the constants

Returns:

  • (String)

    The system program id



66
67
68
# File 'lib/solace/squads_smart_accounts/composers/close_settings_transaction_composer.rb', line 66

def system_program
  Solace::Constants::SYSTEM_PROGRAM_ID
end

#transactionString

Extracts the settings transaction PDA address from the params

Returns:

  • (String)

    The transaction address



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

def transaction
  params[:transaction].to_s
end

#transaction_rent_collectorString

Extracts the transaction rent collector address from the params

Returns:

  • (String)

    The transaction rent collector address



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

def transaction_rent_collector
  params[:transaction_rent_collector].to_s
end