Class: Solace::Composers::SquadsSmartAccountsExecuteSettingsTransactionSyncComposer

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

Overview

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

Synchronously applies a batch of SettingsActions to an autonomous smart account. The outer transaction must be co-signed by enough smart account signers to reach the settings threshold — controlled accounts are rejected by the program (use the *AsAuthority composers instead).

Required params:

:settings   [String]                 Base58 address of the settings account.
:signers    [Array<#to_s, Keypair>]  Co-signers proving threshold consensus.
:actions    [Array<SquadsSmartAccounts::SettingsAction>] Actions applied atomically.
:rent_payer [#to_s, Keypair]         Pays for settings reallocation (must sign).

Optional params:

:spending_limit_accounts [Array<#to_s>] SpendingLimit PDAs initialized or
                         closed by AddSpendingLimit/RemoveSpendingLimit
                         actions, in action order (default: []).
:memo [String] Indexing memo (default: nil).

Instance Method Summary collapse

Instance Method Details

#actionsArray<SquadsSmartAccounts::SettingsAction>

Extracts the settings actions from the params

Returns:



42
43
44
# File 'lib/solace/squads_smart_accounts/composers/execute_settings_transaction_sync_composer.rb', line 42

def actions
  params[:actions]
end

#build_instruction(context) ⇒ Solace::Instruction

Builds the instruction with resolved account indices.

Parameters:

  • context (Solace::Utils::AccountContext)

    Merged context from TransactionComposer.

Returns:

  • (Solace::Instruction)


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

def build_instruction(context)
  SquadsSmartAccounts::Instructions::ExecuteSettingsTransactionSyncInstruction.build(
    num_signers:            signers.length,
    actions:,
    memo:,
    settings_index:         context.index_of(settings),
    rent_payer_index:       context.index_of(rent_payer),
    system_program_index:   context.index_of(system_program),
    program_index:          context.index_of(program_id),
    signer_indices:         signers.map { |signer| context.index_of(signer) },
    spending_limit_indices: spending_limit_accounts.map { || context.index_of() }
  )
end

#memoString?

Extracts the memo from the params

Returns:

  • (String, nil)

    The memo



63
64
65
# File 'lib/solace/squads_smart_accounts/composers/execute_settings_transaction_sync_composer.rb', line 63

def memo
  params[:memo]
end

#program_idString

Returns the Squads Smart Account program id from the constants

Returns:

  • (String)

    The Squads Smart Account program id



70
71
72
# File 'lib/solace/squads_smart_accounts/composers/execute_settings_transaction_sync_composer.rb', line 70

def program_id
  SquadsSmartAccounts::PROGRAM_ID
end

#rent_payerString

Extracts the rent payer address from the params

Returns:

  • (String)

    The rent payer address



49
50
51
# File 'lib/solace/squads_smart_accounts/composers/execute_settings_transaction_sync_composer.rb', line 49

def rent_payer
  params[:rent_payer].to_s
end

#settingsString

Extracts the settings address from the params

Returns:

  • (String)

    The settings address



28
29
30
# File 'lib/solace/squads_smart_accounts/composers/execute_settings_transaction_sync_composer.rb', line 28

def settings
  params[:settings].to_s
end

#setup_accountsObject

Declares all accounts required by this instruction.



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

def setup_accounts
  .add_writable_nonsigner(settings)
  .add_writable_signer(rent_payer)
  .add_readonly_nonsigner(system_program)
  .add_readonly_nonsigner(program_id)

  # Co-signers proving threshold consensus (remaining accounts)
  signers.each { |signer| .add_readonly_signer(signer) }

  # SpendingLimit PDAs initialized/closed by the actions follow the signers
  spending_limit_accounts.each { || .add_writable_nonsigner() }
end

#signersArray<String>

Extracts the co-signer addresses from the params

Returns:

  • (Array<String>)

    The signer addresses



35
36
37
# File 'lib/solace/squads_smart_accounts/composers/execute_settings_transaction_sync_composer.rb', line 35

def signers
  params[:signers].map(&: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 [])



56
57
58
# File 'lib/solace/squads_smart_accounts/composers/execute_settings_transaction_sync_composer.rb', line 56

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



77
78
79
# File 'lib/solace/squads_smart_accounts/composers/execute_settings_transaction_sync_composer.rb', line 77

def system_program
  Solace::Constants::SYSTEM_PROGRAM_ID
end