
How the Matching Engine Works
Paystream’s matching engine can be viewed as a priority queue or a pseudo-order book for matching loans. However, unlike a traditional order book, users do not place bids or asks with specific interest rates. Instead, the protocol automatically determines a fair P2P interest rate (one that lies between the pool’s supply APY and borrow APY) and matches lenders to borrowers at that rate. This means lenders and borrowers don’t negotiate rates; any available lending liquidity will be paired with borrowing demand instantly at the optimised P2P rate.Matching Algorithm

Note: a borrower cannot put a borrow order greater than the available liquidity; it is blocked at the time.
Routing idle liquidty

- Alice (Lender) joins first
- Alice deposits USDC into Paystream. Since no borrower is waiting, her funds are automatically deposited into a fallback liquidity pool (like Kamino or MarginFi) to ensure yield is earned.
- Bob (Borrower) joins later
- When Bob borrows USDC, Paystream checks for matched P2P liquidity. It sees Alice’s funds in the fallback pool, withdraws them instantly, and matches her to Bob at an optimised P2P interest rate.