Skip to content

Commit

Permalink
Merge branch 'master' of github.com:galacticcouncil/Basilisk-node int…
Browse files Browse the repository at this point in the history
…o apopiak/next-gen-oracle

# Conflicts:
#	Cargo.lock
#	integration-tests/Cargo.toml
#	integration-tests/parachain-runtime-mock/Cargo.toml
#	pallets/duster/Cargo.toml
#	pallets/lbp/Cargo.toml
#	pallets/marketplace/Cargo.toml
#	pallets/xyk-liquidity-mining/Cargo.toml
#	pallets/xyk-liquidity-mining/benchmarking/Cargo.toml
#	pallets/xyk/Cargo.toml
#	primitives/Cargo.toml
#	runtime/basilisk/Cargo.toml
#	runtime/common/Cargo.toml
#	runtime/testing-basilisk/Cargo.toml
  • Loading branch information
apopiak committed Jan 27, 2023
2 parents 48efdb3 + 3a7672d commit fe5a771
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
9 changes: 7 additions & 2 deletions pallets/xyk-liquidity-mining/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ pub mod pallet {

/// Asset is not in the `AssetPair`.
AssetNotInAssetPair,

/// Provided `AssetPair` is not used by the deposit.
InvalidAssetPair,
}

#[pallet::event]
Expand Down Expand Up @@ -732,17 +735,19 @@ pub mod pallet {
deposit_id: DepositId,
) -> DispatchResult {
let owner = Self::ensure_nft_owner(origin, deposit_id)?;
Self::ensure_xyk(asset_pair)?;
let amm_pool_id = Self::ensure_xyk(asset_pair)?;

let amm_share_token = T::AMM::get_share_token(asset_pair);

let shares_amount = T::LiquidityMiningHandler::redeposit_lp_shares(
let (shares_amount, deposit_amm_pool_id) = T::LiquidityMiningHandler::redeposit_lp_shares(
global_farm_id,
yield_farm_id,
deposit_id,
Self::get_token_value_of_lp_shares,
)?;

ensure!(amm_pool_id == deposit_amm_pool_id, Error::<T>::InvalidAssetPair);

Self::deposit_event(Event::SharesRedeposited {
global_farm_id,
yield_farm_id,
Expand Down
9 changes: 7 additions & 2 deletions pallets/xyk-liquidity-mining/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ pub const BSX_KSM_ASSET_PAIR: AssetPair = AssetPair {
asset_out: KSM,
};

pub const BSX_ACA_ASSET_PAIR: AssetPair = AssetPair {
asset_in: BSX,
asset_out: ACA,
};

pub const BSX_DOT_ASSET_PAIR: AssetPair = AssetPair {
asset_in: BSX,
asset_out: DOT,
Expand Down Expand Up @@ -663,7 +668,7 @@ impl hydradx_traits::liquidity_mining::Mutate<AccountId, AssetId, BlockNumber> f
yield_farm_id: u32,
deposit_id: u128,
get_token_value_of_lp_shares: fn(AssetId, Self::AmmPoolId, Balance) -> Result<Self::Balance, Self::Error>,
) -> Result<Self::Balance, Self::Error> {
) -> Result<(Self::Balance, Self::AmmPoolId), Self::Error> {
let deposit = DEPOSITS.with(|v| {
let mut p = v.borrow_mut();
let mut deposit = p.get_mut(&deposit_id).unwrap();
Expand Down Expand Up @@ -691,7 +696,7 @@ impl hydradx_traits::liquidity_mining::Mutate<AccountId, AssetId, BlockNumber> f
)
});

Ok(deposit.shares_amount)
Ok((deposit.shares_amount, deposit.amm_pool_id))
}

fn claim_rewards(
Expand Down
47 changes: 47 additions & 0 deletions pallets/xyk-liquidity-mining/src/tests/redeposit_shares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,50 @@ fn redeposit_shares_should_fail_when_nft_owner_is_not_found() {
);
})
}

#[test]
fn redeposit_shares_should_fail_when_asset_pair_is_not_in_the_deposit() {
ExtBuilder::default()
.with_endowed_accounts(vec![
(BOB, BSX, 1_000_000 * ONE),
(BOB, ACA, 1_000_000 * ONE),
(CHARLIE, BSX_KSM_SHARE_ID, 200 * ONE),
])
.with_amm_pool(BSX_KSM_AMM, BSX_KSM_SHARE_ID, BSX_KSM_ASSET_PAIR)
.with_amm_pool(BSX_ACA_AMM, BSX_ACA_SHARE_ID, BSX_ACA_ASSET_PAIR)
.with_global_farm(
500_000 * ONE,
20_000,
10,
BSX,
BSX,
ALICE,
Perquintill::from_percent(1),
ONE,
One::one(),
)
.with_global_farm(
500_000 * ONE,
20_000,
10,
BSX,
BSX,
BOB,
Perquintill::from_percent(1),
ONE,
One::one(),
)
.with_yield_farm(ALICE, 1, One::one(), None, BSX_KSM_ASSET_PAIR)
.with_yield_farm(BOB, 2, One::one(), None, BSX_KSM_ASSET_PAIR)
.with_deposit(CHARLIE, 1, 3, BSX_KSM_ASSET_PAIR, 100 * ONE)
.build()
.execute_with(|| {
set_block_number(50_000);

//Act
assert_noop!(
LiquidityMining::redeposit_shares(Origin::signed(CHARLIE), 2, 4, BSX_ACA_ASSET_PAIR, 1),
Error::<Test>::InvalidAssetPair
);
})
}

0 comments on commit fe5a771

Please sign in to comment.