Skip to content

Commit

Permalink
Added hybrid inflation to Shiden + Migration
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreOssun committed Dec 4, 2023
1 parent 45ea9ff commit 702a34e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

6 changes: 3 additions & 3 deletions bin/collator/src/parachain/chain_spec/shiden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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),
Expand Down
36 changes: 1 addition & 35 deletions runtime/shibuya/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Runtime>::put(reward_config);

<Runtime as frame_system::pallet::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<
<Runtime as frame_system::Config>::RuntimeEvent,
Expand Down
8 changes: 4 additions & 4 deletions runtime/shiden/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
50 changes: 42 additions & 8 deletions runtime/shiden/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -468,7 +468,7 @@ impl Get<Balance> for DappsStakingTvlProvider {
}

pub struct BeneficiaryPayout();
impl pallet_block_reward::BeneficiaryPayout<NegativeImbalance> for BeneficiaryPayout {
impl pallet_block_rewards_hybrid::BeneficiaryPayout<NegativeImbalance> for BeneficiaryPayout {
fn treasury(reward: NegativeImbalance) {
Balances::resolve_creating(&TreasuryPalletId::get().into_account_truncating(), reward);
}
Expand All @@ -483,16 +483,16 @@ impl pallet_block_reward::BeneficiaryPayout<NegativeImbalance> 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<Runtime>;
type WeightInfo = pallet_block_rewards_hybrid::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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::<Runtime>::put(reward_config);

<Runtime as frame_system::pallet::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<
<Runtime as frame_system::Config>::RuntimeEvent,
Expand Down

0 comments on commit 702a34e

Please sign in to comment.