Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clippy fixes #779

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 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
27 changes: 7 additions & 20 deletions pallets/ceres-liquidity-locker/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! Ceres liquidity locker module benchmarking.

#![cfg_attr(not(feature = "std"), no_std)]
// TODO #167: fix clippy warnings
#![allow(clippy::all)]

use ceres_liquidity_locker::AccountIdOf;
use codec::Decode;
Expand Down Expand Up @@ -85,30 +83,19 @@ fn setup_benchmark_assets_only<T: Config>() -> Result<(), &'static str> {
None,
);

TradingPair::<T>::register(
owner_origin.clone(),
DEX.into(),
XOR.into(),
ceres_asset_id.into(),
)
.unwrap();

Assets::<T>::mint_to(&XOR.into(), &owner.clone(), &owner.clone(), balance!(50000))?;
Assets::<T>::mint_to(
&ceres_asset_id.into(),
&owner.clone(),
&owner.clone(),
balance!(50000),
)?;
TradingPair::<T>::register(owner_origin, DEX.into(), XOR.into(), ceres_asset_id.into())
.unwrap();

Assets::<T>::mint_to(&XOR.into(), &owner, &owner, balance!(50000))?;
Assets::<T>::mint_to(&ceres_asset_id.into(), &owner, &owner, balance!(50000))?;

Ok(())
}

fn setup_benchmark<T: Config>() -> Result<(), &'static str> {
let owner = alice::<T>();
frame_system::Pallet::<T>::inc_providers(&owner);
let owner_origin: <T as frame_system::Config>::RuntimeOrigin =
RawOrigin::Signed(owner.clone()).into();
let owner_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(owner).into();
let ceres_asset_id = common::AssetId32::from_bytes(hex!(
"008bcfd2387d3fc453333557eecb0efe59fcba128769b2feefdd306e98e66440"
));
Expand All @@ -123,7 +110,7 @@ fn setup_benchmark<T: Config>() -> Result<(), &'static str> {
)?;

XYKPool::<T>::deposit_liquidity(
owner_origin.clone(),
owner_origin,
DEX.into(),
XOR.into(),
ceres_asset_id.into(),
Expand Down
3 changes: 1 addition & 2 deletions pallets/ceres-liquidity-locker/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use currencies::BasicCurrencyAdapter;

use frame_support::traits::{Everything, GenesisBuild};
use frame_support::{construct_runtime, parameter_types};
use frame_system;

use common::prelude::Balance;
use frame_system::pallet_prelude::BlockNumberFor;
Expand Down Expand Up @@ -42,7 +41,7 @@ parameter_types! {
pub GetPswapDistributionAccountId: AccountId = AccountId32::from([3; 32]);
pub const GetDefaultSubscriptionFrequency: BlockNumber = 10;
pub const GetBurnUpdateFrequency: BlockNumber = 14400;
pub GetIncentiveAssetId: AssetId = common::PSWAP.into();
pub GetIncentiveAssetId: AssetId = common::PSWAP;
pub GetParliamentAccountId: AccountId = AccountId32::from([8; 32]);
pub GetXykFee: Fixed = fixed!(0.003);
pub const MinimumPeriod: u64 = 5;
Expand Down
44 changes: 19 additions & 25 deletions pallets/ceres-liquidity-locker/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#![cfg_attr(not(feature = "std"), no_std)]
// TODO #167: fix clippy warnings
#![allow(clippy::all)]

#[cfg(test)]
mod mock;
Expand Down Expand Up @@ -229,10 +227,11 @@ pub mod pallet {
let mut locked_pool_tokens = 0;

for locks in lockups.iter() {
if locks.asset_a == asset_a && locks.asset_b == asset_b {
if current_timestamp < locks.unlocking_timestamp {
locked_pool_tokens = locked_pool_tokens + locks.pool_tokens;
}
if locks.asset_a == asset_a
&& locks.asset_b == asset_b
&& current_timestamp < locks.unlocking_timestamp
{
locked_pool_tokens += locks.pool_tokens;
}
}

Expand All @@ -257,7 +256,7 @@ pub mod pallet {
} else {
// Transfer CERES fee amount
Assets::<T>::transfer_from(
&T::CeresAssetId::get().into(),
&T::CeresAssetId::get(),
&user,
&FeesOptionTwoAccount::<T>::get(),
FeesOptionTwoCeresAmount::<T>::get(),
Expand All @@ -274,8 +273,8 @@ pub mod pallet {
)?;
}

pool_tokens = T::XYKPool::balance_of_pool_provider(pool_account.clone(), user.clone())
.unwrap_or(0);
pool_tokens =
T::XYKPool::balance_of_pool_provider(pool_account, user.clone()).unwrap_or(0);
T::DemeterFarmingPlatform::update_pool_tokens(
user.clone(),
pool_tokens,
Expand Down Expand Up @@ -367,7 +366,7 @@ pub mod pallet {
withdrawing_amount: Balance,
) -> bool {
// Get lock info of extrinsic caller
let lockups = <LockerData<T>>::get(&user);
let lockups = <LockerData<T>>::get(user);
let current_timestamp = Timestamp::<T>::get();

// Get pool account
Expand All @@ -380,27 +379,23 @@ pub mod pallet {

// Calculate number of pool tokens to be locked
let pool_tokens =
T::XYKPool::balance_of_pool_provider(pool_account.clone(), user.clone())
.unwrap_or(0);
T::XYKPool::balance_of_pool_provider(pool_account, user.clone()).unwrap_or(0);
if pool_tokens == 0 {
return false;
}

let mut locked_pool_tokens = 0;
for locks in lockups.iter() {
if locks.asset_a == asset_a && locks.asset_b == asset_b {
if current_timestamp < locks.unlocking_timestamp {
locked_pool_tokens = locked_pool_tokens + locks.pool_tokens;
}
if locks.asset_a == asset_a
&& locks.asset_b == asset_b
&& current_timestamp < locks.unlocking_timestamp
{
locked_pool_tokens += locks.pool_tokens;
}
}
let unlocked_pool_tokens = pool_tokens.checked_sub(locked_pool_tokens).unwrap_or(0);
let unlocked_pool_tokens = pool_tokens.saturating_sub(locked_pool_tokens);

if withdrawing_amount > pool_tokens || unlocked_pool_tokens >= withdrawing_amount {
true
} else {
false
}
withdrawing_amount > pool_tokens || unlocked_pool_tokens >= withdrawing_amount
}

/// Pay Locker fees in LP tokens
Expand All @@ -423,15 +418,14 @@ pub mod pallet {
FeesOptionTwoAccount::<T>::get()
};

let result = T::XYKPool::transfer_lp_tokens(
T::XYKPool::transfer_lp_tokens(
pool_account,
asset_a,
asset_b,
user,
fee_account,
pool_tokens,
);
return result;
)
}
}
}
14 changes: 7 additions & 7 deletions pallets/ceres-liquidity-locker/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use currencies::BasicCurrencyAdapter;
use frame_support::traits::{Everything, GenesisBuild, Hooks};
use frame_support::weights::Weight;
use frame_support::{construct_runtime, parameter_types};
use frame_system;

use hex_literal::hex;
use orml_traits::parameter_type_with_key;
use permissions::{Scope, MANAGE_DEX};
Expand Down Expand Up @@ -44,8 +44,8 @@ parameter_types! {
pub const MaximumBlockWeight: Weight = Weight::from_parts(1024, 0);
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
pub GetBaseAssetId: AssetId = common::AssetId32::from_bytes(hex!("0200000000000000000000000000000000000000000000000000000000000000").into());
pub GetIncentiveAssetId: AssetId = common::AssetId32::from_bytes(hex!("0200050000000000000000000000000000000000000000000000000000000000").into());
pub GetBaseAssetId: AssetId = common::AssetId32::from_bytes(hex!("0200000000000000000000000000000000000000000000000000000000000000"));
pub GetIncentiveAssetId: AssetId = common::AssetId32::from_bytes(hex!("0200050000000000000000000000000000000000000000000000000000000000"));
pub const ExistentialDeposit: u128 = 0;
pub GetPswapDistributionAccountId: AccountId = 3u128;
pub const GetDefaultSubscriptionFrequency: BlockNumber = 10;
Expand Down Expand Up @@ -289,14 +289,14 @@ impl Default for ExtBuilder {
initial_dex_list: vec![(
DEX_A_ID,
DEXInfo {
base_asset_id: XOR.into(),
synthetic_base_asset_id: XST.into(),
base_asset_id: XOR,
synthetic_base_asset_id: XST,
is_public: true,
},
)],
endowed_accounts: vec![
(ALICE(), CERES_ASSET_ID.into(), balance!(2000)),
(BOB(), CERES_ASSET_ID.into(), balance!(1000)),
(ALICE(), CERES_ASSET_ID, balance!(2000)),
(BOB(), CERES_ASSET_ID, balance!(1000)),
],
initial_permission_owners: vec![(
MANAGE_DEX,
Expand Down
Loading