caelum0x 1fa82f19ea feat: close Python/Rust VaultClient pool-stats parity gap, fix stale anvil-deploy tests
@qie-forge/core's TS VaultClient already exposed getLiquidationBonusBps/
getLenderShares/getPoolStats (totalAssets/totalReserves/protocolReserves/
totalDebtPrincipal/borrowCap/reserveFactorBps/totalLenderShares/
lenderShares) — Python's and Rust's VaultClient never did, a real
cross-language parity gap flagged but deliberately left open by the
previous pass. Ported the same methods to packages/python/qie_forge/
vault.py and packages/rust/src/vault.rs.

While wiring these up, found both SDKs' own "proven against real
deployed bytecode" integration tests (tests/test_anvil_integration.py,
tests/anvil_integration.rs) had been silently broken since an earlier
same-day pass grew QieForgeVault's constructor from 7 to 11 args
(liquidationBonusMaxBps/treasury/reserveFactorBps/borrowCap) without
updating either test's deploy call — confirmed via a pre-fix run
(Python: `TypeError: Incorrect argument count`, Rust:
`DecodingError(InvalidData)`). Fixed both deploy calls and extended
both tests to assert the new pool-stats/liquidation-bonus fields
against real on-chain state.

Verified live: Rust `cargo test --test anvil_integration` 2/2 pass
against real deployed bytecode on a local anvil devnet; Python
`pytest` 15 passed/8 skipped (skips are live-network tests gated
behind QIE_FORGE_RUN_LIVE_TESTS). Rust `cargo build`/`cargo clippy`
clean, no new warnings.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-29 13:01:41 +03:00
..

qie-forge (Rust SDK)

Rust client (ethers-rs-based) mirroring @qie-forge/core / the Python qie_forge package: a real chain client, the real (corrected) QIE Oracle ABI via abigen!, a fail-closed QUSDC helper, pure AMM quote math, an on-chain reserve-reading/quote path (get_reserves/get_amounts_out_onchain), unsigned swap-tx building, and a read-only VaultClient.

Build & test

cargo build
cargo test                                   # unit + local-anvil integration tests
QIE_FORGE_RUN_LIVE_TESTS=1 cargo test --test live_chain -- --nocapture
  • src/amm.rs, src/networks.rs, src/qusdc.rs — unit tests (#[cfg(test)] mod tests), no network.
  • tests/anvil_integration.rs — deploys the REAL compiled packages/contracts bytecode (MockERC20 ×2, MockAggregatorV3 ×2, QieOracleAdapter, QieForgeVault, QieForgeFactory, QieForgeRouter — loaded straight from forge build's own out/ artifacts, never re-implemented) to a local anvil devnet via ethers-rs's ContractFactory, then proves the Rust SDK's VaultClient::get_position() matches a hand-calculated health factor and get_amounts_out_onchain() matches the deployed router's own getAmountsOut() call exactly, and that the unsigned tx build_swap_exact_tokens_for_tokens_tx() builds actually executes on-chain. Requires anvil (Foundry) on PATH; skips cleanly (prints a message, does not fail) if it isn't installed. Mirrors packages/python/tests/test_anvil_integration.py's exact pattern and rigor.
  • tests/live_chain.rs — real calls against https://testnet.qie.digital/api/eth-rpc (chain 1983) and https://rpc1mainnet.qie.digital (chain 1990), gated behind QIE_FORGE_RUN_LIVE_TESTS=1 checked at runtime (tests no-op cleanly without it, so cargo test alone stays offline-safe).

15/15 tests pass as of 2026-10-27 (9 unit + 2 local-anvil integration + 4 live-stub). The two anvil tests share a process-wide mutex so they run sequentially even under cargo test's default per-binary thread concurrency — each spins up its own real anvil devnet and sends several real transactions, and running both at once was observed to occasionally starve one node's RPC responsiveness on a loaded machine (a resource-contention flake, not a logic bug).

Usage

use qie_forge::{ChainClient, OracleClient, QieNetwork};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let chain = ChainClient::new(&QieNetwork::Mainnet, None)?;
    let snapshot = chain.get_snapshot().await?;
    println!("{snapshot:?}");

    let oracle = OracleClient::new(&chain, vec!["mainnet"]);
    let btc = oracle.get_price("BTC").await?;
    println!("{} = ${:.2} ({})", btc.asset, btc.human_price(), btc.description);
    Ok(())
}
use qie_forge::vault::VaultClient;
use qie_forge::{ChainClient, QieNetwork};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let chain = ChainClient::new(&QieNetwork::Mainnet, None)?;
    let vault = VaultClient::new(&chain, "0x0000000000000000000000000000000000000000")?;
    let position = vault.get_position("0x0000000000000000000000000000000000000000").await?;
    println!("{position:?}");
    Ok(())
}

Known scope gaps

None remaining as of 2026-10-27: tests/anvil_integration.rs closed the local-anvil contract-deployment gap tracked here and in docs/STATUS.md — the Rust SDK now has the same proof the Python SDK had (see "Build & test" above).