use core::marker::PhantomData; use substrate_fixed::types::U64F64; use subtensor_runtime_common::{AlphaBalance, TaoBalance, Token, TokenReserve}; pub trait Order: Clone { type PaidIn: Token; type PaidOut: Token; type ReserveIn: TokenReserve; type ReserveOut: TokenReserve; fn with_amount(amount: impl Into) -> Self; fn amount(&self) -> Self::PaidIn; fn is_beyond_price_limit(&self, current_price: U64F64, limit_price: U64F64) -> bool; } #[derive(Clone, Default)] pub struct GetAlphaForTao where ReserveIn: TokenReserve, ReserveOut: TokenReserve, { amount: TaoBalance, _phantom: PhantomData<(ReserveIn, ReserveOut)>, } impl Order for GetAlphaForTao where ReserveIn: TokenReserve + Clone, ReserveOut: TokenReserve + Clone, { type PaidIn = TaoBalance; type PaidOut = AlphaBalance; type ReserveIn = ReserveIn; type ReserveOut = ReserveOut; fn with_amount(amount: impl Into) -> Self { Self { amount: amount.into(), _phantom: PhantomData, } } fn amount(&self) -> TaoBalance { self.amount } fn is_beyond_price_limit(&self, current_price: U64F64, limit_price: U64F64) -> bool { current_price < limit_price } } #[derive(Clone, Default)] pub struct GetTaoForAlpha where ReserveIn: TokenReserve, ReserveOut: TokenReserve, { amount: AlphaBalance, _phantom: PhantomData<(ReserveIn, ReserveOut)>, } impl Order for GetTaoForAlpha where ReserveIn: TokenReserve + Clone, ReserveOut: TokenReserve + Clone, { type PaidIn = AlphaBalance; type PaidOut = TaoBalance; type ReserveIn = ReserveIn; type ReserveOut = ReserveOut; fn with_amount(amount: impl Into) -> Self { Self { amount: amount.into(), _phantom: PhantomData, } } fn amount(&self) -> AlphaBalance { self.amount } fn is_beyond_price_limit(&self, current_price: U64F64, limit_price: U64F64) -> bool { current_price > limit_price } }