Evoq Finance
  • introduction
    • Evoq Finance: A P2P-Based Lending Optimizer
  • background
    • Problem: Capital Inefficiency
  • protocol overview
    • How it works
      • Fallback Mechanism
      • Interest Rate Model
      • Cap Mechanism
    • Liquidation
    • Price Oracle
    • Risk Fund
  • advanced mechanism
    • Matching Engine
      • Priority Queue Matching
      • Max Gas Limit
    • Delta Mechanism
  • security
    • General Risks
      • Flash Loan Attack
      • Front-Running Attack
    • Audits
  • Technical
    • Overview
      • Evoq
      • WBNBGateway
      • Lens
      • Contract Deployments
    • Liquidation Bot
  • GETTING STARTED
    • User Guide
    • FAQ
  • Links
    • Launch App
    • Community
Powered by GitBook
On this page
  1. advanced mechanism
  2. Matching Engine

Priority Queue Matching

PreviousMatching EngineNextMax Gas Limit

Last updated 4 months ago

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.

Example: Priority queue matching