DocumentationOpen App

Bot System

Gearbox features a granular bot permission system that allows automated management of Credit Accounts. Bots can execute operations on behalf of account owners with specific, revocable permissions.

Architecture

ComponentDescription
BotListV3Registry storing (bot, creditManager, creditAccount) → permissions
IBot interfaceBots implement requiredPermissions() to declare needed permissions
CreditFacadeV3Entry point for bot execution via botMulticall

Permission Model

Permissions are stored as a uint192 bitmask. Account owners grant specific permissions to specific bots:

PermissionOperation
ADD_COLLATERALAdd funds to account
INCREASE_DEBTBorrow more from pool
DECREASE_DEBTRepay debt
WITHDRAW_COLLATERALWithdraw assets
UPDATE_QUOTAChange token quotas
SET_BOT_PERMISSIONSManage other bots
EXTERNAL_CALLSExecute adapter calls

Granting Permissions

Account owners grant permissions via a multicall operation:

TypeScript
const calls = [ service.setBotPermissions( creditAccount, botAddress, ADD_COLLATERAL_PERMISSION | EXTERNAL_CALLS_PERMISSION ), ]; await facade.multicall(creditAccount, calls);

Bot Execution

Bots execute via botMulticall on the Credit Facade:

TypeScript
// Bot calls botMulticall with the account and operations await facade.botMulticall(creditAccount, [ service.addCollateral(creditAccount, tokenAddress, amount), // ... other permitted operations ]);

The Facade checks the bot's permissions before each operation. If a bot attempts an unpermitted action, the transaction reverts.

Safety Model

  • Isolation — each permission grant is scoped to a specific (bot, creditManager, creditAccount) tuple
  • Immutability — bots cannot modify their own permissions
  • DAO forbid list — the DAO can globally forbid malicious bots
  • Collateral check — bot multicalls undergo the same solvency check as user multicalls

Revoking Permissions

TypeScript
// Revoke all permissions for a bot await facade.multicall(creditAccount, [ service.setBotPermissions(creditAccount, botAddress, 0), ]);

Learn More