diff --git a/libraries/chain/asset.cpp b/libraries/chain/asset.cpp index daff0964..36963571 100644 --- a/libraries/chain/asset.cpp +++ b/libraries/chain/asset.cpp @@ -121,26 +121,9 @@ namespace graphene { namespace chain { { try { //wdump((debt)(collateral)(collateral_ratio)); boost::rational swan(debt.amount.value,collateral.amount.value); - boost::rational ratio( collateral_ratio, 1000 ); + boost::rational ratio( collateral_ratio, GRAPHENE_COLLATERAL_RATIO_DENOM ); auto cp = swan * ratio; return ~(asset( cp.numerator(), debt.asset_id ) / asset( cp.denominator(), collateral.asset_id )); - - /* - while( collateral.amount < 100000 && debt.amount < GRAPHENE_MAX_SHARE_SUPPLY/100 ) - { - collateral.amount *= 1000; - debt.amount *= 1000; - } - - fc::uint128 tmp( collateral.amount.value ); - tmp *= 1000; - tmp /= collateral_ratio; - FC_ASSERT( tmp <= GRAPHENE_MAX_SHARE_SUPPLY ); - asset col( tmp.to_uint64(), collateral.asset_id); - - if( col.amount == 0 ) col.amount = 1; - return col / debt; - */ } FC_CAPTURE_AND_RETHROW( (debt)(collateral)(collateral_ratio) ) } bool price::is_null() const { return *this == price(); } @@ -166,35 +149,9 @@ namespace graphene { namespace chain { price price_feed::max_short_squeeze_price()const { boost::rational sp( settlement_price.base.amount.value, settlement_price.quote.amount.value ); //debt.amount.value,collateral.amount.value); - boost::rational ratio( 1000, maximum_short_squeeze_ratio ); + boost::rational ratio( GRAPHENE_COLLATERAL_RATIO_DENOM, maximum_short_squeeze_ratio ); auto cp = sp * ratio; return (asset( cp.numerator(), settlement_price.base.asset_id ) / asset( cp.denominator(), settlement_price.quote.asset_id )); - - /* - asset collateral = settlement_price.quote; - fc::uint128 tmp( collateral.amount.value ); - tmp *= maximum_short_squeeze_ratio; - tmp /= 1000; - FC_ASSERT( tmp <= GRAPHENE_MAX_SHARE_SUPPLY ); - collateral.amount = tmp.to_uint64(); - auto tmp2 = settlement_price.base / collateral; - wdump((rtn)(tmp2)); - return rtn; - */ - } - /* - price price_feed::maintenance_price()const - { - asset collateral = settlement_price.quote; - fc::uint128 tmp( collateral.amount.value ); - tmp *= maintenance_collateral_ratio; - tmp /= 1000; - FC_ASSERT( tmp <= GRAPHENE_MAX_SHARE_SUPPLY ); - collateral.amount = tmp.to_uint64(); - return settlement_price.base / collateral; - } - */ - } } // graphene::chain diff --git a/libraries/chain/include/graphene/chain/asset.hpp b/libraries/chain/include/graphene/chain/asset.hpp index b306833f..697099a8 100644 --- a/libraries/chain/include/graphene/chain/asset.hpp +++ b/libraries/chain/include/graphene/chain/asset.hpp @@ -128,7 +128,7 @@ namespace graphene { namespace chain { /** * Required maintenance collateral is defined * as a fixed point number with a maximum value of 10.000 - * and a minimum value of 1.000. (denominated in 1000) + * and a minimum value of 1.000. (denominated in GRAPHENE_COLLATERAL_RATIO_DENOM) * * A black swan event occurs when value_of_collateral equals * value_of_debt, to avoid a black swan a margin call is @@ -145,10 +145,10 @@ namespace graphene { namespace chain { */ price settlement_price; - /** Fixed point between 1.000 and 10.000, implied fixed point denominator is 1000 */ + /** Fixed point between 1.000 and 10.000, implied fixed point denominator is GRAPHENE_COLLATERAL_RATIO_DENOM */ uint16_t maintenance_collateral_ratio = GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO; - /** Fixed point between 1.000 and 10.000, implied fixed point denominator is 1000 */ + /** Fixed point between 1.000 and 10.000, implied fixed point denominator is GRAPHENE_COLLATERAL_RATIO_DENOM */ uint16_t maximum_short_squeeze_ratio = GRAPHENE_DEFAULT_MAX_SHORT_SQUEEZE_RATIO; /** diff --git a/libraries/chain/include/graphene/chain/config.hpp b/libraries/chain/include/graphene/chain/config.hpp index 2aa1b1ab..75da2610 100644 --- a/libraries/chain/include/graphene/chain/config.hpp +++ b/libraries/chain/include/graphene/chain/config.hpp @@ -63,11 +63,12 @@ #define GRAPHENE_DEFAULT_MAX_ASSET_FEED_PUBLISHERS 10 /** - * These ratios are fixed point numbers with a denominator of 1000, the + * These ratios are fixed point numbers with a denominator of GRAPHENE_COLLATERAL_RATIO_DENOM, the * minimum maitenance collateral is therefore 1.001x and the default * maintenance ratio is 1.75x */ ///@{ +#define GRAPHENE_COLLATERAL_RATIO_DENOM 1000 #define GRAPHENE_MIN_COLLATERAL_RATIO 1001 ///< lower than this could result in divide by 0 #define GRAPHENE_MAX_COLLATERAL_RATIO 32000 ///< higher than this is unnecessary and may exceed int16 storage #define GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO 1750 ///< Call when collateral only pays off 175% the debt