solace 0.1.1 → 0.1.3

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: a9bca105aef6d20a1a5b6d5dc6b2fce8c7a8523c9a2a24afd3ad15bf36efbb55
4
- data.tar.gz: e6a70370368a4822249bf7c912f70f54a02ce5389ef128e40acdc769b315ebae
3
+ metadata.gz: 4c4e4949dfaad369b5fbe6db182896b73fce66456fa04b480a394753bd76f3d8
4
+ data.tar.gz: e0fc2a7292a0ef3688555b419a534b7d8aa64fae214cc5f0317aebcd2af767e1
5
5
  SHA512:
6
- metadata.gz: 44fc38f19753ed736c05e1ba58bc7799fbe96d736553e3df220cfa38cae60a0dc2d2ecb3459990300efc108d56b9ec0ae8ce4fc552c39b31cf668e54878f52bd
7
- data.tar.gz: 4ffe860837dc85e925f308fdff68129ba01cdc41fb192495af4926bbd91328c62847f862c2847a819c9615cd1b223d512910a421713ee64f9b038bee25def482
6
+ metadata.gz: a1653573d2cabf8c0253157a03b7bb5ebfadedf0eeeb6dea1eefa89c0b79aa01250637bab175f0d91e3072bcf7fd18a43b082d40851cb9b5d5bc7759971d54fe
7
+ data.tar.gz: 718ea842339b67b89b99f9c1a674148b510e3ed6bdd4921a9fa574cd83525452e8ff7e17d8138a97821d9885cdb54a8b09037b3826666c7db59328bdfc25f67c
data/CHANGELOG CHANGED
@@ -18,10 +18,29 @@ 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
 
36
+ ## [0.1.2] - 2025-05-11
37
+
38
+ ### Added
39
+
40
+ 1. Added support for closing SPL token accounts with:
41
+ - `Solace::Composers::SystemProgramCreateAccountComposer`
42
+ - `Solace::Instructions::SystemProgram::CreateAccountInstruction`
43
+
25
44
  ## [0.1.1] - 2025-05-11
26
45
 
27
46
  ### Added
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -2,6 +2,5 @@
2
2
 
3
3
  module Solace
4
4
  # Latest version of the Solace gem.
5
- # @since 0.1.1
6
- VERSION = '0.1.1'
5
+ VERSION = '0.1.3'
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.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Scholl
@@ -108,7 +108,9 @@ 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
113
+ - lib/solace/composers/spl_token_program_close_account_composer.rb
112
114
  - lib/solace/composers/spl_token_program_initialize_mint_composer.rb
113
115
  - lib/solace/composers/spl_token_program_mint_to_composer.rb
114
116
  - lib/solace/composers/spl_token_program_transfer_checked_composer.rb
@@ -124,7 +126,9 @@ files:
124
126
  - lib/solace/errors/parse_error.rb
125
127
  - lib/solace/errors/rpc_error.rb
126
128
  - lib/solace/instruction.rb
127
- - lib/solace/instructions/associated_token_account/create_associated_token_account_instruction.rb
129
+ - lib/solace/instructions/associated_token_account/create_account_instruction.rb
130
+ - lib/solace/instructions/associated_token_account/create_idempotent_account_instruction.rb
131
+ - lib/solace/instructions/spl_token/close_account_instruction.rb
128
132
  - lib/solace/instructions/spl_token/initialize_account_instruction.rb
129
133
  - lib/solace/instructions/spl_token/initialize_mint_instruction.rb
130
134
  - lib/solace/instructions/spl_token/mint_to_instruction.rb