Prompt file imported from ratik/morpho-blue-liquidation-bot (
.claude/commands/add-chain.md). Copyright stays with the author.
Add Chain
Interactive workflow for adding a new chain to the liquidation bot. Follow CLAUDE.md "How to Add a New Chain" exactly.
Input
Ask the user for:
- Chain name — e.g.
scroll,linea - Is the chain available in
viem/chains? If not, collect:- Chain ID
- Chain display name
- Native currency symbol, name, and decimals
- Default RPC URL
- Block explorer URL (optional)
- Multicall3 address and block created (optional)
- Wrapped native token address (
wNative) - Vault whitelist — list of vault addresses, or
"morpho-api"for API-based discovery - Which liquidity venues to enable (ordered list from existing
LiquidityVenueNamevalues) - Which pricers to enable (ordered list from existing
PricerNamevalues, optional) - Which data provider to use (
"morphoApi"or"hyperIndex") - Flashbots toggle (
useFlashbots) - Block interval (optional)
- Liquidation buffer bps (optional, default 50)
Steps
1. Custom chain definition (if not in viem/chains)
Create apps/config/src/chains/<name>.ts:
import { defineChain } from "viem";
export const <name> = defineChain({
id: <chainId>,
name: "<displayName>",
network: "<name>",
nativeCurrency: {
symbol: "<SYMBOL>",
name: "<CurrencyName>",
decimals: 18,
},
rpcUrls: {
default: {
http: ["<rpcUrl>"],
},
},
blockExplorers: {
default: {
name: "<ExplorerName>",
url: "<explorerUrl>",
},
},
contracts: {
multicall3: {
address: "<multicall3Address>",
blockCreated: <blockNumber>,
},
},
});
Add export in apps/config/src/chains/index.ts:
export * from "./<name>";
2. Add chain config
Add an entry to chainConfigs in apps/config/src/config.ts:
[<chainImport>.id]: {
chain: <chainImport>,
wNative: "<wNativeAddress>",
options: {
dataProvider: "<dataProviderName>",
vaultWhitelist: <whitelist>,
additionalMarketsWhitelist: [],
liquidityVenues: [<ordered venue list>],
pricers: [<ordered pricer list>],
liquidationBufferBps: <bufferBps>,
useFlashbots: <flashbotsToggle>,
blockInterval: <interval>,
},
},
Import the chain at the top of the file — from viem/chains if standard, or from ./chains if custom.
3. Update venue/pricer config mappings
Check and update per-chain config files that have Record<number, ...> mappings. These typically include:
apps/config/src/liquidityVenues/erc20Wrapper.ts—wrappersrecordapps/config/src/liquidityVenues/uniswapV3.ts— factory/router addresses (if uniswapV3 venue is enabled)apps/config/src/liquidityVenues/uniswapV4.ts— addresses (if uniswapV4 venue is enabled)apps/config/src/pricers/uniswapV3.ts—USD_REFERENCErecord (if uniswapV3 pricer is enabled)
For each enabled venue/pricer, add the chain ID entry with the correct addresses. Ask the user for any chain-specific addresses needed.
4. Add HyperIndex config (if using hyperIndex data provider)
Add the chain to apps/config/src/dataProviders/hyperindex.ts:
[<chainId>]: {
morphoStartBlock: <block>,
metaMorphoFactoryStartBlock: <block>,
adaptiveCurveIrmStartBlock: <block>,
preLiquidationFactoryStartBlock: <block>,
},
Ask the user for the deployment block numbers.
5. Reminder
After scaffolding, remind the user:
- Set up environment variables:
RPC_URL_<chainId>— RPC endpointEXECUTOR_ADDRESS_<chainId>— deployed executor contract addressLIQUIDATION_PRIVATE_KEY_<chainId>— private key for the liquidator wallet
- Deploy the executor contract:
pnpm deploy:executor - Venue and pricer ordering matters — venues are tried sequentially, first success wins
- Run
pnpm build:configto verify the config compiles
