@@ -92,6 +92,7 @@ pub mod pallet {
9292 use frame_system:: pallet_prelude:: * ;
9393 use pallet_drand:: types:: RoundNumber ;
9494 use runtime_common:: prod_or_fast;
95+ use share_pool:: SafeFloat ;
9596 use sp_core:: { ConstU32 , H160 , H256 } ;
9697 use sp_runtime:: traits:: { Dispatchable , TrailingZeroInput } ;
9798 use sp_std:: collections:: btree_map:: BTreeMap ;
@@ -1433,11 +1434,41 @@ pub mod pallet {
14331434 ValueQuery ,
14341435 > ;
14351436
1437+ /// DMAP ( hot, netuid ) --> total_alpha_shares | Returns the number of alpha shares for a hotkey on a subnet, stores SafeFloat.
1438+ #[ pallet:: storage]
1439+ pub type TotalHotkeySharesV2 < T : Config > = StorageDoubleMap <
1440+ _ ,
1441+ Blake2_128Concat ,
1442+ T :: AccountId , // hot
1443+ Identity ,
1444+ NetUid , // subnet
1445+ SafeFloat , // Hotkey shares in unlimited precision
1446+ ValueQuery ,
1447+ > ;
1448+
1449+ /// --- NMAP ( hot, cold, netuid ) --> alpha | Returns the alpha shares for a hotkey, coldkey, netuid triplet, stores SafeFloat.
1450+ #[ pallet:: storage]
1451+ pub type AlphaV2 < T : Config > = StorageNMap <
1452+ _ ,
1453+ (
1454+ NMapKey < Blake2_128Concat , T :: AccountId > , // hot
1455+ NMapKey < Blake2_128Concat , T :: AccountId > , // cold
1456+ NMapKey < Identity , NetUid > , // subnet
1457+ ) ,
1458+ SafeFloat , // Shares in unlimited precision
1459+ ValueQuery ,
1460+ > ;
1461+
14361462 /// Contains last Alpha storage map key to iterate (check first)
14371463 #[ pallet:: storage]
14381464 pub type AlphaMapLastKey < T : Config > =
14391465 StorageValue < _ , Option < Vec < u8 > > , ValueQuery , DefaultAlphaIterationLastKey < T > > ;
14401466
1467+ /// Contains last AlphaV2 storage map key to iterate (check first)
1468+ #[ pallet:: storage]
1469+ pub type AlphaV2MapLastKey < T : Config > =
1470+ StorageValue < _ , Option < Vec < u8 > > , ValueQuery , DefaultAlphaIterationLastKey < T > > ;
1471+
14411472 /// --- MAP ( netuid ) --> token_symbol | Returns the token symbol for a subnet.
14421473 #[ pallet:: storage]
14431474 pub type TokenSymbol < T : Config > =
@@ -2493,9 +2524,9 @@ use sp_std::vec::Vec;
24932524use subtensor_macros:: freeze_struct;
24942525
24952526#[ derive( Clone ) ]
2496- pub struct TaoCurrencyReserve < T : Config > ( PhantomData < T > ) ;
2527+ pub struct TaoBalanceReserve < T : Config > ( PhantomData < T > ) ;
24972528
2498- impl < T : Config > TokenReserve < TaoBalance > for TaoCurrencyReserve < T > {
2529+ impl < T : Config > TokenReserve < TaoBalance > for TaoBalanceReserve < T > {
24992530 #![ deny( clippy:: expect_used) ]
25002531 fn reserve ( netuid : NetUid ) -> TaoBalance {
25012532 SubnetTAO :: < T > :: get ( netuid) . saturating_add ( SubnetTaoProvided :: < T > :: get ( netuid) )
@@ -2511,9 +2542,9 @@ impl<T: Config> TokenReserve<TaoBalance> for TaoCurrencyReserve<T> {
25112542}
25122543
25132544#[ derive( Clone ) ]
2514- pub struct AlphaCurrencyReserve < T : Config > ( PhantomData < T > ) ;
2545+ pub struct AlphaBalanceReserve < T : Config > ( PhantomData < T > ) ;
25152546
2516- impl < T : Config > TokenReserve < AlphaBalance > for AlphaCurrencyReserve < T > {
2547+ impl < T : Config > TokenReserve < AlphaBalance > for AlphaBalanceReserve < T > {
25172548 #![ deny( clippy:: expect_used) ]
25182549 fn reserve ( netuid : NetUid ) -> AlphaBalance {
25192550 SubnetAlphaIn :: < T > :: get ( netuid) . saturating_add ( SubnetAlphaInProvided :: < T > :: get ( netuid) )
@@ -2529,9 +2560,9 @@ impl<T: Config> TokenReserve<AlphaBalance> for AlphaCurrencyReserve<T> {
25292560}
25302561
25312562pub type GetAlphaForTao < T > =
2532- subtensor_swap_interface:: GetAlphaForTao < TaoCurrencyReserve < T > , AlphaCurrencyReserve < T > > ;
2563+ subtensor_swap_interface:: GetAlphaForTao < TaoBalanceReserve < T > , AlphaBalanceReserve < T > > ;
25332564pub type GetTaoForAlpha < T > =
2534- subtensor_swap_interface:: GetTaoForAlpha < AlphaCurrencyReserve < T > , TaoCurrencyReserve < T > > ;
2565+ subtensor_swap_interface:: GetTaoForAlpha < AlphaBalanceReserve < T > , TaoBalanceReserve < T > > ;
25352566
25362567impl < T : Config + pallet_balances:: Config < Balance = TaoBalance > >
25372568 subtensor_runtime_common:: SubnetInfo < T :: AccountId > for Pallet < T >
@@ -2619,20 +2650,25 @@ impl<T: Config + pallet_balances::Config<Balance = TaoBalance>>
26192650 hotkey : & T :: AccountId ,
26202651 netuid : NetUid ,
26212652 alpha : AlphaBalance ,
2622- ) -> Result < AlphaBalance , DispatchError > {
2653+ ) -> Result < ( ) , DispatchError > {
26232654 ensure ! (
26242655 Self :: hotkey_account_exists( hotkey) ,
26252656 Error :: <T >:: HotKeyAccountNotExists
26262657 ) ;
26272658
2659+ ensure ! (
2660+ Self :: get_stake_for_hotkey_and_coldkey_on_subnet( hotkey, coldkey, netuid) >= alpha,
2661+ Error :: <T >:: InsufficientBalance
2662+ ) ;
2663+
26282664 // Decrese alpha out counter
26292665 SubnetAlphaOut :: < T > :: mutate ( netuid, |total| {
26302666 * total = total. saturating_sub ( alpha) ;
26312667 } ) ;
26322668
2633- Ok ( Self :: decrease_stake_for_hotkey_and_coldkey_on_subnet (
2634- hotkey , coldkey , netuid , alpha ,
2635- ) )
2669+ Self :: decrease_stake_for_hotkey_and_coldkey_on_subnet ( hotkey , coldkey , netuid , alpha ) ;
2670+
2671+ Ok ( ( ) )
26362672 }
26372673}
26382674
0 commit comments