solace 0.0.3 → 0.0.5
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 +12 -0
- data/README.md +140 -285
- data/lib/solace/address_lookup_table.rb +34 -18
- data/lib/solace/composers/base.rb +16 -11
- data/lib/solace/composers/spl_token_program_transfer_checked_composer.rb +27 -1
- data/lib/solace/composers/system_program_transfer_composer.rb +22 -1
- data/lib/solace/concerns/binary_serializable.rb +39 -0
- data/lib/solace/connection.rb +69 -38
- data/lib/solace/constants.rb +7 -14
- data/lib/solace/instruction.rb +30 -19
- data/lib/solace/instructions/associated_token_account/create_associated_token_account_instruction.rb +18 -3
- data/lib/solace/instructions/spl_token/initialize_account_instruction.rb +24 -3
- data/lib/solace/instructions/spl_token/initialize_mint_instruction.rb +18 -1
- data/lib/solace/instructions/spl_token/mint_to_instruction.rb +16 -3
- data/lib/solace/instructions/spl_token/transfer_checked_instruction.rb +17 -1
- data/lib/solace/instructions/spl_token/transfer_instruction.rb +15 -2
- data/lib/solace/instructions/system_program/create_account_instruction.rb +18 -3
- data/lib/solace/instructions/system_program/transfer_instruction.rb +15 -7
- data/lib/solace/keypair.rb +64 -31
- data/lib/solace/message.rb +22 -10
- data/lib/solace/programs/associated_token_account.rb +45 -20
- data/lib/solace/programs/base.rb +6 -0
- data/lib/solace/programs/spl_token.rb +52 -14
- data/lib/solace/public_key.rb +45 -20
- data/lib/solace/serializers/address_lookup_table_deserializer.rb +3 -5
- data/lib/solace/serializers/address_lookup_table_serializer.rb +7 -7
- data/lib/solace/serializers/base_deserializer.rb +29 -19
- data/lib/solace/serializers/base_serializer.rb +18 -9
- data/lib/solace/serializers/instruction_deserializer.rb +5 -7
- data/lib/solace/serializers/instruction_serializer.rb +4 -6
- data/lib/solace/serializers/message_deserializer.rb +3 -5
- data/lib/solace/serializers/message_serializer.rb +3 -5
- data/lib/solace/serializers/transaction_deserializer.rb +5 -7
- data/lib/solace/serializers/transaction_serializer.rb +5 -7
- data/lib/solace/transaction.rb +38 -23
- data/lib/solace/transaction_composer.rb +47 -13
- data/lib/solace/utils/account_context.rb +64 -65
- data/lib/solace/utils/codecs.rb +56 -128
- data/lib/solace/utils/curve25519_dalek.rb +9 -4
- data/lib/solace/utils/pda.rb +22 -24
- data/lib/solace/version.rb +2 -1
- data/lib/solace.rb +4 -9
- metadata +7 -10
- data/lib/solace/instructions/base.rb +0 -21
- data/lib/solace/serializable_record.rb +0 -26
- data/lib/solace/serializers/base.rb +0 -31
@@ -1,20 +1,36 @@
|
|
1
1
|
# encoding: ASCII-8BIT
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
# =============================
|
5
|
-
# Address Lookup Table
|
6
|
-
# =============================
|
7
|
-
#
|
8
|
-
# Class representing an address lookup table.
|
9
|
-
#
|
10
|
-
# The BufferLayout is:
|
11
|
-
# - [Account key (32 bytes)]
|
12
|
-
# - [Number of writable indexes (compact u16)]
|
13
|
-
# - [Writable indexes (variable length)]
|
14
|
-
# - [Number of readonly indexes (compact u16)]
|
15
|
-
# - [Readonly indexes (variable length)]
|
16
|
-
#
|
17
4
|
module Solace
|
5
|
+
# Represents a Solana Address Lookup Table account.
|
6
|
+
#
|
7
|
+
# This class models the internal structure of a deserialized address lookup table and provides
|
8
|
+
# access to the account key, writable indexes, and readonly indexes.
|
9
|
+
#
|
10
|
+
# It includes serialization and deserialization logic for encoding and decoding the table
|
11
|
+
# according to Solana’s buffer layout.
|
12
|
+
#
|
13
|
+
# ## Buffer Layout (in bytes):
|
14
|
+
# - `[account (32 bytes)]`
|
15
|
+
# - `[num_writable (compact-u16)]`
|
16
|
+
# - `[writable indexes]`
|
17
|
+
# - `[num_readonly (compact-u16)]`
|
18
|
+
# - `[readonly indexes]`
|
19
|
+
#
|
20
|
+
# Includes `BinarySerializable`, enabling methods like `#to_binary`, `#to_io`, and `#to_bytes`.
|
21
|
+
#
|
22
|
+
# @example Deserialize from base64
|
23
|
+
# io = StringIO.new(base64)
|
24
|
+
# table = Solace::AddressLookupTable.deserialize(io)
|
25
|
+
#
|
26
|
+
# @example Serialize to base64
|
27
|
+
# table = Solace::AddressLookupTable.new
|
28
|
+
# table.account = pubkey
|
29
|
+
# table.writable_indexes = [1, 2]
|
30
|
+
# table.readonly_indexes = [3, 4]
|
31
|
+
# base64 = table.serialize
|
32
|
+
#
|
33
|
+
# @since 0.0.1
|
18
34
|
class AddressLookupTable
|
19
35
|
include Solace::Concerns::BinarySerializable
|
20
36
|
|
@@ -31,20 +47,20 @@ module Solace
|
|
31
47
|
attr_accessor :readonly_indexes
|
32
48
|
|
33
49
|
class << self
|
34
|
-
#
|
50
|
+
# Deserializes an address lookup table from io stream
|
35
51
|
#
|
36
|
-
# @param io [IO
|
52
|
+
# @param io [IO, StringIO] The input to read bytes from.
|
37
53
|
# @return [Solace::AddressLookupTable] Parsed address lookup table object
|
38
54
|
def deserialize(io)
|
39
|
-
Solace::Serializers::AddressLookupTableDeserializer.
|
55
|
+
Solace::Serializers::AddressLookupTableDeserializer.new(io).call
|
40
56
|
end
|
41
57
|
end
|
42
58
|
|
43
|
-
#
|
59
|
+
# Serializes the address lookup table
|
44
60
|
#
|
45
61
|
# @return [String] The serialized address lookup table (base64)
|
46
62
|
def serialize
|
47
|
-
Solace::Serializers::AddressLookupTableSerializer.
|
63
|
+
Solace::Serializers::AddressLookupTableSerializer.new(self).call
|
48
64
|
end
|
49
65
|
end
|
50
66
|
end
|
@@ -1,22 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Solace
|
2
4
|
module Composers
|
5
|
+
# A Base class for all composers
|
6
|
+
#
|
7
|
+
# @since 0.0.3
|
3
8
|
class Base
|
4
|
-
# @!attribute
|
9
|
+
# @!attribute params
|
5
10
|
# The params for the composer
|
6
|
-
#
|
11
|
+
#
|
7
12
|
# @return [Hash] The parameters passed to the composer
|
8
13
|
attr_reader :params
|
9
|
-
|
10
|
-
# @!attribute
|
14
|
+
|
15
|
+
# @!attribute account_context
|
11
16
|
# The account_context for the composer
|
12
17
|
#
|
13
18
|
# @return [Utils::AccountContext] The AccountContext instance for the composer
|
14
19
|
attr_reader :account_context
|
15
|
-
|
20
|
+
|
16
21
|
# Initialize the composer
|
17
22
|
#
|
18
|
-
# @param
|
19
|
-
def initialize(
|
23
|
+
# @param params [Hash] Parameters to pass to the composer constructor
|
24
|
+
def initialize(params)
|
20
25
|
@params = params
|
21
26
|
@account_context = Utils::AccountContext.new
|
22
27
|
setup_accounts
|
@@ -26,15 +31,15 @@ module Solace
|
|
26
31
|
#
|
27
32
|
# @return [void]
|
28
33
|
def setup_accounts
|
29
|
-
raise NotImplementedError,
|
34
|
+
raise NotImplementedError, 'Subclasses must implement setup_accounts method'
|
30
35
|
end
|
31
|
-
|
36
|
+
|
32
37
|
# Build instruction with resolved account indices
|
33
38
|
#
|
34
39
|
# @return [void]
|
35
40
|
def build_instruction(indices)
|
36
|
-
raise NotImplementedError,
|
41
|
+
raise NotImplementedError, 'Subclasses must implement build_instruction method'
|
37
42
|
end
|
38
43
|
end
|
39
44
|
end
|
40
|
-
end
|
45
|
+
end
|
@@ -2,6 +2,33 @@
|
|
2
2
|
|
3
3
|
module Solace
|
4
4
|
module Composers
|
5
|
+
# Composer for creating a SPL Token Program `TransferChecked` instruction.
|
6
|
+
#
|
7
|
+
# This composer resolves and orders the required accounts for a `TransferChecked` instruction,
|
8
|
+
# sets up their access permissions, and delegates construction to the appropriate
|
9
|
+
# instruction builder (`Instructions::SplToken::TransferCheckedInstruction`).
|
10
|
+
#
|
11
|
+
# It is used for transferring SPL tokens with decimal precision and validation checks.
|
12
|
+
#
|
13
|
+
# Required accounts:
|
14
|
+
# - **From**: source token account (writable, non-signer)
|
15
|
+
# - **To**: destination token account (writable, non-signer)
|
16
|
+
# - **Mint**: mint address (readonly, non-signer)
|
17
|
+
# - **Authority**: token owner (writable, signer)
|
18
|
+
# - **Program**: SPL Token program (readonly, non-signer)
|
19
|
+
#
|
20
|
+
# @example Compose and build a transfer_checked instruction
|
21
|
+
# composer = SplTokenProgramTransferCheckedComposer.new(
|
22
|
+
# from: from_address,
|
23
|
+
# to: to_address,
|
24
|
+
# mint: mint_address,
|
25
|
+
# authority: authority_pubkey,
|
26
|
+
# amount: 1_000_000,
|
27
|
+
# decimals: 6
|
28
|
+
# )
|
29
|
+
#
|
30
|
+
# @see Instructions::SplToken::TransferCheckedInstruction
|
31
|
+
# @since 0.0.3
|
5
32
|
class SplTokenProgramTransferCheckedComposer < Base
|
6
33
|
# Extracts the to address from the params
|
7
34
|
#
|
@@ -84,4 +111,3 @@ module Solace
|
|
84
111
|
end
|
85
112
|
end
|
86
113
|
end
|
87
|
-
|
@@ -2,6 +2,28 @@
|
|
2
2
|
|
3
3
|
module Solace
|
4
4
|
module Composers
|
5
|
+
# Composer for creating a system program transfer instruction.
|
6
|
+
#
|
7
|
+
# This composer resolves and orders the required accounts for a `Transfer` instruction,
|
8
|
+
# sets up their access permissions, and delegates construction to the appropriate
|
9
|
+
# instruction builder (`Instructions::SystemProgram::TransferInstruction`).
|
10
|
+
#
|
11
|
+
# It is used for transferring lamports from one account to another.
|
12
|
+
#
|
13
|
+
# Required accounts:
|
14
|
+
# - **From**: source account (writable, signer)
|
15
|
+
# - **To**: destination account (writable, non-signer)
|
16
|
+
# - **Program**: System program (readonly, non-signer)
|
17
|
+
#
|
18
|
+
# @example Compose and build a transfer instruction
|
19
|
+
# composer = SystemProgramTransferComposer.new(
|
20
|
+
# from: from_address,
|
21
|
+
# to: to_address,
|
22
|
+
# lamports: 1_000_000
|
23
|
+
# )
|
24
|
+
#
|
25
|
+
# @see Instructions::SystemProgram::TransferInstruction
|
26
|
+
# @since 0.0.3
|
5
27
|
class SystemProgramTransferComposer < Base
|
6
28
|
# Extracts the to address from the params
|
7
29
|
#
|
@@ -56,4 +78,3 @@ module Solace
|
|
56
78
|
end
|
57
79
|
end
|
58
80
|
end
|
59
|
-
|
@@ -2,7 +2,24 @@
|
|
2
2
|
|
3
3
|
module Solace
|
4
4
|
module Concerns
|
5
|
+
# Adds binary serialization support to a class
|
6
|
+
#
|
7
|
+
# Transactions, Messages, Instructions, and AddressLookupTables are all binary serializable.
|
8
|
+
# These classes use this concern to add binary serialization support.
|
9
|
+
#
|
10
|
+
# @see Solace::Transaction
|
11
|
+
# @see Solace::Message
|
12
|
+
# @see Solace::Instruction
|
13
|
+
# @see Solace::AddressLookupTable
|
14
|
+
# @since 0.0.1
|
5
15
|
module BinarySerializable
|
16
|
+
# Include the module
|
17
|
+
#
|
18
|
+
# @param base [Class] The base class to include the module into
|
19
|
+
def self.included(base)
|
20
|
+
base.extend ClassMethods
|
21
|
+
end
|
22
|
+
|
6
23
|
# Returns the binary decoded from the serialized string
|
7
24
|
#
|
8
25
|
# Expects the class to have a `serialize` method that returns a base64 string.
|
@@ -25,6 +42,28 @@ module Solace
|
|
25
42
|
def to_bytes
|
26
43
|
to_binary.bytes
|
27
44
|
end
|
45
|
+
|
46
|
+
# Serializes the record to a binary format
|
47
|
+
#
|
48
|
+
# @return [String] The serialized record (binary)
|
49
|
+
def serialize
|
50
|
+
self.class::SERIALIZER.new(self).call
|
51
|
+
rescue NameError => e
|
52
|
+
raise "SERIALIZER must be defined: #{e.message}"
|
53
|
+
end
|
54
|
+
|
55
|
+
# Class methods for binary serializable
|
56
|
+
module ClassMethods
|
57
|
+
# Parse record from bytestream
|
58
|
+
#
|
59
|
+
# @param stream [IO, StringIO] The input to read bytes from.
|
60
|
+
# @return [Solace::Instruction] Parsed instruction instance
|
61
|
+
def deserialize(stream)
|
62
|
+
self::DESERIALIZER.new(stream).call
|
63
|
+
rescue NameError => e
|
64
|
+
raise "DESERIALIZER must be defined: #{e.message}"
|
65
|
+
end
|
66
|
+
end
|
28
67
|
end
|
29
68
|
end
|
30
69
|
end
|
data/lib/solace/connection.rb
CHANGED
@@ -5,72 +5,69 @@ require 'json'
|
|
5
5
|
require 'uri'
|
6
6
|
|
7
7
|
module Solace
|
8
|
+
# Connection to a Solana RPC node
|
9
|
+
#
|
10
|
+
# This class provides methods for sending JSON-RPC requests to a Solana RPC node and parsing responses.
|
11
|
+
# It includes methods for sending transactions, getting account information, and getting blockhashes.
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# # Initialize the connection
|
15
|
+
# connection = Solace::Connection.new('http://localhost:8899', commitment: 'confirmed')
|
16
|
+
#
|
17
|
+
# # Get account information
|
18
|
+
# connection.get_account_info(account.address)
|
19
|
+
#
|
20
|
+
# # Request an airdrop
|
21
|
+
# result = connection.request_airdrop(account.address, 1000000)
|
22
|
+
#
|
23
|
+
# # Wait for the transaction to be finalized
|
24
|
+
# connection.wait_for_confirmed_signature('finalized') { result['result'] }
|
25
|
+
#
|
26
|
+
# @since 0.0.1
|
27
|
+
#
|
28
|
+
# rubocop:disable Metrics/ClassLength
|
8
29
|
class Connection
|
9
30
|
# @!attribute [r] rpc_url
|
10
31
|
# The URL of the Solana RPC node
|
11
|
-
#
|
12
|
-
# @return [String] The URL of the Solana RPC node
|
13
32
|
attr_reader :rpc_url
|
14
33
|
|
15
34
|
# @!attribute [r] default_options
|
16
35
|
# The default options for RPC requests
|
17
|
-
#
|
18
|
-
# @return [Hash] The default options for RPC requests
|
19
36
|
attr_reader :default_options
|
20
37
|
|
21
38
|
# Initialize the connection with a default or custom RPC URL
|
22
39
|
#
|
23
40
|
# @param rpc_url [String] The URL of the Solana RPC node
|
41
|
+
# @param commitment [String] The commitment level for RPC requests
|
24
42
|
# @return [Solace::Connection] The connection object
|
25
43
|
def initialize(rpc_url = 'http://localhost:8899', commitment: 'confirmed')
|
26
44
|
@request_id = nil
|
27
45
|
@rpc_url = rpc_url
|
28
46
|
|
29
47
|
# Set default options
|
30
|
-
@default_options = {
|
48
|
+
@default_options = {
|
31
49
|
commitment: commitment,
|
32
50
|
encoding: 'base64'
|
33
51
|
}
|
34
52
|
end
|
35
53
|
|
36
|
-
#
|
54
|
+
# Sends a JSON-RPC request to the configured Solana RPC server.
|
37
55
|
#
|
38
|
-
# @param method [String]
|
39
|
-
# @param params [Array]
|
40
|
-
# @return [
|
56
|
+
# @param method [String] the JSON-RPC method name
|
57
|
+
# @param params [Array] the parameters for the RPC method
|
58
|
+
# @return [Hash] the parsed JSON response
|
59
|
+
# @raise [RuntimeError] if the response is not successful
|
41
60
|
def rpc_request(method, params = [])
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
req['Accept'] = 'application/json'
|
46
|
-
req['Content-Type'] = 'application/json'
|
47
|
-
|
48
|
-
@request_id = SecureRandom.uuid
|
49
|
-
|
50
|
-
req.body = {
|
51
|
-
jsonrpc: '2.0',
|
52
|
-
id: @request_id,
|
53
|
-
method: method,
|
54
|
-
params: params
|
55
|
-
}.to_json
|
56
|
-
|
57
|
-
res = Net::HTTP.start(
|
58
|
-
uri.hostname,
|
59
|
-
uri.port,
|
60
|
-
use_ssl: uri.scheme == 'https'
|
61
|
-
) do |http|
|
62
|
-
http.request(req)
|
63
|
-
end
|
64
|
-
|
65
|
-
raise "RPC error: #{res.body}" unless res.is_a?(Net::HTTPSuccess)
|
66
|
-
|
67
|
-
JSON.parse(res.body)
|
61
|
+
request = build_rpc_request(method, params)
|
62
|
+
response = perform_http_request(request)
|
63
|
+
handle_rpc_response(response)
|
68
64
|
end
|
69
65
|
|
70
66
|
# Request an airdrop of lamports to a given address
|
71
67
|
#
|
72
68
|
# @param pubkey [String] The public key of the account to receive the airdrop
|
73
69
|
# @param lamports [Integer] Amount of lamports to airdrop
|
70
|
+
# @param [Hash{Symbol => Object}] options The options for the request
|
74
71
|
# @return [String] The transaction signature of the airdrop
|
75
72
|
def request_airdrop(pubkey, lamports, options = {})
|
76
73
|
rpc_request(
|
@@ -148,6 +145,7 @@ module Solace
|
|
148
145
|
#
|
149
146
|
# @param signature [String] The signature of the transaction
|
150
147
|
# @return [Solace::Transaction] The transaction object
|
148
|
+
# @param [Hash{Symbol => Object}] options
|
151
149
|
def get_transaction(signature, options = { maxSupportedTransactionVersion: 0 })
|
152
150
|
rpc_request(
|
153
151
|
'getTransaction',
|
@@ -176,6 +174,7 @@ module Solace
|
|
176
174
|
#
|
177
175
|
# @param transaction [Solace::Transaction] The transaction to send
|
178
176
|
# @return [String] The signature of the transaction
|
177
|
+
# @param [Hash{Symbol => Object}] options
|
179
178
|
def send_transaction(transaction, options = {})
|
180
179
|
rpc_request(
|
181
180
|
'sendTransaction',
|
@@ -201,13 +200,45 @@ module Solace
|
|
201
200
|
# Wait for confirmation
|
202
201
|
loop do
|
203
202
|
status = get_signature_status([signature]).dig('value', 0)
|
204
|
-
|
203
|
+
|
205
204
|
break if status && status['confirmationStatus'] == commitment
|
206
|
-
|
205
|
+
|
207
206
|
sleep interval
|
208
207
|
end
|
209
|
-
|
208
|
+
|
210
209
|
signature
|
211
210
|
end
|
211
|
+
|
212
|
+
private
|
213
|
+
|
214
|
+
def build_rpc_request(method, params)
|
215
|
+
uri = URI(rpc_url)
|
216
|
+
req = Net::HTTP::Post.new(uri)
|
217
|
+
req['Accept'] = 'application/json'
|
218
|
+
req['Content-Type'] = 'application/json'
|
219
|
+
@request_id = SecureRandom.uuid
|
220
|
+
|
221
|
+
req.body = {
|
222
|
+
jsonrpc: '2.0',
|
223
|
+
id: @request_id,
|
224
|
+
method: method,
|
225
|
+
params: params
|
226
|
+
}.to_json
|
227
|
+
|
228
|
+
[uri, req]
|
229
|
+
end
|
230
|
+
|
231
|
+
def perform_http_request((uri, req))
|
232
|
+
Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
233
|
+
http.request(req)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def handle_rpc_response(response)
|
238
|
+
raise "RPC error: #{response.body}" unless response.is_a?(Net::HTTPSuccess)
|
239
|
+
|
240
|
+
JSON.parse(response.body)
|
241
|
+
end
|
212
242
|
end
|
243
|
+
# rubocop:enable Metrics/ClassLength
|
213
244
|
end
|
data/lib/solace/constants.rb
CHANGED
@@ -7,46 +7,39 @@
|
|
7
7
|
# @return [Module] Constants module
|
8
8
|
module Solace
|
9
9
|
module Constants
|
10
|
-
# @!
|
10
|
+
# @!attribute SYSTEM_PROGRAM_ID
|
11
11
|
# The public key of the System Program (native SOL transfers, account creation, etc)
|
12
12
|
# This is the same across all Solana clusters
|
13
|
-
# @return [String]
|
14
13
|
SYSTEM_PROGRAM_ID = '11111111111111111111111111111111'
|
15
14
|
|
16
|
-
# @!
|
15
|
+
# @!attribute SYSVAR_RENT_PROGRAM_ID
|
17
16
|
# The public key of the Rent Program
|
18
17
|
# This is the same across all Solana clusters
|
19
|
-
# @return [String]
|
20
18
|
SYSVAR_RENT_PROGRAM_ID = 'SysvarRent111111111111111111111111111111111'
|
21
19
|
|
22
|
-
# @!
|
20
|
+
# @!attribute COMPUTE_BUDGET_PROGRAM_ID
|
23
21
|
# The public key of the Compute Budget Program
|
24
22
|
# This is the same across all Solana clusters
|
25
|
-
# @return [String]
|
26
23
|
COMPUTE_BUDGET_PROGRAM_ID = 'ComputeBudget111111111111111111111111111111'
|
27
24
|
|
28
|
-
# @!
|
25
|
+
# @!attribute TOKEN_PROGRAM_ID
|
29
26
|
# The public key of the SPL Token Program
|
30
27
|
# This is the same across all Solana clusters
|
31
|
-
# @return [String]
|
32
28
|
TOKEN_PROGRAM_ID = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
|
33
29
|
|
34
|
-
# @!
|
30
|
+
# @!attribute ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID
|
35
31
|
# The public key of the Associated Token Account Program
|
36
32
|
# This is the same across all Solana clusters
|
37
|
-
# @return [String]
|
38
33
|
ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'
|
39
34
|
|
40
|
-
# @!
|
35
|
+
# @!attribute MEMO_PROGRAM_ID
|
41
36
|
# The public key of the Memo Program
|
42
37
|
# This is the same across all Solana clusters
|
43
|
-
# @return [String]
|
44
38
|
MEMO_PROGRAM_ID = 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'
|
45
39
|
|
46
|
-
# @!
|
40
|
+
# @!attribute ADDRESS_LOOKUP_TABLE_PROGRAM_ID
|
47
41
|
# The public key of the Address Lookup Table Program
|
48
42
|
# This is the same across all Solana clusters
|
49
|
-
# @return [String]
|
50
43
|
ADDRESS_LOOKUP_TABLE_PROGRAM_ID = 'AddressLookupTab1e1111111111111111111111111'
|
51
44
|
end
|
52
45
|
end
|
data/lib/solace/instruction.rb
CHANGED
@@ -1,37 +1,48 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# =============================
|
4
|
-
# Instruction
|
5
|
-
# =============================
|
6
|
-
#
|
7
|
-
# Class representing a Solana instruction.
|
8
|
-
#
|
9
|
-
# The BufferLayout is:
|
10
|
-
# - [Program index (1 byte)]
|
11
|
-
# - [Number of accounts (compact u16)]
|
12
|
-
# - [Accounts (variable length)]
|
13
|
-
# - [Data length (compact u16)]
|
14
|
-
# - [Data (variable length)]
|
15
|
-
#
|
16
3
|
module Solace
|
17
|
-
|
18
|
-
|
4
|
+
# Class representing a Solana instruction.
|
5
|
+
#
|
6
|
+
# Handles serialization and deserialization of instruction fields. Instructions are used to
|
7
|
+
# encode the data that is sent to a program on the Solana blockchain. Instructions are part of
|
8
|
+
# transaction messages. All instruction builders and instruction composers return an instance of
|
9
|
+
# this class.
|
10
|
+
#
|
11
|
+
# The BufferLayout is:
|
12
|
+
# - [Program index (1 byte)]
|
13
|
+
# - [Number of accounts (compact u16)]
|
14
|
+
# - [Accounts (variable length)]
|
15
|
+
# - [Data length (compact u16)]
|
16
|
+
# - [Data (variable length)]
|
17
|
+
#
|
18
|
+
# @example
|
19
|
+
# instruction = Solace::Instruction.new(
|
20
|
+
# program_index: 0,
|
21
|
+
# accounts: [1, 2, 3],
|
22
|
+
# data: [4, 5, 6]
|
23
|
+
# )
|
24
|
+
#
|
25
|
+
# @since 0.0.1
|
26
|
+
class Instruction
|
27
|
+
include Solace::Concerns::BinarySerializable
|
28
|
+
|
29
|
+
# @!attribute SERIALIZER
|
19
30
|
# @return [Solace::Serializers::InstructionSerializer] The serializer for the instruction
|
20
31
|
SERIALIZER = Solace::Serializers::InstructionSerializer
|
21
32
|
|
22
|
-
# @!
|
33
|
+
# @!attribute DESERIALIZER
|
23
34
|
# @return [Solace::Serializers::InstructionDeserializer] The deserializer for the instruction
|
24
35
|
DESERIALIZER = Solace::Serializers::InstructionDeserializer
|
25
36
|
|
26
|
-
# @!attribute
|
37
|
+
# @!attribute [rw] program_index
|
27
38
|
# @return [Integer] The program index of the instruction
|
28
39
|
attr_accessor :program_index
|
29
40
|
|
30
|
-
# @!attribute
|
41
|
+
# @!attribute [rw] accounts
|
31
42
|
# @return [Array<Integer>] The accounts of the instruction
|
32
43
|
attr_accessor :accounts
|
33
44
|
|
34
|
-
# @!attribute
|
45
|
+
# @!attribute [rw] data
|
35
46
|
# @return [Array<Integer>] The instruction data
|
36
47
|
attr_accessor :data
|
37
48
|
end
|
data/lib/solace/instructions/associated_token_account/create_associated_token_account_instruction.rb
CHANGED
@@ -3,8 +3,23 @@
|
|
3
3
|
module Solace
|
4
4
|
module Instructions
|
5
5
|
module AssociatedTokenAccount
|
6
|
-
#
|
7
|
-
#
|
6
|
+
# Instruction for creating an Associated Token Account.
|
7
|
+
#
|
8
|
+
# This is a special "all-in-one" instruction that creates and initializes the account. It
|
9
|
+
# is used to create an Associated Token Account (ATA) for a given mint and owner.
|
10
|
+
#
|
11
|
+
# @example Build a CreateAssociatedTokenAccount instruction
|
12
|
+
# instruction = Solace::Instructions::AssociatedTokenAccount::CreateAssociatedTokenAccountInstruction.build(
|
13
|
+
# funder_index: 0,
|
14
|
+
# associated_token_account_index: 1,
|
15
|
+
# owner_index: 2,
|
16
|
+
# mint_index: 3,
|
17
|
+
# system_program_index: 4,
|
18
|
+
# token_program_index: 5,
|
19
|
+
# program_index: 6
|
20
|
+
# )
|
21
|
+
#
|
22
|
+
# @since 0.0.2
|
8
23
|
class CreateAssociatedTokenAccountInstruction
|
9
24
|
# !@const INSTRUCTION_INDEX
|
10
25
|
# Instruction index for CreateAssociatedTokenAccount
|
@@ -65,4 +80,4 @@ module Solace
|
|
65
80
|
end
|
66
81
|
end
|
67
82
|
end
|
68
|
-
end
|
83
|
+
end
|
@@ -1,11 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# lib/solace/instructions/spl_token/initialize_account_instruction.rb
|
2
4
|
|
3
5
|
module Solace
|
4
6
|
module Instructions
|
5
7
|
module SplToken
|
6
|
-
#
|
8
|
+
# Instruction for initializing a new token account.
|
9
|
+
#
|
10
|
+
# This instruction is used to initialize a new token account for a given mint and owner. It
|
11
|
+
# is used in conjunction with the CreateAccount instruction to create and initialize a new
|
12
|
+
# token account. Note that the AssociatedTokenAccount::CreateAssociatedTokenAccountInstruction
|
13
|
+
# is a special "all-in-one" instruction that creates and initializes the account in a single
|
14
|
+
# instruction.
|
15
|
+
#
|
16
|
+
# @example Build an InitializeAccount instruction
|
17
|
+
# instruction = Solace::Instructions::SplToken::InitializeAccountInstruction.build(
|
18
|
+
# account_index: 0,
|
19
|
+
# mint_index: 1,
|
20
|
+
# owner_index: 2,
|
21
|
+
# rent_sysvar_index: 3,
|
22
|
+
# program_index: 4
|
23
|
+
# )
|
24
|
+
#
|
25
|
+
# @see Solace::Instructions::AssociatedTokenAccount::CreateAssociatedTokenAccountInstruction
|
26
|
+
# @see Solace::Instructions::SystemProgram::CreateAccountInstruction
|
27
|
+
# @since 0.0.2
|
7
28
|
class InitializeAccountInstruction
|
8
|
-
# @!
|
29
|
+
# @!attribute [Array<Integer>] INSTRUCTION_INDEX
|
9
30
|
# Instruction index for SPL Token Program's InitializeAccount instruction.
|
10
31
|
INSTRUCTION_INDEX = [1].freeze
|
11
32
|
|
@@ -43,4 +64,4 @@ module Solace
|
|
43
64
|
end
|
44
65
|
end
|
45
66
|
end
|
46
|
-
end
|
67
|
+
end
|
@@ -3,6 +3,23 @@
|
|
3
3
|
module Solace
|
4
4
|
module Instructions
|
5
5
|
module SplToken
|
6
|
+
# Instruction for initializing a new mint.
|
7
|
+
#
|
8
|
+
# This instruction is used to initialize a new mint for a given token. It is used in conjunction with the SystemProgram::CreateAccount
|
9
|
+
# instruction to create and initialize a new mint account.
|
10
|
+
#
|
11
|
+
# @example Build an InitializeMint instruction
|
12
|
+
# instruction = Solace::Instructions::SplToken::InitializeMintInstruction.build(
|
13
|
+
# decimals: 6,
|
14
|
+
# mint_authority: mint_authority.address,
|
15
|
+
# freeze_authority: freeze_authority.address,
|
16
|
+
# rent_sysvar_index: 2,
|
17
|
+
# mint_account_index: 1,
|
18
|
+
# program_index: 3
|
19
|
+
# )
|
20
|
+
#
|
21
|
+
# @see Solace::Instructions::SystemProgram::CreateAccountInstruction
|
22
|
+
# @since 0.0.2
|
6
23
|
class InitializeMintInstruction
|
7
24
|
# Instruction index for Initialize Mint
|
8
25
|
INSTRUCTION_INDEX = [0].freeze
|
@@ -49,7 +66,7 @@ module Solace
|
|
49
66
|
# @param decimals [Integer] Number of decimals for the token
|
50
67
|
# @param mint_authority [String] Public key of the mint authority
|
51
68
|
# @param freeze_authority [String, nil] Public key of the freeze authority
|
52
|
-
# @return [Array]
|
69
|
+
# @return [Array<u8>] The instruction data
|
53
70
|
def self.data(decimals, mint_authority, freeze_authority)
|
54
71
|
INSTRUCTION_INDEX +
|
55
72
|
[decimals] +
|
@@ -3,9 +3,22 @@
|
|
3
3
|
module Solace
|
4
4
|
module Instructions
|
5
5
|
module SplToken
|
6
|
-
#
|
6
|
+
# Instruction for minting tokens to a token account.
|
7
|
+
#
|
8
|
+
# This instruction is used to mint tokens to a token account for a given mint and owner.
|
9
|
+
#
|
10
|
+
# @example Build a MintTo instruction
|
11
|
+
# instruction = Solace::Instructions::SplToken::MintToInstruction.build(
|
12
|
+
# amount: 100,
|
13
|
+
# mint_index: 1,
|
14
|
+
# mint_authority_index: 2,
|
15
|
+
# destination_index: 3,
|
16
|
+
# program_index: 4
|
17
|
+
# )
|
18
|
+
#
|
19
|
+
# @since 0.0.2
|
7
20
|
class MintToInstruction
|
8
|
-
# @!
|
21
|
+
# @!attribute [Array<Integer>] INSTRUCTION_INDEX
|
9
22
|
# Instruction index for SPL Token Program's MintTo instruction.
|
10
23
|
INSTRUCTION_INDEX = [7].freeze
|
11
24
|
|
@@ -45,4 +58,4 @@ module Solace
|
|
45
58
|
end
|
46
59
|
end
|
47
60
|
end
|
48
|
-
end
|
61
|
+
end
|