BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
liquidity_pool.cpp
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  */
25 
26 #include <fc/io/raw.hpp>
27 
28 namespace graphene { namespace protocol {
29 
31 {
32  FC_ASSERT( fee.amount >= 0, "Fee should not be negative" );
33  FC_ASSERT( asset_a < asset_b, "ID of the first asset should be smaller than ID of the second asset" );
35  "Share asset can not be the same as one of the assets in the pool" );
36  FC_ASSERT( taker_fee_percent <= GRAPHENE_100_PERCENT, "Taker fee percent should not exceed 100%" );
37  FC_ASSERT( withdrawal_fee_percent <= GRAPHENE_100_PERCENT, "Withdrawal fee percent should not exceed 100%" );
38 }
39 
41 {
42  FC_ASSERT( fee.amount >= 0, "Fee should not be negative" );
43 }
44 
46 {
47  FC_ASSERT( fee.amount >= 0, "Fee should not be negative" );
48  FC_ASSERT( taker_fee_percent.valid() || withdrawal_fee_percent.valid(), "Should update something" );
49  if( taker_fee_percent.valid() )
50  FC_ASSERT( *taker_fee_percent <= GRAPHENE_100_PERCENT, "Taker fee percent should not exceed 100%" );
52  FC_ASSERT( 0 == *withdrawal_fee_percent, "Withdrawal fee percent can only be updated to zero" );
53 }
54 
56 {
57  FC_ASSERT( fee.amount >= 0, "Fee should not be negative" );
58  FC_ASSERT( amount_a.amount > 0 && amount_b.amount > 0, "Both amounts of the assets should be positive" );
60  "ID of the first asset should be smaller than ID of the second asset" );
61 }
62 
64 {
65  FC_ASSERT( fee.amount >= 0, "Fee should not be negative" );
66  FC_ASSERT( share_amount.amount > 0, "Amount of the share asset should be positive" );
67 }
68 
70 {
71  FC_ASSERT( fee.amount >= 0, "Fee should not be negative" );
72  FC_ASSERT( amount_to_sell.amount > 0, "Amount to sell should be positive" );
73  FC_ASSERT( min_to_receive.amount > 0, "Minimum amount to receive should be positive" );
75  "ID of the two assets should not be the same" );
76 }
77 
78 } } // graphene::protocol
79 
86 
graphene::protocol::liquidity_pool_delete_operation::validate
void validate() const
Definition: liquidity_pool.cpp:40
graphene::protocol::liquidity_pool_update_operation::validate
void validate() const
Definition: liquidity_pool.cpp:45
graphene::protocol::liquidity_pool_create_operation::asset_a
asset_id_type asset_a
Type of the first asset in the pool.
Definition: liquidity_pool.hpp:40
graphene::protocol::liquidity_pool_deposit_operation::amount_b
asset amount_b
The amount of the second asset to deposit.
Definition: liquidity_pool.hpp:102
graphene::protocol::liquidity_pool_exchange_operation
Exchange with a liquidity pool.
Definition: liquidity_pool.hpp:138
graphene::protocol::liquidity_pool_create_operation::fee_params_t
Definition: liquidity_pool.hpp:36
graphene::protocol::liquidity_pool_withdraw_operation::fee_params_t
Definition: liquidity_pool.hpp:116
graphene::protocol::liquidity_pool_create_operation::asset_b
asset_id_type asset_b
Type of the second asset in the pool.
Definition: liquidity_pool.hpp:41
graphene::protocol::liquidity_pool_create_operation
Create a new liquidity pool.
Definition: liquidity_pool.hpp:34
graphene::protocol::liquidity_pool_update_operation::fee
asset fee
Operation fee.
Definition: liquidity_pool.hpp:78
GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION
#define GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:86
graphene::protocol::liquidity_pool_update_operation::withdrawal_fee_percent
optional< uint16_t > withdrawal_fee_percent
Withdrawal fee percent.
Definition: liquidity_pool.hpp:82
graphene::protocol::liquidity_pool_create_operation::withdrawal_fee_percent
uint16_t withdrawal_fee_percent
Withdrawal fee percent.
Definition: liquidity_pool.hpp:44
graphene::protocol::liquidity_pool_withdraw_operation
Withdraw from a liquidity pool.
Definition: liquidity_pool.hpp:114
graphene::protocol::liquidity_pool_withdraw_operation::share_amount
asset share_amount
The amount of the share asset to use.
Definition: liquidity_pool.hpp:121
graphene::protocol::liquidity_pool_delete_operation::fee
asset fee
Operation fee.
Definition: liquidity_pool.hpp:60
graphene::protocol::liquidity_pool_deposit_operation::validate
void validate() const
Definition: liquidity_pool.cpp:55
fc::optional::valid
bool valid() const
Definition: optional.hpp:186
liquidity_pool.hpp
graphene::protocol::asset::asset_id
asset_id_type asset_id
Definition: asset.hpp:37
graphene::protocol::liquidity_pool_deposit_operation
Deposit to a liquidity pool.
Definition: liquidity_pool.hpp:94
graphene::protocol::liquidity_pool_exchange_operation::fee
asset fee
Operation fee.
Definition: liquidity_pool.hpp:142
graphene::protocol::liquidity_pool_create_operation::validate
void validate() const
Definition: liquidity_pool.cpp:30
graphene::protocol::liquidity_pool_deposit_operation::fee
asset fee
Operation fee.
Definition: liquidity_pool.hpp:98
graphene::protocol::liquidity_pool_exchange_operation::min_to_receive
asset min_to_receive
The minimum amount of the other asset type to receive.
Definition: liquidity_pool.hpp:146
graphene::protocol::liquidity_pool_exchange_operation::amount_to_sell
asset amount_to_sell
The amount of one asset type to sell.
Definition: liquidity_pool.hpp:145
graphene::protocol::liquidity_pool_update_operation::taker_fee_percent
optional< uint16_t > taker_fee_percent
Taker fee percent.
Definition: liquidity_pool.hpp:81
graphene::protocol::liquidity_pool_deposit_operation::fee_params_t
Definition: liquidity_pool.hpp:96
graphene::protocol::liquidity_pool_update_operation::fee_params_t
Definition: liquidity_pool.hpp:76
FC_ASSERT
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
graphene::protocol::liquidity_pool_create_operation::fee
asset fee
Operation fee.
Definition: liquidity_pool.hpp:38
graphene::protocol::liquidity_pool_create_operation::share_asset
asset_id_type share_asset
Type of the share asset aka the LP token.
Definition: liquidity_pool.hpp:42
graphene::protocol::liquidity_pool_update_operation
Update a liquidity pool.
Definition: liquidity_pool.hpp:74
graphene::protocol::liquidity_pool_deposit_operation::amount_a
asset amount_a
The amount of the first asset to deposit.
Definition: liquidity_pool.hpp:101
graphene::protocol::asset::amount
share_type amount
Definition: asset.hpp:36
graphene::protocol::liquidity_pool_withdraw_operation::fee
asset fee
Operation fee.
Definition: liquidity_pool.hpp:118
graphene::protocol::liquidity_pool_delete_operation
Delete a liquidity pool.
Definition: liquidity_pool.hpp:56
graphene::protocol::liquidity_pool_withdraw_operation::validate
void validate() const
Definition: liquidity_pool.cpp:63
graphene::protocol::liquidity_pool_exchange_operation::validate
void validate() const
Definition: liquidity_pool.cpp:69
graphene::protocol::liquidity_pool_delete_operation::fee_params_t
Definition: liquidity_pool.hpp:58
graphene::protocol::liquidity_pool_exchange_operation::fee_params_t
Definition: liquidity_pool.hpp:140
graphene::protocol::liquidity_pool_create_operation::taker_fee_percent
uint16_t taker_fee_percent
Taker fee percent.
Definition: liquidity_pool.hpp:43
GRAPHENE_100_PERCENT
#define GRAPHENE_100_PERCENT
Definition: config.hpp:102
graphene
Definition: api.cpp:48
raw.hpp