Class: Solace::SquadsSmartAccounts::Instructions::CreateSettingsTransactionInstruction

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

Overview

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

Stores a batch of SettingsActions on-chain as a SettingsTransaction, to be applied later by ‘executeSettingsTransaction` once its proposal is approved. Autonomous accounts only — controlled accounts use the *AsAuthority instructions.

Accounts (in order):

0. settings      — writable, non-signer
1. transaction   — writable, non-signer (SettingsTransaction PDA to create)
2. creator       — readonly, signer (must be a signer with Initiate permission)
3. rentPayer     — writable, signer (funds the new account's rent)
4. systemProgram — readonly, non-signer
5. program       — readonly, non-signer (the Squads program itself)

The SettingsTransaction PDA shares the vault Transaction seeds [“smart_account”, settings, “transaction”, u64(index)]; only the stored account type differs.

Constant Summary collapse

DISCRIMINATOR =
[101, 168, 254, 203, 222, 102, 95, 192].freeze

Class Method Summary collapse

Class Method Details

.build(actions:, memo:, settings_index:, transaction_index:, creator_index:, rent_payer_index:, system_program_index:, program_index:) ⇒ Solace::Instruction

Builds a Instruction for createSettingsTransaction.

Parameters:

  • actions (Array<SettingsAction>)

    The settings actions to store.

  • memo (String, nil)

    Optional indexing memo.

  • settings_index (Integer)

    Account index of the settings account.

  • transaction_index (Integer)

    Account index of the SettingsTransaction PDA.

  • creator_index (Integer)

    Account index of the creator.

  • 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 (the invoked program).

Returns:

  • (Solace::Instruction)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/solace/squads_smart_accounts/instructions/create_settings_transaction_instruction.rb', line 40

def self.build(
  actions:,
  memo:,
  settings_index:,
  transaction_index:,
  creator_index:,
  rent_payer_index:,
  system_program_index:,
  program_index:
)
  Solace::Instruction.new.tap do |ix|
    ix.program_index = program_index
    ix.accounts      = [
      settings_index,
      transaction_index,
      creator_index,
      rent_payer_index,
      system_program_index,
      program_index
    ]

    ix.data = data(actions:, memo:)
  end
end

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

Encodes the ‘CreateSettingsTransactionArgs { actions, memo }` in Borsh.

Parameters:

  • actions (Array<SettingsAction>)

    The settings actions to store.

  • memo (String, nil)

    Optional indexing memo.

Returns:

  • (Array<Integer>)

    Byte array of the encoded instruction data.



70
71
72
73
74
# File 'lib/solace/squads_smart_accounts/instructions/create_settings_transaction_instruction.rb', line 70

def self.data(actions:, memo:)
  DISCRIMINATOR +
    Solace::Utils::Codecs.encode_settings_actions(actions) +
    Solace::Utils::Codecs.encode_option_string(memo)
end