From 702a34e0f851225d61cfd68eb04c7a1b1dd02654 Mon Sep 17 00:00:00 2001 From: PierreOssun Date: Mon, 4 Dec 2023 16:57:07 +0100 Subject: [PATCH 1/2] Added hybrid inflation to Shiden + Migration --- Cargo.lock | 2 +- .../src/parachain/chain_spec/shiden.rs | 6 +-- runtime/shibuya/src/lib.rs | 36 +------------ runtime/shiden/Cargo.toml | 8 +-- runtime/shiden/src/lib.rs | 50 ++++++++++++++++--- 5 files changed, 51 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 85ad40c65a..279f9f146e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13243,7 +13243,7 @@ dependencies = [ "pallet-aura", "pallet-authorship", "pallet-balances", - "pallet-block-reward", + "pallet-block-rewards-hybrid", "pallet-collator-selection", "pallet-collective", "pallet-contracts", diff --git a/bin/collator/src/parachain/chain_spec/shiden.rs b/bin/collator/src/parachain/chain_spec/shiden.rs index bc7ee05487..bc9a888db7 100644 --- a/bin/collator/src/parachain/chain_spec/shiden.rs +++ b/bin/collator/src/parachain/chain_spec/shiden.rs @@ -22,7 +22,7 @@ use cumulus_primitives_core::ParaId; use sc_service::ChainType; use shiden_runtime::{ wasm_binary_unwrap, AccountId, AuraId, Balance, BlockRewardConfig, EVMConfig, - ParachainInfoConfig, Precompiles, Signature, SystemConfig, SDN, + ParachainInfoConfig, Precompiles, RewardDistributionConfig, Signature, SystemConfig, SDN, }; use sp_core::{sr25519, Pair, Public}; @@ -113,8 +113,8 @@ fn make_genesis( balances: shiden_runtime::BalancesConfig { balances }, block_reward: BlockRewardConfig { // Make sure sum is 100 - reward_config: pallet_block_reward::RewardDistributionConfig { - base_treasury_percent: Perbill::from_percent(40), + reward_config: RewardDistributionConfig { + treasury_percent: Perbill::from_percent(40), base_staker_percent: Perbill::from_percent(25), dapps_percent: Perbill::from_percent(25), collators_percent: Perbill::from_percent(10), diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs index b0532f7cc7..33e00640c7 100644 --- a/runtime/shibuya/src/lib.rs +++ b/runtime/shibuya/src/lib.rs @@ -1324,44 +1324,10 @@ pub type Executive = frame_executive::Executive< Migrations, >; -pub use frame_support::traits::{OnRuntimeUpgrade, StorageVersion}; -pub struct HybridInflationModelMigration; -impl OnRuntimeUpgrade for HybridInflationModelMigration { - fn on_runtime_upgrade() -> Weight { - let mut reward_config = pallet_block_rewards_hybrid::RewardDistributionConfig { - // 4.66% - treasury_percent: Perbill::from_rational(4_663_701u32, 100_000_000u32), - // 23.09% - base_staker_percent: Perbill::from_rational(2_309_024u32, 10_000_000u32), - // 17.31% - dapps_percent: Perbill::from_rational(173_094_531u32, 1_000_000_000u32), - // 2.99% - collators_percent: Perbill::from_rational(29_863_296u32, 1_000_000_000u32), - // 51.95% - adjustable_percent: Perbill::from_rational(519_502_763u32, 1_000_000_000u32), - // 60.00% - ideal_dapps_staking_tvl: Perbill::from_percent(60), - }; - - // This HAS to be tested prior to update - we need to ensure that config is consistent - #[cfg(feature = "try-runtime")] - assert!(reward_config.is_consistent()); - - // This should never execute but we need to have code in place that ensures config is consistent - if !reward_config.is_consistent() { - reward_config = Default::default(); - } - - pallet_block_rewards_hybrid::RewardDistributionConfigStorage::::put(reward_config); - - ::DbWeight::get().writes(1) - } -} - /// All migrations that will run on the next runtime upgrade. /// /// Once done, migrations should be removed from the tuple. -pub type Migrations = HybridInflationModelMigration; +pub type Migrations = (); type EventRecord = frame_system::EventRecord< ::RuntimeEvent, diff --git a/runtime/shiden/Cargo.toml b/runtime/shiden/Cargo.toml index 2aa781ddf8..7680ebf7ca 100644 --- a/runtime/shiden/Cargo.toml +++ b/runtime/shiden/Cargo.toml @@ -100,7 +100,7 @@ frame-try-runtime = { workspace = true, optional = true } # Astar pallets astar-primitives = { workspace = true } -pallet-block-reward = { workspace = true } +pallet-block-rewards-hybrid = { workspace = true } pallet-collator-selection = { workspace = true } pallet-dapps-staking = { workspace = true } pallet-evm-precompile-assets-erc20 = { workspace = true } @@ -146,7 +146,7 @@ std = [ "pallet-balances/std", "pallet-contracts/std", "pallet-contracts-primitives/std", - "pallet-block-reward/std", + "pallet-block-rewards-hybrid/std", "pallet-dynamic-evm-base-fee/std", "pallet-ethereum/std", "pallet-evm/std", @@ -212,7 +212,7 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-dapps-staking/runtime-benchmarks", - "pallet-block-reward/runtime-benchmarks", + "pallet-block-rewards-hybrid/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-collective/runtime-benchmarks", "pallet-ethereum/runtime-benchmarks", @@ -233,7 +233,7 @@ try-runtime = [ "frame-system/try-runtime", "pallet-aura/try-runtime", "pallet-balances/try-runtime", - "pallet-block-reward/try-runtime", + "pallet-block-rewards-hybrid/try-runtime", "pallet-dapps-staking/try-runtime", "pallet-sudo/try-runtime", "pallet-timestamp/try-runtime", diff --git a/runtime/shiden/src/lib.rs b/runtime/shiden/src/lib.rs index d2a3e2c971..1922c0d7f1 100644 --- a/runtime/shiden/src/lib.rs +++ b/runtime/shiden/src/lib.rs @@ -70,7 +70,7 @@ pub use astar_primitives::{ evm::EvmRevertCodeHandler, xcm::AssetLocationIdConverter, AccountId, Address, AssetId, Balance, BlockNumber, Hash, Header, Index, Signature, }; - +pub use pallet_block_rewards_hybrid::RewardDistributionConfig; use pallet_evm_precompile_assets_erc20::AddressToAssetId; #[cfg(any(feature = "std", test))] @@ -468,7 +468,7 @@ impl Get for DappsStakingTvlProvider { } pub struct BeneficiaryPayout(); -impl pallet_block_reward::BeneficiaryPayout for BeneficiaryPayout { +impl pallet_block_rewards_hybrid::BeneficiaryPayout for BeneficiaryPayout { fn treasury(reward: NegativeImbalance) { Balances::resolve_creating(&TreasuryPalletId::get().into_account_truncating(), reward); } @@ -483,16 +483,16 @@ impl pallet_block_reward::BeneficiaryPayout for BeneficiaryPa } parameter_types! { - pub const RewardAmount: Balance = 2_664 * MILLISDN; + pub const MaxBlockRewardAmount: Balance = 2_307_700 * MICROSDN; } -impl pallet_block_reward::Config for Runtime { +impl pallet_block_rewards_hybrid::Config for Runtime { type Currency = Balances; type DappsStakingTvlProvider = DappsStakingTvlProvider; type BeneficiaryPayout = BeneficiaryPayout; - type RewardAmount = RewardAmount; + type MaxBlockRewardAmount = MaxBlockRewardAmount; type RuntimeEvent = RuntimeEvent; - type WeightInfo = pallet_block_reward::weights::SubstrateWeight; + type WeightInfo = pallet_block_rewards_hybrid::weights::SubstrateWeight; } parameter_types! { @@ -989,7 +989,7 @@ construct_runtime!( Balances: pallet_balances = 31, Vesting: pallet_vesting = 32, DappsStaking: pallet_dapps_staking = 34, - BlockReward: pallet_block_reward = 35, + BlockReward: pallet_block_rewards_hybrid = 35, Assets: pallet_assets = 36, Authorship: pallet_authorship = 40, @@ -1050,10 +1050,44 @@ pub type Executive = frame_executive::Executive< Migrations, >; +pub use frame_support::traits::{OnRuntimeUpgrade, StorageVersion}; +pub struct HybridInflationModelMigration; +impl OnRuntimeUpgrade for HybridInflationModelMigration { + fn on_runtime_upgrade() -> Weight { + let mut reward_config = pallet_block_rewards_hybrid::RewardDistributionConfig { + // 4.66% + treasury_percent: Perbill::from_rational(4_662_651u32, 100_000_000u32), + // 23.09% + base_staker_percent: Perbill::from_rational(2_308_792u32, 10_000_000u32), + // 17.32% + dapps_percent: Perbill::from_rational(173_159_422u32, 1_000_000_000u32), + // 2.99% + collators_percent: Perbill::from_rational(29_856_567u32, 1_000_000_000u32), + // 51.95% + adjustable_percent: Perbill::from_rational(519_478_301u32, 1_000_000_000u32), + // 60.00% + ideal_dapps_staking_tvl: Perbill::from_percent(60), + }; + + // This HAS to be tested prior to update - we need to ensure that config is consistent + #[cfg(feature = "try-runtime")] + assert!(reward_config.is_consistent()); + + // This should never execute but we need to have code in place that ensures config is consistent + if !reward_config.is_consistent() { + reward_config = Default::default(); + } + + pallet_block_rewards_hybrid::RewardDistributionConfigStorage::::put(reward_config); + + ::DbWeight::get().writes(1) + } +} + /// All migrations that will run on the next runtime upgrade. /// /// Once done, migrations should be removed from the tuple. -pub type Migrations = (); +pub type Migrations = HybridInflationModelMigration; type EventRecord = frame_system::EventRecord< ::RuntimeEvent, From 9444c8c84fc3f9f8c10d7c81a14cdb1943658ed1 Mon Sep 17 00:00:00 2001 From: PierreOssun Date: Tue, 5 Dec 2023 10:58:59 +0100 Subject: [PATCH 2/2] updated RewardDistributionConfig --- runtime/shiden/src/lib.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/runtime/shiden/src/lib.rs b/runtime/shiden/src/lib.rs index 1922c0d7f1..89245b51e9 100644 --- a/runtime/shiden/src/lib.rs +++ b/runtime/shiden/src/lib.rs @@ -483,7 +483,7 @@ impl pallet_block_rewards_hybrid::BeneficiaryPayout for Benef } parameter_types! { - pub const MaxBlockRewardAmount: Balance = 2_307_700 * MICROSDN; + pub const MaxBlockRewardAmount: Balance = 2_313_789 * MICROSDN; } impl pallet_block_rewards_hybrid::Config for Runtime { @@ -1055,16 +1055,16 @@ pub struct HybridInflationModelMigration; impl OnRuntimeUpgrade for HybridInflationModelMigration { fn on_runtime_upgrade() -> Weight { let mut reward_config = pallet_block_rewards_hybrid::RewardDistributionConfig { - // 4.66% - treasury_percent: Perbill::from_rational(4_662_651u32, 100_000_000u32), - // 23.09% - base_staker_percent: Perbill::from_rational(2_308_792u32, 10_000_000u32), - // 17.32% - dapps_percent: Perbill::from_rational(173_159_422u32, 1_000_000_000u32), - // 2.99% - collators_percent: Perbill::from_rational(29_856_567u32, 1_000_000_000u32), - // 51.95% - adjustable_percent: Perbill::from_rational(519_478_301u32, 1_000_000_000u32), + // 4.81% + treasury_percent: Perbill::from_rational(4_811_793u32, 100_000_000u32), + // 23.02% + base_staker_percent: Perbill::from_rational(23_027_164u32, 100_000_000u32), + // 17.27% + dapps_percent: Perbill::from_rational(17_270_373u32, 100_000_000u32), + // 3.07% + collators_percent: Perbill::from_rational(3_079_547u32, 100_000_000u32), + // 51.81% + adjustable_percent: Perbill::from_rational(51_811_123u32, 100_000_000u32), // 60.00% ideal_dapps_staking_tvl: Perbill::from_percent(60), }; @@ -1165,7 +1165,7 @@ mod benches { [pallet_balances, Balances] [pallet_timestamp, Timestamp] [pallet_dapps_staking, DappsStaking] - [pallet_block_reward, BlockReward] + [block_rewards_hybrid, BlockReward] [pallet_xc_asset_config, XcAssetConfig] [pallet_collator_selection, CollatorSelection] [pallet_xcm, PolkadotXcm]