stellar-base 0.26.0 → 0.30.0
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.md +54 -32
- data/README.md +3 -3
- data/generated/stellar/account_flags.rb +9 -4
- data/generated/stellar/account_merge_result.rb +1 -1
- data/generated/stellar/allow_trust_op.rb +3 -18
- data/generated/stellar/allow_trust_result_code.rb +4 -1
- 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_code.rb +30 -0
- data/generated/stellar/asset_type.rb +3 -1
- data/generated/stellar/begin_sponsoring_future_reserves_result.rb +2 -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 +13 -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/claimable_balance_entry/ext.rb +4 -0
- data/generated/stellar/claimable_balance_entry.rb +2 -0
- data/generated/stellar/{asset/alpha_num12.rb → claimable_balance_entry_extension_v1/ext.rb} +9 -7
- data/generated/stellar/{operation_id.rb → claimable_balance_entry_extension_v1.rb} +12 -14
- data/generated/stellar/claimable_balance_flags.rb +22 -0
- data/generated/stellar/clawback_claimable_balance_op.rb +18 -0
- data/generated/stellar/clawback_claimable_balance_result.rb +26 -0
- data/generated/stellar/clawback_claimable_balance_result_code.rb +29 -0
- data/generated/stellar/clawback_op.rb +22 -0
- data/generated/stellar/clawback_result.rb +25 -0
- data/generated/stellar/clawback_result_code.rb +31 -0
- data/generated/stellar/create_passive_sell_offer_op.rb +1 -1
- data/generated/stellar/end_sponsoring_future_reserves_result.rb +2 -1
- data/generated/stellar/envelope_type.rb +10 -8
- data/generated/stellar/{operation_id/id.rb → hash_id_preimage/operation_id.rb} +4 -4
- data/generated/stellar/hash_id_preimage/revoke_id.rb +28 -0
- data/generated/stellar/hash_id_preimage.rb +44 -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/ledger_header_extension_v1/ext.rb +24 -0
- 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 +26 -0
- data/generated/stellar/liquidity_pool_deposit_result_code.rb +41 -0
- data/generated/stellar/liquidity_pool_entry/body/constant_product.rb +31 -0
- data/generated/stellar/liquidity_pool_entry/body.rb +37 -0
- data/generated/stellar/liquidity_pool_entry.rb +38 -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 +26 -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/operation/body.rb +20 -0
- data/generated/stellar/operation.rb +10 -0
- data/generated/stellar/operation_result/tr.rb +20 -0
- data/generated/stellar/operation_result.rb +10 -0
- data/generated/stellar/operation_type.rb +11 -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/payment_result_code.rb +1 -1
- data/generated/stellar/revoke_sponsorship_op.rb +1 -2
- data/generated/stellar/revoke_sponsorship_result_code.rb +3 -1
- data/generated/stellar/scp_quorum_set.rb +2 -2
- data/generated/stellar/set_options_result_code.rb +14 -11
- data/generated/stellar/set_trust_line_flags_op.rb +25 -0
- data/generated/stellar/set_trust_line_flags_result.rb +25 -0
- data/generated/stellar/set_trust_line_flags_result_code.rb +34 -0
- data/generated/stellar/transaction_result_code.rb +1 -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/trust_line_flags.rb +5 -1
- data/generated/stellar-base-generated.rb +40 -1
- data/lib/stellar/account.rb +59 -0
- 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/compat.rb +6 -3
- data/lib/stellar/concerns/transaction.rb +4 -2
- data/lib/stellar/dsl.rb +26 -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 +357 -386
- data/lib/stellar/price.rb +13 -7
- data/lib/stellar/transaction_builder.rb +27 -11
- data/lib/stellar/trust_line_flags.rb +53 -0
- data/lib/stellar/util/strkey.rb +15 -7
- data/lib/stellar/version.rb +3 -0
- data/lib/stellar-base.rb +5 -2
- metadata +61 -16
- data/generated/stellar/allow_trust_op/asset.rb +0 -33
- data/lib/stellar/base/version.rb +0 -5
|
@@ -19,7 +19,7 @@ module Stellar::Concerns
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def merge(other)
|
|
22
|
-
cloned =
|
|
22
|
+
cloned = from_xdr(to_xdr)
|
|
23
23
|
cloned.operations += other.to_operations
|
|
24
24
|
cloned
|
|
25
25
|
end
|
|
@@ -32,7 +32,9 @@ module Stellar::Concerns
|
|
|
32
32
|
#
|
|
33
33
|
# @return [Array<Operation>] the operations
|
|
34
34
|
def to_operations
|
|
35
|
-
|
|
35
|
+
codec = XDR::VarArray[Stellar::Operation]
|
|
36
|
+
ops = respond_to?(:operations) ? operations : inner_tx.value.tx.operations
|
|
37
|
+
cloned = codec.from_xdr(codec.to_xdr(ops))
|
|
36
38
|
cloned.each do |op|
|
|
37
39
|
op.source_account ||= source_account
|
|
38
40
|
end
|
data/lib/stellar/dsl.rb
CHANGED
|
@@ -27,10 +27,35 @@ module Stellar
|
|
|
27
27
|
)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
def Account(subject = nil)
|
|
31
|
+
case subject
|
|
32
|
+
when Account
|
|
33
|
+
subject
|
|
34
|
+
when /^M[A-Z0-9]{68}$/
|
|
35
|
+
Account.from_address(subject.to_str)
|
|
36
|
+
when nil
|
|
37
|
+
Account.random
|
|
38
|
+
else
|
|
39
|
+
begin
|
|
40
|
+
keypair = KeyPair(subject)
|
|
41
|
+
|
|
42
|
+
Account.new(keypair)
|
|
43
|
+
rescue TypeError
|
|
44
|
+
raise TypeError, "Cannot convert #{subject.inspect} to Stellar::Account"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# @param [Asset, String, nil] subject
|
|
50
|
+
# @return [Stellar::Asset] instance of the Stellar::Asset
|
|
51
|
+
# @raise [TypeError] if subject cannot be converted to Stellar::Asset
|
|
30
52
|
def Asset(subject = nil)
|
|
31
53
|
case subject
|
|
32
54
|
when Asset
|
|
33
55
|
subject
|
|
56
|
+
when Array
|
|
57
|
+
raise TypeError, "Invalid asset type #{subject[0]}" unless [:native, :alphanum4, :alphanum12].include?(subject[0])
|
|
58
|
+
Asset.send(*subject)
|
|
34
59
|
when nil, /^(XLM[-:])?native$/
|
|
35
60
|
Asset.native
|
|
36
61
|
when /^([0-9A-Z]{1,4})[-:](G[A-Z0-9]{55})$/
|
|
@@ -45,6 +70,7 @@ module Stellar
|
|
|
45
70
|
# Generates Stellar::Keypair from subject, use Stellar::Client.to_keypair as shortcut.
|
|
46
71
|
# @param subject [String|Stellar::Account|Stellar::PublicKey|Stellar::SignerKey|Stellar::Keypair] subject.
|
|
47
72
|
# @return [Stellar::Keypair] Stellar::Keypair instance.
|
|
73
|
+
# @raise [TypeError] if subject cannot be converted to Stellar::KeyPair
|
|
48
74
|
def KeyPair(subject = nil)
|
|
49
75
|
case subject
|
|
50
76
|
when ->(subj) { subj.respond_to?(:to_keypair) }
|
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
|