Class: Solace::Composers::SquadsSmartAccountsExecuteTransactionSyncComposer
- Inherits:
-
Base
- Object
- Base
- Solace::Composers::SquadsSmartAccountsExecuteTransactionSyncComposer
- 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
-
#account_index ⇒ Integer
Extracts the vault index from the params.
-
#build_instruction(context) ⇒ Solace::Instruction
Builds the instruction with resolved account indices.
-
#compiled_instructions ⇒ Array<Solace::Instruction>
Inner instructions built against the remaining-accounts context, ready for encoding into the Squads compiled wire format.
-
#instructions ⇒ Array<Solace::Composers::Base>
Extracts the inner instruction composers from the params.
-
#program_id ⇒ String
Returns the Squads Smart Account program id from the constants.
-
#remaining_accounts_context ⇒ Solace::Utils::AccountContext
Local AccountContext scoped to the full remaining-accounts list as the program sees it: co-signers first, then the inner-instruction accounts.
-
#remaining_pubkeys ⇒ Array<String>
Ordered, unique pubkeys referenced by the inner instructions, in declaration order, excluding co-signers (which already occupy the leading remaining-account positions).
-
#settings ⇒ String
Extracts the settings address from the params.
-
#setup_accounts ⇒ Object
Declares all accounts required by this instruction.
-
#signers ⇒ Array<String>
Extracts the co-signer addresses from the params.
-
#smart_account ⇒ String
Extracts the vault address from the params.
Instance Method Details
#account_index ⇒ Integer
Extracts the vault index from the params
59 60 61 |
# File 'lib/solace/squads_smart_accounts/composers/execute_transaction_sync_composer.rb', line 59 def account_index params[:account_index] || 0 end |
#build_instruction(context) ⇒ Solace::Instruction
Builds the instruction with resolved account indices.
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_instructions ⇒ Array<Solace::Instruction>
Inner instructions built against the remaining-accounts context, ready for encoding into the Squads compiled wire format.
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 |
#instructions ⇒ Array<Solace::Composers::Base>
Extracts the inner instruction composers from the params
52 53 54 |
# File 'lib/solace/squads_smart_accounts/composers/execute_transaction_sync_composer.rb', line 52 def instructions params[:instructions] end |
#program_id ⇒ String
Returns the Squads Smart Account program id from the constants
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_context ⇒ Solace::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.
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_pubkeys ⇒ Array<String>
Ordered, unique pubkeys referenced by the inner instructions, in declaration order, excluding co-signers (which already occupy the leading remaining-account positions).
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.account_context.pubkey_account_map.keys end.uniq - signers end |
#settings ⇒ String
Extracts the settings address from the params
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_accounts ⇒ Object
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 account_context.add_readonly_nonsigner(settings) account_context.add_readonly_nonsigner(program_id) # Co-signers proving threshold consensus signers.each { |signer| account_context.add_readonly_signer(signer) } # Accounts referenced by the inner instructions, with their inner flags. instructions.each do |composer| composer.account_context.pubkey_account_map.each do |pubkey, flags| add_inner_account(pubkey, flags) end end end |
#signers ⇒ Array<String>
Extracts the co-signer addresses from the params
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_account ⇒ String
Extracts the vault address from the params
38 39 40 |
# File 'lib/solace/squads_smart_accounts/composers/execute_transaction_sync_composer.rb', line 38 def smart_account params[:smart_account].to_s end |