Class: Solace::Composers::SquadsSmartAccountsCreateTransactionComposer
- Inherits:
-
Base
- Object
- Base
- Solace::Composers::SquadsSmartAccountsCreateTransactionComposer
- Defined in:
- lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb
Overview
Composes a ‘createTransaction` instruction for the Squads Smart Account program.
Stores a pending vault transaction on-chain. The inner instructions are regular Solace composers (e.g. SystemProgramTransferComposer with the vault as :from); they are compiled into a TransactionMessage — account keys ordered canonically, header counts derived, instructions re-indexed — and serialized into the stored transaction. Execution happens later via the proposal flow.
Scope: simple messages only — no ephemeral signers, no address-table lookups.
Required params:
:settings [#to_s] Base58 address of the settings account.
:transaction [#to_s] The Transaction PDA to create.
:creator [#to_s, Keypair] The transaction creator (must sign).
:rent_payer [#to_s, Keypair] Funds the new account's rent (must sign).
:instructions [Array<Composers::Base>] Inner instruction composers.
Optional params:
:account_index [Integer] Vault index the message spends from (default: 0).
:ephemeral_signers [Integer] Ephemeral signer count (default: 0; only 0 supported).
:memo [String] Indexing memo (default: nil).
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.
-
#creator ⇒ String
Extracts the creator address from the params.
-
#ephemeral_signers ⇒ Integer
Extracts the ephemeral signer count from the params.
-
#instructions ⇒ Array<Solace::Composers::Base>
Extracts the inner instruction composers from the params.
-
#memo ⇒ String?
Extracts the memo from the params.
-
#message_context ⇒ Solace::Utils::AccountContext
Local AccountContext holding the compiled inner message: all accounts the inner instructions reference, ordered canonically.
-
#program_id ⇒ String
Returns the Squads Smart Account program id from the constants.
-
#rent_payer ⇒ String
Extracts the rent payer address from the params.
-
#settings ⇒ String
Extracts the settings address from the params.
-
#setup_accounts ⇒ Object
Declares all accounts required by this instruction.
-
#system_program ⇒ String
Returns the system program id from the constants.
-
#transaction ⇒ String
Extracts the transaction PDA address from the params.
-
#transaction_message ⇒ Array<Integer>
Serializes the inner instructions into a TransactionMessage byte array.
Instance Method Details
#account_index ⇒ Integer
Extracts the vault index from the params
65 66 67 |
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 65 def account_index params[:account_index] || 0 end |
#build_instruction(context) ⇒ Solace::Instruction
Builds the instruction with resolved account indices.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 138 def build_instruction(context) SquadsSmartAccounts::Instructions::CreateTransactionInstruction.build( account_index:, ephemeral_signers:, transaction_message:, memo:, settings_index: context.index_of(settings), transaction_index: context.index_of(transaction), creator_index: context.index_of(creator), rent_payer_index: context.index_of(rent_payer), system_program_index: context.index_of(system_program), program_index: context.index_of(program_id) ) end |
#creator ⇒ String
Extracts the creator address from the params
44 45 46 |
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 44 def creator params[:creator].to_s end |
#ephemeral_signers ⇒ Integer
Extracts the ephemeral signer count from the params
72 73 74 |
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 72 def ephemeral_signers params[:ephemeral_signers] || 0 end |
#instructions ⇒ Array<Solace::Composers::Base>
Extracts the inner instruction composers from the params
58 59 60 |
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 58 def instructions params[:instructions] end |
#memo ⇒ String?
Extracts the memo from the params
79 80 81 |
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 79 def memo params[:memo] end |
#message_context ⇒ Solace::Utils::AccountContext
Local AccountContext holding the compiled inner message: all accounts the inner instructions reference, ordered canonically. Inner instruction indexes resolve against this context.
102 103 104 105 106 107 |
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 102 def @message_context ||= Solace::Utils::AccountContext.new.tap do |context| instructions.each { |composer| context.merge_from(composer.account_context) } context.compile end end |
#program_id ⇒ String
Returns the Squads Smart Account program id from the constants
86 87 88 |
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 86 def program_id SquadsSmartAccounts::PROGRAM_ID end |
#rent_payer ⇒ String
Extracts the rent payer address from the params
51 52 53 |
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 51 def rent_payer params[:rent_payer].to_s end |
#settings ⇒ String
Extracts the settings address from the params
30 31 32 |
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 30 def settings params[:settings].to_s end |
#setup_accounts ⇒ Object
Declares all accounts required by this instruction.
125 126 127 128 129 130 131 132 |
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 125 def setup_accounts account_context.add_writable_nonsigner(settings) account_context.add_writable_nonsigner(transaction) account_context.add_readonly_signer(creator) account_context.add_writable_signer(rent_payer) account_context.add_readonly_nonsigner(system_program) account_context.add_readonly_nonsigner(program_id) end |
#system_program ⇒ String
Returns the system program id from the constants
93 94 95 |
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 93 def system_program Solace::Constants::SYSTEM_PROGRAM_ID end |
#transaction ⇒ String
Extracts the transaction PDA address from the params
37 38 39 |
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 37 def transaction params[:transaction].to_s end |
#transaction_message ⇒ Array<Integer>
Serializes the inner instructions into a TransactionMessage byte array.
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 112 def header = .header SquadsSmartAccounts::TransactionMessage.new( num_signers: header[0], num_writable_signers: header[0] - header[1], num_writable_non_signers: (.accounts.length - header[0]) - header[2], account_keys: .accounts, instructions: instructions.map { |composer| composer.build_instruction() } ).serialize end |