This repository provides tools to fetch data from Morpho Blue markets and prepare reallocation transactions using the public allocator via the Bundler contract. The implementation supports Viem only for now.
An API (combined with RPC calls) version has been created to fetch data from the API and prepare reallocation transactions. It is automitically simulating the reallocation transaction and filtering with any potential error during atomic reallocation process. It is currently in WIP.
Current SDK versions are in pre-release. Use the following commands to install the latest next versions. Note the liquidity-sdk-viem is on version 1.1.0.
yarn add @morpho-org/blue-sdk@next
yarn add @morpho-org/blue-sdk-viem@next
yarn add @morpho-org/morpho-blue-bundlers@latest
yarn add @morpho-org/morpho-ts@next
yarn add @morpho-org/simulation-sdk@next
yarn add viem@^2.21.54
yarn add dotenv
and also:
yarn add @morpho-org/[email protected]
Note: npm has potential issues parsing package names containing '@' symbols. We recommend using yarn or pnpm instead.
If one really needs to use npm, use exact versions in package.json:
Create a .env
file in the root directory with the following variables:
RPC_URL_MAINNET=your_mainnet_rpc_url_here
RPC_URL_BASE=your_base_rpc_url_here
The script implements a two-step data fetching process for optimal performance:
-
Initial Quick Overview: Uses the Morpho API to fetch basic liquidity data
- More efficient for initial checks
- May have a ~1 minute delay
- Suitable for UI displays and quick checks
-
Detailed RPC Data: Only fetched when reallocation is needed
- More resource-intensive
- Provides real-time data
- Required for accurate transaction preparation
Currently only viem is supported, given a version dependency.
- Update the market parameters in your script:
const chainId = 8453 as ChainId;
const marketId =
"0x9103c3b4e834476c9a62ea009ba2c884ee42e94e6e314a26f04d312434191836" as MarketId;
// Example amounts: 20 USDC and 20M USDC
const examples = [
{ amount: 20, label: "20 USDC" },
{ amount: 20_000_000, label: "20M USDC" },
];
- Run the script:
npx tsx scripts/sdks/viem/sdkBundler.ts
The script will:
- Fetch initial market metrics from the GraphQL API
- Get current market data and liquidity state
- Calculate utilization and required reallocation
- Process withdrawals if needed
- Run market simulations for impact analysis
- Generate transaction data if reallocation is required
- Provide detailed results including:
- Current market liquidity
- API metrics
- Simulation results
- Reallocation details
- Transaction data (if applicable)
- Status messages
- API data has a potential 1-minute delay
- Reallocatable liquidity calculations consider utilization caps (92% max)
- For support, reach out on Discord
This project is licensed under the MIT License.