The Kuru Router governs all the markets- it is the default owner of all markets and can be used to upgrade markets to a new implementation. The Router is also used to deploy all markets. It stores market params for every market and hence can be easily used to route through markets. The Kuru Margin Account takes care of all accounting related to limit orders and backstop liquidity AMMs.
Each market on Kuru comprises of an OrderBook and discretised AMM liquidity. Simply said, you can discretise a CPAMM and transform it into an OrderBook if you calculate the amount of tokens which have to flow in or out between two price points. The OrderBook contract treats the AMM liquidity as a first-class citizen, so it can aggregate between limit orders on the book and the AMM liquidity while maintaining price priority.
All limit orders on Kuru maintain price-time priority, i.e, incoming orders match on the best price available, with first-in-first-out fill priority. The prices are stored in a bitmap-based tree which allows us to fetch best price at O(1) complexity. All orders for a specific price point are stored in a double-linked-list, and therefore order matching is at O(n) complexity.
Markets on Kuru need to be initialised with a given set of parameters which suit the base/quote pair. You will find recommendations on how to set these in the same repo. If you are going YOLO, please note that a low sizePrecision
will wreck the backstop liquidity and wrong pricePrecision
might make it impossible to place limit orders on certain pairs.
Since matching is done fully onchain, taker orders essentially 'crank' maker orders and credit the outputs to the makers. Hence, to avoid potential DOS, we use the margin account for all debits and credits related to limit orders. However, taker orders can choose which path they want to take.