solace 0.1.0 → 0.1.2

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: 844d1bceeb32ec4fb6758548f24c8a0b04b5ef534cd2d387b6146a7923ee2ca0
4
- data.tar.gz: 4ea095f315b2feac568e5bf4361986b19fe951085050a13250f9e6e84065c51f
3
+ metadata.gz: 21862a029b8b0922fa42fd3798e86d11c69900255bb92a035c806d83a8c985c1
4
+ data.tar.gz: 10eb8a0433c9907b7e75a7a3bb71637f1e41f0012e7cb695afcb91f2115d3f3f
5
5
  SHA512:
6
- metadata.gz: 166e17cb2a4fea1dac6e3497d064402bdce4477797d22f57f7812ee1faacf7ea9c77d94bbfa9172a4f1b92ceaacba2fef007ee0018d3ba4360ac568eefb3c3e8
7
- data.tar.gz: cdf77b2bf7a7b813aefc1f80f6405a371ff82aad3448097b6030eb74028a770aac282697f128746dd001668171032524aa80906091cebfd871eea98335c1710d
6
+ metadata.gz: 813efcb0fae947ac7a93bb88d6984ca4b4369390b807d08eb11e9ff7d49b7742c53de1e2a9d0ffd6c2fd98b07dcd3cd8161e477ec91e9b0b5574ebdb54dd5ebc
7
+ data.tar.gz: a7a077c4af7e7379364bec45ef965eafcab28c58cca0588f9f2c0854a99bb5e4f5bf7a4262e4f5c64d57bd02f311c03bb98146b500e0d6a6621a528fe297a782
data/CHANGELOG CHANGED
@@ -1,4 +1,5 @@
1
1
  # Change Log
2
+
2
3
  All notable changes to this project will be documented in this file.
3
4
 
4
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
@@ -9,6 +10,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
9
10
  ## [VERSION] - yyyy-mm-dd
10
11
 
11
12
  ### Added
13
+
12
14
  1.
13
15
 
14
16
  ### Changed
@@ -20,6 +22,20 @@ Got it — here’s your changelog tidied up for clarity and consistency without
20
22
 
21
23
  ---
22
24
 
25
+ ## [0.1.2] - 2025-05-11
26
+
27
+ ### Added
28
+
29
+ 1. Added support for closing SPL token accounts with:
30
+ - `Solace::Composers::SystemProgramCreateAccountComposer`
31
+ - `Solace::Instructions::SystemProgram::CreateAccountInstruction`
32
+
33
+ ## [0.1.1] - 2025-05-11
34
+
35
+ ### Added
36
+
37
+ 1. Added support to inject encoding externally to get the data with respective encoding.
38
+
23
39
  ## [0.1.0] - 2025-18-10
24
40
 
25
41
  **NOTE (Breaking):**
@@ -30,8 +46,8 @@ Additionally, unless explicitly required by a composer’s instruction, the `pay
30
46
 
31
47
  1. **`Solace::Tokens`** — a structured registry and lookup system for Solana token metadata.
32
48
 
33
- * Developers can define token details via a YAML configuration file scoped by network (e.g., `mainnet`, `devnet`).
34
- * Programmatic access to token metadata:
49
+ - Developers can define token details via a YAML configuration file scoped by network (e.g., `mainnet`, `devnet`).
50
+ - Programmatic access to token metadata:
35
51
 
36
52
  ```ruby
37
53
  Solace::Tokens.load(path: 'tokens.yml', network: :devnet)
@@ -39,49 +55,50 @@ Additionally, unless explicitly required by a composer’s instruction, the `pay
39
55
  Solace::Tokens.fetch('USDC') # => <Solace::Tokens::Token ...>
40
56
  Solace::Tokens.where(decimals: 6)
41
57
  ```
42
- * Dynamically registers constants for each token symbol (`USDC`, `SOL`, etc.).
43
- * Safety improvements to preserve internal constants (`Token`) during reloads.
58
+
59
+ - Dynamically registers constants for each token symbol (`USDC`, `SOL`, etc.).
60
+ - Safety improvements to preserve internal constants (`Token`) during reloads.
44
61
 
45
62
  2. **`SystemProgramCreateAccountComposer`** — composer for building account creation flows via the Solana System Program.
46
63
 
47
- * Wraps `SystemProgram::CreateAccountInstruction`.
48
- * Handles lamport allocation, rent exemption, and ownership assignment.
49
- * Simplifies creation of system-owned and program-owned accounts.
64
+ - Wraps `SystemProgram::CreateAccountInstruction`.
65
+ - Handles lamport allocation, rent exemption, and ownership assignment.
66
+ - Simplifies creation of system-owned and program-owned accounts.
50
67
 
51
68
  3. **`SplTokenProgramInitializeMintComposer`** — composer for initializing new SPL Token mints.
52
69
 
53
- * Wraps `SplToken::InitializeMintInstruction`.
54
- * Supports decimals, mint authority, and optional freeze authority.
55
- * Designed to pair with `SystemProgramCreateAccountComposer` for one-transaction mint creation.
70
+ - Wraps `SplToken::InitializeMintInstruction`.
71
+ - Supports decimals, mint authority, and optional freeze authority.
72
+ - Designed to pair with `SystemProgramCreateAccountComposer` for one-transaction mint creation.
56
73
 
57
74
  4. **`SplTokenProgramMintToComposer`** — composer for minting tokens to an ATA.
58
75
 
59
- * Wraps `SplToken::MintToInstruction`.
60
- * Supports minting tokens to a destination ATA.
76
+ - Wraps `SplToken::MintToInstruction`.
77
+ - Supports minting tokens to a destination ATA.
61
78
 
62
79
  5. **`SplTokenProgramTransferComposer`** — composer for transferring tokens.
63
80
 
64
- * Wraps `SplToken::TransferInstruction`.
65
- * Supports sending SPL tokens.
81
+ - Wraps `SplToken::TransferInstruction`.
82
+ - Supports sending SPL tokens.
66
83
 
67
84
  6. **`Solace::Connection`** — cached blockhash accessors.
68
85
 
69
- * Added `last_fetched_blockhash` and `last_fetched_block_height`.
70
- * Stores the most recently retrieved blockhash and corresponding `lastValidBlockHeight`.
71
- * Enables reuse without re-fetching between sequential transactions.
72
- * `get_latest_blockhash` now sets these values automatically.
86
+ - Added `last_fetched_blockhash` and `last_fetched_block_height`.
87
+ - Stores the most recently retrieved blockhash and corresponding `lastValidBlockHeight`.
88
+ - Enables reuse without re-fetching between sequential transactions.
89
+ - `get_latest_blockhash` now sets these values automatically.
73
90
 
74
91
  7. **`TransactionComposer`** — instruction ordering helpers.
75
92
 
76
- * Added `prepend_instruction` and `insert_instruction` for finer control of instruction order.
93
+ - Added `prepend_instruction` and `insert_instruction` for finer control of instruction order.
77
94
 
78
95
  8. **`Transaction`** — signature helper.
79
96
 
80
- * Added `transaction.signature` to get the signature from a signed transaction.
97
+ - Added `transaction.signature` to get the signature from a signed transaction.
81
98
 
82
99
  9. **Program method options** — higher-level control.
83
100
 
84
- * Added `execute`, `sign`, and a yield block to relevant Program methods for flow control and composer access.
101
+ - Added `execute`, `sign`, and a yield block to relevant Program methods for flow control and composer access.
85
102
 
86
103
  ### Changed
87
104
 
@@ -105,23 +122,26 @@ Additionally, unless explicitly required by a composer’s instruction, the `pay
105
122
 
106
123
  ### Fixed
107
124
 
108
- * Improved token loading safety in `Solace::Tokens` to prevent internal constant removal during reloads.
125
+ - Improved token loading safety in `Solace::Tokens` to prevent internal constant removal during reloads.
109
126
 
110
127
  ---
111
128
 
112
129
  ## [0.0.9] - 2025-08-12
113
130
 
114
131
  ### Added
132
+
115
133
  1. Added `get_program_accounts` to `Solace::Connection`.
116
134
 
117
135
  ### Changed
118
136
 
119
137
  ### Fixed
138
+
120
139
  1. Removed use of the `try` method for supporting non-rails environments.
121
140
 
122
141
  ## [0.0.8] - 2025-08-11
123
142
 
124
143
  ### Added
144
+
125
145
  1. Added `load` method to `Solace::Constants` to load constants from a YAML file. This method allows for loading constants from a YAML file (i.e. custom program addresses and mint accounts).
126
146
  2. Added `to_s` and `address` method to `Solace::Keypair` and `Solace::PublicKey` to return the public key as a Base58 string.
127
147
  3. Added `get_signature_status` and `get_signature_statuses` to `Solace::Connection`.
@@ -129,18 +149,22 @@ Additionally, unless explicitly required by a composer’s instruction, the `pay
129
149
  5. Added `Errors` module to `Solace::Utils` to handle errors from the HTTP requests made to the Solana RPC node.
130
150
 
131
151
  ### Changed
152
+
132
153
  1. All methods that take a `Solace::Keypair` or `Solace::Pubkey` where an address is needed now also accept a plain string address. This prevents the need of creating instances of the classes when all that is needed is the address. This is with the exception of the low-level instruction builders, which only expect the correct data and indicies with no required casting.
133
154
  2. Changed `wait_for_confirmed_signature` method to accept a `timeout`, `interval`, and `commitment` arguments.
134
155
 
135
156
  ### Fixed
157
+
136
158
  1. Fixed `get_or_create_address` method in `Solace::Programs::AssociatedTokenAccount` to return the address of the associated token account if it already exists by checking if there is any data at the address.
137
159
 
138
160
  ## [0.0.7] - 2025-08-09
139
161
 
140
162
  ### Added
163
+
141
164
  1. Added `AssociatedTokenAccountProgramCreateAccountComposer` with tests.
142
165
 
143
166
  ### Changed
167
+
144
168
  1. Updated `AssociatedTokenAccount` to use `AssociatedTokenAccountProgramCreateAccountComposer` and sign the transaction in the `create_associated_token_account` method instead of the `compose_create_associated_token_account` method.
145
169
 
146
170
  ### Fixed
@@ -148,20 +172,23 @@ Additionally, unless explicitly required by a composer’s instruction, the `pay
148
172
  ## [0.0.6] - 2025-08-07
149
173
 
150
174
  ### Added
175
+
151
176
  1. Added `from_address` method to `Solace::PublicKey`.
152
177
  2. Change docs on most methods to include an `@example` section.
153
178
 
154
179
  ### Changed
180
+
155
181
  1. Change `private_key` method on Keypair to `pivate_key_bytes`
156
182
  2. Change README to include a practical example of using composers.
157
183
 
158
184
  ### Fixed
159
- 1. Fix `encode_signatures` method in `Solace::Serializers::TransactionSerializer` to correctly count the number of signatures using the `num_required_signatures` field in the message.
160
185
 
186
+ 1. Fix `encode_signatures` method in `Solace::Serializers::TransactionSerializer` to correctly count the number of signatures using the `num_required_signatures` field in the message.
161
187
 
162
188
  ## [0.0.3] - 2025-07-30
163
189
 
164
190
  ### Added
191
+
165
192
  1. Moved `TransferCheckedInstruction` and `TransferInstruction` to `Solace::Instructions::SystemProgram` namespace.
166
193
  2. Added `get_token_account_balance` to `Solace::Connection`.
167
194
  3. Added `get_or_create_address` to `Solace::Programs::AssociatedTokenAccount`.
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solace
4
+ module Composers
5
+ # Composer for creating a SPL Token Program CloseAccount instruction.
6
+ #
7
+ # This composer resolves and orders the required accounts for a `CloseAccount` instruction,
8
+ # sets up their access permissions, and delegates construction to the appropriate
9
+ # instruction builder.
10
+ #
11
+ # The CloseAccount instruction closes a token account and transfers remaining lamports
12
+ # to a destination account. The account must have a balance of zero tokens.
13
+ #
14
+ # Required accounts:
15
+ # - **Account**: token account to close (writable, non-signer)
16
+ # - **Destination**: account to receive lamports (writable, non-signer)
17
+ # - **Authority**: account authority (non-writable, signer)
18
+ #
19
+ # @example Compose and build a close account instruction
20
+ # composer = SplTokenProgramCloseAccountComposer.new(
21
+ # account: token_account_address,
22
+ # destination: destination_address,
23
+ # authority: authority_address
24
+ # )
25
+ #
26
+ # @since 0.1.2
27
+ class SplTokenProgramCloseAccountComposer < Base
28
+ # Extracts the token account address from the params
29
+ #
30
+ # @return [String] The token account address
31
+ def account
32
+ params[:account].to_s
33
+ end
34
+
35
+ # Extracts the destination address from the params
36
+ #
37
+ # @return [String] The destination address
38
+ def destination
39
+ params[:destination].to_s
40
+ end
41
+
42
+ # Extracts the authority address from the params
43
+ #
44
+ # @return [String] The authority address
45
+ def authority
46
+ params[:authority].to_s
47
+ end
48
+
49
+ # Returns the spl token program id
50
+ #
51
+ # @return [String] The spl token program id
52
+ def spl_token_program
53
+ Constants::TOKEN_PROGRAM_ID.to_s
54
+ end
55
+
56
+ # Setup accounts required for close account instruction
57
+ # Called automatically during initialization
58
+ #
59
+ # @return [void]
60
+ def setup_accounts
61
+ account_context.add_writable_nonsigner(account)
62
+ account_context.add_writable_nonsigner(destination)
63
+ account_context.add_readonly_signer(authority)
64
+ account_context.add_readonly_nonsigner(spl_token_program)
65
+ end
66
+
67
+ # Build instruction with resolved account indices
68
+ #
69
+ # @param account_context [Utils::AccountContext] The account context
70
+ # @return [Solace::Instruction]
71
+ def build_instruction(account_context)
72
+ Instructions::SplToken::CloseAccountInstruction.build(
73
+ account_index: account_context.index_of(account),
74
+ authority_index: account_context.index_of(authority),
75
+ destination_index: account_context.index_of(destination),
76
+ program_index: account_context.index_of(spl_token_program)
77
+ )
78
+ end
79
+ end
80
+ end
81
+ end
@@ -55,11 +55,13 @@ module Solace
55
55
  # @return [Solace::Connection] The connection object
56
56
  # @param [Integer] http_open_timeout The timeout for opening an HTTP connection
57
57
  # @param [Integer] http_read_timeout The timeout for reading an HTTP response
58
+ # @param [String] encoding The encoding for the RPC requests
58
59
  def initialize(
59
60
  rpc_url = 'http://localhost:8899',
60
61
  commitment: 'processed',
61
62
  http_open_timeout: 30,
62
- http_read_timeout: 60
63
+ http_read_timeout: 60,
64
+ encoding: 'base64'
63
65
  )
64
66
  # Initialize the RPC client
65
67
  @rpc_client = Utils::RPCClient.new(
@@ -71,7 +73,7 @@ module Solace
71
73
  # Set default options for rpc requests
72
74
  @default_options = {
73
75
  commitment: commitment,
74
- encoding: 'base64'
76
+ encoding: encoding
75
77
  }
76
78
  end
77
79
 
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solace
4
+ module Instructions
5
+ module SplToken
6
+ # Instruction builder for SPL Token Program CloseAccount.
7
+ #
8
+ # The CloseAccount instruction closes a token account and transfers all remaining
9
+ # lamports to a destination account. The token account must have a balance of zero.
10
+ #
11
+ # Instruction discriminator: 9
12
+ #
13
+ # Accounts:
14
+ # 1. [writable] Token account to close
15
+ # 2. [writable] Destination account to receive lamports
16
+ # 3. [signer] Account authority
17
+ #
18
+ # @since 0.1.2
19
+ class CloseAccountInstruction
20
+ # Instruction discriminator for CloseAccount
21
+ INSTRUCTION_DISCRIMINATOR = [9].freeze
22
+
23
+ # Builds a CloseAccount instruction
24
+ #
25
+ # @param account_index [Integer] Index of the token account to close
26
+ # @param destination_index [Integer] Index of the destination account
27
+ # @param authority_index [Integer] Index of the account authority
28
+ # @param program_index [Integer] Index of the SPL Token program
29
+ # @return [Solace::Instruction] The constructed instruction
30
+ def self.build(account_index:, destination_index:, authority_index:, program_index:)
31
+ Solace::Instruction.new.tap do |ix|
32
+ ix.program_index = program_index
33
+ ix.accounts = [account_index, destination_index, authority_index]
34
+ ix.data = data
35
+ end
36
+ end
37
+
38
+ # Builds the data for a CloseAccount instruction
39
+ #
40
+ # The BufferLayout is:
41
+ # - [Instruction Index (1 byte)]
42
+ #
43
+ # @return [Array] 1-byte instruction index
44
+ def self.data
45
+ INSTRUCTION_DISCRIMINATOR
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -2,6 +2,5 @@
2
2
 
3
3
  module Solace
4
4
  # Latest version of the Solace gem.
5
- # @since 0.1.0
6
- VERSION = '0.1.0'
5
+ VERSION = '0.1.2'
7
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.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Scholl
@@ -109,6 +109,7 @@ files:
109
109
  - lib/solace/address_lookup_table.rb
110
110
  - lib/solace/composers/associated_token_account_program_create_account_composer.rb
111
111
  - lib/solace/composers/base.rb
112
+ - lib/solace/composers/spl_token_program_close_account_composer.rb
112
113
  - lib/solace/composers/spl_token_program_initialize_mint_composer.rb
113
114
  - lib/solace/composers/spl_token_program_mint_to_composer.rb
114
115
  - lib/solace/composers/spl_token_program_transfer_checked_composer.rb
@@ -125,6 +126,7 @@ files:
125
126
  - lib/solace/errors/rpc_error.rb
126
127
  - lib/solace/instruction.rb
127
128
  - lib/solace/instructions/associated_token_account/create_associated_token_account_instruction.rb
129
+ - lib/solace/instructions/spl_token/close_account_instruction.rb
128
130
  - lib/solace/instructions/spl_token/initialize_account_instruction.rb
129
131
  - lib/solace/instructions/spl_token/initialize_mint_instruction.rb
130
132
  - lib/solace/instructions/spl_token/mint_to_instruction.rb