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

fix: only adding shares created for new liquidity #945

Merged
merged 9 commits into from
Nov 7, 2024
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
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "runtime-integration-tests"
version = "1.25.0"
version = "1.25.1"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
7 changes: 7 additions & 0 deletions integration-tests/src/omnipool_liquidity_mining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,13 @@ fn add_liquidity_and_join_farms_should_work_for_multiple_farms() {
10_000 * UNITS as i128,
));

//Add some liquidiity to make sure that it does not interfere with the new liquidty add
assert_ok!(hydradx_runtime::Omnipool::add_liquidity(
RuntimeOrigin::signed(CHARLIE.into()),
ETH,
100 * UNITS,
));

let position_id = hydradx_runtime::Omnipool::next_position_id();

set_relaychain_block_number(400);
Expand Down
14 changes: 13 additions & 1 deletion integration-tests/src/xyk_liquidity_mining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,18 @@ fn add_liquidity_and_join_farms_should_work_with_multiple_farm_entries() {
10_000_0000 * UNITS as i128,
));

//Add some liquidity unrelated to make sure some existing shares are not effected
assert_ok!(XYK::add_liquidity(
RuntimeOrigin::signed(BOB.into()),
asset_pair.asset_in,
asset_pair.asset_out,
100 * UNITS,
100000 * UNITS
));

let existing_shares = 1000 * UNITS;
assert_eq!(Currencies::free_balance(xyk_share_id, &BOB.into()), existing_shares);

let farms = vec![
(global_farm_1_id, yield_farm_1_id),
(global_farm_2_id, yield_farm_2_id),
Expand Down Expand Up @@ -537,7 +549,7 @@ fn add_liquidity_and_join_farms_should_work_with_multiple_farm_entries() {

//assert LM deposit
assert_nft_owner!(hydradx_runtime::XYKLmCollectionId::get(), 1, BOB.into());
assert_eq!(Currencies::free_balance(xyk_share_id, &BOB.into()), Balance::zero());
assert_eq!(Currencies::free_balance(xyk_share_id, &BOB.into()), existing_shares); //User only have the shares they had before
assert_eq!(
Currencies::free_balance(xyk_share_id, &XYKLiquidityMining::account_id()),
50000000000000000000
Expand Down
2 changes: 1 addition & 1 deletion pallets/xyk-liquidity-mining/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pallet-xyk-liquidity-mining"
version = "1.3.0"
version = "1.3.1"
description = "Liquidity mining"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
9 changes: 3 additions & 6 deletions pallets/xyk-liquidity-mining/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub mod pallet {
/// AMM helper functions.
type AMM: AMM<Self::AccountId, AssetId, AssetPair, Balance>
+ AMMPosition<AssetId, Balance, Error = DispatchError>
+ AMMAddLiquidity<OriginFor<Self>, AssetId, Balance>;
+ AMMAddLiquidity<Self::AccountId, AssetId, Balance>;

/// The origin account that can create new liquidity mining program.
type CreateOrigin: EnsureOrigin<Self::RuntimeOrigin>;
Expand Down Expand Up @@ -809,12 +809,9 @@ pub mod pallet {
asset_out: asset_b,
};

T::AMM::add_liquidity(origin.clone(), asset_a, asset_b, amount_a, amount_b_max_limit)?;
let shares_added = T::AMM::add_liquidity(who, asset_a, asset_b, amount_a, amount_b_max_limit)?;

let share_token = T::AMM::get_share_token(asset_pair);
let shares_amount = T::Currencies::free_balance(share_token, &who);

Self::join_farms(origin, farm_entries, asset_pair, shares_amount)?;
Self::join_farms(origin, farm_entries, asset_pair, shares_added)?;

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn add_liquidity_and_join_farms_should_work() {
// Check if LP tokens are locked
assert_eq!(
Tokens::total_balance(BSX_KSM_SHARE_ID, &LiquidityMining::account_id()),
share_amount + LOCKED_XYK_ADD_LIQUIDITY_XYK_SHARE_AMOUNT
ADD_LIQUIDITY_XYK_SHARE_AMOUNT
);

// Check if NFT is minted
Expand All @@ -78,7 +78,7 @@ fn add_liquidity_and_join_farms_should_work() {
yield_farm_id: 4,
who: ALICE,
lp_token: BSX_KSM_SHARE_ID,
amount: share_amount,
amount: ADD_LIQUIDITY_XYK_SHARE_AMOUNT,
deposit_id: 1,
}
.into(),
Expand All @@ -87,7 +87,7 @@ fn add_liquidity_and_join_farms_should_work() {
yield_farm_id: 5,
who: ALICE,
lp_token: BSX_KSM_SHARE_ID,
amount: share_amount,
amount: ADD_LIQUIDITY_XYK_SHARE_AMOUNT,
deposit_id: 1,
}
.into(),
Expand All @@ -96,7 +96,7 @@ fn add_liquidity_and_join_farms_should_work() {
yield_farm_id: 6,
who: ALICE,
lp_token: BSX_KSM_SHARE_ID,
amount: share_amount,
amount: ADD_LIQUIDITY_XYK_SHARE_AMOUNT,
deposit_id: 1,
}
.into(),
Expand Down
25 changes: 7 additions & 18 deletions pallets/xyk-liquidity-mining/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,28 +354,17 @@ impl liq_mining::Config for Test {
type MaxFarmEntriesPerDeposit = MaxEntriesPerDeposit;
}

pub const LOCKED_XYK_ADD_LIQUIDITY_XYK_SHARE_AMOUNT: Balance = 20 * ONE;
pub const ADD_LIQUIDITY_XYK_SHARE_AMOUNT: Balance = 20 * ONE;

impl AMMAddLiquidity<OriginFor<Test>, AssetId, Balance> for DummyAMM {
impl AMMAddLiquidity<AccountId, AssetId, Balance> for DummyAMM {
fn add_liquidity(
_origin: OriginFor<Test>,
asset_a: AssetId,
asset_b: AssetId,
_origin: AccountId,
_asset_a: AssetId,
_asset_b: AssetId,
_amount_a: Balance,
_amount_b_max_limit: Balance,
) -> DispatchResult {
let asset_pair = AssetPair {
asset_in: asset_a,
asset_out: asset_b,
};
let share_token = DummyAMM::get_share_token(asset_pair);

Tokens::deposit(
share_token,
&LiquidityMining::account_id(),
LOCKED_XYK_ADD_LIQUIDITY_XYK_SHARE_AMOUNT,
)?;
Ok(())
) -> Result<Balance, DispatchError> {
Ok(ADD_LIQUIDITY_XYK_SHARE_AMOUNT)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pallets/xyk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = 'pallet-xyk'
version = "6.6.1"
version = "6.6.2"
description = 'XYK automated market maker'
authors = ['GalacticCouncil']
edition = '2021'
Expand Down
Loading
Loading