Class: Solace::Composers::SquadsSmartAccountsCreateSmartAccountComposer

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

Overview

Composes a ‘createSmartAccount` instruction for the Squads Smart Account program.

Required params:

:creator   [String]                        Base58 pubkey of the account creating the smart account.
:treasury  [String]                        Base58 pubkey of the treasury (from ProgramConfig).
:settings  [#to_s, Array<#to_s>]           The settings PDA(s) to offer as remaining accounts.
                                           Pass a single address for deterministic creation
                                           (derive via Programs::SquadsSmartAccount.get_settings_address),
                                           or an array (a "window" of candidates) for race-free creation —
                                           the program initializes whichever matches the incremented
                                           counter. See Programs::SquadsSmartAccount.next_smart_account_candidates.
:threshold [Integer]                       Number of approvals required to execute a transaction.
:signers   [Array<SquadsSmartAccounts::SmartAccountSigner>]  Signers on the smart account.
:time_lock [Integer]                       Seconds between proposal and execution (0 to disable).

Optional params:

:settings_authority [String]  Pubkey of the reconfiguration authority (default: nil).
:rent_collector     [String]  Pubkey for reclaiming rent on closed accounts (default: nil).
:memo               [String]  Indexing memo (default: nil).

Instance Method Summary collapse

Instance Method Details

#build_instruction(context) ⇒ Solace::Instruction

Builds the instruction with resolved account indices.

Parameters:

  • context (Solace::Utils::AccountContext)

    Merged context from TransactionComposer.

Returns:

  • (Solace::Instruction)


133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 133

def build_instruction(context)
  SquadsSmartAccounts::Instructions::CreateSmartAccountInstruction.build(
    settings_authority:,
    threshold:,
    signers:,
    time_lock:,
    rent_collector:,
    memo:,
    program_config_index: context.index_of(config),
    treasury_index:       context.index_of(treasury),
    creator_index:        context.index_of(creator),
    system_program_index: context.index_of(system_program),
    program_index:        context.index_of(program_id),
    settings_index:       settings.map { |address| context.index_of(address) }
  )
end

#configString

Returns the program config address from the constants

Returns:

  • (String)

    The program config address



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

def config
  SquadsSmartAccounts::PROGRAM_CONFIG_ADDRESS
end

#creatorString

Extracts the creator address from the params

Returns:

  • (String)

    The creator address



35
36
37
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 35

def creator
  params[:creator].to_s
end

#memoString?

Extracts the memo from the params

Returns:

  • (String, nil)

    The memo



108
109
110
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 108

def memo
  params[:memo]
end

#program_idString

Returns the Squads Smart Account program id from the constants

Returns:

  • (String)

    The Squads Smart Account program id



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

def program_id
  SquadsSmartAccounts::PROGRAM_ID
end

#rent_collectorString?

Extracts the rent collector address from the params

Returns:

  • (String, nil)

    The rent collector address



80
81
82
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 80

def rent_collector
  params[:rent_collector]&.to_s
end

#settingsArray<String>

Normalizes the :settings param to an array of base58 addresses.

Accepts a single pubkey (deterministic creation) or an array of candidate pubkeys (windowed, race-free creation), so both flows share this composer.

Returns:

  • (Array<String>)

    The settings address(es), in seed order.



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

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

#settings_authorityString?

Extracts the settings authority address from the params

Returns:

  • (String, nil)

    The settings authority address



73
74
75
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 73

def settings_authority
  params[:settings_authority]&.to_s
end

#setup_accountsObject

Declares all accounts required by this instruction.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 113

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

  # Writable accounts
  .add_writable_nonsigner(config)
  .add_writable_nonsigner(treasury)

  # Each candidate settings PDA is offered as a writable remaining account.
  settings.each { |address| .add_writable_nonsigner(address) }

  # Writable signers
  .add_writable_signer(creator)
end

#signersArray<SquadsSmartAccounts::SmartAccountSigner>

Extracts the signers from the params

Returns:



101
102
103
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 101

def signers
  params[:signers]
end

#system_programString

Returns the system program id from the constants

Returns:

  • (String)

    The system program id



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

def system_program
  Solace::Constants::SYSTEM_PROGRAM_ID
end

#thresholdInteger

Extracts the threshold from the params

Returns:

  • (Integer)

    The threshold



87
88
89
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 87

def threshold
  params[:threshold]
end

#time_lockInteger

Extracts the time lock from the params

Returns:

  • (Integer)

    The time lock



94
95
96
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 94

def time_lock
  params[:time_lock]
end

#treasuryString

Extracts the treasury address from the params

Returns:

  • (String)

    The treasury address



28
29
30
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 28

def treasury
  params[:treasury].to_s
end