Merge branch 'master' of github.com:cryptonomex/graphene
This commit is contained in:
commit
5adb85cde9
2 changed files with 36 additions and 18 deletions
|
|
@ -158,6 +158,8 @@ bool database::check_for_blackswan( const asset_object& mia, bool enable_black_s
|
|||
|
||||
const asset_bitasset_data_object& bitasset = mia.bitasset_data(*this);
|
||||
if( bitasset.has_settlement() ) return true; // already force settled
|
||||
auto settle_price = bitasset.current_feed.settlement_price;
|
||||
if( settle_price.is_null() ) return false; // no feed
|
||||
|
||||
const call_order_index& call_index = get_index_type<call_order_index>();
|
||||
const auto& call_price_index = call_index.indices().get<by_price>();
|
||||
|
|
@ -180,10 +182,7 @@ bool database::check_for_blackswan( const asset_object& mia, bool enable_black_s
|
|||
auto call_itr = call_price_index.lower_bound( call_min );
|
||||
auto call_end = call_price_index.upper_bound( call_max );
|
||||
|
||||
auto settle_price = bitasset.current_feed.settlement_price;
|
||||
|
||||
if( settle_price.is_null() ) return false; /// no feed;
|
||||
if( call_itr == call_end ) return false; /// no call orders
|
||||
if( call_itr == call_end ) return false; // no call orders
|
||||
|
||||
price highest = settle_price;
|
||||
if( limit_itr != limit_end ) {
|
||||
|
|
|
|||
|
|
@ -317,6 +317,7 @@ BOOST_AUTO_TEST_CASE( black_swan_issue_346 )
|
|||
{
|
||||
price_feed feed;
|
||||
feed.settlement_price = settlement_price;
|
||||
wdump( (feed.max_short_squeeze_price()) );
|
||||
publish_feed( bitusd, feeder, feed );
|
||||
};
|
||||
|
||||
|
|
@ -332,22 +333,40 @@ BOOST_AUTO_TEST_CASE( black_swan_issue_346 )
|
|||
BOOST_CHECK( idx.empty() );
|
||||
};
|
||||
|
||||
const asset_object& bitusd = setup_asset();
|
||||
top_up();
|
||||
set_price( bitusd, bitusd.amount(1) / core.amount(5) ); // $0.20
|
||||
borrow(borrower, bitusd.amount(100), asset(1000)); // 2x collat
|
||||
transfer( borrower, settler, bitusd.amount(100) );
|
||||
{
|
||||
const asset_object& bitusd = setup_asset();
|
||||
top_up();
|
||||
set_price( bitusd, bitusd.amount(1) / core.amount(5) ); // $0.20
|
||||
borrow(borrower, bitusd.amount(100), asset(1000)); // 2x collat
|
||||
transfer( borrower, settler, bitusd.amount(100) );
|
||||
|
||||
// drop to $0.02 and settle
|
||||
BOOST_CHECK( !bitusd.bitasset_data(db).has_settlement() );
|
||||
set_price( bitusd, bitusd.amount(1) / core.amount(50) );
|
||||
BOOST_CHECK( bitusd.bitasset_data(db).has_settlement() );
|
||||
GRAPHENE_REQUIRE_THROW( borrow( borrower2, bitusd.amount(100), asset(10000) ), fc::exception );
|
||||
force_settle( settler, bitusd.amount(100) );
|
||||
// drop to $0.02 and settle
|
||||
BOOST_CHECK( !bitusd.bitasset_data(db).has_settlement() );
|
||||
set_price( bitusd, bitusd.amount(1) / core.amount(50) ); // $0.02
|
||||
BOOST_CHECK( bitusd.bitasset_data(db).has_settlement() );
|
||||
GRAPHENE_REQUIRE_THROW( borrow( borrower2, bitusd.amount(100), asset(10000) ), fc::exception );
|
||||
force_settle( settler, bitusd.amount(100) );
|
||||
|
||||
// wait for forced settlement to execute
|
||||
// this would throw on Sep.18 testnet, see #346
|
||||
wait_for_settlement();
|
||||
// wait for forced settlement to execute
|
||||
// this would throw on Sep.18 testnet, see #346
|
||||
wait_for_settlement();
|
||||
}
|
||||
|
||||
// issue 350
|
||||
{
|
||||
// ok, new asset
|
||||
const asset_object& bitusd = setup_asset();
|
||||
top_up();
|
||||
set_price( bitusd, bitusd.amount(40) / core.amount(1000) ); // $0.04
|
||||
borrow( borrower, bitusd.amount(100), asset(5000) ); // 2x collat
|
||||
transfer( borrower, seller, bitusd.amount(100) );
|
||||
limit_order_id_type oid_019 = create_sell_order( seller, bitusd.amount(39), core.amount(2000) )->id; // this order is at $0.019, we should not be able to match against it
|
||||
limit_order_id_type oid_020 = create_sell_order( seller, bitusd.amount(40), core.amount(2000) )->id; // this order is at $0.020, we should be able to match against it
|
||||
set_price( bitusd, bitusd.amount(21) / core.amount(1000) ); // $0.021
|
||||
BOOST_CHECK( !bitusd.bitasset_data(db).has_settlement() );
|
||||
BOOST_CHECK( db.find_object( oid_019 ) != nullptr );
|
||||
BOOST_CHECK( db.find_object( oid_020 ) == nullptr );
|
||||
}
|
||||
|
||||
} catch( const fc::exception& e) {
|
||||
edump((e.to_detail_string()));
|
||||
|
|
|
|||
Loading…
Reference in a new issue