solace 0.1.5 → 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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/lib/solace/composers/associated_token_account_program_create_account_composer.rb +6 -6
  3. data/lib/solace/composers/associated_token_account_program_create_idempotent_account_composer.rb +2 -1
  4. data/lib/solace/composers/base.rb +1 -1
  5. data/lib/solace/composers/compute_budget_program_set_compute_unit_limit_composer.rb +58 -0
  6. data/lib/solace/composers/compute_budget_program_set_compute_unit_price_composer.rb +58 -0
  7. data/lib/solace/composers/spl_token_program_close_account_composer.rb +3 -3
  8. data/lib/solace/composers/spl_token_program_initialize_mint_composer.rb +5 -5
  9. data/lib/solace/composers/spl_token_program_mint_to_composer.rb +4 -4
  10. data/lib/solace/composers/spl_token_program_transfer_checked_composer.rb +6 -6
  11. data/lib/solace/composers/spl_token_program_transfer_composer.rb +4 -4
  12. data/lib/solace/composers/system_program_create_account_composer.rb +5 -5
  13. data/lib/solace/composers/system_program_transfer_composer.rb +3 -3
  14. data/lib/solace/composers/token_2022_program_close_account_composer.rb +3 -3
  15. data/lib/solace/composers/token_2022_program_initialize_mint_composer.rb +5 -5
  16. data/lib/solace/composers/token_2022_program_mint_to_composer.rb +4 -4
  17. data/lib/solace/composers/token_2022_program_transfer_checked_composer.rb +6 -6
  18. data/lib/solace/composers/token_2022_program_transfer_composer.rb +4 -4
  19. data/lib/solace/connection.rb +16 -5
  20. data/lib/solace/errors/confirmation_timeout.rb +4 -4
  21. data/lib/solace/errors/rpc_error.rb +4 -4
  22. data/lib/solace/instructions/associated_token_account/create_account_instruction.rb +2 -1
  23. data/lib/solace/instructions/compute_budget/set_compute_unit_limit_instruction.rb +51 -0
  24. data/lib/solace/instructions/compute_budget/set_compute_unit_price_instruction.rb +62 -0
  25. data/lib/solace/instructions/spl_token/close_account_instruction.rb +2 -2
  26. data/lib/solace/instructions/spl_token/initialize_account_instruction.rb +2 -2
  27. data/lib/solace/instructions/spl_token/initialize_mint_instruction.rb +2 -2
  28. data/lib/solace/instructions/spl_token/mint_to_instruction.rb +2 -2
  29. data/lib/solace/instructions/spl_token/transfer_checked_instruction.rb +2 -2
  30. data/lib/solace/instructions/spl_token/transfer_instruction.rb +2 -2
  31. data/lib/solace/instructions/system_program/create_account_instruction.rb +2 -2
  32. data/lib/solace/instructions/system_program/transfer_instruction.rb +2 -2
  33. data/lib/solace/instructions/token_2022/close_account_instruction.rb +2 -2
  34. data/lib/solace/instructions/token_2022/initialize_account_instruction.rb +2 -2
  35. data/lib/solace/instructions/token_2022/initialize_mint_instruction.rb +2 -2
  36. data/lib/solace/instructions/token_2022/mint_to_instruction.rb +2 -2
  37. data/lib/solace/instructions/token_2022/transfer_checked_instruction.rb +2 -2
  38. data/lib/solace/instructions/token_2022/transfer_instruction.rb +2 -2
  39. data/lib/solace/message.rb +5 -5
  40. data/lib/solace/programs/associated_token_account.rb +10 -9
  41. data/lib/solace/programs/token_program_interface.rb +18 -18
  42. data/lib/solace/serializers/address_lookup_table_deserializer.rb +2 -2
  43. data/lib/solace/serializers/base_deserializer.rb +1 -1
  44. data/lib/solace/serializers/instruction_deserializer.rb +2 -2
  45. data/lib/solace/serializers/message_deserializer.rb +3 -3
  46. data/lib/solace/serializers/transaction_deserializer.rb +1 -1
  47. data/lib/solace/tokens/token.rb +1 -1
  48. data/lib/solace/tokens.rb +2 -2
  49. data/lib/solace/transaction.rb +1 -1
  50. data/lib/solace/transaction_composer.rb +5 -5
  51. data/lib/solace/utils/account_context.rb +9 -9
  52. data/lib/solace/utils/codecs.rb +309 -49
  53. data/lib/solace/utils/rpc_client.rb +9 -9
  54. data/lib/solace/version.rb +1 -1
  55. metadata +115 -9
  56. data/CHANGELOG +0 -243
  57. data/LICENSE +0 -21
  58. data/README.md +0 -578
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2d850b2d501a6bf777043a53e320a2bef57fee4ea47e9a2a08e3331e4695c8f
4
- data.tar.gz: 80139c66611fb213d966db7f6ea7468a46fec9b8b6418917995c424627f2998b
3
+ metadata.gz: ab3415933c7875971ad410ecc1d8d7487233a7eb58e9c3701f23babdaae9fbd5
4
+ data.tar.gz: a9ef2bbb03d7988487ae48bff51122dc45670e5ad6ef8c8d6154fa386d0a1281
5
5
  SHA512:
6
- metadata.gz: 659cfcfef1750281cb209a0ef13398af0c56c77f0ebe2479380c09d1764cf83eb39c74a08a3fa6234ceb7e9fbd1e97b5abbdd281bee653c39e00c177fea4aa27
7
- data.tar.gz: 9d79ebd0a3c418fca8933b533bd5588605a01338327aeb6b8ed5db831497ea5acd5597d5f82a63ed563ae2e857d84a78745a39c2e1b2750b9b5eb0d5d2e2da09
6
+ metadata.gz: 869108bf70f8a9143e28dae425a5e843135aedfd78642c39683fd214ab4a3d1c847125e0e2f0fc60b1766ac45970dc8f14bfc512861db95b89cdaaedc593226d
7
+ data.tar.gz: 8ff9bcac1403007eb3dcc340587c76f4acb5dff266390621f16708589153644db16a16cdb0f08936f3d3a690c2943d78edd570735e9f0692eac6ffb62ee3c969
@@ -98,13 +98,13 @@ module Solace
98
98
  # @return [Solace::Instruction] The instruction
99
99
  def build_instruction(account_context)
100
100
  Instructions::AssociatedTokenAccount::CreateAccountInstruction.build(
101
- funder_index: account_context.index_of(funder),
102
- owner_index: account_context.index_of(owner),
103
- mint_index: account_context.index_of(mint),
101
+ funder_index: account_context.index_of(funder),
102
+ owner_index: account_context.index_of(owner),
103
+ mint_index: account_context.index_of(mint),
104
104
  associated_token_account_index: account_context.index_of(ata_address),
105
- system_program_index: account_context.index_of(system_program_id),
106
- token_program_index: account_context.index_of(token_program_id),
107
- program_index: account_context.index_of(associated_token_account_program_id)
105
+ system_program_index: account_context.index_of(system_program_id),
106
+ token_program_index: account_context.index_of(token_program_id),
107
+ program_index: account_context.index_of(associated_token_account_program_id)
108
108
  )
109
109
  end
110
110
  end
@@ -4,7 +4,8 @@ module Solace
4
4
  module Composers
5
5
  # Composer for creating an associated token account program create account instruction with idempotency
6
6
  #
7
- # This composer resolves and orders the required accounts for a `CreateIdempotentAssociatedTokenAccount` instruction,
7
+ # This composer resolves and orders the required accounts for a
8
+ # `CreateIdempotentAssociatedTokenAccount` instruction,
8
9
  # sets up their access permissions, and delegates construction to the appropriate
9
10
  # instruction builder (`Instructions::AssociatedTokenAccount::CreateIdempotentAssociatedTokenAccountInstruction`).
10
11
  #
@@ -57,7 +57,7 @@ module Solace
57
57
  #
58
58
  # @param params [Hash] Parameters to pass to the composer constructor
59
59
  def initialize(params)
60
- @params = params
60
+ @params = params
61
61
  @account_context = Utils::AccountContext.new
62
62
  setup_accounts
63
63
  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 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
@@ -70,10 +70,10 @@ module Solace
70
70
  # @return [Solace::Instruction]
71
71
  def build_instruction(account_context)
72
72
  Instructions::SplToken::CloseAccountInstruction.build(
73
- account_index: account_context.index_of(account),
74
- authority_index: account_context.index_of(authority),
73
+ account_index: account_context.index_of(account),
74
+ authority_index: account_context.index_of(authority),
75
75
  destination_index: account_context.index_of(destination),
76
- program_index: account_context.index_of(spl_token_program)
76
+ program_index: account_context.index_of(spl_token_program)
77
77
  )
78
78
  end
79
79
  end
@@ -83,11 +83,11 @@ module Solace
83
83
  def build_instruction(account_context)
84
84
  Instructions::SplToken::InitializeMintInstruction.build(
85
85
  mint_account_index: account_context.index_of(mint_account),
86
- rent_sysvar_index: account_context.index_of(rent_sysvar),
87
- program_index: account_context.index_of(spl_token_program),
88
- decimals: decimals,
89
- mint_authority: mint_authority,
90
- freeze_authority: freeze_authority
86
+ rent_sysvar_index: account_context.index_of(rent_sysvar),
87
+ program_index: account_context.index_of(spl_token_program),
88
+ decimals: decimals,
89
+ mint_authority: mint_authority,
90
+ freeze_authority: freeze_authority
91
91
  )
92
92
  end
93
93
  end
@@ -74,11 +74,11 @@ module Solace
74
74
  # @return [Solace::Instruction]
75
75
  def build_instruction(account_context)
76
76
  Instructions::SplToken::MintToInstruction.build(
77
- amount: amount,
78
- mint_index: account_context.index_of(mint),
79
- destination_index: account_context.index_of(destination),
77
+ amount: amount,
78
+ mint_index: account_context.index_of(mint),
79
+ destination_index: account_context.index_of(destination),
80
80
  mint_authority_index: account_context.index_of(mint_authority),
81
- program_index: account_context.index_of(spl_token_program)
81
+ program_index: account_context.index_of(spl_token_program)
82
82
  )
83
83
  end
84
84
  end
@@ -99,13 +99,13 @@ module Solace
99
99
  # @return [Solace::Instruction]
100
100
  def build_instruction(account_context)
101
101
  Instructions::SplToken::TransferCheckedInstruction.build(
102
- amount: amount,
103
- decimals: decimals,
104
- to_index: account_context.index_of(to),
105
- from_index: account_context.index_of(from),
106
- mint_index: account_context.index_of(mint),
102
+ amount: amount,
103
+ decimals: decimals,
104
+ to_index: account_context.index_of(to),
105
+ from_index: account_context.index_of(from),
106
+ mint_index: account_context.index_of(mint),
107
107
  authority_index: account_context.index_of(authority),
108
- program_index: account_context.index_of(spl_token_program)
108
+ program_index: account_context.index_of(spl_token_program)
109
109
  )
110
110
  end
111
111
  end
@@ -78,11 +78,11 @@ module Solace
78
78
  # @return [Solace::Instruction]
79
79
  def build_instruction(account_context)
80
80
  Instructions::SplToken::TransferInstruction.build(
81
- amount: amount,
82
- owner_index: account_context.index_of(owner),
83
- source_index: account_context.index_of(source),
81
+ amount: amount,
82
+ owner_index: account_context.index_of(owner),
83
+ source_index: account_context.index_of(source),
84
84
  destination_index: account_context.index_of(destination),
85
- program_index: account_context.index_of(spl_token_program)
85
+ program_index: account_context.index_of(spl_token_program)
86
86
  )
87
87
  end
88
88
  end
@@ -85,11 +85,11 @@ module Solace
85
85
  # @return [Solace::Instruction]
86
86
  def build_instruction(account_context)
87
87
  Solace::Instructions::SystemProgram::CreateAccountInstruction.build(
88
- space: space,
89
- lamports: lamports,
90
- owner: owner,
91
- from_index: account_context.index_of(from),
92
- new_account_index: account_context.index_of(new_account),
88
+ space: space,
89
+ lamports: lamports,
90
+ owner: owner,
91
+ from_index: account_context.index_of(from),
92
+ new_account_index: account_context.index_of(new_account),
93
93
  system_program_index: account_context.index_of(system_program)
94
94
  )
95
95
  end
@@ -69,9 +69,9 @@ module Solace
69
69
  # @return [Solace::Instruction]
70
70
  def build_instruction(account_context)
71
71
  Instructions::SystemProgram::TransferInstruction.build(
72
- lamports: lamports,
73
- to_index: account_context.index_of(to),
74
- from_index: account_context.index_of(from),
72
+ lamports: lamports,
73
+ to_index: account_context.index_of(to),
74
+ from_index: account_context.index_of(from),
75
75
  program_index: account_context.index_of(system_program)
76
76
  )
77
77
  end
@@ -64,10 +64,10 @@ module Solace
64
64
  # @return [Solace::Instruction]
65
65
  def build_instruction(account_context)
66
66
  Instructions::Token2022::CloseAccountInstruction.build(
67
- account_index: account_context.index_of(account),
68
- authority_index: account_context.index_of(authority),
67
+ account_index: account_context.index_of(account),
68
+ authority_index: account_context.index_of(authority),
69
69
  destination_index: account_context.index_of(destination),
70
- program_index: account_context.index_of(token_2022_program)
70
+ program_index: account_context.index_of(token_2022_program)
71
71
  )
72
72
  end
73
73
  end
@@ -81,11 +81,11 @@ module Solace
81
81
  def build_instruction(account_context)
82
82
  Instructions::Token2022::InitializeMintInstruction.build(
83
83
  mint_account_index: account_context.index_of(mint_account),
84
- rent_sysvar_index: account_context.index_of(rent_sysvar),
85
- program_index: account_context.index_of(token_2022_program),
86
- decimals: decimals,
87
- mint_authority: mint_authority,
88
- freeze_authority: freeze_authority
84
+ rent_sysvar_index: account_context.index_of(rent_sysvar),
85
+ program_index: account_context.index_of(token_2022_program),
86
+ decimals: decimals,
87
+ mint_authority: mint_authority,
88
+ freeze_authority: freeze_authority
89
89
  )
90
90
  end
91
91
  end
@@ -72,11 +72,11 @@ module Solace
72
72
  # @return [Solace::Instruction]
73
73
  def build_instruction(account_context)
74
74
  Instructions::Token2022::MintToInstruction.build(
75
- amount: amount,
76
- mint_index: account_context.index_of(mint),
77
- destination_index: account_context.index_of(destination),
75
+ amount: amount,
76
+ mint_index: account_context.index_of(mint),
77
+ destination_index: account_context.index_of(destination),
78
78
  mint_authority_index: account_context.index_of(mint_authority),
79
- program_index: account_context.index_of(token_2022_program)
79
+ program_index: account_context.index_of(token_2022_program)
80
80
  )
81
81
  end
82
82
  end
@@ -95,13 +95,13 @@ module Solace
95
95
  # @return [Solace::Instruction]
96
96
  def build_instruction(account_context)
97
97
  Instructions::Token2022::TransferCheckedInstruction.build(
98
- amount: amount,
99
- decimals: decimals,
100
- to_index: account_context.index_of(to),
101
- from_index: account_context.index_of(from),
102
- mint_index: account_context.index_of(mint),
98
+ amount: amount,
99
+ decimals: decimals,
100
+ to_index: account_context.index_of(to),
101
+ from_index: account_context.index_of(from),
102
+ mint_index: account_context.index_of(mint),
103
103
  authority_index: account_context.index_of(authority),
104
- program_index: account_context.index_of(token_2022_program)
104
+ program_index: account_context.index_of(token_2022_program)
105
105
  )
106
106
  end
107
107
  end
@@ -74,11 +74,11 @@ module Solace
74
74
  # @return [Solace::Instruction]
75
75
  def build_instruction(account_context)
76
76
  Instructions::Token2022::TransferInstruction.build(
77
- amount: amount,
78
- owner_index: account_context.index_of(owner),
79
- source_index: account_context.index_of(source),
77
+ amount: amount,
78
+ owner_index: account_context.index_of(owner),
79
+ source_index: account_context.index_of(source),
80
80
  destination_index: account_context.index_of(destination),
81
- program_index: account_context.index_of(token_2022_program)
81
+ program_index: account_context.index_of(token_2022_program)
82
82
  )
83
83
  end
84
84
  end
@@ -74,7 +74,7 @@ module Solace
74
74
  # Set default options for rpc requests
75
75
  @default_options = {
76
76
  commitment: commitment,
77
- encoding: encoding
77
+ encoding: encoding
78
78
  }
79
79
  end
80
80
 
@@ -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
@@ -266,9 +277,9 @@ module Solace
266
277
  # @return [Hash] The options for the send_transaction call
267
278
  def build_send_transaction_options(overrides)
268
279
  {
269
- skipPreflight: false,
270
- encoding: default_options[:encoding],
271
- commitment: default_options[:commitment],
280
+ skipPreflight: false,
281
+ encoding: default_options[:encoding],
282
+ commitment: default_options[:commitment],
272
283
  preflightCommitment: default_options[:commitment]
273
284
  }.merge(overrides)
274
285
  end
@@ -307,7 +318,7 @@ module Solace
307
318
  raise ArgumentError, 'Block required' unless block_given?
308
319
 
309
320
  signature = extract_signature_from(yield)
310
- deadline = monotonic_deadline(timeout)
321
+ deadline = monotonic_deadline(timeout)
311
322
 
312
323
  # Wait for confirmation
313
324
  until deadline_passed?(deadline)
@@ -26,9 +26,9 @@ module Solace
26
26
  # @param [Integer] timeout The time out reached
27
27
  def initialize(message, signature:, commitment:, timeout:)
28
28
  super(message)
29
- @signature = signature
29
+ @signature = signature
30
30
  @commitment = commitment
31
- @timeout = timeout
31
+ @timeout = timeout
32
32
  end
33
33
 
34
34
  # Formats a confirmation timeout error
@@ -40,9 +40,9 @@ module Solace
40
40
  def self.format(signature, commitment, timeout)
41
41
  new(
42
42
  "Timed out waiting for signature #{signature} at commitment=#{commitment} after #{timeout}s",
43
- signature: signature,
43
+ signature: signature,
44
44
  commitment: commitment,
45
- timeout: timeout
45
+ timeout: timeout
46
46
  )
47
47
  end
48
48
  end
@@ -28,9 +28,9 @@ module Solace
28
28
  # @param [Object] rpc_data The JSON-RPC error data
29
29
  def initialize(message, rpc_code:, rpc_message:, rpc_data: nil)
30
30
  super(message)
31
- @rpc_code = rpc_code
31
+ @rpc_code = rpc_code
32
32
  @rpc_message = rpc_message
33
- @rpc_data = rpc_data
33
+ @rpc_data = rpc_data
34
34
  end
35
35
 
36
36
  # Formats a response to an error
@@ -40,8 +40,8 @@ module Solace
40
40
  def self.format_response(response)
41
41
  new(
42
42
  "RPC error #{response['error']['code']}: #{response['error']['message']}",
43
- rpc_data: response['error']['data'],
44
- rpc_code: response['error']['code'],
43
+ rpc_data: response['error']['data'],
44
+ rpc_code: response['error']['code'],
45
45
  rpc_message: response['error']['message']
46
46
  )
47
47
  end
@@ -63,7 +63,7 @@ module Solace
63
63
  )
64
64
  Solace::Instruction.new.tap do |ix|
65
65
  ix.program_index = program_index
66
- ix.accounts = [
66
+ ix.accounts = [
67
67
  funder_index,
68
68
  associated_token_account_index,
69
69
  owner_index,
@@ -71,6 +71,7 @@ module Solace
71
71
  system_program_index,
72
72
  token_program_index
73
73
  ]
74
+
74
75
  ix.data = data
75
76
  end
76
77
  end
@@ -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
@@ -30,8 +30,8 @@ module Solace
30
30
  def self.build(account_index:, destination_index:, authority_index:, program_index:)
31
31
  Solace::Instruction.new.tap do |ix|
32
32
  ix.program_index = program_index
33
- ix.accounts = [account_index, destination_index, authority_index]
34
- ix.data = data
33
+ ix.accounts = [account_index, destination_index, authority_index]
34
+ ix.data = data
35
35
  end
36
36
  end
37
37
 
@@ -47,8 +47,8 @@ module Solace
47
47
  )
48
48
  Solace::Instruction.new.tap do |ix|
49
49
  ix.program_index = program_index
50
- ix.accounts = [account_index, mint_index, owner_index, rent_sysvar_index]
51
- ix.data = data
50
+ ix.accounts = [account_index, mint_index, owner_index, rent_sysvar_index]
51
+ ix.data = data
52
52
  end
53
53
  end
54
54
 
@@ -49,8 +49,8 @@ module Solace
49
49
  )
50
50
  Solace::Instruction.new.tap do |ix|
51
51
  ix.program_index = program_index
52
- ix.accounts = [mint_account_index, rent_sysvar_index]
53
- ix.data = data(decimals, mint_authority, freeze_authority)
52
+ ix.accounts = [mint_account_index, rent_sysvar_index]
53
+ ix.data = data(decimals, mint_authority, freeze_authority)
54
54
  end
55
55
  end
56
56