Class: Solace::Composers::ComputeBudgetProgramSetComputeUnitLimitComposer

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

Overview

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

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

It is used for capping the compute units a transaction may consume.

Required accounts:

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

Examples:

Compose and build a set compute unit limit instruction

composer = ComputeBudgetProgramSetComputeUnitLimitComposer.new(
  units: 200_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_limit_composer.rb', line 50

def build_instruction()
  Instructions::ComputeBudget::SetComputeUnitLimitInstruction.build(
    units:         units,
    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_limit_composer.rb', line 34

def compute_budget_program
  Constants::COMPUTE_BUDGET_PROGRAM_ID.to_s
end

#setup_accountsvoid

This method returns an undefined value.

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

Since:

  • 0.1.7



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

def setup_accounts
  .add_readonly_nonsigner(compute_budget_program)
end

#unitsInteger

Extracts the compute unit limit from the params

Returns:

  • (Integer)

    The compute unit limit

Since:

  • 0.1.7



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

def units
  params[:units]
end