Skip to content

Commit

Permalink
Merge pull request #284 from nasqn/fix/change_xyk_pallet_errors
Browse files Browse the repository at this point in the history
fix(xyk)!: change xyk pallet errors
  • Loading branch information
enthusiastmartin authored Jun 28, 2021
2 parents e5692e3 + 04df8df commit 18b05cb
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

10 changes: 5 additions & 5 deletions pallets/exchange/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2261,7 +2261,7 @@ fn discount_tests_with_error() {
user_4_sell_intention_id,
DispatchError::Module {
index: 2,
error: 19,
error: 20,
message: None,
},
)
Expand All @@ -2276,7 +2276,7 @@ fn discount_tests_with_error() {
user_2_sell_intention_id,
DispatchError::Module {
index: 2,
error: 19,
error: 20,
message: None,
},
)
Expand All @@ -2291,7 +2291,7 @@ fn discount_tests_with_error() {
user_3_sell_intention_id,
DispatchError::Module {
index: 2,
error: 19,
error: 20,
message: None,
},
)
Expand Down Expand Up @@ -2880,7 +2880,7 @@ fn simple_sell_sell_with_error_should_not_pass() {
user_2_sell_intention_id,
DispatchError::Module {
index: 2,
error: 8,
error: 9,
message: None,
},
)
Expand All @@ -2895,7 +2895,7 @@ fn simple_sell_sell_with_error_should_not_pass() {
user_3_sell_intention_id,
DispatchError::Module {
index: 2,
error: 8,
error: 9,
message: None,
},
)
Expand Down
2 changes: 1 addition & 1 deletion pallets/xyk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ homepage = 'https://github.com/galacticcouncil/hydradx-node'
license = 'Apache 2.0'
name = 'pallet-xyk'
repository = 'https://github.com/galacticcouncil/hydradx-node'
version = '1.2.0'
version = '2.0.0'

[package.metadata.docs.rs]
targets = ['x86_64-unknown-linux-gnu']
Expand Down
13 changes: 8 additions & 5 deletions pallets/xyk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,11 @@ pub mod pallet {
/// Overflow
InvalidLiquidityAmount, // no tests

/// Given trading limit has been exceeded (Sell) or has Not been reached (buy).
AssetBalanceLimitExceeded,
/// Asset amount has exceeded given limit.
AssetAmountExceededLimit,

/// Asset amount has not reached given limit.
AssetAmountNotReachedLimit,

/// Asset balance is not sufficient.
InsufficientAssetBalance,
Expand Down Expand Up @@ -319,7 +322,7 @@ pub mod pallet {

ensure!(
amount_b_required <= amount_b_max_limit,
Error::<T>::AssetBalanceLimitExceeded
Error::<T>::AssetAmountExceededLimit
);

ensure!(shares_added > 0_u128, Error::<T>::InvalidMintedLiquidity);
Expand Down Expand Up @@ -626,7 +629,7 @@ impl<T: Config> AMM<T::AccountId, AssetId, AssetPair, Balance> for Pallet<T> {

ensure!(asset_out_reserve > amount_out, Error::<T>::InsufficientAssetBalance);

ensure!(min_bought <= amount_out_without_fee, Error::<T>::AssetBalanceLimitExceeded);
ensure!(min_bought <= amount_out_without_fee, Error::<T>::AssetAmountNotReachedLimit);

let discount_fee = if discount {
let native_asset = T::NativeAssetId::get();
Expand Down Expand Up @@ -753,7 +756,7 @@ impl<T: Config> AMM<T::AccountId, AssetId, AssetPair, Balance> for Pallet<T> {
.checked_add(transfer_fee)
.ok_or(Error::<T>::BuyAssetAmountInvalid)?;

ensure!(max_limit >= buy_price_with_fee, Error::<T>::AssetBalanceLimitExceeded);
ensure!(max_limit >= buy_price_with_fee, Error::<T>::AssetAmountExceededLimit);

ensure!(
T::Currency::free_balance(assets.asset_in, who) >= buy_price_with_fee,
Expand Down
6 changes: 3 additions & 3 deletions pallets/xyk/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ fn create_pool_with_same_assets_should_not_be_allowed() {
}

#[test]
fn sell_test_exceeding_max_limit() {
fn sell_test_not_reaching_limit() {
ExtBuilder::default().build().execute_with(|| {
let user_1 = ALICE;
let asset_a = ACA;
Expand Down Expand Up @@ -1087,7 +1087,7 @@ fn sell_test_exceeding_max_limit() {
1_000_000_000_000_000,
false,
),
Error::<Test>::AssetBalanceLimitExceeded
Error::<Test>::AssetAmountNotReachedLimit
);

assert_eq!(Currency::free_balance(asset_a, &user_1), 999800000000000);
Expand Down Expand Up @@ -1135,7 +1135,7 @@ fn buy_test_exceeding_max_limit() {
1_000_000_000,
false,
),
Error::<Test>::AssetBalanceLimitExceeded
Error::<Test>::AssetAmountExceededLimit
);

assert_eq!(Currency::free_balance(asset_a, &user_1), 999800000000000);
Expand Down

0 comments on commit 18b05cb

Please sign in to comment.