Skip to content

Commit 1c81eaf

Browse files
Progress bitshares#1604: Add dust check
Add dust check to limit order update logic, and test
1 parent 8da1f72 commit 1c81eaf

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

libraries/chain/market_evaluator.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,17 @@ void_result limit_order_update_evaluator::do_evaluate(const limit_order_update_o
163163
"Cannot deduct more from order than order contains");
164164
}
165165

166+
// Check dust
167+
if (o.new_price || (o.delta_amount_to_sell && o.delta_amount_to_sell->amount < 0)) {
168+
auto new_price = o.new_price? *o.new_price : _order->sell_price;
169+
auto new_amount = _order->amount_for_sale();
170+
if (o.delta_amount_to_sell)
171+
new_amount += *o.delta_amount_to_sell;
172+
auto new_amount_to_receive = new_amount * new_price;
173+
174+
FC_ASSERT(new_amount_to_receive.amount > 0, "Cannot update limit order: order becomes too small; cancel order instead");
175+
}
176+
166177
// Check expiration is in the future
167178
if (o.new_expiration)
168179
FC_ASSERT(*o.new_expiration >= d.head_block_time(),

tests/tests/operation_tests.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,27 @@ BOOST_AUTO_TEST_CASE(limit_order_update_test)
172172
}
173173
}
174174

175+
BOOST_AUTO_TEST_CASE(limit_order_update_dust_test)
176+
{
177+
try {
178+
ACTORS((nathan));
179+
const auto& munee = create_user_issued_asset("MUNEE");
180+
181+
transfer(committee_account, nathan_id, asset(10000));
182+
issue_uia(nathan, munee.amount(1000));
183+
184+
auto expiration = db.head_block_time() + 1000;
185+
limit_order_id_type order_id = create_sell_order(nathan, asset(1000), munee.amount(100), expiration)->id;
186+
187+
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, asset(-995)), fc::assert_exception);
188+
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, price(asset(1000000), munee.amount(100))), fc::assert_exception);
189+
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, price(asset(2000), munee.amount(100)), asset(-985)), fc::assert_exception);
190+
} catch (fc::exception& e) {
191+
edump((e.to_detail_string()));
192+
throw;
193+
}
194+
}
195+
175196
BOOST_AUTO_TEST_CASE(limit_order_update_match_test)
176197
{
177198
try {

0 commit comments

Comments
 (0)