Skip to content

Commit

Permalink
Merge branch 'master' into fix/staking-remove-vote
Browse files Browse the repository at this point in the history
  • Loading branch information
enthusiastmartin authored Nov 17, 2023
2 parents 6da651c + 60de95b commit 6ec3338
Show file tree
Hide file tree
Showing 58 changed files with 784 additions and 1,416 deletions.
359 changes: 176 additions & 183 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ members = [
'math',
'pallets/staking',
'pallets/democracy',
'runtime/hydradx/src/evm/evm-utility/macro',
]

[workspace.dependencies]
Expand Down Expand Up @@ -227,7 +228,7 @@ pallet-evm-chain-id = { git = "https://github.com/PureStake/frontier", branch =
pallet-evm-precompile-dispatch = { git = "https://github.com/PureStake/frontier", branch = "moonbeam-polkadot-v0.9.38", default-features = false }

# EVM from acala
module-evm-utility-macro = { git = "https://github.com/AcalaNetwork/Acala", branch = "release-acala-2.22.0", default-features = false }
module-evm-utility-macro = { path = "runtime/hydradx/src/evm/evm-utility/macro", default-features = false}

# Polkadot dependencies
pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38", default-features = false }
Expand Down
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.0"
version = "1.16.1"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
16 changes: 9 additions & 7 deletions integration-tests/src/circuit_breaker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,17 +578,19 @@ fn remove_liquidity_to_omnipool_should_not_fail_when_liquidity_limit_per_block_e
}

fn init_omnipool() {
assert_ok!(hydradx_runtime::Omnipool::set_tvl_cap(
assert_ok!(hydradx_runtime::Omnipool::add_token(
hydradx_runtime::RuntimeOrigin::root(),
222_222_000_000_000_000_000_000,
HDX,
FixedU128::from(1),
Permill::from_percent(100),
hydradx_runtime::Omnipool::protocol_account(),
));

assert_ok!(Omnipool::initialize_pool(
RawOrigin::Root.into(),
assert_ok!(hydradx_runtime::Omnipool::add_token(
hydradx_runtime::RuntimeOrigin::root(),
DAI,
FixedU128::from_float(0.00001), // adjust the amount of LRNA to roughly match the amount of LRNA that belongs to HDX. This way we can avoid MaxOutRatioExceeded error.
FixedU128::from(1),
Permill::from_percent(100),
Permill::from_percent(100)
hydradx_runtime::Omnipool::protocol_account(),
));

do_trading_activity_to_populate_oracle();
Expand Down
64 changes: 41 additions & 23 deletions integration-tests/src/dca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ mod omnipool {

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 @@ -134,6 +136,10 @@ mod omnipool {

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 @@ -490,6 +496,8 @@ mod omnipool {
//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 @@ -532,41 +540,39 @@ mod omnipool {
}

#[test]
fn sell_schedule_should_work_without_route() {
fn sell_schedule_execution_should_work_without_route() {
TestNet::reset();
Hydra::execute_with(|| {
//Arrange
init_omnipool_with_oracle_for_block_10();
let alice_init_hdx_balance = 5000 * UNITS;
assert_ok!(Balances::set_balance(
RuntimeOrigin::root(),
ALICE.into(),
alice_init_hdx_balance,
0,
));

let dca_budget = 1000 * UNITS;
let amount_to_sell = 700 * UNITS;

assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE);

let amount_in = 100 * UNITS;
let no_route = vec![];
let schedule1 =
schedule_fake_with_sell_order_with_route(ALICE, dca_budget, HDX, DAI, amount_to_sell, no_route);
schedule_fake_with_sell_order_with_route(ALICE.into(), dca_budget, HDX, DAI, amount_in, no_route);
create_schedule(ALICE, schedule1);

assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget);
assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE - dca_budget);
assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE);
assert_reserved_balance!(&ALICE.into(), HDX, dca_budget);
assert_balance!(&Treasury::account_id(), HDX, TREASURY_ACCOUNT_INIT_BALANCE);

//Act
run_to_block(11, 15);
set_relaychain_block_number(11);

//Assert
assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget);
assert_reserved_balance!(&ALICE.into(), HDX, 0);
let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE;

let schedule_id = 0;
let schedule = DCA::schedules(schedule_id);
assert!(schedule.is_none());
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 @@ -2227,8 +2233,6 @@ pub fn init_omnipol() {
let stable_price = FixedU128::from_float(0.7);
let acc = Omnipool::protocol_account();

assert_ok!(Omnipool::set_tvl_cap(RuntimeOrigin::root(), u128::MAX));

let stable_amount: Balance = 5_000_000_000_000_000_000_000u128;
let native_amount: Balance = 5_000_000_000_000_000_000_000u128;
assert_ok!(Tokens::set_balance(
Expand All @@ -2245,12 +2249,20 @@ pub fn init_omnipol() {
native_amount as i128,
));

assert_ok!(Omnipool::initialize_pool(
RuntimeOrigin::root(),
stable_price,
assert_ok!(hydradx_runtime::Omnipool::add_token(
hydradx_runtime::RuntimeOrigin::root(),
HDX,
native_price,
Permill::from_percent(60),
Permill::from_percent(60)
hydradx_runtime::Omnipool::protocol_account(),
));

assert_ok!(hydradx_runtime::Omnipool::add_token(
hydradx_runtime::RuntimeOrigin::root(),
DAI,
stable_price,
Permill::from_percent(60),
hydradx_runtime::Omnipool::protocol_account(),
));

assert_ok!(Balances::set_balance(
Expand Down Expand Up @@ -2447,3 +2459,9 @@ 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);
}
14 changes: 8 additions & 6 deletions integration-tests/src/dynamic_fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,17 +324,19 @@ fn init_omnipool() {
let native_price = FixedU128::from_inner(1201500000000000);
let stable_price = FixedU128::from_inner(45_000_000_000);

assert_ok!(hydradx_runtime::Omnipool::set_tvl_cap(
assert_ok!(hydradx_runtime::Omnipool::add_token(
hydradx_runtime::RuntimeOrigin::root(),
522_222_000_000_000_000_000_000,
HDX,
native_price,
Permill::from_percent(10),
hydradx_runtime::Omnipool::protocol_account(),
));

assert_ok!(hydradx_runtime::Omnipool::initialize_pool(
assert_ok!(hydradx_runtime::Omnipool::add_token(
hydradx_runtime::RuntimeOrigin::root(),
DAI,
stable_price,
native_price,
Permill::from_percent(100),
Permill::from_percent(10)
hydradx_runtime::Omnipool::protocol_account(),
));

let dot_price = FixedU128::from_inner(25_650_000_000_000_000_000);
Expand Down
16 changes: 11 additions & 5 deletions integration-tests/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,6 @@ pub fn init_omnipol() {
let stable_price = FixedU128::from_float(0.7);
let acc = hydradx_runtime::Omnipool::protocol_account();

assert_ok!(hydradx_runtime::Omnipool::set_tvl_cap(RuntimeOrigin::root(), u128::MAX));

let stable_amount: Balance = 5_000_000_000_000_000_000_000u128;
let native_amount: Balance = 5_000_000_000_000_000_000_000u128;
assert_ok!(Tokens::set_balance(
Expand All @@ -720,12 +718,20 @@ pub fn init_omnipol() {
native_amount as i128,
));

assert_ok!(hydradx_runtime::Omnipool::initialize_pool(
assert_ok!(hydradx_runtime::Omnipool::add_token(
hydradx_runtime::RuntimeOrigin::root(),
stable_price,
HDX,
native_price,
Permill::from_percent(60),
Permill::from_percent(60)
AccountId::from(ALICE),
));

assert_ok!(hydradx_runtime::Omnipool::add_token(
hydradx_runtime::RuntimeOrigin::root(),
DAI,
stable_price,
Permill::from_percent(60),
AccountId::from(ALICE),
));

assert_ok!(Balances::set_balance(
Expand Down
7 changes: 5 additions & 2 deletions integration-tests/src/omnipool_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ fn removing_token_should_work_when_no_shares_remaining() {
let bob_account = AccountId::from(UNKNOWN);
let dot_amount = 87_719_298_250_000_u128;

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

let token_price = FixedU128::from_inner(25_650_000_000_000_000_000);
assert_ok!(hydradx_runtime::Omnipool::add_token(
hydradx_runtime::RuntimeOrigin::root(),
Expand All @@ -289,10 +291,11 @@ fn removing_token_should_work_when_no_shares_remaining() {
));

let position =
pallet_omnipool::Pallet::<hydradx_runtime::Runtime>::load_position(0, bob_account.clone()).unwrap();
pallet_omnipool::Pallet::<hydradx_runtime::Runtime>::load_position(position_id, bob_account.clone())
.unwrap();
assert_ok!(hydradx_runtime::Omnipool::remove_liquidity(
hydradx_runtime::RuntimeOrigin::signed(UNKNOWN.into()),
0,
position_id,
position.shares,
));

Expand Down
15 changes: 8 additions & 7 deletions integration-tests/src/omnipool_liquidity_mining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,19 +542,20 @@ fn init_omnipool() {
let native_price = FixedU128::from_inner(1201500000000000);
let stable_price = FixedU128::from_inner(45_000_000_000);

assert_ok!(hydradx_runtime::Omnipool::set_tvl_cap(
assert_ok!(hydradx_runtime::Omnipool::add_token(
hydradx_runtime::RuntimeOrigin::root(),
u128::MAX,
HDX,
native_price,
Permill::from_percent(10),
hydradx_runtime::Omnipool::protocol_account(),
));

assert_ok!(hydradx_runtime::Omnipool::initialize_pool(
assert_ok!(hydradx_runtime::Omnipool::add_token(
hydradx_runtime::RuntimeOrigin::root(),
DAI,
stable_price,
native_price,
Permill::from_percent(100),
Permill::from_percent(10)
hydradx_runtime::Omnipool::protocol_account(),
));

let token_price = FixedU128::from_inner(25_650_000_000_000_000_000);

assert_ok!(hydradx_runtime::Omnipool::add_token(
Expand Down
27 changes: 22 additions & 5 deletions integration-tests/src/polkadot_test_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,17 +496,34 @@ pub fn init_omnipool() {
let native_price = FixedU128::from_inner(1201500000000000);
let stable_price = FixedU128::from_inner(45_000_000_000);

assert_ok!(hydradx_runtime::Omnipool::set_tvl_cap(
let native_position_id = hydradx_runtime::Omnipool::next_position_id();

assert_ok!(hydradx_runtime::Omnipool::add_token(
hydradx_runtime::RuntimeOrigin::root(),
522_222_000_000_000_000_000_000,
HDX,
native_price,
Permill::from_percent(10),
AccountId::from(ALICE),
));

assert_ok!(hydradx_runtime::Omnipool::initialize_pool(
let stable_position_id = hydradx_runtime::Omnipool::next_position_id();

assert_ok!(hydradx_runtime::Omnipool::add_token(
hydradx_runtime::RuntimeOrigin::root(),
DAI,
stable_price,
native_price,
Permill::from_percent(100),
Permill::from_percent(10)
AccountId::from(ALICE),
));

assert_ok!(hydradx_runtime::Omnipool::sacrifice_position(
hydradx_runtime::RuntimeOrigin::signed(ALICE.into()),
native_position_id,
));

assert_ok!(hydradx_runtime::Omnipool::sacrifice_position(
hydradx_runtime::RuntimeOrigin::signed(ALICE.into()),
stable_position_id,
));
}

Expand Down
2 changes: 1 addition & 1 deletion math/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = 'Apache-2.0'
name = "hydra-dx-math"
description = "A collection of utilities to make performing liquidity pool calculations more convenient."
repository = 'https://github.com/galacticcouncil/hydradx-math'
version = "7.6.2"
version = "7.6.3"

[dependencies]
primitive-types = {default-features = false, version = '0.12.0'}
Expand Down
9 changes: 5 additions & 4 deletions math/src/stableswap/tests/invariants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,11 @@ proptest! {
let result = calculate_shares_for_amount::<D_ITERATIONS>(&pool, 0, amount, amp, issuance, Permill::zero()).unwrap();

let received =
calculate_withdraw_one_asset::<D_ITERATIONS, Y_ITERATIONS>(&pool, result + 3_000 , 0, issuance, amp, Permill::zero())
calculate_withdraw_one_asset::<D_ITERATIONS, Y_ITERATIONS>(&pool, result, 0, issuance, amp, Permill::zero())
.unwrap();
assert!(received.0 >= amount);
let diff = received.0 - amount;
assert!(diff <= 5000)
// LP should not receive more than provided.
assert!(received.0 <= amount);
let diff = amount - received.0;
assert!(diff <= 1000)
}
}
2 changes: 1 addition & 1 deletion pallets/circuit-breaker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pallet-circuit-breaker"
version = "1.1.16"
version = "1.1.17"
authors = ["GalacticCouncil <hydradx@galacticcouncil.io>"]
edition = "2021"
license = "Apache-2.0"
Expand Down
Loading

0 comments on commit 6ec3338

Please sign in to comment.