From fc14b13401e1fb5e7391715fc76a308204173802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dino=20Pa=C4=8Dandi?= <3002868+Dinonard@users.noreply.github.com> Date: Fri, 9 Feb 2024 07:59:05 +0100 Subject: [PATCH] dApp staking v3 & Tokenomics 2.0 - Astar Integration (#1165) * 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 --- Cargo.lock | 14 +- .../src/parachain/chain_spec/astar.rs | 53 +- pallets/dapp-staking-migration/src/lib.rs | 9 + pallets/dapp-staking-migration/src/weights.rs | 76 +-- .../rpc/runtime-api/Cargo.toml | 2 +- .../dapp-staking-v3/src/benchmarking/mod.rs | 2 + .../dapp-staking-v3/src/benchmarking/utils.rs | 2 + pallets/dapp-staking-v3/src/lib.rs | 51 +- pallets/dapp-staking-v3/src/test/mock.rs | 1 + pallets/dapp-staking-v3/src/test/tests.rs | 26 +- pallets/inflation/src/benchmarking.rs | 21 - pallets/inflation/src/lib.rs | 24 - pallets/inflation/src/tests.rs | 45 +- pallets/inflation/src/weights.rs | 15 - primitives/src/dapp_staking.rs | 18 +- runtime/astar/Cargo.toml | 32 +- runtime/astar/src/lib.rs | 366 +++++++++++--- runtime/astar/src/precompiles.rs | 6 +- runtime/astar/src/weights/mod.rs | 2 + .../src/weights/pallet_dapp_staking_v3.rs | 455 ++++++++++++++++++ runtime/astar/src/weights/pallet_inflation.rs | 95 ++++ runtime/astar/src/xcm_config.rs | 2 +- .../shibuya/src/weights/pallet_inflation.rs | 7 - runtime/shiden/Cargo.toml | 6 - runtime/shiden/src/lib.rs | 183 +------ .../shiden/src/weights/pallet_inflation.rs | 7 - runtime/shiden/src/xcm_config.rs | 2 +- tests/integration/src/dapp_staking_v3.rs | 1 - ...r_new.rs => dispatch_precompile_filter.rs} | 0 .../src/dispatch_precompile_filter_old.rs | 221 --------- tests/integration/src/lib.rs | 18 +- .../src/{proxy_new.rs => proxy.rs} | 0 tests/integration/src/proxy_old.rs | 213 -------- tests/integration/src/setup.rs | 33 +- 34 files changed, 1089 insertions(+), 919 deletions(-) create mode 100644 runtime/astar/src/weights/pallet_dapp_staking_v3.rs create mode 100644 runtime/astar/src/weights/pallet_inflation.rs rename tests/integration/src/{dispatch_precompile_filter_new.rs => dispatch_precompile_filter.rs} (100%) delete mode 100644 tests/integration/src/dispatch_precompile_filter_old.rs rename tests/integration/src/{proxy_new.rs => proxy.rs} (100%) delete mode 100644 tests/integration/src/proxy_old.rs diff --git a/Cargo.lock b/Cargo.lock index 757672eac..231b50348 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -555,6 +555,7 @@ dependencies = [ "cumulus-primitives-core", "cumulus-primitives-timestamp", "cumulus-primitives-utility", + "dapp-staking-v3-runtime-api", "fp-rpc", "fp-self-contained", "frame-benchmarking", @@ -576,11 +577,11 @@ dependencies = [ "pallet-aura", "pallet-authorship", "pallet-balances", - "pallet-block-rewards-hybrid", "pallet-collator-selection", - "pallet-collective", "pallet-contracts", "pallet-contracts-primitives", + "pallet-dapp-staking-migration", + "pallet-dapp-staking-v3", "pallet-dapps-staking", "pallet-dynamic-evm-base-fee", "pallet-ethereum", @@ -588,7 +589,7 @@ dependencies = [ "pallet-evm-precompile-assets-erc20", "pallet-evm-precompile-blake2", "pallet-evm-precompile-bn128", - "pallet-evm-precompile-dapps-staking", + "pallet-evm-precompile-dapp-staking-v3", "pallet-evm-precompile-dispatch", "pallet-evm-precompile-ed25519", "pallet-evm-precompile-modexp", @@ -598,9 +599,11 @@ dependencies = [ "pallet-evm-precompile-substrate-ecdsa", "pallet-evm-precompile-xcm", "pallet-identity", + "pallet-inflation", "pallet-multisig", "pallet-proxy", "pallet-session", + "pallet-static-price-provider", "pallet-sudo", "pallet-timestamp", "pallet-transaction-payment", @@ -618,6 +621,7 @@ dependencies = [ "scale-info", "smallvec 1.11.0", "sp-api", + "sp-arithmetic", "sp-block-builder", "sp-consensus-aura", "sp-core", @@ -2461,7 +2465,7 @@ dependencies = [ [[package]] name = "dapp-staking-v3-runtime-api" -version = "0.0.1-alpha" +version = "0.1.0" dependencies = [ "astar-primitives", "sp-api", @@ -13371,7 +13375,6 @@ dependencies = [ "pallet-contracts-primitives", "pallet-dapp-staking-migration", "pallet-dapp-staking-v3", - "pallet-dapps-staking", "pallet-dynamic-evm-base-fee", "pallet-ethereum", "pallet-evm", @@ -13411,7 +13414,6 @@ dependencies = [ "scale-info", "smallvec 1.11.0", "sp-api", - "sp-arithmetic", "sp-block-builder", "sp-consensus-aura", "sp-core", diff --git a/bin/collator/src/parachain/chain_spec/astar.rs b/bin/collator/src/parachain/chain_spec/astar.rs index cce4ef951..fcecc4563 100644 --- a/bin/collator/src/parachain/chain_spec/astar.rs +++ b/bin/collator/src/parachain/chain_spec/astar.rs @@ -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}; @@ -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 @@ -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(), + }, } } diff --git a/pallets/dapp-staking-migration/src/lib.rs b/pallets/dapp-staking-migration/src/lib.rs index 68dc8c023..56c343dcf 100644 --- a/pallets/dapp-staking-migration/src/lib.rs +++ b/pallets/dapp-staking-migration/src/lib.rs @@ -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 = ::MinimumLockedAmount::get(); let stakers: Vec<_> = pallet_dapps_staking::Ledger::::iter() .filter_map(|(staker, ledger)| { + total_locked.saturating_accrue(ledger.locked); if ledger.locked >= min_lock_amount { Some((staker, ledger.locked)) } else { @@ -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.", diff --git a/pallets/dapp-staking-migration/src/weights.rs b/pallets/dapp-staking-migration/src/weights.rs index 15db668cc..87250d7fa 100644 --- a/pallets/dapp-staking-migration/src/weights.rs +++ b/pallets/dapp-staking-migration/src/weights.rs @@ -20,16 +20,16 @@ //! 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 @@ -37,7 +37,7 @@ // --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)] @@ -74,8 +74,8 @@ impl WeightInfo for SubstrateWeight { // 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)) } @@ -85,8 +85,8 @@ impl WeightInfo for SubstrateWeight { // 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) @@ -99,15 +99,17 @@ impl WeightInfo for SubstrateWeight { /// 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) @@ -116,8 +118,8 @@ impl WeightInfo for SubstrateWeight { // 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) @@ -127,10 +129,10 @@ impl WeightInfo for SubstrateWeight { // 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()))) @@ -140,8 +142,8 @@ impl WeightInfo for SubstrateWeight { // 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) } } @@ -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)) } @@ -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) @@ -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) @@ -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) @@ -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()))) @@ -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) } } diff --git a/pallets/dapp-staking-v3/rpc/runtime-api/Cargo.toml b/pallets/dapp-staking-v3/rpc/runtime-api/Cargo.toml index 244715aa1..37b20002a 100644 --- a/pallets/dapp-staking-v3/rpc/runtime-api/Cargo.toml +++ b/pallets/dapp-staking-v3/rpc/runtime-api/Cargo.toml @@ -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 diff --git a/pallets/dapp-staking-v3/src/benchmarking/mod.rs b/pallets/dapp-staking-v3/src/benchmarking/mod.rs index af1cf1034..49efbc979 100644 --- a/pallets/dapp-staking-v3/src/benchmarking/mod.rs +++ b/pallets/dapp-staking-v3/src/benchmarking/mod.rs @@ -245,6 +245,8 @@ mod benchmarks { #[benchmark] fn claim_unlocked(x: Linear<0, { T::MaxNumberOfStakedContracts::get() }>) { + initial_config::(); + // Prepare staker account and lock some amount let staker: T::AccountId = whitelisted_caller(); let amount = (T::MinimumStakeAmount::get() + 1) diff --git a/pallets/dapp-staking-v3/src/benchmarking/utils.rs b/pallets/dapp-staking-v3/src/benchmarking/utils.rs index 83651decf..e7d9cd7dd 100644 --- a/pallets/dapp-staking-v3/src/benchmarking/utils.rs +++ b/pallets/dapp-staking-v3/src/benchmarking/utils.rs @@ -203,6 +203,8 @@ pub(super) fn initial_config() { StaticTierParams::::put(tier_params); TierConfig::::put(init_tier_config.clone()); + + Safeguard::::put(false); } /// Maximum number of contracts that 'makes sense' - considers both contract number limit & number of slots. diff --git a/pallets/dapp-staking-v3/src/lib.rs b/pallets/dapp-staking-v3/src/lib.rs index ff243de88..7e9d8d7d7 100644 --- a/pallets/dapp-staking-v3/src/lib.rs +++ b/pallets/dapp-staking-v3/src/lib.rs @@ -363,9 +363,8 @@ pub mod pallet { TooManyStakedContracts, /// There are no expired entries to cleanup for the account. NoExpiredEntries, - // TODO: remove this prior to the launch - /// Tier parameters aren't valid. - InvalidTierParameters, + /// Force call is not allowed in production. + ForceNotAllowed, } /// General information about dApp staking protocol state. @@ -458,6 +457,18 @@ pub mod pallet { #[pallet::storage] pub type HistoryCleanupMarker = StorageValue<_, CleanupMarker, ValueQuery>; + #[pallet::type_value] + pub fn DefaultSafeguard() -> bool { + // In production, safeguard is enabled by default. + true + } + + /// Safeguard to prevent unwanted operations in production. + /// Kept as a storage without extrinsic setter, so we can still enable it for some + /// chain-fork debugging if required. + #[pallet::storage] + pub type Safeguard = StorageValue<_, bool, ValueQuery, DefaultSafeguard>; + #[pallet::genesis_config] #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig { @@ -1510,7 +1521,6 @@ pub mod pallet { .into()) } - // TODO: make this unavailable in production, to be only used for testing /// Used to force a change of era or subperiod. /// The effect isn't immediate but will happen on the next block. /// @@ -1524,6 +1534,8 @@ pub mod pallet { Self::ensure_pallet_enabled()?; T::ManagerOrigin::ensure_origin(origin)?; + ensure!(!Safeguard::::get(), Error::::ForceNotAllowed); + // Ensure a 'change' happens on the next block ActiveProtocolState::::mutate(|state| { let current_block = frame_system::Pallet::::block_number(); @@ -1547,37 +1559,6 @@ pub mod pallet { Ok(()) } - - // TODO: remove this prior to Astar launch, to be only used for testing - #[pallet::call_index(100)] - #[pallet::weight(T::DbWeight::get().writes(1))] - pub fn force_set_tier_params( - origin: OriginFor, - value: TierParameters, - ) -> DispatchResult { - Self::ensure_pallet_enabled()?; - T::ManagerOrigin::ensure_origin(origin)?; - ensure!(value.is_valid(), Error::::InvalidTierParameters); - - StaticTierParams::::put(value); - - Ok(()) - } - - // TODO: remove this prior to Astar launch, to be only used for testing - #[pallet::call_index(101)] - #[pallet::weight(T::DbWeight::get().writes(1))] - pub fn force_set_tier_config( - origin: OriginFor, - value: TiersConfiguration, - ) -> DispatchResult { - Self::ensure_pallet_enabled()?; - T::ManagerOrigin::ensure_origin(origin)?; - - TierConfig::::put(value); - - Ok(()) - } } impl Pallet { diff --git a/pallets/dapp-staking-v3/src/test/mock.rs b/pallets/dapp-staking-v3/src/test/mock.rs index ae7e1c504..c1cc3d678 100644 --- a/pallets/dapp-staking-v3/src/test/mock.rs +++ b/pallets/dapp-staking-v3/src/test/mock.rs @@ -326,6 +326,7 @@ impl ExtBuilder { pallet_dapp_staking::StaticTierParams::::put(tier_params); pallet_dapp_staking::TierConfig::::put(init_tier_config.clone()); + pallet_dapp_staking::Safeguard::::put(false); DappStaking::on_initialize(System::block_number()); }); diff --git a/pallets/dapp-staking-v3/src/test/tests.rs b/pallets/dapp-staking-v3/src/test/tests.rs index 5f83eb7b5..f196dab81 100644 --- a/pallets/dapp-staking-v3/src/test/tests.rs +++ b/pallets/dapp-staking-v3/src/test/tests.rs @@ -19,7 +19,8 @@ use crate::test::{mock::*, testing_utils::*}; use crate::{ pallet::Config, ActiveProtocolState, DAppId, EraRewards, Error, Event, ForcingType, - IntegratedDApps, Ledger, NextDAppId, PeriodNumber, StakerInfo, Subperiod, TierConfig, + IntegratedDApps, Ledger, NextDAppId, PeriodNumber, Safeguard, StakerInfo, Subperiod, + TierConfig, }; use frame_support::{ @@ -2312,6 +2313,17 @@ fn force_with_incorrect_origin_fails() { }) } +#[test] +fn force_with_safeguard_on_fails() { + ExtBuilder::build().execute_with(|| { + Safeguard::::put(true); + assert_noop!( + DappStaking::force(RuntimeOrigin::root(), ForcingType::Era), + Error::::ForceNotAllowed + ); + }) +} + #[test] fn get_dapp_tier_assignment_and_rewards_basic_example_works() { ExtBuilder::build().execute_with(|| { @@ -2750,3 +2762,15 @@ fn unregister_after_max_number_of_contracts_allows_register_again() { assert_register(developer, &smart_contract); }) } + +#[test] +fn safeguard_on_by_default() { + let storage = frame_system::GenesisConfig::default() + .build_storage::() + .unwrap(); + + let mut ext = sp_io::TestExternalities::from(storage); + ext.execute_with(|| { + assert!(Safeguard::::get()); + }); +} diff --git a/pallets/inflation/src/benchmarking.rs b/pallets/inflation/src/benchmarking.rs index 6f3853799..e774b1497 100644 --- a/pallets/inflation/src/benchmarking.rs +++ b/pallets/inflation/src/benchmarking.rs @@ -84,27 +84,6 @@ mod benchmarks { assert_last_event::(Event::::InflationParametersForceChanged.into()); } - #[benchmark] - fn force_set_inflation_config() { - initial_config::(); - let config = InflationConfiguration { - recalculation_era: 456, - issuance_safety_cap: 112233, - collator_reward_per_block: 777, - treasury_reward_per_block: 444, - dapp_reward_pool_per_era: 55555, - base_staker_reward_pool_per_era: 77777, - adjustable_staker_reward_pool_per_era: 99999, - bonus_reward_pool_per_period: 123987, - ideal_staking_rate: Perquintill::from_percent(37), - }; - - #[extrinsic_call] - _(RawOrigin::Root, config.clone()); - - assert_last_event::(Event::::InflationConfigurationForceChanged { config }.into()); - } - #[benchmark] fn force_inflation_recalculation() { initial_config::(); diff --git a/pallets/inflation/src/lib.rs b/pallets/inflation/src/lib.rs index 1ea770ab2..1af12ca81 100644 --- a/pallets/inflation/src/lib.rs +++ b/pallets/inflation/src/lib.rs @@ -301,30 +301,6 @@ pub mod pallet { Ok(().into()) } - - /// Used to force-set the inflation configuration. - /// The parameters aren't checked for validity, since essentially anything can be valid. - /// - /// Must be called by `root` origin. - /// - /// Purpose of the call is testing & handling unforeseen circumstances. - /// - /// **NOTE:** and a TODO, remove this before deploying on mainnet. - #[pallet::call_index(2)] - #[pallet::weight(T::WeightInfo::force_set_inflation_config())] - pub fn force_set_inflation_config( - origin: OriginFor, - config: InflationConfiguration, - ) -> DispatchResult { - ensure_root(origin)?; - - config.sanity_check(); - ActiveInflationConfig::::put(config.clone()); - - Self::deposit_event(Event::::InflationConfigurationForceChanged { config }); - - Ok(().into()) - } } impl Pallet { diff --git a/pallets/inflation/src/tests.rs b/pallets/inflation/src/tests.rs index e7529c36a..8270429da 100644 --- a/pallets/inflation/src/tests.rs +++ b/pallets/inflation/src/tests.rs @@ -74,39 +74,6 @@ fn force_set_inflation_params_fails() { }) } -#[test] -fn force_set_inflation_config_work() { - ExternalityBuilder::build().execute_with(|| { - let mut new_config = ActiveInflationConfig::::get(); - new_config.recalculation_era = new_config.recalculation_era + 50; - - // Execute call, ensure it works - assert_ok!(Inflation::force_set_inflation_config( - RuntimeOrigin::root(), - new_config - )); - System::assert_last_event( - Event::InflationConfigurationForceChanged { config: new_config }.into(), - ); - - assert_eq!(ActiveInflationConfig::::get(), new_config); - }) -} - -#[test] -fn force_set_inflation_config_fails() { - ExternalityBuilder::build().execute_with(|| { - let mut new_config = ActiveInflationConfig::::get(); - new_config.recalculation_era = new_config.recalculation_era + 50; - - // Make sure action is privileged - assert_noop!( - Inflation::force_set_inflation_config(RuntimeOrigin::signed(1), new_config), - BadOrigin - ); - }) -} - #[test] fn force_inflation_recalculation_work() { ExternalityBuilder::build().execute_with(|| { @@ -460,14 +427,20 @@ fn cycle_configuration_works() { ExternalityBuilder::build().execute_with(|| { type CycleConfig = ::CycleConfiguration; - let eras_per_period = CycleConfig::eras_per_voting_subperiod() - + CycleConfig::eras_per_build_and_earn_subperiod(); + let eras_per_period = CycleConfig::eras_per_build_and_earn_subperiod() + 1; assert_eq!(CycleConfig::eras_per_period(), eras_per_period); + let period_in_era_lengths = CycleConfig::eras_per_voting_subperiod() + + CycleConfig::eras_per_build_and_earn_subperiod(); + assert_eq!(CycleConfig::period_in_era_lengths(), period_in_era_lengths); + let eras_per_cycle = eras_per_period * CycleConfig::periods_per_cycle(); assert_eq!(CycleConfig::eras_per_cycle(), eras_per_cycle); - let blocks_per_cycle = eras_per_cycle * CycleConfig::blocks_per_era(); + let cycle_in_era_lengths = period_in_era_lengths * CycleConfig::periods_per_cycle(); + assert_eq!(CycleConfig::cycle_in_era_lengths(), cycle_in_era_lengths); + + let blocks_per_cycle = cycle_in_era_lengths * CycleConfig::blocks_per_era(); assert_eq!(CycleConfig::blocks_per_cycle(), blocks_per_cycle); let build_and_earn_eras_per_cycle = diff --git a/pallets/inflation/src/weights.rs b/pallets/inflation/src/weights.rs index 702c0f11b..7eeb43f31 100644 --- a/pallets/inflation/src/weights.rs +++ b/pallets/inflation/src/weights.rs @@ -50,7 +50,6 @@ use core::marker::PhantomData; /// Weight functions needed for pallet_inflation. pub trait WeightInfo { fn force_set_inflation_params() -> Weight; - fn force_set_inflation_config() -> Weight; fn force_inflation_recalculation() -> Weight; fn recalculation() -> Weight; fn hooks_without_recalculation() -> Weight; @@ -69,13 +68,6 @@ impl WeightInfo for SubstrateWeight { Weight::from_parts(9_652_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } - fn force_set_inflation_config() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 9_168_000 picoseconds. - Weight::from_parts(9_436_000, 0) - } /// Storage: Inflation InflationParams (r:1 w:0) /// Proof: Inflation InflationParams (max_values: Some(1), max_size: Some(64), added: 559, mode: MaxEncodedLen) fn force_inflation_recalculation() -> Weight { @@ -121,13 +113,6 @@ impl WeightInfo for () { Weight::from_parts(9_652_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - fn force_set_inflation_config() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 9_168_000 picoseconds. - Weight::from_parts(9_436_000, 0) - } /// Storage: Inflation InflationParams (r:1 w:0) /// Proof: Inflation InflationParams (max_values: Some(1), max_size: Some(64), added: 559, mode: MaxEncodedLen) fn force_inflation_recalculation() -> Weight { diff --git a/primitives/src/dapp_staking.rs b/primitives/src/dapp_staking.rs index 23638089a..8042a2f4d 100644 --- a/primitives/src/dapp_staking.rs +++ b/primitives/src/dapp_staking.rs @@ -62,24 +62,34 @@ pub trait CycleConfiguration { fn blocks_per_era() -> BlockNumber; /// For how many standard era lengths does the period last. - fn eras_per_period() -> EraNumber { + fn period_in_era_lengths() -> EraNumber { Self::eras_per_voting_subperiod().saturating_add(Self::eras_per_build_and_earn_subperiod()) } /// For how many standard era lengths does the cycle (a 'year') last. - fn eras_per_cycle() -> EraNumber { - Self::eras_per_period().saturating_mul(Self::periods_per_cycle()) + fn cycle_in_era_lengths() -> EraNumber { + Self::period_in_era_lengths().saturating_mul(Self::periods_per_cycle()) } /// How many blocks are there per cycle (a 'year'). fn blocks_per_cycle() -> BlockNumber { - Self::blocks_per_era().saturating_mul(Self::eras_per_cycle()) + Self::blocks_per_era().saturating_mul(Self::cycle_in_era_lengths()) } /// For how many standard era lengths do all the build&earn subperiods in a cycle last. fn build_and_earn_eras_per_cycle() -> EraNumber { Self::eras_per_build_and_earn_subperiod().saturating_mul(Self::periods_per_cycle()) } + + /// How many distinct eras are there in a single period. + fn eras_per_period() -> EraNumber { + Self::eras_per_build_and_earn_subperiod().saturating_add(1) + } + + /// How many distinct eras are there in a cycle. + fn eras_per_cycle() -> EraNumber { + Self::eras_per_period().saturating_mul(Self::periods_per_cycle()) + } } /// Trait for observers (listeners) of various events related to dApp staking protocol. diff --git a/runtime/astar/Cargo.toml b/runtime/astar/Cargo.toml index 8ee6f6f5d..9584ef156 100644 --- a/runtime/astar/Cargo.toml +++ b/runtime/astar/Cargo.toml @@ -20,6 +20,7 @@ smallvec = { workspace = true } fp-rpc = { workspace = true } fp-self-contained = { workspace = true } sp-api = { workspace = true } +sp-arithmetic = { workspace = true } sp-block-builder = { workspace = true } sp-consensus-aura = { workspace = true } sp-core = { workspace = true } @@ -92,24 +93,28 @@ orml-xtokens = { workspace = true } array-bytes = { workspace = true } frame-benchmarking = { workspace = true, optional = true } frame-system-benchmarking = { workspace = true, optional = true } -pallet-collective = { workspace = true, optional = true } # try-runtime frame-try-runtime = { workspace = true, optional = true } # Astar pallets astar-primitives = { workspace = true } -pallet-block-rewards-hybrid = { workspace = true } pallet-collator-selection = { workspace = true } +pallet-dapp-staking-migration = { workspace = true } +pallet-dapp-staking-v3 = { workspace = true } pallet-dapps-staking = { workspace = true } pallet-evm-precompile-assets-erc20 = { workspace = true } -pallet-evm-precompile-dapps-staking = { workspace = true } +pallet-evm-precompile-dapp-staking-v3 = { workspace = true } pallet-evm-precompile-sr25519 = { workspace = true } pallet-evm-precompile-substrate-ecdsa = { workspace = true } pallet-evm-precompile-xcm = { workspace = true } +pallet-inflation = { workspace = true } +pallet-static-price-provider = { workspace = true } pallet-xc-asset-config = { workspace = true } pallet-xcm = { workspace = true } +dapp-staking-v3-runtime-api = { workspace = true } + # Moonbeam tracing moonbeam-evm-tracer = { workspace = true, optional = true } moonbeam-rpc-primitives-debug = { workspace = true, optional = true } @@ -129,6 +134,7 @@ std = [ "sp-api/std", "sp-core/std", "sp-consensus-aura/std", + "sp-arithmetic/std", "sp-io/std", "sp-runtime/std", "sp-runtime-interface/std", @@ -146,9 +152,12 @@ std = [ "pallet-aura/std", "pallet-balances/std", "pallet-proxy/std", - "pallet-block-rewards-hybrid/std", - "pallet-dapps-staking/std", - "pallet-evm-precompile-dapps-staking/std", + "pallet-static-price-provider/std", + "pallet-dapp-staking-v3/std", + "pallet-dapp-staking-migration/std", + "dapp-staking-v3-runtime-api/std", + "pallet-inflation/std", + "pallet-evm-precompile-dapp-staking-v3/std", "pallet-evm-precompile-sr25519/std", "pallet-evm-precompile-assets-erc20/std", "pallet-evm-precompile-substrate-ecdsa/std", @@ -212,10 +221,10 @@ runtime-benchmarks = [ 'pallet-balances/runtime-benchmarks', "pallet-proxy/runtime-benchmarks", 'pallet-timestamp/runtime-benchmarks', - 'pallet-collective/runtime-benchmarks', "pallet-ethereum/runtime-benchmarks", - "pallet-dapps-staking/runtime-benchmarks", - "pallet-block-rewards-hybrid/runtime-benchmarks", + "pallet-dapp-staking-v3/runtime-benchmarks", + "pallet-dapp-staking-migration/runtime-benchmarks", + "pallet-inflation/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "xcm-builder/runtime-benchmarks", "pallet-xc-asset-config/runtime-benchmarks", @@ -235,12 +244,15 @@ try-runtime = [ "pallet-aura/try-runtime", "pallet-balances/try-runtime", "pallet-proxy/try-runtime", - "pallet-block-rewards-hybrid/try-runtime", "pallet-dapps-staking/try-runtime", + "pallet-dapp-staking-v3/try-runtime", + "pallet-dapp-staking-migration/try-runtime", + "pallet-inflation/try-runtime", "pallet-sudo/try-runtime", "pallet-timestamp/try-runtime", "pallet-transaction-payment/try-runtime", "pallet-utility/try-runtime", + "pallet-static-price-provider/try-runtime", "pallet-vesting/try-runtime", "pallet-xc-asset-config/try-runtime", "pallet-ethereum/try-runtime", diff --git a/runtime/astar/src/lib.rs b/runtime/astar/src/lib.rs index 69c0a8256..fa9b733b1 100644 --- a/runtime/astar/src/lib.rs +++ b/runtime/astar/src/lib.rs @@ -22,11 +22,6 @@ // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. #![recursion_limit = "256"] -pub use crate::precompiles::WhitelistedCalls; -pub use astar_primitives::{ - evm::EvmRevertCodeHandler, xcm::AssetLocationIdConverter, AccountId, Address, AssetId, Balance, - BlockNumber, Hash, Header, Index, Signature, -}; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use frame_support::{ construct_runtime, @@ -49,7 +44,6 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, EnsureSigned, }; -pub use pallet_block_rewards_hybrid::RewardDistributionConfig; use pallet_ethereum::PostLogContent; use pallet_evm::{FeeCalculator, GasWeightMapping, Runner}; use pallet_evm_precompile_assets_erc20::AddressToAssetId; @@ -70,7 +64,23 @@ use sp_runtime::{ transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError}, ApplyExtrinsicResult, FixedPointNumber, Perbill, Permill, Perquintill, RuntimeDebug, }; -use sp_std::prelude::*; +use sp_std::{collections::btree_map::BTreeMap, prelude::*}; + +use astar_primitives::{ + dapp_staking::{ + AccountCheck as DappStakingAccountCheck, CycleConfiguration, DAppId, EraNumber, + PeriodNumber, SmartContract, TierId, + }, + evm::EvmRevertCodeHandler, + xcm::AssetLocationIdConverter, + Address, AssetId, BlockNumber, Hash, Header, Index, +}; +pub use astar_primitives::{AccountId, Balance, Signature}; + +pub use pallet_dapp_staking_v3::TierThreshold; +pub use pallet_inflation::InflationParameters; + +pub use crate::precompiles::WhitelistedCalls; #[cfg(any(feature = "std", test))] use sp_version::NativeVersion; @@ -263,7 +273,7 @@ parameter_types! { impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; - type OnTimestampSet = BlockReward; + type OnTimestampSet = (); type MinimumPeriod = MinimumPeriod; type WeightInfo = pallet_timestamp::weights::SubstrateWeight; } @@ -336,28 +346,115 @@ impl pallet_dapps_staking::Config for Runtime { type MaxEraStakeValues = MaxEraStakeValues; // Not allowed on Astar yet type UnregisteredDappRewardRetention = ConstU32<{ u32::MAX }>; + // Needed so benchmark can use the pallets extrinsics + #[cfg(feature = "runtime-benchmarks")] type ForcePalletDisabled = ConstBool; + #[cfg(not(feature = "runtime-benchmarks"))] + type ForcePalletDisabled = ConstBool; // Fee required to claim rewards for another account. Calculated & tested manually. type DelegateClaimFee = ConstU128<057_950_348_114_187_155>; } -/// Multi-VM pointer to smart contract instance. -#[derive( - PartialEq, Eq, Copy, Clone, Encode, Decode, RuntimeDebug, MaxEncodedLen, scale_info::TypeInfo, -)] -pub enum SmartContract { - /// EVM smart contract instance. - Evm(sp_core::H160), - /// Wasm smart contract instance. - Wasm(AccountId), +impl pallet_static_price_provider::Config for Runtime { + type RuntimeEvent = RuntimeEvent; } -impl Default for SmartContract { - fn default() -> Self { - SmartContract::Evm(H160::repeat_byte(0x00)) +#[cfg(feature = "runtime-benchmarks")] +pub struct BenchmarkHelper(sp_std::marker::PhantomData<(SC, ACC)>); +#[cfg(feature = "runtime-benchmarks")] +impl pallet_dapp_staking_v3::BenchmarkHelper, AccountId> + for BenchmarkHelper, AccountId> +{ + fn get_smart_contract(id: u32) -> SmartContract { + let id_bytes = id.to_le_bytes(); + let mut account = [0u8; 32]; + account[..id_bytes.len()].copy_from_slice(&id_bytes); + + SmartContract::Wasm(AccountId::from(account)) + } + + fn set_balance(account: &AccountId, amount: Balance) { + use frame_support::traits::fungible::Unbalanced as FunUnbalanced; + Balances::write_balance(account, amount) + .expect("Must succeed in test/benchmark environment."); } } +pub struct AccountCheck; +impl DappStakingAccountCheck for AccountCheck { + fn allowed_to_stake(account: &AccountId) -> bool { + !CollatorSelection::is_account_candidate(account) + } +} + +impl pallet_dapp_staking_v3::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeFreezeReason = RuntimeFreezeReason; + type Currency = Balances; + type SmartContract = SmartContract; + type ManagerOrigin = frame_system::EnsureRoot; + type NativePriceProvider = StaticPriceProvider; + type StakingRewardHandler = Inflation; + type CycleConfiguration = InflationCycleConfig; + type Observers = Inflation; + type AccountCheck = AccountCheck; + type EraRewardSpanLength = ConstU32<16>; + type RewardRetentionInPeriods = ConstU32<4>; + type MaxNumberOfContracts = ConstU32<500>; + type MaxUnlockingChunks = ConstU32<8>; + type MinimumLockedAmount = MinimumStakingAmount; + type UnlockingPeriod = ConstU32<9>; + type MaxNumberOfStakedContracts = ConstU32<16>; + type MinimumStakeAmount = MinimumStakingAmount; + type NumberOfTiers = ConstU32<4>; + type WeightInfo = weights::pallet_dapp_staking_v3::SubstrateWeight; + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkHelper = BenchmarkHelper, AccountId>; +} + +pub struct InflationPayoutPerBlock; +impl pallet_inflation::PayoutPerBlock for InflationPayoutPerBlock { + fn treasury(reward: NegativeImbalance) { + Balances::resolve_creating(&TreasuryPalletId::get().into_account_truncating(), reward); + } + + fn collators(reward: NegativeImbalance) { + ToStakingPot::on_unbalanced(reward); + } +} + +pub struct InflationCycleConfig; +impl CycleConfiguration for InflationCycleConfig { + fn periods_per_cycle() -> u32 { + 3 + } + + fn eras_per_voting_subperiod() -> u32 { + 11 + } + + fn eras_per_build_and_earn_subperiod() -> u32 { + 111 + } + + fn blocks_per_era() -> BlockNumber { + 24 * HOURS + } +} + +impl pallet_inflation::Config for Runtime { + type Currency = Balances; + type PayoutPerBlock = InflationPayoutPerBlock; + type CycleConfiguration = InflationCycleConfig; + type RuntimeEvent = RuntimeEvent; + type WeightInfo = weights::pallet_inflation::SubstrateWeight; +} + +impl pallet_dapp_staking_migration::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = pallet_dapp_staking_migration::weights::SubstrateWeight; +} + impl pallet_utility::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; @@ -429,9 +526,8 @@ parameter_types! { pub struct CollatorSelectionAccountCheck; impl pallet_collator_selection::AccountCheck for CollatorSelectionAccountCheck { - fn allowed_candidacy(_account: &AccountId) -> bool { - // TODO: update this when dApp staking v3 is integrated - true + fn allowed_candidacy(account: &AccountId) -> bool { + !DappStaking::is_staker(account) } } @@ -469,41 +565,6 @@ impl OnUnbalanced for ToStakingPot { } } -pub struct DappsStakingTvlProvider(); -impl Get for DappsStakingTvlProvider { - fn get() -> Balance { - DappsStaking::tvl() - } -} - -pub struct BeneficiaryPayout(); -impl pallet_block_rewards_hybrid::BeneficiaryPayout for BeneficiaryPayout { - fn treasury(reward: NegativeImbalance) { - Balances::resolve_creating(&TreasuryPalletId::get().into_account_truncating(), reward); - } - - fn collators(reward: NegativeImbalance) { - ToStakingPot::on_unbalanced(reward); - } - - fn dapps_staking(stakers: NegativeImbalance, dapps: NegativeImbalance) { - DappsStaking::rewards(stakers, dapps) - } -} - -parameter_types! { - pub const MaxBlockRewardAmount: Balance = 231_206_532 * MICROASTR; -} - -impl pallet_block_rewards_hybrid::Config for Runtime { - type Currency = Balances; - type DappsStakingTvlProvider = DappsStakingTvlProvider; - type BeneficiaryPayout = BeneficiaryPayout; - type MaxBlockRewardAmount = MaxBlockRewardAmount; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = pallet_block_rewards_hybrid::weights::SubstrateWeight; -} - parameter_types! { pub const ExistentialDeposit: Balance = 1_000_000; pub const MaxLocks: u32 = 50; @@ -521,9 +582,9 @@ impl pallet_balances::Config for Runtime { type AccountStore = frame_system::Pallet; type WeightInfo = pallet_balances::weights::SubstrateWeight; type HoldIdentifier = (); - type FreezeIdentifier = (); + type FreezeIdentifier = RuntimeFreezeReason; type MaxHolds = ConstU32<0>; - type MaxFreezes = ConstU32<0>; + type MaxFreezes = ConstU32<1>; } impl AddressToAssetId for Runtime { @@ -876,7 +937,7 @@ pub enum ProxyType { /// Only reject_announcement call from pallet proxy allowed for proxy account CancelProxy, /// All runtime calls from pallet DappStaking allowed for proxy account - DappsStaking, + DappStaking, /// Only claim_staker call from pallet DappStaking allowed for proxy account StakerRewardClaim, } @@ -908,7 +969,7 @@ impl InstanceFilter for ProxyType { | RuntimeCall::Vesting(pallet_vesting::Call::vest{..}) | RuntimeCall::Vesting(pallet_vesting::Call::vest_other{..}) // Specifically omitting Vesting `vested_transfer`, and `force_vested_transfer` - | RuntimeCall::DappsStaking(..) + | RuntimeCall::DappStaking(..) // Skip entire Assets pallet | RuntimeCall::CollatorSelection(..) | RuntimeCall::Session(..) @@ -940,13 +1001,15 @@ impl InstanceFilter for ProxyType { RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) ) } - ProxyType::DappsStaking => { - matches!(c, RuntimeCall::DappsStaking(..)) + ProxyType::DappStaking => { + matches!(c, RuntimeCall::DappStaking(..)) } ProxyType::StakerRewardClaim => { matches!( c, - RuntimeCall::DappsStaking(pallet_dapps_staking::Call::claim_staker { .. }) + RuntimeCall::DappStaking( + pallet_dapp_staking_v3::Call::claim_staker_rewards { .. } + ) ) } } @@ -957,7 +1020,7 @@ impl InstanceFilter for ProxyType { (x, y) if x == y => true, (ProxyType::Any, _) => true, (_, ProxyType::Any) => false, - (ProxyType::DappsStaking, ProxyType::StakerRewardClaim) => true, + (ProxyType::DappStaking, ProxyType::StakerRewardClaim) => true, _ => false, } } @@ -1008,8 +1071,12 @@ construct_runtime!( TransactionPayment: pallet_transaction_payment = 30, Balances: pallet_balances = 31, Vesting: pallet_vesting = 32, - DappsStaking: pallet_dapps_staking = 34, - BlockReward: pallet_block_rewards_hybrid = 35, +// Inflation needs to execute `on_initialize` as soon as possible, and `on_finalize` as late as possible. + // However, we need to execute Balance genesis before Inflation genesis, otherwise we'll have zero issuance when Inflation + // logic is executed. + // TODO: Address this later. It would be best if Inflation was first pallet. + Inflation: pallet_inflation = 33, + DappStaking: pallet_dapp_staking_v3 = 34, Assets: pallet_assets = 36, Authorship: pallet_authorship = 40, @@ -1032,6 +1099,13 @@ construct_runtime!( Contracts: pallet_contracts = 70, Sudo: pallet_sudo = 99, + + // To be removed & cleaned up once proper oracle is implemented + StaticPriceProvider: pallet_static_price_provider = 253, + // To be removed & cleaned up after migration has been finished + DappStakingMigration: pallet_dapp_staking_migration = 254, + // Legacy dApps staking v2, to be removed after migration has been finished + DappsStaking: pallet_dapps_staking = 255, } ); @@ -1069,7 +1143,135 @@ pub type Executive = frame_executive::Executive< Migrations, >; -pub type Migrations = (); +parameter_types! { + pub const BlockRewardName: &'static str = "BlockReward"; +} +/// All migrations that will run on the next runtime upgrade. +/// +/// Once done, migrations should be removed from the tuple. +pub type Migrations = ( + pallet_static_price_provider::InitActivePrice, + pallet_inflation::PalletInflationInitConfig, + pallet_dapp_staking_v3::migrations::DAppStakingV3InitConfig< + Runtime, + InitDappStakingV3Params, + InitActivePriceGet, + >, + // This will handle new pallet storage version setting & it will put the new pallet into maintenance mode. + // But it's most important for testing with try-runtime. + pallet_dapp_staking_migration::DappStakingMigrationHandler, + frame_support::migrations::RemovePallet< + BlockRewardName, + ::DbWeight, + >, +); + +use sp_arithmetic::fixed_point::FixedU64; +pub struct InitActivePriceGet; +impl Get for InitActivePriceGet { + fn get() -> FixedU64 { + FixedU64::from_rational(18, 100) + } +} + +/// Used to initialize inflation parameters for the runtime. +pub struct InitInflationParamsHelper; +impl Get<(pallet_inflation::InflationParameters, EraNumber, Weight)> for InitInflationParamsHelper { + fn get() -> (pallet_inflation::InflationParameters, EraNumber, Weight) { + ( + pallet_inflation::InflationParameters { + // Recalculation is done every two weeks, hence the small %. + max_inflation_rate: Perquintill::from_percent(7), + treasury_part: Perquintill::from_percent(5), + collators_part: Perquintill::from_rational(32_u64, 1000), + dapps_part: Perquintill::from_percent(13), + base_stakers_part: Perquintill::from_percent(25), + adjustable_stakers_part: Perquintill::from_percent(40), + bonus_part: Perquintill::from_rational(138_u64, 1000), + ideal_staking_rate: Perquintill::from_percent(50), + }, + pallet_dapps_staking::CurrentEra::::get().saturating_add(1), + ::DbWeight::get().reads(1), + ) + } +} + +use frame_support::BoundedVec; +use pallet_dapp_staking_v3::{TierParameters, TiersConfiguration}; +type NumberOfTiers = ::NumberOfTiers; +/// Used to initialize dApp staking parameters for the runtime. +pub struct InitDappStakingV3Params; +impl + Get<( + EraNumber, + TierParameters, + TiersConfiguration, + )> for InitDappStakingV3Params +{ + fn get() -> ( + EraNumber, + TierParameters, + TiersConfiguration, + ) { + // 1. Prepare init values + + // Init era of dApp staking v3 should be the next era after dApp staking v2 + let init_era = pallet_dapps_staking::CurrentEra::::get().saturating_add(1); + + // Reward portions according to the Tokenomics 2.0 report + let reward_portion = BoundedVec::try_from(vec![ + Permill::from_percent(25), + Permill::from_percent(47), + Permill::from_percent(25), + Permill::from_percent(3), + ]) + .unwrap_or_default(); + + // Tier thresholds adjusted according to numbers observed on Shibuya + let tier_thresholds = BoundedVec::try_from(vec![ + TierThreshold::DynamicTvlAmount { + amount: ASTR.saturating_mul(300_000_000), + minimum_amount: ASTR.saturating_mul(200_000_000), + }, + TierThreshold::DynamicTvlAmount { + amount: ASTR.saturating_mul(75_000_000), + minimum_amount: ASTR.saturating_mul(50_000_000), + }, + TierThreshold::DynamicTvlAmount { + amount: ASTR.saturating_mul(20_000_000), + minimum_amount: ASTR.saturating_mul(15_000_000), + }, + TierThreshold::FixedTvlAmount { + amount: ASTR.saturating_mul(1_500_000), + }, + ]) + .unwrap_or_default(); + + // 2. Tier params + let tier_params = + TierParameters::<::NumberOfTiers> { + reward_portion: reward_portion.clone(), + slot_distribution: BoundedVec::try_from(vec![ + Permill::from_percent(5), + Permill::from_percent(20), + Permill::from_percent(30), + Permill::from_percent(45), + ]) + .unwrap_or_default(), + tier_thresholds: tier_thresholds.clone(), + }; + + // 3. Init tier config + let init_tier_config = TiersConfiguration { + number_of_slots: 100, + slots_per_tier: BoundedVec::try_from(vec![5, 20, 30, 45]).unwrap_or_default(), + reward_portion, + tier_thresholds, + }; + + (init_era, tier_params, init_tier_config) + } +} type EventRecord = frame_system::EventRecord< ::RuntimeEvent, @@ -1147,7 +1349,9 @@ mod benches { [pallet_balances, Balances] [pallet_timestamp, Timestamp] [pallet_dapps_staking, DappsStaking] - [block_rewards_hybrid, BlockReward] + [pallet_dapp_staking_v3, DappStaking] + [pallet_inflation, Inflation] + [pallet_dapp_staking_migration, DappStakingMigration] [pallet_xc_asset_config, XcAssetConfig] [pallet_collator_selection, CollatorSelection] [pallet_xcm, PolkadotXcm] @@ -1609,6 +1813,28 @@ impl_runtime_apis! { } } + impl dapp_staking_v3_runtime_api::DappStakingApi for Runtime { + fn periods_per_cycle() -> PeriodNumber { + InflationCycleConfig::periods_per_cycle() + } + + fn eras_per_voting_subperiod() -> EraNumber { + InflationCycleConfig::eras_per_voting_subperiod() + } + + fn eras_per_build_and_earn_subperiod() -> EraNumber { + InflationCycleConfig::eras_per_build_and_earn_subperiod() + } + + fn blocks_per_era() -> BlockNumber { + InflationCycleConfig::blocks_per_era() + } + + fn get_dapp_tier_assignment() -> BTreeMap { + DappStaking::get_dapp_tier_assignment() + } + } + #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { fn benchmark_metadata(extra: bool) -> ( diff --git a/runtime/astar/src/precompiles.rs b/runtime/astar/src/precompiles.rs index 938f4fec0..2b483d85e 100644 --- a/runtime/astar/src/precompiles.rs +++ b/runtime/astar/src/precompiles.rs @@ -24,7 +24,7 @@ use frame_support::{parameter_types, traits::Contains}; use pallet_evm_precompile_assets_erc20::Erc20AssetsPrecompileSet; use pallet_evm_precompile_blake2::Blake2F; use pallet_evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing}; -use pallet_evm_precompile_dapps_staking::DappsStakingWrapper; +use pallet_evm_precompile_dapp_staking_v3::DappStakingV3Precompile; use pallet_evm_precompile_dispatch::Dispatch; use pallet_evm_precompile_ed25519::Ed25519Verify; use pallet_evm_precompile_modexp::Modexp; @@ -57,7 +57,7 @@ impl Contains for WhitelistedCalls { | RuntimeCall::Utility(pallet_utility::Call::batch_all { calls }) => { calls.iter().all(|call| WhitelistedCalls::contains(call)) } - RuntimeCall::DappsStaking(_) => true, + RuntimeCall::DappStaking(_) => true, RuntimeCall::Assets(pallet_assets::Call::transfer { .. }) => true, _ => false, } @@ -91,7 +91,7 @@ pub type AstarPrecompilesSetAt = ( // Astar specific precompiles: PrecompileAt< AddressU64<20481>, - DappsStakingWrapper, + DappStakingV3Precompile, (CallableByContract, CallableByPrecompile), >, PrecompileAt< diff --git a/runtime/astar/src/weights/mod.rs b/runtime/astar/src/weights/mod.rs index 6471081ec..23a0bb4e9 100644 --- a/runtime/astar/src/weights/mod.rs +++ b/runtime/astar/src/weights/mod.rs @@ -17,4 +17,6 @@ // along with Astar. If not, see . pub mod pallet_assets; +pub mod pallet_dapp_staking_v3; +pub mod pallet_inflation; pub mod pallet_xcm; diff --git a/runtime/astar/src/weights/pallet_dapp_staking_v3.rs b/runtime/astar/src/weights/pallet_dapp_staking_v3.rs new file mode 100644 index 000000000..d07b37ab1 --- /dev/null +++ b/runtime/astar/src/weights/pallet_dapp_staking_v3.rs @@ -0,0 +1,455 @@ +// This file is part of Astar. + +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Astar is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Astar. If not, see . + +//! Autogenerated weights for pallet_dapp_staking_v3 +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! 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("astar-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/release/astar-collator +// benchmark +// pallet +// --chain=astar-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_dapp_staking_v3 +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=./benchmark-results/astar-dev/dapp_staking_v3_weights.rs +// --template=./scripts/templates/weight-template.hbs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use core::marker::PhantomData; +use pallet_dapp_staking_v3::WeightInfo; + +/// Weights for pallet_dapp_staking_v3 using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + fn maintenance_mode() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 9_172_000 picoseconds. + Weight::from_parts(9_411_000, 0) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:1) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) + /// Storage: DappStaking CounterForIntegratedDApps (r:1 w:1) + /// Proof: DappStaking CounterForIntegratedDApps (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: DappStaking NextDAppId (r:1 w:1) + /// Proof: DappStaking NextDAppId (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) + fn register() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `3086` + // Minimum execution time: 16_953_000 picoseconds. + Weight::from_parts(17_223_000, 3086) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:1) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) + fn set_dapp_reward_beneficiary() -> Weight { + // Proof Size summary in bytes: + // Measured: `74` + // Estimated: `3086` + // Minimum execution time: 13_226_000 picoseconds. + Weight::from_parts(13_585_000, 3086) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:1) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) + fn set_dapp_owner() -> Weight { + // Proof Size summary in bytes: + // Measured: `74` + // Estimated: `3086` + // Minimum execution time: 13_029_000 picoseconds. + Weight::from_parts(13_242_000, 3086) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:1) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) + /// Storage: DappStaking CounterForIntegratedDApps (r:1 w:1) + /// Proof: DappStaking CounterForIntegratedDApps (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: DappStaking ContractStake (r:0 w:1) + /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) + fn unregister() -> Weight { + // Proof Size summary in bytes: + // Measured: `74` + // Estimated: `3086` + // Minimum execution time: 17_784_000 picoseconds. + Weight::from_parts(18_196_000, 3086) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// 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: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + fn lock_new_account() -> Weight { + // Proof Size summary in bytes: + // Measured: `138` + // Estimated: `4764` + // Minimum execution time: 34_451_000 picoseconds. + Weight::from_parts(35_062_000, 4764) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + fn lock_existing_account() -> Weight { + // Proof Size summary in bytes: + // Measured: `158` + // Estimated: `4764` + // Minimum execution time: 37_185_000 picoseconds. + Weight::from_parts(37_955_000, 4764) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + fn unlock() -> Weight { + // Proof Size summary in bytes: + // Measured: `158` + // Estimated: `4764` + // Minimum execution time: 33_457_000 picoseconds. + Weight::from_parts(33_833_000, 4764) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + /// The range of component `x` is `[0, 16]`. + fn claim_unlocked(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `190` + // Estimated: `4764` + // Minimum execution time: 36_715_000 picoseconds. + Weight::from_parts(38_253_697, 4764) + // Standard Error: 4_195 + .saturating_add(Weight::from_parts(173_577, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + fn relock_unlocking() -> Weight { + // Proof Size summary in bytes: + // Measured: `200` + // Estimated: `4764` + // Minimum execution time: 33_049_000 picoseconds. + Weight::from_parts(33_731_000, 4764) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:0) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: DappStaking StakerInfo (r:1 w:1) + /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: DappStaking ContractStake (r:1 w:1) + /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + fn stake() -> Weight { + // Proof Size summary in bytes: + // Measured: `251` + // Estimated: `4764` + // Minimum execution time: 44_722_000 picoseconds. + Weight::from_parts(44_977_000, 4764) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:0) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: DappStaking StakerInfo (r:1 w:1) + /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: DappStaking ContractStake (r:1 w:1) + /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + fn unstake() -> Weight { + // Proof Size summary in bytes: + // Measured: `432` + // Estimated: `4764` + // Minimum execution time: 48_465_000 picoseconds. + Weight::from_parts(49_098_000, 4764) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: DappStaking EraRewards (r:1 w:0) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) + /// Storage: DappStaking PeriodEnd (r:1 w:0) + /// Proof: DappStaking PeriodEnd (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// The range of component `x` is `[1, 16]`. + fn claim_staker_rewards_past_period(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `541` + // Estimated: `4764` + // Minimum execution time: 51_303_000 picoseconds. + Weight::from_parts(49_440_154, 4764) + // Standard Error: 4_315 + .saturating_add(Weight::from_parts(3_164_288, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: DappStaking EraRewards (r:1 w:0) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// The range of component `x` is `[1, 16]`. + fn claim_staker_rewards_ongoing_period(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `519` + // Estimated: `4764` + // Minimum execution time: 48_956_000 picoseconds. + Weight::from_parts(46_951_013, 4764) + // Standard Error: 4_800 + .saturating_add(Weight::from_parts(3_195_446, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: DappStaking StakerInfo (r:1 w:1) + /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: DappStaking PeriodEnd (r:1 w:0) + /// Proof: DappStaking PeriodEnd (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen) + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + fn claim_bonus_reward() -> Weight { + // Proof Size summary in bytes: + // Measured: `271` + // Estimated: `3775` + // Minimum execution time: 41_373_000 picoseconds. + Weight::from_parts(42_446_000, 3775) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:0) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) + /// Storage: DappStaking DAppTiers (r:1 w:1) + /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(1583), added: 4058, mode: MaxEncodedLen) + fn claim_dapp_reward() -> Weight { + // Proof Size summary in bytes: + // Measured: `2584` + // Estimated: `5048` + // Minimum execution time: 57_307_000 picoseconds. + Weight::from_parts(58_880_000, 5048) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: DappStaking IntegratedDApps (r:1 w:0) + /// Proof: DappStaking IntegratedDApps (max_values: Some(65535), max_size: Some(116), added: 2096, mode: MaxEncodedLen) + /// Storage: DappStaking StakerInfo (r:1 w:1) + /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + fn unstake_from_unregistered() -> Weight { + // Proof Size summary in bytes: + // Measured: `318` + // Estimated: `4764` + // Minimum execution time: 41_250_000 picoseconds. + Weight::from_parts(41_849_000, 4764) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } + /// Storage: DappStaking StakerInfo (r:17 w:16) + /// Proof: DappStaking StakerInfo (max_values: None, max_size: Some(138), added: 2613, mode: MaxEncodedLen) + /// Storage: DappStaking Ledger (r:1 w:1) + /// Proof: DappStaking Ledger (max_values: None, max_size: Some(310), added: 2785, mode: MaxEncodedLen) + /// Storage: Balances Freezes (r:1 w:1) + /// Proof: Balances Freezes (max_values: None, max_size: Some(67), added: 2542, mode: MaxEncodedLen) + /// Storage: Balances Locks (r:1 w:0) + /// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen) + /// The range of component `x` is `[1, 16]`. + fn cleanup_expired_entries(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `257 + x * (69 ±0)` + // Estimated: `4764 + x * (2613 ±0)` + // Minimum execution time: 42_815_000 picoseconds. + Weight::from_parts(39_631_627, 4764) + // Standard Error: 6_828 + .saturating_add(Weight::from_parts(4_984_583, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(x.into()))) + .saturating_add(Weight::from_parts(0, 2613).saturating_mul(x.into())) + } + /// Storage: DappStaking Safeguard (r:1 w:0) + /// Proof: DappStaking Safeguard (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) + fn force() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `1486` + // Minimum execution time: 11_946_000 picoseconds. + Weight::from_parts(12_108_000, 1486) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + /// Storage: DappStaking EraRewards (r:1 w:1) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) + fn on_initialize_voting_to_build_and_earn() -> Weight { + // Proof Size summary in bytes: + // Measured: `16` + // Estimated: `4254` + // Minimum execution time: 17_411_000 picoseconds. + Weight::from_parts(17_960_000, 4254) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + /// Storage: DappStaking StaticTierParams (r:1 w:0) + /// Proof: DappStaking StaticTierParams (max_values: Some(1), max_size: Some(167), added: 662, mode: MaxEncodedLen) + /// Storage: DappStaking TierConfig (r:1 w:1) + /// Proof: DappStaking TierConfig (max_values: Some(1), max_size: Some(161), added: 656, mode: MaxEncodedLen) + /// Storage: DappStaking PeriodEnd (r:1 w:2) + /// Proof: DappStaking PeriodEnd (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen) + /// Storage: DappStaking HistoryCleanupMarker (r:1 w:1) + /// Proof: DappStaking HistoryCleanupMarker (max_values: Some(1), max_size: Some(12), added: 507, mode: MaxEncodedLen) + /// Storage: DappStaking EraRewards (r:1 w:1) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) + /// Storage: DappStaking DAppTiers (r:0 w:1) + /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(1583), added: 4058, mode: MaxEncodedLen) + fn on_initialize_build_and_earn_to_voting() -> Weight { + // Proof Size summary in bytes: + // Measured: `837` + // Estimated: `4254` + // Minimum execution time: 47_150_000 picoseconds. + Weight::from_parts(49_622_000, 4254) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(7_u64)) + } + /// Storage: DappStaking CurrentEraInfo (r:1 w:1) + /// Proof: DappStaking CurrentEraInfo (max_values: Some(1), max_size: Some(112), added: 607, mode: MaxEncodedLen) + /// Storage: DappStaking EraRewards (r:1 w:1) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) + /// Storage: DappStaking DAppTiers (r:0 w:1) + /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(1583), added: 4058, mode: MaxEncodedLen) + fn on_initialize_build_and_earn_to_build_and_earn() -> Weight { + // Proof Size summary in bytes: + // Measured: `68` + // Estimated: `4254` + // Minimum execution time: 23_567_000 picoseconds. + Weight::from_parts(24_230_000, 4254) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: DappStaking ContractStake (r:101 w:0) + /// Proof: DappStaking ContractStake (max_values: Some(65535), max_size: Some(91), added: 2071, mode: MaxEncodedLen) + /// Storage: DappStaking TierConfig (r:1 w:0) + /// Proof: DappStaking TierConfig (max_values: Some(1), max_size: Some(161), added: 656, mode: MaxEncodedLen) + /// The range of component `x` is `[0, 100]`. + fn dapp_tier_assignment(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `152 + x * (32 ±0)` + // Estimated: `3061 + x * (2071 ±0)` + // Minimum execution time: 7_476_000 picoseconds. + Weight::from_parts(12_571_316, 3061) + // Standard Error: 3_559 + .saturating_add(Weight::from_parts(2_337_771, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) + .saturating_add(Weight::from_parts(0, 2071).saturating_mul(x.into())) + } + /// Storage: DappStaking HistoryCleanupMarker (r:1 w:1) + /// Proof: DappStaking HistoryCleanupMarker (max_values: Some(1), max_size: Some(12), added: 507, mode: MaxEncodedLen) + /// Storage: DappStaking EraRewards (r:1 w:1) + /// Proof: DappStaking EraRewards (max_values: None, max_size: Some(789), added: 3264, mode: MaxEncodedLen) + /// Storage: DappStaking DAppTiers (r:0 w:1) + /// Proof: DappStaking DAppTiers (max_values: None, max_size: Some(1583), added: 4058, mode: MaxEncodedLen) + fn on_idle_cleanup() -> Weight { + // Proof Size summary in bytes: + // Measured: `293` + // Estimated: `4254` + // Minimum execution time: 8_101_000 picoseconds. + Weight::from_parts(8_272_000, 4254) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } +} diff --git a/runtime/astar/src/weights/pallet_inflation.rs b/runtime/astar/src/weights/pallet_inflation.rs new file mode 100644 index 000000000..98814451a --- /dev/null +++ b/runtime/astar/src/weights/pallet_inflation.rs @@ -0,0 +1,95 @@ + +// This file is part of Astar. + +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Astar is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Astar. If not, see . + +//! Autogenerated weights for pallet_inflation +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! 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("astar-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/release/astar-collator +// benchmark +// pallet +// --chain=astar-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_inflation +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=./benchmark-results/astar-dev/inflation_weights.rs +// --template=./scripts/templates/weight-template.hbs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use core::marker::PhantomData; +use pallet_inflation::WeightInfo; + +/// Weights for pallet_inflation using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + /// Storage: Inflation InflationParams (r:0 w:1) + /// Proof: Inflation InflationParams (max_values: Some(1), max_size: Some(64), added: 559, mode: MaxEncodedLen) + fn force_set_inflation_params() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 8_868_000 picoseconds. + Weight::from_parts(9_183_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: Inflation InflationParams (r:1 w:0) + /// Proof: Inflation InflationParams (max_values: Some(1), max_size: Some(64), added: 559, mode: MaxEncodedLen) + fn force_inflation_recalculation() -> Weight { + // Proof Size summary in bytes: + // Measured: `40` + // Estimated: `1549` + // Minimum execution time: 13_226_000 picoseconds. + Weight::from_parts(13_460_000, 1549) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } + /// Storage: Inflation InflationParams (r:1 w:0) + /// Proof: Inflation InflationParams (max_values: Some(1), max_size: Some(64), added: 559, mode: MaxEncodedLen) + fn recalculation() -> Weight { + // Proof Size summary in bytes: + // Measured: `58` + // Estimated: `1549` + // Minimum execution time: 13_150_000 picoseconds. + Weight::from_parts(13_395_000, 1549) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } + /// Storage: System Account (r:2 w:2) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + fn hooks_without_recalculation() -> Weight { + // Proof Size summary in bytes: + // Measured: `39` + // Estimated: `6196` + // Minimum execution time: 39_539_000 picoseconds. + Weight::from_parts(40_043_000, 6196) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } +} \ No newline at end of file diff --git a/runtime/astar/src/xcm_config.rs b/runtime/astar/src/xcm_config.rs index 8cc1ba9c0..53d872360 100644 --- a/runtime/astar/src/xcm_config.rs +++ b/runtime/astar/src/xcm_config.rs @@ -162,7 +162,7 @@ impl SafeCallFilter { | RuntimeCall::Identity(..) | RuntimeCall::Balances(..) | RuntimeCall::Vesting(..) - | RuntimeCall::DappsStaking(..) + | RuntimeCall::DappStaking(..) | RuntimeCall::Assets(..) | RuntimeCall::PolkadotXcm(..) | RuntimeCall::Session(..) diff --git a/runtime/shibuya/src/weights/pallet_inflation.rs b/runtime/shibuya/src/weights/pallet_inflation.rs index 1fdb896f5..2fb650930 100644 --- a/runtime/shibuya/src/weights/pallet_inflation.rs +++ b/runtime/shibuya/src/weights/pallet_inflation.rs @@ -61,13 +61,6 @@ impl WeightInfo for SubstrateWeight { Weight::from_parts(9_652_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } - fn force_set_inflation_config() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 9_168_000 picoseconds. - Weight::from_parts(9_436_000, 0) - } /// Storage: Inflation InflationParams (r:1 w:0) /// Proof: Inflation InflationParams (max_values: Some(1), max_size: Some(64), added: 559, mode: MaxEncodedLen) fn force_inflation_recalculation() -> Weight { diff --git a/runtime/shiden/Cargo.toml b/runtime/shiden/Cargo.toml index 9a2a4d850..426da8748 100644 --- a/runtime/shiden/Cargo.toml +++ b/runtime/shiden/Cargo.toml @@ -21,7 +21,6 @@ fp-rpc = { workspace = true } fp-self-contained = { workspace = true } sp-api = { workspace = true } -sp-arithmetic = { workspace = true } sp-block-builder = { workspace = true } sp-consensus-aura = { workspace = true } sp-core = { workspace = true } @@ -105,7 +104,6 @@ astar-primitives = { workspace = true } pallet-collator-selection = { workspace = true } pallet-dapp-staking-migration = { workspace = true } pallet-dapp-staking-v3 = { workspace = true } -pallet-dapps-staking = { workspace = true } pallet-evm-precompile-assets-erc20 = { workspace = true } pallet-evm-precompile-dapp-staking-v3 = { workspace = true } pallet-evm-precompile-sr25519 = { workspace = true } @@ -138,7 +136,6 @@ std = [ "sp-api/std", "sp-core/std", "sp-consensus-aura/std", - "sp-arithmetic/std", "sp-io/std", "sp-runtime/std", "pallet-static-price-provider/std", @@ -168,7 +165,6 @@ std = [ "pallet-evm-precompile-ed25519/std", "pallet-evm-precompile-modexp/std", "pallet-evm-precompile-sha3fips/std", - "pallet-dapps-staking/std", "pallet-dapp-staking-v3/std", "pallet-dapp-staking-migration/std", "dapp-staking-v3-runtime-api/std", @@ -226,7 +222,6 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "pallet-balances/runtime-benchmarks", - "pallet-dapps-staking/runtime-benchmarks", "pallet-dapp-staking-v3/runtime-benchmarks", "pallet-dapp-staking-migration/runtime-benchmarks", "pallet-inflation/runtime-benchmarks", @@ -253,7 +248,6 @@ try-runtime = [ "pallet-dapp-staking-v3/try-runtime", "pallet-dapp-staking-migration/try-runtime", "pallet-inflation/try-runtime", - "pallet-dapps-staking/try-runtime", "pallet-sudo/try-runtime", "pallet-timestamp/try-runtime", "pallet-transaction-payment/try-runtime", diff --git a/runtime/shiden/src/lib.rs b/runtime/shiden/src/lib.rs index ed4f714f2..1f6e99512 100644 --- a/runtime/shiden/src/lib.rs +++ b/runtime/shiden/src/lib.rs @@ -28,7 +28,7 @@ use frame_support::{ dispatch::DispatchClass, parameter_types, traits::{ - AsEnsureOriginWithArg, ConstU128, ConstU32, Contains, Currency, FindAuthor, Get, Imbalance, + AsEnsureOriginWithArg, ConstU32, Contains, Currency, FindAuthor, Get, Imbalance, InstanceFilter, Nothing, OnFinalize, OnUnbalanced, WithdrawReasons, }, weights::{ @@ -323,41 +323,6 @@ impl pallet_multisig::Config for Runtime { type WeightInfo = pallet_multisig::weights::SubstrateWeight; } -parameter_types! { - pub const BlockPerEra: BlockNumber = DAYS; - pub const RegisterDeposit: Balance = 100 * SDN; - pub const MaxNumberOfStakersPerContract: u32 = 1024; - pub const MinimumStakingAmount: Balance = 50 * SDN; - pub const MinimumRemainingAmount: Balance = SDN; - pub const MaxUnlockingChunks: u32 = 5; - pub const UnbondingPeriod: u32 = 5; - pub const MaxEraStakeValues: u32 = 5; -} - -impl pallet_dapps_staking::Config for Runtime { - type Currency = Balances; - type BlockPerEra = BlockPerEra; - type SmartContract = SmartContract; - type RegisterDeposit = RegisterDeposit; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = pallet_dapps_staking::weights::SubstrateWeight; - type MaxNumberOfStakersPerContract = MaxNumberOfStakersPerContract; - type MinimumStakingAmount = MinimumStakingAmount; - type PalletId = DappsStakingPalletId; - type MinimumRemainingAmount = MinimumRemainingAmount; - type MaxUnlockingChunks = MaxUnlockingChunks; - type UnbondingPeriod = UnbondingPeriod; - type MaxEraStakeValues = MaxEraStakeValues; - type UnregisteredDappRewardRetention = ConstU32<7>; - // Needed so benchmark can use the pallets extrinsics - #[cfg(feature = "runtime-benchmarks")] - type ForcePalletDisabled = ConstBool; - #[cfg(not(feature = "runtime-benchmarks"))] - type ForcePalletDisabled = ConstBool; - // Fee required to claim rewards for another account. Calculated & tested manually. - type DelegateClaimFee = ConstU128<000_579_268_481_141_871>; -} - impl pallet_static_price_provider::Config for Runtime { type RuntimeEvent = RuntimeEvent; } @@ -390,6 +355,10 @@ impl DappStakingAccountCheck for AccountCheck { } } +parameter_types! { + pub const MinimumStakingAmount: Balance = 50 * SDN; +} + impl pallet_dapp_staking_v3::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeFreezeReason = RuntimeFreezeReason; @@ -453,11 +422,6 @@ impl pallet_inflation::Config for Runtime { type WeightInfo = weights::pallet_inflation::SubstrateWeight; } -impl pallet_dapp_staking_migration::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type WeightInfo = pallet_dapp_staking_migration::weights::SubstrateWeight; -} - impl pallet_utility::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; @@ -554,7 +518,6 @@ impl pallet_collator_selection::Config for Runtime { parameter_types! { pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry"); - pub const DappsStakingPalletId: PalletId = PalletId(*b"py/dpsst"); pub TreasuryAccountId: AccountId = TreasuryPalletId::get().into_account_truncating(); } @@ -1094,10 +1057,6 @@ construct_runtime!( // To be removed & cleaned up once proper oracle is implemented StaticPriceProvider: pallet_static_price_provider = 253, - // To be removed & cleaned up after migration has been finished - DappStakingMigration: pallet_dapp_staking_migration = 254, - // Legacy dApps staking v2, to be removed after migration has been finished - DappsStaking: pallet_dapps_staking = 255, } ); @@ -1136,133 +1095,35 @@ pub type Executive = frame_executive::Executive< >; parameter_types! { - pub const BlockRewardName: &'static str = "BlockReward"; + pub const DappStakingMigrationName: &'static str = "DappStakingMigration"; } /// All migrations that will run on the next runtime upgrade. /// /// Once done, migrations should be removed from the tuple. pub type Migrations = ( - pallet_static_price_provider::InitActivePrice, - pallet_inflation::PalletInflationInitConfig, - pallet_dapp_staking_v3::migrations::DAppStakingV3InitConfig< - Runtime, - InitDappStakingV3Params, - InitActivePriceGet, - >, - // This will handle new pallet storage version setting & it will put the new pallet into maintenance mode. - // But it's most important for testing with try-runtime. - pallet_dapp_staking_migration::DappStakingMigrationHandler, + // Part of shiden-119 frame_support::migrations::RemovePallet< - BlockRewardName, + DappStakingMigrationName, ::DbWeight, >, + // Part of shiden-119 + RecalculationEraFix, ); -use sp_arithmetic::fixed_point::FixedU64; -pub struct InitActivePriceGet; -impl Get for InitActivePriceGet { - fn get() -> FixedU64 { - // Roughly the average price, taken from CoinMarketCap data. - FixedU64::from_rational(32, 100) - } -} +use frame_support::traits::OnRuntimeUpgrade; +pub struct RecalculationEraFix; +impl OnRuntimeUpgrade for RecalculationEraFix { + fn on_runtime_upgrade() -> Weight { + let first_dapp_staking_v3_era = 743; -/// Used to initialize inflation parameters for the runtime. -pub struct InitInflationParamsHelper; -impl Get<(pallet_inflation::InflationParameters, EraNumber, Weight)> for InitInflationParamsHelper { - fn get() -> (pallet_inflation::InflationParameters, EraNumber, Weight) { - ( - pallet_inflation::InflationParameters { - // Recalculation is done every two weeks, hence the small %. - max_inflation_rate: Perquintill::from_percent(7), - treasury_part: Perquintill::from_percent(5), - collators_part: Perquintill::from_rational(32_u64, 1000), - dapps_part: Perquintill::from_percent(13), - base_stakers_part: Perquintill::from_percent(10), - adjustable_stakers_part: Perquintill::from_rational(588_u64, 1000), - bonus_part: Perquintill::from_percent(10), - ideal_staking_rate: Perquintill::from_percent(50), - }, - pallet_dapps_staking::CurrentEra::::get().saturating_add(1), - ::DbWeight::get().reads(1), - ) - } -} - -use frame_support::BoundedVec; -use pallet_dapp_staking_v3::{TierParameters, TiersConfiguration}; -type NumberOfTiers = ::NumberOfTiers; -/// Used to initialize dApp staking parameters for the runtime. -pub struct InitDappStakingV3Params; -impl - Get<( - EraNumber, - TierParameters, - TiersConfiguration, - )> for InitDappStakingV3Params -{ - fn get() -> ( - EraNumber, - TierParameters, - TiersConfiguration, - ) { - // 1. Prepare init values - - // Init era of dApp staking v3 should be the next era after dApp staking v2 - let init_era = pallet_dapps_staking::CurrentEra::::get().saturating_add(1); - - // Reward portions according to the Tokenomics 2.0 report - let reward_portion = BoundedVec::try_from(vec![ - Permill::from_percent(25), - Permill::from_percent(47), - Permill::from_percent(25), - Permill::from_percent(3), - ]) - .unwrap_or_default(); - - // Tier thresholds adjusted according to numbers observed on Shibuya - let tier_thresholds = BoundedVec::try_from(vec![ - TierThreshold::DynamicTvlAmount { - amount: SDN.saturating_mul(3_000_000), - minimum_amount: SDN.saturating_mul(2_000_000), - }, - TierThreshold::DynamicTvlAmount { - amount: SDN.saturating_mul(750_000), - minimum_amount: SDN.saturating_mul(500_000), - }, - TierThreshold::DynamicTvlAmount { - amount: SDN.saturating_mul(200_000), - minimum_amount: SDN.saturating_mul(150_000), - }, - TierThreshold::FixedTvlAmount { - amount: SDN.saturating_mul(50_000), - }, - ]) - .unwrap_or_default(); - - // 2. Tier params - let tier_params = - TierParameters::<::NumberOfTiers> { - reward_portion: reward_portion.clone(), - slot_distribution: BoundedVec::try_from(vec![ - Permill::from_percent(5), - Permill::from_percent(20), - Permill::from_percent(30), - Permill::from_percent(45), - ]) - .unwrap_or_default(), - tier_thresholds: tier_thresholds.clone(), - }; + let expected_recalculation_era = + InflationCycleConfig::eras_per_cycle().saturating_add(first_dapp_staking_v3_era); - // 3. Init tier config - let init_tier_config = TiersConfiguration { - number_of_slots: 100, - slots_per_tier: BoundedVec::try_from(vec![5, 20, 30, 45]).unwrap_or_default(), - reward_portion, - tier_thresholds, - }; + pallet_inflation::ActiveInflationConfig::::mutate(|config| { + config.recalculation_era = expected_recalculation_era; + }); - (init_era, tier_params, init_tier_config) + ::DbWeight::get().reads_writes(1, 1) } } @@ -1341,10 +1202,8 @@ mod benches { [pallet_assets, Assets] [pallet_balances, Balances] [pallet_timestamp, Timestamp] - [pallet_dapps_staking, DappsStaking] [pallet_dapp_staking_v3, DappStaking] [pallet_inflation, Inflation] - [pallet_dapp_staking_migration, DappStakingMigration] [pallet_xc_asset_config, XcAssetConfig] [pallet_collator_selection, CollatorSelection] [pallet_xcm, PolkadotXcm] diff --git a/runtime/shiden/src/weights/pallet_inflation.rs b/runtime/shiden/src/weights/pallet_inflation.rs index beaa686a8..b68ce70ee 100644 --- a/runtime/shiden/src/weights/pallet_inflation.rs +++ b/runtime/shiden/src/weights/pallet_inflation.rs @@ -61,13 +61,6 @@ impl WeightInfo for SubstrateWeight { Weight::from_parts(9_303_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } - fn force_set_inflation_config() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 9_559_000 picoseconds. - Weight::from_parts(9_789_000, 0) - } /// Storage: Inflation InflationParams (r:1 w:0) /// Proof: Inflation InflationParams (max_values: Some(1), max_size: Some(64), added: 559, mode: MaxEncodedLen) fn force_inflation_recalculation() -> Weight { diff --git a/runtime/shiden/src/xcm_config.rs b/runtime/shiden/src/xcm_config.rs index b1c512c41..a28758ec6 100644 --- a/runtime/shiden/src/xcm_config.rs +++ b/runtime/shiden/src/xcm_config.rs @@ -164,7 +164,7 @@ impl SafeCallFilter { | RuntimeCall::Identity(..) | RuntimeCall::Balances(..) | RuntimeCall::Vesting(..) - | RuntimeCall::DappsStaking(..) + | RuntimeCall::DappStaking(..) | RuntimeCall::Assets(..) | RuntimeCall::PolkadotXcm(..) | RuntimeCall::Session(..) diff --git a/tests/integration/src/dapp_staking_v3.rs b/tests/integration/src/dapp_staking_v3.rs index 5fa769ea1..167e4d4aa 100644 --- a/tests/integration/src/dapp_staking_v3.rs +++ b/tests/integration/src/dapp_staking_v3.rs @@ -27,7 +27,6 @@ use pallet_dapp_staking_v3::*; fn dapp_staking_triggers_inflation_recalculation() { new_test_ext().execute_with(|| { let init_inflation_config = pallet_inflation::ActiveInflationConfig::::get(); - let recalculation_era = init_inflation_config.recalculation_era; // It's not feasible to run through all the blocks needed to trigger all the eras. diff --git a/tests/integration/src/dispatch_precompile_filter_new.rs b/tests/integration/src/dispatch_precompile_filter.rs similarity index 100% rename from tests/integration/src/dispatch_precompile_filter_new.rs rename to tests/integration/src/dispatch_precompile_filter.rs diff --git a/tests/integration/src/dispatch_precompile_filter_old.rs b/tests/integration/src/dispatch_precompile_filter_old.rs deleted file mode 100644 index 95d04bcfb..000000000 --- a/tests/integration/src/dispatch_precompile_filter_old.rs +++ /dev/null @@ -1,221 +0,0 @@ -// This file is part of Astar. - -// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. -// SPDX-License-Identifier: GPL-3.0-or-later - -// Astar is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Astar is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Astar. If not, see . -#![cfg(test)] - -use crate::setup::*; -use astar_primitives::precompiles::DispatchFilterValidate; -use fp_evm::{ExitError, PrecompileFailure}; -use frame_support::{ - dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo, Pays}, - traits::Contains, -}; -use pallet_evm_precompile_dispatch::DispatchValidateT; -use parity_scale_codec::Compact; - -/// Whitelisted Calls are defined in the runtime -#[test] -fn filter_accepts_batch_call_with_whitelisted_calls() { - ExtBuilder::default().build().execute_with(|| { - let contract = SmartContract::Evm(H160::repeat_byte(0x01)); - let inner_call = RuntimeCall::DappsStaking(DappsStakingCall::Call::claim_staker { - contract_id: contract.clone(), - }); - let call = RuntimeCall::Utility(UtilityCall::batch { - calls: vec![inner_call], - }); - assert!(WhitelistedCalls::contains(&call)); - }); -} - -#[test] -fn filter_rejects_non_whitelisted_batch_calls() { - ExtBuilder::default().build().execute_with(|| { - // CASE1 - only non whitelisted calls - let transfer_call = RuntimeCall::Balances(BalancesCall::transfer { - dest: MultiAddress::Id(CAT), - value: 100_000_000_000, - }); - let transfer = Box::new(transfer_call); - let call = Box::new(RuntimeCall::Utility(UtilityCall::batch { - calls: vec![*transfer.clone()], - })); - - // Utility call containing Balances Call - assert!(!WhitelistedCalls::contains(&call)); - - // CASE 2 - now whitelisted mixed with whitelisted calls - - let contract = SmartContract::Evm(H160::repeat_byte(0x01)); - let staking_call = RuntimeCall::DappsStaking(DappsStakingCall::Call::claim_staker { - contract_id: contract.clone(), - }); - let staking = Box::new(staking_call); - - let call = Box::new(RuntimeCall::Utility(UtilityCall::batch { - calls: vec![*transfer, *staking.clone()], - })); - - // Utility call containing Balances Call and Dappsstaking Call Fails filter - assert!(!WhitelistedCalls::contains(&call)); - }); -} - -#[test] -fn filter_accepts_whitelisted_calls() { - ExtBuilder::default().build().execute_with(|| { - // Dappstaking call works - let contract = SmartContract::Evm(H160::repeat_byte(0x01)); - let stake_call = RuntimeCall::DappsStaking(DappsStakingCall::Call::claim_staker { - contract_id: contract.clone(), - }); - assert!(WhitelistedCalls::contains(&stake_call)); - - // Pallet::Assets transfer call works - let transfer_call = RuntimeCall::Assets(pallet_assets::Call::transfer { - id: Compact(0), - target: MultiAddress::Address20(H160::repeat_byte(0x01).into()), - amount: 100, - }); - assert!(WhitelistedCalls::contains(&transfer_call)); - }); -} - -#[test] -fn filter_rejects_non_whitelisted_calls() { - ExtBuilder::default().build().execute_with(|| { - // Random call from non whitelisted pallet doesn't work - let transfer_call = RuntimeCall::Balances(BalancesCall::transfer { - dest: MultiAddress::Id(CAT), - value: 100_000_000_000, - }); - assert!(!WhitelistedCalls::contains(&transfer_call)); - - // Only `transfer` call from pallet assets work - // Other random call from Pallet Assets doesn't work - let thaw_asset_call = - RuntimeCall::Assets(pallet_assets::Call::thaw_asset { id: Compact(0) }); - assert!(!WhitelistedCalls::contains(&thaw_asset_call)); - }) -} - -#[test] -fn filter_accepts_whitelisted_batch_all_calls() { - ExtBuilder::default().build().execute_with(|| { - let contract = SmartContract::Evm(H160::repeat_byte(0x01)); - let inner_call1 = RuntimeCall::DappsStaking(DappsStakingCall::Call::claim_staker { - contract_id: contract.clone(), - }); - let inner_call2 = RuntimeCall::DappsStaking(DappsStakingCall::Call::claim_staker { - contract_id: contract.clone(), - }); - let transfer_call = RuntimeCall::Assets(pallet_assets::Call::transfer { - id: Compact(0), - target: MultiAddress::Address20(H160::repeat_byte(0x01).into()), - amount: 100, - }); - let call = RuntimeCall::Utility(UtilityCall::batch_all { - calls: vec![inner_call1, inner_call2, transfer_call], - }); - assert!(WhitelistedCalls::contains(&call)); - }); -} - -#[test] -fn test_correct_dispatch_info_works() { - ExtBuilder::default().build().execute_with(|| { - // Mock implementation - struct Filter; - struct AccountId; - enum RuntimeCall { - System, - DappsStaking, - } - impl GetDispatchInfo for RuntimeCall { - fn get_dispatch_info(&self) -> DispatchInfo { - // Default is Pays::Yes and DispatchCall::Normal - DispatchInfo::default() - } - } - impl Contains for Filter { - fn contains(t: &RuntimeCall) -> bool { - match t { - RuntimeCall::DappsStaking => true, - _ => false, - } - } - } - // Case 1: Whitelisted Call with correct Dispatch info - assert_eq!( - DispatchFilterValidate::::validate_before_dispatch( - &AccountId, - &RuntimeCall::DappsStaking - ), - Option::None - ); - // Case 2: Non-Whitelisted Call with correct Dispatch Info - assert_eq!( - DispatchFilterValidate::::validate_before_dispatch( - &AccountId, - &RuntimeCall::System - ), - Option::Some(PrecompileFailure::Error { - exit_status: ExitError::Other("call filtered out".into()), - }) - ); - }); -} - -#[test] -fn test_incorrect_dispatch_info_fails() { - ExtBuilder::default().build().execute_with(|| { - // Mock implementation - struct Filter; - struct AccountId; - enum RuntimeCall { - DappsStaking, - } - impl GetDispatchInfo for RuntimeCall { - fn get_dispatch_info(&self) -> DispatchInfo { - DispatchInfo { - weight: Weight::default(), - class: DispatchClass::Normal, - // Should have been Pays::Yes for call to pass - pays_fee: Pays::No, - } - } - } - impl Contains for Filter { - fn contains(t: &RuntimeCall) -> bool { - match t { - RuntimeCall::DappsStaking => true, - } - } - } - - // WhiteListed Call fails because of incorrect DispatchInfo - assert_eq!( - DispatchFilterValidate::::validate_before_dispatch( - &AccountId, - &RuntimeCall::DappsStaking - ), - Option::Some(PrecompileFailure::Error { - exit_status: ExitError::Other("invalid call".into()), - }) - ); - }) -} diff --git a/tests/integration/src/lib.rs b/tests/integration/src/lib.rs index 7f12e9903..8693ee2c6 100644 --- a/tests/integration/src/lib.rs +++ b/tests/integration/src/lib.rs @@ -23,12 +23,8 @@ #[cfg(any(feature = "shibuya", feature = "shiden", feature = "astar"))] mod setup; -#[cfg(any(feature = "shibuya", feature = "shiden"))] -mod proxy_new; - -// Remove this once dApp staking v3 is integrated into Shiden & Astar -#[cfg(any(feature = "astar"))] -mod proxy_old; +#[cfg(any(feature = "shibuya", feature = "shiden", feature = "astar"))] +mod proxy; #[cfg(any(feature = "shibuya", feature = "shiden", feature = "astar"))] mod assets; @@ -36,17 +32,13 @@ mod assets; #[cfg(feature = "shibuya")] mod xvm; -#[cfg(any(feature = "shibuya", feature = "shiden"))] -mod dispatch_precompile_filter_new; - -// Remove this once dApp staking v3 is integrated into Shiden & Astar -#[cfg(any(feature = "astar"))] -mod dispatch_precompile_filter_old; +#[cfg(any(feature = "shibuya", feature = "shiden", feature = "astar"))] +mod dispatch_precompile_filter; #[cfg(feature = "shibuya")] mod unified_accounts; -#[cfg(any(feature = "shibuya", feature = "shiden"))] +#[cfg(any(feature = "shibuya", feature = "shiden", feature = "astar"))] mod dapp_staking_v3; #[cfg(any(feature = "shibuya"))] diff --git a/tests/integration/src/proxy_new.rs b/tests/integration/src/proxy.rs similarity index 100% rename from tests/integration/src/proxy_new.rs rename to tests/integration/src/proxy.rs diff --git a/tests/integration/src/proxy_old.rs b/tests/integration/src/proxy_old.rs deleted file mode 100644 index d6d9479a8..000000000 --- a/tests/integration/src/proxy_old.rs +++ /dev/null @@ -1,213 +0,0 @@ -// This file is part of Astar. - -// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. -// SPDX-License-Identifier: GPL-3.0-or-later - -// Astar is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Astar is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Astar. If not, see . - -use crate::setup::*; - -#[test] -fn test_utility_call_pass_for_any() { - new_test_ext().execute_with(|| { - // Any proxy should be allowed to make balance transfer call - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(ALICE), - MultiAddress::Id(BOB), - ProxyType::Any, - 0 - )); - - // Preparing Utility call - let transfer_call = RuntimeCall::Balances(BalancesCall::transfer { - dest: MultiAddress::Id(CAT), - value: 100_000_000_000, - }); - let inner = Box::new(transfer_call); - let call = Box::new(RuntimeCall::Utility(UtilityCall::batch { - calls: vec![*inner], - })); - - // Utility call passed through filter - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(BOB), - MultiAddress::Id(ALICE), - None, - call.clone() - )); - expect_events(vec![ - UtilityEvent::BatchCompleted.into(), - ProxyEvent::ProxyExecuted { result: Ok(()) }.into(), - ]); - }); -} - -#[test] -fn test_utility_call_pass_for_balances() { - new_test_ext().execute_with(|| { - // Balances proxy should be allowed to make balance transfer call - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(ALICE), - MultiAddress::Id(BOB), - ProxyType::Balances, - 0 - )); - - // Preparing Utility call - let transfer_call = RuntimeCall::Balances(BalancesCall::transfer { - dest: MultiAddress::Id(CAT), - value: 100_000_000_000, - }); - let inner = Box::new(transfer_call); - let call = Box::new(RuntimeCall::Utility(UtilityCall::batch { - calls: vec![*inner], - })); - - // Utility call passed through filter - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(BOB), - MultiAddress::Id(ALICE), - None, - call.clone() - )); - expect_events(vec![ - UtilityEvent::BatchCompleted.into(), - ProxyEvent::ProxyExecuted { result: Ok(()) }.into(), - ]); - }); -} - -#[test] -fn test_utility_call_fail_non_transfer() { - new_test_ext().execute_with(|| { - // NonTransfer proxy shouldn't be allowed to make balance transfer call - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(ALICE), - MultiAddress::Id(BOB), - ProxyType::NonTransfer, - 0 - )); - - // Preparing Utility call - let transfer_call = RuntimeCall::Balances(BalancesCall::transfer { - dest: MultiAddress::Id(CAT), - value: 100_000_000_000, - }); - let inner = Box::new(transfer_call); - let call = Box::new(RuntimeCall::Utility(UtilityCall::batch { - calls: vec![*inner], - })); - - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(BOB), - MultiAddress::Id(ALICE), - None, - call.clone() - )); - - // Utility call filtered out - expect_events(vec![ - UtilityEvent::BatchInterrupted { - index: 0, - error: SystemError::CallFiltered.into(), - } - .into(), - ProxyEvent::ProxyExecuted { result: Ok(()) }.into(), - ]); - }); -} - -#[test] -fn test_utility_call_fail_for_dappstaking() { - new_test_ext().execute_with(|| { - // Dappstaking proxy shouldn't be allowed to make balance transfer call - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(ALICE), - MultiAddress::Id(BOB), - ProxyType::DappsStaking, - 0 - )); - - // Preparing Utility call - let transfer_call = RuntimeCall::Balances(BalancesCall::transfer { - dest: MultiAddress::Id(CAT), - value: 100_000_000_000, - }); - let inner = Box::new(transfer_call); - let call = Box::new(RuntimeCall::Utility(UtilityCall::batch { - calls: vec![*inner], - })); - - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(BOB), - MultiAddress::Id(ALICE), - None, - call.clone() - )); - // Utility call filtered out - expect_events(vec![ - UtilityEvent::BatchInterrupted { - index: 0, - error: SystemError::CallFiltered.into(), - } - .into(), - ProxyEvent::ProxyExecuted { result: Ok(()) }.into(), - ]); - }); -} - -#[test] -fn test_staker_reward_claim_proxy_works() { - new_test_ext().execute_with(|| { - // Make CAT delegate for StakerRewardClaim proxy - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(BOB), - MultiAddress::Id(CAT), - ProxyType::StakerRewardClaim, - 0 - )); - - let contract = SmartContract::Evm(H160::repeat_byte(0x01)); - let staker_reward_claim_call = - RuntimeCall::DappsStaking(DappsStakingCall::Call::claim_staker { - contract_id: contract.clone(), - }); - let call = Box::new(staker_reward_claim_call); - - // contract must be registered - assert_ok!(DappsStaking::register( - RuntimeOrigin::root(), - ALICE.clone(), - contract.clone() - )); - - // some amount must be staked - assert_ok!(DappsStaking::bond_and_stake( - RuntimeOrigin::signed(BOB), - contract.clone(), - 600 * UNIT - )); - run_to_block(10); - - // CAT making proxy call on behalf of staker (BOB) - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(CAT), - MultiAddress::Id(BOB), - None, - call.clone() - )); - - expect_events(vec![ProxyEvent::ProxyExecuted { result: Ok(()) }.into()]); - }) -} diff --git a/tests/integration/src/setup.rs b/tests/integration/src/setup.rs index 2bca834b2..1454d40c0 100644 --- a/tests/integration/src/setup.rs +++ b/tests/integration/src/setup.rs @@ -28,7 +28,9 @@ pub use sp_core::{H160, H256, U256}; pub use sp_io::hashing::keccak_256; pub use sp_runtime::{AccountId32, MultiAddress}; -pub use astar_primitives::{evm::UnifiedAddressMapper, BlockNumber}; +pub use astar_primitives::{ + dapp_staking::CycleConfiguration, evm::UnifiedAddressMapper, BlockNumber, +}; #[cfg(feature = "shibuya")] pub use shibuya::*; @@ -191,7 +193,6 @@ impl ExtBuilder { .assimilate_storage(&mut t) .unwrap(); - #[cfg(any(feature = "shibuya", feature = "shiden"))] // Needed to trigger initial inflation config setting. >::assimilate_storage( &pallet_inflation::GenesisConfig::default(), @@ -200,7 +201,25 @@ impl ExtBuilder { .unwrap(); let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); + ext.execute_with(|| { + System::set_block_number(1); + + let era_length = ::CycleConfiguration::blocks_per_era(); + let voting_period_length_in_eras = + ::CycleConfiguration::eras_per_voting_subperiod(); + + pallet_dapp_staking_v3::ActiveProtocolState::::put(pallet_dapp_staking_v3::ProtocolState { + era: 1, + next_era_start: era_length.saturating_mul(voting_period_length_in_eras.into()) + 1, + period_info: pallet_dapp_staking_v3::PeriodInfo { + number: 1, + subperiod: pallet_dapp_staking_v3::Subperiod::Voting, + next_subperiod_start_era: 2, + }, + maintenance: false, + }); + pallet_dapp_staking_v3::Safeguard::::put(false); + }); ext } } @@ -222,10 +241,7 @@ pub fn run_to_block(n: BlockNumber) { while System::block_number() < n { let block_number = System::block_number(); TransactionPayment::on_finalize(block_number); - #[cfg(any(feature = "shibuya", feature = "shiden"))] DappStaking::on_finalize(block_number); - #[cfg(any(feature = "astar"))] - DappsStaking::on_finalize(block_number); Authorship::on_finalize(block_number); Session::on_finalize(block_number); AuraExt::on_finalize(block_number); @@ -233,20 +249,15 @@ pub fn run_to_block(n: BlockNumber) { Ethereum::on_finalize(block_number); CollatorSelection::on_finalize(block_number); DynamicEvmBaseFee::on_finalize(block_number); - #[cfg(any(feature = "shibuya", feature = "shiden"))] Inflation::on_finalize(block_number); System::set_block_number(block_number + 1); let block_number = System::block_number(); - #[cfg(any(feature = "shibuya", feature = "shiden"))] Inflation::on_initialize(block_number); Timestamp::set_timestamp(block_number as u64 * BLOCK_TIME); TransactionPayment::on_initialize(block_number); - #[cfg(any(feature = "shibuya", feature = "shiden"))] DappStaking::on_initialize(block_number); - #[cfg(any(feature = "astar"))] - DappsStaking::on_initialize(block_number); Authorship::on_initialize(block_number); Aura::on_initialize(block_number); AuraExt::on_initialize(block_number);