A simple, fast, and easily deployable reallocation bot for the Morpho Vaults v2. This bot is entirely based on RPC calls and the Morpho API and is designed to automate Morpho vaults v1 reallocations according customable strategies.
- Automatically rebalances assets within vaults v2 to maintain capital efficiency
- Equalizes utilization rates across markets
- Multi-chain compatible (Ethereum, Base, and more)
- Configurable minimum threshold for utilization changes (2.5% by default)
This is the v0 of the bot, so it makes strong assumptions about the vaults' configuration:
- Vaults are expected to have only one adapter, which must be a MorphoMarketV1AdapterV2.
- Vaults are expected to have meaningful caps only at the market V1 level. Caps on collaterals or on the adapter should be maxed (or very high), as the vault won't consider them reachable.
These constraints will be removed in future versions as more adapters are whitelisted by the Morpho Registry List.
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 installThe bot can be configured to run on any EVM-compatible chain where the Morpho v2 stack has been deployed and supported by the Morpho API. Chain configuration is done in the apps/config/src/config.ts file.
In this file, you'll define an array of chain configurations. Each entry specifies:
- chain: The chain to run the bot on
- strategy: The strategy to use for that chain
- vaultWhitelist: The list of vault addresses to rebalance
- executionInterval: Minutes between each bot run
You can use different strategies for different chains. For example:
export const chains: ChainSettings[] = [
{
chain: mainnet,
strategy: "equilizeUtilizations",
vaultWhitelist: [
"0xbeef0046fcab1dE47E41fB75BB3dC4Dfc94108E3",
"0xbeef003C68896c7D2c3c60d363e8d71a49Ab2bf9",
],
executionInterval: 10,
},
{
chain: base,
strategy: "apyRange",
vaultWhitelist: ["0xabcd..."],
executionInterval: 30,
},
];Secrets are set in the .env file at the root of the repository, keyed by chain ID:
RPC_URL_<chainId>: The RPC URL of the chain that will be used by the bot.REALLOCATOR_PRIVATE_KEY_<chainId>: The private key of the EOA that will be used to execute the reallocations. This EOA must have the allocator role of all curated vaults.
Example for mainnet (chainId 1):
RPC_URL_1=https://eth-mainnet.g.alchemy.com/v2/<your-alchemy-api-key>
REALLOCATOR_PRIVATE_KEY_1=0x1234567890123456789012345678901234567890123456789012345678901234
Some strategies require some chains and vaults specific configutation.
This configuration is handled in the apps/config/src/strategies folder, which contains the config files of every configurable strategies.
This strategy:
- 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)
This strategy tries to keep vaults listed markets borrow APY within the ranges defined in apps/config/src/strategies/apyRange.ts.
Ranges can be defined at the global level, at the vaults level, or/and at the markets level.
If you don't plan on supporting a new pricer venue, you can ignore this section.
To add your own strategy, you need to create a new folder in the apps/client/src/strategy folder, named after your strategy.
This folder should contain one index.ts file. In this file you will implement the new strategy class that needs to implements the Strategy interface (located in apps/client/src/strategies/strategy.ts).
This class will contain the logic of the strategy, and needs to export one method: findReallocation(Returns a Reallocation typed object). This methods can be async.
Next, you'll need to:
- Update the
StrategyNametype inapps/config/src/types.tsby adding your strategy name to it. - Update the
createStrategyfunction inapps/client/src/strategies/factory.tsto include your strategy. - Update the exports in
apps/client/src/strategies/index.tsto include your strategy.
Additionally:
- If your strategy requires vault, chain, or other specific configuration, add a configuration file named after your strategy in the
apps/config/src/strategiesfolder. - If your strategy requires any ABIs, add them to a new file in the
apps/client/src/abisfolder.
Once the bot is installed and configured, you can run it by executing the following command:
pnpm reallocateThis command will start the bot.