Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hybrid Inflation Model #1077

Merged
merged 15 commits into from
Nov 17, 2023
11 changes: 5 additions & 6 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions bin/collator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "astar-collator"
version = "5.24.0"
PierreOssun marked this conversation as resolved.
Show resolved Hide resolved
version = "5.25.0"
description = "Astar collator implementation in Rust."
build = "build.rs"
default-run = "astar-collator"
Expand Down Expand Up @@ -94,7 +94,6 @@ shiden-runtime = { workspace = true, features = ["std"] }

# astar pallets dependencies
astar-primitives = { workspace = true }
block-rewards-hybrid = { workspace = true }
pallet-block-reward = { workspace = true }

# frame dependencies
Expand Down
4 changes: 2 additions & 2 deletions bin/collator/src/local/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! Chain specifications.

use local_runtime::{
wasm_binary_unwrap, AccountId, AuraConfig, AuraId, BalancesConfig, BlockRewardConfig,
wasm_binary_unwrap, AccountId, AuraConfig, AuraId, BalancesConfig, BlockRewardConfig, RewardDistributionConfig,
CouncilConfig, DemocracyConfig, EVMConfig, GenesisConfig, GrandpaConfig, GrandpaId,
Precompiles, Signature, SudoConfig, SystemConfig, TechnicalCommitteeConfig, TreasuryConfig,
VestingConfig,
Expand Down Expand Up @@ -117,7 +117,7 @@ fn testnet_genesis(
},
block_reward: BlockRewardConfig {
// Make sure sum is 100
reward_config: block_rewards_hybrid::RewardDistributionConfig {
reward_config: RewardDistributionConfig {
treasury_percent: Perbill::from_percent(25),
base_staker_percent: Perbill::from_percent(30),
dapps_percent: Perbill::from_percent(20),
Expand Down
4 changes: 2 additions & 2 deletions bin/collator/src/parachain/chain_spec/shibuya.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use cumulus_primitives_core::ParaId;
use sc_service::ChainType;
use shibuya_runtime::{
wasm_binary_unwrap, AccountId, AuraConfig, AuraId, Balance, BalancesConfig, BlockRewardConfig,
wasm_binary_unwrap, AccountId, AuraConfig, AuraId, Balance, BalancesConfig, BlockRewardConfig, RewardDistributionConfig,
CollatorSelectionConfig, CouncilConfig, DemocracyConfig, EVMChainIdConfig, EVMConfig,
GenesisConfig, ParachainInfoConfig, Precompiles, SessionConfig, SessionKeys, Signature,
SudoConfig, SystemConfig, TechnicalCommitteeConfig, TreasuryConfig, VestingConfig, SBY,
Expand Down Expand Up @@ -115,7 +115,7 @@ fn make_genesis(
balances: BalancesConfig { balances },
block_reward: BlockRewardConfig {
// Make sure sum is 100
reward_config: block_rewards_hybrid::RewardDistributionConfig {
reward_config: RewardDistributionConfig {
treasury_percent: Perbill::from_percent(10),
base_staker_percent: Perbill::from_percent(20),
dapps_percent: Perbill::from_percent(20),
Expand Down
28 changes: 16 additions & 12 deletions pallets/block-rewards-hybrid/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ fn reward_distribution_config_is_consistent() {
// 4
// 100%
let reward_config = RewardDistributionConfig {
treasury_percent: Perbill::from_percent(3),
base_staker_percent: Perbill::from_percent(14),
dapps_percent: Perbill::from_percent(18),
collators_percent: Perbill::from_percent(31),
adjustable_percent: Perbill::from_percent(34),
ideal_dapps_staking_tvl: Zero::zero(),
treasury_percent: Perbill::from_rational(4663701u32, 100000000u32),
base_staker_percent: Perbill::from_rational(2309024u32, 10000000u32),
dapps_percent: Perbill::from_rational(173094531u32, 1000000000u32),
collators_percent: Perbill::from_rational(29863296u32, 1000000000u32),
adjustable_percent: Perbill::from_rational(519502763u32, 1000000000u32),
ideal_dapps_staking_tvl: Perbill::from_percent(60),
};
assert!(reward_config.is_consistent());
}
Expand Down Expand Up @@ -211,13 +211,13 @@ pub fn reward_distribution_as_expected() {
reward_config.clone()
));

// Initial adjustment of TVL
set_tvl(30);

// Issue rewards a couple of times and verify distribution is as expected
// also ensure that the non distributed reward amount is burn
// (that the total issuance is only increased by the amount that has been rewarded)
for _block in 1..=100 {
// TVL amount is updated every block
// to ensure TVL ratio as expected
adjust_tvl(30);
let init_balance_state = FreeBalanceSnapshot::new();
let total_issuance_before = <TestRuntime as Config>::Currency::total_issuance();
let distributed_rewards = Rewards::calculate(&reward_config);
Expand Down Expand Up @@ -258,10 +258,10 @@ pub fn non_distributed_reward_amount_is_burned() {
));

for tvl in [30, 50, 70, 100] {
// Initial adjustment of TVL
set_tvl(tvl);

for _block in 1..=100 {
// TVL amount is updated every block
// to ensure TVL ratio as expected
adjust_tvl(tvl);
let total_issuance_before = <TestRuntime as Config>::Currency::total_issuance();
let distributed_rewards = Rewards::calculate(&reward_config);
let burned_amount = BLOCK_REWARD - distributed_rewards.sum();
Expand Down Expand Up @@ -456,3 +456,7 @@ impl Rewards {
+ self.treasury_reward
}
}

fn adjust_tvl(desired_percent: u128) {
set_tvl(<TestRuntime as Config>::Currency::total_issuance() / 100 * desired_percent);
}
2 changes: 1 addition & 1 deletion runtime/astar/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "astar-runtime"
version = "5.24.0"
version = "5.25.0"
build = "build.rs"
authors.workspace = true
edition.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion runtime/astar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("astar"),
impl_name: create_runtime_str!("astar"),
authoring_version: 1,
spec_version: 71,
spec_version: 72,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
Expand Down
2 changes: 1 addition & 1 deletion runtime/local/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "local-runtime"
version = "5.23.0"
version = "5.25.0"
build = "build.rs"
authors.workspace = true
edition.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion runtime/local/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub use astar_primitives::{
evm::EvmRevertCodeHandler, AccountId, Address, AssetId, Balance, BlockNumber, Hash, Header,
Index, Signature,
};
pub use block_rewards_hybrid::RewardDistributionConfig;

pub use crate::precompiles::WhitelistedCalls;
#[cfg(feature = "std")]
Expand Down Expand Up @@ -438,7 +439,7 @@ impl block_rewards_hybrid::BeneficiaryPayout<NegativeImbalance> for BeneficiaryP
}

parameter_types! {
pub const MaxBlockRewardAmount: Balance = 2_664 * MILLIAST;
pub const MaxBlockRewardAmount: Balance = 230_718 * MILLIAST;
PierreOssun marked this conversation as resolved.
Show resolved Hide resolved
}

impl block_rewards_hybrid::Config for Runtime {
Expand Down
2 changes: 1 addition & 1 deletion runtime/shibuya/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "shibuya-runtime"
version = "5.24.0"
version = "5.25.0"
build = "build.rs"
authors.workspace = true
edition.workspace = true
Expand Down
41 changes: 38 additions & 3 deletions runtime/shibuya/src/lib.rs
PierreOssun marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub use astar_primitives::{
xcm::AssetLocationIdConverter, AccountId, Address, AssetId, Balance, BlockNumber, Hash, Header,
Index, Signature,
};
pub use block_rewards_hybrid::RewardDistributionConfig;

pub use crate::precompiles::WhitelistedCalls;

Expand Down Expand Up @@ -166,7 +167,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("shibuya"),
impl_name: create_runtime_str!("shibuya"),
authoring_version: 1,
spec_version: 114,
spec_version: 115,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
Expand Down Expand Up @@ -552,7 +553,7 @@ impl block_rewards_hybrid::BeneficiaryPayout<NegativeImbalance> for BeneficiaryP
}

parameter_types! {
pub const MaxBlockRewardAmount: Balance = 2_530 * MILLISBY;
pub const MaxBlockRewardAmount: Balance = 230_718 * MILLISBY;
}

impl block_rewards_hybrid::Config for Runtime {
Expand Down Expand Up @@ -1311,10 +1312,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 = block_rewards_hybrid::RewardDistributionConfig {
// 4.66%
treasury_percent: Perbill::from_rational(4663701u32, 100000000u32),
PierreOssun marked this conversation as resolved.
Show resolved Hide resolved
// 23.09%
base_staker_percent: Perbill::from_rational(2309024u32, 10000000u32),
// 17.31%
dapps_percent: Perbill::from_rational(173094531u32, 1000000000u32),
// 2.99%
collators_percent: Perbill::from_rational(29863296u32, 1000000000u32),
// 51.95%
adjustable_percent: Perbill::from_rational(519502763u32, 1000000000u32),
// 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();
}

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
2 changes: 1 addition & 1 deletion runtime/shiden/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "shiden-runtime"
version = "5.24.0"
version = "5.25.0"
build = "build.rs"
authors.workspace = true
edition.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion runtime/shiden/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("shiden"),
impl_name: create_runtime_str!("shiden"),
authoring_version: 1,
spec_version: 111,
spec_version: 112,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
Expand Down
Loading