diff --git a/Cargo.lock b/Cargo.lock index e4008e878..bc3a77021 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5567,6 +5567,7 @@ dependencies = [ "pallet-xcm", "parity-scale-codec", "scale-info", + "sp-arithmetic", "sp-core", "sp-io", "sp-runtime", diff --git a/modules/homa-lite/Cargo.toml b/modules/homa-lite/Cargo.toml index c068f2ffb..52390ae56 100644 --- a/modules/homa-lite/Cargo.toml +++ b/modules/homa-lite/Cargo.toml @@ -10,6 +10,7 @@ scale-info = { version = "1.0", default-features = false, features = ["derive"] frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.12", default-features = false, optional = true} frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.12", default-features = false } frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.12", default-features = false } +sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.12", default-features = false } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.12", default-features = false } sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.12", default-features = false } sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.12", default-features = false } @@ -36,6 +37,7 @@ std = [ "frame-support/std", "frame-system/std", "scale-info/std", + "sp-arithmetic/std", "sp-runtime/std", "sp-core/std", "sp-std/std", @@ -49,5 +51,6 @@ runtime-benchmarks = [ "frame-benchmarking", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", ] try-runtime = ["frame-support/try-runtime"] diff --git a/modules/homa-lite/src/benchmarking.rs b/modules/homa-lite/src/benchmarking.rs index 07b318a4d..1be4a05ad 100644 --- a/modules/homa-lite/src/benchmarking.rs +++ b/modules/homa-lite/src/benchmarking.rs @@ -30,6 +30,21 @@ pub struct Module(crate::Pallet); const SEED: u32 = 0; benchmarks! { + on_initialize { + let _ = crate::Pallet::::set_staking_interest_rate_per_update( + RawOrigin::Root.into(), + Permill::from_percent(1) + ); + let _ = crate::Pallet::::set_total_staking_currency(RawOrigin::Root.into(), 1_000_000_000_000_000_000); + }: { + let _ = crate::Pallet::::on_initialize(::BlockNumber::default()); + } + + on_initialize_without_work {}: { + // interest rate is not calculated becasue `set_staking_interest_rate_per_update` is not called. + let _ = crate::Pallet::::on_initialize(::BlockNumber::default()); + } + mint { let amount = 1_000_000_000_000; let caller: T::AccountId = account("caller", 0, SEED); @@ -78,6 +93,7 @@ benchmarks! { replace_schedule_unbond {}: _(RawOrigin::Root, vec![(1_000_000, ::BlockNumber::default()), (1_000_000_000, ::BlockNumber::default())]) + set_staking_interest_rate_per_update {}: _(RawOrigin::Root, Permill::default()) redeem_with_available_staking_balance { let amount = 1_000_000_000_000_000; let caller: T::AccountId = account("caller", 0, SEED); @@ -99,6 +115,18 @@ mod tests { use crate::mock::*; use frame_support::assert_ok; + #[test] + fn test_on_initialize() { + ExtBuilder::default().build().execute_with(|| { + assert_ok!(Pallet::::test_benchmark_on_initialize()); + }); + } + #[test] + fn test_on_initialize_without_work() { + ExtBuilder::default().build().execute_with(|| { + assert_ok!(Pallet::::test_benchmark_on_initialize_without_work()); + }); + } #[test] fn test_mint() { ExtBuilder::default().build().execute_with(|| { @@ -160,6 +188,13 @@ mod tests { assert_ok!(Pallet::::test_benchmark_replace_schedule_unbond()); }); } + + #[test] + fn test_set_staking_interest_rate_per_update() { + ExtBuilder::default().build().execute_with(|| { + assert_ok!(Pallet::::test_benchmark_set_staking_interest_rate_per_update()); + }); + } #[test] fn test_redeem_with_available_staking_balance() { ExtBuilder::default().build().execute_with(|| { diff --git a/modules/homa-lite/src/lib.rs b/modules/homa-lite/src/lib.rs index 8e87285dc..7d6dc9a24 100644 --- a/modules/homa-lite/src/lib.rs +++ b/modules/homa-lite/src/lib.rs @@ -32,6 +32,7 @@ use orml_traits::{ arithmetic::Signed, BalanceStatus, MultiCurrency, MultiCurrencyExtended, MultiReservableCurrency, XcmTransfer, }; use primitives::{Balance, CurrencyId}; +use sp_arithmetic::traits::CheckedRem; use sp_runtime::{ traits::{BlockNumberProvider, Bounded, Saturating, Zero}, ArithmeticError, FixedPointNumber, Permill, @@ -138,6 +139,10 @@ pub mod module { /// Maximum number of scheduled unbonds allowed #[pallet::constant] type MaxScheduledUnbonds: Get; + + /// The number of blocks to pass before TotalStakingCurrency is updated. + #[pallet::constant] + type StakingUpdateFrequency: Get; } #[pallet::error] @@ -200,6 +205,9 @@ pub mod module { ///\[staking_amount_added\] ScheduledUnbondWithdrew(Balance), + /// Interest rate for TotalStakingCurrency is set + StakingInterestRatePerUpdateSet(Permill), + /// The amount of the staking currency available to be redeemed is set. /// \[total_available_staking_balance\] AvailableStakingBalanceSet(Balance), @@ -243,6 +251,12 @@ pub mod module { pub type ScheduledUnbond = StorageValue<_, BoundedVec<(Balance, RelayChainBlockNumberOf), T::MaxScheduledUnbonds>, ValueQuery>; + /// Every T::StakingUpdateFrequency blocks, TotalStakingCurrency gain interest by this rate. + /// StakingInterestRatePerUpdate: Value: Permill + #[pallet::storage] + #[pallet::getter(fn staking_interest_rate_per_update)] + pub type StakingInterestRatePerUpdate = StorageValue<_, Permill, ValueQuery>; + #[pallet::pallet] pub struct Pallet(_); @@ -287,6 +301,24 @@ pub mod module { current_weight } + + fn on_initialize(n: T::BlockNumber) -> Weight { + // Update the total amount of Staking balance by acrueing the interest periodically. + let interest_rate = Self::staking_interest_rate_per_update(); + if !interest_rate.is_zero() + && n.checked_rem(&T::StakingUpdateFrequency::get()) + .map_or(false, |n| n.is_zero()) + { + // Inflate the staking total by the interest rate. + // This will only fail when current TotalStakingCurrency is 0. In this case it is OK to fail. + let _ = Self::update_total_staking_currency_storage(|current| { + Ok(current.saturating_add(interest_rate.mul(current))) + }); + ::WeightInfo::on_initialize() + } else { + ::WeightInfo::on_initialize_without_work() + } + } } #[pallet::call] @@ -320,12 +352,7 @@ pub mod module { #[transactional] pub fn set_total_staking_currency(origin: OriginFor, staking_total: Balance) -> DispatchResult { T::GovernanceOrigin::ensure_origin(origin)?; - ensure!(!staking_total.is_zero(), Error::::InvalidTotalStakingCurrency); - - TotalStakingCurrency::::put(staking_total); - Self::deposit_event(Event::::TotalStakingCurrencySet(staking_total)); - - Ok(()) + Self::update_total_staking_currency_storage(|_n| Ok(staking_total)) } /// Adjusts the total_staking_currency by the given difference. @@ -355,16 +382,13 @@ pub mod module { ); // Adjust the current total. - TotalStakingCurrency::::mutate(|current| { - if by_amount.is_positive() { - *current = current.saturating_add(by_balance); + Self::update_total_staking_currency_storage(|current_staking_total| { + Ok(if by_amount.is_positive() { + current_staking_total.saturating_add(by_balance) } else { - *current = current.saturating_sub(by_balance); - } - Self::deposit_event(Event::::TotalStakingCurrencySet(*current)); - }); - - Ok(()) + current_staking_total.saturating_sub(by_balance) + }) + }) } /// Updates the cap for how much Staking currency can be used to Mint liquid currency. @@ -635,6 +659,25 @@ pub mod module { let _ = Self::process_redeem_requests_with_available_staking_balance(max_num_matches)?; Ok(()) } + + /// Set the interest rate for TotalStakingCurrency. + /// TotakStakingCurrency is incremented every `T::StakingUpdateFrequency` blocks + /// + /// Requires `T::GovernanceOrigin` + /// + /// Parameters: + /// - `interest_rate`: the new interest rate for TotalStakingCurrency. + #[pallet::weight(< T as Config >::WeightInfo::set_staking_interest_rate_per_update())] + #[transactional] + pub fn set_staking_interest_rate_per_update(origin: OriginFor, interest_rate: Permill) -> DispatchResult { + T::GovernanceOrigin::ensure_origin(origin)?; + + StakingInterestRatePerUpdate::::put(interest_rate); + + Self::deposit_event(Event::::StakingInterestRatePerUpdateSet(interest_rate)); + + Ok(()) + } } impl Pallet { @@ -810,16 +853,17 @@ pub mod module { liquid_to_mint = (Permill::one().saturating_sub(T::MaxRewardPerEra::get())).mul(liquid_to_mint); liquid_to_mint = Self::convert_staking_to_liquid(liquid_to_mint)?; - // Ensure the total amount staked doesn't exceed the cap. - let new_total_staking_currency = Self::total_staking_currency() - .checked_add(staking_remaining) - .ok_or(ArithmeticError::Overflow)?; - ensure!( - new_total_staking_currency <= Self::staking_currency_mint_cap(), - Error::::ExceededStakingCurrencyMintCap - ); - - TotalStakingCurrency::::put(new_total_staking_currency); + // Update staking total and ensure the new total doesn't exceed the cap. + Self::update_total_staking_currency_storage(|total_staking_currency| { + let new_total_staking_currency = total_staking_currency + .checked_add(staking_remaining) + .ok_or(ArithmeticError::Overflow)?; + ensure!( + new_total_staking_currency <= Self::staking_currency_mint_cap(), + Error::::ExceededStakingCurrencyMintCap + ); + Ok(new_total_staking_currency) + })?; // All checks pass. Proceed with Xcm transfer. T::XcmTransfer::transfer( @@ -894,7 +938,7 @@ pub mod module { ); let actual_staking_amount = Self::convert_liquid_to_staking(actual_liquid_amount)?; - TotalStakingCurrency::::mutate(|x| *x = x.saturating_sub(actual_staking_amount)); + Self::update_total_staking_currency_storage(|total| Ok(total.saturating_sub(actual_staking_amount)))?; // Redeem from the available_staking_balances costs only the xcm unbond fee. T::Currency::deposit( @@ -968,6 +1012,18 @@ pub mod module { Self::xcm_dest_weight(), ) } + + /// Helper function that update the storage of total_staking_currency and emit event. + fn update_total_staking_currency_storage( + f: impl FnOnce(Balance) -> Result, + ) -> DispatchResult { + TotalStakingCurrency::::try_mutate(|current| { + *current = f(*current)?; + ensure!(!current.is_zero(), Error::::InvalidTotalStakingCurrency); + Self::deposit_event(Event::::TotalStakingCurrencySet(*current)); + Ok(()) + }) + } } impl ExchangeRateProvider for Pallet { diff --git a/modules/homa-lite/src/mock.rs b/modules/homa-lite/src/mock.rs index 6e7cca5be..7f734fb4b 100644 --- a/modules/homa-lite/src/mock.rs +++ b/modules/homa-lite/src/mock.rs @@ -270,6 +270,7 @@ parameter_types! { pub const MaxScheduledUnbonds: u32 = 14; pub const SubAccountIndex: u16 = 0; pub ParachainId: ParaId = ParaId::from(PARACHAIN_ID); + pub const StakingUpdateFrequency: BlockNumber = 100; } ord_parameter_types! { pub const Root: AccountId = ROOT; @@ -306,6 +307,7 @@ impl Config for Runtime { type MaximumRedeemRequestMatchesForMint = MaximumRedeemRequestMatchesForMint; type RelayChainUnbondingSlashingSpans = RelayChainUnbondingSlashingSpans; type MaxScheduledUnbonds = MaxScheduledUnbonds; + type StakingUpdateFrequency = StakingUpdateFrequency; } type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; diff --git a/modules/homa-lite/src/tests.rs b/modules/homa-lite/src/tests.rs index 3f3fcdd3f..e973ac96d 100644 --- a/modules/homa-lite/src/tests.rs +++ b/modules/homa-lite/src/tests.rs @@ -429,6 +429,11 @@ fn on_idle_can_process_xcm_to_increase_available_staking_balance() { #[test] fn new_available_staking_currency_can_handle_redeem_requests() { ExtBuilder::default().build().execute_with(|| { + assert_ok!(HomaLite::set_total_staking_currency( + Origin::root(), + Currencies::total_issuance(LKSM) / 10 + )); + assert_ok!(HomaLite::replace_schedule_unbond( Origin::root(), vec![(dollar(1_000), 1)], @@ -453,13 +458,13 @@ fn new_available_staking_currency_can_handle_redeem_requests() { HomaLite::on_idle(MockRelayBlockNumberProvider::get(), 5_000_000_000); // All available staking currency should be redeemed, paying the `XcmUnbondFee` - assert_eq!(AvailableStakingBalance::::get(), 0); - assert_eq!(Currencies::free_balance(KSM, &ROOT), dollar(999)); + assert_eq!(AvailableStakingBalance::::get(), 1); // rounding error + assert_eq!(Currencies::free_balance(KSM, &ROOT), dollar(999) - 1); // rounding error assert_eq!(Currencies::free_balance(LKSM, &ROOT), dollar(989_000)); - assert_eq!(Currencies::reserved_balance(LKSM, &ROOT), dollar(989)); + assert_eq!(Currencies::reserved_balance(LKSM, &ROOT), dollar(98911) / 100); assert_eq!( RedeemRequests::::get(&ROOT), - Some((dollar(989), Permill::zero())) + Some((dollar(98911) / 100, Permill::zero())) ); // Add more redeem request @@ -479,6 +484,13 @@ fn new_available_staking_currency_can_handle_redeem_requests() { RedeemRequests::::get(&ALICE), Some((dollar(999), Permill::zero())) ); + + // Change the exchange rate to 1(S) : 10(L) + assert_ok!(HomaLite::set_total_staking_currency( + Origin::root(), + Currencies::total_issuance(LKSM) / 10 + )); + // Add more staking currency by adjust_available_staking_balance also // automatically fullfill pending redeem request. assert_ok!(HomaLite::adjust_available_staking_balance( @@ -488,8 +500,8 @@ fn new_available_staking_currency_can_handle_redeem_requests() { )); // The 2 remaining requests are redeemed, the leftover is stored. - // available_staking_remain = 200 - 98.9 - 99.9 = 1.2 - assert_eq!(AvailableStakingBalance::::get(), dollar(12) / 10); + // available_staking_remain = 200 - 99.9 - 98.911 = 1.189 + assert_eq!(AvailableStakingBalance::::get(), 1_189_000_000_001); assert_eq!(RedeemRequests::::get(&ALICE), None); assert_eq!(HomaLite::get_exchange_rate(), Ratio::saturating_from_rational(1, 10)); @@ -501,11 +513,12 @@ fn new_available_staking_currency_can_handle_redeem_requests() { assert_eq!(Currencies::free_balance(LKSM, &ALICE), 0); assert_eq!(Currencies::reserved_balance(LKSM, &ALICE), 0); - assert_eq!(RedeemRequests::::get(&ROOT), None); - // staking = 999(first redeem) + 98.9(this redeem) - 1(xcm_fee) = 1096.9 - assert_eq!(Currencies::free_balance(KSM, &ROOT), dollar(10_969) / 10); + // The last request is redeemed, the leftover is stored. + // staking = 999(first redeem) + 98.911(this redeem) - 1(xcm_fee) = 1096.911 (with rounding error) + assert_eq!(Currencies::free_balance(KSM, &ROOT), 1_096_910_999_999_999); assert_eq!(Currencies::free_balance(LKSM, &ROOT), dollar(989_000)); assert_eq!(Currencies::reserved_balance(LKSM, &ROOT), 0); + assert_eq!(RedeemRequests::::get(&ROOT), None); }); } @@ -514,6 +527,11 @@ fn new_available_staking_currency_can_handle_redeem_requests() { #[test] fn on_idle_can_handle_changes_in_exchange_rate() { ExtBuilder::default().build().execute_with(|| { + assert_ok!(HomaLite::set_total_staking_currency( + Origin::root(), + Currencies::total_issuance(LKSM) / 10 + )); + // When redeem was requested, 100_000 is redeemed to 10_000 staking currency assert_ok!(HomaLite::request_redeem( Origin::signed(ROOT), @@ -636,13 +654,25 @@ fn request_redeem_can_handle_dust_redeem_requests() { // on_idle can handle dust redeem requests #[test] fn on_idle_can_handle_dust_redeem_requests() { - ExtBuilder::default().build().execute_with(|| { - // Test that on_idle doesn't add dust redeem requests into the queue. + ExtBuilder::empty().build().execute_with(|| { + assert_ok!(Currencies::update_balance( + Origin::root(), + ALICE, + LKSM, + dollar(500_501) as i128 + )); + + // This amount will leave a dust after redeem assert_ok!(HomaLite::request_redeem( - Origin::signed(ROOT), - dollar(500_010), + Origin::signed(ALICE), + dollar(500_501), Permill::zero() )); + assert_ok!(HomaLite::set_total_staking_currency( + Origin::root(), + Currencies::total_issuance(LKSM) / 10 + )); + assert_ok!(HomaLite::replace_schedule_unbond( Origin::root(), vec![(dollar(50_000), 2)], @@ -650,11 +680,12 @@ fn on_idle_can_handle_dust_redeem_requests() { MockRelayBlockNumberProvider::set(2); HomaLite::on_idle(MockRelayBlockNumberProvider::get(), 5_000_000_000); - assert_eq!(AvailableStakingBalance::::get(), 49_001_000_000_000); - assert_eq!(Currencies::free_balance(KSM, &ROOT), 49_949_999_000_000_000); - assert_eq!(Currencies::free_balance(LKSM, &ROOT), dollar(499_990)); - assert_eq!(Currencies::reserved_balance(LKSM, &ROOT), 0); - assert_eq!(RedeemRequests::::get(&ROOT), None); + assert_eq!(AvailableStakingBalance::::get(), 0); + assert_eq!(Currencies::free_balance(KSM, &ALICE), dollar(49_999)); + // Dust amount is un-reserved and returned to the user + assert_eq!(Currencies::free_balance(LKSM, &ALICE), 499_000_000_000); + assert_eq!(Currencies::reserved_balance(LKSM, &ALICE), 0); + assert_eq!(RedeemRequests::::get(&ALICE), None); }); } @@ -966,6 +997,71 @@ fn redeem_can_handle_dust_available_staking_currency() { }); } +#[test] +fn total_staking_currency_update_periodically() { + ExtBuilder::default().build().execute_with(|| { + assert_ok!(HomaLite::set_total_staking_currency(Origin::root(), dollar(1_000_000))); + + let on_initialize_weight = ::WeightInfo::on_initialize(); + let on_initialize_without_work_weight = ::WeightInfo::on_initialize_without_work(); + + // Interst rate isn't set yet - no interest rate calculation is done. + assert_eq!(HomaLite::on_initialize(0), on_initialize_without_work_weight); + // Default inflation rate is 0% + assert_eq!(TotalStakingCurrency::::get(), dollar(1_000_000)); + + for i in 1..100 { + assert_eq!(HomaLite::on_initialize(i), on_initialize_without_work_weight); + } + // Interst rate isn't set yet - no interest rate calculation is done. + assert_eq!(HomaLite::on_initialize(0), on_initialize_without_work_weight); + assert_eq!(TotalStakingCurrency::::get(), dollar(1_000_000)); + + // Interest rate can only be set by governance + assert_noop!( + HomaLite::set_staking_interest_rate_per_update(Origin::signed(ALICE), Permill::from_percent(1)), + BadOrigin + ); + assert_ok!(HomaLite::set_staking_interest_rate_per_update( + Origin::root(), + Permill::from_percent(1) + )); + System::assert_last_event(Event::HomaLite(crate::Event::StakingInterestRatePerUpdateSet( + Permill::from_percent(1), + ))); + + for i in 101..200 { + assert_eq!(HomaLite::on_initialize(i), on_initialize_without_work_weight); + } + assert_eq!(HomaLite::on_initialize(200), on_initialize_weight); + // Inflate by 1%: 1_000_000 * 1.01 + assert_eq!(TotalStakingCurrency::::get(), dollar(1_010_000)); + System::assert_last_event(Event::HomaLite(crate::Event::TotalStakingCurrencySet(dollar( + 1_010_000, + )))); + + for i in 201..300 { + assert_eq!(HomaLite::on_initialize(i), on_initialize_without_work_weight); + } + assert_eq!(HomaLite::on_initialize(300), on_initialize_weight); + // 1_010_000 * 1.01 + assert_eq!(TotalStakingCurrency::::get(), dollar(1_020_100)); + System::assert_last_event(Event::HomaLite(crate::Event::TotalStakingCurrencySet(dollar( + 1_020_100, + )))); + + for i in 301..400 { + assert_eq!(HomaLite::on_initialize(i), on_initialize_without_work_weight); + } + assert_eq!(HomaLite::on_initialize(400), on_initialize_weight); + //1_020_100 * 1.01 + assert_eq!(TotalStakingCurrency::::get(), dollar(1_030_301)); + System::assert_last_event(Event::HomaLite(crate::Event::TotalStakingCurrencySet(dollar( + 1_030_301, + )))); + }); +} + #[test] fn process_scheduled_unbond_with_multiple_requests() { ExtBuilder::empty().build().execute_with(|| { @@ -1300,16 +1396,20 @@ fn available_staking_balances_can_handle_rounding_error_dust() { assert_eq!(HomaLite::available_staking_balance(), 1); let events = System::events(); assert_eq!( - events[events.len() - 3].event, + events[events.len() - 4].event, Event::HomaLite(crate::Event::ScheduledUnbondWithdrew(999_999_999_999)) ); + assert_eq!( + events[events.len() - 3].event, + Event::HomaLite(crate::Event::TotalStakingCurrencySet(999_237_000_000_002)) + ); assert_eq!( events[events.len() - 2].event, - Event::Tokens(orml_tokens::Event::Unreserved(LKSM, ALICE, 9987632930985)) + Event::Tokens(orml_tokens::Event::Unreserved(LKSM, ALICE, 9_987_632_930_985)) ); assert_eq!( events[events.len() - 1].event, - Event::HomaLite(crate::Event::Redeemed(ALICE, 999999999998, 9987632930985)) + Event::HomaLite(crate::Event::Redeemed(ALICE, 999_999_999_998, 9_987_632_930_985)) ); }); } diff --git a/modules/homa-lite/src/weights.rs b/modules/homa-lite/src/weights.rs index a027b88e6..0f2bacaa1 100644 --- a/modules/homa-lite/src/weights.rs +++ b/modules/homa-lite/src/weights.rs @@ -19,13 +19,13 @@ //! Autogenerated weights for module_homa_lite //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2021-11-01, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 +//! DATE: 2021-11-03, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("karura-dev"), DB CACHE: 128 // Executed Command: // target/release/acala // benchmark -// --chain=dev +// --chain=karura-dev // --steps=50 // --repeat=20 // --pallet=module-homa-lite @@ -47,6 +47,8 @@ use sp_std::marker::PhantomData; /// Weight functions needed for module_homa_lite. pub trait WeightInfo { + fn on_initialize() -> Weight; + fn on_initialize_without_work() -> Weight; fn mint() -> Weight; fn mint_for_requests() -> Weight; fn set_total_staking_currency() -> Weight; @@ -57,6 +59,7 @@ pub trait WeightInfo { fn request_redeem() -> Weight; fn schedule_unbond() -> Weight; fn replace_schedule_unbond() -> Weight; + fn set_staking_interest_rate_per_update() -> Weight; fn redeem_with_available_staking_balance() -> Weight; fn xcm_unbond() -> Weight; } @@ -64,18 +67,28 @@ pub trait WeightInfo { /// Weights for module_homa_lite using the Acala node and recommended hardware. pub struct AcalaWeight(PhantomData); impl WeightInfo for AcalaWeight { + fn on_initialize() -> Weight { + (13_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn on_initialize_without_work() -> Weight { + (2_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + } fn mint() -> Weight { - (138_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(14 as Weight)) - .saturating_add(T::DbWeight::get().writes(7 as Weight)) + (139_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(17 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn mint_for_requests() -> Weight { - (348_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(30 as Weight)) - .saturating_add(T::DbWeight::get().writes(21 as Weight)) + (145_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(19 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn set_total_staking_currency() -> Weight { - (11_000_000 as Weight) + (12_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn adjust_total_staking_currency() -> Weight { @@ -84,58 +97,72 @@ impl WeightInfo for AcalaWeight { .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn adjust_available_staking_balance_with_no_matches() -> Weight { - (17_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) + (11_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn set_minting_cap() -> Weight { - (11_000_000 as Weight) + (10_000_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn set_xcm_dest_weight() -> Weight { - (11_000_000 as Weight) + (10_000_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn request_redeem() -> Weight { - (82_000_000 as Weight) + (73_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn schedule_unbond() -> Weight { - (13_000_000 as Weight) + (12_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn replace_schedule_unbond() -> Weight { - (11_000_000 as Weight) + (10_000_000 as Weight) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn set_staking_interest_rate_per_update() -> Weight { + (10_000_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn redeem_with_available_staking_balance() -> Weight { - (6_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) + (8_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn xcm_unbond() -> Weight { - (24_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(5 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + (32_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(8 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) } } // For backwards compatibility and tests impl WeightInfo for () { + fn on_initialize() -> Weight { + (13_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } + fn on_initialize_without_work() -> Weight { + (2_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(1 as Weight)) + } fn mint() -> Weight { - (138_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(14 as Weight)) - .saturating_add(RocksDbWeight::get().writes(7 as Weight)) + (139_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(17 as Weight)) + .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } fn mint_for_requests() -> Weight { - (348_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(30 as Weight)) - .saturating_add(RocksDbWeight::get().writes(21 as Weight)) + (145_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(19 as Weight)) + .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } fn set_total_staking_currency() -> Weight { - (11_000_000 as Weight) + (12_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn adjust_total_staking_currency() -> Weight { @@ -144,40 +171,44 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn adjust_available_staking_balance_with_no_matches() -> Weight { - (17_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + (11_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn set_minting_cap() -> Weight { - (11_000_000 as Weight) + (10_000_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn set_xcm_dest_weight() -> Weight { - (11_000_000 as Weight) + (10_000_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn request_redeem() -> Weight { - (82_000_000 as Weight) + (73_000_000 as Weight) .saturating_add(RocksDbWeight::get().reads(7 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } fn schedule_unbond() -> Weight { - (13_000_000 as Weight) + (12_000_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn replace_schedule_unbond() -> Weight { - (11_000_000 as Weight) + (10_000_000 as Weight) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } + fn set_staking_interest_rate_per_update() -> Weight { + (10_000_000 as Weight) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn redeem_with_available_staking_balance() -> Weight { - (6_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + (8_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn xcm_unbond() -> Weight { - (24_000_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(5 as Weight)) - .saturating_add(RocksDbWeight::get().writes(2 as Weight)) + (32_000_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(8 as Weight)) + .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } } diff --git a/runtime/acala/src/lib.rs b/runtime/acala/src/lib.rs index 1d380fa17..67abeb76c 100644 --- a/runtime/acala/src/lib.rs +++ b/runtime/acala/src/lib.rs @@ -1547,6 +1547,7 @@ parameter_types! { pub SubAccountIndex: u16 = RelayChainSubAccountId::HomaLite as u16; pub const XcmUnbondFee: Balance = 600_000_000; // TODO identify unbond fee } + impl module_homa_lite::Config for Runtime { type Event = Event; type WeightInfo = weights::module_homa_lite::WeightInfo; @@ -1570,6 +1571,7 @@ impl module_homa_lite::Config for Runtime { type MaximumRedeemRequestMatchesForMint = MaximumRedeemRequestMatchesForMint; type RelayChainUnbondingSlashingSpans = RelayChainUnbondingSlashingSpans; type MaxScheduledUnbonds = MaxScheduledUnbonds; + type StakingUpdateFrequency = OneDay; } pub type LocalAssetTransactor = MultiCurrencyAdapter< diff --git a/runtime/acala/src/weights/module_homa_lite.rs b/runtime/acala/src/weights/module_homa_lite.rs index 592f8c022..552697ce4 100644 --- a/runtime/acala/src/weights/module_homa_lite.rs +++ b/runtime/acala/src/weights/module_homa_lite.rs @@ -19,7 +19,7 @@ //! Autogenerated weights for module_homa_lite //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2021-10-22, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2021-11-03, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("acala-dev"), DB CACHE: 128 // Executed Command: @@ -47,28 +47,38 @@ use sp_std::marker::PhantomData; /// Weight functions for module_homa_lite. pub struct WeightInfo(PhantomData); impl module_homa_lite::WeightInfo for WeightInfo { + fn on_initialize() -> Weight { + (12_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn on_initialize_without_work() -> Weight { + (2_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + } fn mint() -> Weight { - (134_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(14 as Weight)) - .saturating_add(T::DbWeight::get().writes(7 as Weight)) + (136_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(17 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn mint_for_requests() -> Weight { - (342_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(30 as Weight)) - .saturating_add(T::DbWeight::get().writes(21 as Weight)) + (325_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(33 as Weight)) + .saturating_add(T::DbWeight::get().writes(22 as Weight)) } fn set_total_staking_currency() -> Weight { - (10_000_000 as Weight) + (11_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn adjust_total_staking_currency() -> Weight { - (12_000_000 as Weight) + (11_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn adjust_available_staking_balance_with_no_matches() -> Weight { - (17_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) + (11_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn set_minting_cap() -> Weight { @@ -80,25 +90,31 @@ impl module_homa_lite::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn request_redeem() -> Weight { - (74_000_000 as Weight) + (73_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn schedule_unbond() -> Weight { - (13_000_000 as Weight) + (12_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn replace_schedule_unbond() -> Weight { - (11_000_000 as Weight) + (10_000_000 as Weight) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn set_staking_interest_rate_per_update() -> Weight { + (10_000_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn redeem_with_available_staking_balance() -> Weight { - (21_316_000 as Weight) + (7_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn xcm_unbond() -> Weight { - (21_316_000 as Weight) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + (32_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(8 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) } } diff --git a/runtime/integration-tests/src/homa_lite.rs b/runtime/integration-tests/src/homa_lite.rs index 6d53582a7..0c3c8850e 100644 --- a/runtime/integration-tests/src/homa_lite.rs +++ b/runtime/integration-tests/src/homa_lite.rs @@ -19,7 +19,7 @@ //! Tests the Homa-lite module, and its cross-chain functionalities. use crate::setup::*; -use frame_support::{assert_noop, assert_ok}; +use frame_support::{assert_noop, assert_ok, traits::Hooks}; use module_support::ExchangeRateProvider; use orml_traits::{MultiCurrency, MultiReservableCurrency}; @@ -313,6 +313,68 @@ fn homa_lite_mint_and_redeem() { }); } +#[test] +fn liquid_value_goes_up_periodically() { + ExtBuilder::default() + .balances(vec![(alice(), LIQUID_CURRENCY, 10_000_000 * dollar(LIQUID_CURRENCY))]) + .build() + .execute_with(|| { + assert_ok!(HomaLite::set_total_staking_currency( + Origin::root(), + 1_000_000 * dollar(RELAY_CHAIN_CURRENCY) + )); + assert_ok!(HomaLite::set_staking_interest_rate_per_update( + Origin::root(), + Permill::from_rational(383u32, 1_000_000u32) + )); + + let rate1 = HomaLite::get_exchange_rate(); + + HomaLite::on_initialize(0); + // Inflate by 1.000383 every 1 day (14400 blocks) + // 1_000_000 * 1.000383 = 1_000_383 + assert_eq!( + HomaLite::total_staking_currency(), + 1_000_383 * dollar(RELAY_CHAIN_CURRENCY) + ); + let rate2 = HomaLite::get_exchange_rate(); + assert!(rate2 > rate1); + + for i in 1..14401 { + HomaLite::on_initialize(i); + } + // 1_000_383 * 1.000383 = 1000766.14669 (with rounding error) + #[cfg(feature = "with-mandala-runtime")] + assert_eq!(HomaLite::total_staking_currency(), 10_007_661_466_890_000); + + // Karura ias 12 sec block time + // 1_000_383 * 1.000383 * 1.000383 = 1001149.440123181887 + #[cfg(feature = "with-karura-runtime")] + assert_eq!(HomaLite::total_staking_currency(), 1_001_149_440_123_181_887); + #[cfg(feature = "with-acala-runtime")] + assert_eq!(HomaLite::total_staking_currency(), 10_011_494_401_231_819); + + let rate3 = HomaLite::get_exchange_rate(); + assert!(rate3 > rate2); + + for i in 14401..28802 { + HomaLite::on_initialize(i); + } + // 1000766.146689 * 1.000383 = 1.001149440123181887 + #[cfg(feature = "with-mandala-runtime")] + assert_eq!(HomaLite::total_staking_currency(), 10_011_494_401_231_819); + + // 1001149.440123181887 * 1.000383 * 1.000383 = 1001916.46745192646655 + #[cfg(feature = "with-karura-runtime")] + assert_eq!(HomaLite::total_staking_currency(), 1_001_916_467_451_926_467); + #[cfg(feature = "with-acala-runtime")] + assert_eq!(HomaLite::total_staking_currency(), 10_019_164_674_519_265); + + let rate4 = HomaLite::get_exchange_rate(); + assert!(rate4 > rate3); + }); +} + #[cfg(feature = "with-karura-runtime")] mod karura_only_tests { use crate::relaychain::kusama_test_net::*; diff --git a/runtime/karura/src/lib.rs b/runtime/karura/src/lib.rs index 237b08d74..791b6d162 100644 --- a/runtime/karura/src/lib.rs +++ b/runtime/karura/src/lib.rs @@ -1610,6 +1610,7 @@ impl module_homa_lite::Config for Runtime { type MaximumRedeemRequestMatchesForMint = MaximumRedeemRequestMatchesForMint; type RelayChainUnbondingSlashingSpans = RelayChainUnbondingSlashingSpans; type MaxScheduledUnbonds = MaxScheduledUnbonds; + type StakingUpdateFrequency = OneDay; } pub type LocalAssetTransactor = MultiCurrencyAdapter< diff --git a/runtime/karura/src/weights/module_homa_lite.rs b/runtime/karura/src/weights/module_homa_lite.rs index 300ec0565..e780091f2 100644 --- a/runtime/karura/src/weights/module_homa_lite.rs +++ b/runtime/karura/src/weights/module_homa_lite.rs @@ -19,7 +19,7 @@ //! Autogenerated weights for module_homa_lite //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2021-11-01, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2021-11-03, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("karura-dev"), DB CACHE: 128 // Executed Command: @@ -47,32 +47,42 @@ use sp_std::marker::PhantomData; /// Weight functions for module_homa_lite. pub struct WeightInfo(PhantomData); impl module_homa_lite::WeightInfo for WeightInfo { + fn on_initialize() -> Weight { + (12_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn on_initialize_without_work() -> Weight { + (2_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + } fn mint() -> Weight { - (144_000_000 as Weight) + (137_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(17 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn mint_for_requests() -> Weight { - (153_000_000 as Weight) + (145_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(19 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn set_total_staking_currency() -> Weight { - (10_000_000 as Weight) + (12_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn adjust_total_staking_currency() -> Weight { - (12_000_000 as Weight) + (11_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn adjust_available_staking_balance_with_no_matches() -> Weight { - (12_000_000 as Weight) + (11_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn set_minting_cap() -> Weight { - (11_000_000 as Weight) + (10_000_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn set_xcm_dest_weight() -> Weight { @@ -80,7 +90,7 @@ impl module_homa_lite::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn request_redeem() -> Weight { - (81_000_000 as Weight) + (73_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } @@ -90,16 +100,20 @@ impl module_homa_lite::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn replace_schedule_unbond() -> Weight { - (11_000_000 as Weight) + (10_000_000 as Weight) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn set_staking_interest_rate_per_update() -> Weight { + (10_000_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn redeem_with_available_staking_balance() -> Weight { - (6_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) + (7_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn xcm_unbond() -> Weight { - (34_000_000 as Weight) + (32_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index b4a699142..a2e40ffbe 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -1319,6 +1319,7 @@ impl module_homa_lite::Config for Runtime { type MaximumRedeemRequestMatchesForMint = MaximumRedeemRequestMatchesForMint; type RelayChainUnbondingSlashingSpans = RelayChainUnbondingSlashingSpans; type MaxScheduledUnbonds = MaxScheduledUnbonds; + type StakingUpdateFrequency = OneDay; } parameter_types! { diff --git a/runtime/mandala/src/weights/module_homa_lite.rs b/runtime/mandala/src/weights/module_homa_lite.rs index ec32809a0..8a8a54887 100644 --- a/runtime/mandala/src/weights/module_homa_lite.rs +++ b/runtime/mandala/src/weights/module_homa_lite.rs @@ -19,7 +19,7 @@ //! Autogenerated weights for module_homa_lite //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2021-10-22, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2021-11-03, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: @@ -47,58 +47,74 @@ use sp_std::marker::PhantomData; /// Weight functions for module_homa_lite. pub struct WeightInfo(PhantomData); impl module_homa_lite::WeightInfo for WeightInfo { + fn on_initialize() -> Weight { + (13_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn on_initialize_without_work() -> Weight { + (2_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + } fn mint() -> Weight { - (137_000_000 as Weight) + (131_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(14 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } fn mint_for_requests() -> Weight { - (345_000_000 as Weight) + (320_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(30 as Weight)) .saturating_add(T::DbWeight::get().writes(21 as Weight)) } fn set_total_staking_currency() -> Weight { - (11_000_000 as Weight) + (12_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn adjust_total_staking_currency() -> Weight { - (13_000_000 as Weight) + (11_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn adjust_available_staking_balance_with_no_matches() -> Weight { - (18_000_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) + (11_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn set_minting_cap() -> Weight { - (11_000_000 as Weight) + (10_000_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn set_xcm_dest_weight() -> Weight { - (11_000_000 as Weight) + (10_000_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn request_redeem() -> Weight { - (77_000_000 as Weight) + (74_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn schedule_unbond() -> Weight { - (14_000_000 as Weight) + (12_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn replace_schedule_unbond() -> Weight { - (11_000_000 as Weight) + (10_000_000 as Weight) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn set_staking_interest_rate_per_update() -> Weight { + (10_000_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn redeem_with_available_staking_balance() -> Weight { - (21_316_000 as Weight) + (8_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn xcm_unbond() -> Weight { - (21_316_000 as Weight) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + (22_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) } }