Skip to content

Commit 83a4a81

Browse files
authored
dApp Staking v3 & Tokenomics 2.0 - Shiden Integration (#1161)
* dApp staking v3 & Tokenomics 2.0 - Shiden Integration * Full integration * Changes * Fix * Proper fix, really * Fix for ed issue * Fix formatting * Weights * Resolve TODOs * Minor changes * Fmt fix * Bump versions * Comment * dapp staking v3 - Freeze Improvements (#1164) * Init commit * Collator selection change * Collator selection update * Integration tests * Update astar spec due to changes * Weight updates
1 parent 90df4e5 commit 83a4a81

41 files changed

Lines changed: 1818 additions & 684 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 14 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/collator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "astar-collator"
3-
version = "5.30.0"
3+
version = "5.31.0"
44
description = "Astar collator implementation in Rust."
55
build = "build.rs"
66
default-run = "astar-collator"

bin/collator/src/parachain/chain_spec/shibuya.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ fn make_genesis(
176176
Permill::from_percent(30),
177177
Permill::from_percent(40),
178178
],
179-
// TODO: adjust this if needed
180179
tier_thresholds: vec![
181180
TierThreshold::DynamicTvlAmount {
182181
amount: 100 * SBY,
@@ -194,7 +193,6 @@ fn make_genesis(
194193
],
195194
slots_per_tier: vec![10, 20, 30, 40],
196195
},
197-
// TODO: adjust this if needed
198196
inflation: InflationConfig {
199197
params: InflationParameters::default(),
200198
},

bin/collator/src/parachain/chain_spec/shiden.rs

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
use cumulus_primitives_core::ParaId;
2222
use sc_service::ChainType;
2323
use shiden_runtime::{
24-
wasm_binary_unwrap, AccountId, AuraId, Balance, BlockRewardConfig, EVMConfig,
25-
ParachainInfoConfig, Precompiles, RewardDistributionConfig, Signature, SystemConfig, SDN,
24+
wasm_binary_unwrap, AccountId, AuraId, Balance, DappStakingConfig, EVMConfig, InflationConfig,
25+
InflationParameters, ParachainInfoConfig, Precompiles, Signature, SystemConfig, TierThreshold,
26+
SDN,
2627
};
2728
use sp_core::{sr25519, Pair, Public};
2829

2930
use sp_runtime::{
3031
traits::{IdentifyAccount, Verify},
31-
Perbill,
32+
Permill,
3233
};
3334

3435
use super::{get_from_seed, Extensions};
@@ -111,17 +112,6 @@ fn make_genesis(
111112
},
112113
parachain_info: ParachainInfoConfig { parachain_id },
113114
balances: shiden_runtime::BalancesConfig { balances },
114-
block_reward: BlockRewardConfig {
115-
// Make sure sum is 100
116-
reward_config: RewardDistributionConfig {
117-
treasury_percent: Perbill::from_percent(40),
118-
base_staker_percent: Perbill::from_percent(25),
119-
dapps_percent: Perbill::from_percent(25),
120-
collators_percent: Perbill::from_percent(10),
121-
adjustable_percent: Perbill::from_percent(0),
122-
ideal_dapps_staking_tvl: Perbill::from_percent(0),
123-
},
124-
},
125115
vesting: shiden_runtime::VestingConfig { vesting: vec![] },
126116
session: shiden_runtime::SessionConfig {
127117
keys: authorities
@@ -160,6 +150,39 @@ fn make_genesis(
160150
assets: Default::default(),
161151
parachain_system: Default::default(),
162152
transaction_payment: Default::default(),
153+
dapp_staking: DappStakingConfig {
154+
reward_portion: vec![
155+
Permill::from_percent(40),
156+
Permill::from_percent(30),
157+
Permill::from_percent(20),
158+
Permill::from_percent(10),
159+
],
160+
slot_distribution: vec![
161+
Permill::from_percent(10),
162+
Permill::from_percent(20),
163+
Permill::from_percent(30),
164+
Permill::from_percent(40),
165+
],
166+
tier_thresholds: vec![
167+
TierThreshold::DynamicTvlAmount {
168+
amount: 30000 * SDN,
169+
minimum_amount: 20000 * SDN,
170+
},
171+
TierThreshold::DynamicTvlAmount {
172+
amount: 7500 * SDN,
173+
minimum_amount: 5000 * SDN,
174+
},
175+
TierThreshold::DynamicTvlAmount {
176+
amount: 20000 * SDN,
177+
minimum_amount: 15000 * SDN,
178+
},
179+
TierThreshold::FixedTvlAmount { amount: 5000 * SDN },
180+
],
181+
slots_per_tier: vec![10, 20, 30, 40],
182+
},
183+
inflation: InflationConfig {
184+
params: InflationParameters::default(),
185+
},
163186
}
164187
}
165188

pallets/collator-selection/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ std = [
5959
"pallet-authorship/std",
6060
"pallet-session/std",
6161
"pallet-aura/std",
62+
"pallet-balances/std",
6263
]
6364

6465
try-runtime = ["frame-support/try-runtime"]

pallets/collator-selection/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ pub mod pallet {
109109
}
110110
}
111111

112+
/// Used to check whether an account is allowed to be a candidate.
113+
pub trait AccountCheck<AccountId> {
114+
/// `true` if the account is allowed to be a candidate, `false` otherwise.
115+
fn allowed_candidacy(account: &AccountId) -> bool;
116+
}
117+
112118
/// Configure the pallet by specifying the parameters and types on which it depends.
113119
#[pallet::config]
114120
pub trait Config: frame_system::Config {
@@ -157,6 +163,9 @@ pub mod pallet {
157163
/// How many in perc kicked collators should be slashed (set 0 to disable)
158164
type SlashRatio: Get<Perbill>;
159165

166+
/// Used to check whether an account is allowed to be a candidate.
167+
type AccountCheck: AccountCheck<Self::AccountId>;
168+
160169
/// The weight information of this pallet.
161170
type WeightInfo: WeightInfo;
162171
}
@@ -287,6 +296,8 @@ pub mod pallet {
287296
NoAssociatedValidatorId,
288297
/// Validator ID is not yet registered
289298
ValidatorNotRegistered,
299+
/// Account is now allowed to be a candidate due to an external reason (e.g. it might be participating in dApp staking)
300+
NotAllowedCandidate,
290301
}
291302

292303
#[pallet::hooks]
@@ -375,6 +386,10 @@ pub mod pallet {
375386
!Self::invulnerables().contains(&who),
376387
Error::<T>::AlreadyInvulnerable
377388
);
389+
ensure!(
390+
T::AccountCheck::allowed_candidacy(&who),
391+
Error::<T>::NotAllowedCandidate
392+
);
378393

379394
let validator_key = T::ValidatorIdOf::convert(who.clone())
380395
.ok_or(Error::<T>::NoAssociatedValidatorId)?;
@@ -502,6 +517,11 @@ pub mod pallet {
502517
})
503518
.collect::<Vec<_>>()
504519
}
520+
521+
/// Check whether an account is a candidate.
522+
pub fn is_account_candidate(account: &T::AccountId) -> bool {
523+
Self::candidates().iter().any(|c| &c.who == account)
524+
}
505525
}
506526

507527
/// Keep track of number of authored blocks per authority, uncles are counted as well since

pallets/collator-selection/src/mock.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ impl ValidatorRegistration<u64> for IsRegistered {
212212
}
213213
}
214214

215+
pub(crate) const BLACKLISTED_ACCOUNT: u64 = 987654321;
216+
217+
pub struct DummyAccountCheck;
218+
impl AccountCheck<u64> for DummyAccountCheck {
219+
fn allowed_candidacy(account: &u64) -> bool {
220+
*account != BLACKLISTED_ACCOUNT
221+
}
222+
}
223+
215224
impl Config for Test {
216225
type RuntimeEvent = RuntimeEvent;
217226
type Currency = Balances;
@@ -225,6 +234,7 @@ impl Config for Test {
225234
type ValidatorIdOf = IdentityCollator;
226235
type ValidatorRegistration = IsRegistered;
227236
type SlashRatio = SlashRatio;
237+
type AccountCheck = DummyAccountCheck;
228238
type WeightInfo = ();
229239
}
230240

pallets/collator-selection/src/tests.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,16 @@ fn cannot_register_as_candidate_if_poor() {
214214
});
215215
}
216216

217+
#[test]
218+
fn cannot_register_candidate_if_externally_blacklisted() {
219+
new_test_ext().execute_with(|| {
220+
assert_noop!(
221+
CollatorSelection::register_as_candidate(RuntimeOrigin::signed(BLACKLISTED_ACCOUNT)),
222+
Error::<Test>::NotAllowedCandidate,
223+
);
224+
})
225+
}
226+
217227
#[test]
218228
fn register_as_candidate_works() {
219229
new_test_ext().execute_with(|| {

0 commit comments

Comments
 (0)