diff --git a/Cargo.lock b/Cargo.lock index 64f309b659..c176529f70 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -659,6 +659,7 @@ name = "bifrost-flexible-fee" version = "0.8.0" dependencies = [ "cumulus-primitives-core", + "frame-benchmarking", "frame-support", "frame-system", "node-primitives", @@ -710,6 +711,7 @@ version = "0.8.0" dependencies = [ "bifrost-vtoken-mint", "fixed", + "frame-benchmarking", "frame-support", "frame-system", "node-primitives", @@ -892,6 +894,7 @@ name = "bifrost-vtoken-mint" version = "0.8.0" dependencies = [ "bifrost-minter-reward", + "frame-benchmarking", "frame-support", "frame-system", "node-primitives", diff --git a/node/service/src/chain_spec/asgard.rs b/node/service/src/chain_spec/asgard.rs index 6c77f707a9..b306b85c1e 100644 --- a/node/service/src/chain_spec/asgard.rs +++ b/node/service/src/chain_spec/asgard.rs @@ -216,10 +216,14 @@ fn local_config_genesis(id: ParaId) -> GenesisConfig { .flat_map(|x| { vec![ (x.clone(), CurrencyId::Stable(TokenSymbol::AUSD), ENDOWMENT * 10_000), - (x.clone(), CurrencyId::Token(TokenSymbol::DOT), ENDOWMENT * 4_000_000), (x.clone(), CurrencyId::VSToken(TokenSymbol::DOT), ENDOWMENT * 4_000_000), - (x.clone(), CurrencyId::Token(TokenSymbol::ETH), ENDOWMENT), - (x.clone(), CurrencyId::Token(TokenSymbol::KSM), ENDOWMENT), + (x.clone(), CurrencyId::VToken(TokenSymbol::DOT), ENDOWMENT * 4_000_000), + (x.clone(), CurrencyId::Token(TokenSymbol::DOT), ENDOWMENT * 4_000_000), + (x.clone(), CurrencyId::Token(TokenSymbol::ETH), ENDOWMENT * 4_000_000), + (x.clone(), CurrencyId::Token(TokenSymbol::KSM), ENDOWMENT * 4_000_000), + (x.clone(), CurrencyId::Token(TokenSymbol::ASG), ENDOWMENT * 4_000_000), + (x.clone(), CurrencyId::Token(TokenSymbol::AUSD), ENDOWMENT * 4_000_000), + (x.clone(), CurrencyId::Token(TokenSymbol::BNC), ENDOWMENT * 4_000_000), ] }) .collect(); diff --git a/pallets/flexible-fee/Cargo.toml b/pallets/flexible-fee/Cargo.toml index 07f598d8c8..484624df01 100644 --- a/pallets/flexible-fee/Cargo.toml +++ b/pallets/flexible-fee/Cargo.toml @@ -15,6 +15,7 @@ sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false } zenlink-protocol = { version = "*", default-features = false } orml-traits = { version = "0.4.1-dev", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false, optional = true } [dev-dependencies] orml-tokens = { version = "0.4.1-dev" } @@ -39,3 +40,9 @@ std = [ "sp-arithmetic/std", "orml-traits/std", ] + +runtime-benchmarks = [ + "frame-benchmarking", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", +] diff --git a/pallets/flexible-fee/src/benchmarking.rs b/pallets/flexible-fee/src/benchmarking.rs new file mode 100644 index 0000000000..2f1e15c3c3 --- /dev/null +++ b/pallets/flexible-fee/src/benchmarking.rs @@ -0,0 +1,42 @@ +// This file is part of Bifrost. + +// Copyright (C) 2019-2021 Liebi Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#![cfg(feature = "runtime-benchmarks")] + +use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller}; +use frame_system::RawOrigin; +use node_primitives::{CurrencyId, TokenSymbol}; + +use super::*; +#[allow(unused_imports)] +use crate::Pallet as FlexibleFee; + +benchmarks! { + set_user_fee_charge_order { + let order_vec = vec![CurrencyId::Token(TokenSymbol::try_from(0u8).unwrap_or_default())]; + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller), Some(order_vec)) +} + +impl_benchmark_test_suite!( + FlexibleFee, + crate::mock::ExtBuilder::default() + .one_hundred_precision_for_each_currency_type_for_whitelist_account() + .build(), + crate::mock::Test +); diff --git a/pallets/flexible-fee/src/fee_dealer.rs b/pallets/flexible-fee/src/fee_dealer.rs index 8a263315aa..49549e4e59 100644 --- a/pallets/flexible-fee/src/fee_dealer.rs +++ b/pallets/flexible-fee/src/fee_dealer.rs @@ -19,8 +19,6 @@ // The swap pool algorithm implements Balancer protocol // For more details, refer to https://balancer.finance/whitepaper/ -#![cfg_attr(not(feature = "std"), no_std)] - use sp_runtime::traits::UniqueSaturatedFrom; use super::*; diff --git a/pallets/flexible-fee/src/lib.rs b/pallets/flexible-fee/src/lib.rs index 842a0b199f..8a142692a0 100644 --- a/pallets/flexible-fee/src/lib.rs +++ b/pallets/flexible-fee/src/lib.rs @@ -29,7 +29,6 @@ use frame_support::{ Currency, ExistenceRequirement, Get, Imbalance, OnUnbalanced, ReservableCurrency, WithdrawReasons, }, - weights::Weight, }; use frame_system::pallet_prelude::*; use node_primitives::{CurrencyId, TokenSymbol}; @@ -42,23 +41,22 @@ use sp_runtime::{ transaction_validity::TransactionValidityError, }; use sp_std::{vec, vec::Vec}; +pub use weights::WeightInfo; use zenlink_protocol::{AssetBalance, AssetId, ExportZenlink}; use crate::fee_dealer::FeeDealer; -mod default_weight; +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; pub mod fee_dealer; mod mock; mod tests; +mod weights; type CurrencyIdOf = <::MultiCurrency as MultiCurrency< ::AccountId, >>::CurrencyId; -pub trait WeightInfo { - fn set_user_fee_charge_order() -> Weight; -} - #[frame_support::pallet] pub mod pallet { use super::*; diff --git a/pallets/flexible-fee/src/mock.rs b/pallets/flexible-fee/src/mock.rs index b5a3b6075c..bef0c5a2ce 100644 --- a/pallets/flexible-fee/src/mock.rs +++ b/pallets/flexible-fee/src/mock.rs @@ -22,6 +22,8 @@ use std::convert::TryInto; // pub use polkadot_parachain::primitives::Id; pub use cumulus_primitives_core::ParaId; +#[cfg(feature = "runtime-benchmarks")] +use frame_benchmarking::whitelisted_caller; use frame_support::{ parameter_types, weights::{IdentityFee, WeightToFeeCoefficients, WeightToFeePolynomial}, @@ -44,6 +46,7 @@ use crate as flexible_fee; // use node_primitives::Balance; use crate::fee_dealer::FixedCurrencyFeeRate; +pub type AccountId = AccountId32; pub type BlockNumber = u64; pub type Amount = i128; @@ -279,6 +282,55 @@ where } } +#[cfg(feature = "runtime-benchmarks")] +pub struct ExtBuilder { + endowed_accounts: Vec<(AccountId, CurrencyId, Balance)>, +} + +#[cfg(feature = "runtime-benchmarks")] +impl Default for ExtBuilder { + fn default() -> Self { + Self { endowed_accounts: vec![] } + } +} + +#[cfg(feature = "runtime-benchmarks")] +impl ExtBuilder { + pub fn balances(mut self, endowed_accounts: Vec<(AccountId32, CurrencyId, Balance)>) -> Self { + self.endowed_accounts = endowed_accounts; + self + } + + pub fn one_hundred_precision_for_each_currency_type_for_whitelist_account(self) -> Self { + let whitelist_caller: AccountId32 = whitelisted_caller(); + let c0 = CurrencyId::Token(TokenSymbol::try_from(0u8).unwrap_or_default()); + let c1 = CurrencyId::Token(TokenSymbol::try_from(1u8).unwrap_or_default()); + let c2 = CurrencyId::Token(TokenSymbol::try_from(2u8).unwrap_or_default()); + let c3 = CurrencyId::Token(TokenSymbol::try_from(3u8).unwrap_or_default()); + let c4 = CurrencyId::Token(TokenSymbol::try_from(4u8).unwrap_or_default()); + let c5 = CurrencyId::Token(TokenSymbol::try_from(5u8).unwrap_or_default()); + + self.balances(vec![ + (whitelist_caller.clone(), c0, 100_000_000_000_000), + (whitelist_caller.clone(), c1, 100_000_000_000_000), + (whitelist_caller.clone(), c2, 100_000_000_000_000), + (whitelist_caller.clone(), c3, 100_000_000_000_000), + (whitelist_caller.clone(), c4, 100_000_000_000_000), + (whitelist_caller.clone(), c5, 100_000_000_000_000), + ]) + } + + pub fn build(self) -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + + orml_tokens::GenesisConfig:: { balances: self.endowed_accounts } + .assimilate_storage(&mut t) + .unwrap(); + + t.into() + } +} + // Build genesis storage according to the mock runtime. pub(crate) fn new_test_ext() -> sp_io::TestExternalities { system::GenesisConfig::default().build_storage::().unwrap().into() diff --git a/pallets/flexible-fee/src/default_weight.rs b/pallets/flexible-fee/src/weights.rs similarity index 91% rename from pallets/flexible-fee/src/default_weight.rs rename to pallets/flexible-fee/src/weights.rs index f365328827..6995b4f474 100644 --- a/pallets/flexible-fee/src/default_weight.rs +++ b/pallets/flexible-fee/src/weights.rs @@ -22,8 +22,12 @@ use frame_support::weights::{constants::RocksDbWeight as DbWeight, Weight}; +pub trait WeightInfo { + fn set_user_fee_charge_order() -> Weight; +} + impl crate::WeightInfo for () { fn set_user_fee_charge_order() -> Weight { - 102 as Weight + 50_000_000 as Weight } } diff --git a/pallets/minter-reward/Cargo.toml b/pallets/minter-reward/Cargo.toml index cbffa1b91e..9f63b79452 100644 --- a/pallets/minter-reward/Cargo.toml +++ b/pallets/minter-reward/Cargo.toml @@ -13,6 +13,7 @@ frame-system = { version = "3.0.0", default-features = false } orml-traits = { version = "0.4.1-dev", default-features = false } sp-runtime = { version = "3.0.0", default-features = false } zenlink-protocol = { version = "*", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false, optional = true } [dev-dependencies] orml-tokens = "0.4.1-dev" @@ -33,4 +34,10 @@ std = [ "orml-traits/std", "sp-runtime/std", "zenlink-protocol/std" +] + +runtime-benchmarks = [ + "frame-benchmarking", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", ] \ No newline at end of file diff --git a/pallets/minter-reward/src/benchmarking.rs b/pallets/minter-reward/src/benchmarking.rs new file mode 100644 index 0000000000..bfcc45b7de --- /dev/null +++ b/pallets/minter-reward/src/benchmarking.rs @@ -0,0 +1,54 @@ +// This file is part of Bifrost. + +// Copyright (C) 2019-2021 Liebi Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#![cfg(feature = "runtime-benchmarks")] + +use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller}; +use frame_system::RawOrigin; +use node_primitives::{CurrencyId, TokenSymbol}; +use sp_runtime::traits::UniqueSaturatedFrom; + +use super::*; +#[allow(unused_imports)] +use crate::Pallet as MinterReward; + +benchmarks! { + claim_reward { + let caller: T::AccountId = whitelisted_caller(); + UserReward::::insert(caller.clone(), BalanceOf::::unique_saturated_from(10 as u128)); + }: _(RawOrigin::Signed(caller)) + + on_initialize { + let block_num = T::BlockNumber::from(120u32); + CurrentRoundStartAt::::set(T::BlockNumber::from(100u32)); + + let max_mint = (T::BlockNumber::from(111u32), BalanceOf::::unique_saturated_from(100 as u128), CurrencyId::Token(TokenSymbol::DOT)); + MaximumVtokenMinted::::set(max_mint); + + + }:{MinterReward::::on_initialize(block_num);} + +} + +impl_benchmark_test_suite!( + MinterReward, + crate::mock::ExtBuilder::default() + .one_hundred_precision_for_each_currency_type_for_whitelist_account() + .build(), + crate::mock::Runtime +); diff --git a/pallets/minter-reward/src/lib.rs b/pallets/minter-reward/src/lib.rs index 1f1930afea..ec1c1d2c51 100644 --- a/pallets/minter-reward/src/lib.rs +++ b/pallets/minter-reward/src/lib.rs @@ -25,12 +25,16 @@ use fixed::{types::extra::U0, FixedU128}; pub use frame_support::traits::GenesisBuild; use frame_support::{ pallet_prelude::{ - Blake2_128Concat, IsType, StorageDoubleMap, StorageMap, StorageValue, ValueQuery, + Blake2_128Concat, DispatchResult, IsType, StorageDoubleMap, StorageMap, StorageValue, + ValueQuery, Weight, }, traits::{Get, Hooks}, Parameter, }; -use frame_system::pallet_prelude::BlockNumberFor; +use frame_system::{ + ensure_signed, + pallet_prelude::{BlockNumberFor, OriginFor}, +}; use node_primitives::{CurrencyId, MinterRewardExt, TokenSymbol}; use orml_traits::{ currency::TransferAll, MultiCurrency, MultiCurrencyExtended, MultiLockableCurrency, @@ -41,10 +45,14 @@ use sp_runtime::traits::{ AtLeast32Bit, MaybeSerializeDeserialize, Member, SaturatedConversion, Saturating, UniqueSaturatedFrom, Zero, }; +pub use weights::WeightInfo; use zenlink_protocol::{AssetId, ExportZenlink}; +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; mod mock; mod tests; +pub mod weights; #[frame_support::pallet] pub mod pallet { @@ -97,6 +105,9 @@ pub mod pallet { + MaybeSerializeDeserialize + Into> + From>; + + /// Set default weight. + type WeightInfo: WeightInfo; } /// How much BNC will be issued to minters each block after. @@ -161,9 +172,6 @@ pub mod pallet { #[pallet::pallet] pub struct Pallet(PhantomData); - /// No call in this pallet. - #[pallet::call] - impl Pallet {} #[pallet::error] pub enum Error { @@ -177,7 +185,7 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { - fn on_finalize(n: BlockNumberFor) { + fn on_initialize(n: BlockNumberFor) -> Weight { // reach two year if n % T::HalvingCycle::get() == Zero::zero() && n > Zero::zero() { // Change round index @@ -214,6 +222,8 @@ pub mod pallet { let _ = Minter::::remove_all(None); let _ = TotalVtokenMinted::::remove_all(None); } + + 70_943_000 as Weight } } @@ -246,6 +256,25 @@ pub mod pallet { } } + #[pallet::call] + impl Pallet { + #[pallet::weight(T::WeightInfo::claim_reward())] + pub fn claim_reward(origin: OriginFor) -> DispatchResult { + let claimer = ensure_signed(origin)?; + + // get reward amount and deposit it to the claimer's account + let amount = Self::user_reward(&claimer); + if amount > Zero::zero() { + T::MultiCurrency::deposit(CurrencyId::Native(TokenSymbol::ASG), &claimer, amount)?; + + // delete the record in the storage + crate::UserReward::::remove(&claimer); + } + + Ok(()) + } + } + impl Pallet { pub fn compare_max_vtoken_minted( currency_id: CurrencyId, @@ -280,11 +309,6 @@ pub mod pallet { let total_vtoken_mint = TotalVtokenMinted::::get(currency_id); // AUSD let reward = bnc_reward.saturating_mul(weight.into().saturating_mul(vtoken_amount)) / (total_weight.saturating_mul(total_vtoken_mint)); - let _ = T::MultiCurrency::deposit( - CurrencyId::Native(TokenSymbol::ASG), - &minter, - reward, - ); // Record all BNC rewards the user receives. if UserReward::::contains_key(&minter) { diff --git a/pallets/minter-reward/src/mock.rs b/pallets/minter-reward/src/mock.rs index c5bad25104..8007161ce9 100644 --- a/pallets/minter-reward/src/mock.rs +++ b/pallets/minter-reward/src/mock.rs @@ -24,6 +24,8 @@ use core::marker::PhantomData; use std::convert::TryInto; +#[cfg(feature = "runtime-benchmarks")] +use frame_benchmarking::whitelisted_caller; use frame_support::{parameter_types, traits::GenesisBuild, PalletId}; use node_primitives::{CurrencyId, TokenSymbol}; use orml_traits::MultiCurrency; @@ -253,6 +255,7 @@ impl crate::Config for Runtime { type RewardWindow = RewardWindow; type ShareWeight = Balance; type StableCurrencyId = StableCurrencyId; + type WeightInfo = (); } pub struct ExtBuilder { @@ -310,6 +313,18 @@ impl ExtBuilder { // ]) // } + #[cfg(feature = "runtime-benchmarks")] + pub fn one_hundred_precision_for_each_currency_type_for_whitelist_account(self) -> Self { + let whitelist_caller: AccountId = whitelisted_caller(); + + self.balances(vec![ + (whitelist_caller.clone(), KSM, 100_000_000_000_000), + (whitelist_caller.clone(), DOT, 100_000_000_000_000), + (whitelist_caller.clone(), vKSM, 100_000_000_000_000), + (whitelist_caller.clone(), vDOT, 100_000_000_000_000), + ]) + } + pub fn build(self) -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); diff --git a/pallets/minter-reward/src/tests.rs b/pallets/minter-reward/src/tests.rs index 74e9ca513b..92ec99b2d1 100644 --- a/pallets/minter-reward/src/tests.rs +++ b/pallets/minter-reward/src/tests.rs @@ -37,8 +37,23 @@ pub(crate) fn run_to_block(n: u64) { } } -// The following test is ignored due to some bugs on zenlink. It can be reopened after the bug is -// fixed.frame_system The functionality has already been tested. +#[test] +fn claim_reward_should_work() { + ExtBuilder::default().ten_thousand_for_alice_n_bob().build().execute_with(|| { + crate::UserReward::::insert(&ALICE, 1000); + assert_eq!(MinterReward::user_reward(&ALICE), 1000); + // Alice original has 100000 native token. + assert_eq!(Currencies::free_balance(CurrencyId::Native(TokenSymbol::ASG), &ALICE), 100000); + + assert_ok!(MinterReward::claim_reward(Origin::signed(ALICE))); + assert_eq!(MinterReward::user_reward(&ALICE), 0); + assert_eq!( + Currencies::free_balance(CurrencyId::Native(TokenSymbol::ASG), &ALICE), + 100000 + 1000 + ) + }); +} + #[test] fn minter_reward_should_work() { ExtBuilder::default().ten_thousand_for_alice_n_bob().build().execute_with(|| { @@ -150,9 +165,9 @@ fn minter_reward_should_work() { (12, 56, CurrencyId::VToken(TokenSymbol::DOT)) ); - // start block is 2, max extended block is 20, block 22 should still be the last block of + // start block is 2, max extended block is 20, block 21 should still be the last block of // maximum_vtoken(12, 56, CurrencyId::VToken(TokenSymbol::DOT)) - run_to_block(22); + run_to_block(21); assert_eq!( MinterReward::maximum_vtoken_minted(), (12, 56, CurrencyId::VToken(TokenSymbol::DOT)) diff --git a/pallets/minter-reward/src/weights.rs b/pallets/minter-reward/src/weights.rs new file mode 100644 index 0000000000..e053bc0786 --- /dev/null +++ b/pallets/minter-reward/src/weights.rs @@ -0,0 +1,42 @@ +// This file is part of Bifrost. + +// Copyright (C) 2019-2021 Liebi Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{ + traits::Get, + weights::{constants::RocksDbWeight, Weight}, +}; + +/// Weight functions needed for the pallet. +pub trait WeightInfo { + fn claim_reward() -> Weight; + fn on_initialize() -> Weight; +} + +// For backwards compatibility and tests +impl WeightInfo for () { + fn claim_reward() -> Weight { + (50_000_000 as Weight) + } + + fn on_initialize() -> Weight { + (50_000_000 as Weight) + } +} diff --git a/pallets/vtoken-mint/Cargo.toml b/pallets/vtoken-mint/Cargo.toml index f58a2b79d7..af335511e5 100644 --- a/pallets/vtoken-mint/Cargo.toml +++ b/pallets/vtoken-mint/Cargo.toml @@ -15,6 +15,7 @@ sp-runtime = { version = "3.0.0", default-features = false } zenlink-protocol = { version = "*", default-features = false } orml-traits = { version = "0.4.1-dev", default-features = false } bifrost-minter-reward = { path = "../minter-reward", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false, optional = true } [dev-dependencies] orml-tokens = { version = "0.4.1-dev" } @@ -40,3 +41,9 @@ std = [ "orml-traits/std", "bifrost-minter-reward/std" ] + +runtime-benchmarks = [ + "frame-benchmarking", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", +] \ No newline at end of file diff --git a/pallets/vtoken-mint/src/benchmarking.rs b/pallets/vtoken-mint/src/benchmarking.rs new file mode 100644 index 0000000000..1f11fa53d7 --- /dev/null +++ b/pallets/vtoken-mint/src/benchmarking.rs @@ -0,0 +1,71 @@ +// This file is part of Bifrost. + +// Copyright (C) 2019-2021 Liebi Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#![cfg(feature = "runtime-benchmarks")] + +use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller}; +use frame_system::RawOrigin; +use node_primitives::{CurrencyId, TokenSymbol}; +use sp_runtime::traits::UniqueSaturatedFrom; + +use super::*; +#[allow(unused_imports)] +use crate::Pallet as VtokenMint; + +benchmarks! { + set_token_staking_lock_period { + let token_id = CurrencyId::Token(TokenSymbol::DOT); + let locking_blocks = T::BlockNumber::from(100u32); + }: _(RawOrigin::Root, token_id, locking_blocks) + + set_vtoken_pool { + let currency_id = CurrencyId::Token(TokenSymbol::DOT); + let new_token_pool = BalanceOf::::unique_saturated_from(10u32 as u128); + let new_vtoken_pool = BalanceOf::::unique_saturated_from(20u32 as u128); + }: _(RawOrigin::Root, currency_id, new_token_pool, new_vtoken_pool) + + mint { + VtokenMint::::expand_mint_pool(CurrencyId::Token(TokenSymbol::DOT), BalanceOf::::unique_saturated_from(100u32 as u128))?; + VtokenMint::::expand_mint_pool(CurrencyId::VToken(TokenSymbol::DOT), BalanceOf::::unique_saturated_from(200u32 as u128))?; + + let caller: T::AccountId = whitelisted_caller(); + let vtoken_id = CurrencyId::VToken(TokenSymbol::DOT); + let token_amount = BalanceOf::::unique_saturated_from(10u32 as u128); + }: _(RawOrigin::Signed(caller), vtoken_id, token_amount) + + redeem { + VtokenMint::::expand_mint_pool(CurrencyId::Token(TokenSymbol::DOT), BalanceOf::::unique_saturated_from(100u32 as u128))?; + VtokenMint::::expand_mint_pool(CurrencyId::VToken(TokenSymbol::DOT), BalanceOf::::unique_saturated_from(200u32 as u128))?; + + let caller: T::AccountId = whitelisted_caller(); + let token_id = CurrencyId::Token(TokenSymbol::DOT); + let vtoken_amount = BalanceOf::::unique_saturated_from(10u32 as u128); + }: _(RawOrigin::Signed(caller), token_id, vtoken_amount) + + on_initialize { + let block_num = T::BlockNumber::from(100u32); + }:{VtokenMint::::on_initialize(block_num);} +} + +impl_benchmark_test_suite!( + VtokenMint, + crate::mock::ExtBuilder::default() + .one_hundred_precision_for_each_currency_type_for_whitelist_account() + .build(), + crate::mock::Runtime +); diff --git a/pallets/vtoken-mint/src/lib.rs b/pallets/vtoken-mint/src/lib.rs index 4e2b37a946..adb1ed22f4 100644 --- a/pallets/vtoken-mint/src/lib.rs +++ b/pallets/vtoken-mint/src/lib.rs @@ -41,12 +41,15 @@ use sp_runtime::{ traits::{CheckedSub, Saturating, Zero}, DispatchResult, }; -use weights::WeightInfo; +pub use weights::WeightInfo; mod mock; mod tests; pub mod weights; +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; + type BalanceOf = <::MultiCurrency as MultiCurrency< ::AccountId, >>::Balance; @@ -294,9 +297,10 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { - fn on_finalize(_block_number: T::BlockNumber) { + fn on_initialize(block_number: T::BlockNumber) -> Weight { // Check redeem - let _ = Self::check_redeem_period(_block_number); + let _ = Self::check_redeem_period(block_number); + 471_000 as Weight } } diff --git a/pallets/vtoken-mint/src/mock.rs b/pallets/vtoken-mint/src/mock.rs index 03e240826e..10c275c74b 100644 --- a/pallets/vtoken-mint/src/mock.rs +++ b/pallets/vtoken-mint/src/mock.rs @@ -24,6 +24,8 @@ use core::marker::PhantomData; use std::convert::TryInto; +#[cfg(feature = "runtime-benchmarks")] +use frame_benchmarking::whitelisted_caller; use frame_support::{ parameter_types, traits::{GenesisBuild, Hooks}, @@ -165,6 +167,7 @@ impl bifrost_minter_reward::Config for Runtime { type RewardWindow = RewardWindow; type ShareWeight = Balance; type StableCurrencyId = StableCurrencyId; + type WeightInfo = (); } impl crate::Config for Runtime { @@ -293,6 +296,18 @@ impl ExtBuilder { ]) } + #[cfg(feature = "runtime-benchmarks")] + pub fn one_hundred_precision_for_each_currency_type_for_whitelist_account(self) -> Self { + let whitelist_caller: AccountId = whitelisted_caller(); + + self.balances(vec![ + (whitelist_caller.clone(), KSM, 100_000_000_000_000), + (whitelist_caller.clone(), DOT, 100_000_000_000_000), + (whitelist_caller.clone(), vKSM, 100_000_000_000_000), + (whitelist_caller.clone(), vDOT, 100_000_000_000_000), + ]) + } + pub fn build(self) -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); diff --git a/pallets/vtoken-mint/src/weights.rs b/pallets/vtoken-mint/src/weights.rs index fd5ef16235..91a446b03f 100644 --- a/pallets/vtoken-mint/src/weights.rs +++ b/pallets/vtoken-mint/src/weights.rs @@ -31,11 +31,11 @@ pub trait WeightInfo { fn set_token_staking_lock_period() -> Weight; fn mint() -> Weight; fn redeem() -> Weight; + fn on_finalize() -> Weight; } -/// Weights for the pallet using the Bifrost node and recommended hardware. -pub struct BifrostWeight(PhantomData); -impl WeightInfo for BifrostWeight { +// For backwards compatibility and tests +impl WeightInfo for () { fn set_vtoken_pool() -> Weight { (50_000_000 as Weight) } @@ -51,23 +51,8 @@ impl WeightInfo for BifrostWeight { fn redeem() -> Weight { (50_000_000 as Weight) } -} - -// For backwards compatibility and tests -impl WeightInfo for () { - fn set_vtoken_pool() -> Weight { - (50_000_000 as Weight) - } - fn set_token_staking_lock_period() -> Weight { - (50_000_000 as Weight) - } - - fn mint() -> Weight { - (50_000_000 as Weight) - } - - fn redeem() -> Weight { + fn on_finalize() -> Weight { (50_000_000 as Weight) } } diff --git a/runtime/asgard/Cargo.toml b/runtime/asgard/Cargo.toml index f54196ca21..3b51f55ac5 100644 --- a/runtime/asgard/Cargo.toml +++ b/runtime/asgard/Cargo.toml @@ -186,4 +186,7 @@ runtime-benchmarks = [ "pallet-xcm/runtime-benchmarks", "bifrost-salp/runtime-benchmarks", "bifrost-bancor/runtime-benchmarks", + "bifrost-flexible-fee/runtime-benchmarks", + "bifrost-vtoken-mint/runtime-benchmarks", + "bifrost-minter-reward/runtime-benchmarks", ] diff --git a/runtime/asgard/src/lib.rs b/runtime/asgard/src/lib.rs index ac54ab2af7..63861efcf5 100644 --- a/runtime/asgard/src/lib.rs +++ b/runtime/asgard/src/lib.rs @@ -881,7 +881,7 @@ impl bifrost_vtoken_mint::Config for Runtime { type Event = Event; type MinterReward = MinterReward; type MultiCurrency = Currencies; - type WeightInfo = bifrost_vtoken_mint::weights::BifrostWeight; + type WeightInfo = weights::bifrost_vtoken_mint::WeightInfo; } orml_traits::parameter_type_with_key! { @@ -920,8 +920,8 @@ impl bifrost_flexible_fee::Config for Runtime { type NativeCurrencyId = NativeCurrencyId; type AlternativeFeeCurrencyId = AlternativeFeeCurrencyId; type AltFeeCurrencyExchangeRate = AltFeeCurrencyExchangeRate; - type OnUnbalanced = (); - type WeightInfo = (); + type OnUnbalanced = Treasury; + type WeightInfo = weights::bifrost_flexible_fee::WeightInfo; } parameter_types! { @@ -939,6 +939,7 @@ impl bifrost_minter_reward::Config for Runtime { type RewardWindow = RewardWindow; type ShareWeight = Balance; type StableCurrencyId = StableCurrencyId; + type WeightInfo = weights::bifrost_minter_reward::WeightInfo; } parameter_types! { @@ -1196,7 +1197,7 @@ construct_runtime! { // Bifrost modules VtokenMint: bifrost_vtoken_mint::{Pallet, Call, Storage, Event, Config} = 101, - MinterReward: bifrost_minter_reward::{Pallet, Storage, Event, Config} = 102, + MinterReward: bifrost_minter_reward::{Pallet, Call, Storage, Event, Config} = 102, FlexibleFee: bifrost_flexible_fee::{Pallet, Call, Storage, Event} = 104, Salp: bifrost_salp::{Pallet, Call, Storage, Event} = 105, Bancor: bifrost_bancor::{Pallet, Call, Storage, Event, Config} = 106, @@ -1497,6 +1498,9 @@ impl_runtime_apis! { let params = (&config, &whitelist); add_benchmark!(params, batches, bifrost_salp, Salp); add_benchmark!(params, batches, bifrost_bancor, Bancor); + add_benchmark!(params, batches, bifrost_flexible_fee, FlexibleFee); + add_benchmark!(params, batches, bifrost_vtoken_mint, VtokenMint); + add_benchmark!(params, batches, bifrost_minter_reward, MinterReward); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) diff --git a/runtime/asgard/src/weights/bifrost_bancor.rs b/runtime/asgard/src/weights/bifrost_bancor.rs index e5415b5baa..a038cea54e 100644 --- a/runtime/asgard/src/weights/bifrost_bancor.rs +++ b/runtime/asgard/src/weights/bifrost_bancor.rs @@ -19,7 +19,7 @@ //! Autogenerated weights for bifrost_bancor //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-08-04, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2021-08-11, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-local"), DB CACHE: 128 // Executed Command: @@ -46,21 +46,21 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl bifrost_bancor::WeightInfo for WeightInfo { fn add_token_to_pool() -> Weight { - (61_646_000 as Weight) + (64_271_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn exchange_for_token() -> Weight { - (90_360_000 as Weight) + (91_953_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn exchange_for_vstoken() -> Weight { - (79_159_000 as Weight) + (79_409_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn on_initialize() -> Weight { - (22_252_000 as Weight).saturating_add(T::DbWeight::get().reads(3 as Weight)) + (21_690_000 as Weight).saturating_add(T::DbWeight::get().reads(3 as Weight)) } } diff --git a/runtime/asgard/src/weights/bifrost_flexible_fee.rs b/runtime/asgard/src/weights/bifrost_flexible_fee.rs new file mode 100644 index 0000000000..2da33f55b5 --- /dev/null +++ b/runtime/asgard/src/weights/bifrost_flexible_fee.rs @@ -0,0 +1,53 @@ +// This file is part of Bifrost. + +// Copyright (C) 2019-2021 Liebi Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! Autogenerated weights for bifrost_flexible_fee +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 +//! DATE: 2021-08-11, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-local"), DB CACHE: 128 + +// Executed Command: +// target/release/bifrost +// benchmark +// --chain=asgard-local +// --steps=50 +// --repeat=20 +// --pallet=bifrost_flexible_fee +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --header=./HEADER-GPL3 +// --output=./runtime/asgard/src/weights/bifrost_flexible_fee.rs + +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for bifrost_flexible_fee. +pub struct WeightInfo(PhantomData); +impl bifrost_flexible_fee::WeightInfo for WeightInfo { + fn set_user_fee_charge_order() -> Weight { + (6_081_000 as Weight) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } +} diff --git a/runtime/asgard/src/weights/bifrost_minter_reward.rs b/runtime/asgard/src/weights/bifrost_minter_reward.rs new file mode 100644 index 0000000000..dd5bc9fc6c --- /dev/null +++ b/runtime/asgard/src/weights/bifrost_minter_reward.rs @@ -0,0 +1,58 @@ +// This file is part of Bifrost. + +// Copyright (C) 2019-2021 Liebi Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! Autogenerated weights for bifrost_minter_reward +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 +//! DATE: 2021-08-11, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-local"), DB CACHE: 128 + +// Executed Command: +// target/release/bifrost +// benchmark +// --chain=asgard-local +// --steps=50 +// --repeat=20 +// --pallet=bifrost_minter_reward +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --header=./HEADER-GPL3 +// --output=./runtime/asgard/src/weights/bifrost_minter_reward.rs + +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for bifrost_minter_reward. +pub struct WeightInfo(PhantomData); +impl bifrost_minter_reward::WeightInfo for WeightInfo { + fn claim_reward() -> Weight { + (49_272_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn on_initialize() -> Weight { + (70_943_000 as Weight) + .saturating_add(T::DbWeight::get().reads(9 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } +} diff --git a/runtime/asgard/src/weights/bifrost_salp.rs b/runtime/asgard/src/weights/bifrost_salp.rs index 798704af6f..1fabc47330 100644 --- a/runtime/asgard/src/weights/bifrost_salp.rs +++ b/runtime/asgard/src/weights/bifrost_salp.rs @@ -19,7 +19,7 @@ //! Autogenerated weights for bifrost_salp //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-08-04, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2021-08-11, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-local"), DB CACHE: 128 // Executed Command: @@ -46,19 +46,19 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl bifrost_salp::WeightInfo for WeightInfo { fn create() -> Weight { - (57_287_000 as Weight) + (60_954_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn contribute() -> Weight { - (59_913_000 as Weight) + (64_140_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn on_finalize(n: u32) -> Weight { - (9_072_000 as Weight) - // Standard Error: 2_000 - .saturating_add((219_000 as Weight).saturating_mul(n as Weight)) + (9_002_000 as Weight) + // Standard Error: 0 + .saturating_add((235_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } diff --git a/runtime/asgard/src/weights/bifrost_vtoken_mint.rs b/runtime/asgard/src/weights/bifrost_vtoken_mint.rs new file mode 100644 index 0000000000..2a406ee7ee --- /dev/null +++ b/runtime/asgard/src/weights/bifrost_vtoken_mint.rs @@ -0,0 +1,71 @@ +// This file is part of Bifrost. + +// Copyright (C) 2019-2021 Liebi Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! Autogenerated weights for bifrost_vtoken_mint +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 +//! DATE: 2021-08-11, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-local"), DB CACHE: 128 + +// Executed Command: +// target/release/bifrost +// benchmark +// --chain=asgard-local +// --steps=50 +// --repeat=20 +// --pallet=bifrost_vtoken_mint +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --header=./HEADER-GPL3 +// --output=./runtime/asgard/src/weights/bifrost_vtoken_mint.rs + +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for bifrost_vtoken_mint. +pub struct WeightInfo(PhantomData); +impl bifrost_vtoken_mint::WeightInfo for WeightInfo { + fn set_token_staking_lock_period() -> Weight { + (30_306_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn set_vtoken_pool() -> Weight { + (34_295_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + fn mint() -> Weight { + (147_588_000 as Weight) + .saturating_add(T::DbWeight::get().reads(9 as Weight)) + .saturating_add(T::DbWeight::get().writes(6 as Weight)) + } + fn redeem() -> Weight { + (102_943_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(5 as Weight)) + } + fn on_finalize() -> Weight { + (451_000 as Weight) + } +} diff --git a/runtime/asgard/src/weights/mod.rs b/runtime/asgard/src/weights/mod.rs index 2206502d2c..a2c66ff8f1 100644 --- a/runtime/asgard/src/weights/mod.rs +++ b/runtime/asgard/src/weights/mod.rs @@ -21,5 +21,8 @@ //! A list of the different weight modules for our runtime. pub mod bifrost_bancor; +pub mod bifrost_flexible_fee; +pub mod bifrost_minter_reward; pub mod bifrost_salp; +pub mod bifrost_vtoken_mint; pub mod pallet_vesting; diff --git a/runtime/dev/Cargo.toml b/runtime/dev/Cargo.toml index 3d566d14b2..01a5143f01 100644 --- a/runtime/dev/Cargo.toml +++ b/runtime/dev/Cargo.toml @@ -188,4 +188,7 @@ runtime-benchmarks = [ "pallet-xcm/runtime-benchmarks", "bifrost-salp/runtime-benchmarks", "bifrost-bancor/runtime-benchmarks", + "bifrost-flexible-fee/runtime-benchmarks", + "bifrost-vtoken-mint/runtime-benchmarks", + "bifrost-minter-reward/runtime-benchmarks", ] diff --git a/runtime/dev/src/lib.rs b/runtime/dev/src/lib.rs index 3a5e9d91d2..d8e7742188 100644 --- a/runtime/dev/src/lib.rs +++ b/runtime/dev/src/lib.rs @@ -853,7 +853,7 @@ impl bifrost_vtoken_mint::Config for Runtime { type Event = Event; type MinterReward = MinterReward; type MultiCurrency = Currencies; - type WeightInfo = bifrost_vtoken_mint::weights::BifrostWeight; + type WeightInfo = weights::bifrost_vtoken_mint::WeightInfo; } orml_traits::parameter_type_with_key! { @@ -892,8 +892,8 @@ impl bifrost_flexible_fee::Config for Runtime { type NativeCurrencyId = NativeCurrencyId; type AlternativeFeeCurrencyId = AlternativeFeeCurrencyId; type AltFeeCurrencyExchangeRate = AltFeeCurrencyExchangeRate; - type OnUnbalanced = (); - type WeightInfo = (); + type OnUnbalanced = Treasury; + type WeightInfo = weights::bifrost_flexible_fee::WeightInfo; } parameter_types! { @@ -911,6 +911,7 @@ impl bifrost_minter_reward::Config for Runtime { type RewardWindow = RewardWindow; type ShareWeight = Balance; type StableCurrencyId = StableCurrencyId; + type WeightInfo = weights::bifrost_minter_reward::WeightInfo; } parameter_types! { @@ -1164,7 +1165,7 @@ construct_runtime! { // Bifrost modules VtokenMint: bifrost_vtoken_mint::{Pallet, Call, Storage, Event, Config} = 101, - MinterReward: bifrost_minter_reward::{Pallet, Storage, Event, Config} = 102, + MinterReward: bifrost_minter_reward::{Pallet, Call, Storage, Event, Config} = 102, FlexibleFee: bifrost_flexible_fee::{Pallet, Call, Storage, Event} = 104, Salp: bifrost_salp::{Pallet, Call, Storage, Event} = 105, Bancor: bifrost_bancor::{Pallet, Call, Storage, Event, Config} = 106, @@ -1491,6 +1492,9 @@ impl_runtime_apis! { let params = (&config, &whitelist); add_benchmark!(params, batches, bifrost_salp, Salp); add_benchmark!(params, batches, bifrost_bancor, Bancor); + add_benchmark!(params, batches, bifrost_flexible_fee, FlexibleFee); + add_benchmark!(params, batches, bifrost_vtoken_mint, VtokenMint); + add_benchmark!(params, batches, bifrost_minter_reward, MinterReward); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) diff --git a/runtime/dev/src/weights/bifrost_bancor.rs b/runtime/dev/src/weights/bifrost_bancor.rs index cbfc8d80b9..a038cea54e 100644 --- a/runtime/dev/src/weights/bifrost_bancor.rs +++ b/runtime/dev/src/weights/bifrost_bancor.rs @@ -19,16 +19,16 @@ //! Autogenerated weights for bifrost_bancor //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-08-03, STEPS: `[50, ]`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-dev"), DB CACHE: 128 +//! DATE: 2021-08-11, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-local"), DB CACHE: 128 // Executed Command: // target/release/bifrost // benchmark -// --chain=asgard-dev +// --chain=asgard-local // --steps=50 -// --repeat=1 -// --pallet=bifrost-bancor +// --repeat=20 +// --pallet=bifrost_bancor // --extrinsic=* // --execution=wasm // --wasm-execution=compiled @@ -46,21 +46,21 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl bifrost_bancor::WeightInfo for WeightInfo { fn add_token_to_pool() -> Weight { - (64_732_000 as Weight) + (64_271_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn exchange_for_token() -> Weight { - (94_428_000 as Weight) + (91_953_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn exchange_for_vstoken() -> Weight { - (82_786_000 as Weight) + (79_409_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn on_initialize() -> Weight { - (22_914_000 as Weight).saturating_add(T::DbWeight::get().reads(3 as Weight)) + (21_690_000 as Weight).saturating_add(T::DbWeight::get().reads(3 as Weight)) } } diff --git a/runtime/dev/src/weights/bifrost_flexible_fee.rs b/runtime/dev/src/weights/bifrost_flexible_fee.rs new file mode 100644 index 0000000000..cdd7dff85d --- /dev/null +++ b/runtime/dev/src/weights/bifrost_flexible_fee.rs @@ -0,0 +1,51 @@ +// This file is part of Bifrost. + +// Copyright (C) 2019-2021 Liebi Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! Autogenerated weights for bifrost_flexible_fee +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 +//! DATE: 2021-08-11, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-local"), DB CACHE: 128 + +// Executed Command: +// target/release/bifrost +// benchmark +// --chain=asgard-local +// --steps=50 +// --repeat=20 +// --pallet=bifrost_flexible_fee +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --header=./HEADER-GPL3 +// --output=./runtime/asgard/src/weights/bifrost_flexible_fee.rs + +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for bifrost_flexible_fee. +pub struct WeightInfo(PhantomData); +impl bifrost_flexible_fee::WeightInfo for WeightInfo { + fn set_user_fee_charge_order() -> Weight { + (6_081_000 as Weight).saturating_add(T::DbWeight::get().writes(1 as Weight)) + } +} diff --git a/runtime/dev/src/weights/bifrost_minter_reward.rs b/runtime/dev/src/weights/bifrost_minter_reward.rs new file mode 100644 index 0000000000..5f0fdcdf54 --- /dev/null +++ b/runtime/dev/src/weights/bifrost_minter_reward.rs @@ -0,0 +1,56 @@ +// This file is part of Bifrost. + +// Copyright (C) 2019-2021 Liebi Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! Autogenerated weights for bifrost_minter_reward +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 +//! DATE: 2021-08-11, STEPS: `[50, ]`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-local"), DB CACHE: 128 + +// Executed Command: +// target/release/bifrost +// benchmark +// --chain=asgard-local +// --steps=50 +// --repeat=1 +// --pallet=bifrost_minter_reward +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --header=./HEADER-GPL3 +// --output=./runtime/asgard/src/weights/bifrost_minter_reward.rs + +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for bifrost_minter_reward. +pub struct WeightInfo(PhantomData); +impl bifrost_minter_reward::WeightInfo for WeightInfo { + fn claim_reward() -> Weight { + (51_306_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn on_initialize() -> Weight { + (481_000 as Weight) + } +} diff --git a/runtime/dev/src/weights/bifrost_salp.rs b/runtime/dev/src/weights/bifrost_salp.rs index 4f95249a7f..1fabc47330 100644 --- a/runtime/dev/src/weights/bifrost_salp.rs +++ b/runtime/dev/src/weights/bifrost_salp.rs @@ -19,13 +19,13 @@ //! Autogenerated weights for bifrost_salp //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-07-30, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-dev"), DB CACHE: 128 +//! DATE: 2021-08-11, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-local"), DB CACHE: 128 // Executed Command: // target/release/bifrost // benchmark -// --chain=asgard-dev +// --chain=asgard-local // --steps=50 // --repeat=20 // --pallet=bifrost_salp @@ -46,19 +46,19 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl bifrost_salp::WeightInfo for WeightInfo { fn create() -> Weight { - (60_294_000 as Weight) + (60_954_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn contribute() -> Weight { - (63_079_000 as Weight) + (64_140_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn on_finalize(n: u32) -> Weight { - (8_753_000 as Weight) + (9_002_000 as Weight) // Standard Error: 0 - .saturating_add((214_000 as Weight).saturating_mul(n as Weight)) + .saturating_add((235_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } diff --git a/runtime/dev/src/weights/bifrost_vtoken_mint.rs b/runtime/dev/src/weights/bifrost_vtoken_mint.rs new file mode 100644 index 0000000000..2a406ee7ee --- /dev/null +++ b/runtime/dev/src/weights/bifrost_vtoken_mint.rs @@ -0,0 +1,71 @@ +// This file is part of Bifrost. + +// Copyright (C) 2019-2021 Liebi Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! Autogenerated weights for bifrost_vtoken_mint +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 +//! DATE: 2021-08-11, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("asgard-local"), DB CACHE: 128 + +// Executed Command: +// target/release/bifrost +// benchmark +// --chain=asgard-local +// --steps=50 +// --repeat=20 +// --pallet=bifrost_vtoken_mint +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --header=./HEADER-GPL3 +// --output=./runtime/asgard/src/weights/bifrost_vtoken_mint.rs + +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for bifrost_vtoken_mint. +pub struct WeightInfo(PhantomData); +impl bifrost_vtoken_mint::WeightInfo for WeightInfo { + fn set_token_staking_lock_period() -> Weight { + (30_306_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn set_vtoken_pool() -> Weight { + (34_295_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + fn mint() -> Weight { + (147_588_000 as Weight) + .saturating_add(T::DbWeight::get().reads(9 as Weight)) + .saturating_add(T::DbWeight::get().writes(6 as Weight)) + } + fn redeem() -> Weight { + (102_943_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(5 as Weight)) + } + fn on_finalize() -> Weight { + (451_000 as Weight) + } +} diff --git a/runtime/dev/src/weights/mod.rs b/runtime/dev/src/weights/mod.rs index 2206502d2c..a2c66ff8f1 100644 --- a/runtime/dev/src/weights/mod.rs +++ b/runtime/dev/src/weights/mod.rs @@ -21,5 +21,8 @@ //! A list of the different weight modules for our runtime. pub mod bifrost_bancor; +pub mod bifrost_flexible_fee; +pub mod bifrost_minter_reward; pub mod bifrost_salp; +pub mod bifrost_vtoken_mint; pub mod pallet_vesting;