Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

9 changes: 8 additions & 1 deletion node/service/src/chain_spec/asgard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use asgard_runtime::{
TokensConfig, VestingConfig, VtokenMintConfig, WASM_BINARY,
};
use cumulus_primitives_core::ParaId;
use frame_benchmarking::whitelisted_caller;
use frame_benchmarking::{account, whitelisted_caller};
use hex_literal::hex;
use node_primitives::{CurrencyId, TokenSymbol};
use sc_service::ChainType;
Expand Down Expand Up @@ -198,6 +198,8 @@ fn local_config_genesis(id: ParaId) -> GenesisConfig {
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
whitelisted_caller(), // Benchmarking whitelist_account
account("bechmarking_account_1", 0, 0), /* Benchmarking account_1, used for interacting
* with whitelistted_caller */
];
let balances = endowed_accounts
.iter()
Expand All @@ -224,6 +226,11 @@ fn local_config_genesis(id: ParaId) -> GenesisConfig {
(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),
(
x.clone(),
CurrencyId::VSBond(TokenSymbol::KSM, 3000, 13, 20),
ENDOWMENT * 4_000_000,
),
]
})
.collect();
Expand Down
7 changes: 7 additions & 0 deletions pallets/vsbond-auction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ frame-system = { version = "3.0.0", default-features = false }
frame-support = { version = "3.0.0", default-features = false }
node-primitives = { path = "../../node/primitives", 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 @@ -31,4 +32,10 @@ std = [
"frame-support/std",
"node-primitives/std",
"orml-traits/std",
]

runtime-benchmarks = [
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
76 changes: 76 additions & 0 deletions pallets/vsbond-auction/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// 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::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};
use frame_support::sp_runtime::traits::UniqueSaturatedFrom;
use frame_system::RawOrigin;

use super::*;
#[allow(unused_imports)]
use crate::Pallet as VSBondAuction;

benchmarks! {
create_order {
let caller: T::AccountId = whitelisted_caller();
let index: ParaId = 3000;
let first_slot = 13u32;
let last_slot = 20u32;
let supply = BalanceOf::<T>::unique_saturated_from(10u128);
let total_price = BalanceOf::<T>::unique_saturated_from(30u128);
}: _(RawOrigin::Signed(caller), index, first_slot, last_slot, supply, total_price)

revoke_order {
let caller: T::AccountId = whitelisted_caller();
let index: ParaId = 3000;
let first_slot = 13u32;
let last_slot = 20u32;
let supply = BalanceOf::<T>::unique_saturated_from(10u128);
let total_price = BalanceOf::<T>::unique_saturated_from(30u128);

VSBondAuction::<T>::create_order(<T as frame_system::Config>::Origin::from(RawOrigin::Signed(caller.clone())), index, first_slot, last_slot, supply, total_price)?;
}: _(RawOrigin::Signed(caller),0u64)

clinch_order {
let caller: T::AccountId = whitelisted_caller();
let index: ParaId = 3000;
let first_slot = 13u32;
let last_slot = 20u32;
let supply = BalanceOf::<T>::unique_saturated_from(10u128);
let total_price = BalanceOf::<T>::unique_saturated_from(30u128);
let order_owner = account("bechmarking_account_1", 0, 0);

VSBondAuction::<T>::create_order(<T as frame_system::Config>::Origin::from(RawOrigin::Signed(order_owner)), index, first_slot, last_slot, supply, total_price)?;
}: _(RawOrigin::Signed(caller),0u64)

partial_clinch_order {
let caller: T::AccountId = whitelisted_caller();
let index: ParaId = 3000;
let first_slot = 13u32;
let last_slot = 20u32;
let supply = BalanceOf::<T>::unique_saturated_from(10u128);
let total_price = BalanceOf::<T>::unique_saturated_from(30u128);
let order_owner = account("bechmarking_account_1", 0, 0);

VSBondAuction::<T>::create_order(<T as frame_system::Config>::Origin::from(RawOrigin::Signed(order_owner)), index, first_slot, last_slot, supply, total_price)?;
}: _(RawOrigin::Signed(caller),0u64, BalanceOf::<T>::unique_saturated_from(5u128))

}

impl_benchmark_test_suite!(VSBondAuction, crate::mock::new_test_ext(), crate::mock::Test);
8 changes: 8 additions & 0 deletions pallets/vsbond-auction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ use orml_traits::{MultiCurrency, MultiReservableCurrency};
pub use pallet::*;
use sp_std::{cmp::min, collections::btree_set::BTreeSet};
use substrate_fixed::{traits::FromFixed, types::U64F64};
pub use weights::WeightInfo;

#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;
pub mod weights;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;

#[derive(Encode, Decode, Clone, Eq, PartialEq)]
pub struct OrderInfo<T: Config> {
Expand Down Expand Up @@ -114,6 +119,9 @@ pub mod pallet {

type MultiCurrency: MultiCurrency<AccountIdOf<Self>, CurrencyId = CurrencyId>
+ MultiReservableCurrency<AccountIdOf<Self>, CurrencyId = CurrencyId>;

/// Set default weight.
type WeightInfo: WeightInfo;
}

#[pallet::error]
Expand Down
15 changes: 15 additions & 0 deletions pallets/vsbond-auction/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
// 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::{account, whitelisted_caller};
use frame_support::{construct_runtime, parameter_types, traits::GenesisBuild};
use node_primitives::{Amount, Balance, CurrencyId, TokenSymbol};
use sp_core::H256;
Expand Down Expand Up @@ -108,18 +110,31 @@ impl vsbond_auction::Config for Test {
type MaximumOrderInTrade = MaximumOrderInTrade;
type MinimumSupply = MinimumSupply;
type MultiCurrency = orml_tokens::Pallet<Self>;
type WeightInfo = ();
}

// mockup runtime
pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
let mut fs_gc = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
#[cfg(feature = "runtime-benchmarks")]
let whitelist_caller: AccountId = whitelisted_caller();
#[cfg(feature = "runtime-benchmarks")]
let benchmarking_account_1: AccountId = account("bechmarking_account_1", 0, 0);

orml_tokens::GenesisConfig::<Test> {
balances: vec![
(ALICE, TOKEN, 100),
(ALICE, VSBOND, 100),
(BRUCE, TOKEN, 100),
(BRUCE, VSBOND, 100),
#[cfg(feature = "runtime-benchmarks")]
(whitelist_caller.clone(), TOKEN, 100_000_000_000_000),
#[cfg(feature = "runtime-benchmarks")]
(whitelist_caller.clone(), VSBOND, 100_000_000_000_000),
#[cfg(feature = "runtime-benchmarks")]
(benchmarking_account_1.clone(), TOKEN, 100_000_000_000_000),
#[cfg(feature = "runtime-benchmarks")]
(benchmarking_account_1.clone(), VSBOND, 100_000_000_000_000),
],
}
.assimilate_storage(&mut fs_gc)
Expand Down
53 changes: 53 additions & 0 deletions pallets/vsbond-auction/src/weights.rs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

#![allow(unused_parens)]
#![allow(unused_imports)]

use frame_support::{
traits::Get,
weights::{constants::RocksDbWeight, Weight},
};
use sp_std::marker::PhantomData;

/// Weight functions needed for the pallet.
pub trait WeightInfo {
fn create_order() -> Weight;
fn revoke_order() -> Weight;
fn clinch_order() -> Weight;
fn partial_clinch_order() -> Weight;
}

// For backwards compatibility and tests
impl WeightInfo for () {
fn create_order() -> Weight {
(50_000_000 as Weight)
}

fn revoke_order() -> Weight {
(50_000_000 as Weight)
}

fn clinch_order() -> Weight {
(50_000_000 as Weight)
}

fn partial_clinch_order() -> Weight {
(50_000_000 as Weight)
}
}
4 changes: 2 additions & 2 deletions pallets/vtoken-mint/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub trait WeightInfo {
fn set_token_staking_lock_period() -> Weight;
fn mint() -> Weight;
fn redeem() -> Weight;
fn on_finalize() -> Weight;
fn on_initialize() -> Weight;
}

// For backwards compatibility and tests
Expand All @@ -52,7 +52,7 @@ impl WeightInfo for () {
(50_000_000 as Weight)
}

fn on_finalize() -> Weight {
fn on_initialize() -> Weight {
(50_000_000 as Weight)
}
}
1 change: 1 addition & 0 deletions runtime/asgard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ runtime-benchmarks = [
"bifrost-flexible-fee/runtime-benchmarks",
"bifrost-vtoken-mint/runtime-benchmarks",
"bifrost-minter-reward/runtime-benchmarks",
"bifrost-vsbond-auction/runtime-benchmarks",
]

try-runtime = [
Expand Down
3 changes: 3 additions & 0 deletions runtime/asgard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,7 @@ impl bifrost_vsbond_auction::Config for Runtime {
type MaximumOrderInTrade = MaximumOrderInTrade;
type MinimumSupply = MinimumSupply;
type MultiCurrency = Currencies;
type WeightInfo = weights::bifrost_vsbond_auction::WeightInfo<Runtime>;
}

// bifrost runtime end
Expand Down Expand Up @@ -1503,6 +1504,8 @@ impl_runtime_apis! {
add_benchmark!(params, batches, bifrost_flexible_fee, FlexibleFee);
add_benchmark!(params, batches, bifrost_vtoken_mint, VtokenMint);
add_benchmark!(params, batches, bifrost_minter_reward, MinterReward);
add_benchmark!(params, batches, bifrost_vsbond_auction, VSBondAuction);


if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)
Expand Down
68 changes: 68 additions & 0 deletions runtime/asgard/src/weights/bifrost_vsbond_auction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 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/>.

//! Autogenerated weights for bifrost_vsbond_auction
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0
//! DATE: 2021-08-12, 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_vsbond_auction
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --heap-pages=4096
// --header=./HEADER-GPL3
// --output=./runtime/asgard/src/weights/bifrost_vsbond_auction.rs

#![allow(unused_parens)]
#![allow(unused_imports)]

use frame_support::{traits::Get, weights::Weight};
use sp_std::marker::PhantomData;

/// Weight functions for bifrost_vsbond_auction.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> bifrost_vsbond_auction::WeightInfo for WeightInfo<T> {
fn create_order() -> Weight {
(104_626_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
}
fn revoke_order() -> Weight {
(99_757_000 as Weight)
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
}
fn clinch_order() -> Weight {
(204_564_000 as Weight)
.saturating_add(T::DbWeight::get().reads(8 as Weight))
.saturating_add(T::DbWeight::get().writes(7 as Weight))
}
fn partial_clinch_order() -> Weight {
(179_327_000 as Weight)
.saturating_add(T::DbWeight::get().reads(6 as Weight))
.saturating_add(T::DbWeight::get().writes(5 as Weight))
}
}
2 changes: 1 addition & 1 deletion runtime/asgard/src/weights/bifrost_vtoken_mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<T: frame_system::Config> bifrost_vtoken_mint::WeightInfo for WeightInfo<T>
.saturating_add(T::DbWeight::get().reads(5 as Weight))
.saturating_add(T::DbWeight::get().writes(5 as Weight))
}
fn on_finalize() -> Weight {
fn on_initialize() -> Weight {
(451_000 as Weight)
}
}
1 change: 1 addition & 0 deletions runtime/asgard/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ pub mod bifrost_bancor;
pub mod bifrost_flexible_fee;
pub mod bifrost_minter_reward;
pub mod bifrost_salp;
pub mod bifrost_vsbond_auction;
pub mod bifrost_vtoken_mint;
pub mod pallet_vesting;
1 change: 1 addition & 0 deletions runtime/dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@ impl bifrost_vsbond_auction::Config for Runtime {
type MaximumOrderInTrade = MaximumOrderInTrade;
type MinimumSupply = MinimumSupply;
type MultiCurrency = Currencies;
type WeightInfo = weights::bifrost_vsbond_auction::WeightInfo<Runtime>;
}

// bifrost runtime end
Expand Down
Loading