Vault: Technical Deep Dive
The Kuru AMM vault is tightly integrated with the Orderbook contract and is an integral part of it. It places orders at every price point such that the notional value of the quote asset and the base asset is effectively equal. This means that the curve we follow is the common curve.
As a practical example, let us assume that the vault is placing orders at a gap of 30 BPS. This means that the vault has orders at current price , , , etc.
First, we need to determine the size of the bid (buy) and ask (sell) orders the vault should place on the order book. Even though the vault is a passive market maker as far as LPs are concerned, it is an active MM to the Orderbook.
We assume the vault's best ask price to be , where . This means that the vault's best bid price must be at a gap of 30 BPS, which is . Here, is the amount of quote asset that the vault owns and is the amount of base asset it owns.
Understanding the Math:
If the vault's best ask at is filled completely for size , the price will move up by 30 BPS. This means that the new vault best ask becomes . Based on this, we can formulate an equation:
If the vault's best bid at is completely filled for size , the price moves down by 30 BPS. This means that the new vault best bid would be . The new vault ask price then moves down to . We can find based on this:
Now, if the distribution of sizes along the curve is correct, it should add up to the base token amount owned by the vault. For this:
We know that the current ask size is . This means that at the next ask price, the new ask size must be .
(Infinite geometric series summation with factor < 1)By property of symmetry, a summation of bids across all potential bids should sum to the total quote asset amount that the vault holds, i.e, .
Adjusting for partial fills:
The passive orders placed by the Kuru AMM vault act exactly as standard orders and can be partially filled. Both bid and ask orders from the vault may be partially filled. However, when a price shift occurs (e.g., due to a full fill of a bid or ask), any remaining partially filled order on the other side cannot simply be set to 0, as this would violate the vault's pricing curve logic.
Therefore, we need a method to handle these remaining partial fills consistently with the pricing curve after a price shift. This will be different for both bid and ask partial fills.
Partially filled bid, fully filled ask:
This happens when there is a partially filled vault bid, and the vault ask gets completely filled. This means that a taker has done a market buy, and hence the price moves up by 30 BPS. The new vault bid size is set to the old vault ask size and the new vault ask size is set to a new value.
Now, we must ensure that the partially filled bid value should never be more than the new bid size. Let the new bid size be .
We know that = .
We also know that since
Now, and , it is possible that . This is not acceptable since the partially filled size can not exceed the actual order size. Therefore, an adjustment is required.
We need to find a new partially filled bid , such that its quote value at the new price () equals the quote value of the original partial bid at the old price ()
The new vault best bid price is the old vault best ask price . Then:
Therefore, the new partially filled bid should be .
Now, verifying the contraint :
Now, since , and ,
Thus, our constraint of the partially filled bid size not exceeding the order size is satisfied.
Partially filled ask, fully filled bid:
This happens when a partially filled ask exists and the vault bid gets fully filled. This implies that a taker has done a market sell. The price moves down by 30 BPS, and the new vault best ask price becomes the old vault best bid price.
The current partially filled ask size is , and we know that .
Let the new vault ask size be .
Since ,
This means the partially filled ask will always be smaller than the required new ask size . Therefore, the partially filled ask does not need adjustment.