metrom_resolver_commons/
lib.rs

1use std::collections::HashMap;
2
3use alloy::primitives::U256;
4use metrom_commons::types::{
5    address::Address, amm::Amm, amm_pool_liquidity_type::AmmPoolLiquidityType,
6    chain_type::ChainType,
7};
8use serde::{Deserialize, Serialize};
9
10// reexport this stuff
11pub use metrom_chain_adapter_commons::Token;
12
13pub type ByChainTypeAndId<I> = HashMap<ChainType, HashMap<i32, I>>;
14
15#[derive(Serialize, Deserialize, Debug, Clone)]
16#[serde(rename_all = "camelCase")]
17#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
18/// A token metadata with address representation
19pub struct TokenWithAddress {
20    /// The token address
21    pub address: Address,
22    #[cfg_attr(feature = "utoipa", schema(example = 18))]
23    /// Number of decimals the token uses
24    pub decimals: i32,
25    #[cfg_attr(feature = "utoipa", schema(example = "Foo"))]
26    /// The symbol of the token
27    pub symbol: String,
28    #[cfg_attr(feature = "utoipa", schema(example = "Foobar"))]
29    /// The name of the token
30    pub name: String,
31}
32
33#[derive(Serialize, Deserialize, Debug, Clone)]
34#[serde(rename_all = "camelCase")]
35#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
36pub struct AmmPool {
37    #[cfg_attr(feature = "utoipa", schema(example = "uniswap-v3"))]
38    /// The pool's dex
39    pub dex: String,
40    #[cfg_attr(feature = "utoipa", schema(example = "uniswap-v3"))]
41    /// The pool's AMM
42    pub amm: Amm,
43    #[cfg_attr(feature = "utoipa", schema(example = "concentrated"))]
44    /// The pool's liquidity type
45    pub liquidity_type: AmmPoolLiquidityType,
46    /// The pool's tokens
47    pub tokens: Vec<TokenWithAddress>,
48    #[serde(skip_serializing_if = "Option::is_none")]
49    /// The pool's fee
50    pub fee: Option<f64>,
51    #[serde(skip_serializing_if = "Option::is_none")]
52    /// The pool's USD TVL
53    pub usd_tvl: Option<f64>,
54    #[serde(skip_serializing_if = "Option::is_none")]
55    #[cfg_attr(feature = "utoipa", schema(value_type = String, example = "100288918"))]
56    /// The pool's liquidity
57    pub liquidity: Option<U256>,
58}
59
60impl AmmPool {
61    pub fn supports_weighting(&self) -> bool {
62        match self.amm {
63            Amm::AlgebraIntegral | Amm::UniswapV3 | Amm::PancakeV3 => true,
64            Amm::Velodrome => self.liquidity_type == AmmPoolLiquidityType::Concentrated,
65            _ => false,
66        }
67    }
68}
69
70#[derive(Serialize, Deserialize, Debug, Clone)]
71#[serde(rename_all = "camelCase")]
72pub struct LiquityV2Collateral {
73    pub decimals: i32,
74    pub symbol: String,
75    pub name: String,
76    pub tvl: U256,
77    pub usd_tvl: f64,
78    pub usd_price: f64,
79    pub minted_debt: f64,
80    pub stability_pool_debt: f64,
81}
82
83#[derive(Serialize, Deserialize, Debug, Clone)]
84#[serde(rename_all = "camelCase")]
85pub struct GmxV1Collateral {
86    pub decimals: i32,
87    pub symbol: String,
88    pub name: String,
89    pub tvl: U256,
90    pub usd_tvl: f64,
91    pub usd_price: f64,
92}
93
94#[derive(Serialize, Deserialize, Clone, Debug)]
95#[serde(rename_all = "camelCase")]
96pub struct ResolveTokensQuery {
97    pub with_usd_prices: Option<bool>,
98}
99
100#[derive(Serialize, Deserialize, Clone, Debug)]
101#[serde(rename_all = "camelCase")]
102pub struct ResolveAmmPoolsQuery {
103    pub with_usd_tvls: Option<bool>,
104    pub with_liquidity: Option<bool>,
105}