Introduction

Keeper Bots in the Drift Protocol keep the protocol operational by performing automated actions as autonomous off-chain agents. Keepers are rewarded depending on the duties that they perform.

The various types of keeper bots are:

Bot TypeDifficultyCapital RequiredRewardsLink
Matching BotBasicNoTBDTutorial: Order Matching Bot
Order TriggerBasicNoTBDTutorial: Order Trigger Bot
LiquidatorAdvancedYesTBDTutorial: Liquidation Bot

Note: all bots require some amount of SOL for user account rent and to pay transaction fees.

The reference implementation for all Keeper bots mentioned in these docs is available here (opens in a new tab).

Preparing Environment

First clone the keeper-bots-v2 repo (make sure to check out the correct branch for the cluster you are targetting)

Branch NameCluster
masterdevnet
devnetdevnet
mainnet-betamainnet-beta
git clone https://github.com/drift-labs/keeper-bots-v2 -b devnet

Prepare the required environment variables by copying over .env.example, modify .env with your preferred values

cp .env.example .env

Required Environment Variables

KEEPER_PRIVATE_KEY: the private key of the account to use for signing transactions. This account is the signing of authority of all accounts used by this bot. The value can be a number array (as in the example) or a path to a keypair.json file as generated by solana-keygen ENDPOINT: the JSON-RPC endpoint to use ENV: devnet

Initialise User

The signing account needs to have a User account before they are able to interact with the DriftClient program. We've included a --init-user flag on the Keeper Bot script to help with initializing new users.

yarn run start --init-user
if (!(await driftClient.getUser().exists())) {
    logger.info(`Creating DriftClient for ${wallet.publicKey}`);
    const [txSig] = await driftClient.initializeUserAccount();
    logger.info(`Initialized user account in transaction: ${txSig}`);
}

Depositing Collateral

❗Only required if you are trading or your bot needs to maintain open positions (JIT makers and certain liquidators)

Trading, as well as some Keeper functions (Liquidators and JIT makers), require the account to maintain open positions, and so those accounts must hold collateral. The Keeper Bot script includes a --force-deposit flag to help with depositing collateral.

# deposit 10,000 USDC from account
yarn run start --force-deposit 10000