Skip to content
3 changes: 3 additions & 0 deletions Cargo.lock

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

10 changes: 7 additions & 3 deletions node/service/src/chain_spec/asgard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions pallets/flexible-fee/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -39,3 +40,9 @@ std = [
"sp-arithmetic/std",
"orml-traits/std",
]

runtime-benchmarks = [
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
42 changes: 42 additions & 0 deletions pallets/flexible-fee/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

#![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
);
2 changes: 0 additions & 2 deletions pallets/flexible-fee/src/fee_dealer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
10 changes: 4 additions & 6 deletions pallets/flexible-fee/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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<T> = <<T as Config>::MultiCurrency as MultiCurrency<
<T as frame_system::Config>::AccountId,
>>::CurrencyId;

pub trait WeightInfo {
fn set_user_fee_charge_order() -> Weight;
}

#[frame_support::pallet]
pub mod pallet {
use super::*;
Expand Down
52 changes: 52 additions & 0 deletions pallets/flexible-fee/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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;

Expand Down Expand Up @@ -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::<Test>().unwrap();

orml_tokens::GenesisConfig::<Test> { 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::<Test>().unwrap().into()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
7 changes: 7 additions & 0 deletions pallets/minter-reward/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
]
54 changes: 54 additions & 0 deletions pallets/minter-reward/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

#![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::<T>::insert(caller.clone(), BalanceOf::<T>::unique_saturated_from(10 as u128));
}: _(RawOrigin::Signed(caller))

on_initialize {
let block_num = T::BlockNumber::from(120u32);
CurrentRoundStartAt::<T>::set(T::BlockNumber::from(100u32));

let max_mint = (T::BlockNumber::from(111u32), BalanceOf::<T>::unique_saturated_from(100 as u128), CurrencyId::Token(TokenSymbol::DOT));
MaximumVtokenMinted::<T>::set(max_mint);


}:{MinterReward::<T>::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
);
Loading