Skip to content

Add a Spending Limit

Creates a spending limit: a pre-authorized, periodically resetting allowance that named signers can spend from a vault without a proposal. On a controlled account it is authorized by the settings authority.

Controlled accounts only via this method. An autonomous account adds a limit through the AddSpendingLimit settings transaction action. The SpendingLimit lives at its own PDA, derived from a client-chosen seed pubkey — derive it with get_spending_limit_address.

Program method — add_spending_limit_as_authority

Signs with payer + settings_authority + rent_payer, then sends.

ParameterTypeRequiredDefaultDescription
payerKeypairyesPays the fee; co-signs.
settings#to_syesThe settings account address.
settings_authority#to_s · KeypairyesThe account's settings authority; must sign.
spending_limit#to_syesThe SpendingLimit PDA to create (from get_spending_limit_address).
rent_payer#to_s · KeypairyesFunds the new account's rent; must sign.
seed#to_syesThe pubkey the SpendingLimit PDA was derived with.
amountIntegeryesAmount spendable per period, in the mint's base units.
periodIntegeryesReset cadence — a Period value.
signersArray<#to_s>yesPubkeys allowed to use the limit.
account_indexIntegerno0Vault index the limit spends from.
mint#to_snoDEFAULT_PUBKEYToken mint; the default pubkey means SOL.
destinationsArray<#to_s>no[]Allowed destinations; empty means any.
expirationIntegernoI64_MAXUnix expiration; the default never expires.
memoStringnonilOptional indexing memo.

Plus the shared sign: / execute: controls and Solace::Transaction return — see Conventions.

ruby
seed = Solace::Keypair.generate

spending_limit, = program.get_spending_limit_address(
  settings_address: identity.settings_address,
  seed:
)

program.add_spending_limit_as_authority(
  payer:              authority,
  settings:           identity.settings_address,
  settings_authority: authority,
  rent_payer:         authority,
  spending_limit:,
  seed:,
  amount:             500_000_000, # 0.5 SOL per period
  period:             Solace::SquadsSmartAccounts::Period::DAY,
  signers:            [member.address]
)

Composer — SquadsSmartAccountsAddSpendingLimitAsAuthorityComposer

ParameterTypeRequiredDefaultDescription
settings#to_syesThe settings account address.
settings_authority#to_s · KeypairyesThe settings authority; must sign.
spending_limit#to_syesThe SpendingLimit PDA to create.
rent_payer#to_s · KeypairyesFunds the new account's rent; must sign.
seed#to_syesThe pubkey the PDA was derived with.
amountIntegeryesAmount per period (mint base units).
periodIntegeryesPeriod value.
signersArray<#to_s>yesPubkeys allowed to use the limit.
account_indexIntegerno0Vault index.
mint#to_snoDEFAULT_PUBKEYToken mint (default = SOL).
destinationsArray<#to_s>no[]Allowed destinations; empty = any.
expirationIntegernoI64_MAXUnix expiration (default = never).
memoStringnonilIndexing memo.
ruby
composer = Solace::Composers::SquadsSmartAccountsAddSpendingLimitAsAuthorityComposer.new(
  settings:           identity.settings_address,
  settings_authority: authority.address,
  spending_limit:     spending_limit,
  rent_payer:         authority.address,
  seed:               seed.address,
  amount:             500_000_000,
  period:             Solace::SquadsSmartAccounts::Period::DAY,
  signers:            [member.address]
)

tx = Solace::TransactionComposer.new(connection:)
                                .add_instruction(composer)
                                .set_fee_payer(authority)
                                .compose_transaction

tx.sign(authority)
connection.send_transaction(tx.serialize)

Low-level instruction (advanced)

  • Discriminator: [169, 189, 84, 54, 30, 244, 223, 212]
  • Encodes (data): pubkey(seed) + account_index + pubkey(mint) + le_u64(amount) + period + vec_pubkeys(signers) + vec_pubkeys(destinations) + le_i64(expiration) + option_string(memo)
ParameterTypeRequiredDefaultDescription
seed#to_syesPubkey the PDA was derived with.
account_indexIntegeryesVault index.
mint#to_syesToken mint (default pubkey = SOL).
amountIntegeryesAmount per period.
periodIntegeryesPeriod value.
signersArray<#to_s>yesAllowed signers.
destinationsArray<#to_s>yesAllowed destinations ([] = any).
expirationIntegeryesUnix expiration.
memoString, nilyesIndexing memo, or nil.
settings_indexIntegeryesIndex of the settings account.
settings_authority_indexIntegeryesIndex of the settings authority.
spending_limit_indexIntegeryesIndex of the SpendingLimit PDA.
rent_payer_indexIntegeryesIndex of the rent payer.
system_program_indexIntegeryesIndex of the System program.
program_indexIntegeryesIndex of the Squads program.

Built on Solace