BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
liquidity_pool_object.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Abit More, and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <graphene/chain/types.hpp>
28 
31 
32 #include <boost/multi_index/composite_key.hpp>
33 
34 namespace graphene { namespace chain {
35 
36 using namespace graphene::db;
37 
44 class liquidity_pool_object : public abstract_object<liquidity_pool_object, protocol_ids, liquidity_pool_object_type>
45 {
46  public:
47  asset_id_type asset_a;
48  asset_id_type asset_b;
51  asset_id_type share_asset;
52  uint16_t taker_fee_percent = 0;
53  uint16_t withdrawal_fee_percent = 0;
54  fc::uint128_t virtual_value = 0;
55 
57  {
58  virtual_value = fc::uint128_t( balance_a.value ) * balance_b.value;
59  }
60 };
61 
62 struct by_share_asset;
63 struct by_asset_a;
64 struct by_asset_b;
65 struct by_asset_ab;
66 
70 typedef multi_index_container<
72  indexed_by<
73  ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
74  ordered_unique< tag<by_share_asset>,
75  member< liquidity_pool_object, asset_id_type, &liquidity_pool_object::share_asset > >,
76  ordered_unique< tag<by_asset_a>,
77  composite_key< liquidity_pool_object,
78  member< liquidity_pool_object, asset_id_type, &liquidity_pool_object::asset_a >,
79  member< object, object_id_type, &object::id>
80  >
81  >,
82  ordered_unique< tag<by_asset_b>,
83  composite_key< liquidity_pool_object,
84  member< liquidity_pool_object, asset_id_type, &liquidity_pool_object::asset_b >,
85  member< object, object_id_type, &object::id>
86  >
87  >,
88  ordered_unique< tag<by_asset_ab>,
89  composite_key< liquidity_pool_object,
90  member< liquidity_pool_object, asset_id_type, &liquidity_pool_object::asset_a >,
91  member< liquidity_pool_object, asset_id_type, &liquidity_pool_object::asset_b >,
92  member< object, object_id_type, &object::id>
93  >
94  >
95  >
97 
102 
103 } } // graphene::chain
104 
106 
107 // Note: this is left here but not moved to a cpp file due to the extended_liquidity_pool_object struct in API.
109  (asset_a)
110  (asset_b)
111  (balance_a)
112  (balance_b)
113  (share_asset)
114  (taker_fee_percent)
115  (withdrawal_fee_percent)
116  (virtual_value)
117  )
118 
graphene::chain::liquidity_pool_object::share_asset
asset_id_type share_asset
Type of the share asset aka the LP token.
Definition: liquidity_pool_object.hpp:51
graphene::chain::liquidity_pool_object::asset_a
asset_id_type asset_a
Type of the first asset in the pool.
Definition: liquidity_pool_object.hpp:47
graphene::chain::liquidity_pool_object::asset_b
asset_id_type asset_b
Type of the second asset in the pool.
Definition: liquidity_pool_object.hpp:48
generic_index.hpp
MAP_OBJECT_ID_TO_TYPE
#define MAP_OBJECT_ID_TO_TYPE(OBJECT)
Definition: object_id.hpp:93
graphene::db::abstract_object
Definition: object.hpp:107
graphene::chain::liquidity_pool_object::balance_a
share_type balance_a
The balance of the first asset in the pool.
Definition: liquidity_pool_object.hpp:49
graphene::chain::liquidity_pool_multi_index_type
multi_index_container< liquidity_pool_object, indexed_by< ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >, ordered_unique< tag< by_share_asset >, member< liquidity_pool_object, asset_id_type, &liquidity_pool_object::share_asset > >, ordered_unique< tag< by_asset_a >, composite_key< liquidity_pool_object, member< liquidity_pool_object, asset_id_type, &liquidity_pool_object::asset_a >, member< object, object_id_type, &object::id > > >, ordered_unique< tag< by_asset_b >, composite_key< liquidity_pool_object, member< liquidity_pool_object, asset_id_type, &liquidity_pool_object::asset_b >, member< object, object_id_type, &object::id > > >, ordered_unique< tag< by_asset_ab >, composite_key< liquidity_pool_object, member< liquidity_pool_object, asset_id_type, &liquidity_pool_object::asset_a >, member< liquidity_pool_object, asset_id_type, &liquidity_pool_object::asset_b >, member< object, object_id_type, &object::id > > > >> liquidity_pool_multi_index_type
Definition: liquidity_pool_object.hpp:65
FC_REFLECT_DERIVED
#define FC_REFLECT_DERIVED(TYPE, INHERITS, MEMBERS)
Specializes fc::reflector for TYPE where type inherits other reflected classes.
Definition: reflect.hpp:305
liquidity_pool.hpp
graphene::chain::liquidity_pool_object::balance_b
share_type balance_b
The balance of the second asset in the pool.
Definition: liquidity_pool_object.hpp:50
graphene::chain::liquidity_pool_index
generic_index< liquidity_pool_object, liquidity_pool_multi_index_type > liquidity_pool_index
Definition: liquidity_pool_object.hpp:101
GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:85
graphene::chain::liquidity_pool_object::update_virtual_value
void update_virtual_value()
Definition: liquidity_pool_object.hpp:56
graphene::chain::liquidity_pool_object
A liquidity pool.
Definition: liquidity_pool_object.hpp:44
types.hpp
graphene::db::generic_index
Definition: generic_index.hpp:43
graphene::db
Definition: generic_index.hpp:31
fc::safe::value
T value
Definition: safe.hpp:28
asset.hpp
graphene
Definition: api.cpp:48
graphene::db::object
base for all database objects
Definition: object.hpp:61
fc::safe
Definition: safe.hpp:26