Class: Solace::SquadsSmartAccounts::Instructions::CreateSmartAccountInstruction

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

Overview

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

Creates a new smart account (multisig) on-chain. The resulting settings account is a PDA derived from the creator’s public key.

IDL accounts (in order):

0. programConfig  — writable, non-signer
1. treasury       — writable, non-signer
2. creator        — writable, signer
3. systemProgram  — readonly, non-signer
4. program        — readonly, non-signer
5. settings       — writable, non-signer (remaining account — PDA to be created)

Constant Summary collapse

DISCRIMINATOR =

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

[197, 102, 253, 231, 77, 84, 50, 17].freeze

Class Method Summary collapse

Class Method Details

.build(settings_authority:, threshold:, signers:, time_lock:, rent_collector:, memo:, program_config_index:, treasury_index:, creator_index:, system_program_index:, program_index:, settings_index:) ⇒ Solace::Instruction

Builds a Instruction for createSmartAccount.

Parameters:

  • settings_authority (String, nil)

    Base58 pubkey of the optional reconfiguration authority, or nil for autonomous smart accounts.

  • threshold (Integer)

    Number of approvals required to execute a transaction.

  • signers (Array<SmartAccountSigner>)

    Signers on the smart account.

  • time_lock (Integer)

    Seconds that must pass between proposal and execution.

  • rent_collector (String, nil)

    Base58 pubkey for reclaiming rent, or nil.

  • memo (String, nil)

    Optional indexing memo.

  • program_config_index (Integer)

    Account index of programConfig.

  • treasury_index (Integer)

    Account index of treasury.

  • creator_index (Integer)

    Account index of creator.

  • system_program_index (Integer)

    Account index of systemProgram.

  • program_index (Integer)

    Account index of the Squads program.

  • settings_index (Integer)

    Account index of the settings PDA to be created.

Returns:

  • (Solace::Instruction)


38
39
40
41
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
# File 'lib/solace/squads_smart_accounts/instructions/create_smart_account_instruction.rb', line 38

def self.build(
  settings_authority:,
  threshold:,
  signers:,
  time_lock:,
  rent_collector:,
  memo:,
  program_config_index:,
  treasury_index:,
  creator_index:,
  system_program_index:,
  program_index:,
  settings_index:
)
  Solace::Instruction.new.tap do |ix|
    ix.program_index = program_index
    ix.accounts      = [
      program_config_index,
      treasury_index,
      creator_index,
      system_program_index,
      program_index,
      settings_index
    ]

    ix.data = data(
      settings_authority:,
      threshold:,
      signers:,
      time_lock:,
      rent_collector:,
      memo:
    )
  end
end

.data(settings_authority:, threshold:, signers:, time_lock:, rent_collector:, memo:) ⇒ Array<Integer>

Encodes the ‘CreateSmartAccountArgs` struct in Borsh format.

Returns:

  • (Array<Integer>)

    Byte array of the encoded instruction data.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/solace/squads_smart_accounts/instructions/create_smart_account_instruction.rb', line 77

def self.data(
  settings_authority:,
  threshold:,
  signers:,
  time_lock:,
  rent_collector:,
  memo:
)
  DISCRIMINATOR +
    Solace::Utils::Codecs.encode_option_pubkey(settings_authority) +
    Solace::Utils::Codecs.encode_le_u16(threshold).bytes +
    Solace::Utils::Codecs.(signers) +
    Solace::Utils::Codecs.encode_le_u32(time_lock).bytes +
    Solace::Utils::Codecs.encode_option_pubkey(rent_collector) +
    Solace::Utils::Codecs.encode_option_string(memo)
end