eth-prices 1.1.0

A library for fetching Ethereum prices.
Documentation

[!IMPORTANT] eth-prices aims to provide Ethereum price estimation only. It is not intended for, nor does it provide guarantees of, exchange rates.

Quickstart

cargo add eth-prices
use eth_prices::{
    quoter::{Quoter, RateDirection},
    asset::Asset,
};

// Define your data sources
let quoter = vec![
    UniswapV2Quoter::from_selector(provider, UniswapV2Selector::Pair { pair_address }).await,
    UniswapV3Quoter::from_selector(provider, UniswapV3Selector::Pool { pool_address }).await,
    ERC4626Quoter::new(vault_address, provider).await,
    FixedQuoter::new(fixed_rate, provider).await,
];

// Create a router
let router = QuoterGraph::new(quoters);

// Compute a route
let token_in = TokenIdentifier::ERC20 { address: address!("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48") };
let token_out = TokenIdentifier::Fiat { symbol: "usd".to_string() };
let route = router.compute(&token_in, &token_out).await.unwrap();

// Get the latest block number
let block = provider.get_block_number().await.unwrap();

// Quote the rate
let quote = route.quote(block, amount_in).await.unwrap();

Data Sources

Currently supported data sources include:

Examples

This crate has a few examples you can toy around with:

Autorouter Evaluation

The live evaluation suite in bench compares the Rust and TypeScript autorouters at the same Ethereum block against six keyless USD price sources. Run it with just eval. Results are written to target/evals/.

Documentation

You can read the documentation at docs.rs/eth-prices.