metrom_resolver_commons/
lib.rs1use 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
10pub 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))]
18pub struct TokenWithAddress {
20 pub address: Address,
22 #[cfg_attr(feature = "utoipa", schema(example = 18))]
23 pub decimals: i32,
25 #[cfg_attr(feature = "utoipa", schema(example = "Foo"))]
26 pub symbol: String,
28 #[cfg_attr(feature = "utoipa", schema(example = "Foobar"))]
29 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 pub dex: String,
40 #[cfg_attr(feature = "utoipa", schema(example = "uniswap-v3"))]
41 pub amm: Amm,
43 #[cfg_attr(feature = "utoipa", schema(example = "concentrated"))]
44 pub liquidity_type: AmmPoolLiquidityType,
46 pub tokens: Vec<TokenWithAddress>,
48 #[serde(skip_serializing_if = "Option::is_none")]
49 pub fee: Option<f64>,
51 #[serde(skip_serializing_if = "Option::is_none")]
52 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 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}