Skip to content

Commit

Permalink
Merge branch 'master' into evm
Browse files Browse the repository at this point in the history
  • Loading branch information
vgantchev committed Oct 31, 2023
2 parents c6e0842 + a798076 commit 12c6d6b
Show file tree
Hide file tree
Showing 19 changed files with 1,266 additions and 97 deletions.
8 changes: 4 additions & 4 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.13.0"
version = "1.14.0"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
91 changes: 91 additions & 0 deletions integration-tests/src/omnipool_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use frame_support::{assert_noop, assert_ok};

use orml_traits::currency::MultiCurrency;
use orml_traits::MultiCurrencyExtended;
use sp_runtime::FixedPointNumber;
use sp_runtime::{FixedU128, Permill};
use xcm_emulator::TestExt;

Expand Down Expand Up @@ -227,3 +228,93 @@ fn add_liquidity_should_fail_when_price_changes_across_multiple_block() {
);
});
}

#[test]
fn withdraw_pool_liquidity_should_work_when_withdrawing_all() {
TestNet::reset();

Hydra::execute_with(|| {
init_omnipool();
let bob_account = AccountId::from(UNKNOWN);
let stable_price = FixedU128::from_inner(45_000_000_000);
let state = pallet_omnipool::Pallet::<hydradx_runtime::Runtime>::load_asset_state(DAI).unwrap();
let dai_reserve = state.reserve;

assert_ok!(hydradx_runtime::Omnipool::withdraw_protocol_liquidity(
hydradx_runtime::RuntimeOrigin::root(),
DAI,
state.protocol_shares,
(stable_price.into_inner(), FixedU128::DIV),
bob_account.clone()
));

let state = pallet_omnipool::Pallet::<hydradx_runtime::Runtime>::load_asset_state(DAI).unwrap();
assert_eq!(state.reserve, 0);
assert_eq!(state.hub_reserve, 0);
assert_eq!(state.shares, 0);
assert_eq!(state.protocol_shares, 0);

let dai_balance = hydradx_runtime::Tokens::free_balance(DAI, &bob_account);
assert!(dai_balance <= dai_reserve);
let lrna_balance = hydradx_runtime::Tokens::free_balance(LRNA, &bob_account);
assert_eq!(lrna_balance, 0);
});
}

use pallet_omnipool::types::Tradability;
#[test]
fn removing_token_should_work_when_no_shares_remaining() {
TestNet::reset();

Hydra::execute_with(|| {
init_omnipool();
let bob_account = AccountId::from(UNKNOWN);
let dot_amount = 87_719_298_250_000_u128;

let token_price = FixedU128::from_inner(25_650_000_000_000_000_000);
assert_ok!(hydradx_runtime::Omnipool::add_token(
hydradx_runtime::RuntimeOrigin::root(),
DOT,
token_price,
Permill::from_percent(100),
bob_account.clone(),
));

hydra_run_to_block(10);

assert_ok!(hydradx_runtime::Omnipool::set_asset_tradable_state(
hydradx_runtime::RuntimeOrigin::root(),
DOT,
Tradability::ADD_LIQUIDITY | Tradability::REMOVE_LIQUIDITY
));

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

let state = pallet_omnipool::Pallet::<hydradx_runtime::Runtime>::load_asset_state(DOT).unwrap();
let dot_balance = hydradx_runtime::Tokens::free_balance(DOT, &bob_account);
assert!(dot_balance <= dot_amount);
let lrna_balance = hydradx_runtime::Tokens::free_balance(LRNA, &bob_account);
assert_eq!(lrna_balance, 0);

assert_ok!(hydradx_runtime::Omnipool::set_asset_tradable_state(
hydradx_runtime::RuntimeOrigin::root(),
DOT,
Tradability::FROZEN
));
assert_ok!(hydradx_runtime::Omnipool::remove_token(
hydradx_runtime::RuntimeOrigin::root(),
DOT,
bob_account.clone(),
));
let dot_balance = hydradx_runtime::Tokens::free_balance(DOT, &bob_account);
assert!(dot_balance == dot_amount);
let lrna_balance = hydradx_runtime::Tokens::free_balance(LRNA, &bob_account);
assert_eq!(lrna_balance, 0);
});
}
1 change: 1 addition & 0 deletions integration-tests/src/polkadot_test_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub const ALICE: [u8; 32] = [4u8; 32];
pub const BOB: [u8; 32] = [5u8; 32];
pub const CHARLIE: [u8; 32] = [6u8; 32];
pub const DAVE: [u8; 32] = [7u8; 32];
pub const UNKNOWN: [u8; 32] = [8u8; 32];

pub fn evm_address() -> H160 {
hex!["222222ff7Be76052e023Ec1a306fCca8F9659D80"].into()
Expand Down
2 changes: 1 addition & 1 deletion pallets/omnipool/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pallet-omnipool"
version = "3.2.3"
version = "3.3.0"
authors = ['GalacticCouncil']
edition = "2021"
license = "Apache-2.0"
Expand Down
Loading

0 comments on commit 12c6d6b

Please sign in to comment.