Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 55 additions & 39 deletions libraries/chain/base_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>( [&]( 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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot assign o here. Did you mean 0?

amount_to_issue.amount.asset_id = MBD_SYMBOL; //making sure it's the new MBD asset id for safety
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this even compile? I think the amount. is too much. Same in following lines.

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a possible way to do it. However,

  • it is confusing because now for some assets you have to specify the amount you want to have converted, and for some you have to specify the amount to receive from the conversion
  • you cannot also add conversion of BTCM->MUSE nor BTCM->VESTS

{
const asset amount_to_issue = o;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean o.amount?

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>( [&]( 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 )
{
Expand Down
10 changes: 6 additions & 4 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do that. This will retroactively change MBD_SYMBOL, which means that you cannot replay the existing blockchain. What you can do is add a new XUSD_SYMBOL, and change the code to use XUSD_SYMBOL or MBD_SYMBOL depending on whether it's before or after the consensus upgrade.

Also, you shouldn't use fixed IDs here. The 3 base assets are created by the core code automatically and therefore have known IDs, but anything after these will be assigned an ID upon creation. One way to deal with this could be to register the assets manually both in testnet and in mainnet, and then insert the resulting IDs into the codebase (which will likely be different between mainnet and testnet).

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);
Expand Down Expand Up @@ -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()
Expand All @@ -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 ) );

Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/get_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions libraries/chain/include/muse/chain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above: you cannot simply change this because the change would happen retroactively. You can define a new interval, and use one or the other depending on whether it happens before or after the upgrade.

#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
Expand Down
3 changes: 2 additions & 1 deletion libraries/chain/protocol/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down