BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface 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>
45 {
46  public:
47  static constexpr uint8_t space_id = protocol_ids;
48  static constexpr uint8_t type_id = liquidity_pool_object_type;
49 
50  asset_id_type asset_a;
51  asset_id_type asset_b;
54  asset_id_type share_asset;
55  uint16_t taker_fee_percent = 0;
56  uint16_t withdrawal_fee_percent = 0;
57  fc::uint128_t virtual_value = 0;
58 
60  {
61  virtual_value = fc::uint128_t( balance_a.value ) * balance_b.value;
62  }
63 };
64 
65 struct by_share_asset;
66 struct by_asset_a;
67 struct by_asset_b;
68 struct by_asset_ab;
69 
73 typedef multi_index_container<
75  indexed_by<
76  ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
77  ordered_unique< tag<by_share_asset>,
78  member< liquidity_pool_object, asset_id_type, &liquidity_pool_object::share_asset > >,
79  ordered_unique< tag<by_asset_a>,
80  composite_key< liquidity_pool_object,
81  member< liquidity_pool_object, asset_id_type, &liquidity_pool_object::asset_a >,
82  member< object, object_id_type, &object::id>
83  >
84  >,
85  ordered_unique< tag<by_asset_b>,
86  composite_key< liquidity_pool_object,
87  member< liquidity_pool_object, asset_id_type, &liquidity_pool_object::asset_b >,
88  member< object, object_id_type, &object::id>
89  >
90  >,
91  ordered_unique< tag<by_asset_ab>,
92  composite_key< liquidity_pool_object,
93  member< liquidity_pool_object, asset_id_type, &liquidity_pool_object::asset_a >,
94  member< liquidity_pool_object, asset_id_type, &liquidity_pool_object::asset_b >,
95  member< object, object_id_type, &object::id>
96  >
97  >
98  >
100 
105 
106 } } // graphene::chain
107 
109 
111 
asset_id_type asset_a
Type of the first asset in the pool.
Definition: api.cpp:56
#define MAP_OBJECT_ID_TO_TYPE(OBJECT)
Definition: object_id.hpp:98
asset_id_type asset_b
Type of the second asset in the pool.
asset_id_type share_asset
Type of the share asset aka the LP token.
FC_REFLECT_TYPENAME(fc::log_message)
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:73
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
share_type balance_a
The balance of the first asset in the pool.
Use the Curiously Recurring Template Pattern to automatically add the ability to clone, serialize, and move objects polymorphically.
Definition: object.hpp:86
generic_index< liquidity_pool_object, liquidity_pool_multi_index_type > liquidity_pool_index
share_type balance_b
The balance of the second asset in the pool.
T value
Definition: safe.hpp:22