stellar-base 0.29.0 → 0.32.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/generated/stellar/account_entry_extension_v2/ext.rb +4 -0
- data/generated/stellar/account_entry_extension_v2.rb +2 -0
- data/generated/stellar/account_entry_extension_v3.rb +28 -0
- data/generated/stellar/allow_trust_result_code.rb +5 -2
- data/generated/stellar/alpha_num12.rb +20 -0
- data/generated/stellar/alpha_num4.rb +20 -0
- data/generated/stellar/asset.rb +2 -15
- data/generated/stellar/asset_type.rb +3 -1
- data/generated/stellar/change_trust_asset.rb +39 -0
- data/generated/stellar/change_trust_op.rb +2 -2
- data/generated/stellar/change_trust_result_code.rb +15 -7
- data/generated/stellar/claim_atom.rb +31 -0
- data/generated/stellar/claim_atom_type.rb +24 -0
- data/generated/stellar/claim_liquidity_atom.rb +30 -0
- data/generated/stellar/claim_offer_atom_v0.rb +33 -0
- data/generated/stellar/crypto_key_type.rb +6 -4
- data/generated/stellar/envelope_type.rb +10 -8
- data/generated/stellar/extension_point.rb +22 -0
- data/generated/stellar/{operation_id/id.rb → hash_id_preimage/operation_id.rb} +2 -2
- data/generated/stellar/{operation_id.rb → hash_id_preimage/revoke_id.rb} +12 -16
- data/generated/stellar/hash_id_preimage.rb +44 -0
- data/generated/stellar/inner_transaction_result/result.rb +6 -2
- data/generated/stellar/inner_transaction_result.rb +2 -0
- data/generated/stellar/ledger_bounds.rb +20 -0
- data/generated/stellar/ledger_entry/data.rb +4 -0
- data/generated/stellar/ledger_entry.rb +2 -0
- data/generated/stellar/ledger_entry_type.rb +3 -1
- data/generated/stellar/ledger_header/ext.rb +4 -0
- data/generated/stellar/ledger_header.rb +2 -0
- data/generated/stellar/{asset/alpha_num12.rb → ledger_header_extension_v1/ext.rb} +9 -7
- data/generated/stellar/ledger_header_extension_v1.rb +30 -0
- data/generated/stellar/ledger_header_flags.rb +24 -0
- data/generated/stellar/{asset/alpha_num4.rb → ledger_key/liquidity_pool.rb} +4 -6
- data/generated/stellar/ledger_key/trust_line.rb +2 -2
- data/generated/stellar/ledger_key.rb +10 -1
- data/generated/stellar/ledger_upgrade.rb +4 -0
- data/generated/stellar/ledger_upgrade_type.rb +3 -1
- data/generated/stellar/liquidity_pool_constant_product_parameters.rb +22 -0
- data/generated/stellar/liquidity_pool_deposit_op.rb +26 -0
- data/generated/stellar/liquidity_pool_deposit_result.rb +25 -0
- data/generated/stellar/liquidity_pool_deposit_result_code.rb +41 -0
- data/generated/stellar/liquidity_pool_entry/body/constant_product.rb +32 -0
- data/generated/stellar/liquidity_pool_entry/body.rb +38 -0
- data/generated/stellar/liquidity_pool_entry.rb +39 -0
- data/generated/stellar/liquidity_pool_parameters.rb +23 -0
- data/generated/stellar/liquidity_pool_type.rb +20 -0
- data/generated/stellar/liquidity_pool_withdraw_op.rb +24 -0
- data/generated/stellar/liquidity_pool_withdraw_result.rb +25 -0
- data/generated/stellar/liquidity_pool_withdraw_result_code.rb +36 -0
- data/generated/stellar/manage_offer_success_result.rb +2 -2
- data/generated/stellar/message_type.rb +4 -1
- data/generated/stellar/offer_entry_flags.rb +2 -1
- data/generated/stellar/operation/body.rb +8 -0
- data/generated/stellar/operation.rb +4 -0
- data/generated/stellar/operation_result/tr.rb +8 -0
- data/generated/stellar/operation_result.rb +4 -0
- data/generated/stellar/operation_type.rb +5 -1
- data/generated/stellar/path_payment_strict_receive_result/success.rb +2 -2
- data/generated/stellar/path_payment_strict_receive_result.rb +1 -1
- data/generated/stellar/path_payment_strict_send_result/success.rb +2 -2
- data/generated/stellar/path_payment_strict_send_result.rb +1 -1
- data/generated/stellar/precondition_type.rb +24 -0
- data/generated/stellar/preconditions.rb +30 -0
- data/generated/stellar/preconditions_v2.rb +51 -0
- data/generated/stellar/revoke_sponsorship_result_code.rb +3 -1
- data/generated/stellar/scp_quorum_set.rb +2 -2
- data/generated/stellar/send_more.rb +18 -0
- data/generated/stellar/set_trust_line_flags_result_code.rb +4 -1
- data/generated/stellar/signer_key/ed25519_signed_payload.rb +24 -0
- data/generated/stellar/signer_key.rb +20 -6
- data/generated/stellar/signer_key_type.rb +6 -4
- data/generated/stellar/stellar_message.rb +4 -0
- data/generated/stellar/transaction.rb +3 -3
- data/generated/stellar/transaction_result_code.rb +6 -1
- data/generated/stellar/trust_line_asset.rb +39 -0
- data/generated/stellar/trust_line_entry/ext/v1/ext.rb +4 -0
- data/generated/stellar/trust_line_entry/ext/v1.rb +2 -0
- data/generated/stellar/trust_line_entry/ext.rb +2 -0
- data/generated/stellar/trust_line_entry.rb +7 -5
- data/generated/stellar/trust_line_entry_extension_v2/ext.rb +24 -0
- data/generated/stellar/trust_line_entry_extension_v2.rb +30 -0
- data/generated/stellar-base-generated.rb +33 -1
- data/lib/stellar/account_flags.rb +1 -1
- data/lib/stellar/amount.rb +36 -0
- data/lib/stellar/asset.rb +8 -0
- data/lib/stellar/dsl.rb +3 -0
- data/lib/stellar/ledger_key.rb +5 -3
- data/lib/stellar/liquidity_pool/base_pool.rb +47 -0
- data/lib/stellar/liquidity_pool/constant_product_pool.rb +15 -0
- data/lib/stellar/liquidity_pool.rb +12 -0
- data/lib/stellar/operation.rb +346 -444
- data/lib/stellar/price.rb +13 -7
- data/lib/stellar/transaction.rb +1 -1
- data/lib/stellar/transaction_builder.rb +120 -18
- data/lib/stellar/transaction_v0.rb +5 -1
- data/lib/stellar/util/strkey.rb +15 -1
- data/lib/stellar/version.rb +1 -1
- data/lib/stellar-base.rb +2 -0
- metadata +51 -70
@@ -0,0 +1,24 @@
|
|
1
|
+
# This code was automatically generated using xdrgen
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# union switch (int v)
|
9
|
+
# {
|
10
|
+
# case 0:
|
11
|
+
# void;
|
12
|
+
# }
|
13
|
+
#
|
14
|
+
# ===========================================================================
|
15
|
+
module Stellar
|
16
|
+
class TrustLineEntryExtensionV2
|
17
|
+
class Ext < XDR::Union
|
18
|
+
switch_on XDR::Int, :v
|
19
|
+
|
20
|
+
switch 0
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# This code was automatically generated using xdrgen
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# struct TrustLineEntryExtensionV2
|
9
|
+
# {
|
10
|
+
# int32 liquidityPoolUseCount;
|
11
|
+
#
|
12
|
+
# union switch (int v)
|
13
|
+
# {
|
14
|
+
# case 0:
|
15
|
+
# void;
|
16
|
+
# }
|
17
|
+
# ext;
|
18
|
+
# };
|
19
|
+
#
|
20
|
+
# ===========================================================================
|
21
|
+
module Stellar
|
22
|
+
class TrustLineEntryExtensionV2 < XDR::Struct
|
23
|
+
include XDR::Namespace
|
24
|
+
|
25
|
+
autoload :Ext
|
26
|
+
|
27
|
+
attribute :liquidity_pool_use_count, Int32
|
28
|
+
attribute :ext, Ext
|
29
|
+
end
|
30
|
+
end
|
@@ -12,6 +12,7 @@ module Stellar
|
|
12
12
|
Int32 = XDR::Int
|
13
13
|
Uint64 = XDR::UnsignedHyper
|
14
14
|
Int64 = XDR::Hyper
|
15
|
+
autoload :ExtensionPoint
|
15
16
|
autoload :CryptoKeyType
|
16
17
|
autoload :PublicKeyType
|
17
18
|
autoload :SignerKeyType
|
@@ -34,11 +35,15 @@ module Stellar
|
|
34
35
|
String64 = XDR::String[64]
|
35
36
|
SequenceNumber = Int64
|
36
37
|
TimePoint = Uint64
|
38
|
+
Duration = Uint64
|
37
39
|
DataValue = XDR::VarOpaque[64]
|
40
|
+
PoolID = Hash
|
38
41
|
AssetCode4 = XDR::Opaque[4]
|
39
42
|
AssetCode12 = XDR::Opaque[12]
|
40
43
|
autoload :AssetType
|
41
44
|
autoload :AssetCode
|
45
|
+
autoload :AlphaNum4
|
46
|
+
autoload :AlphaNum12
|
42
47
|
autoload :Asset
|
43
48
|
autoload :Price
|
44
49
|
autoload :Liabilities
|
@@ -50,6 +55,7 @@ module Stellar
|
|
50
55
|
MASK_ACCOUNT_FLAGS_V17 = 0xF
|
51
56
|
MAX_SIGNERS = 20
|
52
57
|
SponsorshipDescriptor = XDR::Option[AccountID]
|
58
|
+
autoload :AccountEntryExtensionV3
|
53
59
|
autoload :AccountEntryExtensionV2
|
54
60
|
autoload :AccountEntryExtensionV1
|
55
61
|
autoload :AccountEntry
|
@@ -57,6 +63,9 @@ module Stellar
|
|
57
63
|
MASK_TRUSTLINE_FLAGS = 1
|
58
64
|
MASK_TRUSTLINE_FLAGS_V13 = 3
|
59
65
|
MASK_TRUSTLINE_FLAGS_V17 = 7
|
66
|
+
autoload :LiquidityPoolType
|
67
|
+
autoload :TrustLineAsset
|
68
|
+
autoload :TrustLineEntryExtensionV2
|
60
69
|
autoload :TrustLineEntry
|
61
70
|
autoload :OfferEntryFlags
|
62
71
|
MASK_OFFERENTRY_FLAGS = 1
|
@@ -72,6 +81,8 @@ module Stellar
|
|
72
81
|
MASK_CLAIMABLE_BALANCE_FLAGS = 0x1
|
73
82
|
autoload :ClaimableBalanceEntryExtensionV1
|
74
83
|
autoload :ClaimableBalanceEntry
|
84
|
+
autoload :LiquidityPoolConstantProductParameters
|
85
|
+
autoload :LiquidityPoolEntry
|
75
86
|
autoload :LedgerEntryExtensionV1
|
76
87
|
autoload :LedgerEntry
|
77
88
|
autoload :LedgerKey
|
@@ -80,6 +91,7 @@ end
|
|
80
91
|
module Stellar
|
81
92
|
include XDR::Namespace
|
82
93
|
|
94
|
+
autoload :LiquidityPoolParameters
|
83
95
|
autoload :MuxedAccount
|
84
96
|
autoload :DecoratedSignature
|
85
97
|
autoload :OperationType
|
@@ -91,6 +103,7 @@ module Stellar
|
|
91
103
|
autoload :ManageBuyOfferOp
|
92
104
|
autoload :CreatePassiveSellOfferOp
|
93
105
|
autoload :SetOptionsOp
|
106
|
+
autoload :ChangeTrustAsset
|
94
107
|
autoload :ChangeTrustOp
|
95
108
|
autoload :AllowTrustOp
|
96
109
|
autoload :ManageDataOp
|
@@ -103,11 +116,18 @@ module Stellar
|
|
103
116
|
autoload :ClawbackOp
|
104
117
|
autoload :ClawbackClaimableBalanceOp
|
105
118
|
autoload :SetTrustLineFlagsOp
|
119
|
+
LIQUIDITY_POOL_FEE_V18 = 30
|
120
|
+
autoload :LiquidityPoolDepositOp
|
121
|
+
autoload :LiquidityPoolWithdrawOp
|
106
122
|
autoload :Operation
|
107
|
-
autoload :
|
123
|
+
autoload :HashIDPreimage
|
108
124
|
autoload :MemoType
|
109
125
|
autoload :Memo
|
110
126
|
autoload :TimeBounds
|
127
|
+
autoload :LedgerBounds
|
128
|
+
autoload :PreconditionsV2
|
129
|
+
autoload :PreconditionType
|
130
|
+
autoload :Preconditions
|
111
131
|
MAX_OPS_PER_TX = 100
|
112
132
|
autoload :TransactionV0
|
113
133
|
autoload :TransactionV0Envelope
|
@@ -117,7 +137,11 @@ module Stellar
|
|
117
137
|
autoload :FeeBumpTransactionEnvelope
|
118
138
|
autoload :TransactionEnvelope
|
119
139
|
autoload :TransactionSignaturePayload
|
140
|
+
autoload :ClaimAtomType
|
141
|
+
autoload :ClaimOfferAtomV0
|
120
142
|
autoload :ClaimOfferAtom
|
143
|
+
autoload :ClaimLiquidityAtom
|
144
|
+
autoload :ClaimAtom
|
121
145
|
autoload :CreateAccountResultCode
|
122
146
|
autoload :CreateAccountResult
|
123
147
|
autoload :PaymentResultCode
|
@@ -164,6 +188,10 @@ module Stellar
|
|
164
188
|
autoload :ClawbackClaimableBalanceResult
|
165
189
|
autoload :SetTrustLineFlagsResultCode
|
166
190
|
autoload :SetTrustLineFlagsResult
|
191
|
+
autoload :LiquidityPoolDepositResultCode
|
192
|
+
autoload :LiquidityPoolDepositResult
|
193
|
+
autoload :LiquidityPoolWithdrawResultCode
|
194
|
+
autoload :LiquidityPoolWithdrawResult
|
167
195
|
autoload :OperationResultCode
|
168
196
|
autoload :OperationResult
|
169
197
|
autoload :TransactionResultCode
|
@@ -178,6 +206,9 @@ module Stellar
|
|
178
206
|
autoload :StellarValueType
|
179
207
|
autoload :LedgerCloseValueSignature
|
180
208
|
autoload :StellarValue
|
209
|
+
MASK_LEDGER_HEADER_FLAGS = 0x7
|
210
|
+
autoload :LedgerHeaderFlags
|
211
|
+
autoload :LedgerHeaderExtensionV1
|
181
212
|
autoload :LedgerHeader
|
182
213
|
autoload :LedgerUpgradeType
|
183
214
|
autoload :LedgerUpgrade
|
@@ -210,6 +241,7 @@ module Stellar
|
|
210
241
|
|
211
242
|
autoload :ErrorCode
|
212
243
|
autoload :Error
|
244
|
+
autoload :SendMore
|
213
245
|
autoload :AuthCert
|
214
246
|
autoload :Hello
|
215
247
|
autoload :Auth
|
@@ -4,7 +4,7 @@ module Stellar
|
|
4
4
|
# Converts an array of Stellar::AccountFlags members into
|
5
5
|
# an Integer suitable for use in a SetOptionsOp.
|
6
6
|
#
|
7
|
-
# @param flags [Array<Stellar::AccountFlags
|
7
|
+
# @param flags [Array<Stellar::AccountFlags>, nil] the flags to combine
|
8
8
|
#
|
9
9
|
# @return [Fixnum] the combined result
|
10
10
|
def self.make_mask(flags = nil)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Stellar
|
2
|
+
class Amount
|
3
|
+
attr_reader :amount
|
4
|
+
attr_reader :asset
|
5
|
+
|
6
|
+
# @param [Fixnum] amount
|
7
|
+
# @param [Stellar::Asset] asset
|
8
|
+
def initialize(amount, asset = Stellar::Asset.native)
|
9
|
+
# TODO: how are we going to handle decimal considerations?
|
10
|
+
|
11
|
+
@amount = amount
|
12
|
+
@asset = asset
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [Array(Symbol, Fixnum)] in case of a native asset
|
16
|
+
# @return [Array(Symbol, String, Stellar::KeyPair, Fixnum)] in case of alphanum asset
|
17
|
+
def to_payment
|
18
|
+
case asset.type
|
19
|
+
when AssetType.asset_type_native
|
20
|
+
[:native, amount]
|
21
|
+
when AssetType.asset_type_credit_alphanum4
|
22
|
+
keypair = KeyPair.from_public_key(asset.issuer.value)
|
23
|
+
[:alphanum4, asset.code, keypair, amount]
|
24
|
+
when AssetType.asset_type_credit_alphanum12
|
25
|
+
keypair = KeyPair.from_public_key(asset.issuer.value)
|
26
|
+
[:alphanum12, asset.code, keypair, amount]
|
27
|
+
else
|
28
|
+
raise "Unknown asset type: #{asset.type}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def inspect
|
33
|
+
"#<Stellar::Amount #{asset}(#{amount})>"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/stellar/asset.rb
CHANGED
@@ -30,6 +30,14 @@ module Stellar
|
|
30
30
|
new(:asset_type_credit_alphanum12, an)
|
31
31
|
end
|
32
32
|
|
33
|
+
def to_change_trust_asset
|
34
|
+
ChangeTrustAsset.new(switch, value)
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_trust_line_asset
|
38
|
+
TrustLineAsset.new(switch, value)
|
39
|
+
end
|
40
|
+
|
33
41
|
def to_s
|
34
42
|
case switch
|
35
43
|
when AssetType.asset_type_native
|
data/lib/stellar/dsl.rb
CHANGED
@@ -53,6 +53,9 @@ module Stellar
|
|
53
53
|
case subject
|
54
54
|
when Asset
|
55
55
|
subject
|
56
|
+
when Array
|
57
|
+
raise TypeError, "Invalid asset type #{subject[0]}" unless [:native, :alphanum4, :alphanum12].include?(subject[0])
|
58
|
+
Asset.send(*subject)
|
56
59
|
when nil, /^(XLM[-:])?native$/
|
57
60
|
Asset.native
|
58
61
|
when /^([0-9A-Z]{1,4})[-:](G[A-Z0-9]{55})$/
|
data/lib/stellar/ledger_key.rb
CHANGED
@@ -15,14 +15,16 @@ module Stellar
|
|
15
15
|
case field
|
16
16
|
when nil
|
17
17
|
account(account_id: KeyPair(account_id).account_id)
|
18
|
-
when :balance_id
|
19
|
-
claimable_balance(balance_id: ClaimableBalanceID.v0(Stellar::Convert.from_hex(value.to_s)))
|
20
18
|
when :offer_id
|
21
19
|
offer(seller_id: account_id, offer_id: Integer(value))
|
22
20
|
when :data_name
|
23
21
|
data(account_id: account_id, data_name: value.to_s)
|
24
22
|
when :asset
|
25
|
-
trust_line(account_id: account_id, asset: Asset(value))
|
23
|
+
trust_line(account_id: account_id, asset: Asset(value).to_trust_line_asset)
|
24
|
+
when :balance_id
|
25
|
+
claimable_balance(balance_id: ClaimableBalanceID.v0(Stellar::Convert.from_hex(value.to_s)))
|
26
|
+
when :liquidity_pool_id
|
27
|
+
liquidity_pool(liquidity_pool_id: PoolID.from_xdr(value.to_s, :hex))
|
26
28
|
else
|
27
29
|
raise ArgumentError, "unknown option #{field} (not in :asset, :offer_id, :data_name, :balance_id)"
|
28
30
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Stellar
|
2
|
+
module LiquidityPool
|
3
|
+
class BasePool
|
4
|
+
attr_reader :asset_a, :asset_b, :fee
|
5
|
+
|
6
|
+
# @param asset_a [Asset]
|
7
|
+
# @param asset_b [Asset]
|
8
|
+
def initialize(asset_a:, asset_b:)
|
9
|
+
@asset_a = asset_a
|
10
|
+
@asset_b = asset_b
|
11
|
+
@fee = LIQUIDITY_POOL_FEE_V18
|
12
|
+
end
|
13
|
+
|
14
|
+
def id
|
15
|
+
PoolID.to_xdr(to_pool_id, :hex)
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
"liquidity_pool:#{id}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def inspect
|
23
|
+
"#<#{self.class.name} #{self}>"
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_pool_id
|
27
|
+
Digest::SHA256.digest(pool_params.to_xdr)
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_change_trust_asset
|
31
|
+
ChangeTrustAsset.liquidity_pool(pool_params)
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_trust_line_asset
|
35
|
+
TrustLineAsset.liquidity_pool_id(to_pool_id)
|
36
|
+
end
|
37
|
+
|
38
|
+
def pool_type
|
39
|
+
raise NotImplementedError
|
40
|
+
end
|
41
|
+
|
42
|
+
def pool_params
|
43
|
+
raise NotImplementedError
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative "base_pool"
|
2
|
+
|
3
|
+
module Stellar
|
4
|
+
module LiquidityPool
|
5
|
+
class ConstantProductPool < BasePool
|
6
|
+
def pool_type
|
7
|
+
LiquidityPoolType.constant_product
|
8
|
+
end
|
9
|
+
|
10
|
+
def pool_params
|
11
|
+
LiquidityPoolParameters.constant_product(asset_a: asset_a, asset_b: asset_b, fee: fee)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Stellar
|
2
|
+
module LiquidityPool
|
3
|
+
require_relative "liquidity_pool/base_pool"
|
4
|
+
require_relative "liquidity_pool/constant_product_pool"
|
5
|
+
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def constant_product(asset_a:, asset_b:)
|
9
|
+
ConstantProductPool.new(asset_a: DSL::Asset(asset_a), asset_b: DSL::Asset(asset_b))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|