Skip to content

Commit

Permalink
Merge pull request #160 from galacticcouncil/feat/lbp_sim_test
Browse files Browse the repository at this point in the history
feat(lbp): add simulation test
  • Loading branch information
mrq1911 authored Sep 28, 2021
2 parents 4a5c63d + bd59140 commit 41f2391
Show file tree
Hide file tree
Showing 2 changed files with 256 additions and 94 deletions.
19 changes: 10 additions & 9 deletions pallets/lbp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use codec::{Decode, Encode};
use frame_support::sp_runtime::{
app_crypto::sp_core::crypto::UncheckedFrom,
traits::{AtLeast32BitUnsigned, Hash, Zero, Saturating},
traits::{AtLeast32BitUnsigned, Hash, Saturating, Zero},
DispatchError, RuntimeDebug,
};
use frame_support::{
Expand Down Expand Up @@ -77,7 +77,10 @@ pub struct Pool<AccountId, BlockNumber: AtLeast32BitUnsigned + Copy> {
pub fee_receiver: AccountId,
}

fn get_sorted_assets(asset_a: LBPAssetInfo<Balance>, asset_b: LBPAssetInfo<Balance>) -> (LBPAssetInfo<Balance>, LBPAssetInfo<Balance>) {
fn get_sorted_assets(
asset_a: LBPAssetInfo<Balance>,
asset_b: LBPAssetInfo<Balance>,
) -> (LBPAssetInfo<Balance>, LBPAssetInfo<Balance>) {
if asset_a.id < asset_b.id {
(asset_a, asset_b)
} else {
Expand Down Expand Up @@ -412,7 +415,7 @@ pub mod pallet {
fee,
fee_receiver,
);

Self::validate_pool_data(&pool_data)?;

let pool_id = Self::get_pair_id(asset_pair);
Expand Down Expand Up @@ -463,7 +466,7 @@ pub mod pallet {

let (start, end) = match duration {
Some((start, end)) => (Some(start), Some(end)),
_ => (None, None)
_ => (None, None),
};

ensure!(
Expand Down Expand Up @@ -784,7 +787,8 @@ impl<T: Config> Pallet<T> {
let now = <frame_system::Pallet<T>>::block_number();

ensure!(
(pool_data.start.is_zero() && pool_data.end.is_zero()) || (now <= pool_data.start && pool_data.start < pool_data.end),
(pool_data.start.is_zero() && pool_data.end.is_zero())
|| (now <= pool_data.start && pool_data.start < pool_data.end),
Error::<T>::InvalidBlockNumber
);

Expand All @@ -804,10 +808,7 @@ impl<T: Config> Pallet<T> {
Error::<T>::ZeroWeight
);

ensure!(
!pool_data.fee.denominator.is_zero(),
Error::<T>::FeeAmountInvalid
);
ensure!(!pool_data.fee.denominator.is_zero(), Error::<T>::FeeAmountInvalid);

Ok(())
}
Expand Down
Loading

0 comments on commit 41f2391

Please sign in to comment.