Orders are created by accounts and executed at a later stage by off-chain keepers. The price at which the order is executed is based on the latest market conditions and current total positions in the market. This means that the order can be executed at an arbitrary fill price and the creator has no way to define min/max thresholds at which it will get executed, leading to losses.
When an order is created through OrderBranch.createMarketOrder()
the caller provides the following parameters:
Once an order is created subsequently an off-chain keeper picks it up and calls SettlementBranch.fillMarketOrder()
to execute it, providing a price from an offline oracle:
The off-chain price is used to calculate the final fillPrice
in perpMarket.getMarkPrice()
, which is based on the current conditions in the market - more specifically how the skew was changed by every trade before that and how the current trade changes it.
The problem with this is on a couple of levels:
the off-chain price might be disadvantageous to the user - it will be a valid price between the configured thresholds, but based on the positions an account has taken it might not be a price that is acceptable by the user
the execution of the fillMarketOrder
might happen too late in time when market conditions have changed significantly compared to when the account was creating the order
the fillMarketOrder
could get executed after a longer time at different market conditions due to unforeseen reasons, not in favour of the account that created the order.
MarketOrders
can get executed at disadvantageous price levels than the accounts anticipated when orders were created.
Manual Review
Add min/maxFillPrice
fields to the CreateMarketOrderParams
struct, so that the account can guarantee the order will get executed at the price levels he expects.
Also consider adding a deadline parameter, that prevents stale transactions from executing.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.