The logarithmic buckets data structure introduced in Morpho’s AaveV3 Optimizer improves matching outcomes by optimizing efficiency, gas usage, and fairness.
Morpho’s AaveV3 Optimizer is designed to be the most secure and efficient protocol for supplying and borrowing ETH and leveraging LSTs as collateral. The new and technically superior matching engine features a new data structure called logarithmic buckets which improves on the Heap and Double Linked Lists (DLL) used in AaveV2 and Compound V2 optimizers.
The Heap and DLL are traditional data structures that although efficient, can result in suboptimal matching outcomes, especially when dealing with varying liquidity amounts. This is where the logarithmic buckets data structure comes into play, offering a novel and fairer approach designed to maximize both the volume and number of users matched.
The logarithmic buckets data structure allows the matching engine to sort users into multiple buckets, with each bucket accommodating positions within a specific volume range and prioritizes matching users within each bucket, although it is still possible for them to be paired with someone outside of it.
Gone are the times when smaller users would be waiting forever to be matched even when there are plenty of transactions of similar size happening.
But how exactly do log buckets differ from the Heap and DLL used in AaveV2 and CompoundV2 optimizers?
Imagine the following scenario when using a simple DLL. One user first supplies 100 ETH, and ten more supply 10 ETH each. Then ten borrowers arrive, all borrowing 10 ETH. They will get matched with the first supplier (100 ETH) because they have the largest supplied volume. If another borrower wants to borrow 100 ETH, he will loop through all the ten remaining suppliers on the pool, possibly only matching a few because of the gas limit.
Now the scenario with logarithmic buckets, users are sorted by their amount of liquidity. When the ten borrowers come to Morpho to borrow 10 ETH each, they will get matched with the ten users supplying 10 ETH. While the user borrowing 100 ETH with be matched with the person supplying 100 ETH. Noting that this is a simplification of how it works in practice.
You will notice this solution ensures that most of the matching can be done in a single interaction, therefore improving gas efficiency.
Interested in the implementation? See the code code here.
The logarithmic buckets data structure seeks to improve three fundamental aspects of Morpho’s matching system: efficiency, gas usage, and fairness.
The logarithmic buckets data structure introduced in Morpho’s AaveV3 Optimizer improves matching outcomes by optimizing efficiency, gas usage, and fairness. With its ability to match liquidity providers and borrowers based on similar liquidity sizes, this new data structure offers a more efficient and equitable matching, leading to a higher percentage of total matched users over time.
To experience the improved matching engine, try Morpho’s AaveV3-ETH Optimizer.