Priority Queue Matching
Last updated
Last updated
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.
The initial state: Supply 1 is 800 USDC, supply 2 is 1000 USDC, and supply 3 is 500 USDC.
When borrow 4 is requested, the priority goes to supply 2.
After matching order 1, supply 1 remains at 800 USDC, supply 2 at 600 USDC, and supply 3 at 500 USDC.
Thus, for borrow 5, the next priority is supply 1.
After matching order 2, supply 1 is 300 USDC, supply 2 is 600 USDC, and supply 3 is 500 USDC.
Hence, for borrow 6, the next priority is supply 2.
Then, matching order 3 is processed.
Unmatched amounts of supply 1 (300 USDC) and supply 3 (500 USDC) fall back to the underlying protocol.