Keepers
There are 5 keepers used in Mycelium Perpetual Swaps. They are:

1. Position Keeper

The position keeper is used to enter, and alter positions. The Position Keeper interacts with the PositionRouter contract to execute the alteration (open, close, reduce, 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.sol when 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.

2. Price Feed Keeper

The price feed keeper calculates the fair price (as described above). This price is sent to the FastPriceFeed.sol that is used to price swaps. If the price is more than 5 minutes old, the chainlink price is used instead.

3. Watcher Node

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.

4. Liquidation Keeper

The liquidation keeper closes positions which are eligible for liquidation (have breached their margin requirements). They will do this by interaction with the vault.sol contract. They will liquidate at the chainlink price.

5. Order Book Keeper

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.
Export as PDF
Copy link
On this page
1. Position Keeper
2. Price Feed Keeper
3. Watcher Node
4. Liquidation Keeper
5. Order Book Keeper