π°Pricing
Last updated
Last updated
Oyster AMM unifies both concentrated liquidity and limit orders in a single model. In smart contract terms, Range and Order can provide liquidity at each price point. For Range covering the same price point, their liquidity, or square root of k, is added for AMM curve-related calculation. For Order at the same price point, their order sizes are added together to cater to the takerβs trade size. In addition, Order is always consumed before liquidity from Range is consumed.
The collection of concentrated liquidity covering a price point and all open limit orders on the same price point is described in a struct called Pearl and is stored in the smart contract indexed by price. Oyster AMM can be viewed as the collection of Pearl along with the AMM price curve.
In fact, Pearl serves as the pool for limit orders from makers, which is also the key to the feasibility of the asynchronous design of limit orders in Oyster AMM. In this way, logic on the takersβ side is simplified greatly, where takers take as much as they want and nothing more. With Pearl's fungible approach, the gas cost of a trade is directly proportional to the price impact, i.e., the number of ticks crossed.
For a trade of size S0, the process of trading, or consuming unified liquidity, follows the steps below.
Check if there are unfilled limit orders in the Pearl of current price P0.
If not, go to step 2 with S1 = S0.
If so, fill the limit orders as much as possible.
If S0 is fully filled, terminate. (Note that the current price does not change in this case.)
If not, continue to step 2 with the remaining size S1.
Find the Pearl at the next price, P1.
Trade for size S1 on the AMM curve between Pearl at P0 and P1.
If S1 is fully filled, terminate. (Note that the current price does change in this case.)
If not, update the current price as P1 and go to step 1 with the remaining size S2.