Skip to content
Merged
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.126.3"
version = "1.127.0"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
61 changes: 60 additions & 1 deletion integration-tests/src/uniswap_v3_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use hydradx_runtime::{
AssetId, AssetRegistry, Currencies, Dispatcher, Parameters, Router, Runtime, RuntimeCall, RuntimeEvent,
RuntimeOrigin, System, Treasury, DCA,
};
use hydradx_traits::router::{PoolType, Trade};
use hydradx_traits::router::{ExecutorError, PoolType, Trade};
use hydradx_traits::OraclePeriod;
use orml_traits::MultiCurrency;
use pallet_broadcast::types::Filler;
Expand Down Expand Up @@ -225,6 +225,28 @@ fn router_sell_should_increase_output_balance_when_routed_through_uniswap_v3() {
});
}

#[test]
fn router_sell_should_succeed_at_every_amount_when_the_input_is_an_atoken() {
with_uniswap_v3(|| {
for amount in SELL_AMOUNT..SELL_AMOUNT + 32 {
let before = Currencies::free_balance(ASSET_OUT, &ALICE.into());
let result = Router::sell(
RuntimeOrigin::signed(ALICE.into()),
ASSET_IN,
ASSET_OUT,
amount,
0,
uniswap_route().try_into().unwrap(),
);
assert!(result.is_ok(), "router sell of {amount} failed: {result:?}");
assert!(
Currencies::free_balance(ASSET_OUT, &ALICE.into()) > before,
"router sell of {amount} delivered nothing"
);
}
});
}

#[test]
fn router_buy_should_deliver_exact_output_when_routed_through_uniswap_v3() {
with_uniswap_v3(|| {
Expand Down Expand Up @@ -465,6 +487,43 @@ fn trade_weight_should_cover_the_whole_buy_path() {
);
}

#[test]
fn trade_weight_should_cover_the_atoken_sell_path() {
use hydradx_runtime::Runtime as R;
use pallet_evm::GasWeightMapping;

let path_gas = 250_000 + 1_000_000 + 100_000 + 1_000_000 + 5 * 100_000 + 2 * 100_000 + 250_000;
let declared = UniswapV3::trade_weight();
let needed = <R as pallet_evm::Config>::GasWeightMapping::gas_to_weight(path_gas, true);

assert!(
declared.ref_time() >= needed.ref_time(),
"trade_weight() declares {} but the aToken sell path can reserve {} ({} gas)",
declared.ref_time(),
needed.ref_time(),
path_gas
);
}

#[test]
fn execute_sell_should_fail_with_a_named_error_when_the_swap_reverts() {
with_uniswap_v3(|| {
assert_eq!(
UniswapV3::execute_sell(
RuntimeOrigin::signed(ALICE.into()),
PoolType::UniswapV3(FEE_TIER),
ASSET_IN,
ASSET_OUT,
SELL_AMOUNT,
Balance::MAX,
),
Err(ExecutorError::Error(
pallet_dispatcher::Error::<Runtime>::UniswapV3SwapFailed.into()
))
);
});
}

// ---------------------------------------------------------------------------
// ICE simulator
// ---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pallets/dispatcher/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pallet-dispatcher"
version = "1.8.0"
version = "1.9.0"
authors = ['GalacticCouncil']
edition = "2021"
license = "Apache-2.0"
Expand Down
1 change: 1 addition & 0 deletions pallets/dispatcher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ pub mod pallet {
/// Aave - the reserve is paused and no operations are allowed
AaveReservePaused,
UniswapV3InsufficientLiquidity,
UniswapV3SwapFailed,
}

#[pallet::event]
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 = "457.0.0"
version = "458.0.0"
authors = ["GalacticCouncil"]
edition = "2021"
license = "Apache 2.0"
Expand Down
Loading
Loading