Skip to content

Commit

Permalink
dApp Staking v3 & Tokenomics 2.0 - Shiden Integration (#1161)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Dinonard committed Feb 6, 2024
1 parent 90df4e5 commit 83a4a81
Show file tree
Hide file tree
Showing 41 changed files with 1,818 additions and 684 deletions.
22 changes: 14 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/collator/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "astar-collator"
version = "5.30.0"
version = "5.31.0"
description = "Astar collator implementation in Rust."
build = "build.rs"
default-run = "astar-collator"
Expand Down
2 changes: 0 additions & 2 deletions bin/collator/src/parachain/chain_spec/shibuya.rs
Expand Up @@ -176,7 +176,6 @@ fn make_genesis(
Permill::from_percent(30),
Permill::from_percent(40),
],
// TODO: adjust this if needed
tier_thresholds: vec![
TierThreshold::DynamicTvlAmount {
amount: 100 * SBY,
Expand All @@ -194,7 +193,6 @@ fn make_genesis(
],
slots_per_tier: vec![10, 20, 30, 40],
},
// TODO: adjust this if needed
inflation: InflationConfig {
params: InflationParameters::default(),
},
Expand Down
51 changes: 37 additions & 14 deletions bin/collator/src/parachain/chain_spec/shiden.rs
Expand Up @@ -21,14 +21,15 @@
use cumulus_primitives_core::ParaId;
use sc_service::ChainType;
use shiden_runtime::{
wasm_binary_unwrap, AccountId, AuraId, Balance, BlockRewardConfig, EVMConfig,
ParachainInfoConfig, Precompiles, RewardDistributionConfig, Signature, SystemConfig, SDN,
wasm_binary_unwrap, AccountId, AuraId, Balance, DappStakingConfig, EVMConfig, InflationConfig,
InflationParameters, ParachainInfoConfig, Precompiles, Signature, SystemConfig, TierThreshold,
SDN,
};
use sp_core::{sr25519, Pair, Public};

use sp_runtime::{
traits::{IdentifyAccount, Verify},
Perbill,
Permill,
};

use super::{get_from_seed, Extensions};
Expand Down Expand Up @@ -111,17 +112,6 @@ fn make_genesis(
},
parachain_info: ParachainInfoConfig { parachain_id },
balances: shiden_runtime::BalancesConfig { balances },
block_reward: BlockRewardConfig {
// Make sure sum is 100
reward_config: RewardDistributionConfig {
treasury_percent: Perbill::from_percent(40),
base_staker_percent: Perbill::from_percent(25),
dapps_percent: Perbill::from_percent(25),
collators_percent: Perbill::from_percent(10),
adjustable_percent: Perbill::from_percent(0),
ideal_dapps_staking_tvl: Perbill::from_percent(0),
},
},
vesting: shiden_runtime::VestingConfig { vesting: vec![] },
session: shiden_runtime::SessionConfig {
keys: authorities
Expand Down Expand Up @@ -160,6 +150,39 @@ fn make_genesis(
assets: Default::default(),
parachain_system: Default::default(),
transaction_payment: Default::default(),
dapp_staking: DappStakingConfig {
reward_portion: vec![
Permill::from_percent(40),
Permill::from_percent(30),
Permill::from_percent(20),
Permill::from_percent(10),
],
slot_distribution: vec![
Permill::from_percent(10),
Permill::from_percent(20),
Permill::from_percent(30),
Permill::from_percent(40),
],
tier_thresholds: vec![
TierThreshold::DynamicTvlAmount {
amount: 30000 * SDN,
minimum_amount: 20000 * SDN,
},
TierThreshold::DynamicTvlAmount {
amount: 7500 * SDN,
minimum_amount: 5000 * SDN,
},
TierThreshold::DynamicTvlAmount {
amount: 20000 * SDN,
minimum_amount: 15000 * SDN,
},
TierThreshold::FixedTvlAmount { amount: 5000 * SDN },
],
slots_per_tier: vec![10, 20, 30, 40],
},
inflation: InflationConfig {
params: InflationParameters::default(),
},
}
}

Expand Down
1 change: 1 addition & 0 deletions pallets/collator-selection/Cargo.toml
Expand Up @@ -59,6 +59,7 @@ std = [
"pallet-authorship/std",
"pallet-session/std",
"pallet-aura/std",
"pallet-balances/std",
]

try-runtime = ["frame-support/try-runtime"]
20 changes: 20 additions & 0 deletions pallets/collator-selection/src/lib.rs
Expand Up @@ -109,6 +109,12 @@ pub mod pallet {
}
}

/// Used to check whether an account is allowed to be a candidate.
pub trait AccountCheck<AccountId> {
/// `true` if the account is allowed to be a candidate, `false` otherwise.
fn allowed_candidacy(account: &AccountId) -> bool;
}

/// Configure the pallet by specifying the parameters and types on which it depends.
#[pallet::config]
pub trait Config: frame_system::Config {
Expand Down Expand Up @@ -157,6 +163,9 @@ pub mod pallet {
/// How many in perc kicked collators should be slashed (set 0 to disable)
type SlashRatio: Get<Perbill>;

/// Used to check whether an account is allowed to be a candidate.
type AccountCheck: AccountCheck<Self::AccountId>;

/// The weight information of this pallet.
type WeightInfo: WeightInfo;
}
Expand Down Expand Up @@ -287,6 +296,8 @@ pub mod pallet {
NoAssociatedValidatorId,
/// Validator ID is not yet registered
ValidatorNotRegistered,
/// Account is now allowed to be a candidate due to an external reason (e.g. it might be participating in dApp staking)
NotAllowedCandidate,
}

#[pallet::hooks]
Expand Down Expand Up @@ -375,6 +386,10 @@ pub mod pallet {
!Self::invulnerables().contains(&who),
Error::<T>::AlreadyInvulnerable
);
ensure!(
T::AccountCheck::allowed_candidacy(&who),
Error::<T>::NotAllowedCandidate
);

let validator_key = T::ValidatorIdOf::convert(who.clone())
.ok_or(Error::<T>::NoAssociatedValidatorId)?;
Expand Down Expand Up @@ -502,6 +517,11 @@ pub mod pallet {
})
.collect::<Vec<_>>()
}

/// Check whether an account is a candidate.
pub fn is_account_candidate(account: &T::AccountId) -> bool {
Self::candidates().iter().any(|c| &c.who == account)
}
}

/// Keep track of number of authored blocks per authority, uncles are counted as well since
Expand Down
10 changes: 10 additions & 0 deletions pallets/collator-selection/src/mock.rs
Expand Up @@ -212,6 +212,15 @@ impl ValidatorRegistration<u64> for IsRegistered {
}
}

pub(crate) const BLACKLISTED_ACCOUNT: u64 = 987654321;

pub struct DummyAccountCheck;
impl AccountCheck<u64> for DummyAccountCheck {
fn allowed_candidacy(account: &u64) -> bool {
*account != BLACKLISTED_ACCOUNT
}
}

impl Config for Test {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
Expand All @@ -225,6 +234,7 @@ impl Config for Test {
type ValidatorIdOf = IdentityCollator;
type ValidatorRegistration = IsRegistered;
type SlashRatio = SlashRatio;
type AccountCheck = DummyAccountCheck;
type WeightInfo = ();
}

Expand Down
10 changes: 10 additions & 0 deletions pallets/collator-selection/src/tests.rs
Expand Up @@ -214,6 +214,16 @@ fn cannot_register_as_candidate_if_poor() {
});
}

#[test]
fn cannot_register_candidate_if_externally_blacklisted() {
new_test_ext().execute_with(|| {
assert_noop!(
CollatorSelection::register_as_candidate(RuntimeOrigin::signed(BLACKLISTED_ACCOUNT)),
Error::<Test>::NotAllowedCandidate,
);
})
}

#[test]
fn register_as_candidate_works() {
new_test_ext().execute_with(|| {
Expand Down

0 comments on commit 83a4a81

Please sign in to comment.