1
1
use super :: * ;
2
2
use share_pool:: { SharePool , SharePoolDataOperations } ;
3
3
use sp_std:: ops:: Neg ;
4
- use substrate_fixed:: types:: { I64F64 , I96F32 } ;
4
+ use substrate_fixed:: types:: { I64F64 , I96F32 , U64F64 } ;
5
5
6
6
impl < T : Config > Pallet < T > {
7
7
@@ -334,7 +334,7 @@ impl<T: Config> Pallet<T> {
334
334
amount : u64
335
335
) {
336
336
let mut alpha_share_pool = Self :: get_alpha_share_pool ( hotkey. clone ( ) , netuid) ;
337
- let _ = alpha_share_pool. update_value_for_all ( amount as i64 ) ;
337
+ alpha_share_pool. update_value_for_all ( amount as i64 ) ;
338
338
}
339
339
340
340
/// Decrease hotkey stake on a subnet.
@@ -352,7 +352,7 @@ impl<T: Config> Pallet<T> {
352
352
amount : u64
353
353
) {
354
354
let mut alpha_share_pool = Self :: get_alpha_share_pool ( hotkey. clone ( ) , netuid) ;
355
- let _ = alpha_share_pool. update_value_for_all ( ( amount as i64 ) . neg ( ) ) ;
355
+ alpha_share_pool. update_value_for_all ( ( amount as i64 ) . neg ( ) ) ;
356
356
}
357
357
358
358
/// Buys shares in the hotkey on a given subnet
@@ -372,7 +372,7 @@ impl<T: Config> Pallet<T> {
372
372
amount : u64
373
373
) {
374
374
let mut alpha_share_pool = Self :: get_alpha_share_pool ( hotkey. clone ( ) , netuid) ;
375
- let _ = alpha_share_pool. update_value_for_one ( coldkey, amount as i64 ) ;
375
+ alpha_share_pool. update_value_for_one ( coldkey, amount as i64 ) ;
376
376
}
377
377
378
378
/// Sell shares in the hotkey on a given subnet
@@ -392,7 +392,11 @@ impl<T: Config> Pallet<T> {
392
392
amount : u64
393
393
) {
394
394
let mut alpha_share_pool = Self :: get_alpha_share_pool ( hotkey. clone ( ) , netuid) ;
395
- let _ = alpha_share_pool. update_value_for_one ( coldkey, ( amount as i64 ) . neg ( ) ) ;
395
+ if let Ok ( value) = alpha_share_pool. try_get_value ( & coldkey) {
396
+ if value >= amount {
397
+ alpha_share_pool. update_value_for_one ( coldkey, ( amount as i64 ) . neg ( ) ) ;
398
+ }
399
+ }
396
400
}
397
401
398
402
/// Swaps TAO for the alpha token on the subnet.
@@ -656,39 +660,39 @@ impl<T: Config> HotkeyAlphaSharePoolDataOperations<T> {
656
660
type AlphaShareKey < T > = <T as frame_system:: Config >:: AccountId ;
657
661
658
662
impl < T : Config > SharePoolDataOperations < AlphaShareKey < T > > for HotkeyAlphaSharePoolDataOperations < T > {
659
- fn get_shared_value ( & self ) -> I64F64 {
660
- I64F64 :: from_num ( crate :: TotalHotkeyAlpha :: < T > :: get ( & self . hotkey , self . netuid ) )
663
+ fn get_shared_value ( & self ) -> U64F64 {
664
+ U64F64 :: from_num ( crate :: TotalHotkeyAlpha :: < T > :: get ( & self . hotkey , self . netuid ) )
661
665
}
662
666
663
- fn get_share ( & self , key : & AlphaShareKey < T > ) -> I64F64 {
667
+ fn get_share ( & self , key : & AlphaShareKey < T > ) -> U64F64 {
664
668
crate :: Alpha :: < T > :: get ( ( & ( self . hotkey ) , key, self . netuid ) )
665
669
}
666
670
667
- fn try_get_share ( & self , key : & AlphaShareKey < T > ) -> Result < I64F64 , ( ) > {
671
+ fn try_get_share ( & self , key : & AlphaShareKey < T > ) -> Result < U64F64 , ( ) > {
668
672
crate :: Alpha :: < T > :: try_get ( ( & ( self . hotkey ) , key, self . netuid ) )
669
673
}
670
674
671
- fn get_denominator ( & self ) -> I64F64 {
675
+ fn get_denominator ( & self ) -> U64F64 {
672
676
crate :: TotalHotkeyShares :: < T > :: get ( & ( self . hotkey ) , self . netuid )
673
677
}
674
678
675
- fn set_shared_value ( & mut self , value : I64F64 ) {
679
+ fn set_shared_value ( & mut self , value : U64F64 ) {
676
680
if value != 0 {
677
681
crate :: TotalHotkeyAlpha :: < T > :: insert ( & ( self . hotkey ) , self . netuid , value. to_num :: < u64 > ( ) ) ;
678
682
} else {
679
683
crate :: TotalHotkeyAlpha :: < T > :: remove ( & ( self . hotkey ) , self . netuid ) ;
680
684
}
681
685
}
682
686
683
- fn set_share ( & mut self , key : & AlphaShareKey < T > , share : I64F64 ) {
687
+ fn set_share ( & mut self , key : & AlphaShareKey < T > , share : U64F64 ) {
684
688
if share != 0 {
685
689
crate :: Alpha :: < T > :: insert ( ( & self . hotkey , key, self . netuid ) , share) ;
686
690
} else {
687
691
crate :: Alpha :: < T > :: remove ( ( & self . hotkey , key, self . netuid ) ) ;
688
692
}
689
693
}
690
694
691
- fn set_denominator ( & mut self , update : I64F64 ) {
695
+ fn set_denominator ( & mut self , update : U64F64 ) {
692
696
if update != 0 {
693
697
crate :: TotalHotkeyShares :: < T > :: insert ( & self . hotkey , self . netuid , update) ;
694
698
} else {
0 commit comments