Skip to content

Commit

Permalink
Merge branch 'master' into feat/referrals-parachain
Browse files Browse the repository at this point in the history
  • Loading branch information
mrq1911 authored Jan 5, 2024
2 parents 3cba22f + 2248f6f commit 72a4bd3
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 51 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.

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.16.9"
version = "1.16.10"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
50 changes: 6 additions & 44 deletions integration-tests/src/dca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,12 @@ mod omnipool {

//Assert
let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE;
assert!(fee > 0, "Treasury got rugged");
let amount_in = 140421094431120;

assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE + amount_out);
assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE - dca_budget);
assert_reserved_balance!(&ALICE.into(), HDX, dca_budget - amount_in - fee);

let treasury_balance = Currencies::free_balance(HDX, &Treasury::account_id());
assert!(treasury_balance > TREASURY_ACCOUNT_INIT_BALANCE);

assert_that_fee_is_correct(fee);
});
}

Expand Down Expand Up @@ -140,18 +136,12 @@ mod omnipool {

//Assert
let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE;
assert!(fee > 0, "Treasury got rugged");
let amount_in = 140421094431120;

assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE + amount_out);
assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE - dca_budget);
assert_reserved_balance!(&ALICE.into(), HDX, dca_budget - amount_in - fee);

let treasury_balance = Currencies::free_balance(HDX, &Treasury::account_id());
assert!(treasury_balance > TREASURY_ACCOUNT_INIT_BALANCE);

//We make sure is that the default route is incorporated in the fee calculation
let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE;
assert_that_fee_is_correct(fee);
});
}

Expand Down Expand Up @@ -500,16 +490,11 @@ mod omnipool {
//Assert
let amount_out = 71_214_372_591_631;
let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE;
assert!(fee > 0, "Treasury got rugged");

assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE + amount_out);
assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget);
assert_reserved_balance!(&ALICE.into(), HDX, dca_budget - amount_to_sell - fee);

//Assert that fee is sent to treasury
let treasury_balance = Currencies::free_balance(HDX, &Treasury::account_id());
assert!(treasury_balance > TREASURY_ACCOUNT_INIT_BALANCE);

assert_that_fee_is_correct(fee);
});
}

Expand Down Expand Up @@ -578,13 +563,11 @@ mod omnipool {

//Assert
let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE;
assert!(fee > 0, "Treasury got rugged");

assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE - dca_budget);
assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE + 71214372591631);
assert_reserved_balance!(&ALICE.into(), HDX, dca_budget - amount_in - fee);

//We make sure is that the default route is incorporated in the fee calculation
assert_that_fee_is_correct(fee);
});
}

Expand Down Expand Up @@ -1005,7 +988,7 @@ mod omnipool {
init_omnipool_with_oracle_for_block_10();

//Trade 1
let amount_to_sell1 = 150 * UNITS;
let amount_to_sell1 = 200 * UNITS;
let dca_budget1 = 1000 * UNITS;
let schedule1 =
schedule_fake_with_sell_order(ALICE, PoolType::Omnipool, dca_budget1, HDX, DAI, amount_to_sell1);
Expand All @@ -1019,7 +1002,7 @@ mod omnipool {
create_schedule(ALICE, schedule2);

//Trade 3
let amount_to_sell3 = 300 * UNITS;
let amount_to_sell3 = 800 * UNITS;
let dca_budget3 = 2000 * UNITS;
let schedule3 =
schedule_fake_with_sell_order(ALICE, PoolType::Omnipool, dca_budget3, HDX, DAI, amount_to_sell3);
Expand All @@ -1035,11 +1018,6 @@ mod omnipool {

//Assert
assert_reserved_balance!(&ALICE.into(), HDX, 0);
assert_balance!(
ALICE.into(),
HDX,
alice_init_hdx_balance - dca_budget1 - dca_budget2 - dca_budget3
);

let schedule = DCA::schedules(0);
assert!(schedule.is_none());
Expand Down Expand Up @@ -2737,8 +2715,6 @@ mod with_onchain_route {
//Assert
let fee = Currencies::free_balance(DOT, &Treasury::account_id());
assert!(fee > 0, "The treasury did not receive the fee");
assert!(fee < 19 * UNITS);
assert!(fee > 18 * UNITS);

assert_balance!(ALICE.into(), DOT, alice_init_dot_balance - dca_budget);
assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE + 398004528624916);
Expand Down Expand Up @@ -2881,10 +2857,6 @@ mod with_onchain_route {
let fee = Currencies::free_balance(stable_asset_1, &Treasury::account_id());
assert!(fee > 0, "The treasury did not receive the fee");

//If the fee would be HDX, it would cost around 6503744780645
assert!(fee < 58 * UNITS / 10);
assert!(fee > 57 * UNITS / 10);

assert_balance!(ALICE.into(), stable_asset_1, alice_init_stable_balance - dca_budget);
assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance + 237185260073197);

Expand Down Expand Up @@ -3004,10 +2976,6 @@ mod with_onchain_route {
let fee = Currencies::free_balance(DOT, &Treasury::account_id());
assert!(fee > 0, "The treasury did not receive the fee");

//The fee would be 5310255478763 in HDX, so it is less in DOT, which checks out
assert!(fee < 40 * UNITS / 10);
assert!(fee > 36 * UNITS / 10);

assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance + 278060378846663);
assert_reserved_balance!(&ALICE.into(), DOT, dca_budget - amount_to_sell - fee);
});
Expand Down Expand Up @@ -3381,9 +3349,3 @@ pub fn init_stableswap_with_three_assets_having_different_decimals(

Ok((pool_id, asset_in, asset_out))
}

fn assert_that_fee_is_correct(fee: Balance) {
//The fee is approximately 3795361512418, so we check if we are between 3.5 and 4 UNITS
assert!(fee > 35 / 10 * UNITS);
assert!(fee < 4 * UNITS);
}
8 changes: 4 additions & 4 deletions integration-tests/src/referrals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ fn trading_in_omnipool_should_transfer_some_portion_of_fee_when_no_code_linked()
0
));
let pot_balance = Currencies::free_balance(DAI, &Referrals::pot_account_id());
assert_eq!(pot_balance, 28_540_796_051_302_770);
assert_eq!(pot_balance, 28_540_796_051_302_769);
let external_shares = Referrals::trader_shares::<AccountId>(Staking::pot_account_id());
let total_shares = Referrals::total_shares();
assert_eq!(total_shares, external_shares);
Expand Down Expand Up @@ -354,7 +354,7 @@ fn buying_hdx_in_omnipool_should_transfer_correct_fee() {
let ref_dai_balance = Currencies::free_balance(DAI, &ref_account);
let staking_balance = Currencies::free_balance(HDX, &staking_acc);
assert_eq!(ref_dai_balance.abs_diff(orig_balance), 0);
assert_eq!(staking_balance.abs_diff(stak_orig_balance), 2_650_003_961);
assert_eq!(staking_balance.abs_diff(stak_orig_balance), 2_650_003_960);
});
}

Expand Down Expand Up @@ -383,14 +383,14 @@ fn buying_with_hdx_in_omnipool_should_transfer_correct_fee() {
amount_out: 1_000_000_000_000_000_000,
hub_amount_in: 45219585307,
hub_amount_out: 45196975515,
asset_fee_amount: 2_575_616_759_455_039,
asset_fee_amount: 2_575_616_759_455_040,
protocol_fee_amount: 22609792,
}
.into()]);

let ref_dai_balance = Currencies::free_balance(DAI, &ref_account);
let staking_balance = Currencies::free_balance(HDX, &staking_acc);
assert_eq!(ref_dai_balance.abs_diff(orig_balance), 2_575_616_759_455_039 / 2);
assert_eq!(ref_dai_balance.abs_diff(orig_balance), 2_575_616_759_455_040 / 2 - 1);
assert_eq!(staking_balance.abs_diff(stak_orig_balance), 0);
});
}
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn staking_should_transfer_hdx_fees_to_pot_account_when_omnipool_trade_is_execut
));

let staking_account = pallet_staking::Pallet::<hydradx_runtime::Runtime>::pot_account_id();
assert_eq!(Currencies::free_balance(HDX, &staking_account), 1_093_580_529_360);
assert_eq!(Currencies::free_balance(HDX, &staking_account), 1_093_580_529_359);
});
}

Expand Down
1 change: 1 addition & 0 deletions pallets/omnipool/proptest-regressions/tests/invariants.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#cc f8078da4f7e354090cbce1f1a7385338da411cfc9b8e31660d006c18b233ebaf

0 comments on commit 72a4bd3

Please sign in to comment.