Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 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.71.0"
version = "1.72.0"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
56 changes: 56 additions & 0 deletions integration-tests/src/dca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2124,6 +2124,62 @@ mod omnipool {
assert_balance!(ALICE.into(), HDX, 0);
});
}

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

let dca_budget = 1100 * UNITS;
let amount_to_sell = 100 * UNITS;

// Create sell schedule with min_amount_out = 0
// This means last_block_slippage_min_limit will be used as the effective limit
let schedule = Schedule {
owner: AccountId::from(ALICE),
period: 5u32,
total_amount: dca_budget,
max_retries: None,
stability_threshold: None,
slippage: Some(Permill::from_percent(5)),
order: Order::Sell {
asset_in: HDX,
asset_out: DAI,
amount_in: amount_to_sell,
min_amount_out: 0,
route: create_bounded_vec(vec![Trade {
pool: PoolType::Omnipool,
asset_in: HDX,
asset_out: DAI,
}]),
},
};
create_schedule(ALICE, schedule);

let alice_dai_before = Currencies::free_balance(DAI, &ALICE.into());

//Act
go_to_block(12);

//Assert - DCA executed successfully and schedule is still alive
let alice_dai_after = Currencies::free_balance(DAI, &ALICE.into());
assert!(
alice_dai_after > alice_dai_before,
"ALICE should have received DAI from the trade"
);

let schedule = DCA::schedules(0);
assert!(schedule.is_some(), "DCA schedule should still be alive after execution");
});
}
}

mod fee {
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.15.0"
version = "1.16.0"
description = 'A pallet to manage DCA scheduling'
authors = ['GalacticCouncil']
edition = '2021'
Expand Down
14 changes: 12 additions & 2 deletions pallets/dca/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,16 +833,26 @@ impl<T: Config> Pallet<T> {
let last_trade = trade_amounts.last().defensive_ok_or(Error::<T>::InvalidState)?;
let amount_out = last_trade.amount_out;

if *min_amount_out > last_block_slippage_min_limit {
let effective_min_limit = if *min_amount_out > last_block_slippage_min_limit {
ensure!(amount_out >= *min_amount_out, Error::<T>::TradeLimitReached);
amount_out
} else {
ensure!(
amount_out >= last_block_slippage_min_limit,
Error::<T>::SlippageLimitReached
);
// Use slippage limit to mainly absorb aToken rounding errors
last_block_slippage_min_limit
};

T::RouteExecutor::sell(origin, *asset_in, *asset_out, amount_to_sell, amount_out, route.clone())?;
T::RouteExecutor::sell(
origin,
*asset_in,
*asset_out,
amount_to_sell,
effective_min_limit,
route.clone(),
)?;

Ok(AmountInAndOut {
amount_in: amount_to_sell,
Expand Down
2 changes: 1 addition & 1 deletion runtime/hydradx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hydradx-runtime"
version = "399.0.0"
version = "400.0.0"
authors = ["GalacticCouncil"]
edition = "2021"
license = "Apache 2.0"
Expand Down
2 changes: 1 addition & 1 deletion runtime/hydradx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: Cow::Borrowed("hydradx"),
impl_name: Cow::Borrowed("hydradx"),
authoring_version: 1,
spec_version: 399,
spec_version: 400,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
Loading
Loading