Class: Solace::Composers::SquadsSmartAccountsAddSpendingLimitAsAuthorityComposer
- Inherits:
-
Base
- Object
- Base
- Solace::Composers::SquadsSmartAccountsAddSpendingLimitAsAuthorityComposer
- 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
-
#account_index ⇒ Integer
Extracts the vault index from the params.
-
#amount ⇒ Integer
Extracts the per-period amount from the params.
-
#build_instruction(context) ⇒ Solace::Instruction
Builds the instruction with resolved account indices.
-
#destinations ⇒ Array<String>
Extracts the allowed destinations from the params.
-
#expiration ⇒ Integer
Extracts the expiration from the params.
-
#memo ⇒ String?
Extracts the memo from the params.
-
#mint ⇒ String
Extracts the mint from the params.
-
#period ⇒ Integer
Extracts the reset period from the params.
-
#program_id ⇒ String
Returns the Squads Smart Account program id from the constants.
-
#rent_payer ⇒ String
Extracts the rent payer address from the params.
-
#seed ⇒ String
Extracts the PDA seed pubkey from the params.
-
#settings ⇒ String
Extracts the settings address from the params.
-
#settings_authority ⇒ String
Extracts the settings authority address from the params.
-
#setup_accounts ⇒ Object
Declares all accounts required by this instruction.
-
#signers ⇒ Array<String>
Extracts the allowed signer pubkeys from the params.
-
#spending_limit ⇒ String
Extracts the spending limit PDA address from the params.
-
#system_program ⇒ String
Returns the system program id from the constants.
Instance Method Details
#account_index ⇒ Integer
Extracts the vault index from the params
68 69 70 |
# File 'lib/solace/squads_smart_accounts/composers/add_spending_limit_as_authority_composer.rb', line 68 def account_index params[:account_index] || 0 end |
#amount ⇒ Integer
Extracts the per-period amount from the params
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.
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(), 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 |
#destinations ⇒ Array<String>
Extracts the allowed destinations from the params
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 |
#expiration ⇒ Integer
Extracts the expiration from the params
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 |
#memo ⇒ String?
Extracts the memo from the params
117 118 119 |
# File 'lib/solace/squads_smart_accounts/composers/add_spending_limit_as_authority_composer.rb', line 117 def memo params[:memo] end |
#mint ⇒ String
Extracts the mint from the params
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 |
#period ⇒ Integer
Extracts the reset period from the params
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_id ⇒ String
Returns the Squads Smart Account program id from the constants
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_payer ⇒ String
Extracts the rent payer address from the params
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 |
#seed ⇒ String
Extracts the PDA seed pubkey from the params
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 |
#settings ⇒ String
Extracts the settings address from the params
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_authority ⇒ String
Extracts the settings authority address from the params
40 41 42 |
# File 'lib/solace/squads_smart_accounts/composers/add_spending_limit_as_authority_composer.rb', line 40 def params[:settings_authority].to_s end |
#setup_accounts ⇒ Object
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 account_context.add_readonly_nonsigner(settings) account_context.add_readonly_signer() account_context.add_writable_nonsigner(spending_limit) account_context.add_writable_signer(rent_payer) account_context.add_readonly_nonsigner(system_program) account_context.add_readonly_nonsigner(program_id) end |
#signers ⇒ Array<String>
Extracts the allowed signer pubkeys from the params
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_limit ⇒ String
Extracts the spending limit PDA address from the params
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_program ⇒ String
Returns the system program id from the constants
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 |