From e282fc4a9233031b12a01f8207a793a9e1d4f075 Mon Sep 17 00:00:00 2001 From: dmoka Date: Fri, 6 Oct 2023 14:51:21 +0200 Subject: [PATCH 01/22] use default route provider when creating a DCA schedule dmoka Yesterday 15:46 --- integration-tests/src/dca.rs | 2 +- integration-tests/src/router.rs | 3 ++- pallets/dca/src/lib.rs | 30 +++++++++++++++++++--------- pallets/dca/src/tests/mock.rs | 7 ++++++- pallets/dca/src/tests/mod.rs | 2 +- pallets/dca/src/tests/schedule.rs | 13 +++++------- pallets/dca/src/types.rs | 11 +--------- pallets/democracy/src/lib.rs | 1 + pallets/route-executor/src/lib.rs | 15 +++----------- runtime/adapters/src/xcm_exchange.rs | 2 +- runtime/hydradx/src/assets.rs | 7 ++++++- traits/src/router.rs | 20 +++++++++++++++++++ 12 files changed, 68 insertions(+), 45 deletions(-) diff --git a/integration-tests/src/dca.rs b/integration-tests/src/dca.rs index 41d01562d..884fbb079 100644 --- a/integration-tests/src/dca.rs +++ b/integration-tests/src/dca.rs @@ -11,10 +11,10 @@ use hydradx_runtime::Omnipool; use hydradx_runtime::RuntimeOrigin; use hydradx_runtime::Tokens; use hydradx_traits::router::PoolType; +use hydradx_traits::router::Trade; use orml_traits::MultiCurrency; use orml_traits::MultiReservableCurrency; use pallet_dca::types::{Order, Schedule}; -use pallet_route_executor::Trade; use polkadot_primitives::v2::BlockNumber; use primitives::{AssetId, Balance}; use sp_runtime::traits::ConstU32; diff --git a/integration-tests/src/router.rs b/integration-tests/src/router.rs index dc7f55bcb..7028412ab 100644 --- a/integration-tests/src/router.rs +++ b/integration-tests/src/router.rs @@ -9,13 +9,14 @@ use hydradx_adapters::OmnipoolHookAdapter; use hydradx_runtime::{ AmmWeights, AssetRegistry, BlockNumber, Currencies, Omnipool, Router, Runtime, RuntimeOrigin, Stableswap, LBP, XYK, }; +use hydradx_traits::router::Trade; use hydradx_traits::Registry; use hydradx_traits::{router::PoolType, AMM}; use pallet_lbp::weights::WeightInfo as LbpWeights; use pallet_lbp::WeightCurveType; use pallet_omnipool::traits::OmnipoolHooks; use pallet_omnipool::weights::WeightInfo as OmnipoolWeights; -use pallet_route_executor::{AmmTradeWeights, Trade}; +use pallet_route_executor::AmmTradeWeights; use primitives::asset::AssetPair; use primitives::AssetId; diff --git a/pallets/dca/src/lib.rs b/pallets/dca/src/lib.rs index 21a887cc3..3bf901d5e 100644 --- a/pallets/dca/src/lib.rs +++ b/pallets/dca/src/lib.rs @@ -74,12 +74,14 @@ use frame_support::{ use frame_system::{ensure_signed, pallet_prelude::OriginFor, Origin}; use hydradx_adapters::RelayChainBlockHashProvider; use hydradx_traits::pools::SpotPriceProvider; +use hydradx_traits::router::RouteProvider; +use hydradx_traits::router::Trade; use hydradx_traits::{OraclePeriod, PriceOracle}; use orml_traits::arithmetic::CheckedAdd; use orml_traits::MultiCurrency; use orml_traits::NamedMultiReservableCurrency; +use pallet_route_executor::AmountInAndOut; use pallet_route_executor::TradeAmountsCalculator; -use pallet_route_executor::{AmountInAndOut, Trade}; use rand::rngs::StdRng; use rand::{Rng, SeedableRng}; use sp_runtime::traits::CheckedMul; @@ -88,6 +90,7 @@ use sp_runtime::{ traits::{BlockNumberProvider, Saturating}, ArithmeticError, BoundedVec, DispatchError, FixedPointNumber, FixedU128, Permill, }; + use sp_std::vec::Vec; use sp_std::{cmp::min, vec}; #[cfg(test)] @@ -233,6 +236,9 @@ pub mod pallet { ///Spot price provider to get the current price between two asset type SpotPriceProvider: SpotPriceProvider; + ///Spot price provider to get the current price between two asset + type RouteProvider: RouteProvider; + ///Max price difference allowed between blocks #[pallet::constant] type MaxPriceDifferenceBetweenBlocks: Get; @@ -423,8 +429,6 @@ pub mod pallet { let who = ensure_signed(origin.clone())?; ensure!(who == schedule.owner, Error::::Forbidden); - ensure!(schedule.order.get_route_length() > 0, Error::::RouteNotSpecified); - let min_budget = Self::convert_native_amount_to_currency( schedule.order.get_asset_in(), T::MinBudgetInNativeCurrency::get(), @@ -439,8 +443,19 @@ pub mod pallet { let amount_in = match schedule.order { Order::Sell { amount_in, .. } => amount_in, Order::Buy { - amount_out, ref route, .. - } => Self::get_amount_in_for_buy(&amount_out, route)?, + asset_in, + asset_out, + amount_out, + ref route, + .. + } => { + let used_route = if route.is_empty() { + T::RouteProvider::get(asset_in, asset_out) + } else { + (*route).to_vec() + }; + Self::get_amount_in_for_buy(&amount_out, &used_route)? + } }; let min_trade_amount_in_from_fee = transaction_fee.saturating_mul(FEE_MULTIPLIER_FOR_MIN_TRADE_LIMIT); ensure!( @@ -843,10 +858,7 @@ where diff > max_allowed_difference } - fn get_amount_in_for_buy( - amount_out: &Balance, - route: &BoundedVec, ConstU32<5>>, - ) -> Result { + fn get_amount_in_for_buy(amount_out: &Balance, route: &[Trade]) -> Result { let trade_amounts = pallet_route_executor::Pallet::::calculate_buy_trade_amounts(route.as_ref(), (*amount_out).into())?; diff --git a/pallets/dca/src/tests/mock.rs b/pallets/dca/src/tests/mock.rs index 5e529f98d..0cf5432eb 100644 --- a/pallets/dca/src/tests/mock.rs +++ b/pallets/dca/src/tests/mock.rs @@ -641,6 +641,7 @@ impl Config for Test { type WeightInfo = (); type OraclePriceProvider = PriceProviderMock; type SpotPriceProvider = SpotPriceProviderMock; + type RouteProvider = DefaultRouteProvider; type MaxPriceDifferenceBetweenBlocks = OmnipoolMaxAllowedPriceDifference; type NamedReserveId = NamedReserveId; type MaxNumberOfRetriesOnError = MaxNumberOfRetriesOnError; @@ -649,6 +650,10 @@ impl Config for Test { type MinimumTradingLimit = MinTradeAmount; } +pub struct DefaultRouteProvider; + +impl RouteProvider for DefaultRouteProvider {} + pub struct ParentHashGetterMock {} impl RelayChainBlockHashProvider for ParentHashGetterMock { @@ -664,7 +669,7 @@ use hydra_dx_math::ema::EmaPrice; use hydra_dx_math::to_u128_wrapper; use hydra_dx_math::types::Ratio; use hydradx_traits::pools::SpotPriceProvider; -use hydradx_traits::router::{ExecutorError, PoolType, TradeExecution}; +use hydradx_traits::router::{ExecutorError, PoolType, RouteProvider, TradeExecution}; use pallet_omnipool::traits::ExternalPriceProvider; use rand::prelude::StdRng; use rand::SeedableRng; diff --git a/pallets/dca/src/tests/mod.rs b/pallets/dca/src/tests/mod.rs index 4e62f464a..9336d1007 100644 --- a/pallets/dca/src/tests/mod.rs +++ b/pallets/dca/src/tests/mod.rs @@ -1,7 +1,7 @@ use crate::tests::mock::*; use crate::{Balance, Order, Schedule, ScheduleId}; use hydradx_traits::router::PoolType; -use pallet_route_executor::Trade; +use hydradx_traits::router::Trade; use sp_runtime::traits::ConstU32; use sp_runtime::{BoundedVec, Permill}; diff --git a/pallets/dca/src/tests/schedule.rs b/pallets/dca/src/tests/schedule.rs index a49ab46df..3182c7959 100644 --- a/pallets/dca/src/tests/schedule.rs +++ b/pallets/dca/src/tests/schedule.rs @@ -23,8 +23,8 @@ use crate::{Error, Event, Order}; use frame_support::{assert_noop, assert_ok}; use frame_system::pallet_prelude::BlockNumberFor; use hydradx_traits::router::PoolType; +use hydradx_traits::router::Trade; use orml_traits::NamedMultiReservableCurrency; -use pallet_route_executor::Trade; use pretty_assertions::assert_eq; use sp_runtime::DispatchError::BadOrigin; use std::ops::RangeInclusive; @@ -840,12 +840,13 @@ fn schedule_should_fail_when_wrong_user_is_specified_in_schedule() { } #[test] -fn schedule_should_fail_when_no_routes_specified() { +fn schedule_should_be_created_when_no_routes_specified() { ExtBuilder::default() .with_endowed_accounts(vec![(ALICE, HDX, 10000 * ONE)]) .build() .execute_with(|| { //Arrange + set_block_number(500); let total_amount = 100 * ONE; let schedule = ScheduleBuilder::new() @@ -859,12 +860,8 @@ fn schedule_should_fail_when_no_routes_specified() { }) .build(); - //Act - set_block_number(500); - assert_noop!( - DCA::schedule(RuntimeOrigin::signed(ALICE), schedule, Option::None), - Error::::RouteNotSpecified - ); + //Act and assert + assert_ok!(DCA::schedule(RuntimeOrigin::signed(ALICE), schedule, Option::None)); }); } diff --git a/pallets/dca/src/types.rs b/pallets/dca/src/types.rs index 1bceb6193..1d91cbdd9 100644 --- a/pallets/dca/src/types.rs +++ b/pallets/dca/src/types.rs @@ -1,5 +1,5 @@ use codec::{Decode, Encode, MaxEncodedLen}; -use pallet_route_executor::Trade; +use hydradx_traits::router::Trade; use scale_info::TypeInfo; use sp_runtime::traits::ConstU32; use sp_runtime::{BoundedVec, Permill}; @@ -70,13 +70,4 @@ where }; *asset_out } - - pub fn get_route_length(&self) -> usize { - let route = match &self { - Order::Sell { route, .. } => route, - Order::Buy { route, .. } => route, - }; - - route.len() - } } diff --git a/pallets/democracy/src/lib.rs b/pallets/democracy/src/lib.rs index f33ec5478..66fbbf4c0 100644 --- a/pallets/democracy/src/lib.rs +++ b/pallets/democracy/src/lib.rs @@ -169,6 +169,7 @@ use sp_runtime::{ ArithmeticError, DispatchError, DispatchResult, }; use sp_std::prelude::*; +use sp_std::vec; mod conviction; pub mod traits; diff --git a/pallets/route-executor/src/lib.rs b/pallets/route-executor/src/lib.rs index e938987e3..ff5fd0da6 100644 --- a/pallets/route-executor/src/lib.rs +++ b/pallets/route-executor/src/lib.rs @@ -17,7 +17,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -use codec::{Decode, Encode, MaxEncodedLen}; +use codec::MaxEncodedLen; use frame_support::{ ensure, traits::{fungibles::Inspect, Get}, @@ -25,12 +25,11 @@ use frame_support::{ weights::Weight, }; use frame_system::ensure_signed; -use hydradx_traits::router::{ExecutorError, PoolType, TradeExecution}; +use hydradx_traits::router::Trade; +use hydradx_traits::router::{ExecutorError, TradeExecution}; use orml_traits::arithmetic::{CheckedAdd, CheckedSub}; -use scale_info::TypeInfo; use sp_runtime::{ArithmeticError, DispatchError}; use sp_std::vec::Vec; - #[cfg(test)] mod tests; @@ -53,14 +52,6 @@ pub trait TradeAmountsCalculator { ) -> Result>, DispatchError>; } -///A single trade for buy/sell, describing the asset pair and the pool type in which the trade is executed -#[derive(Encode, Decode, Debug, Eq, PartialEq, Copy, Clone, TypeInfo, MaxEncodedLen)] -pub struct Trade { - pub pool: PoolType, - pub asset_in: AssetId, - pub asset_out: AssetId, -} - pub struct AmountInAndOut { pub amount_in: Balance, pub amount_out: Balance, diff --git a/runtime/adapters/src/xcm_exchange.rs b/runtime/adapters/src/xcm_exchange.rs index fb0a508da..3469190f5 100644 --- a/runtime/adapters/src/xcm_exchange.rs +++ b/runtime/adapters/src/xcm_exchange.rs @@ -1,6 +1,6 @@ use hydradx_traits::router::PoolType; +use hydradx_traits::router::Trade; use orml_traits::MultiCurrency; -use pallet_route_executor::Trade; use polkadot_xcm::latest::prelude::*; use sp_core::Get; use sp_runtime::traits::{Convert, Zero}; diff --git a/runtime/hydradx/src/assets.rs b/runtime/hydradx/src/assets.rs index c08f9fcd0..59d3a6139 100644 --- a/runtime/hydradx/src/assets.rs +++ b/runtime/hydradx/src/assets.rs @@ -48,11 +48,12 @@ use frame_support::{ BoundedVec, PalletId, }; use frame_system::{EnsureRoot, EnsureSigned, RawOrigin}; +use hydradx_traits::router::{RouteProvider, Trade}; use orml_traits::currency::MutationHooks; use orml_traits::GetByKey; use pallet_dynamic_fees::types::FeeParams; use pallet_lbp::weights::WeightInfo as LbpWeights; -use pallet_route_executor::{weights::WeightInfo as RouterWeights, AmmTradeWeights, Trade}; +use pallet_route_executor::{weights::WeightInfo as RouterWeights, AmmTradeWeights}; use pallet_staking::types::Action; use pallet_staking::SigmoidPercentage; use sp_std::num::NonZeroU16; @@ -425,6 +426,7 @@ impl pallet_dca::Config for Runtime { type RandomnessProvider = DCA; type OraclePriceProvider = OraclePriceProviderAdapterForOmnipool; type SpotPriceProvider = Omnipool; + type RouteProvider = Runtime; type MaxPriceDifferenceBetweenBlocks = MaxPriceDifference; type MaxSchedulePerBlock = MaxSchedulesPerBlock; type MaxNumberOfRetriesOnError = MaxNumberOfRetriesOnError; @@ -437,6 +439,9 @@ impl pallet_dca::Config for Runtime { type WeightInfo = weights::dca::HydraWeight; } +//Using the default implementation, will be replaced with the real implementation once we have routes stored +impl RouteProvider for Runtime {} + // Provides weight info for the router. Router extrinsics can be executed with different AMMs, so we split the router weights into two parts: // the router extrinsic overhead and the AMM weight. pub struct AmmWeights; diff --git a/traits/src/router.rs b/traits/src/router.rs index 1a6253793..a2c43b536 100644 --- a/traits/src/router.rs +++ b/traits/src/router.rs @@ -1,5 +1,25 @@ use codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; +use sp_std::vec; +use sp_std::vec::Vec; + +pub trait RouteProvider { + fn get(asset_in: AssetId, asset_out: AssetId) -> Vec> { + vec![Trade { + pool: PoolType::Omnipool, + asset_in, + asset_out, + }] + } +} + +///A single trade for buy/sell, describing the asset pair and the pool type in which the trade is executed +#[derive(Encode, Decode, Debug, Eq, PartialEq, Copy, Clone, TypeInfo, MaxEncodedLen)] +pub struct Trade { + pub pool: PoolType, + pub asset_in: AssetId, + pub asset_out: AssetId, +} #[derive(Encode, Decode, Clone, Copy, Debug, Eq, PartialEq, TypeInfo, MaxEncodedLen)] pub enum PoolType { From 16ae0aa90633d5f39019418b3d619752267ca775 Mon Sep 17 00:00:00 2001 From: dmoka Date: Fri, 6 Oct 2023 14:51:39 +0200 Subject: [PATCH 02/22] add failing test to execute schedule with no routes dmoka Today 10:50 --- pallets/dca/src/tests/on_initialize.rs | 43 ++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/pallets/dca/src/tests/on_initialize.rs b/pallets/dca/src/tests/on_initialize.rs index c8a9f0316..729cb7cfb 100644 --- a/pallets/dca/src/tests/on_initialize.rs +++ b/pallets/dca/src/tests/on_initialize.rs @@ -525,6 +525,49 @@ fn full_sell_dca_should_be_completed_when_some_successfull_dca_execution_happene }); } +#[test] +fn full_buy_should_be_completed_when_with_default_routes() { + ExtBuilder::default() + .with_endowed_accounts(vec![(ALICE, HDX, 10000 * ONE)]) + .build() + .execute_with(|| { + //Arrange + proceed_to_blocknumber(1, 500); + + let total_amount = + CALCULATED_AMOUNT_IN_FOR_OMNIPOOL_BUY + BUY_DCA_FEE_IN_NATIVE + BUY_DCA_FEE_IN_NATIVE / 2; + let amount_to_buy = 10 * ONE; + + let schedule = ScheduleBuilder::new() + .with_total_amount(total_amount) + .with_period(ONE_HUNDRED_BLOCKS) + .with_slippage(Some(Permill::from_percent(20))) + .with_order(Order::Buy { + asset_in: HDX, + asset_out: BTC, + amount_out: amount_to_buy, + max_amount_in: Balance::MAX, + route: create_bounded_vec(vec![]), + }) + .build(); + + assert_ok!(DCA::schedule(RuntimeOrigin::signed(ALICE), schedule, Option::None)); + assert_eq!(total_amount, Currencies::reserved_balance(HDX, &ALICE)); + + //Act + proceed_to_blocknumber(501, 801); + + //Assert + assert_eq!(0, Currencies::reserved_balance(HDX, &ALICE)); + + assert_number_of_executed_buy_trades!(1); + assert_balance!(ALICE, BTC, CALCULATED_AMOUNT_IN_FOR_OMNIPOOL_BUY); + + let schedule_id = 0; + assert_that_dca_is_completed(ALICE, schedule_id); + }); +} + #[test] fn full_buy_dca_should_be_completed_when_some_successfull_dca_execution_happened_but_less_than_fee_left() { ExtBuilder::default() From f1a058e05ccc626370b51ee0bff326053cc4a0a4 Mon Sep 17 00:00:00 2001 From: dmoka Date: Fri, 6 Oct 2023 14:51:58 +0200 Subject: [PATCH 03/22] fix buy with using the default router if not specified dmoka 18 minutes ago --- pallets/dca/src/lib.rs | 34 +++++++++++++------------- pallets/dca/src/tests/on_initialize.rs | 9 +++---- pallets/dca/src/types.rs | 19 +++++++++++++- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/pallets/dca/src/lib.rs b/pallets/dca/src/lib.rs index 3bf901d5e..2855b5e68 100644 --- a/pallets/dca/src/lib.rs +++ b/pallets/dca/src/lib.rs @@ -442,19 +442,9 @@ pub mod pallet { let amount_in = match schedule.order { Order::Sell { amount_in, .. } => amount_in, - Order::Buy { - asset_in, - asset_out, - amount_out, - ref route, - .. - } => { - let used_route = if route.is_empty() { - T::RouteProvider::get(asset_in, asset_out) - } else { - (*route).to_vec() - }; - Self::get_amount_in_for_buy(&amount_out, &used_route)? + Order::Buy { amount_out, .. } => { + let route = Self::get_route_or_default(&schedule.order); + Self::get_amount_in_for_buy(&amount_out, &route)? } }; let min_trade_amount_in_from_fee = transaction_fee.saturating_mul(FEE_MULTIPLIER_FOR_MIN_TRADE_LIMIT); @@ -582,6 +572,14 @@ where ::Balance: From, Balance: From<::Balance>, { + fn get_route_or_default(order: &Order) -> Vec> { + if order.get_route().is_empty() { + T::RouteProvider::get(order.get_asset_in(), order.get_asset_out()) + } else { + order.get_route().to_vec() + } + } + fn get_randomness_generator(current_blocknumber: T::BlockNumber, salt: Option) -> StdRng { match T::RandomnessProvider::generator(salt) { Ok(generator) => generator, @@ -697,9 +695,10 @@ where asset_out, amount_out, max_amount_in, - route, + .. } => { - let amount_in = Self::get_amount_in_for_buy(amount_out, route)?; + let route = Self::get_route_or_default(&schedule.order); + let amount_in = Self::get_amount_in_for_buy(amount_out, &route)?; Self::unallocate_amount(schedule_id, schedule, amount_in)?; @@ -761,8 +760,9 @@ where } //In buy we complete with returning leftover, in sell we sell the leftover in the next trade - if let Order::Buy { amount_out, route, .. } = &schedule.order { - let amount_to_unreserve: Balance = Self::get_amount_in_for_buy(amount_out, route)?; + if let Order::Buy { amount_out, .. } = &schedule.order { + let route = Self::get_route_or_default(&schedule.order); + let amount_to_unreserve: Balance = Self::get_amount_in_for_buy(amount_out, &route)?; let amount_for_next_trade: Balance = amount_to_unreserve .checked_add(transaction_fee) diff --git a/pallets/dca/src/tests/on_initialize.rs b/pallets/dca/src/tests/on_initialize.rs index 729cb7cfb..8a970cb72 100644 --- a/pallets/dca/src/tests/on_initialize.rs +++ b/pallets/dca/src/tests/on_initialize.rs @@ -534,8 +534,7 @@ fn full_buy_should_be_completed_when_with_default_routes() { //Arrange proceed_to_blocknumber(1, 500); - let total_amount = - CALCULATED_AMOUNT_IN_FOR_OMNIPOOL_BUY + BUY_DCA_FEE_IN_NATIVE + BUY_DCA_FEE_IN_NATIVE / 2; + let total_amount = 3 * CALCULATED_AMOUNT_IN_FOR_OMNIPOOL_BUY; let amount_to_buy = 10 * ONE; let schedule = ScheduleBuilder::new() @@ -555,13 +554,13 @@ fn full_buy_should_be_completed_when_with_default_routes() { assert_eq!(total_amount, Currencies::reserved_balance(HDX, &ALICE)); //Act - proceed_to_blocknumber(501, 801); + proceed_to_blocknumber(501, 1001); //Assert assert_eq!(0, Currencies::reserved_balance(HDX, &ALICE)); - assert_number_of_executed_buy_trades!(1); - assert_balance!(ALICE, BTC, CALCULATED_AMOUNT_IN_FOR_OMNIPOOL_BUY); + assert_number_of_executed_buy_trades!(2); + assert_balance!(ALICE, BTC, 2 * CALCULATED_AMOUNT_IN_FOR_OMNIPOOL_BUY); let schedule_id = 0; assert_that_dca_is_completed(ALICE, schedule_id); diff --git a/pallets/dca/src/types.rs b/pallets/dca/src/types.rs index 1d91cbdd9..8d8b850a3 100644 --- a/pallets/dca/src/types.rs +++ b/pallets/dca/src/types.rs @@ -1,5 +1,5 @@ use codec::{Decode, Encode, MaxEncodedLen}; -use hydradx_traits::router::Trade; +use hydradx_traits::router::{RouteProvider, Trade}; use scale_info::TypeInfo; use sp_runtime::traits::ConstU32; use sp_runtime::{BoundedVec, Permill}; @@ -70,4 +70,21 @@ where }; *asset_out } + + pub fn get_route(&self) -> &BoundedVec, ConstU32<5>> { + match &self { + Order::Sell { route, .. } => route, + Order::Buy { route, .. } => route, + } + } + + pub fn get_route_or_default( + &self, + default_provider: impl RouteProvider, + ) -> &BoundedVec, ConstU32<5>> { + match &self { + Order::Sell { route, .. } => route, + Order::Buy { route, .. } => route, + } + } } From e9e63f97fc9b3cbba610ceb6d2fff5ea29712c70 Mon Sep 17 00:00:00 2001 From: dmoka Date: Mon, 9 Oct 2023 09:06:53 +0200 Subject: [PATCH 04/22] encapsulate get or default in order so w can always use that --- pallets/dca/src/lib.rs | 14 +++----------- pallets/dca/src/types.rs | 19 +++++++------------ 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/pallets/dca/src/lib.rs b/pallets/dca/src/lib.rs index 2855b5e68..a54954db5 100644 --- a/pallets/dca/src/lib.rs +++ b/pallets/dca/src/lib.rs @@ -443,7 +443,7 @@ pub mod pallet { let amount_in = match schedule.order { Order::Sell { amount_in, .. } => amount_in, Order::Buy { amount_out, .. } => { - let route = Self::get_route_or_default(&schedule.order); + let route = schedule.order.get_route_or_default::(); Self::get_amount_in_for_buy(&amount_out, &route)? } }; @@ -572,14 +572,6 @@ where ::Balance: From, Balance: From<::Balance>, { - fn get_route_or_default(order: &Order) -> Vec> { - if order.get_route().is_empty() { - T::RouteProvider::get(order.get_asset_in(), order.get_asset_out()) - } else { - order.get_route().to_vec() - } - } - fn get_randomness_generator(current_blocknumber: T::BlockNumber, salt: Option) -> StdRng { match T::RandomnessProvider::generator(salt) { Ok(generator) => generator, @@ -697,7 +689,7 @@ where max_amount_in, .. } => { - let route = Self::get_route_or_default(&schedule.order); + let route = schedule.order.get_route_or_default::(); let amount_in = Self::get_amount_in_for_buy(amount_out, &route)?; Self::unallocate_amount(schedule_id, schedule, amount_in)?; @@ -761,7 +753,7 @@ where //In buy we complete with returning leftover, in sell we sell the leftover in the next trade if let Order::Buy { amount_out, .. } = &schedule.order { - let route = Self::get_route_or_default(&schedule.order); + let route = schedule.order.get_route_or_default::(); let amount_to_unreserve: Balance = Self::get_amount_in_for_buy(amount_out, &route)?; let amount_for_next_trade: Balance = amount_to_unreserve diff --git a/pallets/dca/src/types.rs b/pallets/dca/src/types.rs index 8d8b850a3..69229d770 100644 --- a/pallets/dca/src/types.rs +++ b/pallets/dca/src/types.rs @@ -71,20 +71,15 @@ where *asset_out } - pub fn get_route(&self) -> &BoundedVec, ConstU32<5>> { - match &self { - Order::Sell { route, .. } => route, - Order::Buy { route, .. } => route, - } - } - - pub fn get_route_or_default( - &self, - default_provider: impl RouteProvider, - ) -> &BoundedVec, ConstU32<5>> { - match &self { + pub fn get_route_or_default>(&self) -> Vec> { + let route = match &self { Order::Sell { route, .. } => route, Order::Buy { route, .. } => route, + }; + if route.is_empty() { + Provider::get(self.get_asset_in(), self.get_asset_out()) + } else { + route.to_vec() } } } From 552d14abb5494bca93fd567a285c0feea29e6000 Mon Sep 17 00:00:00 2001 From: dmoka Date: Mon, 9 Oct 2023 09:07:24 +0200 Subject: [PATCH 05/22] add failing test for sell without route --- pallets/dca/src/tests/on_initialize.rs | 42 ++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/pallets/dca/src/tests/on_initialize.rs b/pallets/dca/src/tests/on_initialize.rs index 8a970cb72..5ae0d8fac 100644 --- a/pallets/dca/src/tests/on_initialize.rs +++ b/pallets/dca/src/tests/on_initialize.rs @@ -480,6 +480,48 @@ fn full_sell_dca_should_be_completed_with_selling_leftover_in_last_trade() { }); } +//TODO: continue from here +#[ignore] +#[test] +fn full_sell_dca_should_be_completed_when_default_routes_used() { + ExtBuilder::default() + .with_endowed_accounts(vec![(ALICE, HDX, 10000 * ONE)]) + .build() + .execute_with(|| { + //Arrange + proceed_to_blocknumber(1, 500); + + let total_amount = 3 * *AMOUNT_OUT_FOR_OMNIPOOL_SELL; + let amount_to_sell = *AMOUNT_OUT_FOR_OMNIPOOL_SELL; + + let schedule = ScheduleBuilder::new() + .with_total_amount(total_amount) + .with_period(ONE_HUNDRED_BLOCKS) + .with_order(Order::Sell { + asset_in: HDX, + asset_out: BTC, + amount_in: amount_to_sell, + min_amount_out: Balance::MIN, + route: create_bounded_vec(vec![]), + }) + .build(); + + assert_ok!(DCA::schedule(RuntimeOrigin::signed(ALICE), schedule, Option::None)); + assert_eq!(total_amount, Currencies::reserved_balance(HDX, &ALICE)); + + //Act + proceed_to_blocknumber(501, 801); + + //Assert + assert_eq!(0, Currencies::reserved_balance(HDX, &ALICE)); + + assert_number_of_executed_sell_trades!(3); + + let schedule_id = 0; + assert_that_dca_is_completed(ALICE, schedule_id); + }); +} + #[test] fn full_sell_dca_should_be_completed_when_some_successfull_dca_execution_happened_but_less_than_fee_left() { ExtBuilder::default() From c2e8a089f7a5e13c5c1cd0f319410897d26d6954 Mon Sep 17 00:00:00 2001 From: dmoka Date: Mon, 9 Oct 2023 10:24:07 +0200 Subject: [PATCH 06/22] use default route in sell --- pallets/dca/src/lib.rs | 15 +++++++++++---- pallets/dca/src/tests/on_initialize.rs | 2 -- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pallets/dca/src/lib.rs b/pallets/dca/src/lib.rs index a5858f6a1..2122b5742 100644 --- a/pallets/dca/src/lib.rs +++ b/pallets/dca/src/lib.rs @@ -347,7 +347,7 @@ pub mod pallet { ///Slippage limit calculated from oracle is reached, leading to retry SlippageLimitReached, ///The route to execute the trade on is not specified - RouteNotSpecified, + RouteNotSpecified, //TODO: Dani - delete it ///No parent hash has been found from relay chain NoParentHashFound, ///Error that should not really happen only in case of invalid state of the schedule storage entries @@ -630,8 +630,9 @@ impl Pallet { asset_out, amount_in, min_amount_out, - route, + .. } => { + let route = &schedule.order.get_route_or_default::(); let remaining_amount = RemainingAmounts::::get(schedule_id).defensive_ok_or(Error::::InvalidState)?; let amount_to_sell = min(remaining_amount, *amount_in); @@ -645,7 +646,6 @@ impl Pallet { .checked_sub(slippage_amount) .ok_or(ArithmeticError::Overflow)?; - let route = route.to_vec(); let trade_amounts = T::Router::calculate_sell_trade_amounts(&route, amount_to_sell)?; let last_trade = trade_amounts.last().defensive_ok_or(Error::::InvalidState)?; let amount_out = last_trade.amount_out; @@ -659,7 +659,14 @@ impl Pallet { ); }; - T::Router::sell(origin, *asset_in, *asset_out, amount_to_sell, amount_out, route)?; + T::Router::sell( + origin, + *asset_in, + *asset_out, + amount_to_sell, + amount_out, + route.to_vec(), + )?; Ok(AmountInAndOut { amount_in: amount_to_sell, diff --git a/pallets/dca/src/tests/on_initialize.rs b/pallets/dca/src/tests/on_initialize.rs index 915ebb955..df6e560d5 100644 --- a/pallets/dca/src/tests/on_initialize.rs +++ b/pallets/dca/src/tests/on_initialize.rs @@ -480,8 +480,6 @@ fn full_sell_dca_should_be_completed_with_selling_leftover_in_last_trade() { }); } -//TODO: continue from here -#[ignore] #[test] fn full_sell_dca_should_be_completed_when_default_routes_used() { ExtBuilder::default() From 584ac58c37ab197145658e6c8882b649ac5c3406 Mon Sep 17 00:00:00 2001 From: dmoka Date: Mon, 9 Oct 2023 10:55:27 +0200 Subject: [PATCH 07/22] add integration test for sell dca without route --- integration-tests/src/dca.rs | 78 +++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 5 deletions(-) diff --git a/integration-tests/src/dca.rs b/integration-tests/src/dca.rs index 5e6e5a7d0..9c6bcfb04 100644 --- a/integration-tests/src/dca.rs +++ b/integration-tests/src/dca.rs @@ -494,6 +494,54 @@ mod omnipool { }); } + //TODO: continue from here + #[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, + PoolType::Omnipool, + 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!(false); + + //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(); @@ -2075,6 +2123,30 @@ fn schedule_fake_with_sell_order( asset_in: AssetId, asset_out: AssetId, amount: Balance, +) -> Schedule { + schedule_fake_with_sell_order_with_route( + owner, + pool, + 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], + pool: PoolType, + total_amount: Balance, + asset_in: AssetId, + asset_out: AssetId, + amount: Balance, + route: Vec>, ) -> Schedule { Schedule { owner: AccountId::from(owner), @@ -2088,11 +2160,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), }, } } From 41319539bdb5f14905ed4a944ea1b6bf499e6850 Mon Sep 17 00:00:00 2001 From: dmoka Date: Mon, 9 Oct 2023 11:14:46 +0200 Subject: [PATCH 08/22] add check for adapter to prevent returning 1 as price when there are no routes --- runtime/adapters/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/runtime/adapters/src/lib.rs b/runtime/adapters/src/lib.rs index 4bfb7fb5d..0706a6bee 100644 --- a/runtime/adapters/src/lib.rs +++ b/runtime/adapters/src/lib.rs @@ -562,6 +562,10 @@ where prices.push(price); } + if prices.is_empty() { + return None; + } + let nominator = prices .iter() .try_fold(U512::from(1u128), |acc, price| acc.checked_mul(U512::from(price.n)))?; From 49159cb495a67fd521482ac9009722e4fd321f8a Mon Sep 17 00:00:00 2001 From: dmoka Date: Mon, 9 Oct 2023 11:15:44 +0200 Subject: [PATCH 09/22] use default routes if needed in the price stability check of DCA --- integration-tests/src/dca.rs | 2 -- pallets/dca/src/lib.rs | 8 ++------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/integration-tests/src/dca.rs b/integration-tests/src/dca.rs index 9c6bcfb04..515e88430 100644 --- a/integration-tests/src/dca.rs +++ b/integration-tests/src/dca.rs @@ -494,7 +494,6 @@ mod omnipool { }); } - //TODO: continue from here #[test] fn sell_schedule_should_work_without_route() { TestNet::reset(); @@ -530,7 +529,6 @@ mod omnipool { //Act run_to_block(11, 15); - assert!(false); //Assert assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); diff --git a/pallets/dca/src/lib.rs b/pallets/dca/src/lib.rs index 2122b5742..04cbd402b 100644 --- a/pallets/dca/src/lib.rs +++ b/pallets/dca/src/lib.rs @@ -791,9 +791,7 @@ impl Pallet { } fn is_price_unstable(schedule: &Schedule) -> bool { - let route = match &schedule.order { - Order::Sell { route, .. } | Order::Buy { route, .. } => route, - }; + let route = &schedule.order.get_route_or_default::(); let Ok(last_block_price) = Self::get_price_from_last_block_oracle(route) else { return true; @@ -1056,9 +1054,7 @@ impl Pallet { Ok(price_from_rational) } - fn get_price_from_short_oracle( - route: &BoundedVec, ConstU32<5>>, - ) -> Result { + fn get_price_from_short_oracle(route: &[Trade]) -> Result { let price = T::OraclePriceProvider::price(route, OraclePeriod::Short).ok_or(Error::::CalculatingPriceError)?; From bb5a6f55334f939759b7a8b0685425b3aebd1af4 Mon Sep 17 00:00:00 2001 From: dmoka Date: Mon, 9 Oct 2023 13:45:36 +0200 Subject: [PATCH 10/22] add test for buy dca without route --- integration-tests/src/dca.rs | 66 +++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/integration-tests/src/dca.rs b/integration-tests/src/dca.rs index 515e88430..cfa474787 100644 --- a/integration-tests/src/dca.rs +++ b/integration-tests/src/dca.rs @@ -100,6 +100,44 @@ 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(PoolType::Omnipool, 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(); @@ -2092,6 +2130,28 @@ fn schedule_fake_with_buy_order( asset_out: AssetId, amount: Balance, budget: Balance, +) -> Schedule { + schedule_fake_with_buy_order_with_route( + pool, + asset_in, + asset_out, + amount, + budget, + vec![Trade { + pool, + asset_in, + asset_out, + }], + ) +} + +fn schedule_fake_with_buy_order_with_route( + pool: PoolType, + asset_in: AssetId, + asset_out: AssetId, + amount: Balance, + budget: Balance, + route: Vec>, ) -> Schedule { Schedule { owner: AccountId::from(ALICE), @@ -2105,11 +2165,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), }, } } From 8af24db4fe1df11dc8a12313963ae49ffffd7d35 Mon Sep 17 00:00:00 2001 From: dmoka Date: Mon, 9 Oct 2023 13:45:47 +0200 Subject: [PATCH 11/22] refactoring --- integration-tests/src/dca.rs | 18 +++--------------- pallets/dca/src/lib.rs | 3 --- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/integration-tests/src/dca.rs b/integration-tests/src/dca.rs index cfa474787..ed15a02c8 100644 --- a/integration-tests/src/dca.rs +++ b/integration-tests/src/dca.rs @@ -113,8 +113,7 @@ mod omnipool { let amount_out = 100 * UNITS; let no_route = vec![]; - let schedule1 = - schedule_fake_with_buy_order_with_route(PoolType::Omnipool, HDX, DAI, amount_out, dca_budget, no_route); + 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); @@ -549,15 +548,8 @@ mod omnipool { 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, - PoolType::Omnipool, - dca_budget, - HDX, - DAI, - amount_to_sell, - no_route, - ); + 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); @@ -2132,7 +2124,6 @@ fn schedule_fake_with_buy_order( budget: Balance, ) -> Schedule { schedule_fake_with_buy_order_with_route( - pool, asset_in, asset_out, amount, @@ -2146,7 +2137,6 @@ fn schedule_fake_with_buy_order( } fn schedule_fake_with_buy_order_with_route( - pool: PoolType, asset_in: AssetId, asset_out: AssetId, amount: Balance, @@ -2180,7 +2170,6 @@ fn schedule_fake_with_sell_order( ) -> Schedule { schedule_fake_with_sell_order_with_route( owner, - pool, total_amount, asset_in, asset_out, @@ -2195,7 +2184,6 @@ fn schedule_fake_with_sell_order( fn schedule_fake_with_sell_order_with_route( owner: [u8; 32], - pool: PoolType, total_amount: Balance, asset_in: AssetId, asset_out: AssetId, diff --git a/pallets/dca/src/lib.rs b/pallets/dca/src/lib.rs index 04cbd402b..c99fef147 100644 --- a/pallets/dca/src/lib.rs +++ b/pallets/dca/src/lib.rs @@ -73,7 +73,6 @@ use frame_support::{ }; use frame_system::{ensure_signed, pallet_prelude::OriginFor, Origin}; use hydradx_adapters::RelayChainBlockHashProvider; -use hydradx_traits::pools::SpotPriceProvider; use hydradx_traits::router::RouteProvider; use hydradx_traits::router::{AmmTradeWeights, AmountInAndOut, RouterT, Trade}; use hydradx_traits::NativePriceOracle; @@ -346,8 +345,6 @@ pub mod pallet { TradeLimitReached, ///Slippage limit calculated from oracle is reached, leading to retry SlippageLimitReached, - ///The route to execute the trade on is not specified - RouteNotSpecified, //TODO: Dani - delete it ///No parent hash has been found from relay chain NoParentHashFound, ///Error that should not really happen only in case of invalid state of the schedule storage entries From 08ce4df9386d0d0600d0a34c2da427628b1ce89b Mon Sep 17 00:00:00 2001 From: dmoka Date: Mon, 9 Oct 2023 16:12:33 +0200 Subject: [PATCH 12/22] use default route in benchmark if not specified --- pallets/dca/src/lib.rs | 3 ++- pallets/dca/src/types.rs | 8 -------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/pallets/dca/src/lib.rs b/pallets/dca/src/lib.rs index c99fef147..861c3e552 100644 --- a/pallets/dca/src/lib.rs +++ b/pallets/dca/src/lib.rs @@ -411,7 +411,8 @@ pub mod pallet { /// Emits `Scheduled` and `ExecutionPlanned` event when successful. /// #[pallet::call_index(0)] - #[pallet::weight(::WeightInfo::schedule() + ::AmmTradeWeights::calculate_buy_trade_amounts_weight(schedule.order.get_route()))] + #[pallet::weight(::WeightInfo::schedule() + + ::AmmTradeWeights::calculate_buy_trade_amounts_weight(&schedule.order.get_route_or_default::()))] #[transactional] pub fn schedule( origin: OriginFor, diff --git a/pallets/dca/src/types.rs b/pallets/dca/src/types.rs index 4d17002bb..8c9d7f100 100644 --- a/pallets/dca/src/types.rs +++ b/pallets/dca/src/types.rs @@ -72,14 +72,6 @@ where *asset_out } - //TODO: we should remove this, also from benchmark, and but the new method - pub fn get_route(&self) -> &BoundedVec, ConstU32<5>> { - match &self { - Order::Sell { route, .. } => route, - Order::Buy { route, .. } => route, - } - } - pub fn get_route_or_default>(&self) -> Vec> { let route = match &self { Order::Sell { route, .. } => route, From 61c88a68bef41ef8114a229fe2cc4b3437f78596 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 10 Oct 2023 13:41:33 +0200 Subject: [PATCH 13/22] renaming --- pallets/dca/src/lib.rs | 16 +++++++++++----- pallets/dca/src/tests/mock.rs | 2 +- runtime/hydradx/src/assets.rs | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/pallets/dca/src/lib.rs b/pallets/dca/src/lib.rs index 861c3e552..7eb1096d2 100644 --- a/pallets/dca/src/lib.rs +++ b/pallets/dca/src/lib.rs @@ -229,7 +229,13 @@ pub mod pallet { type NativePriceOracle: NativePriceOracle; ///Router implementation - type Router: RouterT, AmountInAndOut>; + type RouteExecutor: RouterT< + Self::RuntimeOrigin, + Self::AssetId, + Balance, + Trade, + AmountInAndOut, + >; ///Spot price provider to get the current price between two asset type RouteProvider: RouteProvider; @@ -644,7 +650,7 @@ impl Pallet { .checked_sub(slippage_amount) .ok_or(ArithmeticError::Overflow)?; - let trade_amounts = T::Router::calculate_sell_trade_amounts(&route, amount_to_sell)?; + let trade_amounts = T::RouteExecutor::calculate_sell_trade_amounts(route, amount_to_sell)?; let last_trade = trade_amounts.last().defensive_ok_or(Error::::InvalidState)?; let amount_out = last_trade.amount_out; @@ -657,7 +663,7 @@ impl Pallet { ); }; - T::Router::sell( + T::RouteExecutor::sell( origin, *asset_in, *asset_out, @@ -698,7 +704,7 @@ impl Pallet { ); }; - T::Router::buy(origin, *asset_in, *asset_out, *amount_out, amount_in, route.to_vec())?; + T::RouteExecutor::buy(origin, *asset_in, *asset_out, *amount_out, amount_in, route.to_vec())?; Ok(AmountInAndOut { amount_in, @@ -833,7 +839,7 @@ impl Pallet { } fn get_amount_in_for_buy(amount_out: &Balance, route: &[Trade]) -> Result { - let trade_amounts = T::Router::calculate_buy_trade_amounts(route.as_ref(), *amount_out)?; + let trade_amounts = T::RouteExecutor::calculate_buy_trade_amounts(route, *amount_out)?; let first_trade = trade_amounts.last().defensive_ok_or(Error::::InvalidState)?; diff --git a/pallets/dca/src/tests/mock.rs b/pallets/dca/src/tests/mock.rs index 8b34507b5..e59cdee7f 100644 --- a/pallets/dca/src/tests/mock.rs +++ b/pallets/dca/src/tests/mock.rs @@ -629,7 +629,7 @@ impl Config for Test { type WeightToFee = IdentityFee; type WeightInfo = (); type OraclePriceProvider = PriceProviderMock; - type Router = RouteExecutor; + type RouteExecutor = RouteExecutor; type RouteProvider = DefaultRouteProvider; type MaxPriceDifferenceBetweenBlocks = OmnipoolMaxAllowedPriceDifference; type NamedReserveId = NamedReserveId; diff --git a/runtime/hydradx/src/assets.rs b/runtime/hydradx/src/assets.rs index 79699e925..c929df29a 100644 --- a/runtime/hydradx/src/assets.rs +++ b/runtime/hydradx/src/assets.rs @@ -470,9 +470,9 @@ impl pallet_dca::Config for Runtime { #[cfg(feature = "runtime-benchmarks")] type OraclePriceProvider = DummyOraclePriceProvider; #[cfg(not(feature = "runtime-benchmarks"))] - type Router = Router; + type RouteExecutor = Router; #[cfg(feature = "runtime-benchmarks")] - type Router = pallet_route_executor::DummyRouter; + type RouteExecutor = pallet_route_executor::DummyRouter; type RouteProvider = Runtime; type MaxPriceDifferenceBetweenBlocks = MaxPriceDifference; type MaxSchedulePerBlock = MaxSchedulesPerBlock; From 898fe6900b65984ce0ce62f15df04dba0dd4445d Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 10 Oct 2023 13:43:09 +0200 Subject: [PATCH 14/22] bump versions --- integration-tests/Cargo.toml | 2 +- pallets/dca/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 427cb6e53..18fd3b3e6 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.13.0" +version = "1.13.2" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/pallets/dca/Cargo.toml b/pallets/dca/Cargo.toml index 00e5aef6a..7e50d9283 100644 --- a/pallets/dca/Cargo.toml +++ b/pallets/dca/Cargo.toml @@ -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' From 48cc893d08377e8d945d2eac286c450fff914420 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 10 Oct 2023 14:01:00 +0200 Subject: [PATCH 15/22] bump versions --- Cargo.lock | 10 +++++----- runtime/adapters/Cargo.toml | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 2 +- traits/Cargo.toml | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c27a34c6f..55706599c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3786,7 +3786,7 @@ dependencies = [ [[package]] name = "hydradx-adapters" -version = "0.6.3" +version = "0.6.4" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -3831,7 +3831,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "183.0.0" +version = "184.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -3937,7 +3937,7 @@ dependencies = [ [[package]] name = "hydradx-traits" -version = "2.7.0" +version = "2.7.1" dependencies = [ "frame-support", "impl-trait-for-tuples", @@ -6598,7 +6598,7 @@ dependencies = [ [[package]] name = "pallet-dca" -version = "1.2.0" +version = "1.2.2" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -10220,7 +10220,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.13.0" +version = "1.13.2" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/runtime/adapters/Cargo.toml b/runtime/adapters/Cargo.toml index d2129fde7..1b001889f 100644 --- a/runtime/adapters/Cargo.toml +++ b/runtime/adapters/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-adapters" -version = "0.6.3" +version = "0.6.4" description = "Structs and other generic types for building runtimes." authors = ["GalacticCouncil"] edition = "2021" diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index 4d36357fe..bcbe3e3a5 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "183.0.0" +version = "184.0.0" authors = ["GalacticCouncil"] edition = "2021" license = "Apache 2.0" diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index c7ffe6dd6..50436df0c 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -94,7 +94,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 183, + spec_version: 184, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, diff --git a/traits/Cargo.toml b/traits/Cargo.toml index 8a236ed39..2842daea3 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-traits" -version = "2.7.0" +version = "2.7.1" description = "Shared traits" authors = ["GalacticCouncil"] edition = "2021" From 5d34cdbb70e5c2713bfaf3c1c454f385ebcc5a1e Mon Sep 17 00:00:00 2001 From: martinfridrich Date: Tue, 24 Oct 2023 14:14:30 +0200 Subject: [PATCH 16/22] pallet-xyk: remove dep on primitives --- Cargo.lock | 6 +-- integration-tests/Cargo.toml | 2 +- integration-tests/src/xyk.rs | 2 +- pallets/xyk/Cargo.toml | 2 +- pallets/xyk/src/impls.rs | 3 +- pallets/xyk/src/lib.rs | 18 +++---- pallets/xyk/src/tests/amm_position.rs | 2 +- pallets/xyk/src/tests/creation.rs | 2 +- pallets/xyk/src/tests/fees.rs | 2 +- pallets/xyk/src/tests/liquidity.rs | 4 +- pallets/xyk/src/tests/mock.rs | 6 ++- pallets/xyk/src/tests/spot_price.rs | 3 +- pallets/xyk/src/tests/trades.rs | 2 +- pallets/xyk/src/trade_execution.rs | 3 +- pallets/xyk/src/types.rs | 68 +++++++++++++++++++++++++++ runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/assets.rs | 2 + runtime/hydradx/src/lib.rs | 2 +- 18 files changed, 100 insertions(+), 31 deletions(-) create mode 100644 pallets/xyk/src/types.rs diff --git a/Cargo.lock b/Cargo.lock index c27a34c6f..b9d94998b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3831,7 +3831,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "183.0.0" +version = "184.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -7779,7 +7779,7 @@ dependencies = [ [[package]] name = "pallet-xyk" -version = "6.2.10" +version = "6.3.0" dependencies = [ "frame-benchmarking", "frame-support", @@ -10220,7 +10220,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.13.0" +version = "1.14.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 427cb6e53..dcc8170dd 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.13.0" +version = "1.14.0" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/integration-tests/src/xyk.rs b/integration-tests/src/xyk.rs index 882427e27..ed737e062 100644 --- a/integration-tests/src/xyk.rs +++ b/integration-tests/src/xyk.rs @@ -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}; diff --git a/pallets/xyk/Cargo.toml b/pallets/xyk/Cargo.toml index 4c88f9acc..0bb2fac5d 100644 --- a/pallets/xyk/Cargo.toml +++ b/pallets/xyk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-xyk' -version = "6.2.10" +version = "6.3.0" description = 'XYK automated market maker' authors = ['GalacticCouncil'] edition = '2021' diff --git a/pallets/xyk/src/impls.rs b/pallets/xyk/src/impls.rs index 8bba9f9a6..41f8a3ca0 100644 --- a/pallets/xyk/src/impls.rs +++ b/pallets/xyk/src/impls.rs @@ -1,8 +1,7 @@ +use crate::types::{AssetId, AssetPair, Price}; use hydradx_traits::pools::SpotPriceProvider; use hydradx_traits::AMM; use orml_traits::MultiCurrency; -use primitives::asset::AssetPair; -use primitives::{AssetId, Price}; use sp_runtime::FixedPointNumber; use sp_std::marker::PhantomData; diff --git a/pallets/xyk/src/lib.rs b/pallets/xyk/src/lib.rs index 9e442e140..a53812719 100644 --- a/pallets/xyk/src/lib.rs +++ b/pallets/xyk/src/lib.rs @@ -35,9 +35,9 @@ use hydradx_traits::{ AMMPosition, AMMTransfer, AssetPairAccountIdFor, CanCreatePool, OnCreatePoolHandler, OnLiquidityChangedHandler, OnTradeHandler, Source, AMM, }; -use primitives::{asset::AssetPair, AssetId, Balance}; use sp_std::{vec, vec::Vec}; +use crate::types::{AssetId, AssetPair, Balance}; use hydra_dx_math::ratio::Ratio; use orml_traits::{MultiCurrency, MultiCurrencyExtended}; use primitives::Amount; @@ -49,15 +49,13 @@ mod benchmarking; mod impls; mod trade_execution; +pub mod types; pub mod weights; pub use impls::XYKSpotPrice; use weights::WeightInfo; -/// Oracle source identifier for this pallet. -pub const SOURCE: Source = *b"hydraxyk"; - // Re-export pallet items so that they can be accessed from the crate namespace. pub use pallet::*; @@ -114,6 +112,10 @@ pub mod pallet { #[pallet::constant] type MaxOutRatio: Get; + /// Oracle source identifier for this pallet. + #[pallet::constant] + type OracleSource: Get; + /// Called to ensure that pool can be created type CanCreatePool: CanCreatePool; @@ -461,7 +463,7 @@ pub mod pallet { let liquidity_a = T::Currency::total_balance(asset_a, &pair_account); let liquidity_b = T::Currency::total_balance(asset_b, &pair_account); T::AMMHandler::on_liquidity_changed( - SOURCE, + T::OracleSource::get(), asset_a, asset_b, amount_a, @@ -567,7 +569,7 @@ pub mod pallet { let liquidity_a = T::Currency::total_balance(asset_a, &pair_account); let liquidity_b = T::Currency::total_balance(asset_b, &pair_account); T::AMMHandler::on_liquidity_changed( - SOURCE, + T::OracleSource::get(), asset_a, asset_b, remove_amount_a, @@ -870,7 +872,7 @@ impl AMM for Pallet { let liquidity_in = T::Currency::total_balance(transfer.assets.asset_in, &pair_account); let liquidity_out = T::Currency::total_balance(transfer.assets.asset_out, &pair_account); T::AMMHandler::on_trade( - SOURCE, + T::OracleSource::get(), transfer.assets.asset_in, transfer.assets.asset_out, transfer.amount, @@ -1032,7 +1034,7 @@ impl AMM for Pallet { let liquidity_in = T::Currency::total_balance(transfer.assets.asset_in, &pair_account); let liquidity_out = T::Currency::total_balance(transfer.assets.asset_out, &pair_account); T::AMMHandler::on_trade( - SOURCE, + T::OracleSource::get(), transfer.assets.asset_in, transfer.assets.asset_out, transfer.amount, diff --git a/pallets/xyk/src/tests/amm_position.rs b/pallets/xyk/src/tests/amm_position.rs index b04b73da1..65196d4d3 100644 --- a/pallets/xyk/src/tests/amm_position.rs +++ b/pallets/xyk/src/tests/amm_position.rs @@ -1,7 +1,7 @@ use super::mock::*; +use crate::types::AssetPair; use crate::*; use frame_support::assert_ok; -use primitives::asset::AssetPair; #[test] fn get_liquidity_behind_shares_should_return_both_assets_value_when_pool_exists() { diff --git a/pallets/xyk/src/tests/creation.rs b/pallets/xyk/src/tests/creation.rs index fb4e56ba2..30e2a67fa 100644 --- a/pallets/xyk/src/tests/creation.rs +++ b/pallets/xyk/src/tests/creation.rs @@ -7,7 +7,7 @@ use orml_traits::MultiCurrency; use pallet_asset_registry::AssetType; use sp_std::convert::TryInto; -use primitives::asset::AssetPair; +use crate::types::AssetPair; #[test] fn create_pool_should_work() { diff --git a/pallets/xyk/src/tests/fees.rs b/pallets/xyk/src/tests/fees.rs index 07477e8f4..49937e3a8 100644 --- a/pallets/xyk/src/tests/fees.rs +++ b/pallets/xyk/src/tests/fees.rs @@ -4,7 +4,7 @@ use frame_support::{assert_noop, assert_ok}; use hydradx_traits::AMM as AmmPool; use orml_traits::MultiCurrency; -use primitives::asset::AssetPair; +use crate::types::AssetPair; #[test] fn fee_calculation() { diff --git a/pallets/xyk/src/tests/liquidity.rs b/pallets/xyk/src/tests/liquidity.rs index 7a5438387..2e2ac8e40 100644 --- a/pallets/xyk/src/tests/liquidity.rs +++ b/pallets/xyk/src/tests/liquidity.rs @@ -1,12 +1,10 @@ pub use super::mock::*; +use crate::types::{AssetPair, Balance}; use crate::{Error, Event}; use frame_support::{assert_noop, assert_ok}; use hydradx_traits::AMM as AmmPool; use orml_traits::MultiCurrency; -use primitives::asset::AssetPair; -use primitives::Balance; - #[test] fn add_liquidity_should_work() { new_test_ext().execute_with(|| { diff --git a/pallets/xyk/src/tests/mock.rs b/pallets/xyk/src/tests/mock.rs index a376fa2aa..9823f1e67 100644 --- a/pallets/xyk/src/tests/mock.rs +++ b/pallets/xyk/src/tests/mock.rs @@ -27,9 +27,9 @@ use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup, One}, }; +use crate::types::{AssetId, Balance}; use frame_support::traits::{Everything, GenesisBuild, Get, Nothing}; -use hydradx_traits::{AssetPairAccountIdFor, CanCreatePool}; -use primitives::{AssetId, Balance}; +use hydradx_traits::{AssetPairAccountIdFor, CanCreatePool, Source}; use frame_system::EnsureSigned; use hydradx_traits::pools::DustRemovalAccountWhitelist; @@ -181,6 +181,7 @@ parameter_types! { pub MaxOutRatio: u128 = MaximumOutRatio::get(); pub ExchangeFeeRate: (u32, u32) = ExchangeFee::get(); pub DiscountedFeeRate: (u32, u32) = DiscountedFee::get(); + pub const OracleSourceIdentifier: Source = *b"hydraxyk"; } pub struct Disallow10_10Pool(); @@ -207,6 +208,7 @@ impl Config for Test { type AMMHandler = (); type DiscountedFee = DiscountedFeeRate; type NonDustableWhitelistHandler = Whitelist; + type OracleSource = OracleSourceIdentifier; } pub struct ExtBuilder { diff --git a/pallets/xyk/src/tests/spot_price.rs b/pallets/xyk/src/tests/spot_price.rs index 66bf37eba..b24eea24e 100644 --- a/pallets/xyk/src/tests/spot_price.rs +++ b/pallets/xyk/src/tests/spot_price.rs @@ -1,11 +1,10 @@ use super::mock::*; +use crate::types::{AssetPair, Price}; use crate::XYKSpotPrice; use crate::*; use frame_support::assert_ok; use frame_support::dispatch::RawOrigin; use hydradx_traits::pools::SpotPriceProvider; -use primitives::asset::AssetPair; -use primitives::Price; #[test] fn spot_price_provider_should_return_correct_price_when_pool_exists() { diff --git a/pallets/xyk/src/tests/trades.rs b/pallets/xyk/src/tests/trades.rs index 5c51c2d9b..55c05d925 100644 --- a/pallets/xyk/src/tests/trades.rs +++ b/pallets/xyk/src/tests/trades.rs @@ -4,7 +4,7 @@ use frame_support::{assert_noop, assert_ok}; use hydradx_traits::AMM as AmmPool; use orml_traits::MultiCurrency; -use primitives::asset::AssetPair; +use crate::types::AssetPair; #[test] fn sell_test() { diff --git a/pallets/xyk/src/trade_execution.rs b/pallets/xyk/src/trade_execution.rs index 6722ed711..c0d77218e 100644 --- a/pallets/xyk/src/trade_execution.rs +++ b/pallets/xyk/src/trade_execution.rs @@ -1,11 +1,10 @@ +use crate::types::{AssetId, AssetPair, Balance}; use crate::{Config, Error, Pallet}; use frame_support::ensure; use frame_support::traits::Get; use hydradx_traits::router::{ExecutorError, PoolType, TradeExecution}; use hydradx_traits::AMM; use orml_traits::MultiCurrency; -use primitives::asset::AssetPair; -use primitives::{AssetId, Balance}; use sp_runtime::DispatchError; impl TradeExecution for Pallet { diff --git a/pallets/xyk/src/types.rs b/pallets/xyk/src/types.rs new file mode 100644 index 000000000..acae283c6 --- /dev/null +++ b/pallets/xyk/src/types.rs @@ -0,0 +1,68 @@ +// This file is part of Basilisk-node. + +// Copyright (C) 2020-2022 Intergalactic, Limited (GIB). +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +pub type AssetId = u32; +pub type Balance = u128; +pub type Price = FixedU128; + +use codec::{Decode, Encode}; +use scale_info::TypeInfo; +use sp_runtime::FixedU128; +use sp_std::vec::Vec; + +#[cfg(feature = "std")] +use serde::{Deserialize, Serialize}; + +/// Asset Pair representation for AMM trades +/// ( asset_a, asset_b ) combination where asset_a is meant to be exchanged for asset_b +/// +/// asset_in represents asset coming into the pool +/// asset_out represents asset coming out of the pool +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] +#[derive(Debug, Encode, Decode, Copy, Clone, PartialEq, Eq, Default, TypeInfo)] +pub struct AssetPair { + pub asset_in: AssetId, + pub asset_out: AssetId, +} + +impl AssetPair { + pub fn new(asset_in: AssetId, asset_out: AssetId) -> Self { + Self { asset_in, asset_out } + } + + /// Return ordered asset tuple (A,B) where A < B + /// Used in storage + pub fn ordered_pair(&self) -> (AssetId, AssetId) { + match self.asset_in <= self.asset_out { + true => (self.asset_in, self.asset_out), + false => (self.asset_out, self.asset_in), + } + } + + /// Return share token name + pub fn name(&self) -> Vec { + let mut buf: Vec = Vec::new(); + + let (asset_a, asset_b) = self.ordered_pair(); + + buf.extend_from_slice(&asset_a.to_le_bytes()); + buf.extend_from_slice(b"HDT"); + buf.extend_from_slice(&asset_b.to_le_bytes()); + + buf + } +} diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index 4d36357fe..bcbe3e3a5 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "183.0.0" +version = "184.0.0" authors = ["GalacticCouncil"] edition = "2021" license = "Apache 2.0" diff --git a/runtime/hydradx/src/assets.rs b/runtime/hydradx/src/assets.rs index f8c922620..ee1a6fd47 100644 --- a/runtime/hydradx/src/assets.rs +++ b/runtime/hydradx/src/assets.rs @@ -906,6 +906,7 @@ impl pallet_lbp::Config for Runtime { parameter_types! { pub XYKExchangeFee: (u32, u32) = (3, 1_000); pub const DiscountedFee: (u32, u32) = (7, 10_000); + pub const XYKOracleSourceIdentifier: Source = *b"hydraxyk"; } impl pallet_xyk::Config for Runtime { @@ -924,4 +925,5 @@ impl pallet_xyk::Config for Runtime { type AMMHandler = pallet_ema_oracle::OnActivityHandler; type DiscountedFee = DiscountedFee; type NonDustableWhitelistHandler = Duster; + type OracleSource = XYKOracleSourceIdentifier; } diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index c7ffe6dd6..50436df0c 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -94,7 +94,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 183, + spec_version: 184, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 5f2368aab9bb50dc596569fd31e2c8c7941cc220 Mon Sep 17 00:00:00 2001 From: mrq Date: Tue, 31 Oct 2023 18:08:12 +0100 Subject: [PATCH 17/22] runtime 185 --- Cargo.lock | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index afe7f7b0d..05570fc48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3831,7 +3831,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "184.0.0" +version = "185.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index bcbe3e3a5..d111e2533 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "184.0.0" +version = "185.0.0" authors = ["GalacticCouncil"] edition = "2021" license = "Apache 2.0" diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index 50436df0c..b23f7efe7 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -94,7 +94,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 184, + spec_version: 185, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 33c742e4290fa4653d33dd092db25903834bad00 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Thu, 2 Nov 2023 16:37:40 +0100 Subject: [PATCH 18/22] move asset pair to lbp pallet --- Cargo.lock | 6 +-- integration-tests/Cargo.toml | 2 +- integration-tests/src/omnipool_init.rs | 1 - integration-tests/src/router.rs | 3 +- pallets/lbp/Cargo.toml | 2 +- pallets/lbp/src/benchmarking.rs | 1 - pallets/lbp/src/lib.rs | 5 +- pallets/lbp/src/mock.rs | 7 ++- pallets/lbp/src/tests.rs | 1 - pallets/lbp/src/trade_execution.rs | 4 +- pallets/lbp/src/types.rs | 66 ++++++++++++++++++++++++++ primitives/src/asset.rs | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 2 +- 14 files changed, 85 insertions(+), 19 deletions(-) create mode 100644 pallets/lbp/src/types.rs diff --git a/Cargo.lock b/Cargo.lock index f2a1440b0..99fd51f3f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3831,7 +3831,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "186.0.0" +version = "187.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -6911,7 +6911,7 @@ dependencies = [ [[package]] name = "pallet-lbp" -version = "4.6.16" +version = "4.7.0" dependencies = [ "frame-benchmarking", "frame-support", @@ -10220,7 +10220,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.15.0" +version = "1.15.1" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 663d811ec..4bdac3b87 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.15.0" +version = "1.15.1" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/integration-tests/src/omnipool_init.rs b/integration-tests/src/omnipool_init.rs index da18be5c8..a363f4107 100644 --- a/integration-tests/src/omnipool_init.rs +++ b/integration-tests/src/omnipool_init.rs @@ -296,7 +296,6 @@ fn removing_token_should_work_when_no_shares_remaining() { position.shares, )); - let state = pallet_omnipool::Pallet::::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); diff --git a/integration-tests/src/router.rs b/integration-tests/src/router.rs index e46cd5d37..2fb234ee2 100644 --- a/integration-tests/src/router.rs +++ b/integration-tests/src/router.rs @@ -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}; @@ -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, }; diff --git a/pallets/lbp/Cargo.toml b/pallets/lbp/Cargo.toml index 72c7b5861..a07116304 100644 --- a/pallets/lbp/Cargo.toml +++ b/pallets/lbp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-lbp" -version = "4.6.16" +version = "4.7.0" description = "HydraDX Liquidity Bootstrapping Pool Pallet" authors = ["GalacticCouncil"] edition = "2021" diff --git a/pallets/lbp/src/benchmarking.rs b/pallets/lbp/src/benchmarking.rs index e9bba5295..f00406ede 100644 --- a/pallets/lbp/src/benchmarking.rs +++ b/pallets/lbp/src/benchmarking.rs @@ -20,7 +20,6 @@ use super::*; use crate::Pallet as LBP; use hydradx_traits::router::{PoolType, TradeExecution}; -use primitives::AssetId; use frame_benchmarking::{account, benchmarks}; use frame_system::RawOrigin; diff --git a/pallets/lbp/src/lib.rs b/pallets/lbp/src/lib.rs index 01a551dc5..90115619f 100644 --- a/pallets/lbp/src/lib.rs +++ b/pallets/lbp/src/lib.rs @@ -21,6 +21,7 @@ #![allow(clippy::type_complexity)] #![allow(clippy::too_many_arguments)] +pub use crate::types::{AssetId, AssetPair, Balance}; use codec::{Decode, Encode, MaxEncodedLen}; use frame_support::sp_runtime::{ traits::{AtLeast32BitUnsigned, BlockNumberProvider, Saturating, Zero}, @@ -36,7 +37,7 @@ use frame_system::ensure_signed; use hydra_dx_math::types::LBPWeight; use hydradx_traits::{AMMTransfer, AssetPairAccountIdFor, CanCreatePool, LockedBalance, AMM}; use orml_traits::{MultiCurrency, MultiCurrencyExtended, MultiLockableCurrency}; -use primitives::{asset::AssetPair, Amount, AssetId, Balance}; +use primitives::Amount; use scale_info::TypeInfo; @@ -58,7 +59,9 @@ pub mod weights; #[cfg(test)] mod invariants; + mod trade_execution; +pub mod types; use weights::WeightInfo; // Re-export pallet items so that they can be accessed from the crate namespace. diff --git a/pallets/lbp/src/mock.rs b/pallets/lbp/src/mock.rs index 6f247e052..047e560cf 100644 --- a/pallets/lbp/src/mock.rs +++ b/pallets/lbp/src/mock.rs @@ -2,12 +2,15 @@ use super::*; use crate as lbp; -use crate::{AssetPairAccountIdFor, Config}; +use crate::{ + types::{AssetId, AssetPair, Balance}, + AssetPairAccountIdFor, Config, +}; use frame_support::parameter_types; use frame_support::traits::{Everything, GenesisBuild, LockIdentifier, Nothing}; use hydradx_traits::LockedBalance; use orml_traits::parameter_type_with_key; -use primitives::constants::chain::{AssetId, Balance, CORE_ASSET_ID}; +use primitives::constants::chain::CORE_ASSET_ID; use sp_core::H256; use sp_runtime::{ testing::Header, diff --git a/pallets/lbp/src/tests.rs b/pallets/lbp/src/tests.rs index 2ea4b6ee4..1ae2c5a3e 100644 --- a/pallets/lbp/src/tests.rs +++ b/pallets/lbp/src/tests.rs @@ -31,7 +31,6 @@ use hydradx_traits::{AMMTransfer, LockedBalance}; use sp_runtime::traits::BadOrigin; use sp_std::convert::TryInto; -use primitives::asset::AssetPair; use primitives::constants::chain::CORE_ASSET_ID; pub fn new_test_ext() -> sp_io::TestExternalities { diff --git a/pallets/lbp/src/trade_execution.rs b/pallets/lbp/src/trade_execution.rs index 3a0bc1c07..1acaf276d 100644 --- a/pallets/lbp/src/trade_execution.rs +++ b/pallets/lbp/src/trade_execution.rs @@ -1,9 +1,7 @@ -use crate::{Config, Error, Pallet, PoolData}; +use crate::*; use hydradx_traits::router::{ExecutorError, PoolType, TradeExecution}; use hydradx_traits::AMM; use orml_traits::MultiCurrency; -use primitives::asset::AssetPair; -use primitives::{AssetId, Balance}; use sp_runtime::traits::BlockNumberProvider; use sp_runtime::DispatchError; diff --git a/pallets/lbp/src/types.rs b/pallets/lbp/src/types.rs new file mode 100644 index 000000000..7b706279e --- /dev/null +++ b/pallets/lbp/src/types.rs @@ -0,0 +1,66 @@ +// This file is part of HydraDX-node. + +// Copyright (C) 2020-2022 Intergalactic, Limited (GIB). +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +pub type AssetId = u32; +pub type Balance = u128; + +use codec::{Decode, Encode}; +use scale_info::TypeInfo; +use sp_std::vec::Vec; + +#[cfg(feature = "std")] +use serde::{Deserialize, Serialize}; + +/// Asset Pair representation for AMM trades +/// ( asset_a, asset_b ) combination where asset_a is meant to be exchanged for asset_b +/// +/// asset_in represents asset coming into the pool +/// asset_out represents asset coming out of the pool +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] +#[derive(Debug, Encode, Decode, Copy, Clone, PartialEq, Eq, Default, TypeInfo)] +pub struct AssetPair { + pub asset_in: AssetId, + pub asset_out: AssetId, +} + +impl AssetPair { + pub fn new(asset_in: AssetId, asset_out: AssetId) -> Self { + Self { asset_in, asset_out } + } + + /// Return ordered asset tuple (A,B) where A < B + /// Used in storage + pub fn ordered_pair(&self) -> (AssetId, AssetId) { + match self.asset_in <= self.asset_out { + true => (self.asset_in, self.asset_out), + false => (self.asset_out, self.asset_in), + } + } + + /// Return share token name + pub fn name(&self) -> Vec { + let mut buf: Vec = Vec::new(); + + let (asset_a, asset_b) = self.ordered_pair(); + + buf.extend_from_slice(&asset_a.to_le_bytes()); + buf.extend_from_slice(b"HDT"); + buf.extend_from_slice(&asset_b.to_le_bytes()); + + buf + } +} diff --git a/primitives/src/asset.rs b/primitives/src/asset.rs index 534be4e0c..a5292963d 100644 --- a/primitives/src/asset.rs +++ b/primitives/src/asset.rs @@ -1,4 +1,4 @@ -// This file is part of Basilisk-node. +// This file is part of HydraDX-node. // Copyright (C) 2020-2022 Intergalactic, Limited (GIB). // SPDX-License-Identifier: Apache-2.0 diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index b072057df..cb89eaa34 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "186.0.0" +version = "187.0.0" authors = ["GalacticCouncil"] edition = "2021" license = "Apache 2.0" diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index 3c651f43a..9367396d9 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -94,7 +94,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 186, + spec_version: 187, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 88ff96bf6044ef5b33ae73240cf60142dd555c1f Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Thu, 2 Nov 2023 20:12:55 +0100 Subject: [PATCH 19/22] remove AssetPair from primitives --- primitives/src/asset.rs | 66 ----------------------------------------- primitives/src/lib.rs | 1 - 2 files changed, 67 deletions(-) delete mode 100644 primitives/src/asset.rs diff --git a/primitives/src/asset.rs b/primitives/src/asset.rs deleted file mode 100644 index a5292963d..000000000 --- a/primitives/src/asset.rs +++ /dev/null @@ -1,66 +0,0 @@ -// This file is part of HydraDX-node. - -// Copyright (C) 2020-2022 Intergalactic, Limited (GIB). -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::AssetId; - -use codec::{Decode, Encode}; - -use sp_std::vec::Vec; - -use scale_info::TypeInfo; - -#[cfg(feature = "std")] -use serde::{Deserialize, Serialize}; - -/// Asset Pair representation for AMM trades -/// ( asset_a, asset_b ) combination where asset_a is meant to be exchanged for asset_b -/// -/// asset_in represents asset coming into the pool -/// asset_out represents asset coming out of the pool -#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -#[derive(Debug, Encode, Decode, Copy, Clone, PartialEq, Eq, Default, TypeInfo)] -pub struct AssetPair { - pub asset_in: AssetId, - pub asset_out: AssetId, -} - -impl AssetPair { - pub fn new(asset_in: AssetId, asset_out: AssetId) -> Self { - Self { asset_in, asset_out } - } - /// Return ordered asset tuple (A,B) where A < B - /// Used in storage - pub fn ordered_pair(&self) -> (AssetId, AssetId) { - match self.asset_in <= self.asset_out { - true => (self.asset_in, self.asset_out), - false => (self.asset_out, self.asset_in), - } - } - - /// Return share token name - pub fn name(&self) -> Vec { - let mut buf: Vec = Vec::new(); - - let (asset_a, asset_b) = self.ordered_pair(); - - buf.extend_from_slice(&asset_a.to_le_bytes()); - buf.extend_from_slice(b"HDT"); - buf.extend_from_slice(&asset_b.to_le_bytes()); - - buf - } -} diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index a165cbbd8..9fe493c72 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -27,7 +27,6 @@ use frame_support::sp_runtime::{ MultiSignature, }; -pub mod asset; pub mod constants; /// An index to a block. From 681783f6db818b2f74a0ba2301608e1a5b42d9c2 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Thu, 2 Nov 2023 20:26:26 +0100 Subject: [PATCH 20/22] bump crate version --- Cargo.lock | 2 +- primitives/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 99fd51f3f..29dcb301b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9467,7 +9467,7 @@ dependencies = [ [[package]] name = "primitives" -version = "5.8.5" +version = "6.0.0" dependencies = [ "frame-support", "hex-literal 0.3.4", diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index d775fc942..4cbb432c3 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "primitives" -version = "5.8.5" +version = "6.0.0" authors = ["GalacticCouncil"] edition = "2021" repository = "https://github.com/galacticcouncil/HydraDX-node" From ba285bff95b4685ca1a43099bcbd9b896b02931a Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Thu, 2 Nov 2023 21:39:18 +0100 Subject: [PATCH 21/22] xyk and lbp: remove dependency on primitives --- Cargo.lock | 2 -- pallets/lbp/Cargo.toml | 2 -- pallets/lbp/src/lib.rs | 3 +-- pallets/lbp/src/mock.rs | 5 ++--- pallets/lbp/src/tests.rs | 10 ++++------ pallets/lbp/src/types.rs | 1 + pallets/xyk/Cargo.toml | 6 +----- pallets/xyk/src/benchmarking.rs | 2 +- pallets/xyk/src/lib.rs | 3 +-- pallets/xyk/src/types.rs | 1 + 10 files changed, 12 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 29dcb301b..ca0f68b3e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6923,7 +6923,6 @@ dependencies = [ "orml-traits", "parity-scale-codec", "primitive-types", - "primitives", "proptest", "rug", "scale-info", @@ -7794,7 +7793,6 @@ dependencies = [ "pallet-asset-registry", "parity-scale-codec", "primitive-types", - "primitives", "proptest", "scale-info", "serde", diff --git a/pallets/lbp/Cargo.toml b/pallets/lbp/Cargo.toml index a07116304..61d072fc9 100644 --- a/pallets/lbp/Cargo.toml +++ b/pallets/lbp/Cargo.toml @@ -23,7 +23,6 @@ serde = { features = ["derive"], optional = true, version = "1.0.136" } ## Local dependencies hydra-dx-math = { workspace = true } hydradx-traits = { workspace = true } -primitives = { workspace = true } ## ORML dependencies orml-traits = { workspace = true } @@ -63,7 +62,6 @@ std = [ "sp-runtime/std", "sp-core/std", "sp-std/std", - "primitives/std", "hydradx-traits/std", "scale-info/std", "hydra-dx-math/std", diff --git a/pallets/lbp/src/lib.rs b/pallets/lbp/src/lib.rs index 90115619f..9e18755c4 100644 --- a/pallets/lbp/src/lib.rs +++ b/pallets/lbp/src/lib.rs @@ -21,7 +21,7 @@ #![allow(clippy::type_complexity)] #![allow(clippy::too_many_arguments)] -pub use crate::types::{AssetId, AssetPair, Balance}; +pub use crate::types::{Amount, AssetId, AssetPair, Balance}; use codec::{Decode, Encode, MaxEncodedLen}; use frame_support::sp_runtime::{ traits::{AtLeast32BitUnsigned, BlockNumberProvider, Saturating, Zero}, @@ -37,7 +37,6 @@ use frame_system::ensure_signed; use hydra_dx_math::types::LBPWeight; use hydradx_traits::{AMMTransfer, AssetPairAccountIdFor, CanCreatePool, LockedBalance, AMM}; use orml_traits::{MultiCurrency, MultiCurrencyExtended, MultiLockableCurrency}; -use primitives::Amount; use scale_info::TypeInfo; diff --git a/pallets/lbp/src/mock.rs b/pallets/lbp/src/mock.rs index 047e560cf..97d27507e 100644 --- a/pallets/lbp/src/mock.rs +++ b/pallets/lbp/src/mock.rs @@ -10,7 +10,6 @@ use frame_support::parameter_types; use frame_support::traits::{Everything, GenesisBuild, LockIdentifier, Nothing}; use hydradx_traits::LockedBalance; use orml_traits::parameter_type_with_key; -use primitives::constants::chain::CORE_ASSET_ID; use sp_core::H256; use sp_runtime::{ testing::Header, @@ -31,7 +30,7 @@ pub const ALICE: AccountId = 1; pub const BOB: AccountId = 2; pub const CHARLIE: AccountId = 3; -pub const HDX: AssetId = CORE_ASSET_ID; +pub const HDX: AssetId = 0; pub const KUSD: AssetId = 2_000; pub const BSX: AssetId = 3_000; pub const ETH: AssetId = 4_000; @@ -154,7 +153,7 @@ impl AssetPairAccountIdFor for AssetPairAccountIdTest { } parameter_types! { - pub const NativeAssetId: AssetId = CORE_ASSET_ID; + pub const NativeAssetId: AssetId = HDX; pub const MinTradingLimit: Balance = 1_000; pub const MinPoolLiquidity: Balance = 1_000; pub const MaxInRatio: u128 = 3; diff --git a/pallets/lbp/src/tests.rs b/pallets/lbp/src/tests.rs index 1ae2c5a3e..c77bfbc9e 100644 --- a/pallets/lbp/src/tests.rs +++ b/pallets/lbp/src/tests.rs @@ -31,8 +31,6 @@ use hydradx_traits::{AMMTransfer, LockedBalance}; use sp_runtime::traits::BadOrigin; use sp_std::convert::TryInto; -use primitives::constants::chain::CORE_ASSET_ID; - pub fn new_test_ext() -> sp_io::TestExternalities { let mut ext = ExtBuilder::default().build(); ext.execute_with(|| set_block_number::(1)); @@ -2316,12 +2314,12 @@ fn buy_should_work() { .into(), frame_system::Event::NewAccount { account: pool_id2 }.into(), mock::RuntimeEvent::Currency(orml_tokens::Event::Endowed { - currency_id: CORE_ASSET_ID, + currency_id: HDX, who: HDX_BSX_POOL_ID, amount: 1000000000, }), mock::RuntimeEvent::Currency(orml_tokens::Event::Transfer { - currency_id: CORE_ASSET_ID, + currency_id: HDX, from: ALICE, to: HDX_BSX_POOL_ID, amount: 1000000000, @@ -2543,12 +2541,12 @@ fn sell_should_work() { .into(), frame_system::Event::NewAccount { account: pool_id2 }.into(), mock::RuntimeEvent::Currency(orml_tokens::Event::Endowed { - currency_id: CORE_ASSET_ID, + currency_id: HDX, who: HDX_BSX_POOL_ID, amount: 1000000000, }), mock::RuntimeEvent::Currency(orml_tokens::Event::Transfer { - currency_id: CORE_ASSET_ID, + currency_id: HDX, from: ALICE, to: HDX_BSX_POOL_ID, amount: 1000000000, diff --git a/pallets/lbp/src/types.rs b/pallets/lbp/src/types.rs index 7b706279e..63c51add9 100644 --- a/pallets/lbp/src/types.rs +++ b/pallets/lbp/src/types.rs @@ -16,6 +16,7 @@ // limitations under the License. pub type AssetId = u32; +pub type Amount = i128; pub type Balance = u128; use codec::{Decode, Encode}; diff --git a/pallets/xyk/Cargo.toml b/pallets/xyk/Cargo.toml index 0bb2fac5d..f9a07717a 100644 --- a/pallets/xyk/Cargo.toml +++ b/pallets/xyk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-xyk' -version = "6.3.0" +version = "6.3.1" description = 'XYK automated market maker' authors = ['GalacticCouncil'] edition = '2021' @@ -23,9 +23,6 @@ log = { version = "0.4.17", default-features = false } hydra-dx-math = { workspace = true } -# Local dependencies -primitives = {path = '../../primitives', default-features = false} - # ORML dependencies orml-tokens = { workspace = true } orml-traits = { workspace = true } @@ -65,7 +62,6 @@ std = [ 'sp-core/std', 'sp-std/std', 'orml-traits/std', - 'primitives/std', "hydradx-traits/std", 'orml-tokens/std', 'frame-benchmarking/std', diff --git a/pallets/xyk/src/benchmarking.rs b/pallets/xyk/src/benchmarking.rs index 6b6acc765..f8835aa7e 100644 --- a/pallets/xyk/src/benchmarking.rs +++ b/pallets/xyk/src/benchmarking.rs @@ -25,8 +25,8 @@ use sp_std::prelude::*; use crate::Pallet as XYK; +use crate::types::{AssetId, Balance}; use hydradx_traits::router::{PoolType, TradeExecution}; -use primitives::{AssetId, Balance}; const SEED: u32 = 1; diff --git a/pallets/xyk/src/lib.rs b/pallets/xyk/src/lib.rs index a53812719..69979508f 100644 --- a/pallets/xyk/src/lib.rs +++ b/pallets/xyk/src/lib.rs @@ -37,10 +37,9 @@ use hydradx_traits::{ }; use sp_std::{vec, vec::Vec}; -use crate::types::{AssetId, AssetPair, Balance}; +use crate::types::{Amount, AssetId, AssetPair, Balance}; use hydra_dx_math::ratio::Ratio; use orml_traits::{MultiCurrency, MultiCurrencyExtended}; -use primitives::Amount; #[cfg(test)] mod tests; diff --git a/pallets/xyk/src/types.rs b/pallets/xyk/src/types.rs index acae283c6..ce20f6aa3 100644 --- a/pallets/xyk/src/types.rs +++ b/pallets/xyk/src/types.rs @@ -16,6 +16,7 @@ // limitations under the License. pub type AssetId = u32; +pub type Amount = i128; pub type Balance = u128; pub type Price = FixedU128; From d9082c97e57a9824d95d1ed19c7e85a0628b738a Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Thu, 2 Nov 2023 21:43:50 +0100 Subject: [PATCH 22/22] update lock file --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index ca0f68b3e..09a5ab98c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7778,7 +7778,7 @@ dependencies = [ [[package]] name = "pallet-xyk" -version = "6.3.0" +version = "6.3.1" dependencies = [ "frame-benchmarking", "frame-support",