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 Nov 7, 2023
2 parents 0afe548 + aa0033c commit 74de4ac
Show file tree
Hide file tree
Showing 40 changed files with 1,161 additions and 971 deletions.
1,592 changes: 747 additions & 845 deletions Cargo.lock

Large diffs are not rendered by default.

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.15.0"
version = "1.16.0"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
133 changes: 122 additions & 11 deletions integration-tests/src/dca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use hydradx_runtime::{
AssetRegistry, Balances, Currencies, Omnipool, Router, Runtime, RuntimeEvent, RuntimeOrigin, Stableswap, Tokens,
Treasury, DCA,
};
use hydradx_traits::router::{PoolType, Trade};
use hydradx_traits::router::PoolType;
use hydradx_traits::router::Trade;
use hydradx_traits::Registry;
use orml_traits::MultiCurrency;
use orml_traits::MultiReservableCurrency;
Expand Down Expand Up @@ -99,6 +100,43 @@ mod omnipool {
});
}

#[test]
fn buy_schedule_execution_should_work_without_route() {
TestNet::reset();
Hydra::execute_with(|| {
//Arrange
init_omnipool_with_oracle_for_block_10();

let dca_budget = 1000 * UNITS;

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

let amount_out = 100 * UNITS;
let no_route = vec![];
let schedule1 = schedule_fake_with_buy_order_with_route(HDX, DAI, amount_out, dca_budget, no_route);
create_schedule(ALICE, schedule1);

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
set_relaychain_block_number(11);

//Assert
let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE;
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);
});
}

#[test]
fn buy_schedule_should_be_retried_multiple_times_then_terminated() {
TestNet::reset();
Expand Down Expand Up @@ -493,6 +531,45 @@ mod omnipool {
});
}

#[test]
fn sell_schedule_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;
let no_route = vec![];
let schedule1 =
schedule_fake_with_sell_order_with_route(ALICE, dca_budget, HDX, DAI, amount_to_sell, no_route);
create_schedule(ALICE, schedule1);

assert_balance!(ALICE.into(), HDX, alice_init_hdx_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);

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

let schedule_id = 0;
let schedule = DCA::schedules(schedule_id);
assert!(schedule.is_none());
});
}

#[test]
fn sell_schedule_should_be_terminated_after_retries() {
TestNet::reset();
Expand Down Expand Up @@ -2045,6 +2122,26 @@ fn schedule_fake_with_buy_order(
asset_out: AssetId,
amount: Balance,
budget: Balance,
) -> Schedule<AccountId, AssetId, u32> {
schedule_fake_with_buy_order_with_route(
asset_in,
asset_out,
amount,
budget,
vec![Trade {
pool,
asset_in,
asset_out,
}],
)
}

fn schedule_fake_with_buy_order_with_route(
asset_in: AssetId,
asset_out: AssetId,
amount: Balance,
budget: Balance,
route: Vec<Trade<AssetId>>,
) -> Schedule<AccountId, AssetId, u32> {
Schedule {
owner: AccountId::from(ALICE),
Expand All @@ -2058,11 +2155,7 @@ fn schedule_fake_with_buy_order(
asset_out,
amount_out: amount,
max_amount_in: Balance::MAX,
route: create_bounded_vec(vec![Trade {
pool,
asset_in,
asset_out,
}]),
route: create_bounded_vec(route),
},
}
}
Expand All @@ -2074,6 +2167,28 @@ fn schedule_fake_with_sell_order(
asset_in: AssetId,
asset_out: AssetId,
amount: Balance,
) -> Schedule<AccountId, AssetId, u32> {
schedule_fake_with_sell_order_with_route(
owner,
total_amount,
asset_in,
asset_out,
amount,
vec![Trade {
pool,
asset_in,
asset_out,
}],
)
}

fn schedule_fake_with_sell_order_with_route(
owner: [u8; 32],
total_amount: Balance,
asset_in: AssetId,
asset_out: AssetId,
amount: Balance,
route: Vec<Trade<AssetId>>,
) -> Schedule<AccountId, AssetId, u32> {
Schedule {
owner: AccountId::from(owner),
Expand All @@ -2087,11 +2202,7 @@ fn schedule_fake_with_sell_order(
asset_out,
amount_in: amount,
min_amount_out: Balance::MIN,
route: create_bounded_vec(vec![Trade {
pool,
asset_in,
asset_out,
}]),
route: create_bounded_vec(route),
},
}
}
Expand Down
1 change: 0 additions & 1 deletion integration-tests/src/omnipool_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ fn removing_token_should_work_when_no_shares_remaining() {
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);
Expand Down
3 changes: 1 addition & 2 deletions integration-tests/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use pallet_omnipool::traits::OmnipoolHooks;
use pallet_omnipool::weights::WeightInfo as OmnipoolWeights;
use pallet_route_executor::AmmTradeWeights;

use primitives::asset::AssetPair;
use primitives::AssetId;

use frame_support::{assert_noop, assert_ok};
Expand Down Expand Up @@ -2237,7 +2236,7 @@ fn create_lbp_pool(accumulated_asset: u32, distributed_asset: u32) {
}

fn get_lbp_pair_account_id(asset_a: AssetId, asset_b: AssetId) -> AccountId {
let asset_pair = AssetPair {
let asset_pair = pallet_lbp::AssetPair {
asset_in: asset_a,
asset_out: asset_b,
};
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/xyk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::polkadot_test_net::*;

use hydradx_runtime::{DustRemovalWhitelist, RuntimeOrigin, XYK};
use hydradx_traits::AMM;
use primitives::{asset::AssetPair, AssetId};
use pallet_xyk::types::AssetPair;
use xcm_emulator::TestExt;

use frame_support::{assert_ok, traits::Contains};
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.2.0"
version = "1.2.2"
description = 'A pallet to manage DCA scheduling'
authors = ['GalacticCouncil']
edition = '2021'
Expand Down
Loading

0 comments on commit 74de4ac

Please sign in to comment.