Skip to content

Commit

Permalink
dApp staking v3 & Tokenomics 2.0 - Astar Integration (#1165)
Browse files Browse the repository at this point in the history
* Integration

* Shiden cleanup

* chain spec update

* Minor changes

* Fix for incorrect eras per cycle function (#1166)

* Adjustments

* Safeguard test

* Docs

* Fixes

* Extra test

* Update weights

* Ensure benchmark tests work

* Formatting

* Init price
  • Loading branch information
Dinonard authored Feb 9, 2024
1 parent 494eddb commit fc14b13
Show file tree
Hide file tree
Showing 34 changed files with 1,089 additions and 919 deletions.
14 changes: 8 additions & 6 deletions Cargo.lock

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

53 changes: 39 additions & 14 deletions bin/collator/src/parachain/chain_spec/astar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
//! Astar chain specifications.

use astar_runtime::{
wasm_binary_unwrap, AccountId, AuraId, Balance, BlockRewardConfig, EVMConfig,
ParachainInfoConfig, Precompiles, RewardDistributionConfig, Signature, SystemConfig, ASTR,
wasm_binary_unwrap, AccountId, AuraId, Balance, DappStakingConfig, EVMConfig, InflationConfig,
InflationParameters, ParachainInfoConfig, Precompiles, Signature, SystemConfig, TierThreshold,
ASTR,
};
use cumulus_primitives_core::ParaId;
use sc_service::ChainType;
use sp_core::{sr25519, Pair, Public};
use sp_runtime::{
traits::{IdentifyAccount, Verify},
Perbill,
Permill,
};

use super::{get_from_seed, Extensions};
Expand Down Expand Up @@ -110,17 +111,6 @@ fn make_genesis(
},
parachain_info: ParachainInfoConfig { parachain_id },
balances: astar_runtime::BalancesConfig { balances },
block_reward: BlockRewardConfig {
// Make sure sum is 100
reward_config: RewardDistributionConfig {
treasury_percent: Perbill::from_percent(10),
base_staker_percent: Perbill::from_percent(20),
dapps_percent: Perbill::from_percent(20),
collators_percent: Perbill::from_percent(5),
adjustable_percent: Perbill::from_percent(45),
ideal_dapps_staking_tvl: Perbill::from_percent(40),
},
},
vesting: astar_runtime::VestingConfig { vesting: vec![] },
session: astar_runtime::SessionConfig {
keys: authorities
Expand Down Expand Up @@ -159,6 +149,41 @@ 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 * ASTR,
minimum_amount: 20000 * ASTR,
},
TierThreshold::DynamicTvlAmount {
amount: 7500 * ASTR,
minimum_amount: 5000 * ASTR,
},
TierThreshold::DynamicTvlAmount {
amount: 20000 * ASTR,
minimum_amount: 15000 * ASTR,
},
TierThreshold::FixedTvlAmount {
amount: 5000 * ASTR,
},
],
slots_per_tier: vec![10, 20, 30, 40],
},
inflation: InflationConfig {
params: InflationParameters::default(),
},
}
}

Expand Down
9 changes: 9 additions & 0 deletions pallets/dapp-staking-migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,10 +580,13 @@ pub mod pallet {

// Get the stakers and their active locked (staked) amount.

use sp_runtime::traits::Zero;
let mut total_locked = Balance::zero();
let min_lock_amount: Balance =
<T as pallet_dapp_staking_v3::Config>::MinimumLockedAmount::get();
let stakers: Vec<_> = pallet_dapps_staking::Ledger::<T>::iter()
.filter_map(|(staker, ledger)| {
total_locked.saturating_accrue(ledger.locked);
if ledger.locked >= min_lock_amount {
Some((staker, ledger.locked))
} else {
Expand All @@ -592,6 +595,12 @@ pub mod pallet {
})
.collect();

log::info!(
target: LOG_TARGET,
"Total locked amount in the old pallet: {:?}.",
total_locked,
);

log::info!(
target: LOG_TARGET,
"Out of {} stakers, {} have sufficient amount to lock.",
Expand Down
76 changes: 40 additions & 36 deletions pallets/dapp-staking-migration/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@
//! Autogenerated weights for pallet_dapp_staking_migration
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2024-02-04, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2024-02-07, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `gh-runner-01-ovh`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shiden-dev"), DB CACHE: 1024
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("astar-dev"), DB CACHE: 1024

// Executed Command:
// ./target/release/astar-collator
// benchmark
// pallet
// --chain=shiden-dev
// --chain=astar-dev
// --steps=50
// --repeat=20
// --pallet=pallet_dapp_staking_migration
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --heap-pages=4096
// --output=./benchmark-results/shiden-dev/dapp_staking_migration_weights.rs
// --output=./benchmark-results/astar-dev/dapp_staking_migration_weights.rs
// --template=./scripts/templates/weight-template.hbs

#![cfg_attr(rustfmt, rustfmt_skip)]
Expand Down Expand Up @@ -74,8 +74,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `558`
// Estimated: `6112`
// Minimum execution time: 48_037_000 picoseconds.
Weight::from_parts(49_209_000, 6112)
// Minimum execution time: 47_762_000 picoseconds.
Weight::from_parts(48_426_000, 6112)
.saturating_add(T::DbWeight::get().reads(6_u64))
.saturating_add(T::DbWeight::get().writes(5_u64))
}
Expand All @@ -85,8 +85,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `3551`
// Minimum execution time: 3_226_000 picoseconds.
Weight::from_parts(3_424_000, 3551)
// Minimum execution time: 3_150_000 picoseconds.
Weight::from_parts(3_368_000, 3551)
.saturating_add(T::DbWeight::get().reads(1_u64))
}
/// Storage: DappsStaking Ledger (r:2 w:1)
Expand All @@ -99,15 +99,17 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
/// Storage: DappStaking Ledger (r:1 w:1)
/// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen)
/// Storage: CollatorSelection Candidates (r:1 w:0)
/// Proof Skipped: CollatorSelection Candidates (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: DappStaking CurrentEraInfo (r:1 w:1)
/// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen)
fn migrate_ledger_success() -> Weight {
// Proof Size summary in bytes:
// Measured: `1749`
// Measured: `1875`
// Estimated: `6472`
// Minimum execution time: 69_988_000 picoseconds.
Weight::from_parts(70_437_000, 6472)
.saturating_add(T::DbWeight::get().reads(7_u64))
// Minimum execution time: 70_640_000 picoseconds.
Weight::from_parts(72_730_000, 6472)
.saturating_add(T::DbWeight::get().reads(8_u64))
.saturating_add(T::DbWeight::get().writes(6_u64))
}
/// Storage: DappsStaking Ledger (r:1 w:0)
Expand All @@ -116,8 +118,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `3731`
// Minimum execution time: 3_019_000 picoseconds.
Weight::from_parts(3_197_000, 3731)
// Minimum execution time: 2_769_000 picoseconds.
Weight::from_parts(2_894_000, 3731)
.saturating_add(T::DbWeight::get().reads(1_u64))
}
/// Storage: DappsStaking Ledger (r:6 w:5)
Expand All @@ -127,10 +129,10 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `700 + x * (40 ±0)`
// Estimated: `3731 + x * (2741 ±0)`
// Minimum execution time: 6_873_000 picoseconds.
Weight::from_parts(6_629_732, 3731)
// Standard Error: 7_063
.saturating_add(Weight::from_parts(688_886, 0).saturating_mul(x.into()))
// Minimum execution time: 6_830_000 picoseconds.
Weight::from_parts(6_598_680, 3731)
// Standard Error: 6_203
.saturating_add(Weight::from_parts(686_141, 0).saturating_mul(x.into()))
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into())))
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(x.into())))
Expand All @@ -140,8 +142,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 2_144_000 picoseconds.
Weight::from_parts(2_233_000, 0)
// Minimum execution time: 2_017_000 picoseconds.
Weight::from_parts(2_116_000, 0)
}
}

Expand All @@ -161,8 +163,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `558`
// Estimated: `6112`
// Minimum execution time: 48_037_000 picoseconds.
Weight::from_parts(49_209_000, 6112)
// Minimum execution time: 47_762_000 picoseconds.
Weight::from_parts(48_426_000, 6112)
.saturating_add(RocksDbWeight::get().reads(6_u64))
.saturating_add(RocksDbWeight::get().writes(5_u64))
}
Expand All @@ -172,8 +174,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `3551`
// Minimum execution time: 3_226_000 picoseconds.
Weight::from_parts(3_424_000, 3551)
// Minimum execution time: 3_150_000 picoseconds.
Weight::from_parts(3_368_000, 3551)
.saturating_add(RocksDbWeight::get().reads(1_u64))
}
/// Storage: DappsStaking Ledger (r:2 w:1)
Expand All @@ -186,15 +188,17 @@ impl WeightInfo for () {
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
/// Storage: DappStaking Ledger (r:1 w:1)
/// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen)
/// Storage: CollatorSelection Candidates (r:1 w:0)
/// Proof Skipped: CollatorSelection Candidates (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: DappStaking CurrentEraInfo (r:1 w:1)
/// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen)
fn migrate_ledger_success() -> Weight {
// Proof Size summary in bytes:
// Measured: `1749`
// Measured: `1875`
// Estimated: `6472`
// Minimum execution time: 69_988_000 picoseconds.
Weight::from_parts(70_437_000, 6472)
.saturating_add(RocksDbWeight::get().reads(7_u64))
// Minimum execution time: 70_640_000 picoseconds.
Weight::from_parts(72_730_000, 6472)
.saturating_add(RocksDbWeight::get().reads(8_u64))
.saturating_add(RocksDbWeight::get().writes(6_u64))
}
/// Storage: DappsStaking Ledger (r:1 w:0)
Expand All @@ -203,8 +207,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `3731`
// Minimum execution time: 3_019_000 picoseconds.
Weight::from_parts(3_197_000, 3731)
// Minimum execution time: 2_769_000 picoseconds.
Weight::from_parts(2_894_000, 3731)
.saturating_add(RocksDbWeight::get().reads(1_u64))
}
/// Storage: DappsStaking Ledger (r:6 w:5)
Expand All @@ -214,10 +218,10 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `700 + x * (40 ±0)`
// Estimated: `3731 + x * (2741 ±0)`
// Minimum execution time: 6_873_000 picoseconds.
Weight::from_parts(6_629_732, 3731)
// Standard Error: 7_063
.saturating_add(Weight::from_parts(688_886, 0).saturating_mul(x.into()))
// Minimum execution time: 6_830_000 picoseconds.
Weight::from_parts(6_598_680, 3731)
// Standard Error: 6_203
.saturating_add(Weight::from_parts(686_141, 0).saturating_mul(x.into()))
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(x.into())))
.saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(x.into())))
Expand All @@ -227,7 +231,7 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 2_144_000 picoseconds.
Weight::from_parts(2_233_000, 0)
// Minimum execution time: 2_017_000 picoseconds.
Weight::from_parts(2_116_000, 0)
}
}
2 changes: 1 addition & 1 deletion pallets/dapp-staking-v3/rpc/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dapp-staking-v3-runtime-api"
version = "0.0.1-alpha"
version = "0.1.0"
description = "dApp Staking v3 runtime API"
authors.workspace = true
edition.workspace = true
Expand Down
2 changes: 2 additions & 0 deletions pallets/dapp-staking-v3/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ mod benchmarks {

#[benchmark]
fn claim_unlocked(x: Linear<0, { T::MaxNumberOfStakedContracts::get() }>) {
initial_config::<T>();

// Prepare staker account and lock some amount
let staker: T::AccountId = whitelisted_caller();
let amount = (T::MinimumStakeAmount::get() + 1)
Expand Down
2 changes: 2 additions & 0 deletions pallets/dapp-staking-v3/src/benchmarking/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ pub(super) fn initial_config<T: Config>() {

StaticTierParams::<T>::put(tier_params);
TierConfig::<T>::put(init_tier_config.clone());

Safeguard::<T>::put(false);
}

/// Maximum number of contracts that 'makes sense' - considers both contract number limit & number of slots.
Expand Down
Loading

0 comments on commit fc14b13

Please sign in to comment.