pub struct MorphoClient { /* private fields */ }Expand description
Unified Morpho client combining API queries and on-chain transactions.
This client provides a namespace-style API for interacting with Morpho vaults:
client.api()- Access to GraphQL API queriesclient.vault_v1()- V1 vault transaction operationsclient.vault_v2()- V2 vault transaction operations
§Example
use morpho_rs_api::{MorphoClient, MorphoClientConfig, Chain};
use alloy::primitives::{Address, U256};
#[tokio::main]
async fn main() -> Result<(), morpho_rs_api::ApiError> {
// API-only client
let client = MorphoClient::new();
let vaults = client.get_vaults_by_chain(Chain::EthMainnet).await?;
// Full client with transaction support
let config = MorphoClientConfig::new()
.with_rpc_url("https://eth.llamarpc.com")
.with_private_key("0x...");
let client = MorphoClient::with_config(config)?;
// V1 vault operations
let vault: Address = "0x...".parse().unwrap();
let balance = client.vault_v1()?.balance(vault).await?;
Ok(())
}Implementations§
Source§impl MorphoClient
impl MorphoClient
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new MorphoClient with default API configuration (no transaction support).
Sourcepub fn with_config(config: MorphoClientConfig) -> Result<Self>
pub fn with_config(config: MorphoClientConfig) -> Result<Self>
Create a MorphoClient with custom configuration.
If both rpc_url and private_key are provided, transaction support is enabled.
Sourcepub fn vault_v1(&self) -> Result<VaultV1Operations<'_>>
pub fn vault_v1(&self) -> Result<VaultV1Operations<'_>>
Get V1 vault operations.
Returns an error if transaction support is not configured.
Sourcepub fn vault_v2(&self) -> Result<VaultV2Operations<'_>>
pub fn vault_v2(&self) -> Result<VaultV2Operations<'_>>
Get V2 vault operations.
Returns an error if transaction support is not configured.
Sourcepub fn api(&self) -> &MorphoApiClient
pub fn api(&self) -> &MorphoApiClient
Get the API client for GraphQL queries.
Sourcepub async fn get_vaults_by_chain(&self, chain: Chain) -> Result<Vec<Vault>>
pub async fn get_vaults_by_chain(&self, chain: Chain) -> Result<Vec<Vault>>
Get vaults (V1 and V2) on a specific chain as unified Vault type.
Sourcepub async fn get_whitelisted_vaults(
&self,
chain: Option<Chain>,
) -> Result<Vec<Vault>>
pub async fn get_whitelisted_vaults( &self, chain: Option<Chain>, ) -> Result<Vec<Vault>>
Get whitelisted vaults (V1 and V2) as unified Vault type.
Sourcepub async fn get_user_vault_positions(
&self,
address: &str,
chain: Option<Chain>,
) -> Result<UserVaultPositions>
pub async fn get_user_vault_positions( &self, address: &str, chain: Option<Chain>, ) -> Result<UserVaultPositions>
Get all vault positions (V1 and V2) for a user.
Sourcepub async fn get_user_account_overview(
&self,
address: &str,
chain: Chain,
) -> Result<UserAccountOverview>
pub async fn get_user_account_overview( &self, address: &str, chain: Chain, ) -> Result<UserAccountOverview>
Get complete account overview for a user on a specific chain.
Sourcepub fn has_transaction_support(&self) -> bool
pub fn has_transaction_support(&self) -> bool
Check if transaction support is configured.
Sourcepub fn signer_address(&self) -> Option<Address>
pub fn signer_address(&self) -> Option<Address>
Get the signer’s address if transaction support is configured.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MorphoClient
impl !RefUnwindSafe for MorphoClient
impl Send for MorphoClient
impl Sync for MorphoClient
impl Unpin for MorphoClient
impl !UnwindSafe for MorphoClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more