eth_prices/lib.rs
1/*!
2`eth-prices` is a pricing library & routing engine for EVM assets.
3
4This crate currently exposes protocol-specific quoters that can read a rate at a
5specific block height.
6
7# Overview
8
9Here is a simple example showing off some of the features of `eth-prices`:
10```rust
11use eth_prices::{quoter::Quoter, router::Router, asset::AssetIdentifier, network::Network, quoter::uniswap_v3::{UniswapV3Quoter, factory::UniswapV3Selector}};
12use alloy::primitives::{address, U256};
13use alloy::providers::{ProviderBuilder, Provider};
14
15#[tokio::main]
16pub async fn main() {
17 println!("Hello, world!");
18 let provider = ProviderBuilder::new().connect("https://ethereum-rpc.publicnode.com").await.unwrap().erased();
19 let selector = UniswapV3Selector::Pool { pool_address: address!("0x99ac8ca7087fa4a2a1fb6357269965a2014abc35") };
20 let quoter = UniswapV3Quoter::from_selector(&provider, selector).await.unwrap();
21 let router = Router::from_iter(vec![quoter.into()]);
22
23 let token_in = AssetIdentifier::try_from("0x2260fac5e5542a773aa44fbcfedf7c193bc2c599").unwrap();
24 let token_out = AssetIdentifier::try_from("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48").unwrap();
25 let route = router.compute(&token_in, &token_out).unwrap();
26
27 let block = provider.get_block_number().await.unwrap();
28 let network = Network::EVM(1, block, provider);
29 let amount = U256::from(1_000_000);
30 let quote = route.quote(&network, amount).await.unwrap();
31
32 println!("quote: {:?}", quote);
33}
34```
35
36Today, the main building blocks are:
37- [`quoter::Quoter`] for single-hop quote sources.
38- [`router::Router`] for routing between assets.
39- [`asset::AssetIdentifier`] for identifying ERC-20, fiat, and native assets.
40- [`asset::Asset`] for asset metadata and amount formatting helpers.
41
42# Quoters
43
44Currently supported quoters include:
45- [`quoter::fixed`] for static conversion rates.
46- [`quoter::uniswap_v2`] for Uniswap v2 pairs.
47- [`quoter::uniswap_v3`] for Uniswap v3 pools.
48- [`quoter::erc4626`] for ERC-4626 vaults.
49- [`quoter::ecb`] for European Central Bank (ECB) rates.
50
51# Features
52
53- `ecb` - Enable European Central Bank (ECB) quoters.
54
55# Routing
56
57Use the [`router::Router`] struct to compute a route and quote the rate.
58
59# Examples
60
61You can find more examples in the [examples](https://github.com/v3xlabs/eth-prices/tree/master/examples) directory.
62*/
63
64pub mod error;
65pub use error::{EthPricesError, Result};
66
67pub mod asset;
68pub mod config;
69pub mod network;
70pub mod quoter;
71pub mod router;
72
73#[cfg(target_arch = "wasm32")]
74pub mod js;
75
76#[cfg(test)]
77pub mod tests;