solace 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 378cd7a1cb5958d12bfbe371485f60c12c72e04141bb557a7ef61dde617b0dfe
4
- data.tar.gz: e36f6aa0189ff832b3ca440a1a38690984d69081dcde8b9613d632320d481cf5
3
+ metadata.gz: ab3415933c7875971ad410ecc1d8d7487233a7eb58e9c3701f23babdaae9fbd5
4
+ data.tar.gz: a9ef2bbb03d7988487ae48bff51122dc45670e5ad6ef8c8d6154fa386d0a1281
5
5
  SHA512:
6
- metadata.gz: 9c15791a7b1967d19f676e594556f19fb29ea1b431c97e9a5f6ddb0c8344b87b4301e402116bd8896da7c14ba50a5f5de1eb5a5791b41df7c4134ee89f397926
7
- data.tar.gz: cb1add67763169e8bb498987f3f760def67a5c92e647852f8e5e4308a5a1a41cb046df0aa8a720202d32b7c82bbe6541e945815e6e45738fd63215b23080e2bc
6
+ metadata.gz: 869108bf70f8a9143e28dae425a5e843135aedfd78642c39683fd214ab4a3d1c847125e0e2f0fc60b1766ac45970dc8f14bfc512861db95b89cdaaedc593226d
7
+ data.tar.gz: 8ff9bcac1403007eb3dcc340587c76f4acb5dff266390621f16708589153644db16a16cdb0f08936f3d3a690c2943d78edd570735e9f0692eac6ffb62ee3c969
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solace
4
+ module Composers
5
+ # Composer for creating a compute budget set compute unit limit instruction.
6
+ #
7
+ # This composer resolves and orders the required accounts for a `SetComputeUnitLimit`
8
+ # instruction, sets up their access permissions, and delegates construction to the
9
+ # appropriate instruction builder (`Instructions::ComputeBudget::SetComputeUnitLimitInstruction`).
10
+ #
11
+ # It is used for capping the compute units a transaction may consume.
12
+ #
13
+ # Required accounts:
14
+ # - **Program**: Compute Budget program (readonly, non-signer)
15
+ #
16
+ # @example Compose and build a set compute unit limit instruction
17
+ # composer = ComputeBudgetProgramSetComputeUnitLimitComposer.new(
18
+ # units: 200_000
19
+ # )
20
+ #
21
+ # @see Instructions::ComputeBudget::SetComputeUnitLimitInstruction
22
+ # @since 0.1.7
23
+ class ComputeBudgetProgramSetComputeUnitLimitComposer < Base
24
+ # Extracts the compute unit limit from the params
25
+ #
26
+ # @return [Integer] The compute unit limit
27
+ def units
28
+ params[:units]
29
+ end
30
+
31
+ # Returns the compute budget program id
32
+ #
33
+ # @return [String] The compute budget program id
34
+ def compute_budget_program
35
+ Constants::COMPUTE_BUDGET_PROGRAM_ID.to_s
36
+ end
37
+
38
+ # Setup accounts required for set compute unit limit instruction
39
+ # Called automatically during initialization
40
+ #
41
+ # @return [void]
42
+ def setup_accounts
43
+ account_context.add_readonly_nonsigner(compute_budget_program)
44
+ end
45
+
46
+ # Build instruction with resolved account indices
47
+ #
48
+ # @param account_context [Utils::AccountContext] The account context
49
+ # @return [Solace::Instruction]
50
+ def build_instruction(account_context)
51
+ Instructions::ComputeBudget::SetComputeUnitLimitInstruction.build(
52
+ units: units,
53
+ program_index: account_context.index_of(compute_budget_program)
54
+ )
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solace
4
+ module Composers
5
+ # Composer for creating a compute budget set compute unit price instruction.
6
+ #
7
+ # This composer resolves and orders the required accounts for a `SetComputeUnitPrice`
8
+ # instruction, sets up their access permissions, and delegates construction to the
9
+ # appropriate instruction builder (`Instructions::ComputeBudget::SetComputeUnitPriceInstruction`).
10
+ #
11
+ # It is used for attaching a priority fee to a transaction.
12
+ #
13
+ # Required accounts:
14
+ # - **Program**: Compute Budget program (readonly, non-signer)
15
+ #
16
+ # @example Compose and build a set compute unit price instruction
17
+ # composer = ComputeBudgetProgramSetComputeUnitPriceComposer.new(
18
+ # micro_lamports: 50_000
19
+ # )
20
+ #
21
+ # @see Instructions::ComputeBudget::SetComputeUnitPriceInstruction
22
+ # @since 0.1.7
23
+ class ComputeBudgetProgramSetComputeUnitPriceComposer < Base
24
+ # Extracts the price per compute unit from the params
25
+ #
26
+ # @return [Integer] The price per compute unit (in micro-lamports)
27
+ def micro_lamports
28
+ params[:micro_lamports]
29
+ end
30
+
31
+ # Returns the compute budget program id
32
+ #
33
+ # @return [String] The compute budget program id
34
+ def compute_budget_program
35
+ Constants::COMPUTE_BUDGET_PROGRAM_ID.to_s
36
+ end
37
+
38
+ # Setup accounts required for set compute unit price instruction
39
+ # Called automatically during initialization
40
+ #
41
+ # @return [void]
42
+ def setup_accounts
43
+ account_context.add_readonly_nonsigner(compute_budget_program)
44
+ end
45
+
46
+ # Build instruction with resolved account indices
47
+ #
48
+ # @param account_context [Utils::AccountContext] The account context
49
+ # @return [Solace::Instruction]
50
+ def build_instruction(account_context)
51
+ Instructions::ComputeBudget::SetComputeUnitPriceInstruction.build(
52
+ micro_lamports: micro_lamports,
53
+ program_index: account_context.index_of(compute_budget_program)
54
+ )
55
+ end
56
+ end
57
+ end
58
+ end
@@ -157,6 +157,17 @@ module Solace
157
157
  [@last_fetched_blockhash, @last_fetched_block_height]
158
158
  end
159
159
 
160
+ # Get the current block height from the Solana node
161
+ #
162
+ # Defaults to the connection's commitment so comparisons against the
163
+ # +lastValidBlockHeight+ from {#get_latest_blockhash} stay consistent.
164
+ #
165
+ # @param commitment [String] The commitment level for the request
166
+ # @return [Integer] The current block height
167
+ def get_block_height(commitment: default_options[:commitment])
168
+ @rpc_client.rpc_request('getBlockHeight', [{ commitment: commitment }])['result']
169
+ end
170
+
160
171
  # Get the minimum required lamports for rent exemption
161
172
  #
162
173
  # @param space [Integer] Number of bytes to allocate for the account
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solace
4
+ module Instructions
5
+ module ComputeBudget
6
+ # Instruction for setting the compute unit limit.
7
+ #
8
+ # This instruction is used to set the maximum number of compute units a
9
+ # transaction may consume. Together with the compute unit price, it
10
+ # determines the priority fee the transaction pays.
11
+ #
12
+ # @example Build a SetComputeUnitLimit instruction
13
+ # instruction = Solace::Instructions::ComputeBudget::SetComputeUnitLimitInstruction.build(
14
+ # units: 200_000,
15
+ # program_index: 1
16
+ # )
17
+ #
18
+ # @since 0.1.7
19
+ class SetComputeUnitLimitInstruction
20
+ # @!attribute [Array<Integer>] INSTRUCTION_INDEX
21
+ # Instruction index for the Compute Budget Program's SetComputeUnitLimit instruction.
22
+ INSTRUCTION_INDEX = [2].freeze
23
+
24
+ # Builds a Solace::Instruction for setting the compute unit limit
25
+ #
26
+ # @param units [Integer] Maximum compute units the transaction may consume
27
+ # @param program_index [Integer] Index of the Compute Budget program in the transaction's accounts
28
+ # @return [Solace::Instruction]
29
+ def self.build(units:, program_index:)
30
+ Solace::Instruction.new.tap do |ix|
31
+ ix.program_index = program_index
32
+ ix.accounts = []
33
+ ix.data = data(units)
34
+ end
35
+ end
36
+
37
+ # Instruction data for a set compute unit limit instruction
38
+ #
39
+ # The BufferLayout is:
40
+ # - [Instruction Index (1 byte)]
41
+ # - [Compute unit limit (4 bytes little-endian u32)]
42
+ #
43
+ # @param units [Integer] Maximum compute units the transaction may consume
44
+ # @return [Array<Integer>] 1-byte instruction index + 4-byte limit
45
+ def self.data(units)
46
+ INSTRUCTION_INDEX + Solace::Utils::Codecs.encode_le_u32(units).bytes
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solace
4
+ module Instructions
5
+ # The ComputeBudget module contains instruction builders for the Compute Budget Program.
6
+ #
7
+ # The Compute Budget program prices and provisions a transaction's execution. Its
8
+ # instructions take no accounts; each encodes a directive the runtime reads when
9
+ # scheduling and executing the transaction, such as the priority fee attached to it.
10
+ #
11
+ # This module contains classes that build the low-level instruction data required
12
+ # to interact with the Compute Budget Program.
13
+ #
14
+ # @see https://docs.solana.com/developing/programming-model/runtime#compute-budget
15
+ # @since 0.1.7
16
+ module ComputeBudget
17
+ # Instruction for setting the compute unit price.
18
+ #
19
+ # This instruction is used to set the price (in micro-lamports per compute unit)
20
+ # a transaction pays as a priority fee, which validators use to order it during
21
+ # congestion.
22
+ #
23
+ # @example Build a SetComputeUnitPrice instruction
24
+ # instruction = Solace::Instructions::ComputeBudget::SetComputeUnitPriceInstruction.build(
25
+ # micro_lamports: 50_000,
26
+ # program_index: 1
27
+ # )
28
+ #
29
+ # @since 0.1.7
30
+ class SetComputeUnitPriceInstruction
31
+ # @!attribute [Array<Integer>] INSTRUCTION_INDEX
32
+ # Instruction index for the Compute Budget Program's SetComputeUnitPrice instruction.
33
+ INSTRUCTION_INDEX = [3].freeze
34
+
35
+ # Builds a Solace::Instruction for setting the compute unit price
36
+ #
37
+ # @param micro_lamports [Integer] Price per compute unit (in micro-lamports)
38
+ # @param program_index [Integer] Index of the Compute Budget program in the transaction's accounts
39
+ # @return [Solace::Instruction]
40
+ def self.build(micro_lamports:, program_index:)
41
+ Solace::Instruction.new.tap do |ix|
42
+ ix.program_index = program_index
43
+ ix.accounts = []
44
+ ix.data = data(micro_lamports)
45
+ end
46
+ end
47
+
48
+ # Instruction data for a set compute unit price instruction
49
+ #
50
+ # The BufferLayout is:
51
+ # - [Instruction Index (1 byte)]
52
+ # - [Price (8 bytes little-endian u64)]
53
+ #
54
+ # @param micro_lamports [Integer] Price per compute unit (in micro-lamports)
55
+ # @return [Array<Integer>] 1-byte instruction index + 8-byte price
56
+ def self.data(micro_lamports)
57
+ INSTRUCTION_INDEX + Solace::Utils::Codecs.encode_le_u64(micro_lamports).bytes
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Solace
4
4
  # Latest version of the Solace gem.
5
- VERSION = '0.1.6'
5
+ VERSION = '0.1.7'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Scholl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-06-22 00:00:00.000000000 Z
11
+ date: 2026-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base58
@@ -206,6 +206,8 @@ files:
206
206
  - lib/solace/composers/associated_token_account_program_create_account_composer.rb
207
207
  - lib/solace/composers/associated_token_account_program_create_idempotent_account_composer.rb
208
208
  - lib/solace/composers/base.rb
209
+ - lib/solace/composers/compute_budget_program_set_compute_unit_limit_composer.rb
210
+ - lib/solace/composers/compute_budget_program_set_compute_unit_price_composer.rb
209
211
  - lib/solace/composers/spl_token_program_close_account_composer.rb
210
212
  - lib/solace/composers/spl_token_program_initialize_mint_composer.rb
211
213
  - lib/solace/composers/spl_token_program_mint_to_composer.rb
@@ -231,6 +233,8 @@ files:
231
233
  - lib/solace/instruction.rb
232
234
  - lib/solace/instructions/associated_token_account/create_account_instruction.rb
233
235
  - lib/solace/instructions/associated_token_account/create_idempotent_account_instruction.rb
236
+ - lib/solace/instructions/compute_budget/set_compute_unit_limit_instruction.rb
237
+ - lib/solace/instructions/compute_budget/set_compute_unit_price_instruction.rb
234
238
  - lib/solace/instructions/spl_token/close_account_instruction.rb
235
239
  - lib/solace/instructions/spl_token/initialize_account_instruction.rb
236
240
  - lib/solace/instructions/spl_token/initialize_mint_instruction.rb