-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Dzmitry Lahoda <dzmitry@lahoda.pro>
- Loading branch information
1 parent
a150c48
commit 066226f
Showing
19 changed files
with
393 additions
and
92 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
use super::*; | ||
use crate::Pallet as DutchAuction; | ||
use codec::Decode; | ||
use composable_traits::defi::{CurrencyPair, DeFiComposableConfig, Sell, Take}; | ||
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller}; | ||
use frame_support::traits::{fungibles::Mutate, Hooks}; | ||
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin}; | ||
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 pair = assets::<T>(); | ||
Sell::new(pair.base, pair.quote, one, 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) | ||
} | ||
|
||
pub type AssetIdOf<T> = <T as DeFiComposableConfig>::MayBeAssetId; | ||
|
||
fn assets<T>() -> CurrencyPair<AssetIdOf<T>> | ||
where | ||
T: Config, | ||
{ | ||
let a = 0u128.to_be_bytes(); | ||
let b = 1u128.to_be_bytes(); | ||
CurrencyPair::new( | ||
AssetIdOf::<T>::decode(&mut &a[..]).unwrap(), | ||
AssetIdOf::<T>::decode(&mut &b[..]).unwrap(), | ||
) | ||
} | ||
|
||
benchmarks! { | ||
where_clause { | ||
where | ||
<T as Config>::MultiCurrency: | ||
Mutate<T::AccountId, Balance = T::Balance, AssetId = T::MayBeAssetId>, | ||
} | ||
ask { | ||
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(); | ||
<T as pallet::Config>::MultiCurrency::mint_into(sell.pair.base, &account_id, amount).unwrap(); | ||
}: _( | ||
caller, | ||
sell, | ||
<_>::default() | ||
) | ||
take { | ||
let x in 1..2^16; | ||
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(); | ||
<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>(); | ||
for i in 0..x { | ||
DutchAuction::<T>::take(caller.clone().into(), order_id, take_order.clone()).unwrap(); | ||
} | ||
}: _( | ||
caller, | ||
order_id, | ||
take_order | ||
) | ||
liquidate { | ||
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(); | ||
<T as pallet::Config>::MultiCurrency::mint_into(sell.pair.base, &account_id, amount).unwrap(); | ||
DutchAuction::<T>::ask(caller.clone().into(), sell, <_>::default()).unwrap(); | ||
let order_id = OrdersIndex::<T>::get(); | ||
}: _( | ||
caller, | ||
order_id | ||
) | ||
known_overhead_for_on_finalize { | ||
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(); | ||
|
||
<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> as Hooks<BlockNumberFor<T>>>::on_finalize(T::BlockNumber::default()) | ||
} | ||
|
||
} | ||
|
||
impl_benchmark_test_suite!( | ||
DutchAuction, | ||
crate::mock::runtime::new_test_externalities(), | ||
crate::mock::runtime::Runtime, | ||
); |
Oops, something went wrong.