Skip to content

Commit f7726fc

Browse files
committed
Abstract SwapStep
1 parent 197f717 commit f7726fc

File tree

5 files changed

+664
-517
lines changed

5 files changed

+664
-517
lines changed

pallets/swap-interface/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use frame_support::pallet_prelude::*;
44
use substrate_fixed::types::U96F32;
55
use subtensor_runtime_common::{AlphaCurrency, Currency, CurrencyReserve, NetUid, TaoCurrency};
66

7-
pub mod order;
7+
pub use order::*;
8+
9+
mod order;
810

911
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1012
pub enum OrderType {

pallets/swap-interface/src/order.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
use core::marker::PhantomData;
22

3-
use subtensor_runtime_common::Currency;
3+
use substrate_fixed::types::U64F64;
4+
use subtensor_runtime_common::{AlphaCurrency, Currency, TaoCurrency};
45

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>
613
where
714
PaidIn: Currency,
815
PaidOut: Currency,
@@ -12,4 +19,22 @@ where
1219
_paid_out: PhantomData<PaidOut>,
1320
}
1421

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

Comments
 (0)