The function createMarketOrder
should implement a price target protection just as fillOffchainOrders
does
When a user creates a market order onchain, the price that will be used to compute if the order is allowed will be using the index price of a Chainlink price feed. But when this order will be actually executed, the bid and ask price will be used instead which can vary significantly from the price that the user expected when he created the market order.
Looking into the fillOffchainOrders
implementation, the user does not initiate the order onchain, he just signs a bunch of data that will be gathered by a keeper and will execute the following function:
As we can see, the user signs a field in the data that is the targetPrice
. This price is used to set a maximum price that the user is willing to accept when he is buying or the minimum price that the user is going to accept when he is selling. So basically there is a security check for the user to not get an order with a non acceptable price.
However, when a user creates a market order onchain, he will not have this price protection and can get his order executed with a price that he did not expect.
Medium
Manual review
I would implement the same price protection when creating the market order onchain
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.