Class: Solace::Instructions::ComputeBudget::SetComputeUnitLimitInstruction

Inherits:
Object
  • Object
show all
Defined in:
lib/solace/instructions/compute_budget/set_compute_unit_limit_instruction.rb

Overview

Instruction for setting the compute unit limit.

This instruction is used to set the maximum number of compute units a transaction may consume. Together with the compute unit price, it determines the priority fee the transaction pays.

Examples:

Build a SetComputeUnitLimit instruction

instruction = Solace::Instructions::ComputeBudget::SetComputeUnitLimitInstruction.build(
  units: 200_000,
  program_index: 1
)

Since:

  • 0.1.7

Constant Summary collapse

INSTRUCTION_INDEX =

Since:

  • 0.1.7

[2].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#INSTRUCTION_INDEXObject (readonly)

Instruction index for the Compute Budget Program's SetComputeUnitLimit instruction.



22
# File 'lib/solace/instructions/compute_budget/set_compute_unit_limit_instruction.rb', line 22

INSTRUCTION_INDEX = [2].freeze

Class Method Details

.build(units:, program_index:) ⇒ Solace::Instruction

Builds a Solace::Instruction for setting the compute unit limit

Parameters:

  • units (Integer)

    Maximum compute units the transaction may consume

  • program_index (Integer)

    Index of the Compute Budget program in the transaction's accounts

Returns:

Since:

  • 0.1.7



29
30
31
32
33
34
35
# File 'lib/solace/instructions/compute_budget/set_compute_unit_limit_instruction.rb', line 29

def self.build(units:, program_index:)
  Solace::Instruction.new.tap do |ix|
    ix.program_index = program_index
    ix.accounts      = []
    ix.data          = data(units)
  end
end

.data(units) ⇒ Array<Integer>

Instruction data for a set compute unit limit instruction

The BufferLayout is:

- [Instruction Index (1 byte)]
- [Compute unit limit (4 bytes little-endian u32)]

Parameters:

  • units (Integer)

    Maximum compute units the transaction may consume

Returns:

  • (Array<Integer>)

    1-byte instruction index + 4-byte limit

Since:

  • 0.1.7



45
46
47
# File 'lib/solace/instructions/compute_budget/set_compute_unit_limit_instruction.rb', line 45

def self.data(units)
  INSTRUCTION_INDEX + Solace::Utils::Codecs.encode_le_u32(units).bytes
end