Class: Solace::Composers::SquadsSmartAccountsCloseTransactionComposer

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

Overview

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

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

Required params:

:settings                   [#to_s] Base58 address of the settings account.
:proposal                   [#to_s] The Proposal PDA to close.
:transaction                [#to_s] The vault Transaction 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)


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

def build_instruction(context)
  SquadsSmartAccounts::Instructions::CloseTransactionInstruction.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



58
59
60
# File 'lib/solace/squads_smart_accounts/composers/close_transaction_composer.rb', line 58

def program_id
  SquadsSmartAccounts::PROGRAM_ID
end

#proposalString

Extracts the proposal PDA address from the params

Returns:

  • (String)

    The proposal address



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

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



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

def proposal_rent_collector
  params[:proposal_rent_collector].to_s
end

#settingsString

Extracts the settings address from the params

Returns:

  • (String)

    The settings address



23
24
25
# File 'lib/solace/squads_smart_accounts/composers/close_transaction_composer.rb', line 23

def settings
  params[:settings].to_s
end

#setup_accountsObject

Declares all accounts required by this instruction.



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

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



65
66
67
# File 'lib/solace/squads_smart_accounts/composers/close_transaction_composer.rb', line 65

def system_program
  Solace::Constants::SYSTEM_PROGRAM_ID
end

#transactionString

Extracts the transaction PDA address from the params

Returns:

  • (String)

    The transaction address



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

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



51
52
53
# File 'lib/solace/squads_smart_accounts/composers/close_transaction_composer.rb', line 51

def transaction_rent_collector
  params[:transaction_rent_collector].to_s
end