{"id":30614579,"url":"https://github.com/morpho-org/morpho-blue-reallocation-bot","last_synced_at":"2025-08-30T07:15:40.565Z","repository":{"id":302644078,"uuid":"971283636","full_name":"morpho-org/morpho-blue-reallocation-bot","owner":"morpho-org","description":null,"archived":false,"fork":false,"pushed_at":"2025-07-03T13:06:55.000Z","size":140,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-07-03T13:45:31.836Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/morpho-org.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-23T09:35:30.000Z","updated_at":"2025-07-03T12:45:18.000Z","dependencies_parsed_at":"2025-07-03T13:45:35.834Z","dependency_job_id":"79353365-13d1-48a1-815b-6b0efbd9d1e0","html_url":"https://github.com/morpho-org/morpho-blue-reallocation-bot","commit_stats":null,"previous_names":["morpho-org/morpho-blue-reallocation-bot"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/morpho-org/morpho-blue-reallocation-bot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morpho-org%2Fmorpho-blue-reallocation-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morpho-org%2Fmorpho-blue-reallocation-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morpho-org%2Fmorpho-blue-reallocation-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morpho-org%2Fmorpho-blue-reallocation-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/morpho-org","download_url":"https://codeload.github.com/morpho-org/morpho-blue-reallocation-bot/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morpho-org%2Fmorpho-blue-reallocation-bot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272817705,"owners_count":24998038,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-30T02:00:09.474Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-30T07:15:38.861Z","updated_at":"2025-08-30T07:15:40.549Z","avatar_url":"https://github.com/morpho-org.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Morpho Blue Reallocation Bot\n\nA simple, fast, and easily deployable reallocation bot for the **Morpho Blue** protocol. This bot is entirely based on **RPC calls** and is designed to\nmeet borrow demand within MetaMorpho vaults by equalizing utilization rates across markets.\n\n## Features\n\n- Automatically rebalances assets within MetaMorpho vaults to maintain capital efficiency\n- Equalizes utilization rates across markets\n- Multi-chain compatible (Ethereum, Base, and more)\n- Minimal setup and dependencies (RPC-only, no extra infra required)\n- Configurable minimum threshold for utilization changes (2.5% by default)\n\n### ⚠️ Disclaimer\n\nThis 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.\n\nUse at your own risk.\n\n## Requirements\n\n- Node.js \u003e= 20\n- [pnpm](https://pnpm.io/) (this repo uses `pnpm` as package manager)\n- [Docker](https://www.docker.com/) (optional, only needed if you want to run the database locally)\n- A valid RPC URL (via Alchemy, Infura, etc)\n- The private key of an EOA with enough funds to pay for gas\n\n## Installation\n\n```bash\ngit clone https://github.com/morpho-org/morpho-blue-reallocation-bot.git\ncd morpho-blue-reallocation-bot\npnpm install\n```\n\n## Chain Configuration\n\nThe bot can be configured to run on any EVM-compatible chain where the Morpho stack has been deployed. The chain configuration is done in the `apps/config/config.ts` file.\n\n### Morpho Stack parameters (addresses and start blocks)\n\n**If you don't plan on supporting a new chain, you can ignore this section.**\n\nMorpho Blue:\n\n- `morpho.address`: The address of the Morpho contract.\n- `morpho.startBlock`: The block number of the Morpho contract deployment.\n\nAdaptive Curve IRM:\n\n- `adaptiveCurveIrm.address`: The address of the Adaptive Curve IRM contract.\n- `adaptiveCurveIrm.startBlock`: The block number of the Adaptive Curve IRM contract deployment.\n\nMeta Morpho Factories:\n\n- `metaMorphoFactories.addresses`: The addresses of the MetaMorpho factories.\n- `metaMorphoFactories.startBlock`: The block number of the oldest MetaMorpho factory deployment.\n\n### Secrets\n\n**Database secrets (optional):**\n\n- `POSTGRES_DATABASE_URL`: The URL of the postgres database that will be used by the bot. If not set, the bot will launch a docker container with a local postgres database.\n\n**Chain secrets:**\n\nFor each chain, the following secrets must be set:\n\n- `RPC_URL`: The RPC URL of the chain that will be used by the bot.\n- `REALLOCATOR_PRIVATE_KEY`: The private key of the EOA that will be used to execute the reallocations.\n\n**Vault Whitelist**: The bot will only rebalance assets within vaults that are whitelisted:\n\n- `VAULT_WHITELIST`: List of MetaMorpho vaults addresses.\n\n**Execution Interval**: The bot will run once every N seconds, with this value as N:\n\n- `EXECUTION_INTERVAL`: Seconds to wait between runs.\n\nThe secrets must be set in the `.env` file at the root of the repository, with the following keys:\n\n- `RPC_URL_\u003cchainId\u003e`\n- `REALLOCATOR_PRIVATE_KEY_\u003cchainId\u003e`\n- `VAULT_WHITELIST_\u003cchainId\u003e`\n- `EXECUTION_INTERVAL_\u003cchainId\u003e`\n\nExample for mainnet (chainId 1):\n\n```\nRPC_URL_1=https://eth-mainnet.g.alchemy.com/v2/\u003cyour-alchemy-api-key\u003e\nREALLOCATOR_PRIVATE_KEY_1=0x1234567890123456789012345678901234567890123456789012345678901234\nVAULT_WHITELIST_1=0xbeeF010f9cb27031ad51e3333f9aF9C6B1228183,0x8eB67A509616cd6A7c1B3c8C21D48FF57df3d458\nEXECUTION_INTERVAL_1=900\n```\n\n### Strategies config\n\nSome strategies require some chains and vaults specific configutation.\nThis configuration is handled in the `apps/config/src/strategies` folder, which contains the config files of every configurable strategies.\n\n## Reallocation Strategy\n\nThe bot uses by default an `EquilizeUtilizations` strategy that:\n\n1. Calculates a target utilization rate across all markets within a vault\n2. Identifies markets with higher-than-target and lower-than-target utilization\n3. Determines optimal withdrawals and deposits to balance utilization rates\n4. Only executes reallocations when the utilization delta exceeds a minimum threshold (2.5% by default)\n\n## Apy Range Strategy\n\nThe bot can also use the `ApyRange` strategy (if you change the strategy passed to the bot in the `apps/client/src/index.ts` file).\n\nThis strategy tries to keep vaults listed markets borrow APY within the ranges defined in `apps/config/src/strategies/apyRange.ts`.\nRanges can be defined at the global level, at the vaults level, or/and at the markets level.\n\n## Run the bot\n\nOnce the bot is installed and configured, you can run it by executing the following command:\n\n```bash\npnpm reallocate\n```\n\nThis command will start the bot, which will start reallocating once the configured chains are fully indexed.\n\n⚠⏱️ The indexing process can take some time depending on the number of blocks to index.\n\n## Config Changes\n\nUnfortunately, Ponder doesn't allow the same schema to be used with different configs.\nIn this project, the config changes only if you add, remove, or modify a chain.\n\nSo, if you try to run the bot with a set of chains that's different from the one used in your initial run, indexing will fail.\nThere are two ways to handle this:\n\n### Reset the postgres database\n\nThis is the easiest and most direct solution, but you will lose the indexed data for the previous chains.\n\nIf you're using Docker to run the local Postgres database, you can simply stop and remove the container and its volume:\n\n```bash\ndocker compose down -v\n```\n\n### Use a new database\n\nThis way you can have different containers storing different indexing data for different sets of chains.\n\n- If you're using Docker to run the local Postgres database, just change the port both in the postgres url given to ponder (in `apps/ponder/ponder.config.ts`) and in `docker-compose.yml`.\n- If you are using an external postgres database, you just need to change the `POSTGRES_DATABASE_URL`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorpho-org%2Fmorpho-blue-reallocation-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorpho-org%2Fmorpho-blue-reallocation-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorpho-org%2Fmorpho-blue-reallocation-bot/lists"}