Liquidity Tracking
Last updated
Last updated
To facilitate query liquidity Midas uses a 3-layer tree structure. Each node is a 256bit array recorded with uint256. There are exactly slots at the bottom of the tree, corresponding to the theoretical maximum of slots in our bin. We record this underlying slot as 1 when there is liquidity in a bin, and label it as 0 otherwise. When a parent node has a 1 in the 256 slots it contains, the parent node is also marked as 1, and so on.
This structure can help us efficiently find the next bin with liquidity in a given direction and update the current floor price and best offer.