Class: Solace::SquadsSmartAccounts::Instructions::UseSpendingLimitInstruction

Inherits:
Object
  • Object
show all
Defined in:
lib/solace/squads_smart_accounts/instructions/use_spending_limit_instruction.rb

Overview

Encodes the ‘useSpendingLimit` instruction for the Squads Smart Account program.

Transfers funds from a vault to a destination within a pre-authorized spending limit — single signature from an allowed signer, no consensus.

IDL accounts (in order):

 0. settings                 — readonly, non-signer
 1. signer                   — readonly, signer (must be allowed by the limit)
 2. spendingLimit            — writable, non-signer
 3. smartAccount             — writable, non-signer (vault to transfer from)
 4. destination              — writable, non-signer
 5. systemProgram            — readonly, optional (required for SOL limits)
 6. mint                     — readonly, optional (SPL limits only)
 7. smartAccountTokenAccount — writable, optional (SPL limits only)
 8. destinationTokenAccount  — writable, optional (SPL limits only)
 9. tokenProgram             — readonly, optional (SPL limits only)
10. program                  — readonly, non-signer

Absent optional accounts are signaled by passing the Squads program ID in their slot (Anchor’s optional-account convention). For SOL limits the four SPL slots must all be the program ID.

Constant Summary collapse

DISCRIMINATOR =

8-byte Anchor discriminator: SHA256(“global:use_spending_limit”)

[41, 179, 70, 5, 194, 147, 239, 158].freeze

Class Method Summary collapse

Class Method Details

.build(amount:, decimals:, memo:, settings_index:, signer_index:, spending_limit_index:, smart_account_index:, destination_index:, system_program_index:, mint_index:, smart_account_token_account_index:, destination_token_account_index:, token_program_index:, program_index:) ⇒ Solace::Instruction

Builds a Instruction for useSpendingLimit.

Parameters:

  • amount (Integer)

    Amount of tokens to transfer (mint decimals).

  • decimals (Integer)

    Decimals of the mint (9 for SOL) — order-of-magnitude check.

  • memo (String, nil)

    Optional indexing memo.

  • settings_index (Integer)

    Account index of the settings account.

  • signer_index (Integer)

    Account index of the allowed signer.

  • spending_limit_index (Integer)

    Account index of the SpendingLimit PDA.

  • smart_account_index (Integer)

    Account index of the vault.

  • destination_index (Integer)

    Account index of the destination.

  • system_program_index (Integer)

    Account index of systemProgram.

  • mint_index (Integer)

    Account index of the mint (program ID slot for SOL).

  • smart_account_token_account_index (Integer)

    Vault ATA index (program ID slot for SOL).

  • destination_token_account_index (Integer)

    Destination ATA index (program ID slot for SOL).

  • token_program_index (Integer)

    Token program index (program ID slot for SOL).

  • program_index (Integer)

    Account index of the Squads program.

Returns:

  • (Solace::Instruction)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/solace/squads_smart_accounts/instructions/use_spending_limit_instruction.rb', line 48

def self.build(
  amount:,
  decimals:,
  memo:,
  settings_index:,
  signer_index:,
  spending_limit_index:,
  smart_account_index:,
  destination_index:,
  system_program_index:,
  mint_index:,
  smart_account_token_account_index:,
  destination_token_account_index:,
  token_program_index:,
  program_index:
)
  Solace::Instruction.new.tap do |ix|
    ix.program_index = program_index
    ix.accounts      = [
      settings_index,
      signer_index,
      spending_limit_index,
      ,
      destination_index,
      system_program_index,
      mint_index,
      ,
      ,
      token_program_index,
      program_index
    ]

    ix.data = data(amount:, decimals:, memo:)
  end
end

.data(amount:, decimals:, memo:) ⇒ Array<Integer>

Encodes the ‘UseSpendingLimitArgs` struct in Borsh format.

Returns:

  • (Array<Integer>)

    Byte array of the encoded instruction data.



87
88
89
90
91
92
# File 'lib/solace/squads_smart_accounts/instructions/use_spending_limit_instruction.rb', line 87

def self.data(amount:, decimals:, memo:)
  DISCRIMINATOR +
    Solace::Utils::Codecs.encode_le_u64(amount).bytes +
    [decimals] +
    Solace::Utils::Codecs.encode_option_string(memo)
end