@@ -14,11 +14,13 @@ use sp_runtime::{
1414 BuildStorage , Vec ,
1515 traits:: { BlakeTwo256 , IdentityLookup } ,
1616} ;
17+ use substrate_fixed:: types:: U64F64 ;
1718use subtensor_runtime_common:: {
18- AlphaCurrency , BalanceOps , CurrencyReserve , NetUid , SubnetInfo , TaoCurrency ,
19+ AlphaCurrency , BalanceOps , Currency , CurrencyReserve , NetUid , SubnetInfo , TaoCurrency ,
1920} ;
21+ use subtensor_swap_interface:: Order ;
2022
21- use crate :: pallet:: EnabledUserLiquidity ;
23+ use crate :: pallet:: { EnabledUserLiquidity , FeeGlobalAlpha , FeeGlobalTao } ;
2224
2325construct_runtime ! (
2426 pub enum Test {
@@ -85,7 +87,8 @@ parameter_types! {
8587 pub const MinimumReserves : NonZeroU64 = NonZeroU64 :: new( 1 ) . unwrap( ) ;
8688}
8789
88- pub ( crate ) struct TaoReserve ;
90+ #[ derive( Clone ) ]
91+ pub struct TaoReserve ;
8992
9093impl CurrencyReserve < TaoCurrency > for TaoReserve {
9194 fn reserve ( netuid : NetUid ) -> TaoCurrency {
@@ -97,11 +100,12 @@ impl CurrencyReserve<TaoCurrency> for TaoReserve {
97100 . into ( )
98101 }
99102
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 ) { }
102105}
103106
104- pub ( crate ) struct AlphaReserve ;
107+ #[ derive( Clone ) ]
108+ pub struct AlphaReserve ;
105109
106110impl CurrencyReserve < AlphaCurrency > for AlphaReserve {
107111 fn reserve ( netuid : NetUid ) -> AlphaCurrency {
@@ -112,8 +116,59 @@ impl CurrencyReserve<AlphaCurrency> for AlphaReserve {
112116 }
113117 }
114118
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+ }
117172}
118173
119174// Mock implementor of SubnetInfo trait
0 commit comments