A simple, fast, and easily deployable reallocation bot for the Morpho Blue protocol. This bot is entirely based on RPC calls and is designed to automate Morpho vaults reallocations according to customizable strategies.
- Automatically rebalances assets within MetaMorpho vaults to maintain capital efficiency
- Multiple built-in strategies (EquilizeUtilizations, ApyRange)
- Per-chain strategy selection via configuration
- Multi-chain compatible (Ethereum, Base, and more)
- Configurable minimum threshold for utilization/APY changes
This bot is provided as-is, without any warranty. The Morpho Association is not responsible for any potential loss of funds resulting from the use of this bot, including (but not limited to) gas fees, failed transactions, or reallocations on malicious or misconfigured markets.
Use at your own risk.
- Node.js >= 20
- pnpm (this repo uses
pnpmas package manager) - A valid RPC URL (via Alchemy, Infura, etc)
- The private key of an EOA with enough funds to pay for gas
git clone https://github.com/morpho-org/morpho-blue-reallocation-bot.git
cd morpho-blue-reallocation-bot
pnpm installAll configuration is done in the apps/config/ package. You should not need to modify the apps/client/ package unless you want to add a new strategy (see Adding a New Strategy).
The chain and strategy configuration is done in apps/config/src/config.ts. Each entry in the chains array defines the chain to run on and the strategy to use for that chain:
export const chains: { chain: Chain; strategy: StrategyName }[] = [
{ chain: base, strategy: "apyRange" },
];The strategy is selected per chain, so you can run different strategies on different chains.
For each chain, the following secrets must be set in the .env file at the root of the repository:
RPC_URL_<chainId>: The RPC URL of the chain.REALLOCATOR_PRIVATE_KEY_<chainId>: The private key of the EOA that will execute reallocations.VAULT_WHITELIST_<chainId>: Comma-separated list of MetaMorpho vault addresses.EXECUTION_INTERVAL_<chainId>: Seconds to wait between runs.
Example for mainnet (chainId 1):
RPC_URL_1=https://eth-mainnet.g.alchemy.com/v2/<your-alchemy-api-key>
REALLOCATOR_PRIVATE_KEY_1=0x1234567890123456789012345678901234567890123456789012345678901234
VAULT_WHITELIST_1=0xbeeF010f9cb27031ad51e3333f9aF9C6B1228183,0x8eB67A509616cd6A7c1B3c8C21D48FF57df3d458
EXECUTION_INTERVAL_1=900
Some strategies require chain- and vault-specific configuration. This is handled in the apps/config/src/strategies/ folder, which contains the config files for each strategy.
CAP_BUFFER_PERCENT(inconfig.ts): When supplying into a market, the bot targets this percentage of the cap instead of the full cap, to avoid hitting the exact cap limit. Defaults to99.99(i.e. 99.99% of the cap).
DEFAULT_MIN_UTILIZATION_DELTA_BIPS: Minimum utilization delta (in bips) to trigger a reallocation. Defaults to250(2.5%).vaultsMinUtilizationDeltaBips: Per-chain, per-vault overrides.
DEFAULT_APY_RANGE: Global default APY range (in percent).ALLOW_IDLE_REALLOCATION: Whether the bot can reallocate liquidity into the idle market.vaultsDefaultApyRanges: Per-chain, per-vault APY range overrides.marketsApyRanges: Per-chain, per-market APY range overrides.DEFAULT_MIN_APY_DELTA_BIPS: Minimum APY delta (in bips) to trigger a reallocation.
- Calculates a target utilization rate across all markets within a vault
- Identifies markets with higher-than-target and lower-than-target utilization
- Determines optimal withdrawals and deposits to balance utilization rates
- Only executes reallocations when the utilization delta exceeds a minimum threshold (2.5% by default)
Tries to keep listed markets' borrow APY within configured ranges. Ranges can be defined at the global level, at the vault level, or at the market level (with market-level overriding vault-level, which overrides global).
If you want to add a custom strategy, you will need to modify the apps/client/ package:
- Create a new strategy class in
apps/client/src/strategies/that implements theStrategyinterface. - Add the strategy name to the
StrategyNametype inapps/config/src/types.ts. - Register it in the factory function in
apps/client/src/strategies/factory.ts. - Set it in
apps/config/src/config.tsfor the desired chain(s).
Once the bot is installed and configured, you can run it by executing the following command:
pnpm reallocateThis command will start the bot.