|
1 | 1 | use core::marker::PhantomData;
|
2 | 2 |
|
3 |
| -use subtensor_runtime_common::Currency; |
| 3 | +use substrate_fixed::types::U64F64; |
| 4 | +use subtensor_runtime_common::{AlphaCurrency, Currency, TaoCurrency}; |
4 | 5 |
|
5 |
| -pub struct OrderType<PaidIn, PaidOut> |
| 6 | +pub trait Order<PaidIn: Currency, PaidOut: Currency>: Clone { |
| 7 | + fn amount(&self) -> PaidIn; |
| 8 | + fn is_beyond_price_limit(&self, alpha_sqrt_price: U64F64, limit_sqrt_price: U64F64) -> bool; |
| 9 | +} |
| 10 | + |
| 11 | +#[derive(Clone)] |
| 12 | +pub struct BasicOrder<PaidIn, PaidOut> |
6 | 13 | where
|
7 | 14 | PaidIn: Currency,
|
8 | 15 | PaidOut: Currency,
|
|
12 | 19 | _paid_out: PhantomData<PaidOut>,
|
13 | 20 | }
|
14 | 21 |
|
15 |
| -pub trait Order<PaidIn: Currency, PaidOut: Currency> {} |
| 22 | +impl Order<TaoCurrency, AlphaCurrency> for BasicOrder<TaoCurrency, AlphaCurrency> { |
| 23 | + fn amount(&self) -> TaoCurrency { |
| 24 | + self.amount |
| 25 | + } |
| 26 | + |
| 27 | + fn is_beyond_price_limit(&self, alpha_sqrt_price: U64F64, limit_sqrt_price: U64F64) -> bool { |
| 28 | + alpha_sqrt_price < limit_sqrt_price |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +impl Order<AlphaCurrency, TaoCurrency> for BasicOrder<AlphaCurrency, TaoCurrency> { |
| 33 | + fn amount(&self) -> AlphaCurrency { |
| 34 | + self.amount |
| 35 | + } |
| 36 | + |
| 37 | + fn is_beyond_price_limit(&self, alpha_sqrt_price: U64F64, limit_sqrt_price: U64F64) -> bool { |
| 38 | + alpha_sqrt_price > limit_sqrt_price |
| 39 | + } |
| 40 | +} |
0 commit comments