Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
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
17 changes: 4 additions & 13 deletions frame/dex/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ benchmarks! {
let asset1 = MultiAssetId::Native;
let asset2 = MultiAssetId::Asset(0.into());
let (lp_token, caller, _) = create_asset_and_pool::<T>(asset1, asset2);
let deadline = T::BlockNumber::max_value();
}: _(SystemOrigin::Signed(caller.clone()), asset1, asset2, 10.into(), 10.into(), 10.into(), 10.into(), caller.clone(), deadline, false)
}: _(SystemOrigin::Signed(caller.clone()), asset1, asset2, 10.into(), 10.into(), 10.into(), 10.into(), caller.clone(), false)
verify {
let pool_id = (asset1, asset2);
assert_last_event::<T>(Event::LiquidityAdded {
Expand All @@ -132,7 +131,6 @@ benchmarks! {
let asset1 = MultiAssetId::Native;
let asset2 = MultiAssetId::Asset(0.into());
let (lp_token, caller, _) = create_asset_and_pool::<T>(asset1, asset2);
let deadline = T::BlockNumber::max_value();

Dex::<T>::add_liquidity(
SystemOrigin::Signed(caller.clone()).into(),
Expand All @@ -143,10 +141,9 @@ benchmarks! {
10.into(),
10.into(),
caller.clone(),
deadline,
false,
)?;
}: _(SystemOrigin::Signed(caller.clone()), asset1, asset2, 8.into(), 1.into(), 1.into(), caller.clone(), deadline)
}: _(SystemOrigin::Signed(caller.clone()), asset1, asset2, 8.into(), 1.into(), 1.into(), caller.clone())
verify {
let pool_id = (asset1, asset2);
assert_last_event::<T>(Event::LiquidityRemoved {
Expand All @@ -167,7 +164,6 @@ benchmarks! {
let (_, caller, _) = create_asset_and_pool::<T>(asset1, asset2);
let (_, _) = create_asset::<T>(asset3);
Dex::<T>::create_pool(SystemOrigin::Signed(caller.clone()).into(), asset2, asset3)?;
let deadline = T::BlockNumber::max_value();
let path: BoundedVec<_, T::MaxSwapPathLength> =
BoundedVec::try_from(vec![asset1, asset2, asset3]).unwrap();

Expand All @@ -180,7 +176,6 @@ benchmarks! {
10.into(),
10.into(),
caller.clone(),
deadline,
false,
)?;
Dex::<T>::add_liquidity(
Expand All @@ -192,10 +187,9 @@ benchmarks! {
10.into(),
10.into(),
caller.clone(),
deadline,
false,
)?;
}: _(SystemOrigin::Signed(caller.clone()), path.clone(), 500.into(), 80.into(), caller.clone(), deadline, false)
}: _(SystemOrigin::Signed(caller.clone()), path.clone(), 500.into(), 80.into(), caller.clone(), false)
verify {
let pool_id = (asset1, asset2);
assert_last_event::<T>(Event::SwapExecuted {
Expand All @@ -214,7 +208,6 @@ benchmarks! {
let (_, caller, _) = create_asset_and_pool::<T>(asset1, asset2);
let (_, _) = create_asset::<T>(asset3);
Dex::<T>::create_pool(SystemOrigin::Signed(caller.clone()).into(), asset2, asset3)?;
let deadline = T::BlockNumber::max_value();
let path: BoundedVec<_, T::MaxSwapPathLength> =
BoundedVec::try_from(vec![asset1, asset2, asset3]).unwrap();

Expand All @@ -227,7 +220,6 @@ benchmarks! {
10.into(),
10.into(),
caller.clone(),
deadline,
false,
)?;
Dex::<T>::add_liquidity(
Expand All @@ -239,10 +231,9 @@ benchmarks! {
10.into(),
10.into(),
caller.clone(),
deadline,
false,
)?;
}: _(SystemOrigin::Signed(caller.clone()), path.clone(), 100.into(), 1000.into(), caller.clone(), deadline, false)
}: _(SystemOrigin::Signed(caller.clone()), path.clone(), 100.into(), 1000.into(), caller.clone(), false)
verify {
let pool_id = (asset1, asset2);
assert_last_event::<T>(Event::SwapExecuted {
Expand Down
19 changes: 0 additions & 19 deletions frame/dex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,6 @@ pub mod pallet {
PoolExists,
/// Desired amount can't be zero.
WrongDesiredAmount,
/// The deadline has already passed.
DeadlinePassed,
/// The pool doesn't exist.
PoolNotFound,
/// An overflow happened.
Expand Down Expand Up @@ -291,7 +289,6 @@ pub mod pallet {
/// `mint_to` will be sent the liquidity tokens that represent this share of the pool.
/// `keep_alive` true will fail the transaction if in enacting the transaction
/// would take the sender's balance below the existential deposit.
/// `deadline` is the blocknumber until which you are happy for the transaction to occur.
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::add_liquidity())]
pub fn add_liquidity(
Expand All @@ -303,7 +300,6 @@ pub mod pallet {
amount1_min: AssetBalanceOf<T>,
amount2_min: AssetBalanceOf<T>,
mint_to: T::AccountId,
deadline: T::BlockNumber,
keep_alive: bool,
) -> DispatchResult {
let sender = ensure_signed(origin)?;
Expand All @@ -316,9 +312,6 @@ pub mod pallet {
Error::<T>::WrongDesiredAmount
);

let now = frame_system::Pallet::<T>::block_number();
ensure!(deadline >= now, Error::<T>::DeadlinePassed);

let maybe_pool = Pools::<T>::get(pool_id);
let pool = maybe_pool.as_ref().ok_or(Error::<T>::PoolNotFound)?;

Expand Down Expand Up @@ -399,7 +392,6 @@ pub mod pallet {
amount1_min_receive: AssetBalanceOf<T>,
amount2_min_receive: AssetBalanceOf<T>,
withdraw_to: T::AccountId,
deadline: T::BlockNumber,
) -> DispatchResult {
let sender = ensure_signed(origin)?;

Expand All @@ -408,9 +400,6 @@ pub mod pallet {

ensure!(lp_token_burn > Zero::zero(), Error::<T>::ZeroLiquidity);

let now = frame_system::Pallet::<T>::block_number();
ensure!(deadline >= now, Error::<T>::DeadlinePassed);

let maybe_pool = Pools::<T>::get(pool_id);
let pool = maybe_pool.as_ref().ok_or(Error::<T>::PoolNotFound)?;

Expand Down Expand Up @@ -469,7 +458,6 @@ pub mod pallet {
amount_in: AssetBalanceOf<T>,
amount_out_min: AssetBalanceOf<T>,
send_to: T::AccountId,
deadline: T::BlockNumber,
keep_alive: bool,
) -> DispatchResult {
let sender = ensure_signed(origin)?;
Expand All @@ -480,9 +468,6 @@ pub mod pallet {
);
ensure!(path.len() >= 2, Error::<T>::InvalidPath);

let now = frame_system::Pallet::<T>::block_number();
ensure!(deadline >= now, Error::<T>::DeadlinePassed);

let amounts = Self::get_amounts_out(&amount_in, &path)?;
let amount_out = *amounts.last().expect("Has always more than 1 element");
ensure!(amount_out >= amount_out_min, Error::<T>::InsufficientOutputAmount);
Expand Down Expand Up @@ -511,7 +496,6 @@ pub mod pallet {
amount_out: AssetBalanceOf<T>,
amount_in_max: AssetBalanceOf<T>,
send_to: T::AccountId,
deadline: T::BlockNumber,
keep_alive: bool,
) -> DispatchResult {
let sender = ensure_signed(origin)?;
Expand All @@ -522,9 +506,6 @@ pub mod pallet {
);
ensure!(path.len() >= 2, Error::<T>::InvalidPath);

let now = frame_system::Pallet::<T>::block_number();
ensure!(deadline >= now, Error::<T>::DeadlinePassed);

let amounts = Self::get_amounts_in(&amount_out, &path)?;
let amount_in = *amounts.first().expect("Always has more than one element");
ensure!(amount_in <= amount_in_max, Error::<T>::ExcessiveInputAmount);
Expand Down
Loading