Class: Solace::Composers::SquadsSmartAccountsExecuteSettingsTransactionComposer

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

Overview

Composes an ‘executeSettingsTransaction` instruction for the Squads Smart Account program.

Applies the stored SettingsActions of an Approved proposal’s SettingsTransaction to the settings account. SpendingLimit PDAs touched by AddSpendingLimit / RemoveSpendingLimit actions are appended as remaining accounts in action order.

Required params:

:settings    [#to_s]          Base58 address of the settings account.
:signer      [#to_s, Keypair] The executing signer (must sign; needs Execute permission).
:proposal    [#to_s]          The Proposal PDA (must be Approved).
:transaction [#to_s]          The SettingsTransaction PDA to apply.
:rent_payer  [#to_s, Keypair] Pays for any settings realloc (must sign).

Optional params:

:spending_limit_accounts [Array<#to_s>] SpendingLimit PDAs initialized or
                         closed by the actions, in action order (default: []).

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)


98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/solace/squads_smart_accounts/composers/execute_settings_transaction_composer.rb', line 98

def build_instruction(context)
  SquadsSmartAccounts::Instructions::ExecuteSettingsTransactionInstruction.build(
    settings_index:         context.index_of(settings),
    signer_index:           context.index_of(signer),
    proposal_index:         context.index_of(proposal),
    transaction_index:      context.index_of(transaction),
    rent_payer_index:       context.index_of(rent_payer),
    system_program_index:   context.index_of(system_program),
    program_index:          context.index_of(program_id),
    spending_limit_indices: spending_limit_accounts.map { || context.index_of() }
  )
end

#program_idString

Returns the Squads Smart Account program id from the constants

Returns:

  • (String)

    The Squads Smart Account program id



69
70
71
# File 'lib/solace/squads_smart_accounts/composers/execute_settings_transaction_composer.rb', line 69

def program_id
  SquadsSmartAccounts::PROGRAM_ID
end

#proposalString

Extracts the proposal PDA address from the params

Returns:

  • (String)

    The proposal address



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

def proposal
  params[:proposal].to_s
end

#rent_payerString

Extracts the rent payer address from the params

Returns:

  • (String)

    The rent payer address



55
56
57
# File 'lib/solace/squads_smart_accounts/composers/execute_settings_transaction_composer.rb', line 55

def rent_payer
  params[:rent_payer].to_s
end

#settingsString

Extracts the settings address from the params

Returns:

  • (String)

    The settings address



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

def settings
  params[:settings].to_s
end

#setup_accountsObject

Declares all accounts required by this instruction.



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/solace/squads_smart_accounts/composers/execute_settings_transaction_composer.rb', line 81

def setup_accounts # rubocop:disable Metrics/AbcSize
  .add_writable_nonsigner(settings)
  .add_readonly_signer(signer)
  .add_writable_nonsigner(proposal)
  .add_readonly_nonsigner(transaction)
  .add_writable_signer(rent_payer)
  .add_readonly_nonsigner(system_program)
  .add_readonly_nonsigner(program_id)

  # SpendingLimit PDAs initialized/closed by the actions, in action order.
  spending_limit_accounts.each { || .add_writable_nonsigner() }
end

#signerString

Extracts the executing signer address from the params

Returns:

  • (String)

    The signer address



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

def signer
  params[:signer].to_s
end

#spending_limit_accountsArray<String>

Extracts the spending limit PDAs touched by the actions from the params

Returns:

  • (Array<String>)

    The spending limit addresses (defaults to [])



62
63
64
# File 'lib/solace/squads_smart_accounts/composers/execute_settings_transaction_composer.rb', line 62

def spending_limit_accounts
  (params[:spending_limit_accounts] || []).map(&:to_s)
end

#system_programString

Returns the system program id from the constants

Returns:

  • (String)

    The system program id



76
77
78
# File 'lib/solace/squads_smart_accounts/composers/execute_settings_transaction_composer.rb', line 76

def system_program
  Solace::Constants::SYSTEM_PROGRAM_ID
end

#transactionString

Extracts the settings transaction PDA address from the params

Returns:

  • (String)

    The transaction address



48
49
50
# File 'lib/solace/squads_smart_accounts/composers/execute_settings_transaction_composer.rb', line 48

def transaction
  params[:transaction].to_s
end