Skip to content

Commit

Permalink
Update Dex Benchmaking (#1588)
Browse files Browse the repository at this point in the history
* benches

* compile

* update

* cargo run --release --color=never --bin=acala --features=runtime-benchmarks --features=with-karura-runtime -- benchmark --chain=karura-dev --steps=50 --repeat=20 --pallet=module_dex --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/karura/src/weights/

* update benchmark

* cargo run --release --color=never --bin=acala --features=runtime-benchmarks --features=with-karura-runtime -- benchmark --chain=karura-dev --steps=50 --repeat=20 --pallet=module_dex --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/karura/src/weights/

* cargo run --release --color=never --bin=acala --features=runtime-benchmarks --features=with-mandala-runtime -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=module_dex --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/mandala/src/weights/

Co-authored-by: Acala Benchmarking Bot <hello@acala.network>
  • Loading branch information
ferrell-code and Acala Benchmarking Bot authored Nov 7, 2021
1 parent 4e743ab commit 9643104
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 80 deletions.
50 changes: 27 additions & 23 deletions runtime/karura/src/weights/module_dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! Autogenerated weights for module_dex
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2021-10-30, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2021-11-05, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("karura-dev"), DB CACHE: 128
// Executed Command:
Expand All @@ -28,7 +28,7 @@
// --chain=karura-dev
// --steps=50
// --repeat=20
// --pallet=*
// --pallet=module_dex
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
Expand All @@ -48,72 +48,76 @@ use sp_std::marker::PhantomData;
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> module_dex::WeightInfo for WeightInfo<T> {
fn enable_trading_pair() -> Weight {
(24_384_000 as Weight)
(26_202_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn disable_trading_pair() -> Weight {
(25_115_000 as Weight)
(26_691_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn list_provisioning() -> Weight {
(35_119_000 as Weight)
(36_301_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn update_provisioning_parameters() -> Weight {
(12_222_000 as Weight)
(12_660_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn end_provisioning() -> Weight {
(76_815_000 as Weight)
(78_179_000 as Weight)
.saturating_add(T::DbWeight::get().reads(5 as Weight))
.saturating_add(T::DbWeight::get().writes(6 as Weight))
}
fn add_provision() -> Weight {
(145_062_000 as Weight)
(147_431_000 as Weight)
.saturating_add(T::DbWeight::get().reads(5 as Weight))
.saturating_add(T::DbWeight::get().writes(5 as Weight))
}
fn claim_dex_share() -> Weight {
(105_816_000 as Weight)
(105_966_000 as Weight)
.saturating_add(T::DbWeight::get().reads(7 as Weight))
.saturating_add(T::DbWeight::get().writes(5 as Weight))
}
fn add_liquidity() -> Weight {
(185_997_000 as Weight)
(186_551_000 as Weight)
.saturating_add(T::DbWeight::get().reads(9 as Weight))
.saturating_add(T::DbWeight::get().writes(7 as Weight))
}
fn add_liquidity_and_stake() -> Weight {
(261_424_000 as Weight)
(263_045_000 as Weight)
.saturating_add(T::DbWeight::get().reads(12 as Weight))
.saturating_add(T::DbWeight::get().writes(10 as Weight))
}
fn remove_liquidity() -> Weight {
(159_057_000 as Weight)
(162_302_000 as Weight)
.saturating_add(T::DbWeight::get().reads(6 as Weight))
.saturating_add(T::DbWeight::get().writes(6 as Weight))
}
fn remove_liquidity_by_unstake() -> Weight {
(278_922_000 as Weight)
(280_899_000 as Weight)
.saturating_add(T::DbWeight::get().reads(12 as Weight))
.saturating_add(T::DbWeight::get().writes(10 as Weight))
}
fn swap_with_exact_supply(u: u32, ) -> Weight {
(103_618_000 as Weight)
// Standard Error: 1_130_000
.saturating_add((9_605_000 as Weight).saturating_mul(u as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
(92_601_000 as Weight)
// Standard Error: 118_000
.saturating_add((17_771_000 as Weight).saturating_mul(u as Weight))
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(u as Weight)))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(u as Weight)))
}
fn swap_with_exact_target(u: u32, ) -> Weight {
(103_842_000 as Weight)
// Standard Error: 1_219_000
.saturating_add((9_514_000 as Weight).saturating_mul(u as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
(95_445_000 as Weight)
// Standard Error: 3_617_000
.saturating_add((18_237_000 as Weight).saturating_mul(u as Weight))
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(u as Weight)))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(u as Weight)))
}
}
93 changes: 62 additions & 31 deletions runtime/mandala/src/benchmarking/dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,32 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{
dollar, AccountId, Balance, Currencies, CurrencyId, Dex, GetNativeCurrencyId, GetStableCurrencyId, Runtime,
TradingPathLimit,
dollar, AccountId, Balance, Currencies, CurrencyId, Dex, Event, GetLiquidCurrencyId, GetNativeCurrencyId,
GetStableCurrencyId, GetStakingCurrencyId, Runtime, System, TradingPathLimit,
};

use frame_benchmarking::{account, whitelisted_caller};
use frame_system::RawOrigin;
use module_dex::TradingPairStatus;
use orml_benchmarking::runtime_benchmarks;
use orml_traits::MultiCurrencyExtended;
use orml_traits::{MultiCurrency, MultiCurrencyExtended};
use primitives::TradingPair;
use runtime_common::{BNC, RENBTC, VSKSM};
use sp_runtime::traits::UniqueSaturatedInto;
use sp_std::prelude::*;

const SEED: u32 = 0;

const NATIVE: CurrencyId = GetNativeCurrencyId::get();
const STABLECOIN: CurrencyId = GetStableCurrencyId::get();
const LIQUID: CurrencyId = GetLiquidCurrencyId::get();
const STAKING: CurrencyId = GetStakingCurrencyId::get();

const CURRENCY_LIST: [CurrencyId; 7] = [NATIVE, STABLECOIN, LIQUID, STAKING, BNC, VSKSM, RENBTC];

fn assert_last_event(generic_event: Event) {
System::assert_last_event(generic_event.into());
}

fn inject_liquidity(
maker: AccountId,
Expand Down Expand Up @@ -80,6 +89,9 @@ runtime_benchmarks! {
Dex::disable_trading_pair(RawOrigin::Root.into(), trading_pair.first(), trading_pair.second())?;
}
}: _(RawOrigin::Root, trading_pair.first(), trading_pair.second())
verify {
assert_last_event(module_dex::Event::EnableTradingPair(trading_pair).into());
}

// disable a Enabled trading pair
disable_trading_pair {
Expand All @@ -88,6 +100,9 @@ runtime_benchmarks! {
Dex::enable_trading_pair(RawOrigin::Root.into(), trading_pair.first(), trading_pair.second())?;
}
}: _(RawOrigin::Root, trading_pair.first(), trading_pair.second())
verify {
assert_last_event(module_dex::Event::DisableTradingPair(trading_pair).into());
}

// list a Provisioning trading pair
list_provisioning {
Expand All @@ -96,6 +111,9 @@ runtime_benchmarks! {
Dex::disable_trading_pair(RawOrigin::Root.into(), trading_pair.first(), trading_pair.second())?;
}
}: _(RawOrigin::Root, trading_pair.first(), trading_pair.second(), dollar(trading_pair.first()), dollar(trading_pair.second()), dollar(trading_pair.first()), dollar(trading_pair.second()), 10)
verify {
assert_last_event(module_dex::Event::ListProvisioning(trading_pair).into());
}

// update parameters of a Provisioning trading pair
update_provisioning_parameters {
Expand Down Expand Up @@ -146,6 +164,9 @@ runtime_benchmarks! {
100 * dollar(trading_pair.second()),
)?;
}: _(RawOrigin::Signed(founder), trading_pair.first(), trading_pair.second())
verify {
assert_last_event(module_dex::Event::ProvisioningToEnabled(trading_pair, 100 * dollar(trading_pair.first()), 100 * dollar(trading_pair.second()), 200 * dollar(trading_pair.first())).into())
}

add_provision {
let founder: AccountId = whitelisted_caller();
Expand All @@ -167,7 +188,10 @@ runtime_benchmarks! {
// set balance
<Currencies as MultiCurrencyExtended<_>>::update_balance(trading_pair.first(), &founder, (10 * dollar(trading_pair.first())).unique_saturated_into())?;
<Currencies as MultiCurrencyExtended<_>>::update_balance(trading_pair.second(), &founder, (10 * dollar(trading_pair.second())).unique_saturated_into())?;
}: _(RawOrigin::Signed(founder), trading_pair.first(), trading_pair.second(), dollar(trading_pair.first()), dollar(trading_pair.second()))
}: _(RawOrigin::Signed(founder.clone()), trading_pair.first(), trading_pair.second(), dollar(trading_pair.first()), dollar(trading_pair.second()))
verify{
assert_last_event(module_dex::Event::AddProvision(founder, trading_pair.first(), dollar(trading_pair.first()), trading_pair.second(), dollar(trading_pair.second())).into());
}

claim_dex_share {
let founder: AccountId = whitelisted_caller();
Expand Down Expand Up @@ -202,7 +226,10 @@ runtime_benchmarks! {
trading_pair.first(),
trading_pair.second(),
)?;
}: _(RawOrigin::Signed(whitelisted_caller()), founder, trading_pair.first(), trading_pair.second())
}: _(RawOrigin::Signed(whitelisted_caller()), founder.clone(), trading_pair.first(), trading_pair.second())
verify {
assert_eq!(Currencies::free_balance(trading_pair.dex_share_currency_id(), &founder), 2_000_000_000_000);
}

// add liquidity but don't staking lp
add_liquidity {
Expand Down Expand Up @@ -253,52 +280,56 @@ runtime_benchmarks! {
swap_with_exact_supply {
let u in 2 .. TradingPathLimit::get() as u32;

let trading_pair = TradingPair::from_currency_ids(STABLECOIN, NATIVE).unwrap();
let maker: AccountId = account("maker", 0, SEED);
let taker: AccountId = whitelisted_caller();

let mut path: Vec<CurrencyId> = vec![];
for i in 1 .. u {
if i == 1 {
path.push(trading_pair.first());
path.push(trading_pair.second());
let cur0 = CURRENCY_LIST[0];
let cur1 = CURRENCY_LIST[1];
path.push(cur0);
path.push(cur1);
inject_liquidity(maker.clone(), cur0, cur1, 10_000 * dollar(cur0), 10_000 * dollar(cur1), false)?;
} else {
if i % 2 == 0 {
path.push(trading_pair.first());
} else {
path.push(trading_pair.second());
}
path.push(CURRENCY_LIST[i as usize]);
inject_liquidity(maker.clone(), CURRENCY_LIST[i as usize - 1], CURRENCY_LIST[i as usize], 10_000 * dollar(CURRENCY_LIST[i as usize - 1]), 10_000 * dollar(CURRENCY_LIST[i as usize]), false)?;
}
}

let maker: AccountId = account("maker", 0, SEED);
let taker: AccountId = whitelisted_caller();
inject_liquidity(maker, trading_pair.first(), trading_pair.second(), 10_000 * dollar(trading_pair.first()), 10_000 * dollar(trading_pair.second()), false)?;

<Currencies as MultiCurrencyExtended<_>>::update_balance(path[0], &taker, (10_000 * dollar(path[0])).unique_saturated_into())?;
}: swap_with_exact_supply(RawOrigin::Signed(taker), path.clone(), 100 * dollar(path[0]), 0)
}: swap_with_exact_supply(RawOrigin::Signed(taker.clone()), path.clone(), 100 * dollar(path[0]), 0)
verify {
// would panic the benchmark anyways, must add new currencies to CURRENCY_LIST for benchmarking to work
assert!(TradingPathLimit::get() < CURRENCY_LIST.len() as u32);
}

swap_with_exact_target {
let u in 2 .. TradingPathLimit::get() as u32;

let trading_pair = TradingPair::from_currency_ids(STABLECOIN, NATIVE).unwrap();
let maker: AccountId = account("maker", 0, SEED);
let taker: AccountId = whitelisted_caller();

let mut path: Vec<CurrencyId> = vec![];
for i in 1 .. u {
if i == 1 {
path.push(trading_pair.first());
path.push(trading_pair.second());
let cur0 = CURRENCY_LIST[0];
let cur1 = CURRENCY_LIST[1];
path.push(cur0);
path.push(cur1);
inject_liquidity(maker.clone(), cur0, cur1, 10_000 * dollar(cur0), 10_000 * dollar(cur1), false)?;
} else {
if i % 2 == 0 {
path.push(trading_pair.first());
} else {
path.push(trading_pair.second());
}
path.push(CURRENCY_LIST[i as usize]);
inject_liquidity(maker.clone(), CURRENCY_LIST[i as usize - 1], CURRENCY_LIST[i as usize], 10_000 * dollar(CURRENCY_LIST[i as usize - 1]), 10_000 * dollar(CURRENCY_LIST[i as usize]), false)?;
}
}

let maker: AccountId = account("maker", 0, SEED);
let taker: AccountId = whitelisted_caller();
inject_liquidity(maker, trading_pair.first(), trading_pair.second(), 10_000 * dollar(trading_pair.first()), 10_000 * dollar(trading_pair.second()), false)?;

<Currencies as MultiCurrencyExtended<_>>::update_balance(path[0], &taker, (10_000 * dollar(path[0])).unique_saturated_into())?;
}: swap_with_exact_target(RawOrigin::Signed(taker), path.clone(), 10 * dollar(path[path.len() - 1]), 100 * dollar(path[0]))
}: swap_with_exact_target(RawOrigin::Signed(taker.clone()), path.clone(), 10 * dollar(path[path.len() - 1]), 100 * dollar(path[0]))
verify {
// would panic the benchmark anyways, must add new currencies to CURRENCY_LIST for benchmarking to work
assert!(TradingPathLimit::get() < CURRENCY_LIST.len() as u32);
}
}

#[cfg(test)]
Expand Down
Loading

0 comments on commit 9643104

Please sign in to comment.