git.delta.rocks / unique-network / refs/commits / 44c855833903

difftreelog

Merge pull request #255 from UniqueNetwork/feature/CORE-247

kozyrevdev2021-12-09parents: #6388bd8 #f94b311.patch.diff
in: master
Inflation pallet block provider added. Setted up to relay chain.

8 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -11679,6 +11679,7 @@
  "pallet-evm-migration",
  "pallet-evm-transaction-payment",
  "pallet-fungible",
+ "pallet-inflation",
  "pallet-nonfungible",
  "pallet-randomness-collective-flip",
  "pallet-refungible",
modifiedpallets/inflation/src/lib.rsdiffbeforeafterboth
before · pallets/inflation/src/lib.rs
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56#![recursion_limit = "1024"]7#![cfg_attr(not(feature = "std"), no_std)]89#[cfg(feature = "std")]10pub use std::*;1112pub use serde::{Serialize, Deserialize};1314#[cfg(feature = "runtime-benchmarks")]15mod benchmarking;1617#[cfg(test)]18mod tests;1920pub use frame_support::{21	construct_runtime, decl_module, decl_storage, ensure,22	traits::{23		Currency, ExistenceRequirement, Get, Imbalance, KeyOwnerProofSystem, OnUnbalanced,24		Randomness, IsSubType, WithdrawReasons,25	},26	weights::{27		constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},28		DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,29		WeightToFeePolynomial, DispatchClass,30	},31	StorageValue, transactional,32};3334// #[cfg(feature = "runtime-benchmarks")]35pub use frame_support::dispatch::DispatchResult;3637use sp_runtime::{38	Perbill,39	traits::{Zero},40};41use sp_std::convert::TryInto;4243use frame_system::{self as system};4445/// The balance type of this module.46pub type BalanceOf<T> =47	<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;4849// pub const YEAR: u32 = 5_259_600; // 6-second block50pub const YEAR: u32 = 2_629_800; // 12-second block51pub const TOTAL_YEARS_UNTIL_FLAT: u32 = 9;52pub const START_INFLATION_PERCENT: u32 = 10;53pub const END_INFLATION_PERCENT: u32 = 4;5455pub trait Config: system::Config {56	type Currency: Currency<Self::AccountId>;57	type TreasuryAccountId: Get<Self::AccountId>;58	type InflationBlockInterval: Get<Self::BlockNumber>;59}6061decl_storage! {62	trait Store for Module<T: Config> as Inflation {63		/// starting year total issuance64		pub StartingYearTotalIssuance get(fn starting_year_total_issuance): BalanceOf<T>;6566		/// Current block inflation67		pub BlockInflation get(fn block_inflation): BalanceOf<T>;68	}69}7071decl_module! {72	pub struct Module<T: Config> for enum Call73	where74		origin: T::Origin,75	{76		const InflationBlockInterval: T::BlockNumber = T::InflationBlockInterval::get();7778		fn on_initialize(now: T::BlockNumber) -> Weight79		{80			let mut consumed_weight = 0;81			let mut add_weight = |reads, writes, weight| {82				consumed_weight += T::DbWeight::get().reads_writes(reads, writes);83				consumed_weight += weight;84			};8586			let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);8788			// TODO: Rewrite inflation to use block timestamp instead of block number89			// let _now = <timestamp::Module<T>>::get();9091			// Recalculate inflation on the first block of the year (or if it is not initialized yet)92			if (now % T::BlockNumber::from(YEAR)).is_zero() || <BlockInflation<T>>::get().is_zero() {93				let current_year: u32 = (now / T::BlockNumber::from(YEAR)).try_into().unwrap_or(0);9495				let one_percent = Perbill::from_percent(1);9697				if current_year <= TOTAL_YEARS_UNTIL_FLAT {98					let amount: BalanceOf<T> = Perbill::from_rational(99						block_interval * (START_INFLATION_PERCENT * TOTAL_YEARS_UNTIL_FLAT - current_year * (START_INFLATION_PERCENT - END_INFLATION_PERCENT)),100						YEAR * TOTAL_YEARS_UNTIL_FLAT101					) * ( one_percent * T::Currency::total_issuance() );102					<BlockInflation<T>>::put(amount);103				}104				else {105					let amount: BalanceOf<T> = Perbill::from_rational(106						block_interval * END_INFLATION_PERCENT,107						YEAR108					) * (one_percent * T::Currency::total_issuance());109					<BlockInflation<T>>::put(amount);110				}111				<StartingYearTotalIssuance<T>>::set(T::Currency::total_issuance());112113				// First time deposit114				T::Currency::deposit_creating(&T::TreasuryAccountId::get(), <BlockInflation<T>>::get());115116				add_weight(7, 6, 28_300_000);117			}118119			// Apply inflation every InflationBlockInterval blocks and in the 1st block to initialize Treasury account120			else if (now % T::BlockNumber::from(block_interval)).is_zero() {121				T::Currency::deposit_into_existing(&T::TreasuryAccountId::get(), <BlockInflation<T>>::get()).ok();122123				add_weight(3, 2, 12_900_000);124			}125126			consumed_weight127		}128129	}130}
after · pallets/inflation/src/lib.rs
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56// #![recursion_limit = "1024"]7#![cfg_attr(not(feature = "std"), no_std)]89#[cfg(feature = "runtime-benchmarks")]10mod benchmarking;1112#[cfg(test)]13mod tests;1415use frame_support::{16	dispatch::{DispatchResult},17	traits::{Currency, Get},18};19pub use pallet::*;20use sp_runtime::{21	Perbill,22	traits::{BlockNumberProvider},23};2425use sp_std::convert::TryInto;2627type BalanceOf<T> =28	<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;2930pub const YEAR: u32 = 5_259_600; // 6-second block31								 // pub const YEAR: u32 = 2_629_800; // 12-second block32pub const TOTAL_YEARS_UNTIL_FLAT: u32 = 9;33pub const START_INFLATION_PERCENT: u32 = 10;34pub const END_INFLATION_PERCENT: u32 = 4;3536#[frame_support::pallet]37pub mod pallet {38	use super::*;39	use frame_support::pallet_prelude::*;40	use frame_system::pallet_prelude::*;4142	#[pallet::config]43	pub trait Config: frame_system::Config {44		type Currency: Currency<Self::AccountId>;45		type TreasuryAccountId: Get<Self::AccountId>;4647		// The block number provider48		type BlockNumberProvider: BlockNumberProvider<BlockNumber = Self::BlockNumber>;4950		/// Number of blocks that pass between treasury balance updates due to inflation51		#[pallet::constant]52		type InflationBlockInterval: Get<Self::BlockNumber>;53	}5455	#[pallet::pallet]56	#[pallet::generate_store(pub(super) trait Store)]57	pub struct Pallet<T>(_);5859	/// starting year total issuance60	#[pallet::storage]61	pub type StartingYearTotalIssuance<T: Config> =62		StorageValue<Value = BalanceOf<T>, QueryKind = ValueQuery>;6364	/// Current inflation for `InflationBlockInterval` number of blocks65	#[pallet::storage]66	pub type BlockInflation<T: Config> = StorageValue<Value = BalanceOf<T>, QueryKind = ValueQuery>;6768	/// Next target (relay) block when inflation will be applied69	#[pallet::storage]70	pub type NextInflationBlock<T: Config> =71		StorageValue<Value = T::BlockNumber, QueryKind = ValueQuery>;7273	/// Next target (relay) block when inflation is recalculated74	#[pallet::storage]75	pub type NextRecalculationBlock<T: Config> =76		StorageValue<Value = T::BlockNumber, QueryKind = ValueQuery>;7778	#[pallet::hooks]79	impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {80		fn on_initialize(_: T::BlockNumber) -> Weight81		where82			<T as frame_system::Config>::BlockNumber: From<u32>,83		{84			let mut consumed_weight = 0;85			let mut add_weight = |reads, writes, weight| {86				consumed_weight += T::DbWeight::get().reads_writes(reads, writes);87				consumed_weight += weight;88			};8990			let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);91			let current_relay_block = T::BlockNumberProvider::current_block_number();92			let next_inflation: T::BlockNumber = <NextInflationBlock<T>>::get();93			add_weight(1, 0, 5_000_000);9495			// Apply inflation every InflationBlockInterval blocks96			// If next_inflation == 0, this means inflation wasn't yet initialized97			if (next_inflation != 0u32.into()) && (current_relay_block >= next_inflation) {98				// Recalculate inflation on the first block of the year (or if it is not initialized yet)99				// Do the "current_relay_block >= next_recalculation" check in the "current_relay_block >= next_inflation"100				// block because it saves InflationBlockInterval DB reads for NextRecalculationBlock.101				let next_recalculation: T::BlockNumber = <NextRecalculationBlock<T>>::get();102				add_weight(1, 0, 0);103				if current_relay_block >= next_recalculation {104					Self::recalculate_inflation(next_recalculation);105					add_weight(0, 4, 5_000_000);106				}107108				T::Currency::deposit_into_existing(109					&T::TreasuryAccountId::get(),110					<BlockInflation<T>>::get(),111				)112				.ok();113114				// Update inflation block115				<NextInflationBlock<T>>::set(next_inflation + block_interval.into());116117				add_weight(3, 3, 10_000_000);118			}119120			consumed_weight121		}122	}123124	#[pallet::call]125	impl<T: Config> Pallet<T> {126		/// This method sets the inflation start date. Can be only called once.127		/// Inflation start block can be backdated and will catch up. The method will create Treasury128		/// account if it does not exist and perform the first inflation deposit.129		///130		/// # Permissions131		///132		/// * Root133		///134		/// # Arguments135		///136		/// * inflation_start_relay_block: The relay chain block at which inflation should start137		#[pallet::weight(0)]138		pub fn start_inflation(139			origin: OriginFor<T>,140			inflation_start_relay_block: T::BlockNumber,141		) -> DispatchResult142		where143			<T as frame_system::Config>::BlockNumber: From<u32>,144		{145			ensure_root(origin)?;146147			// Start inflation if it has not been yet initialized148			let next_inflation: T::BlockNumber = <NextInflationBlock<T>>::get();149			if next_inflation == 0u32.into() {150				// Recalculate inflation. This can be backdated and will catch up.151				Self::recalculate_inflation(inflation_start_relay_block);152				let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);153				<NextInflationBlock<T>>::set(inflation_start_relay_block + block_interval.into());154155				// First time deposit - create Treasury account so that we can call deposit_into_existing everywhere else156				T::Currency::deposit_creating(157					&T::TreasuryAccountId::get(),158					<BlockInflation<T>>::get(),159				);160			}161162			Ok(())163		}164	}165}166167impl<T: Config> Pallet<T> {168	pub fn recalculate_inflation(recalculation_block: T::BlockNumber) {169		let current_year: u32 = (recalculation_block / T::BlockNumber::from(YEAR))170			.try_into()171			.unwrap_or(0);172		let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);173174		let one_percent = Perbill::from_percent(1);175176		if current_year <= TOTAL_YEARS_UNTIL_FLAT {177			let amount: BalanceOf<T> = Perbill::from_rational(178				block_interval179					* (START_INFLATION_PERCENT * TOTAL_YEARS_UNTIL_FLAT180						- current_year * (START_INFLATION_PERCENT - END_INFLATION_PERCENT)),181				YEAR * TOTAL_YEARS_UNTIL_FLAT,182			) * (one_percent * T::Currency::total_issuance());183			<BlockInflation<T>>::put(amount);184		} else {185			let amount: BalanceOf<T> =186				Perbill::from_rational(block_interval * END_INFLATION_PERCENT, YEAR)187					* (one_percent * T::Currency::total_issuance());188			<BlockInflation<T>>::put(amount);189		}190		<StartingYearTotalIssuance<T>>::set(T::Currency::total_issuance());191192		// Update recalculation and inflation blocks193		<NextRecalculationBlock<T>>::set(recalculation_block + YEAR.into());194	}195}
modifiedpallets/inflation/src/tests.rsdiffbeforeafterboth
--- a/pallets/inflation/src/tests.rs
+++ b/pallets/inflation/src/tests.rs
@@ -3,22 +3,23 @@
 use crate as pallet_inflation;
 
 use frame_support::{
-	traits::{Currency},
-	parameter_types,
-};
-use frame_support::{
-	traits::{OnInitialize, Everything},
+	assert_ok, parameter_types,
+	traits::{Currency, OnInitialize, Everything},
 };
+use frame_system::RawOrigin;
 use sp_core::H256;
 use sp_runtime::{
-	traits::{BlakeTwo256, IdentityLookup},
+	traits::{BlakeTwo256, BlockNumberProvider, IdentityLookup},
 	testing::Header,
 };
 
 type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
 type Block = frame_system::mocking::MockBlock<Test>;
 
-const YEAR: u64 = 2_629_800;
+const YEAR: u64 = 5_259_600; // 6-second blocks
+							 // const YEAR: u64 = 2_629_800; // 12-second blocks
+							 // Expected 100-block inflation for year 1 is 100 * 100_000_000 / YEAR = FIRST_YEAR_BLOCK_INFLATION
+const FIRST_YEAR_BLOCK_INFLATION: u64 = 1901;
 
 parameter_types! {
 	pub const ExistentialDeposit: u64 = 1;
@@ -85,12 +86,22 @@
 parameter_types! {
 	pub TreasuryAccountId: u64 = 1234;
 	pub const InflationBlockInterval: u32 = 100; // every time per how many blocks inflation is applied
+	pub static MockBlockNumberProvider: u64 = 0;
 }
 
+impl BlockNumberProvider for MockBlockNumberProvider {
+	type BlockNumber = u64;
+
+	fn current_block_number() -> Self::BlockNumber {
+		Self::get()
+	}
+}
+
 impl pallet_inflation::Config for Test {
 	type Currency = Balances;
 	type TreasuryAccountId = TreasuryAccountId;
 	type InflationBlockInterval = InflationBlockInterval;
+	type BlockNumberProvider = MockBlockNumberProvider;
 }
 
 pub fn new_test_ext() -> sp_io::TestExternalities {
@@ -100,6 +111,29 @@
 		.into()
 }
 
+macro_rules! block_inflation {
+	// Block inflation doesn't have any argumets
+	() => {
+		// Return BlockInflation state variable current value
+		<pallet_inflation::BlockInflation<Test>>::get()
+	};
+}
+
+#[test]
+fn uninitialized_inflation() {
+	new_test_ext().execute_with(|| {
+		let initial_issuance: u64 = 1_000_000_000;
+		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
+		assert_eq!(Balances::free_balance(1234), initial_issuance);
+
+		// BlockInflation should be set after inflation is started
+		// first inflation deposit should be equal to BlockInflation
+		MockBlockNumberProvider::set(1);
+
+		assert_eq!(block_inflation!(), 0);
+	});
+}
+
 #[test]
 fn inflation_works() {
 	new_test_ext().execute_with(|| {
@@ -108,16 +142,25 @@
 		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
 		assert_eq!(Balances::free_balance(1234), initial_issuance);
 
-		// BlockInflation should be set after 1st block and
+		// BlockInflation should be set after inflation is started
 		// first inflation deposit should be equal to BlockInflation
-		Inflation::on_initialize(1);
+		MockBlockNumberProvider::set(1);
 
-		// Expected 100-block inflation for year 1 is 100 * 100_000_000 / YEAR = 3803
-		assert_eq!(Inflation::block_inflation(), 3803);
+		// Start inflation as sudo
+		assert_ok!(Inflation::start_inflation(RawOrigin::Root.into(), 1));
+		assert_eq!(block_inflation!(), FIRST_YEAR_BLOCK_INFLATION);
 		assert_eq!(
 			Balances::free_balance(1234) - initial_issuance,
-			Inflation::block_inflation()
+			block_inflation!()
 		);
+
+		// Trigger inflation
+		MockBlockNumberProvider::set(102);
+		Inflation::on_initialize(0);
+		assert_eq!(
+			Balances::free_balance(1234) - initial_issuance,
+			2 * block_inflation!()
+		);
 	});
 }
 
@@ -128,25 +171,27 @@
 		let initial_issuance: u64 = 1_000_000_000;
 		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
 		assert_eq!(Balances::free_balance(1234), initial_issuance);
-		Inflation::on_initialize(1);
+		MockBlockNumberProvider::set(1);
 
-		// Next inflation deposit happens when block is multiple of InflationBlockInterval
-		let mut block: u32 = 2;
+		// Start inflation as sudo
+		assert_ok!(Inflation::start_inflation(RawOrigin::Root.into(), 1));
+
+		// Next inflation deposit happens when block is greater then or equal to NextInflationBlock
+		let mut block: u64 = 2;
 		let balance_before: u64 = Balances::free_balance(1234);
-		while block % InflationBlockInterval::get() != 0 {
-			Inflation::on_initialize(block as u64);
+		while block < <pallet_inflation::NextInflationBlock<Test>>::get() {
+			MockBlockNumberProvider::set(block as u64);
+			Inflation::on_initialize(0);
 			block += 1;
 		}
 		let balance_just_before: u64 = Balances::free_balance(1234);
 		assert_eq!(balance_before, balance_just_before);
 
 		// The block with inflation
-		Inflation::on_initialize(block as u64);
+		MockBlockNumberProvider::set(block as u64);
+		Inflation::on_initialize(0);
 		let balance_after: u64 = Balances::free_balance(1234);
-		assert_eq!(
-			balance_after - balance_just_before,
-			Inflation::block_inflation()
-		);
+		assert_eq!(balance_after - balance_just_before, block_inflation!());
 	});
 }
 
@@ -157,59 +202,56 @@
 		let initial_issuance: u64 = 1_000_000_000;
 		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
 		assert_eq!(Balances::free_balance(1234), initial_issuance);
-		Inflation::on_initialize(1);
+		MockBlockNumberProvider::set(1);
 
+		// Start inflation as sudo
+		assert_ok!(Inflation::start_inflation(RawOrigin::Root.into(), 1));
+
 		// Go through all the block inflations for year 1,
 		// total issuance will be updated accordingly
-		for block in (100..YEAR).step_by(100) {
-			Inflation::on_initialize(block);
+		// Inflation is set to start in block 1, so first iteration is block 101
+		for block in (101..YEAR).step_by(100) {
+			MockBlockNumberProvider::set(block);
+			Inflation::on_initialize(0);
 		}
 		assert_eq!(
-			initial_issuance + (3803 * (YEAR / 100)),
+			initial_issuance + (FIRST_YEAR_BLOCK_INFLATION * (YEAR / 100)),
 			<Balances as Currency<_>>::total_issuance()
 		);
 
-		Inflation::on_initialize(YEAR);
-		let block_inflation_year_1 = Inflation::block_inflation();
-		// Expected 100-block inflation for year 2: 100 * 9.33% * initial issuance * 110% / YEAR = 3904
-		assert_eq!(block_inflation_year_1, 3904);
+		MockBlockNumberProvider::set(YEAR + 1);
+		Inflation::on_initialize(0);
+		let block_inflation_year_2 = block_inflation!();
+		// Expected 100-block inflation for year 2: 100 * 9.33% * initial issuance * 110% / YEAR == 1951
+		let expecter_year_2_inflation: u64 = (initial_issuance
+			+ FIRST_YEAR_BLOCK_INFLATION * YEAR / 100)
+			* 933 * 100 / (10000 * YEAR);
+		assert_eq!(block_inflation_year_2 / 10, expecter_year_2_inflation / 10); // divide by 10 for approx. equality
 	});
 }
 
 #[test]
-fn inflation_in_1_to_9_years() {
+fn inflation_after_year_10_is_flat() {
 	new_test_ext().execute_with(|| {
 		// Total issuance = 1_000_000_000
 		let initial_issuance: u64 = 1_000_000_000;
 		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
 		assert_eq!(Balances::free_balance(1234), initial_issuance);
-		Inflation::on_initialize(1);
+		MockBlockNumberProvider::set(YEAR * 9 + 1);
 
-		for year in 1..=9 {
-			let block_inflation_year_before = Inflation::block_inflation();
-			Inflation::on_initialize(YEAR * year);
-			let block_inflation_year_after = Inflation::block_inflation();
+		// Start inflation as sudo
+		assert_ok!(Inflation::start_inflation(RawOrigin::Root.into(), 1));
 
-			// SBP M2 review: this is actually not true (not for the first few years)
-			// Assert that next year inflation is less than previous year inflation
-			assert!(block_inflation_year_before > block_inflation_year_after);
+		// Let inflation catch up
+		for _year in 1..=9 {
+			Inflation::on_initialize(0);
 		}
-	});
-}
 
-#[test]
-fn inflation_after_year_10_is_flat() {
-	new_test_ext().execute_with(|| {
-		// Total issuance = 1_000_000_000
-		let initial_issuance: u64 = 1_000_000_000;
-		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
-		assert_eq!(Balances::free_balance(1234), initial_issuance);
-		Inflation::on_initialize(YEAR * 9);
-
 		for year in 10..=20 {
-			let block_inflation_year_before = Inflation::block_inflation();
-			Inflation::on_initialize(YEAR * year);
-			let block_inflation_year_after = Inflation::block_inflation();
+			let block_inflation_year_before = block_inflation!();
+			MockBlockNumberProvider::set(YEAR * year + 1);
+			Inflation::on_initialize(0);
+			let block_inflation_year_after = block_inflation!();
 
 			// Assert that next year inflation is equal to previous year inflation
 			assert_eq!(block_inflation_year_before, block_inflation_year_after);
@@ -231,25 +273,32 @@
 		let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
 		assert_eq!(Balances::free_balance(1234), initial_issuance);
 
+		// Start inflation as sudo
+		assert_ok!(Inflation::start_inflation(RawOrigin::Root.into(), 1));
+
 		for year in 0..=10 {
 			// Year first block
-			Inflation::on_initialize(year * YEAR);
-			let mut actual_payout = Inflation::block_inflation();
+			MockBlockNumberProvider::set(YEAR * year + 1);
+			Inflation::on_initialize(0);
+			let mut actual_payout = block_inflation!();
 			assert_eq!(actual_payout, payout_by_year[year as usize]);
 
 			// Year second block
-			Inflation::on_initialize(year * YEAR + 1);
-			actual_payout = Inflation::block_inflation();
+			MockBlockNumberProvider::set(YEAR * year + 2);
+			Inflation::on_initialize(0);
+			actual_payout = block_inflation!();
 			assert_eq!(actual_payout, payout_by_year[year as usize]);
 
 			// Year middle block
-			Inflation::on_initialize(year * YEAR + YEAR / 2);
-			actual_payout = Inflation::block_inflation();
+			MockBlockNumberProvider::set(year * YEAR + YEAR / 2);
+			Inflation::on_initialize(0);
+			actual_payout = block_inflation!();
 			assert_eq!(actual_payout, payout_by_year[year as usize]);
 
 			// Year last block
-			Inflation::on_initialize((year + 1) * YEAR - 1);
-			actual_payout = Inflation::block_inflation();
+			MockBlockNumberProvider::set((year + 1) * YEAR);
+			Inflation::on_initialize(0);
+			actual_payout = block_inflation!();
 			assert_eq!(actual_payout, payout_by_year[year as usize]);
 		}
 	});
modifiedruntime/Cargo.tomldiffbeforeafterboth
--- a/runtime/Cargo.toml
+++ b/runtime/Cargo.toml
@@ -33,7 +33,7 @@
     'pallet-refungible/runtime-benchmarks',
     'pallet-nonfungible/runtime-benchmarks',
     'pallet-unique/runtime-benchmarks',
-#    'pallet-inflation/runtime-benchmarks',
+    'pallet-inflation/runtime-benchmarks',
     'pallet-xcm/runtime-benchmarks',
     'sp-runtime/runtime-benchmarks',
     'xcm-builder/runtime-benchmarks',
@@ -75,7 +75,7 @@
     'fp-self-contained/std',
     'parachain-info/std',
     'serde',
-#    'pallet-inflation/std',
+    'pallet-inflation/std',
     'pallet-common/std',
     'pallet-fungible/std',
     'pallet-refungible/std',
@@ -380,7 +380,7 @@
 pallet-unique = { path = '../pallets/unique', default-features = false }
 up-rpc = { path = "../primitives/rpc", default-features = false }
 up-evm-mapping = { path = "../primitives/evm-mapping", default-features = false }
-# pallet-inflation = { path = '../pallets/inflation', default-features = false }
+pallet-inflation = { path = '../pallets/inflation', default-features = false }
 up-data-structs = { path = '../primitives/data-structs', default-features = false }
 pallet-common = { default-features = false, path = "../pallets/common" }
 pallet-fungible = { default-features = false, path = "../pallets/fungible" }
modifiedruntime/src/lib.rsdiffbeforeafterboth
--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -785,17 +785,18 @@
 	type Event = Event;
 	type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;
 }
-/*
+
 parameter_types! {
 	pub const InflationBlockInterval: BlockNumber = 100; // every time per how many blocks inflation is applied
-} */
+}
 
 /// Used for the pallet inflation
-/* impl pallet_inflation::Config for Runtime {
+impl pallet_inflation::Config for Runtime {
 	type Currency = Balances;
 	type TreasuryAccountId = TreasuryAccountId;
 	type InflationBlockInterval = InflationBlockInterval;
-} */
+	type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;
+}
 
 // parameter_types! {
 // 	pub MaximumSchedulerWeight: Weight = Perbill::from_percent(50) *
@@ -882,7 +883,7 @@
 		DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 53,
 
 		// Unique Pallets
-		// Inflation: pallet_inflation::{Pallet, Call, Storage} = 60,
+		Inflation: pallet_inflation::{Pallet, Call, Storage} = 60,
 		Unique: pallet_unique::{Pallet, Call, Storage, Event<T>} = 61,
 		// Scheduler: pallet_unq_scheduler::{Pallet, Call, Storage, Event<T>} = 62,
 		// free = 63
@@ -1367,7 +1368,7 @@
 
 			list_benchmark!(list, extra, pallet_evm_migration, EvmMigration);
 			list_benchmark!(list, extra, pallet_unique, Unique);
-			//list_benchmark!(list, extra, pallet_inflation, Inflation);
+			list_benchmark!(list, extra, pallet_inflation, Inflation);
 			list_benchmark!(list, extra, pallet_fungible, Fungible);
 			list_benchmark!(list, extra, pallet_refungible, Refungible);
 			list_benchmark!(list, extra, pallet_nonfungible, Nonfungible);
@@ -1401,7 +1402,7 @@
 
 			add_benchmark!(params, batches, pallet_evm_migration, EvmMigration);
 			add_benchmark!(params, batches, pallet_unique, Unique);
-			//add_benchmark!(params, batches, pallet_inflation, Inflation);
+			add_benchmark!(params, batches, pallet_inflation, Inflation);
 			add_benchmark!(params, batches, pallet_fungible, Fungible);
 			add_benchmark!(params, batches, pallet_refungible, Refungible);
 			add_benchmark!(params, batches, pallet_nonfungible, Nonfungible);
modifiedtests/src/creditFeesToTreasury.test.tsdiffbeforeafterboth
--- a/tests/src/creditFeesToTreasury.test.ts
+++ b/tests/src/creditFeesToTreasury.test.ts
@@ -34,7 +34,7 @@
 // Skip the inflation block pauses if the block is close to inflation block
 // until the inflation happens
 /*eslint no-async-promise-executor: "off"*/
-/*function skipInflationBlock(api: ApiPromise): Promise<void> {
+function skipInflationBlock(api: ApiPromise): Promise<void> {
   const promise = new Promise<void>(async (resolve) => {
     const blockInterval = (await api.consts.inflation.inflationBlockInterval).toNumber();
     const unsubscribe = await api.rpc.chain.subscribeNewHeads(head => {
@@ -49,7 +49,7 @@
   });
 
   return promise;
-}*/
+}
 
 describe('integration test: Fees must be credited to Treasury:', () => {
   before(async () => {
@@ -61,7 +61,7 @@
 
   it('Total issuance does not change', async () => {
     await usingApi(async (api) => {
-      //await skipInflationBlock(api);
+      await skipInflationBlock(api);
       await waitNewBlocks(api, 1);
 
       const totalBefore = (await api.query.balances.totalIssuance()).toBigInt();
@@ -81,7 +81,7 @@
 
   it('Sender balance decreased by fee+sent amount, Treasury balance increased by fee', async () => {
     await usingApi(async (api) => {
-      //await skipInflationBlock(api);
+      await skipInflationBlock(api);
       await waitNewBlocks(api, 1);
 
       const alicePrivateKey = privateKey('//Alice');
@@ -125,7 +125,7 @@
 
   it('NFT Transactions also send fees to Treasury', async () => {
     await usingApi(async (api) => {
-      //await skipInflationBlock(api);
+      await skipInflationBlock(api);
       await waitNewBlocks(api, 1);
 
       const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();
@@ -144,7 +144,7 @@
 
   it('Fees are sane', async () => {
     await usingApi(async (api) => {
-      //await skipInflationBlock(api);
+      await skipInflationBlock(api);
       await waitNewBlocks(api, 1);
 
       const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
@@ -161,7 +161,7 @@
 
   it('NFT Transfer fee is close to 0.1 Unique', async () => {
     await usingApi(async (api) => {
-      //await skipInflationBlock(api);
+      await skipInflationBlock(api);
       await waitNewBlocks(api, 1);
 
       const collectionId = await createCollectionExpectSuccess();
modifiedtests/src/inflation.test.tsdiffbeforeafterboth
--- a/tests/src/inflation.test.ts
+++ b/tests/src/inflation.test.ts
@@ -5,21 +5,32 @@
 
 import chai from 'chai';
 import chaiAsPromised from 'chai-as-promised';
-import {default as usingApi} from './substrate/substrate-api';
+import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
+import privateKey from './substrate/privateKey';
 
 chai.use(chaiAsPromised);
 const expect = chai.expect;
 
-describe.skip('integration test: Inflation', () => {
+describe('integration test: Inflation', () => {
   it('First year inflation is 10%', async () => {
     await usingApi(async (api) => {
 
+      // Make sure non-sudo can't start inflation
+      const tx = api.tx.inflation.startInflation(1);
+      const bob = privateKey('//Bob');
+      await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;
+
+      // Start inflation on relay block 1 (Alice is sudo)
+      const alice = privateKey('//Alice');
+      const sudoTx = api.tx.sudo.sudo(tx as any);
+      await submitTransactionAsync(alice, sudoTx);
+
       const blockInterval = (api.consts.inflation.inflationBlockInterval).toBigInt();
       const totalIssuanceStart = (await api.query.inflation.startingYearTotalIssuance()).toBigInt();
       const blockInflation = (await api.query.inflation.blockInflation()).toBigInt();
 
-      // const YEAR = 5259600n;  // 6-second block. Blocks in one year
-      const YEAR = 2629800n; // 12-second block. Blocks in one year
+      const YEAR = 5259600n;  // 6-second block. Blocks in one year
+      // const YEAR = 2629800n; // 12-second block. Blocks in one year
 
       const totalExpectedInflation = totalIssuanceStart / 10n;
       const totalActualInflation = blockInflation * YEAR / blockInterval;
modifiedtests/src/pallet-presence.test.tsdiffbeforeafterboth
--- a/tests/src/pallet-presence.test.ts
+++ b/tests/src/pallet-presence.test.ts
@@ -34,7 +34,7 @@
   'polkadotxcm',
   'cumulusxcm',
   'dmpqueue',
-  //'inflation',
+  'inflation',
   'unique',
   'nonfungible',
   'refungible',