Assessment reports>GTE -- Perp>Threat Model>_matchIncomingBid

Function: _matchIncomingBid(PerpBook ds, Order incomingOrder, bool amountIsBase)

This internal function matches an incoming taker bid order (BUY order) against available ask orders in the order book. This function iterates through existing ask orders, starting from the lowest ask price, and fills the taker’s bid as much as possible until either the bid amount is fully matched or there are no more available asks with a price less 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, totalBaseTokenReceived and totalQuoteTokenSent are zero.

  • Correct totalBaseTokenReceived and totalQuoteTokenSent are 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 bid is fully filled when the taker bid amount equals the ask.

  • The incoming bid is fully filled using multiple asks.

  • The incoming bid is partially filled when the taker bid amount is smaller than the ask. The remaining amount is returned correctly.

  • All asks are above the taker's limit price — no match.

  • Ask has the same price as the bid limit.

  • totalQuoteTokenFees is calculated correctly for one match.

  • totalQuoteTokenFees is calculated correctly for multiple matches.

Zellic © 2025Back to top ↑