Skip to content
This repository has been archived by the owner on Feb 21, 2019. It is now read-only.

Commit

Permalink
Only cancel high APR shorts on hardfork
Browse files Browse the repository at this point in the history
  • Loading branch information
vikramrajkumar committed Mar 23, 2015
1 parent 0386f83 commit 64cb2f6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libraries/blockchain/chain_database_v1.cpp
Expand Up @@ -78,7 +78,7 @@ void chain_database_impl::execute_markets_v1( const fc::time_point_sec timestamp
else if( pending_block_num == BTS_SHORTFIX_FORK_BLOCK_NUM )
{
market_engine_v7 engine( pending_state, *this );
engine.cancel_all_shorts();
engine.cancel_high_apr_shorts();
market_transactions.insert( market_transactions.end(), engine._market_transactions.begin(), engine._market_transactions.end() );
}

Expand Down
Expand Up @@ -11,6 +11,8 @@ namespace bts { namespace blockchain { namespace detail {

void cancel_all_shorts();

void cancel_high_apr_shorts();

static asset get_interest_paid_fixed(const asset& total_amount_paid, const price& apr, uint32_t age_seconds);
static asset get_interest_owed_fixed(const asset& principle, const price& apr, uint32_t age_seconds);

Expand Down
25 changes: 25 additions & 0 deletions libraries/blockchain/market_engine_v7.cpp
Expand Up @@ -34,6 +34,31 @@ namespace bts { namespace blockchain { namespace detail {
_pending_state->apply_changes();
}

void market_engine_v7::cancel_high_apr_shorts()
{
static fc::uint128 max_apr = fc::uint128( BTS_BLOCKCHAIN_MAX_SHORT_APR_PCT ) * FC_REAL128_PRECISION / 100;

for( auto short_itr = _db_impl._short_db.begin(); short_itr.valid(); ++short_itr )
{
const market_index_key market_idx = short_itr.key();
if( market_idx.order_price.ratio <= max_apr )
continue;

const order_record order_rec = short_itr.value();
_current_bid = market_order( short_order, market_idx, order_rec, order_rec.balance, market_idx.order_price );

// Initialize the market transaction
market_transaction mtrx;
mtrx.bid_owner = _current_bid->get_owner();
mtrx.bid_type = short_order;

cancel_current_short( mtrx, market_idx.order_price.quote_asset_id );
push_market_transaction( mtrx );
}

_pending_state->apply_changes();
}

bool market_engine_v7::execute( asset_id_type quote_id, asset_id_type base_id, const fc::time_point_sec timestamp )
{
try
Expand Down

0 comments on commit 64cb2f6

Please sign in to comment.