Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dmoka committed Oct 31, 2024
1 parent 305e948 commit 0adcd53
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
4 changes: 2 additions & 2 deletions integration-tests/src/xyk_liquidity_mining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ fn add_liquidity_and_join_farms_should_work_with_multiple_farm_entries() {
];
let deposit_id = 1;
let liquidity_amount = 5_000_000 * UNITS;
//Act
//Act
assert_ok!(XYKLiquidityMining::add_liquidity_and_join_farms(
RuntimeOrigin::signed(BOB.into()),
PEPE,
Expand Down Expand Up @@ -1203,7 +1203,7 @@ fn exit_farm_should_work_on_multiple_different_farms() {
(deposit_id, yield_farm_2_id, asset_pair),
(deposit_id2, yield_farm_3_id, asset_pair2),
];
//Act
//Act
assert_ok!(XYKLiquidityMining::exit_farms(
RuntimeOrigin::signed(DAVE.into()),
exit_entries.try_into().unwrap()
Expand Down
21 changes: 17 additions & 4 deletions pallets/xyk-liquidity-mining/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ type PeriodOf<T> = BlockNumberFor<T>;
pub mod pallet {
use super::*;
use frame_system::pallet_prelude::BlockNumberFor;
use hydradx_traits::AmmAddLiquidity;
use hydradx_traits::pools::DustRemovalAccountWhitelist;
use hydradx_traits::AmmAddLiquidity;

const STORAGE_VERSION: StorageVersion = StorageVersion::new(0);

Expand Down Expand Up @@ -709,7 +709,14 @@ pub mod pallet {
let who = ensure_signed(origin)?;
let amm_share_token = T::AMM::get_share_token(asset_pair);

Self::do_deposit_shares(who, global_farm_id, yield_farm_id, asset_pair,amm_share_token, shares_amount)?;
Self::do_deposit_shares(
who,
global_farm_id,
yield_farm_id,
asset_pair,
amm_share_token,
shares_amount,
)?;

Ok(())
}
Expand Down Expand Up @@ -740,8 +747,14 @@ pub mod pallet {

let (global_farm_id, yield_farm_id) = farm_entries.first().ok_or(Error::<T>::NoFarmsSpecified)?;
let amm_share_token = T::AMM::get_share_token(asset_pair);
let deposit_id =
Self::do_deposit_shares(who.clone(), *global_farm_id, *yield_farm_id, asset_pair, amm_share_token, shares_amount)?;
let deposit_id = Self::do_deposit_shares(
who.clone(),
*global_farm_id,
*yield_farm_id,
asset_pair,
amm_share_token,
shares_amount,
)?;

for (global_farm_id, yield_farm_id) in farm_entries.into_iter().skip(1) {
let (redeposited_amount, _) = T::LiquidityMiningHandler::redeposit_lp_shares(
Expand Down
2 changes: 1 addition & 1 deletion pallets/xyk-liquidity-mining/src/tests/join_farms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn join_farms_should_work_with_multiple_farm_pairs() {
set_block_number(1_800);
let deposited_amount = 50 * ONE;
let global_farm_2 = 2;
let farm_entries = vec![(BSX_FARM, 5), (BSX_FARM, 6), (BSX_FARM, 7), (global_farm_2,8)];
let farm_entries = vec![(BSX_FARM, 5), (BSX_FARM, 6), (BSX_FARM, 7), (global_farm_2, 8)];

// Act
assert_ok!(LiquidityMining::join_farms(
Expand Down
26 changes: 16 additions & 10 deletions pallets/xyk-liquidity-mining/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,16 +618,22 @@ impl hydradx_traits::liquidity_mining::Mutate<AccountId, AssetId, BlockNumber> f
) -> Result<u32, Self::Error> {
let farm_id = get_next_farm_id();

YIELD_FARMS.with(|v| {
let mut p = v.borrow_mut();
let yield_farm = p.iter_mut().find(|(_, farm)| farm.amm_pool_id == amm_pool_id && farm.global_farm_id == global_farm_id);

if yield_farm.is_some() {
return Err(sp_runtime::DispatchError::Other("Yield Farm already exists in global farm"));
}

Ok::<(), Self::Error>(())
}).unwrap();
YIELD_FARMS
.with(|v| {
let mut p = v.borrow_mut();
let yield_farm = p
.iter_mut()
.find(|(_, farm)| farm.amm_pool_id == amm_pool_id && farm.global_farm_id == global_farm_id);

if yield_farm.is_some() {
return Err(sp_runtime::DispatchError::Other(
"Yield Farm already exists in global farm",
));
}

Ok::<(), Self::Error>(())
})
.unwrap();

YIELD_FARMS.with(|v| {
v.borrow_mut().insert(
Expand Down

0 comments on commit 0adcd53

Please sign in to comment.