Keeper Architecture

All Keepers have several things in common, they facilitate user actions (trades, liquidations, etc) within the Rook ecosystem, they connect to the HidingBook to learn about user activity, and they submit bids to the Coordinator to gain the rights to facilitate trade for the user and capture MEV. There are a variety of techniques for going about this. Some Keepers may specialize in one specific technique, while other Keepers may cast a wider net and use a variety of techniques.

Example Keeper bot techniques

  • DeFi arbitrage, cross the user with Uniswap or another on-chain DEX
  • CeFi arbitrage, cross the user with Coinbase or another centralized service
  • Liquidation facilitation
    • Liquidate something, and facilitate trade through the user
    • Liquidate the user, and facilitate trade through another source
  • Front running, tailgating, etc, including the user somewhere in the trade
  • Keepers can also just fill a user's order outright

DeFi Keeper bot example architecture

DeFi example
In this example, a DeFi based Keeper bot can facilitate user trade using an on-chain smart contract that they operate. They also have an off-chain bot that connects to the HidingBook and Coordinator. The off-chain bot drives the on-chain contract. They can cross user orders with DEXs like Uniswap, and broadcast their transactions to Ethereum mempool or services like Flashbots.

CeFi Keeper bot example architecture

CeFi example
In this example, a CeFi based Keeper bot can facilitate user trade themselves directly, and can also rebalance or hedge using off-chain exchanges like Binance or even OTC desks. Their off-chain bot connects to the HidingBook and Coordinator. They can broadcast their transactions to Ethereum mempool or services like Flashbots.

Keeper bot architecture

  • A Keeper bot
    • A bot built and operated by the Keeper. This is integrated with the Coordinator and HidingBook components
  • Coordinator WebSocket server
    • Keepers connect and communicate with the Coordinator using this server. When they find arbitrage, they place a bid via WebSockets noting the specific order/liquidation/etc they wish to fill. The Coordinator prevents gas auctions and other bad behaviors. The Coordinator will broadcast the winner of the auction letting the greenlit Keeper know to take the order/liquidation/etc. The Keeper can then capture the arbitrage or MEV any way they'd like, i.e., mempool, Flashbots, Eden, MiningDAO, etc.
  • Coordinator HTTP server
    • Keepers provide and gather critical information to and from this server. Keepers must stay up to date on the payment channel between the Keeper and the coordinator. They also must register their addresses with the Coordinator so the Coordinator can whitelist them appropriately. Keepers can also gather general useful information to help optimize profitability or review historic auctions.
  • HidingBook HTTP server
    • The orderbook containing user orders only fillable by whitelisted Rook Keepers. Keepers can get orders, learn about supported tokens, etc so they can scan the crypto space searching for MEV and ways to facilitate trade for users.
  • HidingBook WebSocket server
    • Keepers listen to real time order update events using this endpoint. This ensures they get orders as soon as they are posted, and they know as soon as an order is filled or expired.