@@ -75,7 +75,7 @@ use sp_runtime::{
75
75
pub use sp_std:: { collections:: btree_map:: BTreeMap , fmt:: Debug , vec:: Vec } ;
76
76
77
77
use astar_primitives:: {
78
- dapp_staking:: { DAppId , EraNumber , PeriodNumber , TierId } ,
78
+ dapp_staking:: { DAppId , EraNumber , PeriodNumber , TierId , TierSlots as TierSlotsFunc } ,
79
79
Balance , BlockNumber ,
80
80
} ;
81
81
@@ -1485,8 +1485,8 @@ impl<NT: Get<u32>> Default for TierParameters<NT> {
1485
1485
CloneNoBound ,
1486
1486
TypeInfo ,
1487
1487
) ]
1488
- #[ scale_info( skip_type_params( NT ) ) ]
1489
- pub struct TiersConfiguration < NT : Get < u32 > > {
1488
+ #[ scale_info( skip_type_params( NT , T ) ) ]
1489
+ pub struct TiersConfiguration < NT : Get < u32 > , T : TierSlotsFunc > {
1490
1490
/// Total number of slots.
1491
1491
#[ codec( compact) ]
1492
1492
pub number_of_slots : u16 ,
@@ -1500,15 +1500,19 @@ pub struct TiersConfiguration<NT: Get<u32>> {
1500
1500
/// Requirements for entry into each tier.
1501
1501
/// First entry refers to the first tier, and so on.
1502
1502
pub tier_thresholds : BoundedVec < TierThreshold , NT > ,
1503
+ /// Phantom data to keep track of the tier slots function.
1504
+ #[ codec( skip) ]
1505
+ pub ( crate ) _phantom : PhantomData < T > ,
1503
1506
}
1504
1507
1505
- impl < NT : Get < u32 > > Default for TiersConfiguration < NT > {
1508
+ impl < NT : Get < u32 > , T : TierSlotsFunc > Default for TiersConfiguration < NT , T > {
1506
1509
fn default ( ) -> Self {
1507
1510
Self {
1508
1511
number_of_slots : 0 ,
1509
1512
slots_per_tier : BoundedVec :: default ( ) ,
1510
1513
reward_portion : BoundedVec :: default ( ) ,
1511
1514
tier_thresholds : BoundedVec :: default ( ) ,
1515
+ _phantom : Default :: default ( ) ,
1512
1516
}
1513
1517
}
1514
1518
}
@@ -1518,7 +1522,7 @@ impl<NT: Get<u32>> Default for TiersConfiguration<NT> {
1518
1522
// * There's no need to keep thresholds in two separate storage items since the calculation can always be done compared to the
1519
1523
// anchor value of 5 cents. This still needs to be checked & investigated, but it's worth a try.
1520
1524
1521
- impl < NT : Get < u32 > > TiersConfiguration < NT > {
1525
+ impl < NT : Get < u32 > , T : TierSlotsFunc > TiersConfiguration < NT , T > {
1522
1526
/// Check if parameters are valid.
1523
1527
pub fn is_valid ( & self ) -> bool {
1524
1528
let number_of_tiers: usize = NT :: get ( ) as usize ;
@@ -1533,7 +1537,7 @@ impl<NT: Get<u32>> TiersConfiguration<NT> {
1533
1537
/// Calculate new `TiersConfiguration`, based on the old settings, current native currency price and tier configuration.
1534
1538
pub fn calculate_new ( & self , native_price : FixedU64 , params : & TierParameters < NT > ) -> Self {
1535
1539
// It must always be at least 1 slot.
1536
- let new_number_of_slots = Self :: calculate_number_of_slots ( native_price) . max ( 1 ) ;
1540
+ let new_number_of_slots = T :: number_of_slots ( native_price) . max ( 1 ) ;
1537
1541
1538
1542
// Calculate how much each tier gets slots.
1539
1543
let new_slots_per_tier: Vec < u16 > = params
@@ -1621,16 +1625,9 @@ impl<NT: Get<u32>> TiersConfiguration<NT> {
1621
1625
slots_per_tier : new_slots_per_tier,
1622
1626
reward_portion : params. reward_portion . clone ( ) ,
1623
1627
tier_thresholds : new_tier_thresholds,
1628
+ _phantom : Default :: default ( ) ,
1624
1629
}
1625
1630
}
1626
-
1627
- /// Calculate number of slots, based on the provided native token price.
1628
- pub fn calculate_number_of_slots ( native_price : FixedU64 ) -> u16 {
1629
- // floor(1000 x price + 50), formula proposed in Tokenomics 2.0 document.
1630
- let result: u64 = native_price. saturating_mul_int ( 1000 ) . saturating_add ( 50 ) ;
1631
-
1632
- result. unique_saturated_into ( )
1633
- }
1634
1631
}
1635
1632
1636
1633
/// Information about all of the dApps that got into tiers, and tier rewards
0 commit comments