Skip to content

morpho-org/public-allocator-scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Morpho Public Allocator - Bundler Implementation

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.

Reallocation Flow

⚠️ API - WIP Notice

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.

⚠️ SDK Versions Notice

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.

For Viem Implementation

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:

Environment Setup

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

Performance Considerations

The script implements a two-step data fetching process for optimal performance:

  1. 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
  2. Detailed RPC Data: Only fetched when reallocation is needed

    • More resource-intensive
    • Provides real-time data
    • Required for accurate transaction preparation

Stack Choice

Currently only viem is supported, given a version dependency.

Usage

  1. 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" },
];
  1. Run the script:
npx tsx scripts/sdks/viem/sdkBundler.ts

The script will:

  1. Fetch initial market metrics from the GraphQL API
  2. Get current market data and liquidity state
  3. Calculate utilization and required reallocation
  4. Process withdrawals if needed
  5. Run market simulations for impact analysis
  6. Generate transaction data if reallocation is required
  7. Provide detailed results including:
    • Current market liquidity
    • API metrics
    • Simulation results
    • Reallocation details
    • Transaction data (if applicable)
    • Status messages

Reallocation Flow

Mermaid Link for preview

Note

  • API data has a potential 1-minute delay
  • Reallocatable liquidity calculations consider utilization caps (92% max)
  • For support, reach out on Discord

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published