@@ -14,11 +14,13 @@ use sp_runtime::{
14
14
BuildStorage , Vec ,
15
15
traits:: { BlakeTwo256 , IdentityLookup } ,
16
16
} ;
17
+ use substrate_fixed:: types:: U64F64 ;
17
18
use subtensor_runtime_common:: {
18
- AlphaCurrency , BalanceOps , CurrencyReserve , NetUid , SubnetInfo , TaoCurrency ,
19
+ AlphaCurrency , BalanceOps , Currency , CurrencyReserve , NetUid , SubnetInfo , TaoCurrency ,
19
20
} ;
21
+ use subtensor_swap_interface:: Order ;
20
22
21
- use crate :: pallet:: EnabledUserLiquidity ;
23
+ use crate :: pallet:: { EnabledUserLiquidity , FeeGlobalAlpha , FeeGlobalTao } ;
22
24
23
25
construct_runtime ! (
24
26
pub enum Test {
@@ -85,7 +87,8 @@ parameter_types! {
85
87
pub const MinimumReserves : NonZeroU64 = NonZeroU64 :: new( 1 ) . unwrap( ) ;
86
88
}
87
89
88
- pub ( crate ) struct TaoReserve ;
90
+ #[ derive( Clone ) ]
91
+ pub struct TaoReserve ;
89
92
90
93
impl CurrencyReserve < TaoCurrency > for TaoReserve {
91
94
fn reserve ( netuid : NetUid ) -> TaoCurrency {
@@ -97,11 +100,12 @@ impl CurrencyReserve<TaoCurrency> for TaoReserve {
97
100
. into ( )
98
101
}
99
102
100
- fn increase_provided ( netuid : NetUid , amount : TaoCurrency ) { }
101
- fn decrease_provided ( netuid : NetUid , amount : TaoCurrency ) { }
103
+ fn increase_provided ( _ : NetUid , _ : TaoCurrency ) { }
104
+ fn decrease_provided ( _ : NetUid , _ : TaoCurrency ) { }
102
105
}
103
106
104
- pub ( crate ) struct AlphaReserve ;
107
+ #[ derive( Clone ) ]
108
+ pub struct AlphaReserve ;
105
109
106
110
impl CurrencyReserve < AlphaCurrency > for AlphaReserve {
107
111
fn reserve ( netuid : NetUid ) -> AlphaCurrency {
@@ -112,8 +116,59 @@ impl CurrencyReserve<AlphaCurrency> for AlphaReserve {
112
116
}
113
117
}
114
118
115
- fn increase_provided ( netuid : NetUid , amount : AlphaCurrency ) { }
116
- fn decrease_provided ( netuid : NetUid , amount : AlphaCurrency ) { }
119
+ fn increase_provided ( _: NetUid , _: AlphaCurrency ) { }
120
+ fn decrease_provided ( _: NetUid , _: AlphaCurrency ) { }
121
+ }
122
+
123
+ pub type AlphaForTao = subtensor_swap_interface:: AlphaForTao < TaoReserve , AlphaReserve > ;
124
+ pub type TaoForAlpha = subtensor_swap_interface:: TaoForAlpha < AlphaReserve , TaoReserve > ;
125
+
126
+ pub ( crate ) trait GlobalFeeInfo : Currency {
127
+ fn global_fee ( & self , netuid : NetUid ) -> U64F64 ;
128
+ }
129
+
130
+ impl GlobalFeeInfo for TaoCurrency {
131
+ fn global_fee ( & self , netuid : NetUid ) -> U64F64 {
132
+ FeeGlobalTao :: < Test > :: get ( netuid)
133
+ }
134
+ }
135
+
136
+ impl GlobalFeeInfo for AlphaCurrency {
137
+ fn global_fee ( & self , netuid : NetUid ) -> U64F64 {
138
+ FeeGlobalAlpha :: < Test > :: get ( netuid)
139
+ }
140
+ }
141
+
142
+ pub ( crate ) trait TestExt < O : Order > {
143
+ fn approx_expected_swap_output (
144
+ sqrt_current_price : f64 ,
145
+ liquidity_before : f64 ,
146
+ order_liquidity : f64 ,
147
+ ) -> f64 ;
148
+ }
149
+
150
+ impl TestExt < AlphaForTao > for Test {
151
+ fn approx_expected_swap_output (
152
+ sqrt_current_price : f64 ,
153
+ liquidity_before : f64 ,
154
+ order_liquidity : f64 ,
155
+ ) -> f64 {
156
+ let denom = sqrt_current_price * ( sqrt_current_price * liquidity_before + order_liquidity) ;
157
+ let per_order_liq = liquidity_before / denom;
158
+ per_order_liq * order_liquidity
159
+ }
160
+ }
161
+
162
+ impl TestExt < TaoForAlpha > for Test {
163
+ fn approx_expected_swap_output (
164
+ sqrt_current_price : f64 ,
165
+ liquidity_before : f64 ,
166
+ order_liquidity : f64 ,
167
+ ) -> f64 {
168
+ let denom = liquidity_before / sqrt_current_price + order_liquidity;
169
+ let per_order_liq = sqrt_current_price * liquidity_before / denom;
170
+ per_order_liq * order_liquidity
171
+ }
117
172
}
118
173
119
174
// Mock implementor of SubnetInfo trait
0 commit comments