Skip to content

Commit 026815e

Browse files
committed
small adjustments
1 parent 87cc1da commit 026815e

File tree

6 files changed

+38
-54
lines changed

6 files changed

+38
-54
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
use super::{Pallet as DappStaking, *};
2020

21-
use astar_primitives::{dapp_staking::STANDARD_TIER_SLOTS_ARGS, Balance};
21+
use astar_primitives::{dapp_staking::FIXED_TIER_SLOTS_ARGS, Balance};
2222

2323
use frame_system::Pallet as System;
2424

@@ -197,12 +197,12 @@ pub(super) fn init_tier_settings<T: Config>() {
197197
},
198198
])
199199
.unwrap(),
200-
slot_number_args: STANDARD_TIER_SLOTS_ARGS,
200+
slot_number_args: FIXED_TIER_SLOTS_ARGS,
201201
rank_points: BoundedVec::try_from(vec![
202202
BoundedVec::try_from(vec![1u8]).unwrap(),
203-
BoundedVec::try_from(vec![1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]).unwrap(),
204-
BoundedVec::try_from(vec![1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]).unwrap(),
205-
BoundedVec::try_from(vec![1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]).unwrap(),
203+
BoundedVec::try_from(vec![1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10]).unwrap(),
204+
BoundedVec::try_from(vec![1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10]).unwrap(),
205+
BoundedVec::try_from(vec![1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10]).unwrap(),
206206
])
207207
.unwrap(),
208208
base_reward_portion: Permill::from_percent(50),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use sp_std::cell::RefCell;
3636

3737
use astar_primitives::{
3838
dapp_staking::{
39-
Observer as DappStakingObserver, SmartContract, StandardTierSlots, STANDARD_TIER_SLOTS_ARGS,
39+
Observer as DappStakingObserver, SmartContract, StandardTierSlots, FIXED_TIER_SLOTS_ARGS,
4040
},
4141
Balance, BlockNumber,
4242
};
@@ -340,7 +340,7 @@ impl ExtBuilder {
340340
},
341341
])
342342
.unwrap(),
343-
slot_number_args: STANDARD_TIER_SLOTS_ARGS,
343+
slot_number_args: FIXED_TIER_SLOTS_ARGS,
344344
rank_points: BoundedVec::try_from(vec![
345345
BoundedVec::try_from(vec![1u8]).unwrap(),
346346
BoundedVec::try_from(vec![1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10]).unwrap(),

pallets/dapp-staking/src/test/tests.rs

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use sp_runtime::{
4242
use astar_primitives::{
4343
dapp_staking::{
4444
CycleConfiguration, EraNumber, RankedTier, SmartContractHandle, StakingRewardHandler,
45-
TierSlots,
45+
TierSlots, STANDARD_TIER_SLOTS_ARGS,
4646
},
4747
Balance, BlockNumber,
4848
};
@@ -2685,6 +2685,13 @@ fn force_with_safeguard_on_fails() {
26852685
#[test]
26862686
fn tier_config_recalculation_works() {
26872687
ExtBuilder::default().build_and_execute(|| {
2688+
// Setup for price based slot capacity
2689+
StaticTierParams::<Test>::mutate(|params| {
2690+
params.slot_number_args = STANDARD_TIER_SLOTS_ARGS;
2691+
});
2692+
assert_ok!(DappStaking::force(RuntimeOrigin::root(), ForcingType::Era));
2693+
run_for_blocks(1);
2694+
26882695
let init_price = NATIVE_PRICE.with(|v| v.borrow().clone());
26892696
let init_tier_config = TierConfig::<Test>::get();
26902697

@@ -2878,12 +2885,6 @@ fn get_dapp_tier_assignment_and_rewards_basic_example_works() {
28782885
dapp_reward_pool,
28792886
);
28802887

2881-
// Debug: Print actual ranks assigned
2882-
for (dapp_id, ranked_tier) in tier_assignment.dapps.iter() {
2883-
let (tier, rank) = ranked_tier.deconstruct();
2884-
println!("Tier {}: dApp {} has rank {}", tier, dapp_id, rank);
2885-
}
2886-
28872888
// Ranks rewards are 50% of the tier allocation
28882889
// Dapp rewards allocations for tiers are: 40%, 30%, 20%, 10%
28892890
// Points per tiers are: 1, 55, 55, 55
@@ -3478,6 +3479,13 @@ fn safeguard_configurable_by_genesis_config() {
34783479
#[test]
34793480
fn base_number_of_slots_is_respected() {
34803481
ExtBuilder::default().build_and_execute(|| {
3482+
// Setup for price based slot capacity
3483+
StaticTierParams::<Test>::mutate(|params| {
3484+
params.slot_number_args = STANDARD_TIER_SLOTS_ARGS;
3485+
});
3486+
assert_ok!(DappStaking::force(RuntimeOrigin::root(), ForcingType::Era));
3487+
run_for_blocks(1);
3488+
34813489
// 0. Get expected number of slots for the base price
34823490
let total_issuance = <Test as Config>::Currency::total_issuance();
34833491
let base_native_price = <Test as Config>::BaseNativeCurrencyPrice::get();
@@ -3589,36 +3597,17 @@ fn base_number_of_slots_is_respected() {
35893597
#[test]
35903598
fn ranking_with_points_calculates_reward_correctly() {
35913599
ExtBuilder::default().build_and_execute(|| {
3592-
// Configure tiers with specific rank_points for predictable testing
35933600
// Tier 1: 3 slots with points [5, 10, 15] (sum = 30)
35943601
// Tier 2: 2 slots with points [4, 8] (sum = 12)
3595-
let tier_params = TierParameters::<<Test as Config>::NumberOfTiers> {
3596-
reward_portion: BoundedVec::try_from(vec![
3597-
Permill::from_percent(40),
3598-
Permill::from_percent(30),
3599-
Permill::from_percent(20),
3600-
Permill::from_percent(10),
3601-
])
3602-
.unwrap(),
3603-
slot_distribution: BoundedVec::try_from(vec![
3604-
Permill::from_percent(10),
3605-
Permill::from_percent(20),
3606-
Permill::from_percent(30),
3607-
Permill::from_percent(40),
3608-
])
3609-
.unwrap(),
3610-
tier_thresholds: StaticTierParams::<Test>::get().tier_thresholds,
3611-
slot_number_args: (0, 16),
3612-
rank_points: BoundedVec::try_from(vec![
3602+
StaticTierParams::<Test>::mutate(|params| {
3603+
params.rank_points = BoundedVec::try_from(vec![
36133604
BoundedVec::try_from(vec![]).unwrap(), // tier 0: no ranking
36143605
BoundedVec::try_from(vec![5u8, 10, 15]).unwrap(), // tier 1: sum = 30
36153606
BoundedVec::try_from(vec![4u8, 8]).unwrap(), // tier 2: sum = 12
36163607
BoundedVec::try_from(vec![]).unwrap(), // tier 3: no ranking
36173608
])
3618-
.unwrap(),
3619-
base_reward_portion: Permill::from_percent(50),
3620-
};
3621-
StaticTierParams::<Test>::put(tier_params);
3609+
.unwrap();
3610+
});
36223611

36233612
// Tier config is specially adapted for this test.
36243613
TierConfig::<Test>::mutate(|config| {
@@ -3680,10 +3669,10 @@ fn ranking_with_points_calculates_reward_correctly() {
36803669
// Tier 3: no ranking → 0
36813670
rank_rewards: BoundedVec::try_from(vec![0, 5_000, 8_333, 0]).unwrap(),
36823671
rank_points: BoundedVec::try_from(vec![
3683-
BoundedVec::try_from(vec![]).unwrap(), // tier 0: no ranking
3684-
BoundedVec::try_from(vec![5u8, 10, 15]).unwrap(), // tier 1: sum = 30
3685-
BoundedVec::try_from(vec![4u8, 8]).unwrap(), // tier 2: sum = 12
3686-
BoundedVec::try_from(vec![]).unwrap(), // tier 3: no ranking
3672+
BoundedVec::try_from(vec![]).unwrap(),
3673+
BoundedVec::try_from(vec![5u8, 10, 15]).unwrap(),
3674+
BoundedVec::try_from(vec![4u8, 8]).unwrap(),
3675+
BoundedVec::try_from(vec![]).unwrap(),
36873676
])
36883677
.unwrap(),
36893678
}
@@ -3698,8 +3687,7 @@ fn ranking_with_points_calculates_reward_correctly() {
36983687
#[test]
36993688
fn claim_dapp_reward_with_rank_points() {
37003689
ExtBuilder::default().build_and_execute(|| {
3701-
// Configure tier 1 with rank_points for testing
3702-
// 5 slots with points [1, 5, 10, 15, 20]
3690+
// Tier-1: 5 slots with points [1, 5, 10, 15, 20]
37033691
StaticTierParams::<Test>::mutate(|params| {
37043692
params.rank_points = BoundedVec::try_from(vec![
37053693
BoundedVec::try_from(vec![]).unwrap(),
@@ -3708,7 +3696,6 @@ fn claim_dapp_reward_with_rank_points() {
37083696
BoundedVec::try_from(vec![]).unwrap(),
37093697
])
37103698
.unwrap();
3711-
params.base_reward_portion = Permill::from_percent(50);
37123699
});
37133700

37143701
let total_issuance = <Test as Config>::Currency::total_issuance();

runtime/astar/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ use xcm_runtime_apis::{
8989
use astar_primitives::{
9090
dapp_staking::{
9191
AccountCheck as DappStakingAccountCheck, CycleConfiguration, DAppId, EraNumber,
92-
PeriodNumber, RankedTier, SmartContract, StandardTierSlots,
92+
PeriodNumber, RankedTier, SmartContract, StandardTierSlots, FIXED_TIER_SLOTS_ARGS,
9393
},
9494
evm::{EVMFungibleAdapterWrapper, EvmRevertCodeHandler},
9595
governance::{
@@ -1743,6 +1743,7 @@ pub type Executive = frame_executive::Executive<
17431743
AllPalletsWithSystem,
17441744
Migrations,
17451745
>;
1746+
17461747
pub struct AstarTierParamsV11;
17471748
impl pallet_dapp_staking::migration::TierParamsV11Config for AstarTierParamsV11 {
17481749
fn reward_portion() -> [Permill; 4] {
@@ -1783,7 +1784,7 @@ impl pallet_dapp_staking::migration::TierParamsV11Config for AstarTierParamsV11
17831784
}
17841785

17851786
fn slot_number_args() -> (u64, u64) {
1786-
(0, 16)
1787+
FIXED_TIER_SLOTS_ARGS
17871788
}
17881789

17891790
fn rank_points() -> [Vec<u8>; 4] {

runtime/shibuya/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ use xcm_runtime_apis::{
8585
use astar_primitives::{
8686
dapp_staking::{
8787
AccountCheck as DappStakingAccountCheck, CycleConfiguration, DAppId, EraNumber,
88-
PeriodNumber, RankedTier, SmartContract, StandardTierSlots,
88+
PeriodNumber, RankedTier, SmartContract, StandardTierSlots, FIXED_TIER_SLOTS_ARGS,
8989
},
9090
evm::{EVMFungibleAdapterWrapper, EvmRevertCodeHandler, HashedDefaultMappings},
9191
governance::{
@@ -1790,7 +1790,7 @@ impl pallet_dapp_staking::migration::TierParamsV11Config for ShibuyaTierParamsV1
17901790
}
17911791

17921792
fn slot_number_args() -> (u64, u64) {
1793-
(0, 16)
1793+
FIXED_TIER_SLOTS_ARGS
17941794
}
17951795

17961796
fn rank_points() -> [Vec<u8>; 4] {

runtime/shiden/src/lib.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ use xcm_runtime_apis::{
8686
use astar_primitives::{
8787
dapp_staking::{
8888
AccountCheck as DappStakingAccountCheck, CycleConfiguration, DAppId, EraNumber,
89-
PeriodNumber, RankedTier, SmartContract, StandardTierSlots,
89+
PeriodNumber, RankedTier, SmartContract, StandardTierSlots, FIXED_TIER_SLOTS_ARGS,
9090
},
9191
evm::{EVMFungibleAdapterWrapper, EvmRevertCodeHandler},
9292
governance::OracleMembershipInst,
@@ -1353,7 +1353,7 @@ impl pallet_dapp_staking::migration::TierParamsV11Config for ShidenTierParamsV11
13531353
}
13541354

13551355
fn slot_number_args() -> (u64, u64) {
1356-
(0, 16)
1356+
FIXED_TIER_SLOTS_ARGS
13571357
}
13581358

13591359
fn rank_points() -> [Vec<u8>; 4] {
@@ -1383,10 +1383,6 @@ pub type Unreleased = (
13831383
/// Migrations/checks that do not need to be versioned and can run on every upgrade.
13841384
pub type Permanent = (pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,);
13851385

1386-
parameter_types! {
1387-
pub const TierSlotsArgs: (u64, u64) = (100, 50);
1388-
}
1389-
13901386
type EventRecord = frame_system::EventRecord<
13911387
<Runtime as frame_system::Config>::RuntimeEvent,
13921388
<Runtime as frame_system::Config>::Hash,

0 commit comments

Comments
 (0)