pub const VERY_LOW_LIQUIDITY_USD: f64 = 10_000.0;
pub const LOW_LIQUIDITY_USD: f64 = 100_000.0;
pub const GOOD_LIQUIDITY_USD: f64 = 1_000_000.0;
pub const HONEYPOT_HIGH_RATIO: f64 = 10.0;
pub const HONEYPOT_MEDIUM_RATIO: f64 = 3.0;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LiquidityTier {
VeryLow,
Low,
Moderate,
Good,
}
pub fn liquidity_tier(liquidity_usd: f64) -> LiquidityTier {
if liquidity_usd < VERY_LOW_LIQUIDITY_USD {
LiquidityTier::VeryLow
} else if liquidity_usd < LOW_LIQUIDITY_USD {
LiquidityTier::Low
} else if liquidity_usd > GOOD_LIQUIDITY_USD {
LiquidityTier::Good
} else {
LiquidityTier::Moderate
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Honeypot {
Unknown,
NoSells { buys: u64 },
Ratio(f64),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum HoneypotLevel {
Unknown,
Low,
Medium,
High,
}
pub fn honeypot(buys: u64, sells: u64) -> Honeypot {
match (buys, sells) {
(0, 0) => Honeypot::Unknown,
(b, 0) => Honeypot::NoSells { buys: b },
(b, s) => Honeypot::Ratio(b as f64 / s as f64),
}
}
impl Honeypot {
pub fn level(self) -> HoneypotLevel {
match self {
Honeypot::Unknown => HoneypotLevel::Unknown,
Honeypot::NoSells { .. } => HoneypotLevel::High,
Honeypot::Ratio(r) if r > HONEYPOT_HIGH_RATIO => HoneypotLevel::High,
Honeypot::Ratio(r) if r > HONEYPOT_MEDIUM_RATIO => HoneypotLevel::Medium,
Honeypot::Ratio(_) => HoneypotLevel::Low,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_liquidity_tiers_and_their_bounds() {
assert_eq!(liquidity_tier(0.0), LiquidityTier::VeryLow);
assert_eq!(liquidity_tier(9_999.0), LiquidityTier::VeryLow);
assert_eq!(liquidity_tier(75_000.0), LiquidityTier::Low);
assert_eq!(liquidity_tier(500_000.0), LiquidityTier::Moderate);
assert_eq!(liquidity_tier(1_000_000.0), LiquidityTier::Moderate);
assert_eq!(liquidity_tier(1_000_001.0), LiquidityTier::Good);
}
#[test]
fn test_any_buys_with_no_sells_is_a_high_honeypot_sign() {
assert_eq!(honeypot(5, 0), Honeypot::NoSells { buys: 5 });
assert_eq!(honeypot(5, 0).level(), HoneypotLevel::High);
assert_eq!(honeypot(0, 0).level(), HoneypotLevel::Unknown);
assert_eq!(honeypot(11, 1).level(), HoneypotLevel::High);
assert_eq!(honeypot(4, 1).level(), HoneypotLevel::Medium);
assert_eq!(honeypot(3, 1).level(), HoneypotLevel::Low);
}
}