Class: Solace::Composers::SquadsSmartAccountsCreateSettingsTransactionComposer

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

Overview

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

Stores a batch of SettingsActions as a SettingsTransaction for later approval and execution. Autonomous accounts only.

Required params:

:settings    [#to_s]          Base58 address of the settings account.
:transaction [#to_s]          The SettingsTransaction PDA to create.
:creator     [#to_s, Keypair] A signer creating the transaction (must sign).
:rent_payer  [#to_s, Keypair] Funds the new account's rent (must sign).
:actions     [Array<SquadsSmartAccounts::SettingsAction>] Actions to store.

Optional params:

:memo [String] Indexing memo (default: nil).

Instance Method Summary collapse

Instance Method Details

#actionsArray<SquadsSmartAccounts::SettingsAction>

Extracts the settings actions from the params

Returns:



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

def actions
  params[:actions]
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)


91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/solace/squads_smart_accounts/composers/create_settings_transaction_composer.rb', line 91

def build_instruction(context)
  SquadsSmartAccounts::Instructions::CreateSettingsTransactionInstruction.build(
    actions:,
    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



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

def creator
  params[:creator].to_s
end

#memoString?

Extracts the memo from the params

Returns:

  • (String, nil)

    The memo



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

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



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

def program_id
  SquadsSmartAccounts::PROGRAM_ID
end

#rent_payerString

Extracts the rent payer address from the params

Returns:

  • (String)

    The rent payer address



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

def rent_payer
  params[:rent_payer].to_s
end

#settingsString

Extracts the settings address from the params

Returns:

  • (String)

    The settings address



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

def settings
  params[:settings].to_s
end

#setup_accountsObject

Declares all accounts required by this instruction.



78
79
80
81
82
83
84
85
# File 'lib/solace/squads_smart_accounts/composers/create_settings_transaction_composer.rb', line 78

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



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

def system_program
  Solace::Constants::SYSTEM_PROGRAM_ID
end

#transactionString

Extracts the transaction PDA address from the params

Returns:

  • (String)

    The transaction address



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

def transaction
  params[:transaction].to_s
end