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 both Ethers.js and Viem for maximum flexibility.
Current SDK versions are in pre-release. Use the following commands to install the latest next versions:
yarn add @morpho-org/blue-sdk@next
yarn add @morpho-org/blue-sdk-ethers@next
yarn add @morpho-org/liquidity-sdk-ethers@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 ethers@^6.13.1
yarn add dotenv
yarn add @morpho-org/blue-sdk@next
yarn add @morpho-org/blue-sdk-viem@next
yarn add @morpho-org/liquidity-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
Note: npm has 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:{ "@morpho-org/blue-api-sdk": "2.0.0-next.14", "@morpho-org/blue-sdk": "2.0.0-next.32", "@morpho-org/blue-sdk-ethers": "2.0.0-next.30", "@morpho-org/blue-sdk-viem": "2.0.0-next.30", "@morpho-org/liquidity-sdk-ethers": "2.0.0-next.6", "@morpho-org/liquidity-sdk-viem": "2.0.0-next.6", "@morpho-org/morpho-blue-bundlers": "1.1.2", "@morpho-org/morpho-ts": "2.0.0-next.16", "@morpho-org/simulation-sdk": "2.0.0-next.30", }
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
Both Ethers.js and Viem implementations provide identical functionality. Choose based on your existing stack:
- Use Ethers.js version if you're already using Ethers.js in your project
- Use Viem version if you're using Viem or starting a new project
- Update the market parameters in your script:
const marketId = "0x..." as MarketId; // Your target market
const chainId = 1; // or 8453 for Base
const REQUESTED_LIQUIDITY = BigInt("1000000000000000000"); // Amount in wei
- Run the script:
ts-node scripts/ethers/sdkBundler.ts
or
ts-node scripts/viem/sdkBundler.ts
The script will:
- Fetch initial market metrics from the API
- Check current market liquidity
- Determine if reallocation is needed
- Optional: Run market state simulations
- Process withdrawals if needed
- Generate and save transaction data to
rawTransaction.json
- 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.