31 #include <graphene/chain/hardfork.hpp>
36 namespace graphene {
namespace chain {
43 FC_ASSERT( HARDFORK_LIQUIDITY_POOL_PASSED(block_time),
"Not allowed until the LP hardfork" );
50 "Only the asset owner can set an asset as the share asset of a liquidity pool" );
53 "Can not specify a market-issued asset as the share asset of a liquidity pool" );
56 "The share asset is already bound to another liquidity pool" );
59 "Current supply of the share asset needs to be zero" );
76 result.
new_objects.insert( new_liquidity_pool_object.id );
122 FC_ASSERT( HARDFORK_CORE_2604_PASSED(block_time),
"Not allowed until the core-2604 hardfork" );
134 "Taker fee percent can only be updated if withdrawal fee percent is zero or "
135 "withdrawal fee percent is to be updated to zero at the same time" );
172 FC_ASSERT( share_asset_obj.
issuer == op.
account,
"The initial deposit can only be done by the pool owner" );
175 _share_asset_dyn_data = &share_asset_obj.
dynamic_data(d);
180 "Can not create new supply for the share asset" );
183 "The account is unauthorized by the share asset" );
185 "The account is unauthorized by asset A" );
187 "The account is unauthorized by asset B" );
193 "For initial deposit, each amount of the two assets in the pool should not be greater than "
194 "the maximum supply of the share asset" );
202 fc::uint128_t max128( max_new_supply.
value );
206 fc::uint128_t new_supply = std::min( { new_supply_if_a, new_supply_if_b, max128 } );
208 FC_ASSERT( new_supply > 0,
"Aborting due to zero outcome" );
210 fc::uint128_t a128 = ( new_supply * _pool->
balance_a.
value + supply128 - 1 ) / supply128;
212 _pool_receives_a =
asset(
static_cast<int64_t
>( a128 ), _pool->
asset_a );
214 fc::uint128_t b128 = ( new_supply * _pool->
balance_b.
value + supply128 - 1 ) / supply128;
216 _pool_receives_b =
asset(
static_cast<int64_t
>( b128 ), _pool->
asset_b );
218 _account_receives =
asset(
static_cast<int64_t
>( new_supply ), _pool->
share_asset );
247 result.
paid.emplace_back( _pool_receives_a );
248 result.
paid.emplace_back( _pool_receives_b );
249 result.
received.emplace_back( _account_receives );
267 "The account is unauthorized by the share asset" );
269 "The account is unauthorized by asset A" );
271 "The account is unauthorized by asset B" );
273 _share_asset_dyn_data = &share_asset_obj.
dynamic_data(d);
276 "Can not withdraw an amount that is more than the current supply" );
291 FC_ASSERT( fee_a <= a128,
"Withdrawal fee percent of the pool is too high" );
296 FC_ASSERT( fee_b <= b128,
"Withdrawal fee percent of the pool is too high" );
298 FC_ASSERT( a128 > 0 || b128 > 0,
"Aborting due to zero outcome" );
299 _pool_pays_a =
asset(
static_cast<int64_t
>( a128 ), _pool->
asset_a );
300 _pool_pays_b =
asset(
static_cast<int64_t
>( b128 ), _pool->
asset_b );
301 _fee_a =
asset(
static_cast<int64_t
>( fee_a ), _pool->
asset_a );
302 _fee_b =
asset(
static_cast<int64_t
>( fee_b ), _pool->
asset_b );
316 if( _pool_pays_a.
amount > 0 )
318 if( _pool_pays_b.
amount > 0 )
335 result.
received.emplace_back( _pool_pays_a );
336 result.
received.emplace_back( _pool_pays_b );
337 result.
fees.emplace_back( _fee_a );
338 result.
fees.emplace_back( _fee_b );
353 "Asset type mismatch" );
358 "The account is unauthorized by asset A" );
362 "The account is unauthorized by asset B" );
370 "The ${a}:${b} market has not been whitelisted by asset ${a}",
377 "The ${a}:${b} market has been blacklisted by asset ${a}",
384 "The ${a}:${b} market has not been whitelisted by asset ${b}",
391 "The ${a}:${b} market has been blacklisted by asset ${b}",
400 "Aborting since the maker market fee of the selling asset is too high" );
409 FC_ASSERT( new_balance_b <= _pool->balance_b,
"Internal error" );
411 _pool_pays_asset = &asset_obj_b;
418 FC_ASSERT( new_balance_a <= _pool->balance_a,
"Internal error" );
420 _pool_pays_asset = &asset_obj_a;
424 FC_ASSERT( pool_taker_fee <= delta,
"Taker fee percent of the pool is too high" );
429 FC_ASSERT( _taker_market_fee <= _pool_pays,
"Market fee should not be greater than the amount to receive" );
430 _account_receives = _pool_pays - _taker_market_fee;
433 liquidity_pool_exchange_unfillable_price,
434 "Unable to exchange at expected price" );
480 result.
received.emplace_back( _account_receives );
481 result.
fees.emplace_back( _maker_market_fee );
482 result.
fees.emplace_back( _taker_market_fee );
483 result.
fees.emplace_back( _pool_taker_fee );