solace 0.1.2 → 0.1.4

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: 21862a029b8b0922fa42fd3798e86d11c69900255bb92a035c806d83a8c985c1
4
- data.tar.gz: 10eb8a0433c9907b7e75a7a3bb71637f1e41f0012e7cb695afcb91f2115d3f3f
3
+ metadata.gz: 18aca49d63b09deffe93ba871b65d6b816a7c81863b0b0e2b2c2bd29ce709ce6
4
+ data.tar.gz: 810a45b1324aa282684e4a5d62ea48738ac2b33a6eb87538e2e0458ca2f54593
5
5
  SHA512:
6
- metadata.gz: 813efcb0fae947ac7a93bb88d6984ca4b4369390b807d08eb11e9ff7d49b7742c53de1e2a9d0ffd6c2fd98b07dcd3cd8161e477ec91e9b0b5574ebdb54dd5ebc
7
- data.tar.gz: a7a077c4af7e7379364bec45ef965eafcab28c58cca0588f9f2c0854a99bb5e4f5bf7a4262e4f5c64d57bd02f311c03bb98146b500e0d6a6621a528fe297a782
6
+ metadata.gz: 50eeac609077e873b361fdb8ed34459ccbed1b4e44d52ad911803350ea0d2f0e669fcfcb30bcddd6d20e9f54dade972a50907532a108dae7142ecca8475f42fb
7
+ data.tar.gz: 5fba491757746aa8fad865bae93941f3469148c6a5fc8cb5c984ebccb79934f1b1c3425184ab37ff2342f6215a1d5b1147a9d04f6d9225a96e7c6b34c38d8b0d
data/CHANGELOG CHANGED
@@ -18,7 +18,18 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
18
18
  ### Fixed
19
19
  ```
20
20
 
21
- Got it — here’s your changelog tidied up for clarity and consistency without changing any of the substance. I only fixed grammar/typos and tightened phrasing.
21
+ ---
22
+
23
+ ## 0.1.3 - 2025-06-11
24
+
25
+ ### Added
26
+
27
+ 1. Added `Solace::Instructions::AssociatedTokenAccount::CreateIdempotentAccountInstruction`
28
+ 2. Added `Solace::Composers::AssociatedTokenAccountCreateIdempotentAccountComposer`
29
+
30
+ ### Changed
31
+
32
+ 1. Renamed `Solace::Instructions::AssociatedTokenAccount::CreateAssociatedTokenAccountInstruction` to `Solace::Instructions::AssociatedTokenAccount::CreateAccountInstruction` with backwards compatibility
22
33
 
23
34
  ---
24
35
 
@@ -6,7 +6,7 @@ module Solace
6
6
  #
7
7
  # This composer resolves and orders the required accounts for a `CreateAssociatedTokenAccount` instruction,
8
8
  # sets up their access permissions, and delegates construction to the appropriate
9
- # instruction builder (`Instructions::AssociatedTokenAccount::CreateAssociatedTokenAccountInstruction`).
9
+ # instruction builder (`Instructions::AssociatedTokenAccount::CreateAccountInstruction`).
10
10
  #
11
11
  # Required accounts:
12
12
  # - **Funder**: the account that will pay for fees and rent.
@@ -25,7 +25,7 @@ module Solace
25
25
  # mint: mint_address
26
26
  # )
27
27
  #
28
- # @see Instructions::AssociatedTokenAccount::CreateAssociatedTokenAccountInstruction
28
+ # @see Instructions::AssociatedTokenAccount::CreateAccountInstruction
29
29
  # @since 0.0.7
30
30
  class AssociatedTokenAccountProgramCreateAccountComposer < Base
31
31
  # Extracts the owner address from the params
@@ -96,7 +96,7 @@ module Solace
96
96
  # @param account_context [Utils::AccountContext] The account context
97
97
  # @return [Solace::Instruction] The instruction
98
98
  def build_instruction(account_context)
99
- Instructions::AssociatedTokenAccount::CreateAssociatedTokenAccountInstruction.build(
99
+ Instructions::AssociatedTokenAccount::CreateAccountInstruction.build(
100
100
  funder_index: account_context.index_of(funder),
101
101
  owner_index: account_context.index_of(owner),
102
102
  mint_index: account_context.index_of(mint),
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solace
4
+ module Composers
5
+ # Composer for creating an associated token account program create account instruction with idempotency
6
+ #
7
+ # This composer resolves and orders the required accounts for a `CreateIdempotentAssociatedTokenAccount` instruction,
8
+ # sets up their access permissions, and delegates construction to the appropriate
9
+ # instruction builder (`Instructions::AssociatedTokenAccount::CreateIdempotentAssociatedTokenAccountInstruction`).
10
+ #
11
+ # Required accounts:
12
+ # - **Funder**: the account that will pay for fees and rent.
13
+ # - **Owner**: the account that will own the new ATA.
14
+ # - **ATA**: the address of the new ATA.
15
+ # - **Mint**: the mint address of the token.
16
+ # - **System Program**: the system program id.
17
+ # - **Token Program**: the token program id.
18
+ # - **Associated Token Account Program**: the associated token account program id.
19
+ #
20
+ # @example Compose and build a create account instruction
21
+ # composer = AssociatedTokenAccountProgramCreateAccountComposer.new(
22
+ # funder: funder_address,
23
+ # owner: owner_address,
24
+ # ata_address: ata_address,
25
+ # mint: mint_address
26
+ # )
27
+ #
28
+ # @see Instructions::AssociatedTokenAccount::CreateAccountInstruction
29
+ # @since 0.1.3
30
+ #
31
+ # rubocop:disable Layout
32
+ class AssociatedTokenAccountProgramCreateIdempotentAccountComposer < AssociatedTokenAccountProgramCreateAccountComposer
33
+ # Builds the instruction for the associated token account program create account instruction
34
+ #
35
+ # @param account_context [Utils::AccountContext] The account context
36
+ # @return [Solace::Instruction] The instruction
37
+ def build_instruction(account_context)
38
+ Instructions::AssociatedTokenAccount::CreateIdempotentAccountInstruction.build(
39
+ funder_index: account_context.index_of(funder),
40
+ owner_index: account_context.index_of(owner),
41
+ mint_index: account_context.index_of(mint),
42
+ associated_token_account_index: account_context.index_of(ata_address),
43
+ system_program_index: account_context.index_of(system_program_id),
44
+ token_program_index: account_context.index_of(token_program_id),
45
+ program_index: account_context.index_of(associated_token_account_program_id)
46
+ )
47
+ end
48
+ end
49
+ # rubocop:enable Layout
50
+ end
51
+ end
@@ -17,7 +17,7 @@ module Solace
17
17
  # end
18
18
  #
19
19
  # @since 0.0.1
20
- class ConfirmationTimeout < StandardError
20
+ class ConfirmationTimeout < Error
21
21
  attr_reader :signature, :commitment, :timeout
22
22
 
23
23
  # @param [String] message The error message
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solace
4
+ module Errors
5
+ # Base error class for connection-related failures.
6
+ #
7
+ # Both {Solace::Errors::HTTPError} and {Solace::Errors::RPCError} inherit
8
+ # from this class, allowing consumers to rescue all connection errors with
9
+ # a single clause:
10
+ #
11
+ # @example Rescuing all connection errors
12
+ # begin
13
+ # connection.send_transaction(transaction)
14
+ # rescue Solace::Errors::ConnectionError => e
15
+ # puts "Connection error: #{e.message}"
16
+ # end
17
+ #
18
+ # @see Solace::Errors::HTTPError
19
+ # @see Solace::Errors::RPCError
20
+ # @since 0.1.4
21
+ class ConnectionError < Error; end
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solace
4
+ module Errors
5
+ # Base error class for all Solace errors.
6
+ #
7
+ # All Solace-specific exceptions inherit from this class, allowing consumers
8
+ # to rescue all Solace errors with a single clause:
9
+ #
10
+ # @example Rescuing all Solace errors
11
+ # begin
12
+ # connection.get_account_info(address)
13
+ # rescue Solace::Errors::Error => e
14
+ # puts "Solace error: #{e.message}"
15
+ # end
16
+ #
17
+ # @since 0.1.4
18
+ class Error < StandardError; end
19
+ end
20
+ end
@@ -18,7 +18,7 @@ module Solace
18
18
  #
19
19
  # @see Solace::Errors::RPCError
20
20
  # @since 0.0.1
21
- class HTTPError < StandardError
21
+ class HTTPError < ConnectionError
22
22
  attr_reader :code, :body
23
23
 
24
24
  # @param [String] message The error message
@@ -17,7 +17,7 @@ module Solace
17
17
  # end
18
18
  #
19
19
  # @since 0.0.1
20
- class ParseError < StandardError
20
+ class ParseError < Error
21
21
  attr_reader :body
22
22
 
23
23
  # @param [String] message The error message
@@ -19,7 +19,7 @@ module Solace
19
19
  #
20
20
  # @see Solace::Errors::HTTPError
21
21
  # @since 0.0.1
22
- class RPCError < StandardError
22
+ class RPCError < ConnectionError
23
23
  attr_reader :rpc_code, :rpc_message, :rpc_data
24
24
 
25
25
  # @param [String] message The error message
data/lib/solace/errors.rb CHANGED
@@ -5,6 +5,8 @@ module Solace
5
5
  #
6
6
  # These exceptions provide specific error handling for various failure scenarios
7
7
  # when interacting with the Solana blockchain, including:
8
+ # - {Solace::Errors::Error} - Base class for all Solace errors
9
+ # - {Solace::Errors::ConnectionError} - Base class for connection-related errors
8
10
  # - {Solace::Errors::HTTPError} - HTTP communication failures
9
11
  # - {Solace::Errors::RPCError} - RPC method errors returned by the node
10
12
  # - {Solace::Errors::ParseError} - Data parsing and deserialization errors
@@ -13,7 +15,8 @@ module Solace
13
15
  # @see Solace::Connection
14
16
  # @since 0.0.8
15
17
  module Errors
16
- # JSON-RPC Errors
18
+ require 'solace/errors/error'
19
+ require 'solace/errors/connection_error'
17
20
  require 'solace/errors/rpc_error'
18
21
  require 'solace/errors/http_error'
19
22
  require 'solace/errors/parse_error'
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Solace
4
4
  module Instructions
5
- # The AssociatedTokenAccount module contains instruction builders for the
5
+ # The Account module contains instruction builders for the
6
6
  # Associated Token Account Program.
7
7
  #
8
8
  # The Associated Token Account (ATA) Program provides a deterministic way to
@@ -17,8 +17,8 @@ module Solace
17
17
  # This is a special "all-in-one" instruction that creates and initializes the account. It
18
18
  # is used to create an Associated Token Account (ATA) for a given mint and owner.
19
19
  #
20
- # @example Build a CreateAssociatedTokenAccount instruction
21
- # instruction = Solace::Instructions::AssociatedTokenAccount::CreateAssociatedTokenAccountInstruction.build(
20
+ # @example Build a CreateAccount instruction
21
+ # instruction = Solace::Instructions::AssociatedTokenAccount::CreateAccountInstruction.build(
22
22
  # funder_index: 0,
23
23
  # associated_token_account_index: 1,
24
24
  # owner_index: 2,
@@ -27,14 +27,14 @@ module Solace
27
27
  # token_program_index: 5,
28
28
  # program_index: 6
29
29
  # )
30
- class CreateAssociatedTokenAccountInstruction
30
+ class CreateAccountInstruction
31
31
  # !@const INSTRUCTION_INDEX
32
- # Instruction index for CreateAssociatedTokenAccount
32
+ # Instruction index for CreateAccount
33
33
  #
34
34
  # @return [Array<Integer>]
35
35
  INSTRUCTION_INDEX = [0].freeze
36
36
 
37
- # Builds a CreateAssociatedTokenAccount instruction.
37
+ # Builds a CreateAccount instruction.
38
38
  #
39
39
  # The on-chain program requires accounts in a specific order:
40
40
  # 1. [writable, signer] Funder: The account paying for the rent.
@@ -75,7 +75,7 @@ module Solace
75
75
  end
76
76
  end
77
77
 
78
- # Data for a CreateAssociatedTokenAccount instruction
78
+ # Data for a CreateAccount instruction
79
79
  #
80
80
  # The BufferLayout is:
81
81
  # - [Instruction Index (1 byte)]
@@ -85,6 +85,9 @@ module Solace
85
85
  INSTRUCTION_INDEX
86
86
  end
87
87
  end
88
+
89
+ # Alias for CreateAccountInstruction for backward compatibility
90
+ CreateAssociatedTokenAccountInstruction = CreateAccountInstruction
88
91
  end
89
92
  end
90
93
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solace
4
+ module Instructions
5
+ # The AssociatedTokenAccount module contains instruction builders for the
6
+ # Associated Token Account Program.
7
+ #
8
+ # The Associated Token Account (ATA) Program provides a deterministic way to
9
+ # derive token account addresses for a given wallet and mint. This ensures that
10
+ # each wallet has a single, predictable token account for each token type.
11
+ #
12
+ # @see https://spl.solana.com/associated-token-account
13
+ # @since 0.1.3
14
+ module AssociatedTokenAccount
15
+ # Instruction for creating an Associated Token Account idempotently.
16
+ #
17
+ # This instruction behaves like `CreateAccountInstruction`, but will not fail
18
+ # if the account already exists. This is useful for scenarios where the existence of the
19
+ # account is uncertain, and you want to ensure it exists without causing an error.
20
+ #
21
+ # @example Build a CreateIdempotentAccount instruction
22
+ # instruction = Solace::Instructions::AssociatedTokenAccount::CreateIdempotentAccountInstruction.build(
23
+ # funder_index: 0,
24
+ # associated_token_account_index: 1,
25
+ # owner_index: 2,
26
+ # mint_index: 3,
27
+ # system_program_index: 4,
28
+ # token_program_index: 5,
29
+ # program_index: 6
30
+ # )
31
+ #
32
+ # @see CreateAccountInstruction
33
+ class CreateIdempotentAccountInstruction < CreateAccountInstruction
34
+ # !@const INSTRUCTION_INDEX
35
+ # Instruction index for CreateIdempotentAccount
36
+ #
37
+ # @return [Array<Integer>]
38
+ INSTRUCTION_INDEX = [1].freeze
39
+
40
+ # Data for a CreateAccount instruction
41
+ #
42
+ # The BufferLayout is:
43
+ # - [Instruction Index (1 byte)]
44
+ #
45
+ # @return [Array] 1-byte instruction index
46
+ def self.data
47
+ INSTRUCTION_INDEX
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -9,7 +9,7 @@ module Solace
9
9
  #
10
10
  # This instruction is used to initialize a new token account for a given mint and owner. It
11
11
  # is used in conjunction with the CreateAccount instruction to create and initialize a new
12
- # token account. Note that the AssociatedTokenAccount::CreateAssociatedTokenAccountInstruction
12
+ # token account. Note that the AssociatedTokenAccount::CreateAccountInstruction
13
13
  # is a special "all-in-one" instruction that creates and initializes the account in a single
14
14
  # instruction.
15
15
  #
@@ -22,7 +22,7 @@ module Solace
22
22
  # program_index: 4
23
23
  # )
24
24
  #
25
- # @see Solace::Instructions::AssociatedTokenAccount::CreateAssociatedTokenAccountInstruction
25
+ # @see Solace::Instructions::AssociatedTokenAccount::CreateAccountInstruction
26
26
  # @see Solace::Instructions::SystemProgram::CreateAccountInstruction
27
27
  # @since 0.0.2
28
28
  class InitializeAccountInstruction
@@ -24,8 +24,18 @@ module Solace
24
24
  # @return [String] The path to the native library
25
25
  # @raise [RuntimeError] If the platform is not supported
26
26
  libfile = case RUBY_PLATFORM
27
- when /linux/ then 'libcurve25519_dalek-linux/libcurve25519_dalek.so'
28
- when /darwin/ then 'libcurve25519_dalek-macos/libcurve25519_dalek.dylib'
27
+ when /linux/
28
+ if RUBY_PLATFORM =~ /arm|aarch64/
29
+ 'libcurve25519_dalek-linux-arm64/libcurve25519_dalek.so'
30
+ else
31
+ 'libcurve25519_dalek-linux/libcurve25519_dalek.so'
32
+ end
33
+ when /darwin/
34
+ if RUBY_PLATFORM =~ /arm64|aarch64/
35
+ 'libcurve25519_dalek-macos-arm64/libcurve25519_dalek.dylib'
36
+ else
37
+ 'libcurve25519_dalek-macos/libcurve25519_dalek.dylib'
38
+ end
29
39
  when /mingw|mswin/ then 'libcurve25519_dalek-windows/curve25519_dalek.dll'
30
40
  else raise 'Unsupported platform'
31
41
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Solace
4
4
  # Latest version of the Solace gem.
5
- VERSION = '0.1.2'
5
+ VERSION = '0.1.4'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Scholl
@@ -108,6 +108,7 @@ files:
108
108
  - lib/solace.rb
109
109
  - lib/solace/address_lookup_table.rb
110
110
  - lib/solace/composers/associated_token_account_program_create_account_composer.rb
111
+ - lib/solace/composers/associated_token_account_program_create_idempotent_account_composer.rb
111
112
  - lib/solace/composers/base.rb
112
113
  - lib/solace/composers/spl_token_program_close_account_composer.rb
113
114
  - lib/solace/composers/spl_token_program_initialize_mint_composer.rb
@@ -121,11 +122,14 @@ files:
121
122
  - lib/solace/constants.rb
122
123
  - lib/solace/errors.rb
123
124
  - lib/solace/errors/confirmation_timeout.rb
125
+ - lib/solace/errors/connection_error.rb
126
+ - lib/solace/errors/error.rb
124
127
  - lib/solace/errors/http_error.rb
125
128
  - lib/solace/errors/parse_error.rb
126
129
  - lib/solace/errors/rpc_error.rb
127
130
  - lib/solace/instruction.rb
128
- - lib/solace/instructions/associated_token_account/create_associated_token_account_instruction.rb
131
+ - lib/solace/instructions/associated_token_account/create_account_instruction.rb
132
+ - lib/solace/instructions/associated_token_account/create_idempotent_account_instruction.rb
129
133
  - lib/solace/instructions/spl_token/close_account_instruction.rb
130
134
  - lib/solace/instructions/spl_token/initialize_account_instruction.rb
131
135
  - lib/solace/instructions/spl_token/initialize_mint_instruction.rb
@@ -157,7 +161,9 @@ files:
157
161
  - lib/solace/utils/account_context.rb
158
162
  - lib/solace/utils/codecs.rb
159
163
  - lib/solace/utils/curve25519_dalek.rb
164
+ - lib/solace/utils/libcurve25519_dalek-linux-arm64/libcurve25519_dalek.so
160
165
  - lib/solace/utils/libcurve25519_dalek-linux/libcurve25519_dalek.so
166
+ - lib/solace/utils/libcurve25519_dalek-macos-arm64/libcurve25519_dalek.dylib
161
167
  - lib/solace/utils/libcurve25519_dalek-macos/libcurve25519_dalek.dylib
162
168
  - lib/solace/utils/libcurve25519_dalek-windows/curve25519_dalek.dll
163
169
  - lib/solace/utils/pda.rb
@@ -190,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
196
  - !ruby/object:Gem::Version
191
197
  version: '0'
192
198
  requirements: []
193
- rubygems_version: 3.6.7
199
+ rubygems_version: 4.0.6
194
200
  specification_version: 4
195
201
  summary: Solana ruby library
196
202
  test_files: []