Expand description
eth-prices is a pricing library & routing engine for EVM assets.
This crate currently exposes protocol-specific quoters that can read a rate at a specific block height.
§Overview
Here is a simple example showing off some of the features of eth-prices:
use eth_prices::{quoter::Quoter, router::Router, asset::AssetIdentifier, network::Network, quoter::uniswap_v3::{UniswapV3Quoter, factory::UniswapV3Selector}};
use alloy::primitives::{address, U256};
use alloy::providers::{ProviderBuilder, Provider};
#[tokio::main]
pub async fn main() {
println!("Hello, world!");
let provider = ProviderBuilder::new().connect("https://ethereum-rpc.publicnode.com").await.unwrap().erased();
let selector = UniswapV3Selector::Pool { pool_address: address!("0x99ac8ca7087fa4a2a1fb6357269965a2014abc35") };
let quoter = UniswapV3Quoter::from_selector(&provider, selector).await.unwrap();
let router = Router::from_iter(vec![quoter.into()]);
let token_in = AssetIdentifier::try_from("0x2260fac5e5542a773aa44fbcfedf7c193bc2c599").unwrap();
let token_out = AssetIdentifier::try_from("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48").unwrap();
let route = router.compute(&token_in, &token_out).unwrap();
let block = provider.get_block_number().await.unwrap();
let network = Network::EVM(1, block, provider);
let amount = U256::from(1_000_000);
let quote = route.quote(&network, amount).await.unwrap();
println!("quote: {:?}", quote);
}Today, the main building blocks are:
quoter::Quoterfor single-hop quote sources.router::Routerfor routing between assets.asset::AssetIdentifierfor identifying ERC-20, fiat, and native assets.asset::Assetfor asset metadata and amount formatting helpers.
§Quoters
Currently supported quoters include:
quoter::fixedfor static conversion rates.quoter::uniswap_v2for Uniswap v2 pairs.quoter::uniswap_v3for Uniswap v3 pools.quoter::erc4626for ERC-4626 vaults.quoter::ecbfor European Central Bank (ECB) rates.
§Features
ecb- Enable European Central Bank (ECB) quoters.
§Routing
Use the router::Router struct to compute a route and quote the rate.
§Examples
You can find more examples in the examples directory.
Re-exports§
pub use error::EthPricesError;pub use error::Result;