Class: Solace::Composers::SquadsSmartAccountsCreateProposalComposer

Inherits:
Base
  • Object
show all
Defined in:
lib/solace/squads_smart_accounts/composers/create_proposal_composer.rb

Overview

Composes a ‘createProposal` instruction for the Squads Smart Account program.

Creates the Proposal account that tracks votes for a stored Transaction. The transaction must already exist (its index is referenced here).

Required params:

:settings          [#to_s]          Base58 address of the settings account.
:proposal          [#to_s]          The Proposal PDA to create.
:creator           [#to_s, Keypair] A smart-account signer creating the proposal (must sign).
:rent_payer        [#to_s, Keypair] Funds the new account's rent (must sign).
:transaction_index [Integer]        Index of the transaction this proposal tracks.

Optional params:

:draft [Boolean] Initialize as Draft instead of Active (default: false).

Instance Method Summary collapse

Instance Method Details

#build_instruction(context) ⇒ Solace::Instruction

Builds the instruction with resolved account indices.

Parameters:

  • context (Solace::Utils::AccountContext)

    Merged context from TransactionComposer.

Returns:

  • (Solace::Instruction)


90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/solace/squads_smart_accounts/composers/create_proposal_composer.rb', line 90

def build_instruction(context)
  SquadsSmartAccounts::Instructions::CreateProposalInstruction.build(
    transaction_index:,
    draft:,
    settings_index:       context.index_of(settings),
    proposal_index:       context.index_of(proposal),
    creator_index:        context.index_of(creator),
    rent_payer_index:     context.index_of(rent_payer),
    system_program_index: context.index_of(system_program),
    program_index:        context.index_of(program_id)
  )
end

#creatorString

Extracts the creator address from the params

Returns:

  • (String)

    The creator address



37
38
39
# File 'lib/solace/squads_smart_accounts/composers/create_proposal_composer.rb', line 37

def creator
  params[:creator].to_s
end

#draftBoolean

Extracts the draft flag from the params

Returns:

  • (Boolean)

    Whether to initialize the proposal as Draft (defaults to false)



58
59
60
# File 'lib/solace/squads_smart_accounts/composers/create_proposal_composer.rb', line 58

def draft
  params[:draft] || false
end

#program_idString

Returns the Squads Smart Account program id from the constants

Returns:

  • (String)

    The Squads Smart Account program id



65
66
67
# File 'lib/solace/squads_smart_accounts/composers/create_proposal_composer.rb', line 65

def program_id
  SquadsSmartAccounts::PROGRAM_ID
end

#proposalString

Extracts the proposal PDA address from the params

Returns:

  • (String)

    The proposal address



30
31
32
# File 'lib/solace/squads_smart_accounts/composers/create_proposal_composer.rb', line 30

def proposal
  params[:proposal].to_s
end

#rent_payerString

Extracts the rent payer address from the params

Returns:

  • (String)

    The rent payer address



44
45
46
# File 'lib/solace/squads_smart_accounts/composers/create_proposal_composer.rb', line 44

def rent_payer
  params[:rent_payer].to_s
end

#settingsString

Extracts the settings address from the params

Returns:

  • (String)

    The settings address



23
24
25
# File 'lib/solace/squads_smart_accounts/composers/create_proposal_composer.rb', line 23

def settings
  params[:settings].to_s
end

#setup_accountsObject

Declares all accounts required by this instruction.



77
78
79
80
81
82
83
84
# File 'lib/solace/squads_smart_accounts/composers/create_proposal_composer.rb', line 77

def setup_accounts
  .add_readonly_nonsigner(settings)
  .add_writable_nonsigner(proposal)
  .add_readonly_signer(creator)
  .add_writable_signer(rent_payer)
  .add_readonly_nonsigner(system_program)
  .add_readonly_nonsigner(program_id)
end

#system_programString

Returns the system program id from the constants

Returns:

  • (String)

    The system program id



72
73
74
# File 'lib/solace/squads_smart_accounts/composers/create_proposal_composer.rb', line 72

def system_program
  Solace::Constants::SYSTEM_PROGRAM_ID
end

#transaction_indexInteger

Extracts the transaction index from the params

Returns:

  • (Integer)

    The transaction index the proposal tracks



51
52
53
# File 'lib/solace/squads_smart_accounts/composers/create_proposal_composer.rb', line 51

def transaction_index
  params[:transaction_index]
end