Class: Solace::SquadsSmartAccounts::Instructions::CreateTransactionInstruction

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

Overview

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

Stores a pending vault transaction (a compiled TransactionMessage) on-chain. The transaction does not execute here — it awaits a proposal and approvals.

IDL accounts (in order):

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

NOTE: the bundled IDL is stale for this instruction. The deployed program is the newer version that (a) models the args as a ‘TransactionPayload` enum variant and (b) requires the Squads `program` as a trailing account. Both are reflected here.

Constant Summary collapse

DISCRIMINATOR =

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

[227, 193, 53, 239, 55, 126, 112, 105].freeze

Class Method Summary collapse

Class Method Details

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

Builds a Instruction for createTransaction.

Parameters:

  • account_index (Integer)

    Vault index the inner message spends from.

  • ephemeral_signers (Integer)

    Number of ephemeral signer PDAs (0 for simple messages).

  • transaction_message (Array<Integer>)

    The serialized TransactionMessage bytes.

  • memo (String, nil)

    Optional indexing memo.

  • settings_index (Integer)

    Account index of the settings account.

  • transaction_index (Integer)

    Account index of the transaction 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
64
65
66
67
68
69
70
# File 'lib/solace/squads_smart_accounts/instructions/create_transaction_instruction.rb', line 40

def self.build(
  account_index:,
  ephemeral_signers:,
  transaction_message:,
  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(
      account_index:,
      ephemeral_signers:,
      transaction_message:,
      memo:
    )
  end
end

.data(account_index:, ephemeral_signers:, transaction_message:, memo:) ⇒ Array<Integer>

Encodes the ‘CreateTransactionArgs::TransactionPayload` variant in Borsh.

Returns:

  • (Array<Integer>)

    Byte array of the encoded instruction data.



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

def self.data(
  account_index:,
  ephemeral_signers:,
  transaction_message:,
  memo:
)
  DISCRIMINATOR +
    # Borsh enum variant index for `CreateTransactionArgs::TransactionPayload`.
    # The deployed program models the args as an enum (TransactionPayload |
    # PolicyPayload) even though the bundled IDL still describes the legacy
    # flat struct — so the serialized data leads with this variant byte.
    [0] +
    [] +
    [ephemeral_signers] +
    Solace::Utils::Codecs.encode_bytes(transaction_message) +
    Solace::Utils::Codecs.encode_option_string(memo)
end