Class: Solace::Composers::SquadsSmartAccountsExecuteTransactionSyncComposer

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

Overview

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

Synchronously executes inner instructions signed by a smart account (vault) PDA. The outer transaction must be co-signed by enough smart account signers to reach the settings threshold — no proposal/voting lifecycle is involved.

Inner instructions are regular Solace composers (e.g. SystemProgramTransferComposer with the vault as :from). Their account requirements are merged into this composer’s context, and their built instructions are re-encoded into the Squads compiled wire format.

Required params:

:settings      [String]  Base58 address of the settings account.
:smart_account [String]  Base58 address of the vault PDA the inner
                         instructions spend from — derive via
                         Programs::SquadsSmartAccount.get_smart_account_address.
:signers       [Array<String>] Base58 pubkeys co-signing the outer transaction.
                         Must be exactly enough to reach the threshold.
:instructions  [Array<Solace::Composers::Base>] Inner instruction composers.

Optional params:

:account_index [Integer] Vault index the smart_account was derived with (default: 0).

Instance Method Summary collapse

Instance Method Details

#account_indexInteger

Extracts the vault index from the params

Returns:

  • (Integer)

    The vault index (defaults to 0)



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

def 
  params[:account_index] || 0
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)


124
125
126
127
128
129
130
131
132
133
134
# File 'lib/solace/squads_smart_accounts/composers/execute_transaction_sync_composer.rb', line 124

def build_instruction(context)
  SquadsSmartAccounts::Instructions::ExecuteTransactionSyncInstruction.build(
    account_index:,
    num_signers:               signers.length,
    instructions:              compiled_instructions,
    settings_index:            context.index_of(settings),
    program_index:             context.index_of(program_id),
    signer_indices:            signers.map { |signer| context.index_of(signer) },
    remaining_account_indices: remaining_pubkeys.map { |pubkey| context.index_of(pubkey) }
  )
end

#compiled_instructionsArray<Solace::Instruction>

Inner instructions built against the remaining-accounts context, ready for encoding into the Squads compiled wire format.

Returns:

  • (Array<Solace::Instruction>)

    The compiled inner instructions



97
98
99
100
101
# File 'lib/solace/squads_smart_accounts/composers/execute_transaction_sync_composer.rb', line 97

def compiled_instructions
  @compiled_instructions ||= instructions.map do |composer|
    composer.build_instruction(remaining_accounts_context)
  end
end

#instructionsArray<Solace::Composers::Base>

Extracts the inner instruction composers from the params

Returns:

  • (Array<Solace::Composers::Base>)

    The inner instruction composers



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

def instructions
  params[:instructions]
end

#program_idString

Returns the Squads Smart Account program id from the constants

Returns:

  • (String)

    The Squads Smart Account program id



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

def program_id
  SquadsSmartAccounts::PROGRAM_ID
end

#remaining_accounts_contextSolace::Utils::AccountContext

Local AccountContext scoped to the full remaining-accounts list as the program sees it: co-signers first, then the inner-instruction accounts. The deployed program resolves inner instruction indexes against this full list (signers included) — not a post-signer slice.

Returns:

  • (Solace::Utils::AccountContext)

    The remaining-accounts context



87
88
89
90
91
# File 'lib/solace/squads_smart_accounts/composers/execute_transaction_sync_composer.rb', line 87

def remaining_accounts_context
  @remaining_accounts_context ||= Solace::Utils::AccountContext.new.tap do |context|
    context.accounts = signers + remaining_pubkeys
  end
end

#remaining_pubkeysArray<String>

Ordered, unique pubkeys referenced by the inner instructions, in declaration order, excluding co-signers (which already occupy the leading remaining-account positions).

Returns:

  • (Array<String>)

    The remaining account pubkeys



75
76
77
78
79
# File 'lib/solace/squads_smart_accounts/composers/execute_transaction_sync_composer.rb', line 75

def remaining_pubkeys
  @remaining_pubkeys ||= instructions.flat_map do |composer|
    composer...keys
  end.uniq - signers
end

#settingsString

Extracts the settings address from the params

Returns:

  • (String)

    The settings address



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

def settings
  params[:settings].to_s
end

#setup_accountsObject

Declares all accounts required by this instruction.



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/solace/squads_smart_accounts/composers/execute_transaction_sync_composer.rb', line 104

def setup_accounts
  # Required read-only accounts
  .add_readonly_nonsigner(settings)
  .add_readonly_nonsigner(program_id)

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

  # Accounts referenced by the inner instructions, with their inner flags.
  instructions.each do |composer|
    composer...each do |pubkey, flags|
      (pubkey, flags)
    end
  end
end

#signersArray<String>

Extracts the co-signer addresses from the params

Returns:

  • (Array<String>)

    The signer addresses



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

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

#smart_accountString

Extracts the vault address from the params

Returns:

  • (String)

    The vault (smart account) address



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

def 
  params[:smart_account].to_s
end