@@ -18,7 +18,9 @@ use pallet_subtensor_proxy as pallet_proxy;
1818use pallet_subtensor_proxy:: WeightInfo ;
1919use sp_runtime:: { DispatchError , Weight , traits:: StaticLookup } ;
2020use sp_std:: marker:: PhantomData ;
21+ use substrate_fixed:: types:: U96F32 ;
2122use subtensor_runtime_common:: { AlphaCurrency , NetUid , ProxyType , TaoCurrency } ;
23+ use subtensor_swap_interface:: SwapHandler ;
2224
2325#[ derive( DebugNoBound ) ]
2426pub struct SubtensorChainExtension < T > ( PhantomData < T > ) ;
@@ -33,7 +35,8 @@ impl<T> ChainExtension<T> for SubtensorChainExtension<T>
3335where
3436 T : pallet_subtensor:: Config
3537 + pallet_contracts:: Config
36- + pallet_proxy:: Config < ProxyType = ProxyType > ,
38+ + pallet_proxy:: Config < ProxyType = ProxyType >
39+ + pallet_subtensor_swap:: Config ,
3740 T :: AccountId : Clone ,
3841 <<T as SysConfig >:: Lookup as StaticLookup >:: Source : From < <T as SysConfig >:: AccountId > ,
3942{
@@ -54,7 +57,8 @@ impl<T> SubtensorChainExtension<T>
5457where
5558 T : pallet_subtensor:: Config
5659 + pallet_contracts:: Config
57- + pallet_proxy:: Config < ProxyType = ProxyType > ,
60+ + pallet_proxy:: Config < ProxyType = ProxyType >
61+ + pallet_subtensor_swap:: Config ,
5862 T :: AccountId : Clone ,
5963{
6064 fn dispatch < Env > ( env : & mut Env ) -> Result < RetVal , DispatchError >
@@ -506,6 +510,26 @@ where
506510 }
507511 }
508512 }
513+ FunctionId :: GetAlphaPriceV1 => {
514+ let netuid: NetUid = env
515+ . read_as ( )
516+ . map_err ( |_| DispatchError :: Other ( "Failed to decode input parameters" ) ) ?;
517+
518+ let current_alpha_price =
519+ <pallet_subtensor_swap:: Pallet < T > as SwapHandler >:: current_alpha_price (
520+ netuid. into ( ) ,
521+ ) ;
522+
523+ let price = current_alpha_price. saturating_mul ( U96F32 :: from_num ( 1_000_000_000 ) ) ;
524+ let price: u64 = price. saturating_to_num ( ) ;
525+
526+ let encoded_result = price. encode ( ) ;
527+
528+ env. write_output ( & encoded_result)
529+ . map_err ( |_| DispatchError :: Other ( "Failed to write output" ) ) ?;
530+
531+ Ok ( RetVal :: Converging ( Output :: Success as u32 ) )
532+ }
509533 }
510534 }
511535}
0 commit comments