Class: Solace::Composers::SquadsSmartAccountsCreateTransactionComposer

Inherits:
Base
  • Object
show all
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

Instance Method Details

#account_indexInteger

Extracts the vault index from the params

Returns:

  • (Integer)

    The vault index (defaults to 0)



65
66
67
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 65

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)


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

#creatorString

Extracts the creator address from the params

Returns:

  • (String)

    The creator address



44
45
46
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 44

def creator
  params[:creator].to_s
end

#ephemeral_signersInteger

Extracts the ephemeral signer count from the params

Returns:

  • (Integer)

    The ephemeral signer count (defaults to 0)



72
73
74
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 72

def ephemeral_signers
  params[:ephemeral_signers] || 0
end

#instructionsArray<Solace::Composers::Base>

Extracts the inner instruction composers from the params

Returns:

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

    The inner instruction composers



58
59
60
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 58

def instructions
  params[:instructions]
end

#memoString?

Extracts the memo from the params

Returns:

  • (String, nil)

    The memo



79
80
81
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 79

def memo
  params[:memo]
end

#message_contextSolace::Utils::AccountContext

Local AccountContext holding the compiled inner message: all accounts the inner instructions reference, ordered canonically. Inner instruction indexes resolve against this context.

Returns:

  • (Solace::Utils::AccountContext)

    The compiled inner-message context



102
103
104
105
106
107
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 102

def message_context
  @message_context ||= Solace::Utils::AccountContext.new.tap do |context|
    instructions.each { |composer| context.merge_from(composer.) }
    context.compile
  end
end

#program_idString

Returns the Squads Smart Account program id from the constants

Returns:

  • (String)

    The Squads Smart Account program id



86
87
88
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 86

def program_id
  SquadsSmartAccounts::PROGRAM_ID
end

#rent_payerString

Extracts the rent payer address from the params

Returns:

  • (String)

    The rent payer address



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

#settingsString

Extracts the settings address from the params

Returns:

  • (String)

    The settings address



30
31
32
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 30

def settings
  params[:settings].to_s
end

#setup_accountsObject

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
  .add_writable_nonsigner(settings)
  .add_writable_nonsigner(transaction)
  .add_readonly_signer(creator)
  .add_writable_signer(rent_payer)
  .add_readonly_nonsigner(system_program)
  .add_readonly_nonsigner(program_id)
end

#system_programString

Returns the system program id from the constants

Returns:

  • (String)

    The system program id



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

#transactionString

Extracts the transaction PDA address from the params

Returns:

  • (String)

    The transaction address



37
38
39
# File 'lib/solace/squads_smart_accounts/composers/create_transaction_composer.rb', line 37

def transaction
  params[:transaction].to_s
end

#transaction_messageArray<Integer>

Serializes the inner instructions into a TransactionMessage byte array.

Returns:

  • (Array<Integer>)

    The serialized message bytes



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 transaction_message
  header = message_context.header

  SquadsSmartAccounts::TransactionMessage.new(
    num_signers:              header[0],
    num_writable_signers:     header[0] - header[1],
    num_writable_non_signers: (message_context.accounts.length - header[0]) - header[2],
    account_keys:             message_context.accounts,
    instructions:             instructions.map { |composer| composer.build_instruction(message_context) }
  ).serialize
end