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  [String]                        Base58 pubkey of the settings PDA to be created —
                                           derive via Programs::SquadsSmartAccount.get_settings_address.
: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)


124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 124

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:       context.index_of(settings)
  )
end

#configString

Returns the program config address from the constants

Returns:

  • (String)

    The program config address



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

def config
  SquadsSmartAccounts::PROGRAM_CONFIG_ADDRESS
end

#creatorString

Extracts the creator address from the params

Returns:

  • (String)

    The creator address



31
32
33
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 31

def creator
  params[:creator].to_s
end

#memoString?

Extracts the memo from the params

Returns:

  • (String, nil)

    The memo



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

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



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

def program_id
  SquadsSmartAccounts::PROGRAM_ID
end

#rent_collectorString?

Extracts the rent collector address from the params

Returns:

  • (String, nil)

    The rent collector address



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

def rent_collector
  params[:rent_collector]&.to_s
end

#settingsString

Extracts the settings address from the params

Returns:

  • (String)

    The settings address



38
39
40
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 38

def settings
  params[:settings].to_s
end

#settings_authorityString?

Extracts the settings authority address from the params

Returns:

  • (String, nil)

    The settings authority address



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

def settings_authority
  params[:settings_authority]&.to_s
end

#setup_accountsObject

Declares all accounts required by this instruction.



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 106

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)
  .add_writable_nonsigner(settings)

  # Writable signers
  .add_writable_signer(creator)
end

#signersArray<SquadsSmartAccounts::SmartAccountSigner>

Extracts the signers from the params

Returns:



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

def signers
  params[:signers]
end

#system_programString

Returns the system program id from the constants

Returns:

  • (String)

    The system program id



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

def system_program
  Solace::Constants::SYSTEM_PROGRAM_ID
end

#thresholdInteger

Extracts the threshold from the params

Returns:

  • (Integer)

    The threshold



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

def threshold
  params[:threshold]
end

#time_lockInteger

Extracts the time lock from the params

Returns:

  • (Integer)

    The time lock



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

def time_lock
  params[:time_lock]
end

#treasuryString

Extracts the treasury address from the params

Returns:

  • (String)

    The treasury address



24
25
26
# File 'lib/solace/squads_smart_accounts/composers/create_smart_account_composer.rb', line 24

def treasury
  params[:treasury].to_s
end