solace 0.0.5 → 0.0.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.
- checksums.yaml +4 -4
- data/CHANGELOG +16 -4
- data/lib/solace/composers/associated_token_account_program_create_account_composer.rb +111 -0
- data/lib/solace/programs/associated_token_account.rb +19 -36
- data/lib/solace/public_key.rb +16 -0
- data/lib/solace/version.rb +1 -1
- data/lib/solace.rb +6 -3
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c814d4aef33915cc30202d32adf427a92cdf3ef5878903bbe0105a8b2c6c21b2
|
4
|
+
data.tar.gz: 4710f8beef3e275de441bc6d4eafaae1d684abb9773a342de481bbbc927bd7b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6beec23916e82507f1f2c0c7f81c351709ccc277d628676992530fb6604842447d25c3fbef034077946b6982bdb871e5d0000a58d865ebe1680426fc22c594c3
|
7
|
+
data.tar.gz: 7fc57c0668cf6bdfd62785de961bb34d819de718430ec954848cade2d6c53107d93d20e9925a2237f379637058b129ad579e7c85b04d3b611eb440a7b77f5c29
|
data/CHANGELOG
CHANGED
@@ -16,17 +16,29 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
|
|
16
16
|
### Fixed
|
17
17
|
```
|
18
18
|
|
19
|
-
## [
|
19
|
+
## [0.0.7] - 2025-08-09
|
20
20
|
|
21
21
|
### Added
|
22
|
-
1.
|
22
|
+
1. Added `AssociatedTokenAccountProgramCreateAccountComposer` with tests.
|
23
23
|
|
24
24
|
### Changed
|
25
|
-
1.
|
25
|
+
1. Updated `AssociatedTokenAccount` to use `AssociatedTokenAccountProgramCreateAccountComposer` and sign the transaction in the `create_associated_token_account` method instead of the `prepare_create_associated_token_account` method.
|
26
|
+
|
27
|
+
### Fixed
|
28
|
+
|
29
|
+
## [0.0.6] - 2025-08-07
|
30
|
+
|
31
|
+
### Added
|
32
|
+
1. Added `from_address` method to `Solace::PublicKey`.
|
26
33
|
2. Change docs on most methods to include an `@example` section.
|
27
|
-
|
34
|
+
|
35
|
+
### Changed
|
36
|
+
1. Change `private_key` method on Keypair to `pivate_key_bytes`
|
37
|
+
2. Change README to include a practical example of using composers.
|
28
38
|
|
29
39
|
### Fixed
|
40
|
+
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.
|
41
|
+
|
30
42
|
|
31
43
|
## [0.0.3] - 2025-07-30
|
32
44
|
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solace
|
4
|
+
module Composers
|
5
|
+
# Composer for creating an associated token account program create account instruction
|
6
|
+
#
|
7
|
+
# This composer resolves and orders the required accounts for a `CreateAssociatedTokenAccount` instruction,
|
8
|
+
# sets up their access permissions, and delegates construction to the appropriate
|
9
|
+
# instruction builder (`Instructions::AssociatedTokenAccount::CreateAssociatedTokenAccountInstruction`).
|
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::CreateAssociatedTokenAccountInstruction
|
29
|
+
# @since 0.0.7
|
30
|
+
class AssociatedTokenAccountProgramCreateAccountComposer < Base
|
31
|
+
# Extracts the owner address from the params
|
32
|
+
#
|
33
|
+
# @return [String] The owner address
|
34
|
+
def owner
|
35
|
+
params[:owner].is_a?(String) ? params[:owner] : params[:owner].address
|
36
|
+
end
|
37
|
+
|
38
|
+
# Extracts the mint address from the params
|
39
|
+
#
|
40
|
+
# @return [String] The mint address
|
41
|
+
def mint
|
42
|
+
params[:mint].is_a?(String) ? params[:mint] : params[:mint].address
|
43
|
+
end
|
44
|
+
|
45
|
+
# Extracts the ata_address from the params
|
46
|
+
#
|
47
|
+
# @return [String] The ata_address
|
48
|
+
def ata_address
|
49
|
+
params[:ata_address].is_a?(String) ? params[:ata_address] : params[:ata_address].address
|
50
|
+
end
|
51
|
+
|
52
|
+
# Extracts the funder address from the params
|
53
|
+
#
|
54
|
+
# @return [String] The funder address
|
55
|
+
def funder
|
56
|
+
params[:funder].is_a?(String) ? params[:funder] : params[:funder].address
|
57
|
+
end
|
58
|
+
|
59
|
+
# Extracts the system program id from the constants
|
60
|
+
#
|
61
|
+
# @return [String] The system program id
|
62
|
+
def system_program_id
|
63
|
+
Constants::SYSTEM_PROGRAM_ID
|
64
|
+
end
|
65
|
+
|
66
|
+
# Extracts the token program id from the constants
|
67
|
+
#
|
68
|
+
# @return [String] The token program id
|
69
|
+
def token_program_id
|
70
|
+
Constants::TOKEN_PROGRAM_ID
|
71
|
+
end
|
72
|
+
|
73
|
+
# Extracts the associated token account program id from the constants
|
74
|
+
#
|
75
|
+
# @return [String] The associated token account program id
|
76
|
+
def associated_token_account_program_id
|
77
|
+
Constants::ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID
|
78
|
+
end
|
79
|
+
|
80
|
+
# Setup accounts required for associated token account program create account instruction
|
81
|
+
# Called automatically during initialization
|
82
|
+
#
|
83
|
+
# @return [void]
|
84
|
+
def setup_accounts # rubocop:disable Metrics/AbcSize
|
85
|
+
account_context.add_writable_signer(funder)
|
86
|
+
account_context.add_writable_nonsigner(ata_address)
|
87
|
+
account_context.add_readonly_nonsigner(owner)
|
88
|
+
account_context.add_readonly_nonsigner(mint)
|
89
|
+
account_context.add_readonly_nonsigner(system_program_id)
|
90
|
+
account_context.add_readonly_nonsigner(token_program_id)
|
91
|
+
account_context.add_readonly_nonsigner(associated_token_account_program_id)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Builds the instruction for the associated token account program create account instruction
|
95
|
+
#
|
96
|
+
# @param account_context [Utils::AccountContext] The account context
|
97
|
+
# @return [Solace::Instruction] The instruction
|
98
|
+
def build_instruction(account_context)
|
99
|
+
Instructions::AssociatedTokenAccount::CreateAssociatedTokenAccountInstruction.build(
|
100
|
+
funder_index: account_context.index_of(funder),
|
101
|
+
owner_index: account_context.index_of(owner),
|
102
|
+
mint_index: account_context.index_of(mint),
|
103
|
+
associated_token_account_index: account_context.index_of(ata_address),
|
104
|
+
system_program_index: account_context.index_of(system_program_id),
|
105
|
+
token_program_index: account_context.index_of(token_program_id),
|
106
|
+
program_index: account_context.index_of(associated_token_account_program_id)
|
107
|
+
)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -51,7 +51,7 @@ module Solace
|
|
51
51
|
|
52
52
|
# Alias method for get_address
|
53
53
|
#
|
54
|
-
# @
|
54
|
+
# @param options [Hash] A hash of options for the get_address class method
|
55
55
|
# @return [Array<String, Integer>] The address of the associated token account and the bump seed
|
56
56
|
def get_address(**options)
|
57
57
|
self.class.get_address(**options)
|
@@ -67,9 +67,9 @@ module Solace
|
|
67
67
|
def get_or_create_address(payer:, owner:, mint:, commitment: 'confirmed')
|
68
68
|
ata_address, _bump = get_address(owner: owner, mint: mint)
|
69
69
|
|
70
|
-
|
70
|
+
account_balance = @connection.get_balance(ata_address)
|
71
71
|
|
72
|
-
return ata_address if
|
72
|
+
return ata_address if account_balance
|
73
73
|
|
74
74
|
response = create_associated_token_account(payer: payer, owner: owner, mint: mint)
|
75
75
|
|
@@ -87,6 +87,8 @@ module Solace
|
|
87
87
|
def create_associated_token_account(**options)
|
88
88
|
tx = prepare_create_associated_token_account(**options)
|
89
89
|
|
90
|
+
tx.sign(options[:payer])
|
91
|
+
|
90
92
|
@connection.send_transaction(tx.serialize)
|
91
93
|
end
|
92
94
|
|
@@ -97,7 +99,6 @@ module Solace
|
|
97
99
|
# @param payer [Solace::Keypair] The keypair that will pay for fees and rent.
|
98
100
|
# @return [Solace::Transaction] The signed transaction.
|
99
101
|
#
|
100
|
-
# rubocop:disable Metrics/MethodLength
|
101
102
|
def prepare_create_associated_token_account(
|
102
103
|
payer:,
|
103
104
|
owner:,
|
@@ -105,39 +106,21 @@ module Solace
|
|
105
106
|
)
|
106
107
|
ata_address, = get_address(owner: owner, mint: mint)
|
107
108
|
|
108
|
-
|
109
|
-
payer
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
mint_index: 3,
|
123
|
-
system_program_index: 4,
|
124
|
-
token_program_index: 5,
|
125
|
-
program_index: 6
|
126
|
-
)
|
127
|
-
|
128
|
-
message = Solace::Message.new(
|
129
|
-
header: [1, 0, 4],
|
130
|
-
accounts: accounts,
|
131
|
-
recent_blockhash: @connection.get_latest_blockhash,
|
132
|
-
instructions: [instruction]
|
133
|
-
)
|
134
|
-
|
135
|
-
tx = Solace::Transaction.new(message: message)
|
136
|
-
tx.sign(payer)
|
137
|
-
|
138
|
-
tx
|
109
|
+
TransactionComposer.new(connection: connection).try do |tx_composer|
|
110
|
+
tx_composer.set_fee_payer(payer)
|
111
|
+
|
112
|
+
tx_composer.add_instruction(
|
113
|
+
Solace::Composers::AssociatedTokenAccountProgramCreateAccountComposer.new(
|
114
|
+
mint: mint,
|
115
|
+
owner: owner,
|
116
|
+
funder: payer,
|
117
|
+
ata_address: ata_address
|
118
|
+
)
|
119
|
+
)
|
120
|
+
|
121
|
+
tx_composer.compose_transaction
|
122
|
+
end
|
139
123
|
end
|
140
|
-
# rubocop:enable Metrics/MethodLength
|
141
124
|
end
|
142
125
|
end
|
143
126
|
end
|
data/lib/solace/public_key.rb
CHANGED
@@ -95,5 +95,21 @@ module Solace
|
|
95
95
|
def to_bytes
|
96
96
|
@bytes.dup
|
97
97
|
end
|
98
|
+
|
99
|
+
class << self
|
100
|
+
# Create a public key instance from a base58 address
|
101
|
+
#
|
102
|
+
# @example
|
103
|
+
# pubkey = Solace::PublicKey.from_address(address)
|
104
|
+
#
|
105
|
+
# @param address [String] The base58 address of the public key
|
106
|
+
# @return [PublicKey] The public key instance
|
107
|
+
# @raise [ArgumentError] If the address is not a valid base58 string
|
108
|
+
#
|
109
|
+
# @since 0.0.6
|
110
|
+
def from_address(address)
|
111
|
+
new(Solace::Utils::Codecs.base58_to_bytes(address))
|
112
|
+
end
|
113
|
+
end
|
98
114
|
end
|
99
115
|
end
|
data/lib/solace/version.rb
CHANGED
data/lib/solace.rb
CHANGED
@@ -25,9 +25,13 @@ require_relative 'solace/instruction'
|
|
25
25
|
require_relative 'solace/address_lookup_table'
|
26
26
|
require_relative 'solace/transaction_composer'
|
27
27
|
|
28
|
-
#
|
28
|
+
# Base Classes (Abstract classes)
|
29
|
+
require_relative 'solace/programs/base'
|
30
|
+
require_relative 'solace/composers/base'
|
31
|
+
|
32
|
+
# 📦 Composers
|
29
33
|
#
|
30
|
-
# Glob require all
|
34
|
+
# Glob require all composers
|
31
35
|
Dir[File.join(__dir__, 'solace/composers', '**', '*.rb')].each { |file| require file }
|
32
36
|
|
33
37
|
# 📦 Instructions (Builders)
|
@@ -36,6 +40,5 @@ Dir[File.join(__dir__, 'solace/composers', '**', '*.rb')].each { |file| require
|
|
36
40
|
Dir[File.join(__dir__, 'solace/instructions', '**', '*.rb')].each { |file| require file }
|
37
41
|
|
38
42
|
# 📦 Programs
|
39
|
-
require_relative 'solace/programs/base'
|
40
43
|
require_relative 'solace/programs/spl_token'
|
41
44
|
require_relative 'solace/programs/associated_token_account'
|
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.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Scholl
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- README.md
|
94
94
|
- lib/solace.rb
|
95
95
|
- lib/solace/address_lookup_table.rb
|
96
|
+
- lib/solace/composers/associated_token_account_program_create_account_composer.rb
|
96
97
|
- lib/solace/composers/base.rb
|
97
98
|
- lib/solace/composers/spl_token_program_transfer_checked_composer.rb
|
98
99
|
- lib/solace/composers/system_program_transfer_composer.rb
|