@@ -2,7 +2,7 @@ use super::*;
2
2
use safe_math:: * ;
3
3
use share_pool:: { SharePool , SharePoolDataOperations } ;
4
4
use sp_std:: ops:: Neg ;
5
- use substrate_fixed:: types:: { I64F64 , I96F32 , U64F64 } ;
5
+ use substrate_fixed:: types:: { I110F18 , I64F64 , I96F32 , U64F64 } ;
6
6
7
7
impl < T : Config > Pallet < T > {
8
8
/// Retrieves the total alpha issuance for a given subnet.
@@ -469,16 +469,15 @@ impl<T: Config> Pallet<T> {
469
469
// Step 2: Initialized vars.
470
470
if mechanism_id == 1 {
471
471
// Step 3.a.1: Dynamic mechanism calculations
472
- let tao_reserves: I96F32 = I96F32 :: saturating_from_num ( SubnetTAO :: < T > :: get ( netuid) ) ;
473
- let alpha_reserves: I96F32 =
474
- I96F32 :: saturating_from_num ( SubnetAlphaIn :: < T > :: get ( netuid) ) ;
472
+ let tao_reserves: I110F18 = I110F18 :: saturating_from_num ( SubnetTAO :: < T > :: get ( netuid) ) ;
473
+ let alpha_reserves: I110F18 =
474
+ I110F18 :: saturating_from_num ( SubnetAlphaIn :: < T > :: get ( netuid) ) ;
475
475
// Step 3.a.2: Compute constant product k = alpha * tao
476
- let k: I96F32 = alpha_reserves. saturating_mul ( tao_reserves) ;
476
+ let k: I110F18 = alpha_reserves. saturating_mul ( tao_reserves) ;
477
477
478
478
// Calculate new alpha reserve
479
- let new_alpha_reserves: I96F32 = k
480
- . checked_div ( tao_reserves. saturating_add ( I96F32 :: saturating_from_num ( tao) ) )
481
- . unwrap_or ( I96F32 :: saturating_from_num ( 0 ) ) ;
479
+ let new_alpha_reserves: I110F18 =
480
+ k. safe_div ( tao_reserves. saturating_add ( I110F18 :: saturating_from_num ( tao) ) ) ;
482
481
483
482
// Step 3.a.3: Calculate alpha staked using the constant product formula
484
483
// alpha_stake_recieved = current_alpha - (k / (current_tao + new_tao))
@@ -509,16 +508,16 @@ impl<T: Config> Pallet<T> {
509
508
// Step 2: Swap alpha and attain tao
510
509
if mechanism_id == 1 {
511
510
// Step 3.a.1: Dynamic mechanism calculations
512
- let tao_reserves: I96F32 = I96F32 :: saturating_from_num ( SubnetTAO :: < T > :: get ( netuid) ) ;
513
- let alpha_reserves: I96F32 =
514
- I96F32 :: saturating_from_num ( SubnetAlphaIn :: < T > :: get ( netuid) ) ;
511
+ let tao_reserves: I110F18 = I110F18 :: saturating_from_num ( SubnetTAO :: < T > :: get ( netuid) ) ;
512
+ let alpha_reserves: I110F18 =
513
+ I110F18 :: saturating_from_num ( SubnetAlphaIn :: < T > :: get ( netuid) ) ;
515
514
// Step 3.a.2: Compute constant product k = alpha * tao
516
- let k: I96F32 = alpha_reserves. saturating_mul ( tao_reserves) ;
515
+ let k: I110F18 = alpha_reserves. saturating_mul ( tao_reserves) ;
517
516
518
517
// Calculate new tao reserve
519
- let new_tao_reserves: I96F32 = k
520
- . checked_div ( alpha_reserves. saturating_add ( I96F32 :: saturating_from_num ( alpha) ) )
521
- . unwrap_or ( I96F32 :: saturating_from_num ( 0 ) ) ;
518
+ let new_tao_reserves: I110F18 = k
519
+ . checked_div ( alpha_reserves. saturating_add ( I110F18 :: saturating_from_num ( alpha) ) )
520
+ . unwrap_or ( I110F18 :: saturating_from_num ( 0 ) ) ;
522
521
523
522
// Step 3.a.3: Calculate alpha staked using the constant product formula
524
523
// tao_recieved = tao_reserves - (k / (alpha_reserves + new_tao))
0 commit comments