Class: Solace::Composers::SquadsSmartAccountsCreateSmartAccountComposer
- Inherits:
-
Base
- Object
- Base
- Solace::Composers::SquadsSmartAccountsCreateSmartAccountComposer
- 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
-
#build_instruction(context) ⇒ Solace::Instruction
Builds the instruction with resolved account indices.
-
#config ⇒ String
Returns the program config address from the constants.
-
#creator ⇒ String
Extracts the creator address from the params.
-
#memo ⇒ String?
Extracts the memo from the params.
-
#program_id ⇒ String
Returns the Squads Smart Account program id from the constants.
-
#rent_collector ⇒ String?
Extracts the rent collector address from the params.
-
#settings ⇒ Array<String>
Normalizes the :settings param to an array of base58 addresses.
-
#settings_authority ⇒ String?
Extracts the settings authority address from the params.
-
#setup_accounts ⇒ Object
Declares all accounts required by this instruction.
-
#signers ⇒ Array<SquadsSmartAccounts::SmartAccountSigner>
Extracts the signers from the params.
-
#system_program ⇒ String
Returns the system program id from the constants.
-
#threshold ⇒ Integer
Extracts the threshold from the params.
-
#time_lock ⇒ Integer
Extracts the time lock from the params.
-
#treasury ⇒ String
Extracts the treasury address from the params.
Instance Method Details
#build_instruction(context) ⇒ Solace::Instruction
Builds the instruction with resolved account indices.
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 |
#config ⇒ String
Returns the program config address from the constants
52 53 54 |
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 52 def config SquadsSmartAccounts::PROGRAM_CONFIG_ADDRESS end |
#creator ⇒ String
Extracts the creator address from the params
35 36 37 |
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 35 def creator params[:creator].to_s end |
#memo ⇒ String?
Extracts the memo from the params
108 109 110 |
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 108 def memo params[:memo] end |
#program_id ⇒ String
Returns the Squads Smart Account program id from the constants
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_collector ⇒ String?
Extracts the rent collector address from the params
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 |
#settings ⇒ Array<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.
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_authority ⇒ String?
Extracts the settings authority address from the params
73 74 75 |
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 73 def params[:settings_authority]&.to_s end |
#setup_accounts ⇒ Object
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 account_context.add_readonly_nonsigner(system_program) account_context.add_readonly_nonsigner(program_id) # Writable accounts account_context.add_writable_nonsigner(config) account_context.add_writable_nonsigner(treasury) # Each candidate settings PDA is offered as a writable remaining account. settings.each { |address| account_context.add_writable_nonsigner(address) } # Writable signers account_context.add_writable_signer(creator) end |
#signers ⇒ Array<SquadsSmartAccounts::SmartAccountSigner>
Extracts the signers from the params
101 102 103 |
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 101 def signers params[:signers] end |
#system_program ⇒ String
Returns the system program id from the constants
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 |
#threshold ⇒ Integer
Extracts the threshold from the params
87 88 89 |
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 87 def threshold params[:threshold] end |
#time_lock ⇒ Integer
Extracts the time lock from the params
94 95 96 |
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 94 def time_lock params[:time_lock] end |
#treasury ⇒ String
Extracts the treasury address from the params
28 29 30 |
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 28 def treasury params[:treasury].to_s end |