The current implementation of the order filling logic contains an error that impacts the execution of trades. The comments correctly state the desired behavior for filling orders based on the type of trade (buy or sell). However, the logic implemented does not match this intended behavior, leading to potential issues for traders trying to fill their orders.
The current logic incorrectly implements the intended behavior:
For a buy order (ctx.isBuyOrder is true), the condition checks if the targetPrice is less than or equal to the fillPrice, which is the opposite of the intended behavior.
For a sell order (ctx.isBuyOrder is false), the condition checks if the targetPrice is greater than or equal to the fillPrice, which is also the opposite of the intended behavior.
Current Logic: The current implementation only fills orders if the targetPrice is less than or equal to the fillPrice. This condition causes several issues for traders:
Unfilled Orders: Traders' orders will frequently not be filled as they intended. This is because the logic incorrectly skips orders where the trader sets the targetPrice to be greater than or equal to the fillPrice.
Potential Losses: Even if a trader sets the targetPrice to be less than or equal to the fillPrice, the trade is likely to incur losses. This is contrary to the expected trading behavior, where a buy order should only be filled at a price less than or equal to the target price, and a sell order should be filled at a price greater than or equal to the target price.
By correcting the logic, we can ensure that:
Buy orders are filled only when the fillPrice is less than or equal to the targetPrice.
Sell orders are filled only when the fillPrice is greater than or equal to the targetPrice.
The logic in the SettlementBranch::filloffchainOrders()can be implemented as such
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.