Skip to main content

Crate eth_prices

Crate eth_prices 

Source
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:

§Quoters

Currently supported quoters include:

§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;

Modules§

asset
Token metadata and identifier helpers.
config
error
network
quoter
Quote sources for converting one asset into another at a given block height.
router