Class: Solace::Composers::SquadsSmartAccountsExecuteTransactionComposer

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

Overview

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

Executes the inner instructions of an Approved proposal’s stored Transaction. The stored message’s account metas are appended as remaining accounts in their canonical order. The vault (smart account) PDA is the message’s signer but cannot sign the outer transaction — the program signs it via CPI — so it is forced to a non-signer here, mirroring SquadsSmartAccountsExecuteTransactionSyncComposer.

Required params:

:settings      [#to_s]          Base58 address of the settings account.
:proposal      [#to_s]          The Proposal PDA (must be Approved).
:transaction   [#to_s]          The Transaction PDA to execute.
:signer        [#to_s, Keypair] The executing signer (must sign; needs Execute permission).
:smart_account [#to_s]          The vault PDA the message spends from (forced non-signer).
:account_metas [Array<Hash>]    The stored message's account metas, in order —
  each { pubkey: #to_s, signer: Boolean, writable: Boolean } (Transaction#account_metas).

Instance Method Summary collapse

Instance Method Details

#account_metasArray<Hash>

The ordered stored-message account metas (from Transaction#account_metas), whose pubkeys are already base58 strings and flags already booleans.

Returns:

  • (Array<Hash>)

    Each { pubkey: String, signer: Boolean, writable: Boolean }



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

def 
  params[:account_metas]
end

#build_instruction(context) ⇒ Solace::Instruction

Builds the instruction with resolved account indices. The remaining account indices preserve the stored message’s account_keys order.

Parameters:

  • context (Solace::Utils::AccountContext)

    Merged context from TransactionComposer.

Returns:

  • (Solace::Instruction)


90
91
92
93
94
95
96
97
98
99
# File 'lib/solace/squads_smart_accounts/composers/execute_transaction_composer.rb', line 90

def build_instruction(context)
  SquadsSmartAccounts::Instructions::ExecuteTransactionInstruction.build(
    settings_index:            context.index_of(settings),
    proposal_index:            context.index_of(proposal),
    transaction_index:         context.index_of(transaction),
    signer_index:              context.index_of(signer),
    program_index:             context.index_of(program_id),
    remaining_account_indices: .map { |meta| context.index_of(meta[:pubkey]) }
  )
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_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



33
34
35
# File 'lib/solace/squads_smart_accounts/composers/execute_transaction_composer.rb', line 33

def proposal
  params[:proposal].to_s
end

#settingsString

Extracts the settings address from the params

Returns:

  • (String)

    The settings address



26
27
28
# File 'lib/solace/squads_smart_accounts/composers/execute_transaction_composer.rb', line 26

def settings
  params[:settings].to_s
end

#setup_accountsObject

Declares all accounts required by this instruction: the fixed accounts followed by each stored-message account with its flags.



75
76
77
78
79
80
81
82
83
# File 'lib/solace/squads_smart_accounts/composers/execute_transaction_composer.rb', line 75

def setup_accounts
  .add_writable_nonsigner(settings)
  .add_writable_nonsigner(proposal)
  .add_readonly_nonsigner(transaction)
  .add_readonly_signer(signer)
  .add_readonly_nonsigner(program_id)

  .each { |meta| (meta) }
end

#signerString

Extracts the executing signer address from the params

Returns:

  • (String)

    The signer address



47
48
49
# File 'lib/solace/squads_smart_accounts/composers/execute_transaction_composer.rb', line 47

def signer
  params[:signer].to_s
end

#smart_accountString

Extracts the vault (smart account) address from the params

Returns:

  • (String)

    The vault address



54
55
56
# File 'lib/solace/squads_smart_accounts/composers/execute_transaction_composer.rb', line 54

def 
  params[:smart_account].to_s
end

#transactionString

Extracts the transaction PDA address from the params

Returns:

  • (String)

    The transaction address



40
41
42
# File 'lib/solace/squads_smart_accounts/composers/execute_transaction_composer.rb', line 40

def transaction
  params[:transaction].to_s
end