metrom_resolver_commons/
lib.rs

1use alloy::primitives::{Address, U256};
2use metrom_commons::{
3    subgraphs::SerdeU256,
4    types::{amm::Amm, amm_pool_liquidity_type::AmmPoolLiquidityType},
5};
6use serde::{Deserialize, Serialize};
7
8#[derive(Serialize, Deserialize, Debug, Clone)]
9#[serde(rename_all = "camelCase")]
10pub struct Token {
11    pub decimals: i32,
12    pub symbol: String,
13    pub name: String,
14}
15
16#[derive(Serialize, Deserialize, Debug, Clone)]
17#[serde(rename_all = "camelCase")]
18pub struct TokenWithAddress {
19    pub address: Address,
20    pub decimals: i32,
21    pub symbol: String,
22    pub name: String,
23}
24
25#[derive(Serialize, Deserialize, Debug, Clone)]
26#[serde(rename_all = "camelCase")]
27pub struct AmmPool {
28    pub dex: String,
29    pub amm: Amm,
30    pub liquidity_type: AmmPoolLiquidityType,
31    pub tokens: Vec<TokenWithAddress>,
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub fee: Option<f64>,
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub usd_tvl: Option<f64>,
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub liquidity: Option<U256>,
38}
39
40impl AmmPool {
41    pub fn supports_weighting(&self) -> bool {
42        match self.amm {
43            Amm::AlgebraIntegral | Amm::UniswapV3 => true,
44            Amm::Velodrome => self.liquidity_type == AmmPoolLiquidityType::Concentrated,
45            _ => false,
46        }
47    }
48}
49
50#[derive(Serialize, Deserialize, Debug, Clone)]
51#[serde(rename_all = "camelCase")]
52pub struct LiquityV2Collateral {
53    pub decimals: i32,
54    pub symbol: String,
55    pub name: String,
56    pub tvl: SerdeU256,
57    pub usd_tvl: f64,
58    pub usd_price: f64,
59    pub minted_debt: f64,
60    pub stability_pool_debt: f64,
61}
62
63#[derive(Serialize, Deserialize, Debug, Clone)]
64#[serde(rename_all = "camelCase")]
65pub struct GmxV1Collateral {
66    pub decimals: i32,
67    pub symbol: String,
68    pub name: String,
69    pub tvl: U256,
70    pub usd_tvl: f64,
71    pub usd_price: f64,
72}
73
74#[derive(Serialize, Deserialize, Clone, Debug)]
75#[serde(rename_all = "camelCase")]
76pub struct ResolveTokensQuery {
77    pub with_usd_prices: Option<bool>,
78}
79
80#[derive(Serialize, Deserialize, Clone, Debug)]
81#[serde(rename_all = "camelCase")]
82pub struct ResolveAmmPoolsQuery {
83    pub with_usd_tvls: Option<bool>,
84    pub with_liquidity: Option<bool>,
85}