There are 5 keepers used in Mycelium Perpetual Swaps. They are:
The position keeper is used to enter, and alter positions. The Position Keeper interacts with the
PositionRoutercontract to execute the alteration (
increase) of Swap positions after the front running interval (currently 5 seconds). The Position Keeper finds the fair price to execute the position at by finding the median of 3 CEXs (Binance, FTX, Bitfinex). If the prices have not been updated in 5 minutes, it will execute at the chainlink price. The Position Keeper cancels the request and returns funds to the user if the trade cannot be executed within the allowed slippage. This keeper can also execute positions from
orderbook.solwhen the conditions of the limit orders are met.
Importantly, the protocol’s operation isn’t reliant on this keeper as the trader can manually execute their order after 3 minutes at the price given by the price feed keeper.
The price feed keeper calculates the fair price (as described above). This price is sent to the
FastPriceFeed.solthat is used to price swaps. If the price is more than 5 minutes old, the chainlink price is used instead.
The watcher node verifies that the output from the price feed keeper is accurate. It does the exactly the same calculation as the price feed keeper, to ensure the prices derived from the position and price keepers are not manipulated. Used as keeper price verification.
If there is a difference in the prices found by the watcher node and the price or position keeper, a spread is introduced between the keeper price and the Chainlink price. In the case there is a spread, the lower price will be used as the the bid, and the higher price as the ask.
The liquidation keeper closes positions which are eligible for liquidation (have breached their margin requirements). They will do this by interaction with the
vault.solcontract. They will liquidate at the chainlink price.
The orderbook keepers checks the current state of the orderbook, and will submit any limit orders which are now eligible for execution. All orders still have to wait the front running interval before executing.