gweiyser/
lib.rs

1use alloy::network::Network;
2use alloy::primitives::Address;
3use alloy::providers::Provider;
4use alloy::transports::Transport;
5use protocols::uniswap::v3::quoter::UniswapV3Quoter;
6use std::marker::PhantomData;
7use std::sync::Arc;
8
9use crate::protocols::uniswap::v2::{UniswapV2Factory, UniswapV2Pool, UniswapV2Router};
10use crate::protocols::uniswap::v3::{UniswapV3Factory, UniswapV3Pool, UniswapV3Router};
11use crate::token::Token;
12
13// modules defines
14pub mod addresses;
15pub mod protocols;
16mod sync_pools;
17mod token;
18pub mod util;
19
20#[derive(Clone, Copy, PartialEq)]
21pub enum Chain {
22    Ethereum,
23    Base,
24}
25
26pub struct Gweiyser<P, T, N>
27where
28    P: Provider<T, N>,
29    T: Transport + Clone,
30    N: Network,
31{
32    http: Arc<P>,
33    chain: Chain,
34    _phantom: PhantomData<(T, N)>,
35}
36
37impl<P, T, N> Gweiyser<P, T, N>
38where
39    P: Provider<T, N>,
40    T: Transport + Clone,
41    N: Network,
42{
43    /// Construct a new Gweisyer
44    pub fn new(http_provider: Arc<P>, chain: Chain) -> Self {
45        Self {
46            http: http_provider,
47            chain,
48            _phantom: PhantomData,
49        }
50    }
51
52    // Construct an new token
53    pub async fn token(&self, address: Address) -> Token<P, T, N> {
54        // Just delegate the call to the token object
55        Token::new(address, self.http.clone()).await
56    }
57
58    /// Construct a new uniswapv2 pool
59    pub async fn uniswap_v2_pool(&self, address: Address) -> UniswapV2Pool<P, T, N> {
60        UniswapV2Pool::new(address, self.http.clone()).await
61    }
62
63    /// Construct a new uniswapv2 router
64    pub fn uniswap_v2_router(&self) -> UniswapV2Router<P, T, N> {
65        UniswapV2Router::new(self.http.clone(), self.chain)
66    }
67
68    /// Construct a new uniswapv2 factory
69    pub fn uniswap_v2_factory(&self) -> UniswapV2Factory<P, T, N> {
70        UniswapV2Factory::new(self.http.clone(), self.chain)
71    }
72
73    /// Construct a new uniswapv3 pool
74    pub async fn uniswap_v3_pool(&self, address: Address) -> UniswapV3Pool<P, T, N> {
75        UniswapV3Pool::new(address, self.http.clone()).await
76    }
77
78    /// Construct a new uniswapv3 factory
79    pub fn uniswap_v3_factory(&self) -> UniswapV3Factory<P, T, N> {
80        UniswapV3Factory::new(self.http.clone(), self.chain)
81    }
82
83    /// Construct a new uniswapv3 quoter
84    pub fn uniswap_v3_quoter(&self) -> UniswapV3Quoter<P, T, N> {
85        UniswapV3Quoter::new(self.http.clone(), self.chain)
86    }
87
88    /// Construct a new uniswapv3 router
89    pub fn uniswap_v3_router(&self) -> UniswapV3Router<P, T, N> {
90        UniswapV3Router::new(self.http.clone(), self.chain)
91    }
92
93
94}