use crate::{
domain::market::{Identifier, Label},
error::{Error, ValidationError},
};
use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
#[serde(try_from = "u32", into = "u32")]
pub struct StablecoinId(u32);
impl StablecoinId {
pub fn new(value: u32) -> Result<Self, Error> {
if value == 0 {
return Err(ValidationError::InvalidMarketIdentity.into());
}
Ok(Self(value))
}
#[must_use]
pub const fn get(self) -> u32 {
self.0
}
}
impl TryFrom<u32> for StablecoinId {
type Error = Error;
fn try_from(v: u32) -> Result<Self, Error> {
Self::new(v)
}
}
impl From<StablecoinId> for u32 {
fn from(v: StablecoinId) -> Self {
v.0
}
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(tag = "scope", content = "chain", rename_all = "snake_case")]
pub enum TvlScope {
All,
Chain(Label),
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct StablecoinScope {
chain: Option<Label>,
asset: Option<StablecoinId>,
}
impl StablecoinScope {
#[must_use]
pub const fn new(chain: Option<Label>, asset: Option<StablecoinId>) -> Self {
Self { chain, asset }
}
#[must_use]
pub const fn chain(&self) -> &Option<Label> {
&self.chain
}
#[must_use]
pub const fn asset(&self) -> Option<StablecoinId> {
self.asset
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum AnalyticsMetric {
DexVolume,
Fees,
Revenue,
HoldersRevenue,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct AnalyticsRequest {
protocol: Identifier,
metric: AnalyticsMetric,
}
impl AnalyticsRequest {
#[must_use]
pub const fn new(protocol: Identifier, metric: AnalyticsMetric) -> Self {
Self { protocol, metric }
}
#[must_use]
pub const fn protocol(&self) -> &Identifier {
&self.protocol
}
#[must_use]
pub const fn metric(&self) -> AnalyticsMetric {
self.metric
}
}