Class: Solace::Composers::SquadsSmartAccountsSetNewSettingsAuthorityAsAuthorityComposer

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

Overview

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

Hands the settings authority of a controlled smart account to a new key. Only the current settings authority may do this — single signature, no consensus.

Required params:

:settings               [String]         Base58 address of the settings account.
:settings_authority     [#to_s, Keypair] The current settings authority (must sign).
:rent_payer             [#to_s, Keypair] Pays for settings account reallocation (must sign).
:new_settings_authority [#to_s, nil]     Base58 pubkey of the new settings authority, or
                                         nil to renounce control — the program convention
                                         stores Pubkey::default(), permanently converting
                                         the account to autonomous.

Optional params:

: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)


87
88
89
90
91
92
93
94
95
96
97
# File 'lib/solace/squads_smart_accounts/composers/set_new_settings_authority_as_authority_composer.rb', line 87

def build_instruction(context)
  SquadsSmartAccounts::Instructions::SetNewSettingsAuthorityAsAuthorityInstruction.build(
    new_settings_authority:,
    memo:,
    settings_index:           context.index_of(settings),
    settings_authority_index: context.index_of(settings_authority),
    rent_payer_index:         context.index_of(rent_payer),
    system_program_index:     context.index_of(system_program),
    program_index:            context.index_of(program_id)
  )
end

#memoString?

Extracts the memo from the params

Returns:

  • (String, nil)

    The memo



56
57
58
# File 'lib/solace/squads_smart_accounts/composers/set_new_settings_authority_as_authority_composer.rb', line 56

def memo
  params[:memo]
end

#new_settings_authorityString

Extracts the new settings authority address from the params. A nil param renounces control: the program convention stores Pubkey::default(), permanently converting the account to autonomous.

Returns:

  • (String)

    The new settings authority address



49
50
51
# File 'lib/solace/squads_smart_accounts/composers/set_new_settings_authority_as_authority_composer.rb', line 49

def new_settings_authority
  (params[:new_settings_authority] || SquadsSmartAccounts::DEFAULT_PUBKEY).to_s
end

#program_idString

Returns the Squads Smart Account program id from the constants

Returns:

  • (String)

    The Squads Smart Account program id



63
64
65
# File 'lib/solace/squads_smart_accounts/composers/set_new_settings_authority_as_authority_composer.rb', line 63

def program_id
  SquadsSmartAccounts::PROGRAM_ID
end

#rent_payerString

Extracts the rent payer address from the params

Returns:

  • (String)

    The rent payer address



40
41
42
# File 'lib/solace/squads_smart_accounts/composers/set_new_settings_authority_as_authority_composer.rb', line 40

def rent_payer
  params[:rent_payer].to_s
end

#settingsString

Extracts the settings address from the params

Returns:

  • (String)

    The settings address



26
27
28
# File 'lib/solace/squads_smart_accounts/composers/set_new_settings_authority_as_authority_composer.rb', line 26

def settings
  params[:settings].to_s
end

#settings_authorityString

Extracts the current settings authority address from the params

Returns:

  • (String)

    The current settings authority address



33
34
35
# File 'lib/solace/squads_smart_accounts/composers/set_new_settings_authority_as_authority_composer.rb', line 33

def settings_authority
  params[:settings_authority].to_s
end

#setup_accountsObject

Declares all accounts required by this instruction.



75
76
77
78
79
80
81
# File 'lib/solace/squads_smart_accounts/composers/set_new_settings_authority_as_authority_composer.rb', line 75

def setup_accounts
  .add_writable_nonsigner(settings)
  .add_readonly_signer(settings_authority)
  .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



70
71
72
# File 'lib/solace/squads_smart_accounts/composers/set_new_settings_authority_as_authority_composer.rb', line 70

def system_program
  Solace::Constants::SYSTEM_PROGRAM_ID
end