Class: Solace::SquadsSmartAccounts::Instructions::CreateProposalInstruction

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

Overview

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

Creates the Proposal account that tracks votes for a previously stored Transaction. A proposal created with ‘draft: false` starts `Active` (ready to vote); `draft: true` starts `Draft` and must be activated first.

Accounts (in order):

0. settings      — readonly, non-signer (consensus account)
1. proposal      — writable, non-signer (PDA to be created)
2. creator       — readonly, signer (must be a smart-account 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)

The trailing ‘program` account is required by the deployed program and is not in the bundled IDL (see memory `reference-deployed-program-drift`).

Constant Summary collapse

DISCRIMINATOR =

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

[132, 116, 68, 174, 216, 160, 198, 22].freeze

Class Method Summary collapse

Class Method Details

.build(transaction_index:, draft:, settings_index:, proposal_index:, creator_index:, rent_payer_index:, system_program_index:, program_index:) ⇒ Solace::Instruction

Builds a Instruction for createProposal.

Parameters:

  • transaction_index (Integer)

    Index of the transaction this proposal tracks (u64).

  • draft (Boolean)

    Whether to initialize the proposal as Draft (vs Active).

  • settings_index (Integer)

    Account index of the settings account.

  • proposal_index (Integer)

    Account index of the proposal 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)


37
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
# File 'lib/solace/squads_smart_accounts/instructions/create_proposal_instruction.rb', line 37

def self.build(
  transaction_index:,
  draft:,
  settings_index:,
  proposal_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,
      proposal_index,
      creator_index,
      rent_payer_index,
      system_program_index,
      program_index
    ]

    ix.data = data(
      transaction_index:,
      draft:
    )
  end
end

.data(transaction_index:, draft:) ⇒ Array<Integer>

Encodes the ‘CreateProposalArgs { transaction_index: u64, draft: bool }` in Borsh.

Parameters:

  • transaction_index (Integer)

    Index of the transaction this proposal tracks (u64).

  • draft (Boolean)

    Whether to initialize the proposal as Draft.

Returns:

  • (Array<Integer>)

    Byte array of the encoded instruction data.



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

def self.data(transaction_index:, draft:)
  DISCRIMINATOR +
    Solace::Utils::Codecs.encode_le_u64(transaction_index).bytes +
    Solace::Utils::Codecs.encode_bool(draft)
end