#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Deserialize, serde::Serialize)]
pub enum CurveVariant {
StableSwapV0,
StableSwapV1,
StableSwapV2,
StableSwapSTETH,
StableSwapALend,
StableSwapNG,
StableSwapMeta,
TwoCryptoV1,
TwoCryptoNG,
TwoCryptoStable,
TriCryptoV1,
TriCryptoNG,
}
impl CurveVariant {
pub fn as_str(&self) -> &'static str {
match self {
Self::StableSwapV0 => "StableSwapV0",
Self::StableSwapV1 => "StableSwapV1",
Self::StableSwapV2 => "StableSwapV2",
Self::StableSwapSTETH => "StableSwapSTETH",
Self::StableSwapALend => "StableSwapALend",
Self::StableSwapNG => "StableSwapNG",
Self::StableSwapMeta => "StableSwapMeta",
Self::TwoCryptoV1 => "TwoCryptoV1",
Self::TwoCryptoNG => "TwoCryptoNG",
Self::TwoCryptoStable => "TwoCryptoStable",
Self::TriCryptoV1 => "TriCryptoV1",
Self::TriCryptoNG => "TriCryptoNG",
}
}
}
impl std::fmt::Display for CurveVariant {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
impl std::str::FromStr for CurveVariant {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"StableSwapV0" => Ok(Self::StableSwapV0),
"StableSwapV1" => Ok(Self::StableSwapV1),
"StableSwapV2" => Ok(Self::StableSwapV2),
"StableSwapSTETH" => Ok(Self::StableSwapSTETH),
"StableSwapALend" => Ok(Self::StableSwapALend),
"StableSwapNG" => Ok(Self::StableSwapNG),
"StableSwapMeta" => Ok(Self::StableSwapMeta),
"TwoCryptoV1" => Ok(Self::TwoCryptoV1),
"TwoCryptoNG" => Ok(Self::TwoCryptoNG),
"TwoCryptoStable" => Ok(Self::TwoCryptoStable),
"TriCryptoV1" => Ok(Self::TriCryptoV1),
"TriCryptoNG" => Ok(Self::TriCryptoNG),
_ => Err(format!("unknown CurveVariant: {s}")),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn from_str_roundtrip() {
let variants = [
CurveVariant::StableSwapV0,
CurveVariant::StableSwapV1,
CurveVariant::StableSwapV2,
CurveVariant::StableSwapSTETH,
CurveVariant::StableSwapALend,
CurveVariant::StableSwapNG,
CurveVariant::StableSwapMeta,
CurveVariant::TwoCryptoV1,
CurveVariant::TwoCryptoNG,
CurveVariant::TwoCryptoStable,
CurveVariant::TriCryptoV1,
CurveVariant::TriCryptoNG,
];
for v in variants {
let s = v.as_str();
let parsed: CurveVariant = s.parse().unwrap();
assert_eq!(parsed, v);
}
}
#[test]
fn from_str_unknown() {
let result: Result<CurveVariant, _> = "FooBar".parse();
assert!(result.is_err());
}
}