| Crates.io | morpho-rs-api |
| lib.rs | morpho-rs-api |
| version | 0.6.0 |
| created_at | 2026-01-23 18:40:07.484007+00 |
| updated_at | 2026-01-25 17:44:10.310202+00 |
| description | Rust API library for querying Morpho V1 (MetaMorpho) and V2 vaults via GraphQL |
| homepage | |
| repository | https://github.com/tynes/morpho-rs |
| max_upload_size | |
| id | 2065245 |
| size | 335,795 |
GraphQL API client for querying Morpho vaults with unified transaction support.
cargo add morpho-rs-api
NamedChain from alloy-chains for chain typesuse morpho_rs_api::{MorphoClient, NamedChain};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create an API-only client (no transaction support)
let client = MorphoClient::new();
// Query vaults on a specific chain
let vaults = client.api().get_vaults_by_chain(NamedChain::Mainnet).await?;
for vault in vaults {
println!("{}: {} (APY: {:.2}%)", vault.symbol, vault.name, vault.net_apy * 100.0);
}
Ok(())
}
use morpho_rs_api::{MorphoClient, MorphoClientConfig, NamedChain};
use alloy_primitives::{Address, U256};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = MorphoClientConfig::new()
.with_rpc_url("https://eth.llamarpc.com")
.with_private_key("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80");
let client = MorphoClient::with_config(config)?;
// API queries still work
let vaults = client.api().get_vaults_by_chain(NamedChain::Mainnet).await?;
// Plus transaction support
let vault: Address = "0x...".parse()?;
let amount = U256::from(1000000);
// V1 vault operations
let balance = client.vault_v1()?.balance(vault).await?;
client.vault_v1()?.deposit(vault, amount).await?;
Ok(())
}
use morpho_rs_api::{MorphoClient, VaultFiltersV1, NamedChain};
let client = MorphoClient::new();
// Build filters
let filters = VaultFiltersV1::new()
.chain(NamedChain::Mainnet)
.listed(true)
.min_apy(0.05); // 5% minimum APY
let vaults = client.api().v1.get_vaults(Some(filters)).await?;
use morpho_rs_api::{MorphoClient, MorphoClientConfig};
use alloy_primitives::{Address, U256};
let config = MorphoClientConfig::new()
.with_rpc_url("https://eth.llamarpc.com")
.with_private_key("0x...");
let client = MorphoClient::with_config(config)?;
let vault: Address = "0x...".parse()?;
let amount = U256::from(1000000);
// Deposit to V1 vault
client.vault_v1()?.deposit(vault, amount).await?;
// Withdraw from V2 vault
client.vault_v2()?.withdraw(vault, amount).await?;
use morpho_rs_api::{MorphoClient, NamedChain};
use alloy_primitives::Address;
let client = MorphoClient::new();
let user: Address = "0x...".parse()?;
// Query positions on all chains
let positions = client.api().get_user_vault_positions(user, None).await?;
println!("V1 positions: {}", positions.vault_positions.len());
println!("V2 positions: {}", positions.vault_v2_positions.len());
// Query positions on specific chain
let positions = client.api().get_user_vault_positions(user, Some(NamedChain::Base)).await?;
// Get complete account overview
let overview = client.api().get_user_account_overview(user, NamedChain::Mainnet).await?;
println!("Total assets USD: {:?}", overview.state.total_assets_usd);
| Chain | ID | Aliases |
|---|---|---|
| Ethereum | 1 | ethereum, eth, mainnet |
| Base | 8453 | base |
| Arbitrum | 42161 | arbitrum, arb |
| Optimism | 10 | optimism, op |
| Polygon | 137 | polygon, matic |
| Linea | 59144 | linea |
| Scroll | 534352 | scroll |
| Mode | 34443 | mode |
| Sonic | 146 | sonic |
| World Chain | 480 | worldchain |
| Fraxtal | 252 | fraxtal |
| Ink | 57073 | ink |
| Unichain | 130 | unichain |
| Corn | 21000000 | corn |
| Katana | 747474 | katana |
| Etherlink | 42793 | etherlink |
| Lisk | 1135 | lisk |
| Hyperliquid | 999 | hyperliquid |
| Sei | 1329 | sei |
| Monad | 143 | monad |
| Stable | 988 | stable |
| Cronos | 25 | cronos |
| Celo | 42220 | celo |
| Abstract | 2741 | abstract |
| Sepolia | 11155111 | sepolia (testnet) |
MorphoClient - Unified client with API + optional transaction supportMorphoClientConfig - Configuration builder for MorphoClientMorphoApiClient - Combined V1 + V2 API clientVaultV1Client - V1 vault query clientVaultV2Client - V2 vault query clientVaultV1Operations / VaultV2Operations - Transaction wrappersVault - Unified vault type (V1 or V2)VaultV1 / VaultV2 - Version-specific vault typesVaultStateV1 / VaultStateV2 - Vault state with APY, fees, allocationsNamedChain - Supported blockchain networks (from alloy-chains)Asset - Token informationUserVaultPositions - User's vault positionsUserAccountOverview - Complete user account stateVaultFiltersV1 - Filter builder for V1 vault queriesVaultFiltersV2 - Filter builder for V2 vault queriespub enum ApiError {
Request(reqwest::Error),
GraphQL(String),
Parse(String),
VaultNotFound { address: Address, chain_id: i64 },
InvalidAddress(String),
InvalidChainId(i64),
Contract(ContractError),
TransactionNotConfigured,
}
MIT