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

Bugfix/liq tokens mgx 434 v2 #603

Merged
merged 29 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
83e0f45
WIP state
majusko May 12, 2023
91c3de1
Removal of pools on liq burn is disabled. Validation for minting liqu…
majusko May 31, 2023
3c058de
Merge branch 'develop' into bugfix/liq-tokens-mgx-434
majusko May 31, 2023
d4636bc
Added a new case of initial liquidity calculation in case the total l…
majusko Jun 7, 2023
0d06e57
Put validation of amounts and liq asset minting before the transactions.
majusko Jun 9, 2023
8f6b436
WIP changes
majusko Jun 28, 2023
ccd66a7
Cleaned some code and resolved all compile issues.
majusko Jul 7, 2023
07351f1
Implemented unit test checking the if the pool is empty after burning…
majusko Aug 17, 2023
17035f3
Resolved merge conflicts.
majusko Aug 18, 2023
a2bc791
Fixed formatting
majusko Aug 18, 2023
a71d754
Fixed compile issues.
majusko Aug 18, 2023
151da2a
Formatting fix.
majusko Aug 18, 2023
446f531
Extended test case and fixed the removal of liquidity assets.
majusko Aug 23, 2023
eaa483d
Fixed formatting.
majusko Aug 23, 2023
8046f91
Merge branch 'develop' into bugfix/liq-tokens-mgx-434
majusko Aug 23, 2023
bbfdef9
Resolved types compile issues.
majusko Aug 23, 2023
c1bcd30
Formatting fix.
majusko Aug 23, 2023
0538dcf
Removed the GenericXYKResult and returning the vec instead.
majusko Aug 23, 2023
a9133c0
Fixed formatting
majusko Aug 23, 2023
cf1cdee
Align benchmarks.
majusko Aug 23, 2023
19f51ba
Merge branch 'develop' into bugfix/liq-tokens-mgx-434
majusko Aug 23, 2023
7ef8852
Merge branch 'develop' into bugfix/liq-tokens-mgx-434
majusko Sep 8, 2023
c0fab48
Added validation of pool existance to sell asset and added test cover…
majusko Sep 11, 2023
fba56a5
Fixed formatting.
majusko Sep 11, 2023
1522720
Added pool is empty validation on buy asset and added test case for it.
majusko Sep 12, 2023
17ae63c
Merged develop
majusko Sep 28, 2023
0a45b91
Validation for basic cases.
majusko Sep 28, 2023
1a2fcf8
Fmt on code.
majusko Sep 28, 2023
11a4749
Removed duplicated code after auto merging
majusko Sep 28, 2023
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: 8 additions & 0 deletions pallets/xyk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,8 @@ impl<T: Config> Pallet<T> {
let (input_reserve, output_reserve) =
Pallet::<T>::get_reserves(sold_token_id, bought_token_id)?;

ensure!(!(Self::is_pool_empty(sold_token_id, bought_token_id)?), Error::<T>::PoolIsEmpty);

Self::calculate_sell_price(input_reserve, output_reserve, sell_amount)
}

Expand All @@ -1352,6 +1354,8 @@ impl<T: Config> Pallet<T> {
let (input_reserve, output_reserve) =
Pallet::<T>::get_reserves(sold_token_id, bought_token_id)?;

ensure!(!(Self::is_pool_empty(sold_token_id, bought_token_id)?), Error::<T>::PoolIsEmpty);

Self::calculate_buy_price(input_reserve, output_reserve, buy_amount)
}

Expand Down Expand Up @@ -1407,6 +1411,8 @@ impl<T: Config> Pallet<T> {
let (first_asset_reserve, second_asset_reserve) =
Pallet::<T>::get_reserves(first_asset_id, second_asset_id)?;

ensure!(!(Self::is_pool_empty(first_asset_id, second_asset_id)?), Error::<T>::PoolIsEmpty);

let (first_asset_amount, second_asset_amount) = Self::get_burn_amount_reserves(
first_asset_reserve,
second_asset_reserve,
Expand Down Expand Up @@ -3061,6 +3067,8 @@ impl<T: Config> XykFunctionsTrait<T::AccountId> for Pallet<T> {
// checks
ensure!(!provided_asset_amount.is_zero(), Error::<T>::ZeroAmount,);

ensure!(!(Self::is_pool_empty(first_asset_id, second_asset_id)?), Error::<T>::PoolIsEmpty);

let (first_reserve, second_reserve) =
Pallet::<T>::get_reserves(first_asset_id, second_asset_id)?;

Expand Down
9 changes: 9 additions & 0 deletions pallets/xyk/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,15 @@ fn burn_all_liq_and_mint_it_again() {
Error::<Test>::PoolIsEmpty,
);

// calculate_buy_price_id should fail as pool is empty
assert_err!(XykStorage::calculate_buy_price_id(1, 4, 20000), Error::<Test>::PoolIsEmpty,);

// calculate_sell_price_id should fail as pool is empty
assert_err!(XykStorage::calculate_sell_price_id(1, 4, 20000), Error::<Test>::PoolIsEmpty,);

// get_burn_amount should fail as pool is empty
assert_err!(XykStorage::get_burn_amount(1, 4, 20000), Error::<Test>::PoolIsEmpty,);

let user_assets_1_value_after_sell = XykStorage::balance(1, DUMMY_USER_ID);
let user_assets_4_value_after_sell = XykStorage::balance(4, DUMMY_USER_ID);

Expand Down