Function: _matchIncomingAsk(PerpBook ds, Order incomingOrder, bool amountIsBase)
This internal function matches an incoming taker ask order (SELL order) against existing bid orders in the order book. The function walks through available bids starting from the highest bid price, ensuring that the ask fills at the best possible prices for the seller.
It continues matching until the ask amount is fully matched or there are no more available bids with a price greater than or equal to incomingOrder.price.
Branches and code coverage
Intended branches
The order book is empty, there is no match, and as a result,
totalQuoteTokenReceivedandtotalBaseTokenSentare zero.Correct
totalQuoteTokenReceivedandtotalBaseTokenSentare calculated across multiple matches.The order book contains only one expired order. The expired order is removed without reverting.
The order book contains only one eligible order with minimum amount.
The incoming ask is fully filled when the taker ask amount equals the bid.
The incoming ask is fully filled using multiple bids.
The incoming ask is partially filled when the taker ask amount is smaller than the bid. The remaining amount is returned correctly.
All bids are lower the taker's limit price — no match.
The incoming ask has the same price as the bid limit.
totalTakerFeeInQuoteis calculated correctly for one match.totalTakerFeeInQuoteis calculated correctly for multiple matches.