morpho-rs-contracts
Contract bindings and transaction clients for Morpho V1 (MetaMorpho) and V2 vaults.
Installation
Features
- VaultV1TransactionClient - Execute transactions against MetaMorpho (V1) vaults
- VaultV2TransactionClient - Execute transactions against V2 vaults
- ERC20/ERC4626 bindings - Solidity interface bindings via
alloy::sol! - HttpProvider - Type alias for RPC connections using alloy
Usage
Creating a Transaction Client
use ;
// V1 (MetaMorpho) vaults
let v1_client = new?;
// V2 vaults
let v2_client = new?;
Querying Balance and Allowance
use ;
let vault: Address = "0x...".parse?;
let token: Address = "0x...".parse?;
let owner = client.signer_address;
// Get underlying asset address
let asset = client.get_asset.await?;
// Get token balance
let balance = client.get_balance.await?;
// Get approval allowance
let allowance = client.get_allowance.await?;
// Get token decimals
let decimals = client.get_decimals.await?;
Executing Deposit and Withdraw
use ;
let vault: Address = "0x...".parse?;
let amount = U256from; // Amount in smallest units
let receiver = client.signer_address;
// Approve the vault to spend tokens (if needed)
let approval_receipt = client.approve_if_needed.await?;
// Deposit assets into the vault
let deposit_receipt = client.deposit.await?;
println!;
// Withdraw assets from the vault
let withdraw_receipt = client.withdraw.await?;
println!;
Public API
Types
VaultV1TransactionClient- Transaction client for V1 vaultsVaultV2TransactionClient- Transaction client for V2 vaultsHttpProvider- HTTP provider type aliasContractError- Error type for contract operationsResult<T>- Result type alias
VaultV1TransactionClient / VaultV2TransactionClient Methods
| Method | Description |
|---|---|
new(rpc_url, private_key) |
Create a new transaction client |
signer_address() |
Get the signer's address |
get_asset(vault) |
Get the underlying asset address |
get_decimals(token) |
Get token decimals |
get_balance(token, owner) |
Get token balance |
get_allowance(token, owner, spender) |
Get approval allowance |
approve_if_needed(token, spender, amount) |
Approve if current allowance insufficient |
deposit(vault, amount, receiver) |
Deposit assets into vault |
withdraw(vault, amount, receiver, owner) |
Withdraw assets from vault |
Error Types
License
MIT