Class: Solace::SquadsSmartAccounts::Instructions::AddSpendingLimitAsAuthorityInstruction

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

Overview

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

Creates a SpendingLimit PDA granting designated signers a pre-authorized allowance from a vault. Only callable by the account’s settings authority — no consensus involved.

IDL accounts (in order):

0. settings          — readonly, non-signer
1. settingsAuthority — readonly, signer
2. spendingLimit     — writable, non-signer (PDA to be created)
3. rentPayer         — writable, signer (funds the new account's rent)
4. systemProgram     — readonly, non-signer
5. program           — readonly, non-signer

Constant Summary collapse

DISCRIMINATOR =
[169, 189, 84, 54, 30, 244, 223, 212].freeze

Class Method Summary collapse

Class Method Details

.build(seed:, account_index:, mint:, amount:, period:, signers:, destinations:, expiration:, memo:, settings_index:, settings_authority_index:, spending_limit_index:, rent_payer_index:, system_program_index:, program_index:) ⇒ Solace::Instruction

Builds a Instruction for addSpendingLimitAsAuthority.

Parameters:

  • seed (#to_s)

    Arbitrary pubkey seeding the SpendingLimit PDA.

  • account_index (Integer)

    Vault index the limit spends from.

  • mint (#to_s)

    Token mint; DEFAULT_PUBKEY for SOL.

  • 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.

  • destinations (Array<#to_s>)

    Allowed destinations; empty = any.

  • expiration (Integer)

    Unix expiration timestamp; I64_MAX = never.

  • memo (String, nil)

    Optional indexing memo.

  • settings_index (Integer)

    Account index of the settings account.

  • settings_authority_index (Integer)

    Account index of the settings authority.

  • spending_limit_index (Integer)

    Account index of the SpendingLimit PDA.

  • rent_payer_index (Integer)

    Account index of the rent payer.

  • system_program_index (Integer)

    Account index of systemProgram.

  • program_index (Integer)

    Account index of the Squads program.

Returns:

  • (Solace::Instruction)


42
43
44
45
46
47
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/add_spending_limit_as_authority_instruction.rb', line 42

def self.build(
  seed:,
  account_index:,
  mint:,
  amount:,
  period:,
  signers:,
  destinations:,
  expiration:,
  memo:,
  settings_index:,
  settings_authority_index:,
  spending_limit_index:,
  rent_payer_index:,
  system_program_index:,
  program_index:
)
  Solace::Instruction.new.tap do |ix|
    ix.program_index = program_index
    ix.accounts      = [
      settings_index,
      settings_authority_index,
      spending_limit_index,
      rent_payer_index,
      system_program_index,
      program_index
    ]

    ix.data = data(
      seed:,
      account_index:,
      mint:,
      amount:,
      period:,
      signers:,
      destinations:,
      expiration:,
      memo:
    )
  end
end

.data(seed:, account_index:, mint:, amount:, period:, signers:, destinations:, expiration:, memo:) ⇒ Array<Integer>

Encodes the ‘AddSpendingLimitArgs` struct in Borsh format.

Returns:

  • (Array<Integer>)

    Byte array of the encoded instruction data.



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/solace/squads_smart_accounts/instructions/add_spending_limit_as_authority_instruction.rb', line 87

def self.data(
  seed:,
  account_index:,
  mint:,
  amount:,
  period:,
  signers:,
  destinations:,
  expiration:,
  memo:
)
  DISCRIMINATOR +
    Solace::Utils::Codecs.encode_pubkey(seed) +
    [] +
    Solace::Utils::Codecs.encode_pubkey(mint) +
    Solace::Utils::Codecs.encode_le_u64(amount).bytes +
    [period] +
    Solace::Utils::Codecs.encode_vec_pubkeys(signers) +
    Solace::Utils::Codecs.encode_vec_pubkeys(destinations) +
    Solace::Utils::Codecs.encode_le_i64(expiration).bytes +
    Solace::Utils::Codecs.encode_option_string(memo)
end