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
@@ -39,8 +39,8 @@ module Solace
39
39
  )
40
40
  Solace::Instruction.new.tap do |ix|
41
41
  ix.program_index = program_index
42
- ix.accounts = [mint_index, destination_index, mint_authority_index]
43
- ix.data = data(amount)
42
+ ix.accounts = [mint_index, destination_index, mint_authority_index]
43
+ ix.data = data(amount)
44
44
  end
45
45
  end
46
46
 
@@ -50,8 +50,8 @@ module Solace
50
50
  )
51
51
  Solace::Instruction.new.tap do |ix|
52
52
  ix.program_index = program_index
53
- ix.accounts = [from_index, mint_index, to_index, authority_index]
54
- ix.data = data(amount, decimals)
53
+ ix.accounts = [from_index, mint_index, to_index, authority_index]
54
+ ix.data = data(amount, decimals)
55
55
  end
56
56
  end
57
57
 
@@ -60,8 +60,8 @@ module Solace
60
60
  )
61
61
  Solace::Instruction.new.tap do |ix|
62
62
  ix.program_index = program_index
63
- ix.accounts = [source_index, destination_index, owner_index]
64
- ix.data = data(amount)
63
+ ix.accounts = [source_index, destination_index, owner_index]
64
+ ix.data = data(amount)
65
65
  end
66
66
  end
67
67
 
@@ -73,8 +73,8 @@ module Solace
73
73
  )
74
74
  Solace::Instruction.new.tap do |ix|
75
75
  ix.program_index = system_program_index
76
- ix.accounts = [from_index, new_account_index]
77
- ix.data = data(lamports, space, owner)
76
+ ix.accounts = [from_index, new_account_index]
77
+ ix.data = data(lamports, space, owner)
78
78
  end
79
79
  end
80
80
  # rubocop:enable Metrics/ParameterLists
@@ -46,8 +46,8 @@ module Solace
46
46
  )
47
47
  Instruction.new.tap do |ix|
48
48
  ix.program_index = program_index
49
- ix.accounts = [from_index, to_index]
50
- ix.data = data(lamports)
49
+ ix.accounts = [from_index, to_index]
50
+ ix.data = data(lamports)
51
51
  end
52
52
  end
53
53
 
@@ -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
 
@@ -42,8 +42,8 @@ module Solace
42
42
  )
43
43
  Solace::Instruction.new.tap do |ix|
44
44
  ix.program_index = program_index
45
- ix.accounts = [account_index, mint_index, owner_index, rent_sysvar_index]
46
- ix.data = data
45
+ ix.accounts = [account_index, mint_index, owner_index, rent_sysvar_index]
46
+ ix.data = data
47
47
  end
48
48
  end
49
49
 
@@ -46,8 +46,8 @@ module Solace
46
46
  )
47
47
  Solace::Instruction.new.tap do |ix|
48
48
  ix.program_index = program_index
49
- ix.accounts = [mint_account_index, rent_sysvar_index]
50
- ix.data = data(decimals, mint_authority, freeze_authority)
49
+ ix.accounts = [mint_account_index, rent_sysvar_index]
50
+ ix.data = data(decimals, mint_authority, freeze_authority)
51
51
  end
52
52
  end
53
53
 
@@ -37,8 +37,8 @@ module Solace
37
37
  )
38
38
  Solace::Instruction.new.tap do |ix|
39
39
  ix.program_index = program_index
40
- ix.accounts = [mint_index, destination_index, mint_authority_index]
41
- ix.data = data(amount)
40
+ ix.accounts = [mint_index, destination_index, mint_authority_index]
41
+ ix.data = data(amount)
42
42
  end
43
43
  end
44
44
 
@@ -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 = [from_index, mint_index, to_index, authority_index]
51
- ix.data = data(amount, decimals)
50
+ ix.accounts = [from_index, mint_index, to_index, authority_index]
51
+ ix.data = data(amount, decimals)
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 = [source_index, destination_index, owner_index]
53
- ix.data = data(amount)
52
+ ix.accounts = [source_index, destination_index, owner_index]
53
+ ix.data = data(amount)
54
54
  end
55
55
  end
56
56
 
@@ -68,11 +68,11 @@ module Solace
68
68
  )
69
69
  super()
70
70
 
71
- @version = version
72
- @header = header
73
- @accounts = accounts
74
- @recent_blockhash = recent_blockhash
75
- @instructions = instructions
71
+ @version = version
72
+ @header = header
73
+ @accounts = accounts
74
+ @recent_blockhash = recent_blockhash
75
+ @instructions = instructions
76
76
  @address_lookup_tables = address_lookup_tables
77
77
  end
78
78
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # The AssociatedTokenAccount program is a Solana program that provides a standardized way to create and manage token accounts.
3
+ # The AssociatedTokenAccount program is a Solana program that provides a standardized
4
+ # way to create and manage token accounts.
4
5
  #
5
6
  # This class provides a Ruby interface to the Associated Token Account program, allowing you to easily
6
7
  # find or create associated token accounts for a given wallet and mint.
@@ -100,10 +101,10 @@ module Solace
100
101
  return ata_address unless account_balance.nil?
101
102
 
102
103
  tx = create_associated_token_account(
103
- payer: payer,
104
- funder: funder,
105
- owner: owner,
106
- mint: mint,
104
+ payer: payer,
105
+ funder: funder,
106
+ owner: owner,
107
+ mint: mint,
107
108
  token_program_id: token_program_id
108
109
  )
109
110
 
@@ -161,10 +162,10 @@ module Solace
161
162
  ata_address, = get_address(owner: owner, mint: mint, token_program_id: token_program_id)
162
163
 
163
164
  ix = Solace::Composers::AssociatedTokenAccountProgramCreateAccountComposer.new(
164
- mint: mint,
165
- owner: owner,
166
- funder: funder,
167
- ata_address: ata_address,
165
+ mint: mint,
166
+ owner: owner,
167
+ funder: funder,
168
+ ata_address: ata_address,
168
169
  token_program_id: token_program_id
169
170
  )
170
171
 
@@ -84,18 +84,18 @@ module Solace
84
84
 
85
85
  # Build the account for the mint
86
86
  create_account_ix = Composers::SystemProgramCreateAccountComposer.new(
87
- from: funder,
87
+ from: funder,
88
88
  new_account: mint_account,
89
- owner: program_id,
90
- lamports: rent_lamports,
91
- space: 82
89
+ owner: program_id,
90
+ lamports: rent_lamports,
91
+ space: 82
92
92
  )
93
93
 
94
94
  # Build the initialize mint composer (per-program class supplied by includer)
95
95
  initialize_mint_ix = initialize_mint_composer_class.new(
96
- decimals: decimals,
97
- mint_account: mint_account,
98
- mint_authority: mint_authority,
96
+ decimals: decimals,
97
+ mint_account: mint_account,
98
+ mint_authority: mint_authority,
99
99
  freeze_authority: freeze_authority
100
100
  )
101
101
 
@@ -153,9 +153,9 @@ module Solace
153
153
  mint_authority:
154
154
  )
155
155
  ix = mint_to_composer_class.new(
156
- amount: amount,
157
- mint: mint,
158
- destination: destination,
156
+ amount: amount,
157
+ mint: mint,
158
+ destination: destination,
159
159
  mint_authority: mint_authority
160
160
  )
161
161
 
@@ -210,9 +210,9 @@ module Solace
210
210
  owner:
211
211
  )
212
212
  ix = transfer_composer_class.new(
213
- amount: amount,
214
- owner: owner,
215
- source: source,
213
+ amount: amount,
214
+ owner: owner,
215
+ source: source,
216
216
  destination: destination
217
217
  )
218
218
 
@@ -272,12 +272,12 @@ module Solace
272
272
  decimals:
273
273
  )
274
274
  ix = transfer_checked_composer_class.new(
275
- to: to,
276
- from: from,
277
- mint: mint,
275
+ to: to,
276
+ from: from,
277
+ mint: mint,
278
278
  authority: authority,
279
- amount: amount,
280
- decimals: decimals
279
+ amount: amount,
280
+ decimals: decimals
281
281
  )
282
282
 
283
283
  TransactionComposer
@@ -40,7 +40,7 @@ module Solace
40
40
  #
41
41
  # @return [Array<Integer>] The writable indexes
42
42
  def next_extract_writable_indexes
43
- length, = Codecs.decode_compact_u16(io)
43
+ length, = Codecs.decode_compact_u16(io)
44
44
  record.writable_indexes = io.read(length).unpack('C*')
45
45
  end
46
46
 
@@ -52,7 +52,7 @@ module Solace
52
52
  #
53
53
  # @return [Array<Integer>] The readonly indexes
54
54
  def next_extract_readonly_indexes
55
- length, = Codecs.decode_compact_u16(io)
55
+ length, = Codecs.decode_compact_u16(io)
56
56
  record.readonly_indexes = io.read(length).unpack('C*')
57
57
  end
58
58
  end
@@ -36,7 +36,7 @@ module Solace
36
36
  # @return [BaseDeserializer] The new deserializer object
37
37
  def initialize(io)
38
38
  super()
39
- @io = io
39
+ @io = io
40
40
  @record = self.class.record_class.new
41
41
  end
42
42
 
@@ -40,7 +40,7 @@ module Solace
40
40
  #
41
41
  # @return [Array] The accounts
42
42
  def next_extract_accounts
43
- length, = Codecs.decode_compact_u16(io)
43
+ length, = Codecs.decode_compact_u16(io)
44
44
  record.accounts = io.read(length).unpack('C*')
45
45
  end
46
46
 
@@ -52,7 +52,7 @@ module Solace
52
52
  #
53
53
  # @return [Array] The instruction data
54
54
  def next_extract_data
55
- length, = Codecs.decode_compact_u16(io)
55
+ length, = Codecs.decode_compact_u16(io)
56
56
  record.data = io.read(length).unpack('C*')
57
57
  end
58
58
  end
@@ -64,7 +64,7 @@ module Solace
64
64
  #
65
65
  # @return [Array<String>] The account keys of the message
66
66
  def next_extract_accounts
67
- count, = Codecs.decode_compact_u16(io)
67
+ count, = Codecs.decode_compact_u16(io)
68
68
  record.accounts = count.times.map do
69
69
  Codecs.bytes_to_base58 io.read(32).bytes
70
70
  end
@@ -88,7 +88,7 @@ module Solace
88
88
  #
89
89
  # @return [Array<Solace::Instruction>] The instructions of the message
90
90
  def next_extract_instructions
91
- count, = Codecs.decode_compact_u16(io)
91
+ count, = Codecs.decode_compact_u16(io)
92
92
  record.instructions = count.times.map do
93
93
  Solace::Instruction.deserialize(io)
94
94
  end
@@ -104,7 +104,7 @@ module Solace
104
104
  def next_extract_address_lookup_table
105
105
  return unless record.versioned?
106
106
 
107
- count, = Codecs.decode_compact_u16(io)
107
+ count, = Codecs.decode_compact_u16(io)
108
108
  record.address_lookup_tables = count.times.map do
109
109
  Solace::AddressLookupTable.deserialize(io)
110
110
  end
@@ -29,7 +29,7 @@ module Solace
29
29
  #
30
30
  # @return [Array] Array of base58 encoded signatures
31
31
  def next_extract_signatures
32
- count, = Codecs.decode_compact_u16(io)
32
+ count, = Codecs.decode_compact_u16(io)
33
33
  record.signatures = count.times.map { io.read(64) }
34
34
  end
35
35
 
@@ -18,7 +18,7 @@ module Solace
18
18
  # @param metadata [Hash] A hash containing the token's metadata attributes
19
19
  # @return [self] The initialized Token object
20
20
  def initialize(symbol, metadata)
21
- @symbol = symbol
21
+ @symbol = symbol
22
22
  @metadata = metadata.transform_keys(&:to_sym)
23
23
  end
24
24
 
data/lib/solace/tokens.rb CHANGED
@@ -29,7 +29,7 @@ module Solace
29
29
  # @param network [String, Symbol] Network name (e.g., 'mainnet', 'testnet')
30
30
  # @return [void]
31
31
  def self.load(path:, network:)
32
- data = YAML.load_file(path)
32
+ data = YAML.load_file(path)
33
33
  tokens = data.fetch(network.to_s) do
34
34
  raise ArgumentError, "Network '#{network}' not found in config"
35
35
  end
@@ -40,7 +40,7 @@ module Solace
40
40
  @registry = {}
41
41
 
42
42
  tokens.each do |symbol, attrs|
43
- token = Solace::Tokens::Token.new(symbol, attrs)
43
+ token = Solace::Tokens::Token.new(symbol, attrs)
44
44
  const_set(symbol, token)
45
45
  @registry[symbol.to_s] = token
46
46
  end
@@ -66,7 +66,7 @@ module Solace
66
66
  )
67
67
  super()
68
68
  @signatures = signatures
69
- @message = message
69
+ @message = message
70
70
  end
71
71
 
72
72
  # Returns the first signature of the transaction (signature of the transaction fee payer)
@@ -77,9 +77,9 @@ module Solace
77
77
  #
78
78
  # @param connection [Solace::Connection] The connection to the Solana cluster
79
79
  def initialize(connection:)
80
- @connection = connection
80
+ @connection = connection
81
81
  @instruction_composers = []
82
- @context = Utils::AccountContext.new
82
+ @context = Utils::AccountContext.new
83
83
  end
84
84
 
85
85
  # Add an instruction composer to the transaction
@@ -161,9 +161,9 @@ module Solace
161
161
  context.compile
162
162
 
163
163
  message = Solace::Message.new(
164
- header: context.header,
165
- accounts: context.accounts,
166
- instructions: build_instructions,
164
+ header: context.header,
165
+ accounts: context.accounts,
166
+ instructions: build_instructions,
167
167
  recent_blockhash: connection.get_latest_blockhash[0]
168
168
  )
169
169
 
@@ -35,8 +35,8 @@ module Solace
35
35
  #
36
36
  # @return [Hash] The default account data with lowest level of permissions
37
37
  DEFAULT_ACCOUNT = {
38
- signer: false,
39
- writable: false,
38
+ signer: false,
39
+ writable: false,
40
40
  fee_payer: false
41
41
  }.freeze
42
42
 
@@ -60,8 +60,8 @@ module Solace
60
60
 
61
61
  # Initialize the account context
62
62
  def initialize
63
- @header = []
64
- @accounts = []
63
+ @header = []
64
+ @accounts = []
65
65
  @pubkey_account_map = {}
66
66
  end
67
67
 
@@ -175,7 +175,7 @@ module Solace
175
175
  #
176
176
  # @return [Hash] The compiled accounts and header
177
177
  def compile
178
- self.header = calculate_header
178
+ self.header = calculate_header
179
179
  self.accounts = order_accounts
180
180
  self
181
181
  end
@@ -206,9 +206,9 @@ module Solace
206
206
  def merge_account(pubkey, signer:, writable:, fee_payer: false)
207
207
  pubkey_str = pubkey.is_a?(String) ? pubkey : pubkey.address
208
208
 
209
- @pubkey_account_map[pubkey_str] ||= DEFAULT_ACCOUNT.dup
210
- @pubkey_account_map[pubkey_str][:signer] ||= signer
211
- @pubkey_account_map[pubkey_str][:writable] ||= writable
209
+ @pubkey_account_map[pubkey_str] ||= DEFAULT_ACCOUNT.dup
210
+ @pubkey_account_map[pubkey_str][:signer] ||= signer
211
+ @pubkey_account_map[pubkey_str][:writable] ||= writable
212
212
  @pubkey_account_map[pubkey_str][:fee_payer] ||= fee_payer
213
213
 
214
214
  self
@@ -242,7 +242,7 @@ module Solace
242
242
  @pubkey_account_map.keys.each_with_object([0, 0, 0]) do |pubkey, acc|
243
243
  acc[0] += 1 if signer?(pubkey)
244
244
 
245
- if readonly_signer?(pubkey) then acc[1] += 1
245
+ if readonly_signer?(pubkey) then acc[1] += 1
246
246
  elsif readonly_nonsigner?(pubkey) then acc[2] += 1
247
247
  end
248
248
  end