Class: Solace::Composers::SquadsSmartAccountsRemoveSpendingLimitAsAuthorityComposer

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

Overview

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

Closes a SpendingLimit PDA, refunding its rent to the rent collector. Only the account’s settings authority may do this — single signature, no consensus.

Required params:

:settings           [#to_s]          Base58 address of the settings account.
:settings_authority [#to_s, Keypair] The account's settings authority (must sign).
:spending_limit     [#to_s]          The SpendingLimit PDA to close.
:rent_collector     [#to_s]          Receives the closed account's rent (does not sign).

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)


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

def build_instruction(context)
  SquadsSmartAccounts::Instructions::RemoveSpendingLimitAsAuthorityInstruction.build(
    memo:,
    settings_index:           context.index_of(settings),
    settings_authority_index: context.index_of(settings_authority),
    spending_limit_index:     context.index_of(spending_limit),
    rent_collector_index:     context.index_of(rent_collector),
    program_index:            context.index_of(program_id)
  )
end

#memoString?

Extracts the memo from the params

Returns:

  • (String, nil)

    The memo



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

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/remove_spending_limit_as_authority_composer.rb', line 59

def program_id
  SquadsSmartAccounts::PROGRAM_ID
end

#rent_collectorString

Extracts the rent collector address from the params

Returns:

  • (String)

    The rent collector address



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

def rent_collector
  params[:rent_collector].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/remove_spending_limit_as_authority_composer.rb', line 24

def settings
  params[:settings].to_s
end

#settings_authorityString

Extracts the settings authority address from the params

Returns:

  • (String)

    The settings authority address



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

def settings_authority
  params[:settings_authority].to_s
end

#setup_accountsObject

Declares all accounts required by this instruction.



64
65
66
67
68
69
70
# File 'lib/solace/squads_smart_accounts/composers/remove_spending_limit_as_authority_composer.rb', line 64

def setup_accounts
  .add_readonly_nonsigner(settings)
  .add_readonly_signer(settings_authority)
  .add_writable_nonsigner(spending_limit)
  .add_writable_nonsigner(rent_collector)
  .add_readonly_nonsigner(program_id)
end

#spending_limitString

Extracts the spending limit PDA address from the params

Returns:

  • (String)

    The spending limit address



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

def spending_limit
  params[:spending_limit].to_s
end