Skip to content

ricardojmendez/keeper-bots-v2

 
 

Repository files navigation

Keeper Bots for Drift Protocol v2

Docs Discord Chat License

Setting up

This repo has two main branches:

  • master: bleeding edge, may be unstable, currently running on the devnet cluster
  • mainnet-beta: stable, currently running on the mainnet-beta cluster

Setup Environment

yaml Config file:

A .yaml file can be used to configure the bot setup now. See config.example.yaml for a commented example.

Then you can run the bot by loading the config file:

yarn run dev --config-file=example.config.yaml

Here is a table defining the various fields and their usage/defaults:

Field Type Description Default
global object global configs to apply to all running bots -
global.endpoint string RPC endpoint to use -
global.wsEndpoint string (optional) Websocket endpoint to use derived from global.endpoint
global.keeperPrivateKey string (optional) The private key to use to pay/sign transactions KEEPER_PRIVATE_KEY environment variable
global.initUser bool Set true to init a fresh userAccount false
global.websocket bool Set true to run the selected bots in websocket mode if compatible false
global.runOnce bool Set true to run only one iteration of the selected bots false
global.debug bool Set true to enable debug logging false
global.subaccounts list (optional) Which subaccount IDs to load 0
enabledBots list list of bots to enable, matching key must be present under botConfigs -
botConfigs object configs for associated bots -
botConfigs.<bot_type> object config for a specific <bot_type> -

Install dependencies

Run from repo root to install npm dependencies:

yarn

Initialize User

A ClearingHouseUser must be created before interacting with the ClearingHouse program.

yarn run dev --init-user

Alternatively, you can put the private key into a browser wallet and use the UI at https://app.drift.trade to initialize the user.

Depositing Collateral

Some bots (i.e. trading, liquidator and JIT makers) require collateral in order to keep positions open, a helper function is included to help with depositing collateral. A user must be initialized first before collateral may be deposited.

# deposit 10,000 USDC
yarn run dev --force-deposit 10000

Alternatively, you can put the private key into a browser wallet and use the UI at https://app.drift.trade to deposit collateral.

Run Bots

After creating your config.yaml file as above, run with:

yarn run dev --config-file=config.yaml

By default, some Prometheus metrics are exposed on localhost:9464/metrics.

Notes on some bots

Filler Bot

Include filler and/or spotFiller under .enabledBots in config.yaml

Read the docs: https://docs.drift.trade/keepers-and-decentralised-orderbook

Fills (matches) crossing orders on the exchange for a small cut of the taker fees. Fillers maintain a copy of the DLOB to look for orders that cross.

Liquidator Bot

Read the docs: https://docs.drift.trade/liquidators

Notes on derisking (useJupiter)

This liquidator implementation includes an option to useJupiter to derisk (sell) spot assets into USDC. The derisk loop will use the more favorable of Drift spot or Jupiter before executing. Set useJupiter under the liquidator config to enable this behavior (see below).

You may also set disableAutoDerisking to true, to disable the derisking loop. You may want to do this as part of a larger strategy where you are ok with taking on risk at a favorable to market price (liquidation fee applied).

Notes on configuring subaccount

By default the liquidator will attempt to liqudate (inherit the risk of) endangered positions in all markets. Set botConfigs.liquidator.perpMarketIndicies and/or botConfigs.liquidator.spotMarketIndicies in the config file to restrict which markets you want to liquidate. The account specified in global.subaccounts will be used as the active account.

perpSubaccountConfig and spotSubaccountConfig can be used instead of perpMarketIndicies and spotMarketIndicies to specify a mapping from subaccount to list of market indicies. The value of these 2 fields are json strings:

An example config.yaml

botConfigs:
  ...
  liquidator:
    ...
    useJupiter: true
    perpSubAccountConfig:
      0:
        - 0
        - 1
        - 2
      1:
        - 3
        - 4
        - 5
        - 6
        - 7
        - 8
        - 9
        - 10
        - 11
        - 12
    spotSubAccountConfig:
      0:
        - 0
        - 1
        - 2

Means the liquidator will liquidate perp markets 0-2 using subaccount 0, perp markets 3-12 using subaccount 1, and spot markets 0-2 using subaccount 0. It will also use jupiter to derisk spot assets into USDC.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 99.4%
  • Other 0.6%