metaflux-client 0.2.0

Rust SDK for the MetaFlux derivatives L1 — REST + WebSocket, EIP-712 signing, and typed builders for the full signed-action surface (orders, TWAP, margin, vaults, staking, spot/Earn).
Documentation
//! Create a user vault, query its NAV.
//!
//! Requires `MTF_PRIVATE_KEY` env var. Run with:
//!
//! ```bash
//! MTF_PRIVATE_KEY=0x... cargo run --example create_vault
//! ```

use metaflux_client::{
    Client,
    types::VaultId,
    types::vault::{CreateVault, VaultKind},
    wallet::Wallet,
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let priv_hex = std::env::var("MTF_PRIVATE_KEY")
        .map_err(|_| "set MTF_PRIVATE_KEY=<64-char hex> to run this example")?;
    let wallet = Wallet::from_hex(&priv_hex)?;
    let client = Client::new("https://devnet-gateway.mtf.exchange")?;

    // The signing wallet becomes the vault leader.
    let create = CreateVault {
        name: "my-vault".into(),
        lock_period_secs: 4 * 86_400, // 4-day follower lock
        parent: None,
        kind: VaultKind::User,
    };
    let resp = client.exchange().create_vault(&wallet, &create).await?;
    println!("create_vault response: {resp:?}");

    // Try to query the newly created vault's NAV.
    // The action response typically carries the assigned vault_id; we
    // demonstrate the info call against vault_id = 1 here.
    let nav = client.rest().info().vault_state(VaultId(1)).await?;
    println!("vault state: {nav:?}");
    Ok(())
}