Class: Solace::Composers::ComputeBudgetProgramSetComputeUnitPriceComposer

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

Overview

Composer for creating a compute budget set compute unit price instruction.

This composer resolves and orders the required accounts for a SetComputeUnitPrice instruction, sets up their access permissions, and delegates construction to the appropriate instruction builder (Instructions::ComputeBudget::SetComputeUnitPriceInstruction).

It is used for attaching a priority fee to a transaction.

Required accounts:

  • Program: Compute Budget program (readonly, non-signer)

Examples:

Compose and build a set compute unit price instruction

composer = ComputeBudgetProgramSetComputeUnitPriceComposer.new(
  micro_lamports: 50_000
)

See Also:

Since:

  • 0.1.7

Instance Attribute Summary

Attributes inherited from Base

#account_context, #params

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Solace::Composers::Base

Instance Method Details

#build_instruction(account_context) ⇒ Solace::Instruction

Build instruction with resolved account indices

Parameters:

Returns:

Since:

  • 0.1.7



50
51
52
53
54
55
# File 'lib/solace/composers/compute_budget_program_set_compute_unit_price_composer.rb', line 50

def build_instruction()
  Instructions::ComputeBudget::SetComputeUnitPriceInstruction.build(
    micro_lamports: micro_lamports,
    program_index:  .index_of(compute_budget_program)
  )
end

#compute_budget_programString

Returns the compute budget program id

Returns:

  • (String)

    The compute budget program id

Since:

  • 0.1.7



34
35
36
# File 'lib/solace/composers/compute_budget_program_set_compute_unit_price_composer.rb', line 34

def compute_budget_program
  Constants::COMPUTE_BUDGET_PROGRAM_ID.to_s
end

#micro_lamportsInteger

Extracts the price per compute unit from the params

Returns:

  • (Integer)

    The price per compute unit (in micro-lamports)

Since:

  • 0.1.7



27
28
29
# File 'lib/solace/composers/compute_budget_program_set_compute_unit_price_composer.rb', line 27

def micro_lamports
  params[:micro_lamports]
end

#setup_accountsvoid

This method returns an undefined value.

Setup accounts required for set compute unit price instruction Called automatically during initialization

Since:

  • 0.1.7



42
43
44
# File 'lib/solace/composers/compute_budget_program_set_compute_unit_price_composer.rb', line 42

def setup_accounts
  .add_readonly_nonsigner(compute_budget_program)
end