Skip to content

Commit

Permalink
Update benchmarks of pallet-dutch-auction
Browse files Browse the repository at this point in the history
  • Loading branch information
andor0 committed Jan 19, 2022
1 parent 7d42a23 commit 7ab3842
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions frame/dutch-auction/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
use super::*;
use crate::Pallet as DutchAuction;
use codec::Decode;
use composable_traits::defi::{CurrencyPair, DeFiComposableConfig, Sell, Take};
use composable_traits::defi::{CurrencyPair, DeFiComposableConfig, Ratio, Sell, Take};
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller};
use frame_support::traits::{fungibles::Mutate, Currency, Get, Hooks};
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
use sp_runtime::traits::{AccountIdConversion, Saturating};
use sp_runtime::{
traits::{AccountIdConversion, Saturating},
FixedPointNumber,
};
use sp_std::prelude::*;

// meaningless sell of 1 to 1
pub fn sell_identity<T: Config>(
) -> Sell<<T as DeFiComposableConfig>::MayBeAssetId, <T as DeFiComposableConfig>::Balance> {
let one: <T as DeFiComposableConfig>::Balance = 1u64.into();
let one: <T as DeFiComposableConfig>::Balance = 1_u64.into();
let pair = assets::<T>();
Sell::new(pair.base, pair.quote, one, one)
Sell::new(pair.base, pair.quote, one, Ratio::saturating_from_integer(one))
}

// meaningless take of 1 to 1
pub fn take_identity<T: Config>() -> Take<<T as DeFiComposableConfig>::Balance> {
let one: <T as DeFiComposableConfig>::Balance = 1u64.into();
Take::new(one, one)
let one: <T as DeFiComposableConfig>::Balance = 1_u64.into();
Take::new(one, Ratio::saturating_from_integer(one))
}

pub type AssetIdOf<T> = <T as DeFiComposableConfig>::MayBeAssetId;
Expand All @@ -28,8 +31,8 @@ fn assets<T>() -> CurrencyPair<AssetIdOf<T>>
where
T: Config,
{
let a = 0u128.to_be_bytes();
let b = 1u128.to_be_bytes();
let a = 0_u128.to_be_bytes();
let b = 1_u128.to_be_bytes();
CurrencyPair::new(
AssetIdOf::<T>::decode(&mut &a[..]).unwrap(),
AssetIdOf::<T>::decode(&mut &b[..]).unwrap(),
Expand All @@ -39,6 +42,8 @@ where
fn mint_native_tokens<T>(account_id: &T::AccountId)
where
T: Config,
<T as Config>::MultiCurrency:
Mutate<T::AccountId, Balance = T::Balance, AssetId = T::MayBeAssetId>,
{
let treasury = &T::PalletId::get().into_account();
let native_token_amount = <T as pallet::Config>::NativeCurrency::minimum_balance()
Expand All @@ -57,7 +62,7 @@ benchmarks! {
let sell = sell_identity::<T>();
let account_id : T::AccountId = whitelisted_caller();
let caller = RawOrigin::Signed(account_id.clone());
let amount: T::Balance = 1_000_000u64.into();
let amount: T::Balance = 1_000_000_000_000_u64.into();
mint_native_tokens::<T>(&account_id);
<T as pallet::Config>::MultiCurrency::mint_into(sell.pair.base, &account_id, amount).unwrap();
}: _(
Expand All @@ -69,7 +74,7 @@ benchmarks! {
let sell = sell_identity::<T>();
let account_id : T::AccountId = whitelisted_caller();
let caller = RawOrigin::Signed(account_id.clone());
let amount: T::Balance = 1_000_000u64.into();
let amount: T::Balance = 1_000_000_000_000_u64.into();
mint_native_tokens::<T>(&account_id);
<T as pallet::Config>::MultiCurrency::mint_into(sell.pair.base, &account_id, amount).unwrap();
<T as pallet::Config>::MultiCurrency::mint_into(sell.pair.quote, &account_id, amount).unwrap();
Expand All @@ -86,7 +91,7 @@ benchmarks! {
let sell = sell_identity::<T>();
let account_id : T::AccountId = whitelisted_caller();
let caller = RawOrigin::Signed(account_id.clone());
let amount: T::Balance = 1_000_000u64.into();
let amount: T::Balance = 1_000_000_000_000_u64.into();
mint_native_tokens::<T>(&account_id);
<T as pallet::Config>::MultiCurrency::mint_into(sell.pair.base, &account_id, amount).unwrap();
DutchAuction::<T>::ask(caller.clone().into(), sell, <_>::default()).unwrap();
Expand All @@ -99,14 +104,14 @@ benchmarks! {
let sell = sell_identity::<T>();
let account_id : T::AccountId = whitelisted_caller();
let caller = RawOrigin::Signed(account_id.clone());
let amount: T::Balance = 1_000_000u64.into();
let amount: T::Balance = 1_000_000_000_000_u64.into();
mint_native_tokens::<T>(&account_id);
<T as pallet::Config>::MultiCurrency::mint_into(sell.pair.base, &account_id, amount).unwrap();
<T as pallet::Config>::MultiCurrency::mint_into(sell.pair.quote, &account_id, amount).unwrap();
DutchAuction::<T>::ask(caller.clone().into(), sell, <_>::default()).unwrap();
let order_id = OrdersIndex::<T>::get();
let take_order = take_identity::<T>();
DutchAuction::<T>::take(caller.clone().into(), order_id, take_order.clone()).unwrap();
DutchAuction::<T>::take(caller.into(), order_id, take_order).unwrap();
} : {
<DutchAuction::<T> as Hooks<BlockNumberFor<T>>>::on_finalize(T::BlockNumber::default())
}
Expand Down

0 comments on commit 7ab3842

Please sign in to comment.