Class: Solace::Composers::SquadsSmartAccountsAddSpendingLimitAsAuthorityComposer

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

Overview

Composes an ‘addSpendingLimitAsAuthority` instruction for the Squads Smart Account program.

Creates a SpendingLimit PDA granting designated signers a pre-authorized allowance from a vault. 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 create — derive via
                                     Programs::SquadsSmartAccount.get_spending_limit_address.
:rent_payer         [#to_s, Keypair] Funds the new account's rent (must sign).
:seed               [#to_s]          The pubkey the spending_limit PDA was derived with.
:amount             [Integer]        Amount spendable per period (mint decimals).
:period             [Integer]        Period enum value (reset cadence).
:signers            [Array<#to_s>]   Pubkeys allowed to use the limit.

Optional params:

:account_index [Integer]      Vault index the limit spends from (default: 0).
:mint          [#to_s]        Token mint (default: DEFAULT_PUBKEY = SOL).
:destinations  [Array<#to_s>] Allowed destinations; empty = any (default: []).
:expiration    [Integer]      Unix expiration timestamp (default: I64_MAX = never).
:memo          [String]       Indexing memo (default: nil).

Instance Method Summary collapse

Instance Method Details

#account_indexInteger

Extracts the vault index from the params

Returns:

  • (Integer)

    The vault index (defaults to 0)



68
69
70
# File 'lib/solace/squads_smart_accounts/composers/add_spending_limit_as_authority_composer.rb', line 68

def 
  params[:account_index] || 0
end

#amountInteger

Extracts the per-period amount from the params

Returns:

  • (Integer)

    The amount spendable per period



82
83
84
# File 'lib/solace/squads_smart_accounts/composers/add_spending_limit_as_authority_composer.rb', line 82

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


149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/solace/squads_smart_accounts/composers/add_spending_limit_as_authority_composer.rb', line 149

def build_instruction(context)
  SquadsSmartAccounts::Instructions::AddSpendingLimitAsAuthorityInstruction.build(
    seed:,
    account_index:,
    mint:,
    amount:,
    period:,
    signers:,
    destinations:,
    expiration:,
    memo:,
    settings_index:           context.index_of(settings),
    settings_authority_index: context.index_of(settings_authority),
    spending_limit_index:     context.index_of(spending_limit),
    rent_payer_index:         context.index_of(rent_payer),
    system_program_index:     context.index_of(system_program),
    program_index:            context.index_of(program_id)
  )
end

#destinationsArray<String>

Extracts the allowed destinations from the params

Returns:

  • (Array<String>)

    The allowed destination addresses (defaults to [])



103
104
105
# File 'lib/solace/squads_smart_accounts/composers/add_spending_limit_as_authority_composer.rb', line 103

def destinations
  (params[:destinations] || []).map(&:to_s)
end

#expirationInteger

Extracts the expiration from the params

Returns:

  • (Integer)

    Unix expiration timestamp (defaults to I64_MAX = never)



110
111
112
# File 'lib/solace/squads_smart_accounts/composers/add_spending_limit_as_authority_composer.rb', line 110

def expiration
  params[:expiration] || SquadsSmartAccounts::I64_MAX
end

#memoString?

Extracts the memo from the params

Returns:

  • (String, nil)

    The memo



117
118
119
# File 'lib/solace/squads_smart_accounts/composers/add_spending_limit_as_authority_composer.rb', line 117

def memo
  params[:memo]
end

#mintString

Extracts the mint from the params

Returns:

  • (String)

    The mint address (defaults to DEFAULT_PUBKEY = SOL)



75
76
77
# File 'lib/solace/squads_smart_accounts/composers/add_spending_limit_as_authority_composer.rb', line 75

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

#periodInteger

Extracts the reset period from the params

Returns:

  • (Integer)

    The Period enum value



89
90
91
# File 'lib/solace/squads_smart_accounts/composers/add_spending_limit_as_authority_composer.rb', line 89

def period
  params[:period]
end

#program_idString

Returns the Squads Smart Account program id from the constants

Returns:

  • (String)

    The Squads Smart Account program id



124
125
126
# File 'lib/solace/squads_smart_accounts/composers/add_spending_limit_as_authority_composer.rb', line 124

def program_id
  SquadsSmartAccounts::PROGRAM_ID
end

#rent_payerString

Extracts the rent payer address from the params

Returns:

  • (String)

    The rent payer address



54
55
56
# File 'lib/solace/squads_smart_accounts/composers/add_spending_limit_as_authority_composer.rb', line 54

def rent_payer
  params[:rent_payer].to_s
end

#seedString

Extracts the PDA seed pubkey from the params

Returns:

  • (String)

    The seed pubkey



61
62
63
# File 'lib/solace/squads_smart_accounts/composers/add_spending_limit_as_authority_composer.rb', line 61

def seed
  params[:seed].to_s
end

#settingsString

Extracts the settings address from the params

Returns:

  • (String)

    The settings address



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

def settings
  params[:settings].to_s
end

#settings_authorityString

Extracts the settings authority address from the params

Returns:

  • (String)

    The settings authority address



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

def settings_authority
  params[:settings_authority].to_s
end

#setup_accountsObject

Declares all accounts required by this instruction.



136
137
138
139
140
141
142
143
# File 'lib/solace/squads_smart_accounts/composers/add_spending_limit_as_authority_composer.rb', line 136

def setup_accounts
  .add_readonly_nonsigner(settings)
  .add_readonly_signer(settings_authority)
  .add_writable_nonsigner(spending_limit)
  .add_writable_signer(rent_payer)
  .add_readonly_nonsigner(system_program)
  .add_readonly_nonsigner(program_id)
end

#signersArray<String>

Extracts the allowed signer pubkeys from the params

Returns:

  • (Array<String>)

    The allowed signer addresses



96
97
98
# File 'lib/solace/squads_smart_accounts/composers/add_spending_limit_as_authority_composer.rb', line 96

def signers
  params[:signers].map(&:to_s)
end

#spending_limitString

Extracts the spending limit PDA address from the params

Returns:

  • (String)

    The spending limit address



47
48
49
# File 'lib/solace/squads_smart_accounts/composers/add_spending_limit_as_authority_composer.rb', line 47

def spending_limit
  params[:spending_limit].to_s
end

#system_programString

Returns the system program id from the constants

Returns:

  • (String)

    The system program id



131
132
133
# File 'lib/solace/squads_smart_accounts/composers/add_spending_limit_as_authority_composer.rb', line 131

def system_program
  Solace::Constants::SYSTEM_PROGRAM_ID
end