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

feat: min liquidity limit in omnipool::add_token #783

Merged
merged 29 commits into from
Apr 26, 2024
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
055454f
add existential_deposit to Inspect trait and change min liquidity lim…
Roznovjak Mar 12, 2024
b68c758
remove comments and invalid reg test cases
Roznovjak Mar 12, 2024
b52d7b2
bump crate versions
Roznovjak Mar 12, 2024
04bfa6a
Merge branch 'master' into add_token_min_liquidity_limit
Roznovjak Mar 12, 2024
92e33d9
bump crate version
Roznovjak Mar 12, 2024
a1db468
update integration test
Roznovjak Mar 12, 2024
da2a550
formatting
Roznovjak Mar 12, 2024
b95ba8e
rerun tests
Roznovjak Mar 13, 2024
47a54bd
Merge branch 'master' into add_token_min_liquidity_limit
Roznovjak Mar 14, 2024
ab9d7d0
bump crate version
Roznovjak Mar 14, 2024
5f52ac9
Merge branch 'master' into add_token_min_liquidity_limit
Roznovjak Mar 18, 2024
9bcf88b
bump crate versions
Roznovjak Mar 18, 2024
a889c8a
Merge branch 'master' into add_token_min_liquidity_limit
Roznovjak Mar 19, 2024
8941852
bump runtime version
Roznovjak Mar 19, 2024
931a341
Merge branch 'master' into add_token_min_liquidity_limit
Roznovjak Mar 19, 2024
6630cff
bump crate versions
Roznovjak Mar 19, 2024
83a6b1f
bump crate version
Roznovjak Mar 19, 2024
3f8de65
rerun tests
Roznovjak Mar 19, 2024
c9b0065
remove generic param from asset registry inspect trait
Roznovjak Apr 12, 2024
7590c17
Merge branch 'master' into add_token_min_liquidity_limit
Roznovjak Apr 12, 2024
0ba7383
fix benchmark test
Roznovjak Apr 12, 2024
ae9b1a4
bump runtime version
Roznovjak Apr 12, 2024
c93262a
bump crate versions
Roznovjak Apr 12, 2024
516c656
Merge branch 'master' into add_token_min_liquidity_limit
Roznovjak Apr 19, 2024
1aaf3df
bump crate version
Roznovjak Apr 19, 2024
330e200
bump runtime version
Roznovjak Apr 19, 2024
cdca9ff
throw error if ED not available
Roznovjak Apr 19, 2024
f129174
add test
Roznovjak Apr 19, 2024
cf7540d
Merge branch 'master' into add_token_min_liquidity_limit
Roznovjak Apr 19, 2024
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
18 changes: 9 additions & 9 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.20.2"
version = "1.20.3"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
98 changes: 98 additions & 0 deletions integration-tests/src/circuit_breaker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,104 @@ fn add_liquidity_to_omnipool_should_fail_when_liquidity_limit_per_block_exceeded
});
}

#[test]
fn add_token_with_minimum_liquidity_to_omnipool_can_disable_adding_liquidity() {
Hydra::execute_with(|| {
//Arrange
init_omnipool();

let ed = <pallet_asset_registry::Pallet<hydradx_runtime::Runtime> as hydradx_traits::registry::Inspect
>::existential_deposit(DOT);
let minimum_initial_liquidity = 20 * ed.unwrap();

assert_ok!(Tokens::set_balance(
RawOrigin::Root.into(),
hydradx_runtime::Omnipool::protocol_account(),
DOT,
minimum_initial_liquidity,
0,
));

assert_ok!(hydradx_runtime::Omnipool::add_token(
hydradx_runtime::RuntimeOrigin::root(),
DOT,
FixedU128::from(1),
Permill::from_percent(100),
hydradx_runtime::Omnipool::protocol_account(),
));

let min_added_liquidity = <hydradx_runtime::Runtime as pallet_omnipool::Config>::MinimumPoolLiquidity::get();

assert_ok!(Tokens::set_balance(
RawOrigin::Root.into(),
ALICE.into(),
DOT,
min_added_liquidity,
0,
));

set_relaychain_block_number(300);

//Act and assert
// ED >= 1_000_000, adding MinimumPoolLiquidity should not trigger the circuit breaker
assert_ok!(Omnipool::add_liquidity(
hydradx_runtime::RuntimeOrigin::signed(ALICE.into()),
DOT,
min_added_liquidity,
));
});

TestNet::reset();

Hydra::execute_with(|| {
//Arrange
init_omnipool();

let ed = <pallet_asset_registry::Pallet<hydradx_runtime::Runtime> as hydradx_traits::registry::Inspect
>::existential_deposit(BTC);
let minimum_initial_liquidity = 20 * ed.unwrap();

assert_ok!(Tokens::set_balance(
RawOrigin::Root.into(),
hydradx_runtime::Omnipool::protocol_account(),
BTC,
minimum_initial_liquidity,
0,
));

assert_ok!(hydradx_runtime::Omnipool::add_token(
hydradx_runtime::RuntimeOrigin::root(),
BTC,
FixedU128::from(1),
Permill::from_percent(100),
hydradx_runtime::Omnipool::protocol_account(),
));

let min_added_liquidity = <hydradx_runtime::Runtime as pallet_omnipool::Config>::MinimumPoolLiquidity::get();

assert_ok!(Tokens::set_balance(
RawOrigin::Root.into(),
ALICE.into(),
BTC,
min_added_liquidity,
0,
));

set_relaychain_block_number(300);

//Act and assert
// ED < 1_000_000, adding MinimumPoolLiquidity triggers the circuit breaker
assert_noop!(
Omnipool::add_liquidity(
hydradx_runtime::RuntimeOrigin::signed(ALICE.into()),
BTC,
min_added_liquidity,
),
pallet_circuit_breaker::Error::<hydradx_runtime::Runtime>::MaxLiquidityLimitPerBlockReached
);
});
}

#[test]
fn add_liquidity_to_omnipool_should_not_fail_when_liquidity_limit_per_block_exceeded_but_called_by_whitelisted() {
Hydra::execute_with(|| {
Expand Down
9 changes: 4 additions & 5 deletions integration-tests/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1157,12 +1157,11 @@ fn dispatch_should_work_with_buying_insufficient_asset() {
.unwrap();

create_xyk_pool_with_amounts(shitcoin, 1000000 * UNITS, HDX, 1000000 * UNITS);
let evm_address = EVMAccounts::evm_address(&Into::<AccountId>::into(ALICE));
init_omnipool_with_oracle_for_block_10();

assert_ok!(hydradx_runtime::Currencies::update_balance(
hydradx_runtime::RuntimeOrigin::root(),
currency_precompile::alice_substrate_evm_addr().into(),
currency_precompile::alice_substrate_evm_addr(),
WETH,
(100 * UNITS * 1_000_000) as i128,
));
Expand All @@ -1186,9 +1185,9 @@ fn dispatch_should_work_with_buying_insufficient_asset() {
let router_swap = RuntimeCall::Router(pallet_route_executor::Call::buy {
asset_in: WETH,
asset_out: shitcoin,
amount_out: 1 * UNITS,
amount_out: UNITS,
max_amount_in: u128::MAX,
route: swap_route.clone(),
route: swap_route,
});

//Arrange
Expand Down Expand Up @@ -1217,7 +1216,7 @@ fn dispatch_should_work_with_buying_insufficient_asset() {
//EVM call passes even when the substrate tx fails, so we need to check if the tx is executed
expect_hydra_events(vec![pallet_evm::Event::Executed { address: DISPATCH_ADDR }.into()]);
let new_balance = Tokens::free_balance(shitcoin, &currency_precompile::alice_substrate_evm_addr());
assert_eq!(new_balance, 1 * UNITS);
assert_eq!(new_balance, UNITS);
});
}

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/polkadot_test_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ pub mod hydra {
(
Some(DOT),
Some(b"DOT".to_vec().try_into().unwrap()),
1_000u128,
1_000_000u128,
None,
None,
None,
Expand Down
2 changes: 1 addition & 1 deletion pallets/asset-registry/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pallet-asset-registry"
version = "3.2.1"
version = "3.2.2"
description = "Pallet for asset registry management"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion pallets/asset-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ impl<T: Config> Inspect for Pallet<T> {
}
}

impl<T: Config> Mutate for Pallet<T> {
impl<T: Config> Mutate<Balance> for Pallet<T> {
type Error = DispatchError;

fn set_location(asset_id: Self::AssetId, location: T::AssetNativeLocation) -> Result<(), Self::Error> {
Expand Down
32 changes: 10 additions & 22 deletions pallets/asset-registry/src/tests/inspect_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,31 +274,19 @@ fn existential_deposit_should_work() {
let asset_one_symbol = b"TKN".to_vec();

ExtBuilder::default()
.with_assets(vec![
(
Some(1),
Some(b"Tkn1".to_vec().try_into().unwrap()),
UNIT,
Some(asset_one_symbol.try_into().unwrap()),
None,
None,
true,
),
(Some(2), None, UNIT, None, None, None, false),
(
Some(3),
Some(b"Tkn3".to_vec().try_into().unwrap()),
2 * UNIT,
None,
None,
None,
true,
),
])
.with_assets(vec![(
Some(1),
Some(b"Tkn1".to_vec().try_into().unwrap()),
2 * UNIT,
Some(asset_one_symbol.try_into().unwrap()),
None,
None,
true,
)])
.build()
.execute_with(|| {
//Act & assert
assert_eq!(<Registry as Inspect>::existential_deposit(3), Some(2 * UNIT));
assert_eq!(<Registry as Inspect>::existential_deposit(1), Some(2 * UNIT));

assert_eq!(<Registry as Inspect>::existential_deposit(non_existing_id), None);
});
Expand Down
6 changes: 3 additions & 3 deletions pallets/asset-registry/src/tests/mutate_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn set_location_should_work_when_location_was_not_set_yet() {
assert_eq!(Registry::locations(asset_id), None);

//Act
assert_ok!(<Registry as Mutate>::set_location(asset_id, location.clone()));
assert_ok!(<Registry as Mutate<Balance>>::set_location(asset_id, location.clone()));

//Assert
assert_eq!(Registry::location_assets(location.clone()), Some(asset_id));
Expand Down Expand Up @@ -59,7 +59,7 @@ fn set_location_should_not_work_when_location_was_not() {

//Act
assert_noop!(
<Registry as Mutate>::set_location(asset_id, location),
<Registry as Mutate<Balance>>::set_location(asset_id, location),
Error::<Test>::LocationAlreadyRegistered
);
});
Expand All @@ -75,7 +75,7 @@ fn set_location_should_not_work_when_asset_does_not_exists() {

//Act
assert_noop!(
<Registry as Mutate>::set_location(non_existing_id, location),
<Registry as Mutate<Balance>>::set_location(non_existing_id, location),
Error::<Test>::AssetNotFound
);
});
Expand Down
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.21"
version = "1.1.22"
authors = ["GalacticCouncil <hydradx@galacticcouncil.io>"]
edition = "2021"
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion pallets/circuit-breaker/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ where
}

fn existential_deposit(_id: Self::AssetId) -> Option<u128> {
unimplemented!()
Some(1u128)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pallets/dca/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = 'pallet-dca'
version = "1.4.3"
version = "1.4.4"
description = 'A pallet to manage DCA scheduling'
authors = ['GalacticCouncil']
edition = '2021'
Expand Down
Loading
Loading