Priority Queue Matching

While a queueing model could be used, it could be exploited by numerous accounts supplying tiny amounts, causing high gas costs for borrowers. Instead, we use a priority queue matching system that sorts users by descending volume, ensuring that higher volumes are matched first. For each new request, the protocol arranges the top 8 opposite requests by volume to respond. Below is an example.

  1. The initial state: Supply 1 is 800 USDC, supply 2 is 1000 USDC, and supply 3 is 500 USDC.

  2. When borrow 4 is requested, the priority goes to supply 2.

  3. After matching order 1, supply 1 remains at 800 USDC, supply 2 at 600 USDC, and supply 3 at 500 USDC.

  4. Thus, for borrow 5, the next priority is supply 1.

  5. After matching order 2, supply 1 is 300 USDC, supply 2 is 600 USDC, and supply 3 is 500 USDC.

  6. Hence, for borrow 6, the next priority is supply 2.

  7. Then, matching order 3 is processed.

  8. Unmatched amounts of supply 1 (300 USDC) and supply 3 (500 USDC) fall back to the underlying protocol.

Last updated