Skip to content

Commit 308579a

Browse files
committed
Merge branch 'master' into fix/contacts-migration
2 parents f7a9a74 + eb26b20 commit 308579a

File tree

15 files changed

+115
-161
lines changed

15 files changed

+115
-161
lines changed

Cargo.lock

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pallets/dapp-staking-migration/src/mock.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use sp_runtime::{
3333
};
3434

3535
use astar_primitives::{
36-
dapp_staking::{CycleConfiguration, SmartContract, StakingRewardHandler},
36+
dapp_staking::{CycleConfiguration, SmartContract, StakingRewardHandler, StandardTierSlots},
3737
oracle::PriceProvider,
3838
Balance, BlockNumber,
3939
};
@@ -180,6 +180,7 @@ impl pallet_dapp_staking_v3::Config for Test {
180180
type CycleConfiguration = DummyCycleConfiguration;
181181
type Observers = ();
182182
type AccountCheck = ();
183+
type TierSlots = StandardTierSlots;
183184
type EraRewardSpanLength = ConstU32<8>;
184185
type RewardRetentionInPeriods = ConstU32<2>;
185186
type MaxNumberOfContracts = ConstU32<10>;

pallets/dapp-staking-v3/src/benchmarking/utils.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,12 @@ pub(super) fn initial_config<T: Config>() {
191191
};
192192

193193
// Init tier config, based on the initial params
194-
let init_tier_config = TiersConfiguration::<T::NumberOfTiers> {
194+
let init_tier_config = TiersConfiguration::<T::NumberOfTiers, T::TierSlots> {
195195
number_of_slots: NUMBER_OF_SLOTS.try_into().unwrap(),
196196
slots_per_tier: BoundedVec::try_from(vec![10, 20, 30, 40]).unwrap(),
197197
reward_portion: tier_params.reward_portion.clone(),
198198
tier_thresholds: tier_params.tier_thresholds.clone(),
199+
_phantom: Default::default(),
199200
};
200201

201202
assert!(tier_params.is_valid());

pallets/dapp-staking-v3/src/lib.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use frame_support::{
3939
pallet_prelude::*,
4040
traits::{
4141
fungible::{Inspect as FunInspect, MutateFreeze as FunMutateFreeze},
42-
OnRuntimeUpgrade, StorageVersion,
42+
StorageVersion,
4343
},
4444
weights::Weight,
4545
};
@@ -53,7 +53,7 @@ pub use sp_std::vec::Vec;
5353
use astar_primitives::{
5454
dapp_staking::{
5555
AccountCheck, CycleConfiguration, DAppId, EraNumber, Observer as DAppStakingObserver,
56-
PeriodNumber, SmartContractHandle, StakingRewardHandler, TierId,
56+
PeriodNumber, SmartContractHandle, StakingRewardHandler, TierId, TierSlots as TierSlotFunc,
5757
},
5858
oracle::PriceProvider,
5959
Balance, BlockNumber,
@@ -70,8 +70,6 @@ mod benchmarking;
7070
mod types;
7171
pub use types::*;
7272

73-
pub mod migrations;
74-
7573
pub mod weights;
7674
pub use weights::WeightInfo;
7775

@@ -147,6 +145,9 @@ pub mod pallet {
147145
/// Used to check whether an account is allowed to participate in dApp staking.
148146
type AccountCheck: AccountCheck<Self::AccountId>;
149147

148+
/// Used to calculate total number of tier slots for some price.
149+
type TierSlots: TierSlotFunc;
150+
150151
/// Maximum length of a single era reward span length entry.
151152
#[pallet::constant]
152153
type EraRewardSpanLength: Get<u32>;
@@ -446,7 +447,7 @@ pub mod pallet {
446447
/// Tier configuration user for current & preceding eras.
447448
#[pallet::storage]
448449
pub type TierConfig<T: Config> =
449-
StorageValue<_, TiersConfiguration<T::NumberOfTiers>, ValueQuery>;
450+
StorageValue<_, TiersConfiguration<T::NumberOfTiers, T::TierSlots>, ValueQuery>;
450451

451452
/// Information about which tier a dApp belonged to in a specific era.
452453
#[pallet::storage]
@@ -506,14 +507,15 @@ pub mod pallet {
506507
let number_of_slots = self.slots_per_tier.iter().fold(0_u16, |acc, &slots| {
507508
acc.checked_add(slots).expect("Overflow")
508509
});
509-
let tier_config = TiersConfiguration::<T::NumberOfTiers> {
510+
let tier_config = TiersConfiguration::<T::NumberOfTiers, T::TierSlots> {
510511
number_of_slots,
511512
slots_per_tier: BoundedVec::<u16, T::NumberOfTiers>::try_from(
512513
self.slots_per_tier.clone(),
513514
)
514515
.expect("Invalid number of slots per tier entries provided."),
515516
reward_portion: tier_params.reward_portion.clone(),
516517
tier_thresholds: tier_params.tier_thresholds.clone(),
518+
_phantom: Default::default(),
517519
};
518520
assert!(
519521
tier_params.is_valid(),

pallets/dapp-staking-v3/src/migrations.rs

-129
This file was deleted.

pallets/dapp-staking-v3/src/test/mock.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ use sp_runtime::{
3737
use sp_std::cell::RefCell;
3838

3939
use astar_primitives::{
40-
dapp_staking::{Observer as DappStakingObserver, SmartContract},
40+
dapp_staking::{Observer as DappStakingObserver, SmartContract, StandardTierSlots},
41+
testing::Header,
4142
Balance, BlockNumber,
4243
};
4344

@@ -204,6 +205,7 @@ impl pallet_dapp_staking::Config for Test {
204205
type CycleConfiguration = DummyCycleConfiguration;
205206
type Observers = DummyDappStakingObserver;
206207
type AccountCheck = DummyAccountCheck;
208+
type TierSlots = StandardTierSlots;
207209
type EraRewardSpanLength = ConstU32<8>;
208210
type RewardRetentionInPeriods = ConstU32<2>;
209211
type MaxNumberOfContracts = ConstU32<10>;
@@ -309,11 +311,15 @@ impl ExtBuilder {
309311
};
310312

311313
// Init tier config, based on the initial params
312-
let init_tier_config = TiersConfiguration::<<Test as Config>::NumberOfTiers> {
314+
let init_tier_config = TiersConfiguration::<
315+
<Test as Config>::NumberOfTiers,
316+
<Test as Config>::TierSlots,
317+
> {
313318
number_of_slots: 40,
314319
slots_per_tier: BoundedVec::try_from(vec![2, 5, 13, 20]).unwrap(),
315320
reward_portion: tier_params.reward_portion.clone(),
316321
tier_thresholds: tier_params.tier_thresholds.clone(),
322+
_phantom: Default::default(),
317323
};
318324

319325
pallet_dapp_staking::StaticTierParams::<Test>::put(tier_params);

pallets/dapp-staking-v3/src/test/tests_types.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// You should have received a copy of the GNU General Public License
1717
// along with Astar. If not, see <http://www.gnu.org/licenses/>.
1818

19-
use astar_primitives::Balance;
19+
use astar_primitives::{dapp_staking::StandardTierSlots, Balance};
2020
use frame_support::assert_ok;
2121
use sp_arithmetic::fixed_point::FixedU64;
2222
use sp_runtime::Permill;
@@ -2732,11 +2732,12 @@ fn tier_configuration_basic_tests() {
27322732
assert!(params.is_valid(), "Example params must be valid!");
27332733

27342734
// Create a configuration with some values
2735-
let init_config = TiersConfiguration::<TiersNum> {
2735+
let init_config = TiersConfiguration::<TiersNum, StandardTierSlots> {
27362736
number_of_slots: 100,
27372737
slots_per_tier: BoundedVec::try_from(vec![10, 20, 30, 40]).unwrap(),
27382738
reward_portion: params.reward_portion.clone(),
27392739
tier_thresholds: params.tier_thresholds.clone(),
2740+
_phantom: Default::default(),
27402741
};
27412742
assert!(init_config.is_valid(), "Init config must be valid!");
27422743

pallets/dapp-staking-v3/src/types.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ use sp_runtime::{
7575
pub use sp_std::{collections::btree_map::BTreeMap, fmt::Debug, vec::Vec};
7676

7777
use astar_primitives::{
78-
dapp_staking::{DAppId, EraNumber, PeriodNumber, TierId},
78+
dapp_staking::{DAppId, EraNumber, PeriodNumber, TierId, TierSlots as TierSlotsFunc},
7979
Balance, BlockNumber,
8080
};
8181

@@ -1485,8 +1485,8 @@ impl<NT: Get<u32>> Default for TierParameters<NT> {
14851485
CloneNoBound,
14861486
TypeInfo,
14871487
)]
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> {
14901490
/// Total number of slots.
14911491
#[codec(compact)]
14921492
pub number_of_slots: u16,
@@ -1500,15 +1500,19 @@ pub struct TiersConfiguration<NT: Get<u32>> {
15001500
/// Requirements for entry into each tier.
15011501
/// First entry refers to the first tier, and so on.
15021502
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>,
15031506
}
15041507

1505-
impl<NT: Get<u32>> Default for TiersConfiguration<NT> {
1508+
impl<NT: Get<u32>, T: TierSlotsFunc> Default for TiersConfiguration<NT, T> {
15061509
fn default() -> Self {
15071510
Self {
15081511
number_of_slots: 0,
15091512
slots_per_tier: BoundedVec::default(),
15101513
reward_portion: BoundedVec::default(),
15111514
tier_thresholds: BoundedVec::default(),
1515+
_phantom: Default::default(),
15121516
}
15131517
}
15141518
}
@@ -1518,7 +1522,7 @@ impl<NT: Get<u32>> Default for TiersConfiguration<NT> {
15181522
// * There's no need to keep thresholds in two separate storage items since the calculation can always be done compared to the
15191523
// anchor value of 5 cents. This still needs to be checked & investigated, but it's worth a try.
15201524

1521-
impl<NT: Get<u32>> TiersConfiguration<NT> {
1525+
impl<NT: Get<u32>, T: TierSlotsFunc> TiersConfiguration<NT, T> {
15221526
/// Check if parameters are valid.
15231527
pub fn is_valid(&self) -> bool {
15241528
let number_of_tiers: usize = NT::get() as usize;
@@ -1533,7 +1537,7 @@ impl<NT: Get<u32>> TiersConfiguration<NT> {
15331537
/// Calculate new `TiersConfiguration`, based on the old settings, current native currency price and tier configuration.
15341538
pub fn calculate_new(&self, native_price: FixedU64, params: &TierParameters<NT>) -> Self {
15351539
// 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);
15371541

15381542
// Calculate how much each tier gets slots.
15391543
let new_slots_per_tier: Vec<u16> = params
@@ -1621,16 +1625,9 @@ impl<NT: Get<u32>> TiersConfiguration<NT> {
16211625
slots_per_tier: new_slots_per_tier,
16221626
reward_portion: params.reward_portion.clone(),
16231627
tier_thresholds: new_tier_thresholds,
1628+
_phantom: Default::default(),
16241629
}
16251630
}
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-
}
16341631
}
16351632

16361633
/// Information about all of the dApps that got into tiers, and tier rewards

precompiles/dapp-staking-v3/src/test/mock.rs

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ extern crate alloc;
4343
use astar_primitives::{
4444
dapp_staking::{
4545
CycleConfiguration, EraNumber, PeriodNumber, SmartContract, StakingRewardHandler,
46+
StandardTierSlots,
4647
},
4748
oracle::PriceProvider,
4849
AccountId, Balance, BlockNumber,
@@ -253,6 +254,7 @@ impl pallet_dapp_staking_v3::Config for Test {
253254
type CycleConfiguration = DummyCycleConfiguration;
254255
type Observers = ();
255256
type AccountCheck = ();
257+
type TierSlots = StandardTierSlots;
256258
type EraRewardSpanLength = ConstU32<8>;
257259
type RewardRetentionInPeriods = ConstU32<2>;
258260
type MaxNumberOfContracts = ConstU32<10>;

0 commit comments

Comments
 (0)