diff --git a/libraries/chain/base_evaluator.cpp b/libraries/chain/base_evaluator.cpp index c2f5650..aed4919 100644 --- a/libraries/chain/base_evaluator.cpp +++ b/libraries/chain/base_evaluator.cpp @@ -555,45 +555,61 @@ void feed_publish_evaluator::do_apply( const feed_publish_operation& o ) } void convert_evaluator::do_apply( const convert_operation& o ) -{ - if( o.amount.asset_id == MUSE_SYMBOL ) - FC_ASSERT( db().has_hardfork( MUSE_HARDFORK_0_6 ), "XSD -> xUSD conversion only allowed after hardfork 6!" ); - - const auto& owner = db().get_account( o.owner ); - FC_ASSERT( db().get_balance( owner, o.amount.asset_id ) >= o.amount ); - - db().adjust_balance( owner, -o.amount ); - - const auto& fhistory = db().get_feed_history(); - FC_ASSERT( !fhistory.effective_median_history.is_null() ); - - if( o.amount.asset_id == MUSE_SYMBOL ) - { - const asset amount_to_issue = o.amount * fhistory.effective_median_history; - - db().adjust_balance( owner, amount_to_issue ); - - db().push_applied_operation( fill_convert_request_operation ( o.owner, o.requestid, o.amount, amount_to_issue ) ); - - db().modify( db().get_dynamic_global_properties(), - [&o,&amount_to_issue,&fhistory]( dynamic_global_property_object& p ) - { - p.current_supply -= o.amount; - p.current_mbd_supply += amount_to_issue; - p.virtual_supply -= o.amount; - p.virtual_supply += amount_to_issue * fhistory.effective_median_history; - } ); - } - else - db().create( [&]( convert_request_object& obj ) - { - obj.owner = o.owner; - obj.requestid = o.requestid; - obj.amount = o.amount; - obj.conversion_date = db().head_block_time() + MUSE_CONVERSION_DELAY; // 1 week - }); - -} + { + if( o.amount.asset_id == MUSE_SYMBOL || BTCM_SYMBOL ) + FC_ASSERT( db().has_hardfork( MUSE_HARDFORK_0_6 ), "XSD -> xUSD & XSD -> BTCM conversion only allowed after hardfork 6!" ); + + const auto& owner = db().get_account( o.owner ); + + if( o.amount.asset_id == MBD_SYMBOL ) { + FC_ASSERT( db().get_balance( owner, o.amount.asset_id ) >= o.amount ); + db().adjust_balance( owner, -o.amount );} + + const auto& fhistory = db().get_feed_history(); + FC_ASSERT( !fhistory.effective_median_history.is_null() ); + + if( o.amount.asset_id == MUSE_SYMBOL ) + { + const asset amount_to_issue = o.amount * fhistory.effective_median_history; + const asset amount_to_subtract = o; + amount_to_issue.amount.asset_id = MBD_SYMBOL; //making sure it's the new MBD asset id for safety + amount_to_subtract.amount.asset_id = BTCM_SYMBOL; //converts 1 USD worth of BTCM to MBD + FC_ASSERT( db().get_balance( owner, amount_to_subtract.amount.asset_id ) >= amount_to_subtract.amount ); + db().adjust_balance( owner, -amount_to_subtract.amount );} + db().adjust_balance( owner, amount_to_issue ); + + db().push_applied_operation( fill_convert_request_operation ( o.owner, o.requestid, amount_to_subtract.amount, amount_to_issue ) ); + + db().modify( db().get_dynamic_global_properties(), + [&o,&amount_to_issue,&fhistory]( dynamic_global_property_object& p ) + { + p.current_supply -= o.amount; + p.current_mbd_supply += amount_to_issue; + p.virtual_supply -= o.amount; + p.virtual_supply += amount_to_issue * fhistory.effective_median_history; + } ); + } + else if( o.amount.asset_id == BTCM_SYMBOL ) //this operation will convert MUSE into BTCM + { + const asset amount_to_issue = o; + const asset amount_to_subtract = o; + amount_to_subract.amount.asset_id = MUSE_SYMBOL; + FC_ASSERT( db().get_balance( owner, amount_to_subtract.amount.asset_id ) >= amount_to_subtract.amount ); + db().adjust_balance( owner, -amount_to_subtract.amount ); + db().adjust_balance( owner, amount_to_issue.amount ); + + db().push_applied_operation( fill_convert_request_operation ( o.owner, o.requestid, amount_to_subtract.amount, amount_to_issue ) ); //no supply updates are required + } + else + db().create( [&]( convert_request_object& obj ) + { + obj.owner = o.owner; + obj.requestid = o.requestid; + obj.amount = o.amount; + obj.conversion_date = db().head_block_time() + MUSE_CONVERSION_DELAY; // 1 week + }); + + } void limit_order_create_evaluator::do_apply( const limit_order_create_operation& o ) { diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 103bbf9..a0b24f5 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -64,8 +64,8 @@ const uint8_t streaming_platform_object::type_id; muse::chain::asset_id_type MUSE_SYMBOL=(muse::chain::asset_id_type(0)); muse::chain::asset_id_type VESTS_SYMBOL=(muse::chain::asset_id_type(1)); -muse::chain::asset_id_type MBD_SYMBOL=(muse::chain::asset_id_type(2)); - +muse::chain::asset_id_type MBD_SYMBOL=(muse::chain::asset_id_type(13)); //changing MBD id from 2 to 13 +muse::chain::asset_id_type BTCM_SYMBOL=(muse::chain::asset_id_type(11)); //declaring BTCM as asset id 11 inline u256 to256( const fc::uint128& t ) { u256 v(t.hi); @@ -2156,7 +2156,7 @@ asset database::get_producer_reward() /** * Iterates over all conversion requests with a conversion date before - * the head block time and then converts them to/from muse/mbd at the + * the head block time and then converts them to/from BTCM/mbd at the * current median price feed history price times the premium */ void database::process_conversions() @@ -2176,11 +2176,13 @@ void database::process_conversions() { const auto& user = get_account( itr->owner ); auto amount_to_issue = itr->amount * fhistory.effective_median_history; + amount_to_issue.amount.asset_id = BTCM_SYMBOL; //the asset issued is modified to BTCM instead of MUSE + adjust_balance( user, amount_to_issue ); net_mbd += itr->amount; - net_muse += amount_to_issue; + net_muse += amount_to_issue; //the total supply still needs to be added as BTCM is considered as an additional base asset push_applied_operation( fill_convert_request_operation ( user.name, itr->requestid, itr->amount, amount_to_issue ) ); diff --git a/libraries/chain/get_config.cpp b/libraries/chain/get_config.cpp index 1e0be0a..1df5800 100644 --- a/libraries/chain/get_config.cpp +++ b/libraries/chain/get_config.cpp @@ -111,7 +111,7 @@ fc::variant_object get_config() result["MUSE_VOTE_REGENERATION_SECONDS"] = MUSE_VOTE_REGENERATION_SECONDS; result["MUSE_SYMBOL"] = MUSE_SYMBOL; result["VESTS_SYMBOL"] = VESTS_SYMBOL; - + result["BTCM_SYMBOL"] = BTCM_SYMBOL; return result; } diff --git a/libraries/chain/include/muse/chain/config.hpp b/libraries/chain/include/muse/chain/config.hpp index f6fe321..7ee347b 100644 --- a/libraries/chain/include/muse/chain/config.hpp +++ b/libraries/chain/include/muse/chain/config.hpp @@ -55,8 +55,8 @@ #define MUSE_ADDRESS_PREFIX "MUSE" #define MUSE_SYMBOL_STRING (BASE_SYMBOL) #define VESTS_SYMBOL_STRING "VESTS" -#define MBD_SYMBOL_STRING "MBD" - +#define MBD_SYMBOL_STRING "XUSD" //Changing the stablecoin asset from MBD to XUSD +#define BTCM_SYMBOL_STRING "BTCM" //New base asset of Bitcoin Music #define NULL_SYMBOL (uint64_t(3) ) #define MUSE_GENESIS_TIME (fc::time_point_sec(1458835200)) @@ -92,7 +92,7 @@ #define MUSE_MAX_TIME_UNTIL_EXPIRATION (60*60) // seconds, aka: 1 hour #define MUSE_MAX_MEMO_SIZE 2048 #define MUSE_MAX_PROXY_RECURSION_DEPTH 4 -#define MUSE_VESTING_WITHDRAW_INTERVALS 13 +#define MUSE_VESTING_WITHDRAW_INTERVALS 4 //changing vesting period from 13 weeks to 4 weeks #define MUSE_VESTING_WITHDRAW_INTERVAL_SECONDS (60*60*24*7) /// 1 week per interval #define MUSE_MAX_WITHDRAW_ROUTES 10 #define MUSE_VOTE_REGENERATION_SECONDS (5*60*60*24) // 5 day diff --git a/libraries/chain/protocol/types.cpp b/libraries/chain/protocol/types.cpp index 6d0949a..3b41a1c 100644 --- a/libraries/chain/protocol/types.cpp +++ b/libraries/chain/protocol/types.cpp @@ -181,7 +181,8 @@ using namespace muse::chain; asset_id_type MUSE_SYMBOL(0); asset_id_type VESTS_SYMBOL(1); -asset_id_type MBD_SYMBOL(2); +asset_id_type MBD_SYMBOL(13); //changing asset id to 13, representing xUSD +asset_id_type BTCM_SYMBOL(11); //declaring BTCM as id 11 namespace fc {