Overview
Add a spending limit via Config Authority. This instruction allows the config authority to add spending limits without going through the standard proposal process.Can only be used with a Controlled Multisig.
Prerequisites
- Multisig with Config Authority set
@sqds/multisigpackage installed- Config Authority signer
Quick Example
import * as multisig from "@sqds/multisig";
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
const spendingLimitCreateKey = Keypair.generate().publicKey;
const spendingLimitPda = multisig.getSpendingLimitPda({
multisigPda,
createKey: spendingLimitCreateKey,
})[0];
multisig.rpc.multisigAddSpendingLimit({
connection,
feePayer,
multisigPda,
spendingLimit: spendingLimitPda,
createKey: spendingLimitCreateKey,
rentPayer: feePayer,
amount: BigInt(1000000000),
configAuthority: configAuthority.publicKey,
period: multisig.generated.Period.Day,
mint: tokenMintPublicKey,
destinations: [destinationPublicKey],
members: [memberPublicKey],
vaultIndex: 1,
signers: [configAuthority],
});
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
connection | Connection | Yes | Solana RPC connection |
feePayer | Keypair | Yes | Transaction fee payer |
multisigPda | PublicKey | Yes | PDA of the multisig |
spendingLimit | PublicKey | Yes | Spending limit PDA |
createKey | PublicKey | Yes | Key to seed the spending limit PDA |
rentPayer | Keypair | Yes | Account paying for rent |
amount | bigint | Yes | Amount per period (respects token decimals) |
configAuthority | PublicKey | Yes | Config authority public key |
period | Period | Yes | Reset period (OneTime, Day, Week, Month) |
mint | PublicKey | Yes | Token mint for the spending limit |
destinations | PublicKey[] | Yes | Allowed destination addresses (empty = any) |
members | PublicKey[] | Yes | Public keys that can use the limit (at least one) |
vaultIndex | number | Yes | Index of the vault |
signers | Signer[] | No | Additional signers. Pass the config authority here so it signs the transaction |
Full Example
import * as multisig from "@sqds/multisig";
// Cluster Connection
const connection = new Connection("<your rpc url>");
// Fee payer is the a signer that pays the transaction fees
const feePayer = Keypair.generate();
// Replace with the keypair of the multisig's config authority
const configAuthority = Keypair.generate();
// Derive the multisig PDA
const multisigPda = multisig.getMultisigPda({
// The createKey has to be a Public Key, see accounts reference for more info
createKey,
})[0];
const spendingLimitCreateKey = Keypair.generate().publicKey;
const spendingLimitPda = multisig.getSpendingLimitPda({
multisigPda,
createKey: spendingLimitCreateKey,
})[0];
multisig.rpc.multisigAddSpendingLimit({
connection,
feePayer,
// The multisig account Public Key
multisigPda,
// The spending limit account Public Key
spendingLimit: spendingLimitPda,
createKey: spendingLimitCreateKey,
// Rent payer for state
rentPayer: feePayer,
// Spending limit amount
amount: BigInt(1000000000),
configAuthority: configAuthority.publicKey,
// Spending limit will apply daily, see reference for more info
period: multisig.generated.Period.Day,
// The mint of the token to apply the spending limit on
mint: Keypair.generate().publicKey,
destinations: [Keypair.generate().publicKey],
// Public Keys that can use the spending limit. At least one is required
members: [Keypair.generate().publicKey],
vaultIndex: 1,
// The config authority must sign the transaction
signers: [configAuthority],
});
Error Handling
| Error | Cause | Solution |
|---|---|---|
| Invalid config authority | Wrong or missing config authority | Verify config authority is set on multisig |
| Not a controlled multisig | Multisig has no config authority | Use Config Transaction instead |