loom_rpc_handler/dto/
pool.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
use alloy_primitives::{Address, U256};

use serde::{Deserialize, Serialize};
use utoipa::openapi::schema::SchemaType;
use utoipa::openapi::{Array, Object, ToArray, Type};
use utoipa::PartialSchema;
use utoipa::{schema, ToSchema};

#[derive(Debug, Serialize, ToSchema)]
pub struct PoolResponse {
    pub pools: Vec<Pool>,
    pub total: usize,
}

#[derive(Debug, Serialize, ToSchema)]
pub struct PoolDetailsResponse {
    #[schema(schema_with = String::schema)]
    pub address: Address,
    pub protocol: PoolProtocol,
    pub pool_class: PoolClass,
    #[schema(schema_with = String::schema)]
    pub fee: U256,
    #[schema(schema_with = array_of_strings)]
    pub tokens: Vec<Address>,
}

#[derive(Debug, Serialize, ToSchema)]
pub struct Pool {
    #[schema(schema_with = String::schema)]
    pub address: Address,
    #[schema(schema_with = String::schema)]
    pub fee: U256,
    #[schema(schema_with = array_of_strings)]
    pub tokens: Vec<Address>,
    pub protocol: PoolProtocol,
    pub pool_class: PoolClass,
}

pub fn array_of_strings() -> Array {
    Object::with_type(SchemaType::Type(Type::String)).to_array()
}

#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum PoolClass {
    Unknown,
    UniswapV2,
    UniswapV3,
    Curve,
    LidoStEth,
    LidoWstEth,
    RocketPool,
    Custom(u64),
}
impl From<loom_types_entities::PoolClass> for PoolClass {
    fn from(pool_class: loom_types_entities::PoolClass) -> Self {
        match pool_class {
            loom_types_entities::PoolClass::Unknown => PoolClass::Unknown,
            loom_types_entities::PoolClass::UniswapV2 => PoolClass::UniswapV2,
            loom_types_entities::PoolClass::UniswapV3 => PoolClass::UniswapV3,
            loom_types_entities::PoolClass::Curve => PoolClass::Curve,
            loom_types_entities::PoolClass::LidoStEth => PoolClass::LidoStEth,
            loom_types_entities::PoolClass::LidoWstEth => PoolClass::LidoWstEth,
            loom_types_entities::PoolClass::RocketPool => PoolClass::RocketPool,
            loom_types_entities::PoolClass::Custom(id) => PoolClass::Custom(id),
        }
    }
}

#[derive(Debug, Deserialize, Serialize, ToSchema)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum PoolProtocol {
    Unknown,
    UniswapV2,
    UniswapV2Like,
    NomiswapStable,
    Sushiswap,
    SushiswapV3,
    DooarSwap,
    Safeswap,
    Miniswap,
    Shibaswap,
    UniswapV3,
    UniswapV3Like,
    PancakeV3,
    Integral,
    Maverick,
    Curve,
    LidoStEth,
    LidoWstEth,
    RocketEth,
    OgPepe,
    Custom(u64),
}
impl From<loom_types_entities::PoolProtocol> for PoolProtocol {
    fn from(protocol: loom_types_entities::PoolProtocol) -> Self {
        match protocol {
            loom_types_entities::PoolProtocol::Unknown => PoolProtocol::Unknown,
            loom_types_entities::PoolProtocol::UniswapV2 => PoolProtocol::UniswapV2,
            loom_types_entities::PoolProtocol::UniswapV2Like => PoolProtocol::UniswapV2Like,
            loom_types_entities::PoolProtocol::NomiswapStable => PoolProtocol::NomiswapStable,
            loom_types_entities::PoolProtocol::Sushiswap => PoolProtocol::Sushiswap,
            loom_types_entities::PoolProtocol::SushiswapV3 => PoolProtocol::SushiswapV3,
            loom_types_entities::PoolProtocol::DooarSwap => PoolProtocol::DooarSwap,
            loom_types_entities::PoolProtocol::Safeswap => PoolProtocol::Safeswap,
            loom_types_entities::PoolProtocol::Miniswap => PoolProtocol::Miniswap,
            loom_types_entities::PoolProtocol::Shibaswap => PoolProtocol::Shibaswap,
            loom_types_entities::PoolProtocol::UniswapV3 => PoolProtocol::UniswapV3,
            loom_types_entities::PoolProtocol::UniswapV3Like => PoolProtocol::UniswapV3Like,
            loom_types_entities::PoolProtocol::PancakeV3 => PoolProtocol::PancakeV3,
            loom_types_entities::PoolProtocol::Integral => PoolProtocol::Integral,
            loom_types_entities::PoolProtocol::Maverick => PoolProtocol::Maverick,
            loom_types_entities::PoolProtocol::Curve => PoolProtocol::Curve,
            loom_types_entities::PoolProtocol::LidoStEth => PoolProtocol::LidoStEth,
            loom_types_entities::PoolProtocol::LidoWstEth => PoolProtocol::LidoWstEth,
            loom_types_entities::PoolProtocol::RocketEth => PoolProtocol::RocketEth,
            loom_types_entities::PoolProtocol::OgPepe => PoolProtocol::OgPepe,
            loom_types_entities::PoolProtocol::Custom(id) => PoolProtocol::Custom(id),
        }
    }
}

impl From<&PoolProtocol> for loom_types_entities::PoolProtocol {
    fn from(protocol: &PoolProtocol) -> Self {
        match protocol {
            PoolProtocol::Unknown => loom_types_entities::PoolProtocol::Unknown,
            PoolProtocol::UniswapV2 => loom_types_entities::PoolProtocol::UniswapV2,
            PoolProtocol::UniswapV2Like => loom_types_entities::PoolProtocol::UniswapV2Like,
            PoolProtocol::NomiswapStable => loom_types_entities::PoolProtocol::NomiswapStable,
            PoolProtocol::Sushiswap => loom_types_entities::PoolProtocol::Sushiswap,
            PoolProtocol::SushiswapV3 => loom_types_entities::PoolProtocol::SushiswapV3,
            PoolProtocol::DooarSwap => loom_types_entities::PoolProtocol::DooarSwap,
            PoolProtocol::Safeswap => loom_types_entities::PoolProtocol::Safeswap,
            PoolProtocol::Miniswap => loom_types_entities::PoolProtocol::Miniswap,
            PoolProtocol::Shibaswap => loom_types_entities::PoolProtocol::Shibaswap,
            PoolProtocol::UniswapV3 => loom_types_entities::PoolProtocol::UniswapV3,
            PoolProtocol::UniswapV3Like => loom_types_entities::PoolProtocol::UniswapV3Like,
            PoolProtocol::PancakeV3 => loom_types_entities::PoolProtocol::PancakeV3,
            PoolProtocol::Integral => loom_types_entities::PoolProtocol::Integral,
            PoolProtocol::Maverick => loom_types_entities::PoolProtocol::Maverick,
            PoolProtocol::Curve => loom_types_entities::PoolProtocol::Curve,
            PoolProtocol::LidoStEth => loom_types_entities::PoolProtocol::LidoStEth,
            PoolProtocol::LidoWstEth => loom_types_entities::PoolProtocol::LidoWstEth,
            PoolProtocol::RocketEth => loom_types_entities::PoolProtocol::RocketEth,
            PoolProtocol::OgPepe => loom_types_entities::PoolProtocol::OgPepe,
            PoolProtocol::Custom(id) => loom_types_entities::PoolProtocol::Custom(*id),
        }
    }
}

#[derive(Debug, Serialize, ToSchema)]
pub struct MarketStats {
    pub total_pools: usize,
}