2
2
3
3
use frame_support:: pallet_prelude:: * ;
4
4
use substrate_fixed:: types:: U96F32 ;
5
- use subtensor_runtime_common:: { AlphaCurrency , NetUid , TaoCurrency } ;
5
+ use subtensor_runtime_common:: { AlphaCurrency , Currency , CurrencyReserve , NetUid , TaoCurrency } ;
6
+
7
+ pub mod order;
6
8
7
9
#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
8
10
pub enum OrderType {
@@ -11,23 +13,33 @@ pub enum OrderType {
11
13
}
12
14
13
15
pub trait SwapHandler < AccountId > {
14
- fn swap (
16
+ fn swap < PaidIn , PaidOut , ReserveIn , ReserveOut > (
15
17
netuid : NetUid ,
16
18
order_t : OrderType ,
17
- amount : u64 ,
18
- price_limit : u64 ,
19
+ amount : PaidIn ,
20
+ price_limit : TaoCurrency ,
19
21
drop_fees : bool ,
20
22
should_rollback : bool ,
21
- ) -> Result < SwapResult , DispatchError > ;
22
- fn sim_swap (
23
+ ) -> Result < SwapResult < PaidIn , PaidOut > , DispatchError >
24
+ where
25
+ PaidIn : Currency ,
26
+ PaidOut : Currency ,
27
+ ReserveIn : CurrencyReserve < PaidIn > ,
28
+ ReserveOut : CurrencyReserve < PaidOut > ;
29
+ fn sim_swap < PaidIn , PaidOut , ReserveIn , ReserveOut > (
23
30
netuid : NetUid ,
24
31
order_t : OrderType ,
25
- amount : u64 ,
26
- ) -> Result < SwapResult , DispatchError > ;
27
- fn approx_fee_amount ( netuid : NetUid , amount : u64 ) -> u64 ;
32
+ amount : PaidIn ,
33
+ ) -> Result < SwapResult < PaidIn , PaidOut > , DispatchError >
34
+ where
35
+ PaidIn : Currency ,
36
+ PaidOut : Currency ,
37
+ ReserveIn : CurrencyReserve < PaidIn > ,
38
+ ReserveOut : CurrencyReserve < PaidOut > ;
39
+ fn approx_fee_amount < T : Currency > ( netuid : NetUid , amount : T ) -> T ;
28
40
fn current_alpha_price ( netuid : NetUid ) -> U96F32 ;
29
- fn max_price ( ) -> u64 ;
30
- fn min_price ( ) -> u64 ;
41
+ fn max_price < C : Currency > ( ) -> C ;
42
+ fn min_price < C : Currency > ( ) -> C ;
31
43
fn adjust_protocol_liquidity (
32
44
netuid : NetUid ,
33
45
tao_delta : TaoCurrency ,
@@ -36,12 +48,16 @@ pub trait SwapHandler<AccountId> {
36
48
fn is_user_liquidity_enabled ( netuid : NetUid ) -> bool ;
37
49
}
38
50
39
- #[ derive( Debug , PartialEq ) ]
40
- pub struct SwapResult {
41
- pub amount_paid_in : u64 ,
42
- pub amount_paid_out : u64 ,
43
- pub fee_paid : u64 ,
51
+ #[ derive( Decode , Encode , PartialEq , Eq , Clone , Debug , TypeInfo ) ]
52
+ pub struct SwapResult < PaidIn , PaidOut >
53
+ where
54
+ PaidIn : Currency ,
55
+ PaidOut : Currency ,
56
+ {
57
+ pub amount_paid_in : PaidIn ,
58
+ pub amount_paid_out : PaidOut ,
59
+ pub fee_paid : PaidIn ,
44
60
// For calculation of new tao/alpha reserves
45
- pub tao_reserve_delta : i64 ,
46
- pub alpha_reserve_delta : i64 ,
61
+ pub tao_reserve_delta : i128 ,
62
+ pub alpha_reserve_delta : i128 ,
47
63
}
0 commit comments