From a9a253d7f0536464d6a3705c81e9a4b9bc2e505c Mon Sep 17 00:00:00 2001 From: dmoka Date: Mon, 3 Jun 2024 15:39:12 +0200 Subject: [PATCH 01/43] disable ED charging and refund for insufficient assets --- integration-tests/src/router.rs | 347 +++++++++++++++++++++++ pallets/dca/src/tests/mock.rs | 24 +- pallets/route-executor/src/lib.rs | 41 ++- pallets/route-executor/src/tests/mock.rs | 24 ++ runtime/adapters/src/tests/mock.rs | 22 ++ runtime/hydradx/src/assets.rs | 16 +- traits/src/router.rs | 4 + 7 files changed, 472 insertions(+), 6 deletions(-) diff --git a/integration-tests/src/router.rs b/integration-tests/src/router.rs index 4c9c11b05..ff1e5b0c9 100644 --- a/integration-tests/src/router.rs +++ b/integration-tests/src/router.rs @@ -757,6 +757,7 @@ mod router_different_pools_tests { mod omnipool_router_tests { use super::*; use frame_support::assert_noop; + use hydradx_runtime::{Balances, XYK}; use hydradx_traits::router::PoolType; use hydradx_traits::AssetKind; @@ -969,6 +970,352 @@ mod omnipool_router_tests { }); } + #[test] + fn sell_should_not_charge_ed_when_insufficient_in_middle_of_route() { + TestNet::reset(); + + Hydra::execute_with(|| { + let _ = with_transaction(|| { + //Arrange + let name = b"INSUFF".to_vec(); + let insufficient_asset = AssetRegistry::register_insufficient_asset( + None, + Some(name.try_into().unwrap()), + AssetKind::External, + Some(1_000), + None, + None, + None, + None, + ) + .unwrap(); + + assert_ok!(Currencies::deposit(ETH, &DAVE.into(), 100000 * UNITS,)); + assert_ok!(Currencies::deposit(DOT, &DAVE.into(), 100000 * UNITS,)); + assert_ok!(Currencies::deposit(insufficient_asset, &DAVE.into(), 100000 * UNITS,)); + assert_ok!(Currencies::update_balance( + hydradx_runtime::RuntimeOrigin::root(), + DAVE.into(), + HDX, + 10000 * UNITS as i128, + )); + + assert_ok!(XYK::create_pool( + RuntimeOrigin::signed(DAVE.into()), + HDX, + 10000 * UNITS, + DOT, + 10000 * UNITS, + )); + + assert_ok!(XYK::create_pool( + RuntimeOrigin::signed(DAVE.into()), + DOT, + 10000 * UNITS, + insufficient_asset, + 10000 * UNITS, + )); + + assert_ok!(XYK::create_pool( + RuntimeOrigin::signed(DAVE.into()), + insufficient_asset, + 10000 * UNITS, + ETH, + 10000 * UNITS, + )); + + let trades = vec![ + Trade { + pool: PoolType::XYK, + asset_in: HDX, + asset_out: DOT, + }, + Trade { + pool: PoolType::XYK, + asset_in: DOT, + asset_out: insufficient_asset, + }, + Trade { + pool: PoolType::XYK, + asset_in: insufficient_asset, + asset_out: ETH, + }, + ]; + + //Act + assert_balance!(ALICE.into(), HDX, 1000 * UNITS); + + let amount_to_sell = 20 * UNITS; + assert_ok!(Router::sell( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + HDX, + ETH, + amount_to_sell, + 0, + trades + )); + + assert_balance!(ALICE.into(), HDX, 1000 * UNITS - amount_to_sell); + + + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); + }); + } + + #[test] + fn sell_should_work_with_only_insufficient_assets() { + TestNet::reset(); + + Hydra::execute_with(|| { + let _ = with_transaction(|| { + //Arrange + let name = b"INSUF1".to_vec(); + let insufficient_asset1 = AssetRegistry::register_insufficient_asset( + None, + Some(name.try_into().unwrap()), + AssetKind::External, + Some(1_000), + None, + None, + None, + None, + ) + .unwrap(); + + let name = b"INSUF2".to_vec(); + let insufficient_asset2 = AssetRegistry::register_insufficient_asset( + None, + Some(name.try_into().unwrap()), + AssetKind::External, + Some(1_000), + None, + None, + None, + None, + ) + .unwrap(); + + let name = b"INSUF3".to_vec(); + let insufficient_asset3 = AssetRegistry::register_insufficient_asset( + None, + Some(name.try_into().unwrap()), + AssetKind::External, + Some(1_000), + None, + None, + None, + None, + ) + .unwrap(); + + let name = b"INSUF4".to_vec(); + let insufficient_asset4 = AssetRegistry::register_insufficient_asset( + None, + Some(name.try_into().unwrap()), + AssetKind::External, + Some(1_000), + None, + None, + None, + None, + ) + .unwrap(); + + assert_ok!(Currencies::deposit(insufficient_asset1, &DAVE.into(), 100000 * UNITS,)); + assert_ok!(Currencies::deposit(insufficient_asset2, &DAVE.into(), 100000 * UNITS,)); + assert_ok!(Currencies::deposit(insufficient_asset3, &DAVE.into(), 100000 * UNITS,)); + assert_ok!(Currencies::deposit(insufficient_asset4, &DAVE.into(), 100000 * UNITS,)); + + assert_ok!(XYK::create_pool( + RuntimeOrigin::signed(DAVE.into()), + insufficient_asset1, + 10000 * UNITS, + insufficient_asset2, + 10000 * UNITS, + )); + + assert_ok!(XYK::create_pool( + RuntimeOrigin::signed(DAVE.into()), + insufficient_asset2, + 10000 * UNITS, + insufficient_asset3, + 10000 * UNITS, + )); + + assert_ok!(XYK::create_pool( + RuntimeOrigin::signed(DAVE.into()), + insufficient_asset3, + 10000 * UNITS, + insufficient_asset4, + 10000 * UNITS, + )); + + let trades = vec![ + Trade { + pool: PoolType::XYK, + asset_in: insufficient_asset1, + asset_out: insufficient_asset2, + }, + Trade { + pool: PoolType::XYK, + asset_in: insufficient_asset2, + asset_out: insufficient_asset3, + }, + Trade { + pool: PoolType::XYK, + asset_in: insufficient_asset3, + asset_out: insufficient_asset4, + } + ]; + + assert_ok!(Currencies::deposit(insufficient_asset1, &ALICE.into(), 1500 * UNITS,)); + + let ed = UNITS * 11 / 10; + assert_balance!(ALICE.into(), HDX, 1000 * UNITS - ed); + + let amount_to_sell = 20 * UNITS; + assert_ok!(Router::sell( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + insufficient_asset1, + insufficient_asset4, + amount_to_sell, + 0, + trades + )); + + assert_balance!(ALICE.into(), HDX, 1000 * UNITS - 2 * ed); + + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); + }); + } + + #[test] + fn ed_should_be_refunded_when_all_insufficient_assets_sold() { + TestNet::reset(); + + Hydra::execute_with(|| { + let _ = with_transaction(|| { + //Arrange + let name = b"INSUF1".to_vec(); + let insufficient_asset1 = AssetRegistry::register_insufficient_asset( + None, + Some(name.try_into().unwrap()), + AssetKind::External, + Some(1_000), + None, + None, + None, + None, + ) + .unwrap(); + + let name = b"INSUF2".to_vec(); + let insufficient_asset2 = AssetRegistry::register_insufficient_asset( + None, + Some(name.try_into().unwrap()), + AssetKind::External, + Some(1_000), + None, + None, + None, + None, + ) + .unwrap(); + + assert_ok!(Currencies::deposit(insufficient_asset1, &DAVE.into(), 100000 * UNITS,)); + assert_ok!(Currencies::deposit(insufficient_asset2, &DAVE.into(), 100000 * UNITS,)); + assert_ok!(Currencies::deposit(ETH, &DAVE.into(), 100000 * UNITS,)); + + assert_ok!(XYK::create_pool( + RuntimeOrigin::signed(DAVE.into()), + insufficient_asset1, + 10000 * UNITS, + insufficient_asset2, + 10000 * UNITS, + )); + + assert_ok!(XYK::create_pool( + RuntimeOrigin::signed(DAVE.into()), + insufficient_asset2, + 10000 * UNITS, + ETH, + 10000 * UNITS, + )); + + + let trades = vec![ + Trade { + pool: PoolType::XYK, + asset_in: insufficient_asset1, + asset_out: insufficient_asset2, + }, + Trade { + pool: PoolType::XYK, + asset_in: insufficient_asset2, + asset_out: ETH, + } + ]; + + let alice_balance_before_trade = Balances::free_balance(AccountId::from(ALICE)); + + let insufficient_asset1_balance = 100 * UNITS; + assert_ok!(Currencies::deposit(insufficient_asset1, &ALICE.into(), insufficient_asset1_balance,)); + + let extra_ed_charge = UNITS / 10; + + let amount_to_sell = insufficient_asset1_balance; + assert_ok!(Router::sell( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + insufficient_asset1, + ETH, + amount_to_sell, + 0, + trades + )); + let alice_balance_after_trade = Balances::free_balance(AccountId::from(ALICE)); + + //ED should be refunded to alice as she sold all her asset, minus the 10% extra + assert_eq!(alice_balance_before_trade, alice_balance_after_trade + extra_ed_charge); + + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); + }); + } + + #[ignore] //TODO: Continue as it does not fail, BUT SHOULD?! + #[test] + fn sell_should_work_when_trade_amount_is_low() { + TestNet::reset(); + + Hydra::execute_with(|| { + //Arrange + init_omnipool(); + + let amount_to_sell = 1_000_000_000; + let limit = 0; + let trades = vec![Trade { + pool: PoolType::Omnipool, + asset_in: HDX, + asset_out: DAI, + }]; + + //Act + assert_ok!(Router::sell( + RuntimeOrigin::signed(BOB.into()), + HDX, + DAI, + amount_to_sell, + limit, + trades + )); + + //Assert + assert_balance!(BOB.into(), HDX, BOB_INITIAL_NATIVE_BALANCE - amount_to_sell); + }); + } + #[test] fn sell_should_pass_when_ed_refund_after_selling_all_shitcoin() { TestNet::reset(); diff --git a/pallets/dca/src/tests/mock.rs b/pallets/dca/src/tests/mock.rs index 72d992889..cd5a86263 100644 --- a/pallets/dca/src/tests/mock.rs +++ b/pallets/dca/src/tests/mock.rs @@ -18,7 +18,7 @@ use crate as dca; use crate::{Config, Error, RandomnessProvider, RelayChainBlockHashProvider}; use cumulus_primitives_core::relay_chain::Hash; -use frame_support::traits::{Everything, Nothing}; +use frame_support::traits::{Contains, Everything, Nothing}; use frame_support::weights::constants::ExtrinsicBaseWeight; use frame_support::weights::WeightToFeeCoefficient; use frame_support::weights::{IdentityFee, Weight}; @@ -365,6 +365,27 @@ impl pallet_route_executor::Config for Test { type WeightInfo = (); type TechnicalOrigin = EnsureRoot; type EdToRefundCalculator = MockedEdCalculator; + type NonDustableWhitelistHandler = Whitelist; +} + +pub struct Whitelist; + +impl Contains for Whitelist { + fn contains(account: &AccountId) -> bool { + false + } +} + +impl DustRemovalAccountWhitelist for Whitelist { + type Error = DispatchError; + + fn add_account(account: &AccountId) -> Result<(), Self::Error> { + Ok(()) + } + + fn remove_account(account: &AccountId) -> Result<(), Self::Error> { + Ok(()) + } } pub struct MockedEdCalculator; @@ -717,6 +738,7 @@ use pallet_omnipool::traits::ExternalPriceProvider; use rand::prelude::StdRng; use rand::SeedableRng; use smallvec::smallvec; +use hydradx_traits::pools::DustRemovalAccountWhitelist; pub struct DummyNFT; diff --git a/pallets/route-executor/src/lib.rs b/pallets/route-executor/src/lib.rs index e8c388e6a..1ab88111a 100644 --- a/pallets/route-executor/src/lib.rs +++ b/pallets/route-executor/src/lib.rs @@ -28,12 +28,13 @@ use frame_support::{ traits::{fungibles::Inspect, Get}, transactional, }; +use frame_support::traits::Contains; use hydra_dx_math::support::rational::{round_u512_to_rational, Rounding}; use frame_system::pallet_prelude::OriginFor; use frame_system::{ensure_signed, Origin}; use hydradx_traits::registry::Inspect as RegistryInspect; -use hydradx_traits::router::{inverse_route, AssetPair, RefundEdCalculator, RouteProvider, RouteSpotPriceProvider}; +use hydradx_traits::router::{inverse_route, AssetPair, RefundEdCalculator, RouteProvider, RouteSpotPriceProvider, IsInMiddleOfRouteCheck}; pub use hydradx_traits::router::{ AmmTradeWeights, AmountInAndOut, ExecutorError, PoolType, RouterT, Trade, TradeExecution, }; @@ -60,6 +61,7 @@ pub mod pallet { use hydradx_traits::router::{ExecutorError, RefundEdCalculator}; use sp_runtime::traits::{AtLeast32BitUnsigned, CheckedDiv, Zero}; use sp_runtime::Saturating; + use hydradx_traits::pools::DustRemovalAccountWhitelist; #[pallet::pallet] pub struct Pallet(_); @@ -114,6 +116,9 @@ pub mod pallet { /// Weight information for the extrinsics. type WeightInfo: AmmTradeWeights>; + + type NonDustableWhitelistHandler: DustRemovalAccountWhitelist; + } #[pallet::event] @@ -154,6 +159,12 @@ pub mod pallet { NotAllowed, } + /// Flag to indicate if the route execution is in the middle of the route + /// Mainly used for disabling ED charging for the trades in the middle of the route + #[pallet::storage] + #[pallet::getter(fn next_schedule_id)] + pub type InMiddleOfRoute = StorageValue<_, bool, ValueQuery>; + /// Storing routes for asset pairs #[pallet::storage] #[pallet::getter(fn route)] @@ -211,7 +222,19 @@ pub mod pallet { Error::::TradingLimitReached ); - for (trade_amount, trade) in trade_amounts.iter().zip(route) { + let route_length = route.len().checked_sub(1).ok_or(Error::::InvalidRoute)?; + + for (trade_index, (trade_amount, trade)) in trade_amounts.iter().zip(route.clone()).enumerate() { + //We whitelist account for ED charging except the last trade because there we want ED charged for insufficient asset + if trade_index != route_length && !T::InspectRegistry::is_sufficient(trade.asset_out) { + T::NonDustableWhitelistHandler::add_account(&who)?; + } + + //We want use this flag to disable ED refund except for the first trade because in case of selling all insufficient asset_in, ED should be refunded to user + if trade_index != 0 && !T::InspectRegistry::is_sufficient(trade.asset_in) { + InMiddleOfRoute::::put(true); //TODO: disable it on on init + } + let user_balance_of_asset_in_before_trade = T::Currency::reducible_balance(trade.asset_in, &who, Preservation::Expendable, Fortitude::Polite); @@ -224,6 +247,11 @@ pub mod pallet { trade_amount.amount_out, ); + if trade_index != route_length && !T::InspectRegistry::is_sufficient(trade.asset_out) { + T::NonDustableWhitelistHandler::remove_account(&who)?; + } + InMiddleOfRoute::::put(false); + handle_execution_error!(execution_result); Self::ensure_that_user_spent_asset_in_at_least( @@ -293,6 +321,7 @@ pub mod pallet { let first_trade = trade_amounts.last().ok_or(Error::::RouteCalculationFailed)?; ensure!(first_trade.amount_in <= max_amount_in, Error::::TradingLimitReached); + //TODO: enable and disable the ED charging and refund for (trade_amount, trade) in trade_amounts.iter().rev().zip(route) { let user_balance_of_asset_out_before_trade = T::Currency::reducible_balance(trade.asset_out, &who, Preservation::Preserve, Fortitude::Polite); @@ -901,3 +930,11 @@ impl RouteSpotPriceProvider for Pallet { FixedU128::checked_from_rational(rat_as_u128.0, rat_as_u128.1) } } + +pub struct IsInMiddleOfRoute(PhantomData); + +impl IsInMiddleOfRouteCheck for IsInMiddleOfRoute { + fn IsTrue() -> bool { + InMiddleOfRoute::::get() + } +} \ No newline at end of file diff --git a/pallets/route-executor/src/tests/mock.rs b/pallets/route-executor/src/tests/mock.rs index 042303d95..85cb1fe6b 100644 --- a/pallets/route-executor/src/tests/mock.rs +++ b/pallets/route-executor/src/tests/mock.rs @@ -35,6 +35,7 @@ use sp_runtime::{ }; use std::cell::RefCell; use std::ops::Deref; +use frame_support::traits::Contains; type Block = frame_system::mocking::MockBlock; @@ -153,6 +154,27 @@ impl Config for Test { type DefaultRoutePoolType = DefaultRoutePoolType; type TechnicalOrigin = EnsureRoot; type WeightInfo = (); + type NonDustableWhitelistHandler = Whitelist; +} + +pub struct Whitelist; + +impl Contains for Whitelist { + fn contains(account: &AccountId) -> bool { + false + } +} + +impl DustRemovalAccountWhitelist for Whitelist { + type Error = DispatchError; + + fn add_account(account: &AccountId) -> Result<(), Self::Error> { + Ok(()) + } + + fn remove_account(account: &AccountId) -> Result<(), Self::Error> { + Ok(()) + } } pub struct MockedEdCalculator; @@ -164,6 +186,8 @@ impl RefundEdCalculator for MockedEdCalculator { } use hydradx_traits::AssetKind; +use hydradx_traits::pools::DustRemovalAccountWhitelist; + pub struct MockedAssetRegistry; impl hydradx_traits::registry::Inspect for MockedAssetRegistry { diff --git a/runtime/adapters/src/tests/mock.rs b/runtime/adapters/src/tests/mock.rs index 3233bcaba..c06843667 100644 --- a/runtime/adapters/src/tests/mock.rs +++ b/runtime/adapters/src/tests/mock.rs @@ -331,6 +331,28 @@ impl pallet_route_executor::Config for Test { type DefaultRoutePoolType = DefaultRoutePoolType; type TechnicalOrigin = EnsureRoot; type WeightInfo = (); + type NonDustableWhitelistHandler = WhitelistHandler; +} + + +pub struct WhitelistHandler; + +impl Contains for WhitelistHandler { + fn contains(account: &AccountId) -> bool { + false + } +} + +impl DustRemovalAccountWhitelist for WhitelistHandler { + type Error = DispatchError; + + fn add_account(account: &AccountId) -> Result<(), Self::Error> { + Ok(()) + } + + fn remove_account(account: &AccountId) -> Result<(), Self::Error> { + Ok(()) + } } pub struct MockedEdCalculator; diff --git a/runtime/hydradx/src/assets.rs b/runtime/hydradx/src/assets.rs index e1fcd77f9..c6e58c6f1 100644 --- a/runtime/hydradx/src/assets.rs +++ b/runtime/hydradx/src/assets.rs @@ -219,9 +219,17 @@ impl SufficiencyCheck { impl OnTransfer for SufficiencyCheck { fn on_transfer(asset: AssetId, from: &AccountId, to: &AccountId, _amount: Balance) -> DispatchResult { + let from_is_whitelisted = ::DustRemovalWhitelist::contains(from); + let to_is_whitelisted = ::DustRemovalWhitelist::contains(to); + + //If both is whitelisted, we don't charge ED. It can happen for example when are transferring insufficient tokens between accounts in a route execution + if from_is_whitelisted && to_is_whitelisted { + return Ok(()); + } + //NOTE: `to` is paying ED if `from` is whitelisted. //This can happen if pallet's account transfers insufficient tokens to another account. - if ::DustRemovalWhitelist::contains(from) { + if from_is_whitelisted{ Self::on_funds(asset, to, to) } else { Self::on_funds(asset, from, to) @@ -238,7 +246,8 @@ impl OnDeposit for SufficiencyCheck { pub struct OnKilledTokenAccount; impl Happened<(AccountId, AssetId)> for OnKilledTokenAccount { fn happened((who, asset): &(AccountId, AssetId)) { - if AssetRegistry::is_sufficient(*asset) || frame_system::Pallet::::account(who).sufficients.is_zero() { + let is_middle_of_route = pallet_route_executor::IsInMiddleOfRoute::::IsTrue(); + if AssetRegistry::is_sufficient(*asset) || frame_system::Pallet::::account(who).sufficients.is_zero() || is_middle_of_route { return; } @@ -1058,6 +1067,7 @@ impl pallet_route_executor::Config for Runtime { type InspectRegistry = AssetRegistry; type TechnicalOrigin = SuperMajorityTechCommittee; type EdToRefundCalculator = RefundAndLockedEdCalculator; + type NonDustableWhitelistHandler = Duster; } parameter_types! { @@ -1139,7 +1149,7 @@ use frame_support::storage::with_transaction; use hydradx_traits::price::PriceProvider; #[cfg(feature = "runtime-benchmarks")] use hydradx_traits::registry::Create; -use hydradx_traits::router::RefundEdCalculator; +use hydradx_traits::router::{IsInMiddleOfRouteCheck, RefundEdCalculator}; use pallet_referrals::traits::Convert; use pallet_referrals::{FeeDistribution, Level}; #[cfg(feature = "runtime-benchmarks")] diff --git a/traits/src/router.rs b/traits/src/router.rs index bf458434d..90366a82c 100644 --- a/traits/src/router.rs +++ b/traits/src/router.rs @@ -340,3 +340,7 @@ impl AmmTradeWeights for () { pub trait RefundEdCalculator { fn calculate() -> Balance; } + +pub trait IsInMiddleOfRouteCheck { + fn IsTrue() -> bool; +} \ No newline at end of file From 2f06de0a064986f03944e6d903a8322d603e1472 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 4 Jun 2024 14:20:08 +0200 Subject: [PATCH 02/43] introduce SkipEd state for route executor --- integration-tests/src/router.rs | 25 ++++++++----- pallets/dca/src/tests/mock.rs | 20 ---------- pallets/route-executor/src/lib.rs | 47 ++++++++++++++---------- pallets/route-executor/src/tests/mock.rs | 17 +-------- runtime/adapters/src/tests/mock.rs | 22 ----------- runtime/hydradx/src/assets.rs | 24 ++++++------ 6 files changed, 58 insertions(+), 97 deletions(-) diff --git a/integration-tests/src/router.rs b/integration-tests/src/router.rs index ff1e5b0c9..60b76c2c5 100644 --- a/integration-tests/src/router.rs +++ b/integration-tests/src/router.rs @@ -1081,7 +1081,7 @@ mod omnipool_router_tests { None, None, ) - .unwrap(); + .unwrap(); let name = b"INSUF2".to_vec(); let insufficient_asset2 = AssetRegistry::register_insufficient_asset( @@ -1094,7 +1094,7 @@ mod omnipool_router_tests { None, None, ) - .unwrap(); + .unwrap(); let name = b"INSUF3".to_vec(); let insufficient_asset3 = AssetRegistry::register_insufficient_asset( @@ -1107,7 +1107,7 @@ mod omnipool_router_tests { None, None, ) - .unwrap(); + .unwrap(); let name = b"INSUF4".to_vec(); let insufficient_asset4 = AssetRegistry::register_insufficient_asset( @@ -1120,7 +1120,7 @@ mod omnipool_router_tests { None, None, ) - .unwrap(); + .unwrap(); assert_ok!(Currencies::deposit(insufficient_asset1, &DAVE.into(), 100000 * UNITS,)); assert_ok!(Currencies::deposit(insufficient_asset2, &DAVE.into(), 100000 * UNITS,)); @@ -1166,7 +1166,7 @@ mod omnipool_router_tests { pool: PoolType::XYK, asset_in: insufficient_asset3, asset_out: insufficient_asset4, - } + }, ]; assert_ok!(Currencies::deposit(insufficient_asset1, &ALICE.into(), 1500 * UNITS,)); @@ -1209,7 +1209,7 @@ mod omnipool_router_tests { None, None, ) - .unwrap(); + .unwrap(); let name = b"INSUF2".to_vec(); let insufficient_asset2 = AssetRegistry::register_insufficient_asset( @@ -1222,7 +1222,7 @@ mod omnipool_router_tests { None, None, ) - .unwrap(); + .unwrap(); assert_ok!(Currencies::deposit(insufficient_asset1, &DAVE.into(), 100000 * UNITS,)); assert_ok!(Currencies::deposit(insufficient_asset2, &DAVE.into(), 100000 * UNITS,)); @@ -1244,7 +1244,6 @@ mod omnipool_router_tests { 10000 * UNITS, )); - let trades = vec![ Trade { pool: PoolType::XYK, @@ -1255,13 +1254,17 @@ mod omnipool_router_tests { pool: PoolType::XYK, asset_in: insufficient_asset2, asset_out: ETH, - } + }, ]; let alice_balance_before_trade = Balances::free_balance(AccountId::from(ALICE)); let insufficient_asset1_balance = 100 * UNITS; - assert_ok!(Currencies::deposit(insufficient_asset1, &ALICE.into(), insufficient_asset1_balance,)); + assert_ok!(Currencies::deposit( + insufficient_asset1, + &ALICE.into(), + insufficient_asset1_balance, + )); let extra_ed_charge = UNITS / 10; @@ -1284,6 +1287,8 @@ mod omnipool_router_tests { }); } + //TODO: add test when we have only one trade, so ed should be charged + #[ignore] //TODO: Continue as it does not fail, BUT SHOULD?! #[test] fn sell_should_work_when_trade_amount_is_low() { diff --git a/pallets/dca/src/tests/mock.rs b/pallets/dca/src/tests/mock.rs index cd5a86263..8687ed3fc 100644 --- a/pallets/dca/src/tests/mock.rs +++ b/pallets/dca/src/tests/mock.rs @@ -365,28 +365,8 @@ impl pallet_route_executor::Config for Test { type WeightInfo = (); type TechnicalOrigin = EnsureRoot; type EdToRefundCalculator = MockedEdCalculator; - type NonDustableWhitelistHandler = Whitelist; } -pub struct Whitelist; - -impl Contains for Whitelist { - fn contains(account: &AccountId) -> bool { - false - } -} - -impl DustRemovalAccountWhitelist for Whitelist { - type Error = DispatchError; - - fn add_account(account: &AccountId) -> Result<(), Self::Error> { - Ok(()) - } - - fn remove_account(account: &AccountId) -> Result<(), Self::Error> { - Ok(()) - } -} pub struct MockedEdCalculator; diff --git a/pallets/route-executor/src/lib.rs b/pallets/route-executor/src/lib.rs index 1ab88111a..237c8ebee 100644 --- a/pallets/route-executor/src/lib.rs +++ b/pallets/route-executor/src/lib.rs @@ -21,6 +21,7 @@ use codec::MaxEncodedLen; use frame_support::storage::with_transaction; use frame_support::traits::fungibles::Mutate; use frame_support::traits::tokens::{Fortitude, Preservation}; +use frame_support::traits::Contains; use frame_support::PalletId; use frame_support::{ ensure, @@ -28,13 +29,14 @@ use frame_support::{ traits::{fungibles::Inspect, Get}, transactional, }; -use frame_support::traits::Contains; use hydra_dx_math::support::rational::{round_u512_to_rational, Rounding}; use frame_system::pallet_prelude::OriginFor; use frame_system::{ensure_signed, Origin}; use hydradx_traits::registry::Inspect as RegistryInspect; -use hydradx_traits::router::{inverse_route, AssetPair, RefundEdCalculator, RouteProvider, RouteSpotPriceProvider, IsInMiddleOfRouteCheck}; +use hydradx_traits::router::{ + inverse_route, AssetPair, IsInMiddleOfRouteCheck, RefundEdCalculator, RouteProvider, RouteSpotPriceProvider, +}; pub use hydradx_traits::router::{ AmmTradeWeights, AmountInAndOut, ExecutorError, PoolType, RouterT, Trade, TradeExecution, }; @@ -53,15 +55,22 @@ pub use pallet::*; pub const MAX_NUMBER_OF_TRADES: u32 = 5; +#[derive(Debug, Encode, Decode, Copy, Clone, PartialEq, Eq, TypeInfo, MaxEncodedLen)] +pub enum SkipEdState { + SkipEdLock, + SkipEdLockAndUnlock, + SkipEdUnlock, +} + #[frame_support::pallet] pub mod pallet { use super::*; use frame_support::traits::fungibles::Mutate; use frame_system::pallet_prelude::OriginFor; + use hydradx_traits::pools::DustRemovalAccountWhitelist; use hydradx_traits::router::{ExecutorError, RefundEdCalculator}; use sp_runtime::traits::{AtLeast32BitUnsigned, CheckedDiv, Zero}; use sp_runtime::Saturating; - use hydradx_traits::pools::DustRemovalAccountWhitelist; #[pallet::pallet] pub struct Pallet(_); @@ -116,9 +125,6 @@ pub mod pallet { /// Weight information for the extrinsics. type WeightInfo: AmmTradeWeights>; - - type NonDustableWhitelistHandler: DustRemovalAccountWhitelist; - } #[pallet::event] @@ -165,6 +171,11 @@ pub mod pallet { #[pallet::getter(fn next_schedule_id)] pub type InMiddleOfRoute = StorageValue<_, bool, ValueQuery>; + //TODO: add doc + #[pallet::storage] + #[pallet::getter(fn last_trade_position)] + pub type SkipEd = StorageValue<_, SkipEdState, OptionQuery>; + /// Storing routes for asset pairs #[pallet::storage] #[pallet::getter(fn route)] @@ -225,14 +236,15 @@ pub mod pallet { let route_length = route.len().checked_sub(1).ok_or(Error::::InvalidRoute)?; for (trade_index, (trade_amount, trade)) in trade_amounts.iter().zip(route.clone()).enumerate() { - //We whitelist account for ED charging except the last trade because there we want ED charged for insufficient asset - if trade_index != route_length && !T::InspectRegistry::is_sufficient(trade.asset_out) { - T::NonDustableWhitelistHandler::add_account(&who)?; - } - - //We want use this flag to disable ED refund except for the first trade because in case of selling all insufficient asset_in, ED should be refunded to user - if trade_index != 0 && !T::InspectRegistry::is_sufficient(trade.asset_in) { - InMiddleOfRoute::::put(true); //TODO: disable it on on init + if route_length > 0 + && (!T::InspectRegistry::is_sufficient(trade.asset_in) + || !T::InspectRegistry::is_sufficient(trade.asset_out)) + { + match trade_index { + 0 => SkipEd::::put(SkipEdState::SkipEdLock), + trade_index if trade_index == route_length => SkipEd::::put(SkipEdState::SkipEdUnlock), + _ => SkipEd::::put(SkipEdState::SkipEdLockAndUnlock), + } } let user_balance_of_asset_in_before_trade = @@ -247,10 +259,7 @@ pub mod pallet { trade_amount.amount_out, ); - if trade_index != route_length && !T::InspectRegistry::is_sufficient(trade.asset_out) { - T::NonDustableWhitelistHandler::remove_account(&who)?; - } - InMiddleOfRoute::::put(false); + SkipEd::::kill(); handle_execution_error!(execution_result); @@ -937,4 +946,4 @@ impl IsInMiddleOfRouteCheck for IsInMiddleOfRoute { fn IsTrue() -> bool { InMiddleOfRoute::::get() } -} \ No newline at end of file +} diff --git a/pallets/route-executor/src/tests/mock.rs b/pallets/route-executor/src/tests/mock.rs index 85cb1fe6b..c73473a6b 100644 --- a/pallets/route-executor/src/tests/mock.rs +++ b/pallets/route-executor/src/tests/mock.rs @@ -17,6 +17,7 @@ use crate as router; use crate::{Config, Trade}; +use frame_support::traits::Contains; use frame_support::{ parameter_types, traits::{Everything, Nothing}, @@ -35,7 +36,6 @@ use sp_runtime::{ }; use std::cell::RefCell; use std::ops::Deref; -use frame_support::traits::Contains; type Block = frame_system::mocking::MockBlock; @@ -154,7 +154,6 @@ impl Config for Test { type DefaultRoutePoolType = DefaultRoutePoolType; type TechnicalOrigin = EnsureRoot; type WeightInfo = (); - type NonDustableWhitelistHandler = Whitelist; } pub struct Whitelist; @@ -165,18 +164,6 @@ impl Contains for Whitelist { } } -impl DustRemovalAccountWhitelist for Whitelist { - type Error = DispatchError; - - fn add_account(account: &AccountId) -> Result<(), Self::Error> { - Ok(()) - } - - fn remove_account(account: &AccountId) -> Result<(), Self::Error> { - Ok(()) - } -} - pub struct MockedEdCalculator; impl RefundEdCalculator for MockedEdCalculator { @@ -185,8 +172,8 @@ impl RefundEdCalculator for MockedEdCalculator { } } -use hydradx_traits::AssetKind; use hydradx_traits::pools::DustRemovalAccountWhitelist; +use hydradx_traits::AssetKind; pub struct MockedAssetRegistry; diff --git a/runtime/adapters/src/tests/mock.rs b/runtime/adapters/src/tests/mock.rs index c06843667..3233bcaba 100644 --- a/runtime/adapters/src/tests/mock.rs +++ b/runtime/adapters/src/tests/mock.rs @@ -331,28 +331,6 @@ impl pallet_route_executor::Config for Test { type DefaultRoutePoolType = DefaultRoutePoolType; type TechnicalOrigin = EnsureRoot; type WeightInfo = (); - type NonDustableWhitelistHandler = WhitelistHandler; -} - - -pub struct WhitelistHandler; - -impl Contains for WhitelistHandler { - fn contains(account: &AccountId) -> bool { - false - } -} - -impl DustRemovalAccountWhitelist for WhitelistHandler { - type Error = DispatchError; - - fn add_account(account: &AccountId) -> Result<(), Self::Error> { - Ok(()) - } - - fn remove_account(account: &AccountId) -> Result<(), Self::Error> { - Ok(()) - } } pub struct MockedEdCalculator; diff --git a/runtime/hydradx/src/assets.rs b/runtime/hydradx/src/assets.rs index c6e58c6f1..b3b683b1e 100644 --- a/runtime/hydradx/src/assets.rs +++ b/runtime/hydradx/src/assets.rs @@ -63,7 +63,7 @@ use orml_traits::currency::{MultiCurrency, MultiLockableCurrency, MutationHooks, use orml_traits::{GetByKey, Happened}; use pallet_dynamic_fees::types::FeeParams; use pallet_lbp::weights::WeightInfo as LbpWeights; -use pallet_route_executor::{weights::WeightInfo as RouterWeights, AmmTradeWeights, MAX_NUMBER_OF_TRADES}; +use pallet_route_executor::{weights::WeightInfo as RouterWeights, AmmTradeWeights, MAX_NUMBER_OF_TRADES, SkipEd, SkipEdState}; use pallet_staking::types::{Action, Point}; use pallet_staking::SigmoidPercentage; use pallet_xyk::weights::WeightInfo as XykWeights; @@ -219,17 +219,15 @@ impl SufficiencyCheck { impl OnTransfer for SufficiencyCheck { fn on_transfer(asset: AssetId, from: &AccountId, to: &AccountId, _amount: Balance) -> DispatchResult { - let from_is_whitelisted = ::DustRemovalWhitelist::contains(from); - let to_is_whitelisted = ::DustRemovalWhitelist::contains(to); - - //If both is whitelisted, we don't charge ED. It can happen for example when are transferring insufficient tokens between accounts in a route execution - if from_is_whitelisted && to_is_whitelisted { - return Ok(()); + if let Some(state) = pallet_route_executor::SkipEd::::get() { + if matches!(state, SkipEdState::SkipEdLock | SkipEdState::SkipEdLockAndUnlock) { + return Ok(()); + } } //NOTE: `to` is paying ED if `from` is whitelisted. //This can happen if pallet's account transfers insufficient tokens to another account. - if from_is_whitelisted{ + if ::DustRemovalWhitelist::contains(from){ Self::on_funds(asset, to, to) } else { Self::on_funds(asset, from, to) @@ -246,8 +244,13 @@ impl OnDeposit for SufficiencyCheck { pub struct OnKilledTokenAccount; impl Happened<(AccountId, AssetId)> for OnKilledTokenAccount { fn happened((who, asset): &(AccountId, AssetId)) { - let is_middle_of_route = pallet_route_executor::IsInMiddleOfRoute::::IsTrue(); - if AssetRegistry::is_sufficient(*asset) || frame_system::Pallet::::account(who).sufficients.is_zero() || is_middle_of_route { + if let Some(state) = pallet_route_executor::SkipEd::::get() { + if matches!(state, SkipEdState::SkipEdUnlock | SkipEdState::SkipEdLockAndUnlock) { + return; + } + } + + if AssetRegistry::is_sufficient(*asset) || frame_system::Pallet::::account(who).sufficients.is_zero() { return; } @@ -1067,7 +1070,6 @@ impl pallet_route_executor::Config for Runtime { type InspectRegistry = AssetRegistry; type TechnicalOrigin = SuperMajorityTechCommittee; type EdToRefundCalculator = RefundAndLockedEdCalculator; - type NonDustableWhitelistHandler = Duster; } parameter_types! { From a9e417b6c3feab9491cd520c99a0c057bb9d2e8e Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 4 Jun 2024 15:13:38 +0200 Subject: [PATCH 03/43] add test for checking one trade --- integration-tests/src/router.rs | 82 ++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/integration-tests/src/router.rs b/integration-tests/src/router.rs index 60b76c2c5..6f72566e0 100644 --- a/integration-tests/src/router.rs +++ b/integration-tests/src/router.rs @@ -1287,7 +1287,87 @@ mod omnipool_router_tests { }); } - //TODO: add test when we have only one trade, so ed should be charged + #[test] + fn should_no_ed_charging_disabled_when_only_one_route_with_insufficient_assets() { + TestNet::reset(); + + Hydra::execute_with(|| { + let _ = with_transaction(|| { + //Arrange + let name = b"INSUF1".to_vec(); + let insufficient_asset_1 = AssetRegistry::register_insufficient_asset( + None, + Some(name.try_into().unwrap()), + AssetKind::External, + Some(1_000), + None, + None, + None, + None, + ) + .unwrap(); + + let name = b"INSUF12".to_vec(); + let insufficient_asset_2 = AssetRegistry::register_insufficient_asset( + None, + Some(name.try_into().unwrap()), + AssetKind::External, + Some(1_000), + None, + None, + None, + None, + ) + .unwrap(); + assert_ok!(Currencies::deposit(insufficient_asset_1, &DAVE.into(), 100000 * UNITS,)); + assert_ok!(Currencies::deposit(insufficient_asset_2, &DAVE.into(), 100000 * UNITS,)); + assert_ok!(Currencies::update_balance( + hydradx_runtime::RuntimeOrigin::root(), + DAVE.into(), + HDX, + 100000 * UNITS as i128, + )); + + assert_ok!(XYK::create_pool( + RuntimeOrigin::signed(DAVE.into()), + insufficient_asset_1, + 100000 * UNITS, + insufficient_asset_2, + 100000 * UNITS, + )); + + let trades = vec![Trade { + pool: PoolType::XYK, + asset_in: insufficient_asset_1, + asset_out: insufficient_asset_2, + }]; + + //Act + let amount_to_sell = 10 * UNITS; + assert_ok!(Currencies::deposit(insufficient_asset_1, &ALICE.into(), amount_to_sell,)); + let ed = UNITS * 11 / 10; + let extra_ed_charge = UNITS / 10; + assert_balance!(ALICE.into(), HDX, 1000 * UNITS - 1 * ed); + + let amount_to_sell = amount_to_sell; + assert_ok!( + Router::sell( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + insufficient_asset_1, + insufficient_asset_2, + amount_to_sell, + 0, + trades + ), + ); + + //ED for insufficient_asset_1 is refunded, but ED for insufficient_asset_2 is charged plus extra 10% + assert_balance!(ALICE.into(), HDX, 1000 * UNITS - 1 * ed - extra_ed_charge); + + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); + }); + } #[ignore] //TODO: Continue as it does not fail, BUT SHOULD?! #[test] From 41632f2c32134b9dd4f1b587e255d0d4900a43bb Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 4 Jun 2024 16:12:42 +0200 Subject: [PATCH 04/43] add optimization to reduce store ops --- integration-tests/src/router.rs | 128 ++++++++++++++++++++++++++++++ pallets/route-executor/src/lib.rs | 45 +++++++---- 2 files changed, 157 insertions(+), 16 deletions(-) diff --git a/integration-tests/src/router.rs b/integration-tests/src/router.rs index 6f72566e0..9e8ad987e 100644 --- a/integration-tests/src/router.rs +++ b/integration-tests/src/router.rs @@ -1369,6 +1369,134 @@ mod omnipool_router_tests { }); } + #[test] + fn buy_should_work_with_only_insufficient_assets() { + TestNet::reset(); + + Hydra::execute_with(|| { + let _ = with_transaction(|| { + //Arrange + let name = b"INSUF1".to_vec(); + let insufficient_asset1 = AssetRegistry::register_insufficient_asset( + None, + Some(name.try_into().unwrap()), + AssetKind::External, + Some(1_000), + None, + None, + None, + None, + ) + .unwrap(); + + let name = b"INSUF2".to_vec(); + let insufficient_asset2 = AssetRegistry::register_insufficient_asset( + None, + Some(name.try_into().unwrap()), + AssetKind::External, + Some(1_000), + None, + None, + None, + None, + ) + .unwrap(); + + let name = b"INSUF3".to_vec(); + let insufficient_asset3 = AssetRegistry::register_insufficient_asset( + None, + Some(name.try_into().unwrap()), + AssetKind::External, + Some(1_000), + None, + None, + None, + None, + ) + .unwrap(); + + let name = b"INSUF4".to_vec(); + let insufficient_asset4 = AssetRegistry::register_insufficient_asset( + None, + Some(name.try_into().unwrap()), + AssetKind::External, + Some(1_000), + None, + None, + None, + None, + ) + .unwrap(); + + assert_ok!(Currencies::deposit(insufficient_asset1, &DAVE.into(), 100000 * UNITS,)); + assert_ok!(Currencies::deposit(insufficient_asset2, &DAVE.into(), 100000 * UNITS,)); + assert_ok!(Currencies::deposit(insufficient_asset3, &DAVE.into(), 100000 * UNITS,)); + assert_ok!(Currencies::deposit(insufficient_asset4, &DAVE.into(), 100000 * UNITS,)); + + assert_ok!(XYK::create_pool( + RuntimeOrigin::signed(DAVE.into()), + insufficient_asset1, + 10000 * UNITS, + insufficient_asset2, + 10000 * UNITS, + )); + + assert_ok!(XYK::create_pool( + RuntimeOrigin::signed(DAVE.into()), + insufficient_asset2, + 10000 * UNITS, + insufficient_asset3, + 10000 * UNITS, + )); + + assert_ok!(XYK::create_pool( + RuntimeOrigin::signed(DAVE.into()), + insufficient_asset3, + 10000 * UNITS, + insufficient_asset4, + 10000 * UNITS, + )); + + let trades = vec![ + Trade { + pool: PoolType::XYK, + asset_in: insufficient_asset1, + asset_out: insufficient_asset2, + }, + Trade { + pool: PoolType::XYK, + asset_in: insufficient_asset2, + asset_out: insufficient_asset3, + }, + Trade { + pool: PoolType::XYK, + asset_in: insufficient_asset3, + asset_out: insufficient_asset4, + }, + ]; + + assert_ok!(Currencies::deposit(insufficient_asset1, &ALICE.into(), 1500 * UNITS,)); + + let ed = UNITS * 11 / 10; + assert_balance!(ALICE.into(), HDX, 1000 * UNITS - ed); + + let amount_to_buy = 20 * UNITS; + assert_ok!(Router::buy( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + insufficient_asset1, + insufficient_asset4, + amount_to_buy, + u128::MAX, + trades + )); + + assert_balance!(ALICE.into(), HDX, 1000 * UNITS - 2 * ed); + + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); + }); + } + #[ignore] //TODO: Continue as it does not fail, BUT SHOULD?! #[test] fn sell_should_work_when_trade_amount_is_low() { diff --git a/pallets/route-executor/src/lib.rs b/pallets/route-executor/src/lib.rs index 237c8ebee..79e494acc 100644 --- a/pallets/route-executor/src/lib.rs +++ b/pallets/route-executor/src/lib.rs @@ -21,7 +21,6 @@ use codec::MaxEncodedLen; use frame_support::storage::with_transaction; use frame_support::traits::fungibles::Mutate; use frame_support::traits::tokens::{Fortitude, Preservation}; -use frame_support::traits::Contains; use frame_support::PalletId; use frame_support::{ ensure, @@ -67,7 +66,6 @@ pub mod pallet { use super::*; use frame_support::traits::fungibles::Mutate; use frame_system::pallet_prelude::OriginFor; - use hydradx_traits::pools::DustRemovalAccountWhitelist; use hydradx_traits::router::{ExecutorError, RefundEdCalculator}; use sp_runtime::traits::{AtLeast32BitUnsigned, CheckedDiv, Zero}; use sp_runtime::Saturating; @@ -235,17 +233,9 @@ pub mod pallet { let route_length = route.len().checked_sub(1).ok_or(Error::::InvalidRoute)?; + let mut skip_ed_disabling: bool = false; for (trade_index, (trade_amount, trade)) in trade_amounts.iter().zip(route.clone()).enumerate() { - if route_length > 0 - && (!T::InspectRegistry::is_sufficient(trade.asset_in) - || !T::InspectRegistry::is_sufficient(trade.asset_out)) - { - match trade_index { - 0 => SkipEd::::put(SkipEdState::SkipEdLock), - trade_index if trade_index == route_length => SkipEd::::put(SkipEdState::SkipEdUnlock), - _ => SkipEd::::put(SkipEdState::SkipEdLockAndUnlock), - } - } + Self::disable_ed_handling_for_insufficient_assets(&mut skip_ed_disabling, route_length, trade_index, trade); let user_balance_of_asset_in_before_trade = T::Currency::reducible_balance(trade.asset_in, &who, Preservation::Expendable, Fortitude::Polite); @@ -259,8 +249,6 @@ pub mod pallet { trade_amount.amount_out, ); - SkipEd::::kill(); - handle_execution_error!(execution_result); Self::ensure_that_user_spent_asset_in_at_least( @@ -271,6 +259,10 @@ pub mod pallet { )?; } + if skip_ed_disabling { + SkipEd::::kill(); + } + Self::ensure_that_user_received_asset_out_at_most( who, asset_in, @@ -330,8 +322,11 @@ pub mod pallet { let first_trade = trade_amounts.last().ok_or(Error::::RouteCalculationFailed)?; ensure!(first_trade.amount_in <= max_amount_in, Error::::TradingLimitReached); - //TODO: enable and disable the ED charging and refund - for (trade_amount, trade) in trade_amounts.iter().rev().zip(route) { + let route_length = route.len().checked_sub(1).ok_or(Error::::InvalidRoute)?; + + let mut skip_ed_disabling: bool = false; + for (trade_index, (trade_amount, trade)) in trade_amounts.iter().rev().zip(route).enumerate() { + Self::disable_ed_handling_for_insufficient_assets(&mut skip_ed_disabling, route_length, trade_index, trade); let user_balance_of_asset_out_before_trade = T::Currency::reducible_balance(trade.asset_out, &who, Preservation::Preserve, Fortitude::Polite); let execution_result = T::AMM::execute_buy( @@ -354,6 +349,10 @@ pub mod pallet { )?; } + if skip_ed_disabling { + SkipEd::::kill(); + } + Self::ensure_that_user_spent_asset_in_at_least( who, asset_in, @@ -611,6 +610,20 @@ impl Pallet { Ok(route) } + fn disable_ed_handling_for_insufficient_assets(skip_ed_disabling: &mut bool, route_length: usize, trade_index: usize, trade: Trade) { + if route_length > 0 + && (!T::InspectRegistry::is_sufficient(trade.asset_in) + || !T::InspectRegistry::is_sufficient(trade.asset_out)) + { + *skip_ed_disabling = true; + match trade_index { + 0 => SkipEd::::put(SkipEdState::SkipEdLock), + trade_index if trade_index == route_length => SkipEd::::put(SkipEdState::SkipEdUnlock), + _ => SkipEd::::put(SkipEdState::SkipEdLockAndUnlock), + } + } + } + fn validate_route(route: &[Trade]) -> Result<(T::Balance, T::Balance), DispatchError> { let reference_amount_in = Self::calculate_reference_amount_in(route)?; let route_validation = Self::validate_sell(route.to_vec(), reference_amount_in); From 445067b77153d88e591b2ab15ec9eadc625643d2 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 4 Jun 2024 16:14:10 +0200 Subject: [PATCH 05/43] formatting --- pallets/route-executor/src/lib.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/pallets/route-executor/src/lib.rs b/pallets/route-executor/src/lib.rs index 79e494acc..d4ceb2af9 100644 --- a/pallets/route-executor/src/lib.rs +++ b/pallets/route-executor/src/lib.rs @@ -235,7 +235,12 @@ pub mod pallet { let mut skip_ed_disabling: bool = false; for (trade_index, (trade_amount, trade)) in trade_amounts.iter().zip(route.clone()).enumerate() { - Self::disable_ed_handling_for_insufficient_assets(&mut skip_ed_disabling, route_length, trade_index, trade); + Self::disable_ed_handling_for_insufficient_assets( + &mut skip_ed_disabling, + route_length, + trade_index, + trade, + ); let user_balance_of_asset_in_before_trade = T::Currency::reducible_balance(trade.asset_in, &who, Preservation::Expendable, Fortitude::Polite); @@ -326,7 +331,12 @@ pub mod pallet { let mut skip_ed_disabling: bool = false; for (trade_index, (trade_amount, trade)) in trade_amounts.iter().rev().zip(route).enumerate() { - Self::disable_ed_handling_for_insufficient_assets(&mut skip_ed_disabling, route_length, trade_index, trade); + Self::disable_ed_handling_for_insufficient_assets( + &mut skip_ed_disabling, + route_length, + trade_index, + trade, + ); let user_balance_of_asset_out_before_trade = T::Currency::reducible_balance(trade.asset_out, &who, Preservation::Preserve, Fortitude::Polite); let execution_result = T::AMM::execute_buy( @@ -610,10 +620,15 @@ impl Pallet { Ok(route) } - fn disable_ed_handling_for_insufficient_assets(skip_ed_disabling: &mut bool, route_length: usize, trade_index: usize, trade: Trade) { + fn disable_ed_handling_for_insufficient_assets( + skip_ed_disabling: &mut bool, + route_length: usize, + trade_index: usize, + trade: Trade, + ) { if route_length > 0 && (!T::InspectRegistry::is_sufficient(trade.asset_in) - || !T::InspectRegistry::is_sufficient(trade.asset_out)) + || !T::InspectRegistry::is_sufficient(trade.asset_out)) { *skip_ed_disabling = true; match trade_index { From 3d26a580f9bdabe73f0a4f1b7e682c597ef4db76 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 4 Jun 2024 16:43:59 +0200 Subject: [PATCH 06/43] passing correct route length --- pallets/route-executor/src/lib.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pallets/route-executor/src/lib.rs b/pallets/route-executor/src/lib.rs index d4ceb2af9..c8c00bd51 100644 --- a/pallets/route-executor/src/lib.rs +++ b/pallets/route-executor/src/lib.rs @@ -231,9 +231,8 @@ pub mod pallet { Error::::TradingLimitReached ); - let route_length = route.len().checked_sub(1).ok_or(Error::::InvalidRoute)?; - let mut skip_ed_disabling: bool = false; + let route_length = route.len(); for (trade_index, (trade_amount, trade)) in trade_amounts.iter().zip(route.clone()).enumerate() { Self::disable_ed_handling_for_insufficient_assets( &mut skip_ed_disabling, @@ -327,9 +326,8 @@ pub mod pallet { let first_trade = trade_amounts.last().ok_or(Error::::RouteCalculationFailed)?; ensure!(first_trade.amount_in <= max_amount_in, Error::::TradingLimitReached); - let route_length = route.len().checked_sub(1).ok_or(Error::::InvalidRoute)?; - let mut skip_ed_disabling: bool = false; + let route_length = route.len(); for (trade_index, (trade_amount, trade)) in trade_amounts.iter().rev().zip(route).enumerate() { Self::disable_ed_handling_for_insufficient_assets( &mut skip_ed_disabling, @@ -626,14 +624,14 @@ impl Pallet { trade_index: usize, trade: Trade, ) { - if route_length > 0 + if route_length > 1 && (!T::InspectRegistry::is_sufficient(trade.asset_in) || !T::InspectRegistry::is_sufficient(trade.asset_out)) { *skip_ed_disabling = true; match trade_index { 0 => SkipEd::::put(SkipEdState::SkipEdLock), - trade_index if trade_index == route_length => SkipEd::::put(SkipEdState::SkipEdUnlock), + trade_index if trade_index.saturating_add(1) == route_length => SkipEd::::put(SkipEdState::SkipEdUnlock), _ => SkipEd::::put(SkipEdState::SkipEdLockAndUnlock), } } From c3fb19c14fef556a18b28ce74c87ab744f3b19a4 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 4 Jun 2024 16:52:10 +0200 Subject: [PATCH 07/43] add optimization --- pallets/route-executor/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pallets/route-executor/src/lib.rs b/pallets/route-executor/src/lib.rs index c8c00bd51..814164e03 100644 --- a/pallets/route-executor/src/lib.rs +++ b/pallets/route-executor/src/lib.rs @@ -629,10 +629,12 @@ impl Pallet { || !T::InspectRegistry::is_sufficient(trade.asset_out)) { *skip_ed_disabling = true; + //We optimize to set the state for middle trades only once at the first middle trade, then we change no state till the last trade match trade_index { 0 => SkipEd::::put(SkipEdState::SkipEdLock), trade_index if trade_index.saturating_add(1) == route_length => SkipEd::::put(SkipEdState::SkipEdUnlock), - _ => SkipEd::::put(SkipEdState::SkipEdLockAndUnlock), + 1 => SkipEd::::put(SkipEdState::SkipEdLockAndUnlock), + _ => (), } } } From 41b47f170ff1b64b00129201b6dfc4ca9f25d5f6 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 4 Jun 2024 18:34:41 +0200 Subject: [PATCH 08/43] abstract away skip ed lock and unlock logic into route executor --- pallets/route-executor/src/lib.rs | 20 +++++++++++++++++++- runtime/hydradx/src/assets.rs | 12 ++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/pallets/route-executor/src/lib.rs b/pallets/route-executor/src/lib.rs index 814164e03..7ab3f47a1 100644 --- a/pallets/route-executor/src/lib.rs +++ b/pallets/route-executor/src/lib.rs @@ -632,13 +632,31 @@ impl Pallet { //We optimize to set the state for middle trades only once at the first middle trade, then we change no state till the last trade match trade_index { 0 => SkipEd::::put(SkipEdState::SkipEdLock), - trade_index if trade_index.saturating_add(1) == route_length => SkipEd::::put(SkipEdState::SkipEdUnlock), + trade_index if trade_index.saturating_add(1) == route_length => { + SkipEd::::put(SkipEdState::SkipEdUnlock) + } 1 => SkipEd::::put(SkipEdState::SkipEdLockAndUnlock), _ => (), } } } + pub fn skip_ed_lock() -> bool { + if let Ok(v) = SkipEd::::try_get() { + return matches!(v, SkipEdState::SkipEdLock | SkipEdState::SkipEdLockAndUnlock) + } + + return false; + } + + pub fn skip_ed_unlock() -> bool { + if let Ok(v) = SkipEd::::try_get() { + return matches!(v, SkipEdState::SkipEdUnlock | SkipEdState::SkipEdLockAndUnlock) + } + + return false; + } + fn validate_route(route: &[Trade]) -> Result<(T::Balance, T::Balance), DispatchError> { let reference_amount_in = Self::calculate_reference_amount_in(route)?; let route_validation = Self::validate_sell(route.to_vec(), reference_amount_in); diff --git a/runtime/hydradx/src/assets.rs b/runtime/hydradx/src/assets.rs index b3b683b1e..759d0142a 100644 --- a/runtime/hydradx/src/assets.rs +++ b/runtime/hydradx/src/assets.rs @@ -219,10 +219,8 @@ impl SufficiencyCheck { impl OnTransfer for SufficiencyCheck { fn on_transfer(asset: AssetId, from: &AccountId, to: &AccountId, _amount: Balance) -> DispatchResult { - if let Some(state) = pallet_route_executor::SkipEd::::get() { - if matches!(state, SkipEdState::SkipEdLock | SkipEdState::SkipEdLockAndUnlock) { - return Ok(()); - } + if pallet_route_executor::Pallet::::skip_ed_lock() { + return Ok(()); } //NOTE: `to` is paying ED if `from` is whitelisted. @@ -244,10 +242,8 @@ impl OnDeposit for SufficiencyCheck { pub struct OnKilledTokenAccount; impl Happened<(AccountId, AssetId)> for OnKilledTokenAccount { fn happened((who, asset): &(AccountId, AssetId)) { - if let Some(state) = pallet_route_executor::SkipEd::::get() { - if matches!(state, SkipEdState::SkipEdUnlock | SkipEdState::SkipEdLockAndUnlock) { - return; - } + if pallet_route_executor::Pallet::::skip_ed_unlock() { + return; } if AssetRegistry::is_sufficient(*asset) || frame_system::Pallet::::account(who).sufficients.is_zero() { From bd9e042d7e2313712523daa50c45084a6de0845c Mon Sep 17 00:00:00 2001 From: dmoka Date: Wed, 5 Jun 2024 09:29:19 +0200 Subject: [PATCH 09/43] remove unnecessary check --- pallets/route-executor/src/lib.rs | 10 +--------- runtime/hydradx/src/assets.rs | 2 +- traits/src/router.rs | 4 ---- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/pallets/route-executor/src/lib.rs b/pallets/route-executor/src/lib.rs index 7ab3f47a1..53ba18610 100644 --- a/pallets/route-executor/src/lib.rs +++ b/pallets/route-executor/src/lib.rs @@ -34,7 +34,7 @@ use frame_system::pallet_prelude::OriginFor; use frame_system::{ensure_signed, Origin}; use hydradx_traits::registry::Inspect as RegistryInspect; use hydradx_traits::router::{ - inverse_route, AssetPair, IsInMiddleOfRouteCheck, RefundEdCalculator, RouteProvider, RouteSpotPriceProvider, + inverse_route, AssetPair, RefundEdCalculator, RouteProvider, RouteSpotPriceProvider, }; pub use hydradx_traits::router::{ AmmTradeWeights, AmountInAndOut, ExecutorError, PoolType, RouterT, Trade, TradeExecution, @@ -985,11 +985,3 @@ impl RouteSpotPriceProvider for Pallet { FixedU128::checked_from_rational(rat_as_u128.0, rat_as_u128.1) } } - -pub struct IsInMiddleOfRoute(PhantomData); - -impl IsInMiddleOfRouteCheck for IsInMiddleOfRoute { - fn IsTrue() -> bool { - InMiddleOfRoute::::get() - } -} diff --git a/runtime/hydradx/src/assets.rs b/runtime/hydradx/src/assets.rs index 74e9694ad..96168bc90 100644 --- a/runtime/hydradx/src/assets.rs +++ b/runtime/hydradx/src/assets.rs @@ -1147,7 +1147,7 @@ use frame_support::storage::with_transaction; use hydradx_traits::price::PriceProvider; #[cfg(feature = "runtime-benchmarks")] use hydradx_traits::registry::Create; -use hydradx_traits::router::{IsInMiddleOfRouteCheck, RefundEdCalculator}; +use hydradx_traits::router::{RefundEdCalculator}; use pallet_referrals::traits::Convert; use pallet_referrals::{FeeDistribution, Level}; #[cfg(feature = "runtime-benchmarks")] diff --git a/traits/src/router.rs b/traits/src/router.rs index 90366a82c..bf458434d 100644 --- a/traits/src/router.rs +++ b/traits/src/router.rs @@ -340,7 +340,3 @@ impl AmmTradeWeights for () { pub trait RefundEdCalculator { fn calculate() -> Balance; } - -pub trait IsInMiddleOfRouteCheck { - fn IsTrue() -> bool; -} \ No newline at end of file From 18ceb99e27dc7bd5a998f93e1c10eacf6609d7cb Mon Sep 17 00:00:00 2001 From: dmoka Date: Wed, 5 Jun 2024 20:33:06 +0200 Subject: [PATCH 10/43] add benchmarking --- integration-tests/src/router.rs | 62 ++------ pallets/dca/src/tests/mock.rs | 2 +- pallets/route-executor/src/lib.rs | 10 +- pallets/route-executor/src/weights.rs | 139 +++++++++++------- runtime/hydradx/src/assets.rs | 40 ++++- .../src/benchmarking/route_executor.rs | 25 +++- runtime/hydradx/src/weights/route_executor.rs | 73 +++++---- 7 files changed, 215 insertions(+), 136 deletions(-) diff --git a/integration-tests/src/router.rs b/integration-tests/src/router.rs index 9e8ad987e..866ecbf24 100644 --- a/integration-tests/src/router.rs +++ b/integration-tests/src/router.rs @@ -1305,7 +1305,7 @@ mod omnipool_router_tests { None, None, ) - .unwrap(); + .unwrap(); let name = b"INSUF12".to_vec(); let insufficient_asset_2 = AssetRegistry::register_insufficient_asset( @@ -1318,7 +1318,7 @@ mod omnipool_router_tests { None, None, ) - .unwrap(); + .unwrap(); assert_ok!(Currencies::deposit(insufficient_asset_1, &DAVE.into(), 100000 * UNITS,)); assert_ok!(Currencies::deposit(insufficient_asset_2, &DAVE.into(), 100000 * UNITS,)); assert_ok!(Currencies::update_balance( @@ -1350,16 +1350,14 @@ mod omnipool_router_tests { assert_balance!(ALICE.into(), HDX, 1000 * UNITS - 1 * ed); let amount_to_sell = amount_to_sell; - assert_ok!( - Router::sell( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - insufficient_asset_1, - insufficient_asset_2, - amount_to_sell, - 0, - trades - ), - ); + assert_ok!(Router::sell( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + insufficient_asset_1, + insufficient_asset_2, + amount_to_sell, + 0, + trades + ),); //ED for insufficient_asset_1 is refunded, but ED for insufficient_asset_2 is charged plus extra 10% assert_balance!(ALICE.into(), HDX, 1000 * UNITS - 1 * ed - extra_ed_charge); @@ -1387,7 +1385,7 @@ mod omnipool_router_tests { None, None, ) - .unwrap(); + .unwrap(); let name = b"INSUF2".to_vec(); let insufficient_asset2 = AssetRegistry::register_insufficient_asset( @@ -1400,7 +1398,7 @@ mod omnipool_router_tests { None, None, ) - .unwrap(); + .unwrap(); let name = b"INSUF3".to_vec(); let insufficient_asset3 = AssetRegistry::register_insufficient_asset( @@ -1413,7 +1411,7 @@ mod omnipool_router_tests { None, None, ) - .unwrap(); + .unwrap(); let name = b"INSUF4".to_vec(); let insufficient_asset4 = AssetRegistry::register_insufficient_asset( @@ -1426,7 +1424,7 @@ mod omnipool_router_tests { None, None, ) - .unwrap(); + .unwrap(); assert_ok!(Currencies::deposit(insufficient_asset1, &DAVE.into(), 100000 * UNITS,)); assert_ok!(Currencies::deposit(insufficient_asset2, &DAVE.into(), 100000 * UNITS,)); @@ -1497,38 +1495,6 @@ mod omnipool_router_tests { }); } - #[ignore] //TODO: Continue as it does not fail, BUT SHOULD?! - #[test] - fn sell_should_work_when_trade_amount_is_low() { - TestNet::reset(); - - Hydra::execute_with(|| { - //Arrange - init_omnipool(); - - let amount_to_sell = 1_000_000_000; - let limit = 0; - let trades = vec![Trade { - pool: PoolType::Omnipool, - asset_in: HDX, - asset_out: DAI, - }]; - - //Act - assert_ok!(Router::sell( - RuntimeOrigin::signed(BOB.into()), - HDX, - DAI, - amount_to_sell, - limit, - trades - )); - - //Assert - assert_balance!(BOB.into(), HDX, BOB_INITIAL_NATIVE_BALANCE - amount_to_sell); - }); - } - #[test] fn sell_should_pass_when_ed_refund_after_selling_all_shitcoin() { TestNet::reset(); diff --git a/pallets/dca/src/tests/mock.rs b/pallets/dca/src/tests/mock.rs index 8687ed3fc..5f29aa068 100644 --- a/pallets/dca/src/tests/mock.rs +++ b/pallets/dca/src/tests/mock.rs @@ -712,13 +712,13 @@ use frame_system::pallet_prelude::OriginFor; use hydra_dx_math::ema::EmaPrice; use hydra_dx_math::to_u128_wrapper; use hydra_dx_math::types::Ratio; +use hydradx_traits::pools::DustRemovalAccountWhitelist; use hydradx_traits::router::{ExecutorError, PoolType, RefundEdCalculator, RouteProvider, Trade, TradeExecution}; use pallet_currencies::fungibles::FungibleCurrencies; use pallet_omnipool::traits::ExternalPriceProvider; use rand::prelude::StdRng; use rand::SeedableRng; use smallvec::smallvec; -use hydradx_traits::pools::DustRemovalAccountWhitelist; pub struct DummyNFT; diff --git a/pallets/route-executor/src/lib.rs b/pallets/route-executor/src/lib.rs index 53ba18610..a0dd2c70b 100644 --- a/pallets/route-executor/src/lib.rs +++ b/pallets/route-executor/src/lib.rs @@ -33,9 +33,7 @@ use hydra_dx_math::support::rational::{round_u512_to_rational, Rounding}; use frame_system::pallet_prelude::OriginFor; use frame_system::{ensure_signed, Origin}; use hydradx_traits::registry::Inspect as RegistryInspect; -use hydradx_traits::router::{ - inverse_route, AssetPair, RefundEdCalculator, RouteProvider, RouteSpotPriceProvider, -}; +use hydradx_traits::router::{inverse_route, AssetPair, RefundEdCalculator, RouteProvider, RouteSpotPriceProvider}; pub use hydradx_traits::router::{ AmmTradeWeights, AmountInAndOut, ExecutorError, PoolType, RouterT, Trade, TradeExecution, }; @@ -618,7 +616,7 @@ impl Pallet { Ok(route) } - fn disable_ed_handling_for_insufficient_assets( + pub fn disable_ed_handling_for_insufficient_assets( skip_ed_disabling: &mut bool, route_length: usize, trade_index: usize, @@ -643,7 +641,7 @@ impl Pallet { pub fn skip_ed_lock() -> bool { if let Ok(v) = SkipEd::::try_get() { - return matches!(v, SkipEdState::SkipEdLock | SkipEdState::SkipEdLockAndUnlock) + return matches!(v, SkipEdState::SkipEdLock | SkipEdState::SkipEdLockAndUnlock); } return false; @@ -651,7 +649,7 @@ impl Pallet { pub fn skip_ed_unlock() -> bool { if let Ok(v) = SkipEd::::try_get() { - return matches!(v, SkipEdState::SkipEdUnlock | SkipEdState::SkipEdLockAndUnlock) + return matches!(v, SkipEdState::SkipEdUnlock | SkipEdState::SkipEdLockAndUnlock); } return false; diff --git a/pallets/route-executor/src/weights.rs b/pallets/route-executor/src/weights.rs index be4375720..70cce77ed 100644 --- a/pallets/route-executor/src/weights.rs +++ b/pallets/route-executor/src/weights.rs @@ -19,9 +19,9 @@ //! Autogenerated weights for `pallet_route_executor` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-03-18, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-06-05, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` +//! HOSTNAME: `dmoka-msi-pc`, CPU: `AMD Ryzen 9 5900X 12-Core Processor` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` // Executed Command: @@ -48,6 +48,7 @@ use core::marker::PhantomData; /// Weight functions needed for `pallet_route_executor`. pub trait WeightInfo { + fn skip_ed_handling_for_trade_with_insufficient_assets() -> Weight; fn calculate_and_execute_sell_in_lbp(c: u32, ) -> Weight; fn calculate_and_execute_buy_in_lbp(c: u32, b: u32, ) -> Weight; fn set_route_for_xyk() -> Weight; @@ -57,30 +58,45 @@ pub trait WeightInfo { /// Weights for `pallet_route_executor` using the HydraDX node and recommended hardware. pub struct HydraWeight(PhantomData); impl WeightInfo for HydraWeight { + /// Storage: `AssetRegistry::Assets` (r:1 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `Router::SkipEd` (r:0 w:1) + /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + fn skip_ed_handling_for_trade_with_insufficient_assets() -> Weight { + // Proof Size summary in bytes: + // Measured: `944` + // Estimated: `3590` + // Minimum execution time: 13_600_000 picoseconds. + Weight::from_parts(13_900_000, 3590) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } /// Storage: `LBP::PoolData` (r:1 w:0) /// Proof: `LBP::PoolData` (`max_values`: None, `max_size`: Some(163), added: 2638, mode: `MaxEncodedLen`) /// Storage: `Tokens::Accounts` (r:5 w:5) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:3 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:2 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Tokens::Locks` (r:1 w:1) /// Proof: `Tokens::Locks` (`max_values`: None, `max_size`: Some(1261), added: 3736, mode: `MaxEncodedLen`) + /// Storage: `Router::SkipEd` (r:1 w:0) + /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) /// Storage: `Duster::AccountBlacklist` (r:2 w:0) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// The range of component `c` is `[0, 1]`. fn calculate_and_execute_sell_in_lbp(c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `3436` + // Measured: `3743` // Estimated: `13905` - // Minimum execution time: 342_467_000 picoseconds. - Weight::from_parts(346_028_529, 13905) - // Standard Error: 185_098 - .saturating_add(Weight::from_parts(50_586_970, 0).saturating_mul(c.into())) - .saturating_add(T::DbWeight::get().reads(16_u64)) + // Minimum execution time: 278_588_000 picoseconds. + Weight::from_parts(284_606_595, 13905) + // Standard Error: 341_686 + .saturating_add(Weight::from_parts(34_052_591, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(17_u64)) .saturating_add(T::DbWeight::get().writes(7_u64)) } /// Storage: `LBP::PoolData` (r:1 w:0) @@ -89,28 +105,30 @@ impl WeightInfo for HydraWeight { /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:3 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:2 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Tokens::Locks` (r:1 w:1) /// Proof: `Tokens::Locks` (`max_values`: None, `max_size`: Some(1261), added: 3736, mode: `MaxEncodedLen`) + /// Storage: `Router::SkipEd` (r:1 w:0) + /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) /// Storage: `Duster::AccountBlacklist` (r:2 w:0) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// The range of component `c` is `[1, 2]`. /// The range of component `b` is `[0, 1]`. fn calculate_and_execute_buy_in_lbp(c: u32, b: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1604 + b * (1837 ±0)` + // Measured: `1637 + b * (2131 ±0)` // Estimated: `6156 + b * (7749 ±0)` - // Minimum execution time: 75_256_000 picoseconds. - Weight::from_parts(76_245_000, 6156) - // Standard Error: 604_587 - .saturating_add(Weight::from_parts(2_376_809, 0).saturating_mul(c.into())) - // Standard Error: 1_327_242 - .saturating_add(Weight::from_parts(273_173_826, 0).saturating_mul(b.into())) + // Minimum execution time: 53_520_000 picoseconds. + Weight::from_parts(54_339_000, 6156) + // Standard Error: 418_984 + .saturating_add(Weight::from_parts(1_659_710, 0).saturating_mul(c.into())) + // Standard Error: 919_791 + .saturating_add(Weight::from_parts(236_379_793, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().reads((13_u64).saturating_mul(b.into()))) + .saturating_add(T::DbWeight::get().reads((14_u64).saturating_mul(b.into()))) .saturating_add(T::DbWeight::get().writes((7_u64).saturating_mul(b.into()))) .saturating_add(Weight::from_parts(0, 7749).saturating_mul(b.into())) } @@ -124,6 +142,8 @@ impl WeightInfo for HydraWeight { /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `XYK::ShareToken` (r:6 w:0) /// Proof: `XYK::ShareToken` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + /// Storage: `Router::SkipEd` (r:1 w:0) + /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) /// Storage: `Duster::AccountBlacklist` (r:7 w:0) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::BannedAssets` (r:5 w:0) @@ -138,11 +158,11 @@ impl WeightInfo for HydraWeight { /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) fn set_route_for_xyk() -> Weight { // Proof Size summary in bytes: - // Measured: `6326` + // Measured: `6426` // Estimated: `39735` - // Minimum execution time: 2_275_922_000 picoseconds. - Weight::from_parts(2_284_697_000, 39735) - .saturating_add(T::DbWeight::get().reads(55_u64)) + // Minimum execution time: 2_085_799_000 picoseconds. + Weight::from_parts(2_111_539_000, 39735) + .saturating_add(T::DbWeight::get().reads(56_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `Router::Routes` (r:0 w:1) @@ -151,38 +171,53 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `1012` // Estimated: `0` - // Minimum execution time: 30_072_000 picoseconds. - Weight::from_parts(30_421_000, 0) + // Minimum execution time: 23_300_000 picoseconds. + Weight::from_parts(24_050_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } } // For backwards compatibility and tests. impl WeightInfo for () { + /// Storage: `AssetRegistry::Assets` (r:1 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `Router::SkipEd` (r:0 w:1) + /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + fn skip_ed_handling_for_trade_with_insufficient_assets() -> Weight { + // Proof Size summary in bytes: + // Measured: `944` + // Estimated: `3590` + // Minimum execution time: 13_600_000 picoseconds. + Weight::from_parts(13_900_000, 3590) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } /// Storage: `LBP::PoolData` (r:1 w:0) /// Proof: `LBP::PoolData` (`max_values`: None, `max_size`: Some(163), added: 2638, mode: `MaxEncodedLen`) /// Storage: `Tokens::Accounts` (r:5 w:5) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:3 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:2 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Tokens::Locks` (r:1 w:1) /// Proof: `Tokens::Locks` (`max_values`: None, `max_size`: Some(1261), added: 3736, mode: `MaxEncodedLen`) + /// Storage: `Router::SkipEd` (r:1 w:0) + /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) /// Storage: `Duster::AccountBlacklist` (r:2 w:0) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// The range of component `c` is `[0, 1]`. fn calculate_and_execute_sell_in_lbp(c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `3436` + // Measured: `3743` // Estimated: `13905` - // Minimum execution time: 342_467_000 picoseconds. - Weight::from_parts(346_028_529, 13905) - // Standard Error: 185_098 - .saturating_add(Weight::from_parts(50_586_970, 0).saturating_mul(c.into())) - .saturating_add(RocksDbWeight::get().reads(16_u64)) + // Minimum execution time: 278_588_000 picoseconds. + Weight::from_parts(284_606_595, 13905) + // Standard Error: 341_686 + .saturating_add(Weight::from_parts(34_052_591, 0).saturating_mul(c.into())) + .saturating_add(RocksDbWeight::get().reads(17_u64)) .saturating_add(RocksDbWeight::get().writes(7_u64)) } /// Storage: `LBP::PoolData` (r:1 w:0) @@ -191,28 +226,30 @@ impl WeightInfo for () { /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:3 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:2 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Tokens::Locks` (r:1 w:1) /// Proof: `Tokens::Locks` (`max_values`: None, `max_size`: Some(1261), added: 3736, mode: `MaxEncodedLen`) + /// Storage: `Router::SkipEd` (r:1 w:0) + /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) /// Storage: `Duster::AccountBlacklist` (r:2 w:0) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// The range of component `c` is `[1, 2]`. /// The range of component `b` is `[0, 1]`. fn calculate_and_execute_buy_in_lbp(c: u32, b: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1604 + b * (1837 ±0)` + // Measured: `1637 + b * (2131 ±0)` // Estimated: `6156 + b * (7749 ±0)` - // Minimum execution time: 75_256_000 picoseconds. - Weight::from_parts(76_245_000, 6156) - // Standard Error: 604_587 - .saturating_add(Weight::from_parts(2_376_809, 0).saturating_mul(c.into())) - // Standard Error: 1_327_242 - .saturating_add(Weight::from_parts(273_173_826, 0).saturating_mul(b.into())) + // Minimum execution time: 53_520_000 picoseconds. + Weight::from_parts(54_339_000, 6156) + // Standard Error: 418_984 + .saturating_add(Weight::from_parts(1_659_710, 0).saturating_mul(c.into())) + // Standard Error: 919_791 + .saturating_add(Weight::from_parts(236_379_793, 0).saturating_mul(b.into())) .saturating_add(RocksDbWeight::get().reads(3_u64)) - .saturating_add(RocksDbWeight::get().reads((13_u64).saturating_mul(b.into()))) + .saturating_add(RocksDbWeight::get().reads((14_u64).saturating_mul(b.into()))) .saturating_add(RocksDbWeight::get().writes((7_u64).saturating_mul(b.into()))) .saturating_add(Weight::from_parts(0, 7749).saturating_mul(b.into())) } @@ -226,6 +263,8 @@ impl WeightInfo for () { /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `XYK::ShareToken` (r:6 w:0) /// Proof: `XYK::ShareToken` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + /// Storage: `Router::SkipEd` (r:1 w:0) + /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) /// Storage: `Duster::AccountBlacklist` (r:7 w:0) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::BannedAssets` (r:5 w:0) @@ -240,11 +279,11 @@ impl WeightInfo for () { /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) fn set_route_for_xyk() -> Weight { // Proof Size summary in bytes: - // Measured: `6326` + // Measured: `6426` // Estimated: `39735` - // Minimum execution time: 2_275_922_000 picoseconds. - Weight::from_parts(2_284_697_000, 39735) - .saturating_add(RocksDbWeight::get().reads(55_u64)) + // Minimum execution time: 2_085_799_000 picoseconds. + Weight::from_parts(2_111_539_000, 39735) + .saturating_add(RocksDbWeight::get().reads(56_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: `Router::Routes` (r:0 w:1) @@ -253,8 +292,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1012` // Estimated: `0` - // Minimum execution time: 30_072_000 picoseconds. - Weight::from_parts(30_421_000, 0) + // Minimum execution time: 23_300_000 picoseconds. + Weight::from_parts(24_050_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } } diff --git a/runtime/hydradx/src/assets.rs b/runtime/hydradx/src/assets.rs index 96168bc90..c42236398 100644 --- a/runtime/hydradx/src/assets.rs +++ b/runtime/hydradx/src/assets.rs @@ -63,7 +63,9 @@ use orml_traits::currency::{MultiCurrency, MultiLockableCurrency, MutationHooks, use orml_traits::{GetByKey, Happened}; use pallet_dynamic_fees::types::FeeParams; use pallet_lbp::weights::WeightInfo as LbpWeights; -use pallet_route_executor::{weights::WeightInfo as RouterWeights, AmmTradeWeights, MAX_NUMBER_OF_TRADES, SkipEd, SkipEdState}; +use pallet_route_executor::{ + weights::WeightInfo as RouterWeights, AmmTradeWeights, SkipEd, SkipEdState, MAX_NUMBER_OF_TRADES, +}; use pallet_staking::types::{Action, Point}; use pallet_staking::SigmoidPercentage; use pallet_xyk::weights::WeightInfo as XykWeights; @@ -225,7 +227,7 @@ impl OnTransfer for SufficiencyCheck { //NOTE: `to` is paying ED if `from` is whitelisted. //This can happen if pallet's account transfers insufficient tokens to another account. - if ::DustRemovalWhitelist::contains(from){ + if ::DustRemovalWhitelist::contains(from) { Self::on_funds(asset, to, to) } else { Self::on_funds(asset, from, to) @@ -858,6 +860,10 @@ impl RouterWeightInfo { number_of_times_execute_sell_amounts_executed, )) } + + pub fn skip_ed_handling_overweight() -> Weight { + weights::route_executor::HydraWeight::::skip_ed_handling_for_trade_with_insufficient_assets() + } } impl AmmTradeWeights> for RouterWeightInfo { @@ -896,6 +902,20 @@ impl AmmTradeWeights> for RouterWeightInfo { weight.saturating_accrue(amm_weight); } + //We add the overweight for skipping ED handling if we have any insufficient asset + let mut unique_assets = sp_std::collections::btree_set::BTreeSet::new(); + for trade in route.iter() { + unique_assets.insert(trade.asset_in); + unique_assets.insert(trade.asset_out); + } + if unique_assets + .iter() + .filter(|asset| !AssetRegistry::is_sufficient(**asset)) + .count() > 0 + { + weight.saturating_accrue(Self::skip_ed_handling_overweight()); + } + weight } @@ -934,6 +954,20 @@ impl AmmTradeWeights> for RouterWeightInfo { weight.saturating_accrue(amm_weight); } + //We add the overweight for skipping ED handling if we have any insufficient asset + let mut unique_assets = sp_std::collections::btree_set::BTreeSet::new(); + for trade in route.iter() { + unique_assets.insert(trade.asset_in); + unique_assets.insert(trade.asset_out); + } + if unique_assets + .iter() + .filter(|asset| !AssetRegistry::is_sufficient(**asset)) + .count() > 0 + { + weight.saturating_accrue(Self::skip_ed_handling_overweight()); + } + weight } @@ -1147,7 +1181,7 @@ use frame_support::storage::with_transaction; use hydradx_traits::price::PriceProvider; #[cfg(feature = "runtime-benchmarks")] use hydradx_traits::registry::Create; -use hydradx_traits::router::{RefundEdCalculator}; +use hydradx_traits::router::RefundEdCalculator; use pallet_referrals::traits::Convert; use pallet_referrals::{FeeDistribution, Level}; #[cfg(feature = "runtime-benchmarks")] diff --git a/runtime/hydradx/src/benchmarking/route_executor.rs b/runtime/hydradx/src/benchmarking/route_executor.rs index f52a37884..ef19255ed 100644 --- a/runtime/hydradx/src/benchmarking/route_executor.rs +++ b/runtime/hydradx/src/benchmarking/route_executor.rs @@ -19,6 +19,7 @@ use crate::{ AccountId, AssetId, Balance, Currencies, InsufficientEDinHDX, Router, Runtime, RuntimeOrigin, System, LBP, XYK, }; +use pallet_route_executor::{SkipEd, SkipEdState}; use super::*; use crate::benchmarking::dca::HDX; @@ -137,7 +138,29 @@ fn create_xyk_pool(asset_a: u32, asset_b: u32) { runtime_benchmarks! { {Runtime, pallet_route_executor} - // Calculates the weight of LBP trade. Used in the calculation to determine the weight of the overhead. + // Calculates the weight all the logic of ED handling of insufficient assets + skip_ed_handling_for_trade_with_insufficient_assets{ + let asset_1 = register_external_asset(b"FCA".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let asset_2 = register_external_asset(b"FCB".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + + let trade = Trade { + pool: PoolType::LBP, + asset_in: asset_1, + asset_out: asset_2 + }; + + }: { + //We assume the worst case, so we change the state 4 times(1 add, 2 modify, 1 kill) + Router::disable_ed_handling_for_insufficient_assets(&mut false, 3, 0, trade); + Router::disable_ed_handling_for_insufficient_assets(&mut false, 3, 1, trade); + Router::disable_ed_handling_for_insufficient_assets(&mut false, 3, 2, trade); + >::kill(); + } + verify { + + } + + calculate_and_execute_sell_in_lbp { let c in 0..1; // if c == 1, calculate_sell_trade_amounts is executed diff --git a/runtime/hydradx/src/weights/route_executor.rs b/runtime/hydradx/src/weights/route_executor.rs index 10f017e21..d876b3d25 100644 --- a/runtime/hydradx/src/weights/route_executor.rs +++ b/runtime/hydradx/src/weights/route_executor.rs @@ -18,9 +18,9 @@ //! Autogenerated weights for `pallet_route_executor` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-03-18, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-06-05, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` +//! HOSTNAME: `dmoka-msi-pc`, CPU: `AMD Ryzen 9 5900X 12-Core Processor` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: @@ -48,30 +48,45 @@ use core::marker::PhantomData; /// Weight functions for `pallet_route_executor`. pub struct HydraWeight(PhantomData); impl pallet_route_executor::weights::WeightInfo for HydraWeight { + /// Storage: `AssetRegistry::Assets` (r:1 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `Router::SkipEd` (r:0 w:1) + /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + fn skip_ed_handling_for_trade_with_insufficient_assets() -> Weight { + // Proof Size summary in bytes: + // Measured: `944` + // Estimated: `3590` + // Minimum execution time: 13_480_000 picoseconds. + Weight::from_parts(13_800_000, 3590) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } /// Storage: `LBP::PoolData` (r:1 w:0) /// Proof: `LBP::PoolData` (`max_values`: None, `max_size`: Some(163), added: 2638, mode: `MaxEncodedLen`) /// Storage: `Tokens::Accounts` (r:5 w:5) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:3 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:2 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Tokens::Locks` (r:1 w:1) /// Proof: `Tokens::Locks` (`max_values`: None, `max_size`: Some(1261), added: 3736, mode: `MaxEncodedLen`) + /// Storage: `Router::SkipEd` (r:1 w:0) + /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) /// Storage: `Duster::AccountBlacklist` (r:2 w:0) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// The range of component `c` is `[0, 1]`. fn calculate_and_execute_sell_in_lbp(c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `3436` + // Measured: `3743` // Estimated: `13905` - // Minimum execution time: 344_173_000 picoseconds. - Weight::from_parts(347_378_169, 13905) - // Standard Error: 131_839 - .saturating_add(Weight::from_parts(49_213_080, 0).saturating_mul(c.into())) - .saturating_add(T::DbWeight::get().reads(16)) + // Minimum execution time: 278_147_000 picoseconds. + Weight::from_parts(283_135_382, 13905) + // Standard Error: 216_715 + .saturating_add(Weight::from_parts(36_755_305, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(17)) .saturating_add(T::DbWeight::get().writes(7)) } /// Storage: `LBP::PoolData` (r:1 w:0) @@ -80,28 +95,30 @@ impl pallet_route_executor::weights::WeightInfo for Hyd /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:3 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:2 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Tokens::Locks` (r:1 w:1) /// Proof: `Tokens::Locks` (`max_values`: None, `max_size`: Some(1261), added: 3736, mode: `MaxEncodedLen`) + /// Storage: `Router::SkipEd` (r:1 w:0) + /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) /// Storage: `Duster::AccountBlacklist` (r:2 w:0) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// The range of component `c` is `[1, 2]`. /// The range of component `b` is `[0, 1]`. fn calculate_and_execute_buy_in_lbp(c: u32, b: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1604 + b * (1837 ±0)` - // Estimated: `6156 + b * (7749 ±251_795_645_551_580_832)` - // Minimum execution time: 75_692_000 picoseconds. - Weight::from_parts(76_409_000, 6156) - // Standard Error: 611_234 - .saturating_add(Weight::from_parts(2_382_471, 0).saturating_mul(c.into())) - // Standard Error: 1_341_833 - .saturating_add(Weight::from_parts(272_805_599, 0).saturating_mul(b.into())) + // Measured: `1637 + b * (2131 ±0)` + // Estimated: `6156 + b * (7749 ±245_709_589_663_843_264)` + // Minimum execution time: 53_260_000 picoseconds. + Weight::from_parts(54_319_000, 6156) + // Standard Error: 448_534 + .saturating_add(Weight::from_parts(1_926_964, 0).saturating_mul(c.into())) + // Standard Error: 984_662 + .saturating_add(Weight::from_parts(234_713_789, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().reads((13_u64).saturating_mul(b.into()))) + .saturating_add(T::DbWeight::get().reads((14_u64).saturating_mul(b.into()))) .saturating_add(T::DbWeight::get().writes((7_u64).saturating_mul(b.into()))) .saturating_add(Weight::from_parts(0, 7749).saturating_mul(b.into())) } @@ -115,6 +132,8 @@ impl pallet_route_executor::weights::WeightInfo for Hyd /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `XYK::ShareToken` (r:6 w:0) /// Proof: `XYK::ShareToken` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + /// Storage: `Router::SkipEd` (r:1 w:0) + /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) /// Storage: `Duster::AccountBlacklist` (r:7 w:0) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::BannedAssets` (r:5 w:0) @@ -129,11 +148,11 @@ impl pallet_route_executor::weights::WeightInfo for Hyd /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) fn set_route_for_xyk() -> Weight { // Proof Size summary in bytes: - // Measured: `6326` + // Measured: `6426` // Estimated: `39735` - // Minimum execution time: 2_263_303_000 picoseconds. - Weight::from_parts(2_275_623_000, 39735) - .saturating_add(T::DbWeight::get().reads(55)) + // Minimum execution time: 2_067_490_000 picoseconds. + Weight::from_parts(2_082_989_000, 39735) + .saturating_add(T::DbWeight::get().reads(56)) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Router::Routes` (r:0 w:1) @@ -142,8 +161,8 @@ impl pallet_route_executor::weights::WeightInfo for Hyd // Proof Size summary in bytes: // Measured: `1012` // Estimated: `0` - // Minimum execution time: 29_861_000 picoseconds. - Weight::from_parts(30_303_000, 0) + // Minimum execution time: 23_250_000 picoseconds. + Weight::from_parts(23_930_000, 0) .saturating_add(T::DbWeight::get().writes(1)) } } \ No newline at end of file From b834cf595c835be4bd50b030370090f5bcc4ce55 Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 6 Jun 2024 12:31:53 +0200 Subject: [PATCH 11/43] refactoring --- runtime/hydradx/src/assets.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/runtime/hydradx/src/assets.rs b/runtime/hydradx/src/assets.rs index c42236398..2925e828f 100644 --- a/runtime/hydradx/src/assets.rs +++ b/runtime/hydradx/src/assets.rs @@ -910,8 +910,7 @@ impl AmmTradeWeights> for RouterWeightInfo { } if unique_assets .iter() - .filter(|asset| !AssetRegistry::is_sufficient(**asset)) - .count() > 0 + .any(|asset| !AssetRegistry::is_sufficient(*asset)) { weight.saturating_accrue(Self::skip_ed_handling_overweight()); } @@ -962,8 +961,7 @@ impl AmmTradeWeights> for RouterWeightInfo { } if unique_assets .iter() - .filter(|asset| !AssetRegistry::is_sufficient(**asset)) - .count() > 0 + .any(|asset| !AssetRegistry::is_sufficient(*asset)) { weight.saturating_accrue(Self::skip_ed_handling_overweight()); } From 8e506f486580220555b70a3d3f3774f017a7e128 Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 6 Jun 2024 12:32:06 +0200 Subject: [PATCH 12/43] rebenchmark pallets --- runtime/hydradx/src/weights/dca.rs | 36 +++++++++--------- runtime/hydradx/src/weights/route_executor.rs | 38 +++++++++---------- 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/runtime/hydradx/src/weights/dca.rs b/runtime/hydradx/src/weights/dca.rs index 143e19da8..661d38f4f 100644 --- a/runtime/hydradx/src/weights/dca.rs +++ b/runtime/hydradx/src/weights/dca.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for `pallet_dca` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-06-06, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 @@ -34,7 +34,7 @@ // --heap-pages=4096 // --template=.maintain/pallet-weight-template-no-back.hbs // --pallet=pallet_dca -// --output=./weights/dca.rs +// --output=dca.rs // --extrinsic=* #![cfg_attr(rustfmt, rustfmt_skip)] @@ -45,11 +45,9 @@ use frame_support::{traits::Get, weights::Weight}; use core::marker::PhantomData; -use pallet_dca::weights::WeightInfo; - /// Weight functions for `pallet_dca`. pub struct HydraWeight(PhantomData); -impl WeightInfo for HydraWeight { +impl pallet_dca::weights::WeightInfo for HydraWeight { /// Storage: `DCA::ScheduleIdsPerBlock` (r:12 w:2) /// Proof: `DCA::ScheduleIdsPerBlock` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`) /// Storage: `DCA::Schedules` (r:1 w:0) @@ -64,10 +62,10 @@ impl WeightInfo for HydraWeight { /// Proof: `DCA::RetriesOnError` (`max_values`: None, `max_size`: Some(21), added: 2496, mode: `MaxEncodedLen`) fn on_initialize_with_buy_trade() -> Weight { // Proof Size summary in bytes: - // Measured: `54411` + // Measured: `54519` // Estimated: `31902` - // Minimum execution time: 237_105_000 picoseconds. - Weight::from_parts(240_959_000, 31902) + // Minimum execution time: 228_102_000 picoseconds. + Weight::from_parts(231_081_000, 31902) .saturating_add(T::DbWeight::get().reads(17)) .saturating_add(T::DbWeight::get().writes(7)) } @@ -85,10 +83,10 @@ impl WeightInfo for HydraWeight { /// Proof: `DCA::RetriesOnError` (`max_values`: None, `max_size`: Some(21), added: 2496, mode: `MaxEncodedLen`) fn on_initialize_with_sell_trade() -> Weight { // Proof Size summary in bytes: - // Measured: `54411` + // Measured: `54627` // Estimated: `31902` - // Minimum execution time: 238_379_000 picoseconds. - Weight::from_parts(241_004_000, 31902) + // Minimum execution time: 229_043_000 picoseconds. + Weight::from_parts(234_068_000, 31902) .saturating_add(T::DbWeight::get().reads(17)) .saturating_add(T::DbWeight::get().writes(7)) } @@ -98,8 +96,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `1075` // Estimated: `3566` - // Minimum execution time: 17_306_000 picoseconds. - Weight::from_parts(17_642_000, 3566) + // Minimum execution time: 17_006_000 picoseconds. + Weight::from_parts(17_344_000, 3566) .saturating_add(T::DbWeight::get().reads(1)) } /// Storage: `MultiTransactionPayment::AcceptedCurrencies` (r:1 w:0) @@ -126,10 +124,10 @@ impl WeightInfo for HydraWeight { /// Proof: `DCA::RemainingAmounts` (`max_values`: None, `max_size`: Some(36), added: 2511, mode: `MaxEncodedLen`) fn schedule() -> Weight { // Proof Size summary in bytes: - // Measured: `52552` + // Measured: `52618` // Estimated: `29326` - // Minimum execution time: 174_494_000 picoseconds. - Weight::from_parts(176_197_000, 29326) + // Minimum execution time: 163_015_000 picoseconds. + Weight::from_parts(166_162_000, 29326) .saturating_add(T::DbWeight::get().reads(17)) .saturating_add(T::DbWeight::get().writes(8)) } @@ -151,9 +149,9 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `2526` // Estimated: `4714` - // Minimum execution time: 80_303_000 picoseconds. - Weight::from_parts(81_183_000, 4714) + // Minimum execution time: 76_076_000 picoseconds. + Weight::from_parts(76_844_000, 4714) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(7)) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/route_executor.rs b/runtime/hydradx/src/weights/route_executor.rs index d876b3d25..4b180c816 100644 --- a/runtime/hydradx/src/weights/route_executor.rs +++ b/runtime/hydradx/src/weights/route_executor.rs @@ -18,9 +18,9 @@ //! Autogenerated weights for `pallet_route_executor` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-06-05, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-06-06, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `dmoka-msi-pc`, CPU: `AMD Ryzen 9 5900X 12-Core Processor` +//! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: @@ -56,8 +56,8 @@ impl pallet_route_executor::weights::WeightInfo for Hyd // Proof Size summary in bytes: // Measured: `944` // Estimated: `3590` - // Minimum execution time: 13_480_000 picoseconds. - Weight::from_parts(13_800_000, 3590) + // Minimum execution time: 15_530_000 picoseconds. + Weight::from_parts(15_945_000, 3590) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -82,10 +82,10 @@ impl pallet_route_executor::weights::WeightInfo for Hyd // Proof Size summary in bytes: // Measured: `3743` // Estimated: `13905` - // Minimum execution time: 278_147_000 picoseconds. - Weight::from_parts(283_135_382, 13905) - // Standard Error: 216_715 - .saturating_add(Weight::from_parts(36_755_305, 0).saturating_mul(c.into())) + // Minimum execution time: 335_788_000 picoseconds. + Weight::from_parts(338_920_485, 13905) + // Standard Error: 196_258 + .saturating_add(Weight::from_parts(50_068_889, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(17)) .saturating_add(T::DbWeight::get().writes(7)) } @@ -110,13 +110,13 @@ impl pallet_route_executor::weights::WeightInfo for Hyd fn calculate_and_execute_buy_in_lbp(c: u32, b: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `1637 + b * (2131 ±0)` - // Estimated: `6156 + b * (7749 ±245_709_589_663_843_264)` - // Minimum execution time: 53_260_000 picoseconds. - Weight::from_parts(54_319_000, 6156) - // Standard Error: 448_534 - .saturating_add(Weight::from_parts(1_926_964, 0).saturating_mul(c.into())) - // Standard Error: 984_662 - .saturating_add(Weight::from_parts(234_713_789, 0).saturating_mul(b.into())) + // Estimated: `6156 + b * (7749 ±0)` + // Minimum execution time: 73_171_000 picoseconds. + Weight::from_parts(73_781_000, 6156) + // Standard Error: 596_349 + .saturating_add(Weight::from_parts(2_327_987, 0).saturating_mul(c.into())) + // Standard Error: 1_309_156 + .saturating_add(Weight::from_parts(273_926_491, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().reads((14_u64).saturating_mul(b.into()))) .saturating_add(T::DbWeight::get().writes((7_u64).saturating_mul(b.into()))) @@ -150,8 +150,8 @@ impl pallet_route_executor::weights::WeightInfo for Hyd // Proof Size summary in bytes: // Measured: `6426` // Estimated: `39735` - // Minimum execution time: 2_067_490_000 picoseconds. - Weight::from_parts(2_082_989_000, 39735) + // Minimum execution time: 2_234_446_000 picoseconds. + Weight::from_parts(2_248_994_000, 39735) .saturating_add(T::DbWeight::get().reads(56)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -161,8 +161,8 @@ impl pallet_route_executor::weights::WeightInfo for Hyd // Proof Size summary in bytes: // Measured: `1012` // Estimated: `0` - // Minimum execution time: 23_250_000 picoseconds. - Weight::from_parts(23_930_000, 0) + // Minimum execution time: 28_506_000 picoseconds. + Weight::from_parts(29_059_000, 0) .saturating_add(T::DbWeight::get().writes(1)) } } \ No newline at end of file From a694ef288cafb2e0fcaf423b8cd66fc09b63b05a Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 6 Jun 2024 12:32:25 +0200 Subject: [PATCH 13/43] formatting --- integration-tests/src/router.rs | 1 - pallets/dca/src/tests/mock.rs | 1 - runtime/hydradx/src/assets.rs | 10 ++-------- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/integration-tests/src/router.rs b/integration-tests/src/router.rs index 866ecbf24..58b939af4 100644 --- a/integration-tests/src/router.rs +++ b/integration-tests/src/router.rs @@ -1057,7 +1057,6 @@ mod omnipool_router_tests { assert_balance!(ALICE.into(), HDX, 1000 * UNITS - amount_to_sell); - TransactionOutcome::Commit(DispatchResult::Ok(())) }); }); diff --git a/pallets/dca/src/tests/mock.rs b/pallets/dca/src/tests/mock.rs index 5f29aa068..5c273c69c 100644 --- a/pallets/dca/src/tests/mock.rs +++ b/pallets/dca/src/tests/mock.rs @@ -367,7 +367,6 @@ impl pallet_route_executor::Config for Test { type EdToRefundCalculator = MockedEdCalculator; } - pub struct MockedEdCalculator; impl RefundEdCalculator for MockedEdCalculator { diff --git a/runtime/hydradx/src/assets.rs b/runtime/hydradx/src/assets.rs index 2925e828f..b6e5a70b2 100644 --- a/runtime/hydradx/src/assets.rs +++ b/runtime/hydradx/src/assets.rs @@ -908,10 +908,7 @@ impl AmmTradeWeights> for RouterWeightInfo { unique_assets.insert(trade.asset_in); unique_assets.insert(trade.asset_out); } - if unique_assets - .iter() - .any(|asset| !AssetRegistry::is_sufficient(*asset)) - { + if unique_assets.iter().any(|asset| !AssetRegistry::is_sufficient(*asset)) { weight.saturating_accrue(Self::skip_ed_handling_overweight()); } @@ -959,10 +956,7 @@ impl AmmTradeWeights> for RouterWeightInfo { unique_assets.insert(trade.asset_in); unique_assets.insert(trade.asset_out); } - if unique_assets - .iter() - .any(|asset| !AssetRegistry::is_sufficient(*asset)) - { + if unique_assets.iter().any(|asset| !AssetRegistry::is_sufficient(*asset)) { weight.saturating_accrue(Self::skip_ed_handling_overweight()); } From a4fa1688ed621cadfc6eeb59a9d97e47ae61b3f7 Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 6 Jun 2024 12:49:58 +0200 Subject: [PATCH 14/43] rebenchmark DCA --- runtime/hydradx/src/weights/dca.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/runtime/hydradx/src/weights/dca.rs b/runtime/hydradx/src/weights/dca.rs index 661d38f4f..3843a70a7 100644 --- a/runtime/hydradx/src/weights/dca.rs +++ b/runtime/hydradx/src/weights/dca.rs @@ -64,8 +64,8 @@ impl pallet_dca::weights::WeightInfo for HydraWeight // Proof Size summary in bytes: // Measured: `54519` // Estimated: `31902` - // Minimum execution time: 228_102_000 picoseconds. - Weight::from_parts(231_081_000, 31902) + // Minimum execution time: 227_216_000 picoseconds. + Weight::from_parts(230_873_000, 31902) .saturating_add(T::DbWeight::get().reads(17)) .saturating_add(T::DbWeight::get().writes(7)) } @@ -85,8 +85,8 @@ impl pallet_dca::weights::WeightInfo for HydraWeight // Proof Size summary in bytes: // Measured: `54627` // Estimated: `31902` - // Minimum execution time: 229_043_000 picoseconds. - Weight::from_parts(234_068_000, 31902) + // Minimum execution time: 227_818_000 picoseconds. + Weight::from_parts(233_360_000, 31902) .saturating_add(T::DbWeight::get().reads(17)) .saturating_add(T::DbWeight::get().writes(7)) } @@ -96,8 +96,8 @@ impl pallet_dca::weights::WeightInfo for HydraWeight // Proof Size summary in bytes: // Measured: `1075` // Estimated: `3566` - // Minimum execution time: 17_006_000 picoseconds. - Weight::from_parts(17_344_000, 3566) + // Minimum execution time: 17_448_000 picoseconds. + Weight::from_parts(17_848_000, 3566) .saturating_add(T::DbWeight::get().reads(1)) } /// Storage: `MultiTransactionPayment::AcceptedCurrencies` (r:1 w:0) @@ -126,8 +126,8 @@ impl pallet_dca::weights::WeightInfo for HydraWeight // Proof Size summary in bytes: // Measured: `52618` // Estimated: `29326` - // Minimum execution time: 163_015_000 picoseconds. - Weight::from_parts(166_162_000, 29326) + // Minimum execution time: 163_228_000 picoseconds. + Weight::from_parts(166_489_000, 29326) .saturating_add(T::DbWeight::get().reads(17)) .saturating_add(T::DbWeight::get().writes(8)) } @@ -149,8 +149,8 @@ impl pallet_dca::weights::WeightInfo for HydraWeight // Proof Size summary in bytes: // Measured: `2526` // Estimated: `4714` - // Minimum execution time: 76_076_000 picoseconds. - Weight::from_parts(76_844_000, 4714) + // Minimum execution time: 76_262_000 picoseconds. + Weight::from_parts(76_953_000, 4714) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(7)) } From 3aff5c7703e9106711b4bf4ef0c6be2c281cb1c4 Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 6 Jun 2024 13:48:56 +0200 Subject: [PATCH 15/43] make clippy happy --- pallets/dca/src/tests/mock.rs | 3 +-- pallets/route-executor/src/lib.rs | 4 ++-- pallets/route-executor/src/tests/mock.rs | 10 ---------- runtime/hydradx/src/assets.rs | 2 +- runtime/hydradx/src/benchmarking/route_executor.rs | 2 +- 5 files changed, 5 insertions(+), 16 deletions(-) diff --git a/pallets/dca/src/tests/mock.rs b/pallets/dca/src/tests/mock.rs index 5c273c69c..72d992889 100644 --- a/pallets/dca/src/tests/mock.rs +++ b/pallets/dca/src/tests/mock.rs @@ -18,7 +18,7 @@ use crate as dca; use crate::{Config, Error, RandomnessProvider, RelayChainBlockHashProvider}; use cumulus_primitives_core::relay_chain::Hash; -use frame_support::traits::{Contains, Everything, Nothing}; +use frame_support::traits::{Everything, Nothing}; use frame_support::weights::constants::ExtrinsicBaseWeight; use frame_support::weights::WeightToFeeCoefficient; use frame_support::weights::{IdentityFee, Weight}; @@ -711,7 +711,6 @@ use frame_system::pallet_prelude::OriginFor; use hydra_dx_math::ema::EmaPrice; use hydra_dx_math::to_u128_wrapper; use hydra_dx_math::types::Ratio; -use hydradx_traits::pools::DustRemovalAccountWhitelist; use hydradx_traits::router::{ExecutorError, PoolType, RefundEdCalculator, RouteProvider, Trade, TradeExecution}; use pallet_currencies::fungibles::FungibleCurrencies; use pallet_omnipool::traits::ExternalPriceProvider; diff --git a/pallets/route-executor/src/lib.rs b/pallets/route-executor/src/lib.rs index a0dd2c70b..8d300d2ac 100644 --- a/pallets/route-executor/src/lib.rs +++ b/pallets/route-executor/src/lib.rs @@ -644,7 +644,7 @@ impl Pallet { return matches!(v, SkipEdState::SkipEdLock | SkipEdState::SkipEdLockAndUnlock); } - return false; + false } pub fn skip_ed_unlock() -> bool { @@ -652,7 +652,7 @@ impl Pallet { return matches!(v, SkipEdState::SkipEdUnlock | SkipEdState::SkipEdLockAndUnlock); } - return false; + false } fn validate_route(route: &[Trade]) -> Result<(T::Balance, T::Balance), DispatchError> { diff --git a/pallets/route-executor/src/tests/mock.rs b/pallets/route-executor/src/tests/mock.rs index c73473a6b..29964d60d 100644 --- a/pallets/route-executor/src/tests/mock.rs +++ b/pallets/route-executor/src/tests/mock.rs @@ -17,7 +17,6 @@ use crate as router; use crate::{Config, Trade}; -use frame_support::traits::Contains; use frame_support::{ parameter_types, traits::{Everything, Nothing}, @@ -156,14 +155,6 @@ impl Config for Test { type WeightInfo = (); } -pub struct Whitelist; - -impl Contains for Whitelist { - fn contains(account: &AccountId) -> bool { - false - } -} - pub struct MockedEdCalculator; impl RefundEdCalculator for MockedEdCalculator { @@ -172,7 +163,6 @@ impl RefundEdCalculator for MockedEdCalculator { } } -use hydradx_traits::pools::DustRemovalAccountWhitelist; use hydradx_traits::AssetKind; pub struct MockedAssetRegistry; diff --git a/runtime/hydradx/src/assets.rs b/runtime/hydradx/src/assets.rs index b6e5a70b2..8aadc0540 100644 --- a/runtime/hydradx/src/assets.rs +++ b/runtime/hydradx/src/assets.rs @@ -64,7 +64,7 @@ use orml_traits::{GetByKey, Happened}; use pallet_dynamic_fees::types::FeeParams; use pallet_lbp::weights::WeightInfo as LbpWeights; use pallet_route_executor::{ - weights::WeightInfo as RouterWeights, AmmTradeWeights, SkipEd, SkipEdState, MAX_NUMBER_OF_TRADES, + weights::WeightInfo as RouterWeights, AmmTradeWeights, MAX_NUMBER_OF_TRADES, }; use pallet_staking::types::{Action, Point}; use pallet_staking::SigmoidPercentage; diff --git a/runtime/hydradx/src/benchmarking/route_executor.rs b/runtime/hydradx/src/benchmarking/route_executor.rs index ef19255ed..b53954112 100644 --- a/runtime/hydradx/src/benchmarking/route_executor.rs +++ b/runtime/hydradx/src/benchmarking/route_executor.rs @@ -19,7 +19,7 @@ use crate::{ AccountId, AssetId, Balance, Currencies, InsufficientEDinHDX, Router, Runtime, RuntimeOrigin, System, LBP, XYK, }; -use pallet_route_executor::{SkipEd, SkipEdState}; +use pallet_route_executor::{SkipEd}; use super::*; use crate::benchmarking::dca::HDX; From 163b459829f33a1314ad0df7004d109eb444294d Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 6 Jun 2024 13:52:24 +0200 Subject: [PATCH 16/43] bump versions --- Cargo.lock | 8 ++++---- integration-tests/Cargo.toml | 2 +- pallets/dca/Cargo.toml | 2 +- pallets/route-executor/Cargo.toml | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9d65ff9aa..714ec200d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4671,7 +4671,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "241.0.0" +version = "242.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -7474,7 +7474,7 @@ dependencies = [ [[package]] name = "pallet-dca" -version = "1.4.7" +version = "1.4.8" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -8422,7 +8422,7 @@ dependencies = [ [[package]] name = "pallet-route-executor" -version = "2.3.2" +version = "2.3.3" dependencies = [ "frame-benchmarking", "frame-support", @@ -11545,7 +11545,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.21.8" +version = "1.21.9" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index a33f3996e..06301f314 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.21.8" +version = "1.21.9" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/pallets/dca/Cargo.toml b/pallets/dca/Cargo.toml index dfac51357..c7634b80c 100644 --- a/pallets/dca/Cargo.toml +++ b/pallets/dca/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-dca' -version = "1.4.7" +version = "1.4.8" description = 'A pallet to manage DCA scheduling' authors = ['GalacticCouncil'] edition = '2021' diff --git a/pallets/route-executor/Cargo.toml b/pallets/route-executor/Cargo.toml index ccf6826f9..fc6eb60d0 100644 --- a/pallets/route-executor/Cargo.toml +++ b/pallets/route-executor/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-route-executor' -version = '2.3.2' +version = '2.3.3' description = 'A pallet to execute a route containing a sequence of trades' authors = ['GalacticCouncil'] edition = '2021' diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index 52353cede..3da4d4ac3 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "241.0.0" +version = "242.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 9ed880600..1c95c24d0 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -109,7 +109,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 241, + spec_version: 242, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 499e2650581cfe1066e6d5682267d537e0ec23e9 Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 6 Jun 2024 14:51:53 +0200 Subject: [PATCH 17/43] formatting --- runtime/hydradx/src/assets.rs | 4 +--- runtime/hydradx/src/benchmarking/route_executor.rs | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/runtime/hydradx/src/assets.rs b/runtime/hydradx/src/assets.rs index 8aadc0540..6fe30c015 100644 --- a/runtime/hydradx/src/assets.rs +++ b/runtime/hydradx/src/assets.rs @@ -63,9 +63,7 @@ use orml_traits::currency::{MultiCurrency, MultiLockableCurrency, MutationHooks, use orml_traits::{GetByKey, Happened}; use pallet_dynamic_fees::types::FeeParams; use pallet_lbp::weights::WeightInfo as LbpWeights; -use pallet_route_executor::{ - weights::WeightInfo as RouterWeights, AmmTradeWeights, MAX_NUMBER_OF_TRADES, -}; +use pallet_route_executor::{weights::WeightInfo as RouterWeights, AmmTradeWeights, MAX_NUMBER_OF_TRADES}; use pallet_staking::types::{Action, Point}; use pallet_staking::SigmoidPercentage; use pallet_xyk::weights::WeightInfo as XykWeights; diff --git a/runtime/hydradx/src/benchmarking/route_executor.rs b/runtime/hydradx/src/benchmarking/route_executor.rs index b53954112..73581c373 100644 --- a/runtime/hydradx/src/benchmarking/route_executor.rs +++ b/runtime/hydradx/src/benchmarking/route_executor.rs @@ -19,7 +19,7 @@ use crate::{ AccountId, AssetId, Balance, Currencies, InsufficientEDinHDX, Router, Runtime, RuntimeOrigin, System, LBP, XYK, }; -use pallet_route_executor::{SkipEd}; +use pallet_route_executor::SkipEd; use super::*; use crate::benchmarking::dca::HDX; From 766a6d9f9f03755b7fa42a88aa5f8ad445b076f5 Mon Sep 17 00:00:00 2001 From: dmoka Date: Fri, 7 Jun 2024 14:10:33 +0200 Subject: [PATCH 18/43] remove leftover unused storage --- pallets/route-executor/src/lib.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pallets/route-executor/src/lib.rs b/pallets/route-executor/src/lib.rs index 8d300d2ac..0dd18f9c4 100644 --- a/pallets/route-executor/src/lib.rs +++ b/pallets/route-executor/src/lib.rs @@ -161,13 +161,7 @@ pub mod pallet { NotAllowed, } - /// Flag to indicate if the route execution is in the middle of the route - /// Mainly used for disabling ED charging for the trades in the middle of the route - #[pallet::storage] - #[pallet::getter(fn next_schedule_id)] - pub type InMiddleOfRoute = StorageValue<_, bool, ValueQuery>; - - //TODO: add doc + ///Flag to indicate when to skip ED handling #[pallet::storage] #[pallet::getter(fn last_trade_position)] pub type SkipEd = StorageValue<_, SkipEdState, OptionQuery>; From e296f815d97fff8ce79af3609097121294fed7c0 Mon Sep 17 00:00:00 2001 From: dmoka Date: Wed, 19 Jun 2024 10:38:39 +0200 Subject: [PATCH 19/43] bump version --- Cargo.lock | 6 +++--- pallets/route-executor/Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6ab21d65e..f41bfec5d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4912,7 +4912,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "243.0.0" +version = "244.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", @@ -8886,7 +8886,7 @@ dependencies = [ [[package]] name = "pallet-route-executor" -version = "2.3.3" +version = "2.3.4" dependencies = [ "frame-benchmarking", "frame-support", @@ -11915,7 +11915,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.22.4" +version = "1.22.5" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", diff --git a/pallets/route-executor/Cargo.toml b/pallets/route-executor/Cargo.toml index fc6eb60d0..06a6f9945 100644 --- a/pallets/route-executor/Cargo.toml +++ b/pallets/route-executor/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-route-executor' -version = '2.3.3' +version = '2.3.4' description = 'A pallet to execute a route containing a sequence of trades' authors = ['GalacticCouncil'] edition = '2021' From ff4d051c8f01dfa75ecbd13e996006637d2e92ff Mon Sep 17 00:00:00 2001 From: dmoka Date: Wed, 19 Jun 2024 11:10:10 +0200 Subject: [PATCH 20/43] fix compilation error --- runtime/hydradx/src/assets.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/hydradx/src/assets.rs b/runtime/hydradx/src/assets.rs index 30aaf60fa..c967c4f6b 100644 --- a/runtime/hydradx/src/assets.rs +++ b/runtime/hydradx/src/assets.rs @@ -862,7 +862,7 @@ impl RouterWeightInfo { } pub fn skip_ed_handling_overweight() -> Weight { - weights::route_executor::HydraWeight::::skip_ed_handling_for_trade_with_insufficient_assets() + weights::pallet_route_executor::HydraWeight::::skip_ed_handling_for_trade_with_insufficient_assets() } } From 4b5f33e1f62827814990e3a166ef3954eb664663 Mon Sep 17 00:00:00 2001 From: dmoka Date: Wed, 19 Jun 2024 13:21:47 +0200 Subject: [PATCH 21/43] fix weight --- .../src/weights/pallet_route_executor.rs | 64 ++++++++++--------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/runtime/hydradx/src/weights/pallet_route_executor.rs b/runtime/hydradx/src/weights/pallet_route_executor.rs index 4b180c816..7a0bdca65 100644 --- a/runtime/hydradx/src/weights/pallet_route_executor.rs +++ b/runtime/hydradx/src/weights/pallet_route_executor.rs @@ -15,13 +15,14 @@ // See the License for the specific language governing permissions and // limitations under the License. + //! Autogenerated weights for `pallet_route_executor` //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-06-06, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-06-19, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` // Executed Command: // target/release/hydradx @@ -32,7 +33,7 @@ // --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --template=.maintain/pallet-weight-template-no-back.hbs +// --template=scripts/pallet-weight-template.hbs // --pallet=pallet_route-executor // --output=re2.rs // --extrinsic=* @@ -42,10 +43,13 @@ #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::Weight}; +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use core::marker::PhantomData; -/// Weight functions for `pallet_route_executor`. +/// Weights for `pallet_route_executor`. +pub struct WeightInfo(PhantomData); + +/// Weights for `pallet_route_executor` using the HydraDX node and recommended hardware. pub struct HydraWeight(PhantomData); impl pallet_route_executor::weights::WeightInfo for HydraWeight { /// Storage: `AssetRegistry::Assets` (r:1 w:0) @@ -56,10 +60,10 @@ impl pallet_route_executor::weights::WeightInfo for Hyd // Proof Size summary in bytes: // Measured: `944` // Estimated: `3590` - // Minimum execution time: 15_530_000 picoseconds. - Weight::from_parts(15_945_000, 3590) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) + // Minimum execution time: 14_113_000 picoseconds. + Weight::from_parts(14_402_000, 3590) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `LBP::PoolData` (r:1 w:0) /// Proof: `LBP::PoolData` (`max_values`: None, `max_size`: Some(163), added: 2638, mode: `MaxEncodedLen`) @@ -82,12 +86,12 @@ impl pallet_route_executor::weights::WeightInfo for Hyd // Proof Size summary in bytes: // Measured: `3743` // Estimated: `13905` - // Minimum execution time: 335_788_000 picoseconds. - Weight::from_parts(338_920_485, 13905) - // Standard Error: 196_258 - .saturating_add(Weight::from_parts(50_068_889, 0).saturating_mul(c.into())) - .saturating_add(T::DbWeight::get().reads(17)) - .saturating_add(T::DbWeight::get().writes(7)) + // Minimum execution time: 351_990_000 picoseconds. + Weight::from_parts(355_911_448, 13905) + // Standard Error: 278_831 + .saturating_add(Weight::from_parts(71_299_613, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(17_u64)) + .saturating_add(T::DbWeight::get().writes(7_u64)) } /// Storage: `LBP::PoolData` (r:1 w:0) /// Proof: `LBP::PoolData` (`max_values`: None, `max_size`: Some(163), added: 2638, mode: `MaxEncodedLen`) @@ -111,13 +115,13 @@ impl pallet_route_executor::weights::WeightInfo for Hyd // Proof Size summary in bytes: // Measured: `1637 + b * (2131 ±0)` // Estimated: `6156 + b * (7749 ±0)` - // Minimum execution time: 73_171_000 picoseconds. - Weight::from_parts(73_781_000, 6156) - // Standard Error: 596_349 - .saturating_add(Weight::from_parts(2_327_987, 0).saturating_mul(c.into())) - // Standard Error: 1_309_156 - .saturating_add(Weight::from_parts(273_926_491, 0).saturating_mul(b.into())) - .saturating_add(T::DbWeight::get().reads(3)) + // Minimum execution time: 94_829_000 picoseconds. + Weight::from_parts(95_816_000, 6156) + // Standard Error: 856_416 + .saturating_add(Weight::from_parts(3_330_760, 0).saturating_mul(c.into())) + // Standard Error: 1_880_077 + .saturating_add(Weight::from_parts(270_751_855, 0).saturating_mul(b.into())) + .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().reads((14_u64).saturating_mul(b.into()))) .saturating_add(T::DbWeight::get().writes((7_u64).saturating_mul(b.into()))) .saturating_add(Weight::from_parts(0, 7749).saturating_mul(b.into())) @@ -150,10 +154,10 @@ impl pallet_route_executor::weights::WeightInfo for Hyd // Proof Size summary in bytes: // Measured: `6426` // Estimated: `39735` - // Minimum execution time: 2_234_446_000 picoseconds. - Weight::from_parts(2_248_994_000, 39735) - .saturating_add(T::DbWeight::get().reads(56)) - .saturating_add(T::DbWeight::get().writes(1)) + // Minimum execution time: 1_924_412_000 picoseconds. + Weight::from_parts(1_932_686_000, 39735) + .saturating_add(T::DbWeight::get().reads(56_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `Router::Routes` (r:0 w:1) /// Proof: `Router::Routes` (`max_values`: None, `max_size`: Some(90), added: 2565, mode: `MaxEncodedLen`) @@ -161,8 +165,8 @@ impl pallet_route_executor::weights::WeightInfo for Hyd // Proof Size summary in bytes: // Measured: `1012` // Estimated: `0` - // Minimum execution time: 28_506_000 picoseconds. - Weight::from_parts(29_059_000, 0) - .saturating_add(T::DbWeight::get().writes(1)) + // Minimum execution time: 25_923_000 picoseconds. + Weight::from_parts(26_400_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)) } } \ No newline at end of file From c2c0908ccf76f406582bbd834ee01d1d70a74fc1 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 16 Jul 2024 16:49:10 +0100 Subject: [PATCH 22/43] renaming --- pallets/route-executor/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pallets/route-executor/src/lib.rs b/pallets/route-executor/src/lib.rs index c4f4c3318..b98f641dd 100644 --- a/pallets/route-executor/src/lib.rs +++ b/pallets/route-executor/src/lib.rs @@ -55,7 +55,7 @@ pub use pallet::*; pub const MAX_NUMBER_OF_TRADES: u32 = 5; #[derive(Debug, Encode, Decode, Copy, Clone, PartialEq, Eq, TypeInfo, MaxEncodedLen)] -pub enum SkipEdState { +pub enum EdHandling { SkipEdLock, SkipEdLockAndUnlock, SkipEdUnlock, @@ -166,7 +166,7 @@ pub mod pallet { ///Flag to indicate when to skip ED handling #[pallet::storage] #[pallet::getter(fn last_trade_position)] - pub type SkipEd = StorageValue<_, SkipEdState, OptionQuery>; + pub type SkipEd = StorageValue<_, EdHandling, OptionQuery>; /// Storing routes for asset pairs #[pallet::storage] @@ -625,11 +625,11 @@ impl Pallet { *skip_ed_disabling = true; //We optimize to set the state for middle trades only once at the first middle trade, then we change no state till the last trade match trade_index { - 0 => SkipEd::::put(SkipEdState::SkipEdLock), + 0 => SkipEd::::put(EdHandling::SkipEdLock), trade_index if trade_index.saturating_add(1) == route_length => { - SkipEd::::put(SkipEdState::SkipEdUnlock) + SkipEd::::put(EdHandling::SkipEdUnlock) } - 1 => SkipEd::::put(SkipEdState::SkipEdLockAndUnlock), + 1 => SkipEd::::put(EdHandling::SkipEdLockAndUnlock), _ => (), } } From e77395245502412b5e1a6c3935d8c1e387717c8d Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 16 Jul 2024 17:12:42 +0100 Subject: [PATCH 23/43] remove optimization --- pallets/route-executor/src/lib.rs | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/pallets/route-executor/src/lib.rs b/pallets/route-executor/src/lib.rs index b98f641dd..1cb8585b6 100644 --- a/pallets/route-executor/src/lib.rs +++ b/pallets/route-executor/src/lib.rs @@ -225,15 +225,9 @@ pub mod pallet { Error::::TradingLimitReached ); - let mut skip_ed_disabling: bool = false; let route_length = route.len(); for (trade_index, (trade_amount, trade)) in trade_amounts.iter().zip(route.clone()).enumerate() { - Self::disable_ed_handling_for_insufficient_assets( - &mut skip_ed_disabling, - route_length, - trade_index, - trade, - ); + Self::disable_ed_handling_for_insufficient_assets(route_length, trade_index, trade); let user_balance_of_asset_in_before_trade = T::Currency::reducible_balance(trade.asset_in, &who, Preservation::Expendable, Fortitude::Polite); @@ -257,9 +251,7 @@ pub mod pallet { )?; } - if skip_ed_disabling { - SkipEd::::kill(); - } + SkipEd::::kill(); Self::ensure_that_user_received_asset_out_at_most( who, @@ -320,15 +312,9 @@ pub mod pallet { let first_trade = trade_amounts.last().ok_or(Error::::RouteCalculationFailed)?; ensure!(first_trade.amount_in <= max_amount_in, Error::::TradingLimitReached); - let mut skip_ed_disabling: bool = false; let route_length = route.len(); for (trade_index, (trade_amount, trade)) in trade_amounts.iter().rev().zip(route).enumerate() { - Self::disable_ed_handling_for_insufficient_assets( - &mut skip_ed_disabling, - route_length, - trade_index, - trade, - ); + Self::disable_ed_handling_for_insufficient_assets(route_length, trade_index, trade); let user_balance_of_asset_out_before_trade = T::Currency::reducible_balance(trade.asset_out, &who, Preservation::Preserve, Fortitude::Polite); let execution_result = T::AMM::execute_buy( @@ -351,9 +337,7 @@ pub mod pallet { )?; } - if skip_ed_disabling { - SkipEd::::kill(); - } + SkipEd::::kill(); Self::ensure_that_user_spent_asset_in_at_least( who, @@ -613,7 +597,6 @@ impl Pallet { } pub fn disable_ed_handling_for_insufficient_assets( - skip_ed_disabling: &mut bool, route_length: usize, trade_index: usize, trade: Trade, @@ -622,7 +605,6 @@ impl Pallet { && (!T::InspectRegistry::is_sufficient(trade.asset_in) || !T::InspectRegistry::is_sufficient(trade.asset_out)) { - *skip_ed_disabling = true; //We optimize to set the state for middle trades only once at the first middle trade, then we change no state till the last trade match trade_index { 0 => SkipEd::::put(EdHandling::SkipEdLock), @@ -637,7 +619,7 @@ impl Pallet { pub fn skip_ed_lock() -> bool { if let Ok(v) = SkipEd::::try_get() { - return matches!(v, SkipEdState::SkipEdLock | SkipEdState::SkipEdLockAndUnlock); + return matches!(v, EdHandling::SkipEdLock | EdHandling::SkipEdLockAndUnlock); } false @@ -645,7 +627,7 @@ impl Pallet { pub fn skip_ed_unlock() -> bool { if let Ok(v) = SkipEd::::try_get() { - return matches!(v, SkipEdState::SkipEdUnlock | SkipEdState::SkipEdLockAndUnlock); + return matches!(v, EdHandling::SkipEdUnlock | EdHandling::SkipEdLockAndUnlock); } false From 9407c3131305779c67257815a44f906ae0b15c8a Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 23 Jul 2024 10:03:12 +0200 Subject: [PATCH 24/43] we only add overweight of skipping ed handling in case of insufficient asset --- runtime/hydradx/src/assets.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/runtime/hydradx/src/assets.rs b/runtime/hydradx/src/assets.rs index 0fd87ac7a..65d340b8e 100644 --- a/runtime/hydradx/src/assets.rs +++ b/runtime/hydradx/src/assets.rs @@ -916,12 +916,8 @@ impl AmmTradeWeights> for RouterWeightInfo { } //We add the overweight for skipping ED handling if we have any insufficient asset - let mut unique_assets = sp_std::collections::btree_set::BTreeSet::new(); - for trade in route.iter() { - unique_assets.insert(trade.asset_in); - unique_assets.insert(trade.asset_out); - } - if unique_assets.iter().any(|asset| !AssetRegistry::is_sufficient(*asset)) { + + if route.iter().any(|trade| !AssetRegistry::is_sufficient(trade.asset_in) || !AssetRegistry::is_sufficient(trade.asset_out)) { weight.saturating_accrue(Self::skip_ed_handling_overweight()); } @@ -966,12 +962,7 @@ impl AmmTradeWeights> for RouterWeightInfo { } //We add the overweight for skipping ED handling if we have any insufficient asset - let mut unique_assets = sp_std::collections::btree_set::BTreeSet::new(); - for trade in route.iter() { - unique_assets.insert(trade.asset_in); - unique_assets.insert(trade.asset_out); - } - if unique_assets.iter().any(|asset| !AssetRegistry::is_sufficient(*asset)) { + if route.iter().any(|trade| !AssetRegistry::is_sufficient(trade.asset_in) || !AssetRegistry::is_sufficient(trade.asset_out)) { weight.saturating_accrue(Self::skip_ed_handling_overweight()); } From 62f56b9c104a59a25460034758787560b998b54a Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 23 Jul 2024 10:08:11 +0200 Subject: [PATCH 25/43] fix compilation error --- runtime/hydradx/src/assets.rs | 8 ++++++-- runtime/hydradx/src/benchmarking/route_executor.rs | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/runtime/hydradx/src/assets.rs b/runtime/hydradx/src/assets.rs index 65d340b8e..814444133 100644 --- a/runtime/hydradx/src/assets.rs +++ b/runtime/hydradx/src/assets.rs @@ -917,7 +917,9 @@ impl AmmTradeWeights> for RouterWeightInfo { //We add the overweight for skipping ED handling if we have any insufficient asset - if route.iter().any(|trade| !AssetRegistry::is_sufficient(trade.asset_in) || !AssetRegistry::is_sufficient(trade.asset_out)) { + if route.iter().any(|trade| { + !AssetRegistry::is_sufficient(trade.asset_in) || !AssetRegistry::is_sufficient(trade.asset_out) + }) { weight.saturating_accrue(Self::skip_ed_handling_overweight()); } @@ -962,7 +964,9 @@ impl AmmTradeWeights> for RouterWeightInfo { } //We add the overweight for skipping ED handling if we have any insufficient asset - if route.iter().any(|trade| !AssetRegistry::is_sufficient(trade.asset_in) || !AssetRegistry::is_sufficient(trade.asset_out)) { + if route.iter().any(|trade| { + !AssetRegistry::is_sufficient(trade.asset_in) || !AssetRegistry::is_sufficient(trade.asset_out) + }) { weight.saturating_accrue(Self::skip_ed_handling_overweight()); } diff --git a/runtime/hydradx/src/benchmarking/route_executor.rs b/runtime/hydradx/src/benchmarking/route_executor.rs index e03385769..476f4e2a9 100644 --- a/runtime/hydradx/src/benchmarking/route_executor.rs +++ b/runtime/hydradx/src/benchmarking/route_executor.rs @@ -151,9 +151,9 @@ runtime_benchmarks! { }: { //We assume the worst case, so we change the state 4 times(1 add, 2 modify, 1 kill) - Router::disable_ed_handling_for_insufficient_assets(&mut false, 3, 0, trade); - Router::disable_ed_handling_for_insufficient_assets(&mut false, 3, 1, trade); - Router::disable_ed_handling_for_insufficient_assets(&mut false, 3, 2, trade); + Router::disable_ed_handling_for_insufficient_assets(3, 0, trade); + Router::disable_ed_handling_for_insufficient_assets(3, 1, trade); + Router::disable_ed_handling_for_insufficient_assets(3, 2, trade); >::kill(); } verify { From 0385a1b0ff7070ab74a501967b8562a3e62a4470 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 23 Jul 2024 13:43:39 +0200 Subject: [PATCH 26/43] adjust benchmarking --- runtime/hydradx/src/assets.rs | 7 +- .../src/benchmarking/route_executor.rs | 1 - .../src/weights/pallet_route_executor.rs | 66 ++++++++++--------- 3 files changed, 39 insertions(+), 35 deletions(-) diff --git a/runtime/hydradx/src/assets.rs b/runtime/hydradx/src/assets.rs index 814444133..3191c81d9 100644 --- a/runtime/hydradx/src/assets.rs +++ b/runtime/hydradx/src/assets.rs @@ -915,9 +915,8 @@ impl AmmTradeWeights> for RouterWeightInfo { weight.saturating_accrue(amm_weight); } - //We add the overweight for skipping ED handling if we have any insufficient asset - - if route.iter().any(|trade| { + //We add the overweight for skipping ED handling if route has multiple trades and we have any insufficient asset + if route.len() > 1 && route.iter().any(|trade| { !AssetRegistry::is_sufficient(trade.asset_in) || !AssetRegistry::is_sufficient(trade.asset_out) }) { weight.saturating_accrue(Self::skip_ed_handling_overweight()); @@ -964,7 +963,7 @@ impl AmmTradeWeights> for RouterWeightInfo { } //We add the overweight for skipping ED handling if we have any insufficient asset - if route.iter().any(|trade| { + if route.len() > 1 && route.iter().any(|trade| { !AssetRegistry::is_sufficient(trade.asset_in) || !AssetRegistry::is_sufficient(trade.asset_out) }) { weight.saturating_accrue(Self::skip_ed_handling_overweight()); diff --git a/runtime/hydradx/src/benchmarking/route_executor.rs b/runtime/hydradx/src/benchmarking/route_executor.rs index 476f4e2a9..f880a74eb 100644 --- a/runtime/hydradx/src/benchmarking/route_executor.rs +++ b/runtime/hydradx/src/benchmarking/route_executor.rs @@ -154,7 +154,6 @@ runtime_benchmarks! { Router::disable_ed_handling_for_insufficient_assets(3, 0, trade); Router::disable_ed_handling_for_insufficient_assets(3, 1, trade); Router::disable_ed_handling_for_insufficient_assets(3, 2, trade); - >::kill(); } verify { diff --git a/runtime/hydradx/src/weights/pallet_route_executor.rs b/runtime/hydradx/src/weights/pallet_route_executor.rs index d853f214e..cb6b04c6a 100644 --- a/runtime/hydradx/src/weights/pallet_route_executor.rs +++ b/runtime/hydradx/src/weights/pallet_route_executor.rs @@ -19,7 +19,7 @@ //! Autogenerated weights for `pallet_route_executor` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2024-06-20, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-07-23, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` @@ -35,7 +35,7 @@ // --heap-pages=4096 // --template=scripts/pallet-weight-template.hbs // --pallet=pallet-route-executor -// --output=weights/router.rs +// --output=router.rs // --extrinsic=* #![cfg_attr(rustfmt, rustfmt_skip)] @@ -60,8 +60,8 @@ impl pallet_route_executor::WeightInfo for HydraWeight< // Proof Size summary in bytes: // Measured: `944` // Estimated: `3590` - // Minimum execution time: 14_113_000 picoseconds. - Weight::from_parts(14_402_000, 3590) + // Minimum execution time: 13_668_000 picoseconds. + Weight::from_parts(13_966_000, 3590) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -75,6 +75,8 @@ impl pallet_route_executor::WeightInfo for HydraWeight< /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Tokens::Locks` (r:1 w:1) /// Proof: `Tokens::Locks` (`max_values`: None, `max_size`: Some(1261), added: 3736, mode: `MaxEncodedLen`) + /// Storage: `Router::SkipEd` (r:1 w:1) + /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) /// Storage: `Duster::AccountBlacklist` (r:2 w:0) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) @@ -82,14 +84,14 @@ impl pallet_route_executor::WeightInfo for HydraWeight< /// The range of component `c` is `[0, 1]`. fn calculate_and_execute_sell_in_lbp(c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `3535` + // Measured: `3743` // Estimated: `13905` - // Minimum execution time: 354_159_000 picoseconds. - Weight::from_parts(358_572_573, 13905) - // Standard Error: 306_143 - .saturating_add(Weight::from_parts(70_834_738, 0).saturating_mul(c.into())) - .saturating_add(T::DbWeight::get().reads(16_u64)) - .saturating_add(T::DbWeight::get().writes(7_u64)) + // Minimum execution time: 350_386_000 picoseconds. + Weight::from_parts(354_293_683, 13905) + // Standard Error: 234_132 + .saturating_add(Weight::from_parts(74_076_628, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(17_u64)) + .saturating_add(T::DbWeight::get().writes(8_u64)) } /// Storage: `LBP::PoolData` (r:1 w:0) /// Proof: `LBP::PoolData` (`max_values`: None, `max_size`: Some(163), added: 2638, mode: `MaxEncodedLen`) @@ -101,6 +103,8 @@ impl pallet_route_executor::WeightInfo for HydraWeight< /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Tokens::Locks` (r:1 w:1) /// Proof: `Tokens::Locks` (`max_values`: None, `max_size`: Some(1261), added: 3736, mode: `MaxEncodedLen`) + /// Storage: `Router::SkipEd` (r:1 w:1) + /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) /// Storage: `Duster::AccountBlacklist` (r:2 w:0) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) @@ -109,17 +113,17 @@ impl pallet_route_executor::WeightInfo for HydraWeight< /// The range of component `b` is `[0, 1]`. fn calculate_and_execute_buy_in_lbp(c: u32, b: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1637 + b * (1923 ±0)` - // Estimated: `6156 + b * (7749 ±228_644_766_292_339_040)` - // Minimum execution time: 94_614_000 picoseconds. - Weight::from_parts(96_046_000, 6156) - // Standard Error: 876_130 - .saturating_add(Weight::from_parts(3_658_596, 0).saturating_mul(c.into())) - // Standard Error: 1_923_356 - .saturating_add(Weight::from_parts(272_645_114, 0).saturating_mul(b.into())) + // Measured: `1637 + b * (2131 ±0)` + // Estimated: `6156 + b * (7749 ±99_524_913_928_918_768)` + // Minimum execution time: 93_928_000 picoseconds. + Weight::from_parts(95_117_000, 6156) + // Standard Error: 840_538 + .saturating_add(Weight::from_parts(3_259_580, 0).saturating_mul(c.into())) + // Standard Error: 1_845_220 + .saturating_add(Weight::from_parts(269_928_748, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().reads((13_u64).saturating_mul(b.into()))) - .saturating_add(T::DbWeight::get().writes((7_u64).saturating_mul(b.into()))) + .saturating_add(T::DbWeight::get().reads((14_u64).saturating_mul(b.into()))) + .saturating_add(T::DbWeight::get().writes((8_u64).saturating_mul(b.into()))) .saturating_add(Weight::from_parts(0, 7749).saturating_mul(b.into())) } /// Storage: `AssetRegistry::Assets` (r:6 w:0) @@ -132,6 +136,8 @@ impl pallet_route_executor::WeightInfo for HydraWeight< /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `XYK::ShareToken` (r:6 w:0) /// Proof: `XYK::ShareToken` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + /// Storage: `Router::SkipEd` (r:1 w:0) + /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) /// Storage: `Duster::AccountBlacklist` (r:7 w:0) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::BannedAssets` (r:5 w:0) @@ -148,9 +154,9 @@ impl pallet_route_executor::WeightInfo for HydraWeight< // Proof Size summary in bytes: // Measured: `6426` // Estimated: `39735` - // Minimum execution time: 1_917_993_000 picoseconds. - Weight::from_parts(1_930_602_000, 39735) - .saturating_add(T::DbWeight::get().reads(55_u64)) + // Minimum execution time: 1_909_709_000 picoseconds. + Weight::from_parts(1_916_924_000, 39735) + .saturating_add(T::DbWeight::get().reads(56_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `Router::Routes` (r:0 w:1) @@ -159,8 +165,8 @@ impl pallet_route_executor::WeightInfo for HydraWeight< // Proof Size summary in bytes: // Measured: `1012` // Estimated: `0` - // Minimum execution time: 25_174_000 picoseconds. - Weight::from_parts(25_689_000, 0) + // Minimum execution time: 25_438_000 picoseconds. + Weight::from_parts(25_832_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `Router::Routes` (r:1 w:0) @@ -169,8 +175,8 @@ impl pallet_route_executor::WeightInfo for HydraWeight< // Proof Size summary in bytes: // Measured: `800` // Estimated: `3555` - // Minimum execution time: 7_562_000 picoseconds. - Weight::from_parts(7_748_000, 3555) + // Minimum execution time: 7_194_000 picoseconds. + Weight::from_parts(7_511_000, 3555) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// Storage: `LBP::PoolData` (r:1 w:0) @@ -183,8 +189,8 @@ impl pallet_route_executor::WeightInfo for HydraWeight< // Proof Size summary in bytes: // Measured: `1674` // Estimated: `6156` - // Minimum execution time: 36_086_000 picoseconds. - Weight::from_parts(36_646_000, 6156) + // Minimum execution time: 34_915_000 picoseconds. + Weight::from_parts(35_614_000, 6156) .saturating_add(T::DbWeight::get().reads(4_u64)) } } \ No newline at end of file From 21b78d459ae976f5a9a0eebfbaa38a6444130f99 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 23 Jul 2024 13:52:58 +0200 Subject: [PATCH 27/43] rebenchmark pallet executor --- .../src/weights/pallet_route_executor.rs | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/runtime/hydradx/src/weights/pallet_route_executor.rs b/runtime/hydradx/src/weights/pallet_route_executor.rs index cb6b04c6a..aac690ae3 100644 --- a/runtime/hydradx/src/weights/pallet_route_executor.rs +++ b/runtime/hydradx/src/weights/pallet_route_executor.rs @@ -60,8 +60,8 @@ impl pallet_route_executor::WeightInfo for HydraWeight< // Proof Size summary in bytes: // Measured: `944` // Estimated: `3590` - // Minimum execution time: 13_668_000 picoseconds. - Weight::from_parts(13_966_000, 3590) + // Minimum execution time: 13_912_000 picoseconds. + Weight::from_parts(14_238_000, 3590) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -86,10 +86,10 @@ impl pallet_route_executor::WeightInfo for HydraWeight< // Proof Size summary in bytes: // Measured: `3743` // Estimated: `13905` - // Minimum execution time: 350_386_000 picoseconds. - Weight::from_parts(354_293_683, 13905) - // Standard Error: 234_132 - .saturating_add(Weight::from_parts(74_076_628, 0).saturating_mul(c.into())) + // Minimum execution time: 351_691_000 picoseconds. + Weight::from_parts(354_925_213, 13905) + // Standard Error: 214_524 + .saturating_add(Weight::from_parts(70_325_474, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(17_u64)) .saturating_add(T::DbWeight::get().writes(8_u64)) } @@ -114,13 +114,13 @@ impl pallet_route_executor::WeightInfo for HydraWeight< fn calculate_and_execute_buy_in_lbp(c: u32, b: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `1637 + b * (2131 ±0)` - // Estimated: `6156 + b * (7749 ±99_524_913_928_918_768)` - // Minimum execution time: 93_928_000 picoseconds. - Weight::from_parts(95_117_000, 6156) - // Standard Error: 840_538 - .saturating_add(Weight::from_parts(3_259_580, 0).saturating_mul(c.into())) - // Standard Error: 1_845_220 - .saturating_add(Weight::from_parts(269_928_748, 0).saturating_mul(b.into())) + // Estimated: `6156 + b * (7749 ±251_795_645_551_580_832)` + // Minimum execution time: 93_322_000 picoseconds. + Weight::from_parts(94_136_000, 6156) + // Standard Error: 853_398 + .saturating_add(Weight::from_parts(3_382_286, 0).saturating_mul(c.into())) + // Standard Error: 1_873_452 + .saturating_add(Weight::from_parts(272_615_125, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().reads((14_u64).saturating_mul(b.into()))) .saturating_add(T::DbWeight::get().writes((8_u64).saturating_mul(b.into()))) @@ -154,8 +154,8 @@ impl pallet_route_executor::WeightInfo for HydraWeight< // Proof Size summary in bytes: // Measured: `6426` // Estimated: `39735` - // Minimum execution time: 1_909_709_000 picoseconds. - Weight::from_parts(1_916_924_000, 39735) + // Minimum execution time: 1_934_716_000 picoseconds. + Weight::from_parts(1_944_221_000, 39735) .saturating_add(T::DbWeight::get().reads(56_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -165,8 +165,8 @@ impl pallet_route_executor::WeightInfo for HydraWeight< // Proof Size summary in bytes: // Measured: `1012` // Estimated: `0` - // Minimum execution time: 25_438_000 picoseconds. - Weight::from_parts(25_832_000, 0) + // Minimum execution time: 25_462_000 picoseconds. + Weight::from_parts(25_776_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `Router::Routes` (r:1 w:0) @@ -175,8 +175,8 @@ impl pallet_route_executor::WeightInfo for HydraWeight< // Proof Size summary in bytes: // Measured: `800` // Estimated: `3555` - // Minimum execution time: 7_194_000 picoseconds. - Weight::from_parts(7_511_000, 3555) + // Minimum execution time: 7_564_000 picoseconds. + Weight::from_parts(7_813_000, 3555) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// Storage: `LBP::PoolData` (r:1 w:0) @@ -189,8 +189,8 @@ impl pallet_route_executor::WeightInfo for HydraWeight< // Proof Size summary in bytes: // Measured: `1674` // Estimated: `6156` - // Minimum execution time: 34_915_000 picoseconds. - Weight::from_parts(35_614_000, 6156) + // Minimum execution time: 35_268_000 picoseconds. + Weight::from_parts(35_625_000, 6156) .saturating_add(T::DbWeight::get().reads(4_u64)) } } \ No newline at end of file From 1bc17b6b1b5c06b521de7aeb6dbcf4a6dd914e73 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 23 Jul 2024 13:55:03 +0200 Subject: [PATCH 28/43] rebenchmark orml as transfer has been changed with skip ed --- runtime/hydradx/src/weights/orml_tokens.rs | 71 +++++++++++----------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/runtime/hydradx/src/weights/orml_tokens.rs b/runtime/hydradx/src/weights/orml_tokens.rs index 2c98146ec..33817844b 100644 --- a/runtime/hydradx/src/weights/orml_tokens.rs +++ b/runtime/hydradx/src/weights/orml_tokens.rs @@ -19,29 +19,24 @@ //! Autogenerated weights for `orml_tokens` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2024-05-23, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-07-23, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` // Executed Command: -// ./target/release/hydradx +// target/release/hydradx // benchmark // pallet +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled -// --pallet -// * -// --extrinsic -// * -// --heap-pages -// 4096 -// --steps -// 50 -// --repeat -// 20 +// --heap-pages=4096 // --template=scripts/pallet-weight-template.hbs -// --output -// weights/ +// --pallet=orml-tokens +// --output=orml.rs +// --extrinsic=* #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -57,6 +52,8 @@ pub struct WeightInfo(PhantomData); /// Weights for `orml_tokens` using the HydraDX node and recommended hardware. pub struct HydraWeight(PhantomData); impl orml_tokens::WeightInfo for HydraWeight { + /// Storage: `Router::SkipEd` (r:1 w:0) + /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) /// Storage: `Duster::AccountBlacklist` (r:1 w:0) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) @@ -81,17 +78,19 @@ impl orml_tokens::WeightInfo for HydraWeight { /// Proof: `AssetRegistry::ExistentialDepositCounter` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) fn transfer() -> Weight { // Proof Size summary in bytes: - // Measured: `3205` + // Measured: `3409` // Estimated: `11322` - // Minimum execution time: 232_476_000 picoseconds. - Weight::from_parts(233_663_000, 11322) - .saturating_add(T::DbWeight::get().reads(21_u64)) + // Minimum execution time: 237_730_000 picoseconds. + Weight::from_parts(239_119_000, 11322) + .saturating_add(T::DbWeight::get().reads(22_u64)) .saturating_add(T::DbWeight::get().writes(9_u64)) } /// Storage: `Tokens::Accounts` (r:4 w:4) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:3 w:3) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Router::SkipEd` (r:1 w:0) + /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) /// Storage: `Duster::AccountBlacklist` (r:1 w:0) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) @@ -112,13 +111,15 @@ impl orml_tokens::WeightInfo for HydraWeight { /// Proof: `AssetRegistry::ExistentialDepositCounter` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) fn transfer_all() -> Weight { // Proof Size summary in bytes: - // Measured: `3257` + // Measured: `3461` // Estimated: `11322` - // Minimum execution time: 236_104_000 picoseconds. - Weight::from_parts(237_656_000, 11322) - .saturating_add(T::DbWeight::get().reads(21_u64)) + // Minimum execution time: 241_359_000 picoseconds. + Weight::from_parts(242_887_000, 11322) + .saturating_add(T::DbWeight::get().reads(22_u64)) .saturating_add(T::DbWeight::get().writes(9_u64)) } + /// Storage: `Router::SkipEd` (r:1 w:0) + /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) /// Storage: `Duster::AccountBlacklist` (r:1 w:0) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) @@ -143,13 +144,15 @@ impl orml_tokens::WeightInfo for HydraWeight { /// Proof: `AssetRegistry::ExistentialDepositCounter` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) fn transfer_keep_alive() -> Weight { // Proof Size summary in bytes: - // Measured: `3255` + // Measured: `3459` // Estimated: `11322` - // Minimum execution time: 161_927_000 picoseconds. - Weight::from_parts(163_592_000, 11322) - .saturating_add(T::DbWeight::get().reads(21_u64)) + // Minimum execution time: 166_510_000 picoseconds. + Weight::from_parts(167_910_000, 11322) + .saturating_add(T::DbWeight::get().reads(22_u64)) .saturating_add(T::DbWeight::get().writes(8_u64)) } + /// Storage: `Router::SkipEd` (r:1 w:0) + /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) /// Storage: `Duster::AccountBlacklist` (r:1 w:0) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) @@ -174,11 +177,11 @@ impl orml_tokens::WeightInfo for HydraWeight { /// Proof: `AssetRegistry::ExistentialDepositCounter` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) fn force_transfer() -> Weight { // Proof Size summary in bytes: - // Measured: `3257` + // Measured: `3461` // Estimated: `11322` - // Minimum execution time: 232_442_000 picoseconds. - Weight::from_parts(233_954_000, 11322) - .saturating_add(T::DbWeight::get().reads(21_u64)) + // Minimum execution time: 238_730_000 picoseconds. + Weight::from_parts(240_390_000, 11322) + .saturating_add(T::DbWeight::get().reads(22_u64)) .saturating_add(T::DbWeight::get().writes(9_u64)) } /// Storage: `Tokens::Accounts` (r:1 w:1) @@ -195,10 +198,10 @@ impl orml_tokens::WeightInfo for HydraWeight { /// Proof: `MultiTransactionPayment::AcceptedCurrencies` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) fn set_balance() -> Weight { // Proof Size summary in bytes: - // Measured: `2213` + // Measured: `2209` // Estimated: `3593` - // Minimum execution time: 53_851_000 picoseconds. - Weight::from_parts(54_455_000, 3593) + // Minimum execution time: 55_376_000 picoseconds. + Weight::from_parts(56_132_000, 3593) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } From 8892361aedf3119c90fef3951c318c92d877f9df Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 23 Jul 2024 13:55:43 +0200 Subject: [PATCH 29/43] update lock --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f6be7d76e..37cad4a9d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4938,7 +4938,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "249.0.0" +version = "250.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", @@ -8936,7 +8936,7 @@ dependencies = [ [[package]] name = "pallet-route-executor" -version = "2.4.1" +version = "2.4.2" dependencies = [ "frame-benchmarking", "frame-support", From 0d0a93377681abbd552d35f0cd7a8593d7ae3a6f Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 23 Jul 2024 16:47:59 +0200 Subject: [PATCH 30/43] formatting --- runtime/hydradx/src/assets.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/runtime/hydradx/src/assets.rs b/runtime/hydradx/src/assets.rs index d7a3339c6..1ec3354d6 100644 --- a/runtime/hydradx/src/assets.rs +++ b/runtime/hydradx/src/assets.rs @@ -922,9 +922,10 @@ impl AmmTradeWeights> for RouterWeightInfo { } //We add the overweight for skipping ED handling if route has multiple trades and we have any insufficient asset - if route.len() > 1 && route.iter().any(|trade| { - !AssetRegistry::is_sufficient(trade.asset_in) || !AssetRegistry::is_sufficient(trade.asset_out) - }) { + if route.len() > 1 + && route.iter().any(|trade| { + !AssetRegistry::is_sufficient(trade.asset_in) || !AssetRegistry::is_sufficient(trade.asset_out) + }) { weight.saturating_accrue(Self::skip_ed_handling_overweight()); } @@ -969,9 +970,10 @@ impl AmmTradeWeights> for RouterWeightInfo { } //We add the overweight for skipping ED handling if we have any insufficient asset - if route.len() > 1 && route.iter().any(|trade| { - !AssetRegistry::is_sufficient(trade.asset_in) || !AssetRegistry::is_sufficient(trade.asset_out) - }) { + if route.len() > 1 + && route.iter().any(|trade| { + !AssetRegistry::is_sufficient(trade.asset_in) || !AssetRegistry::is_sufficient(trade.asset_out) + }) { weight.saturating_accrue(Self::skip_ed_handling_overweight()); } From d515d62bdf11f6691b2f5ef40cabfc5b9be572dc Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 23 Jul 2024 16:48:27 +0200 Subject: [PATCH 31/43] remove unused import --- runtime/hydradx/src/benchmarking/route_executor.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/hydradx/src/benchmarking/route_executor.rs b/runtime/hydradx/src/benchmarking/route_executor.rs index f880a74eb..b19ff97e9 100644 --- a/runtime/hydradx/src/benchmarking/route_executor.rs +++ b/runtime/hydradx/src/benchmarking/route_executor.rs @@ -19,7 +19,6 @@ use crate::{ AccountId, AssetId, Balance, Currencies, InsufficientEDinHDX, Router, Runtime, RuntimeOrigin, System, LBP, XYK, }; -use pallet_route_executor::SkipEd; use super::*; use crate::benchmarking::dca::{DAI, HDX}; From d6137d1993f97a8e94271bd6beb656460e3f96f5 Mon Sep 17 00:00:00 2001 From: dmoka Date: Wed, 24 Jul 2024 10:54:33 +0200 Subject: [PATCH 32/43] fix compilation error --- Cargo.lock | 2 +- pallets/route-executor/src/weights.rs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 2e52285cb..bd6fb8aad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8936,7 +8936,7 @@ dependencies = [ [[package]] name = "pallet-route-executor" -version = "2.5.0" +version = "2.5.1" dependencies = [ "frame-benchmarking", "frame-support", diff --git a/pallets/route-executor/src/weights.rs b/pallets/route-executor/src/weights.rs index 440ea3290..85236a8f6 100644 --- a/pallets/route-executor/src/weights.rs +++ b/pallets/route-executor/src/weights.rs @@ -180,6 +180,26 @@ impl WeightInfo for HydraWeight { .saturating_add(T::DbWeight::get().writes(1_u64)) } + /// Storage: `EmaOracle::Oracles` (r:2 w:0) + /// Proof: `EmaOracle::Oracles` (`max_values`: None, `max_size`: Some(177), added: 2652, mode: `MaxEncodedLen`) + fn get_oracle_price_for_xyk() -> Weight { + // Proof Size summary in bytes: + // Measured: `1452` + // Estimated: `6294` + // Minimum execution time: 26_531_000 picoseconds. + Weight::from_parts(27_010_000, 6294) + .saturating_add(T::DbWeight::get().reads(2_u64)) + } + /// Storage: `EmaOracle::Oracles` (r:4 w:0) + /// Proof: `EmaOracle::Oracles` (`max_values`: None, `max_size`: Some(177), added: 2652, mode: `MaxEncodedLen`) + fn get_oracle_price_for_omnipool() -> Weight { + // Proof Size summary in bytes: + // Measured: `1814` + // Estimated: `11598` + // Minimum execution time: 40_726_000 picoseconds. + Weight::from_parts(41_280_000, 11598) + .saturating_add(T::DbWeight::get().reads(4_u64)) + } /// Storage: `Router::Routes` (r:1 w:0) /// Proof: `Router::Routes` (`max_values`: None, `max_size`: Some(90), added: 2565, mode: `MaxEncodedLen`) fn get_route() -> Weight { From 66b6007f585a73b06d42efa0a64a7e5e690c5ece Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 25 Jul 2024 10:19:53 +0200 Subject: [PATCH 33/43] bump versions --- Cargo.lock | 4 ++-- integration-tests/Cargo.toml | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bd6fb8aad..a27db13ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4938,7 +4938,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "251.0.0" +version = "252.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", @@ -11929,7 +11929,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.23.1" +version = "1.23.2" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 83ee43671..15b8ee223 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.23.1" +version = "1.23.2" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index ec93adbf1..ca49513a1 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "251.0.0" +version = "252.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 be0f65d6b..8cd9d41c4 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -113,7 +113,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 251, + spec_version: 252, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From be062492f28c75188afd2467844e1c312653f4bf Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 25 Jul 2024 14:26:17 +0200 Subject: [PATCH 34/43] renaming --- pallets/route-executor/src/lib.rs | 21 ++++++++------------- pallets/route-executor/src/types.rs | 9 +++++++++ 2 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 pallets/route-executor/src/types.rs diff --git a/pallets/route-executor/src/lib.rs b/pallets/route-executor/src/lib.rs index b9990c3ec..0cbf3dd2b 100644 --- a/pallets/route-executor/src/lib.rs +++ b/pallets/route-executor/src/lib.rs @@ -47,6 +47,8 @@ use sp_std::{vec, vec::Vec}; mod tests; pub mod weights; +mod types; + pub use weights::WeightInfo; // Re-export pallet items so that they can be accessed from the crate namespace. @@ -54,13 +56,6 @@ pub use pallet::*; pub const MAX_NUMBER_OF_TRADES: u32 = 5; -#[derive(Debug, Encode, Decode, Copy, Clone, PartialEq, Eq, TypeInfo, MaxEncodedLen)] -pub enum EdHandling { - SkipEdLock, - SkipEdLockAndUnlock, - SkipEdUnlock, -} - #[frame_support::pallet] pub mod pallet { use super::*; @@ -176,7 +171,7 @@ pub mod pallet { ///Flag to indicate when to skip ED handling #[pallet::storage] #[pallet::getter(fn last_trade_position)] - pub type SkipEd = StorageValue<_, EdHandling, OptionQuery>; + pub type SkipEd = StorageValue<_, types::SkipEd, OptionQuery>; /// Storing routes for asset pairs #[pallet::storage] @@ -600,11 +595,11 @@ impl Pallet { { //We optimize to set the state for middle trades only once at the first middle trade, then we change no state till the last trade match trade_index { - 0 => SkipEd::::put(EdHandling::SkipEdLock), + 0 => SkipEd::::put(types::SkipEd::Lock), trade_index if trade_index.saturating_add(1) == route_length => { - SkipEd::::put(EdHandling::SkipEdUnlock) + SkipEd::::put(types::SkipEd::Unlock) } - 1 => SkipEd::::put(EdHandling::SkipEdLockAndUnlock), + 1 => SkipEd::::put(types::SkipEd::LockAndUnlock), _ => (), } } @@ -612,7 +607,7 @@ impl Pallet { pub fn skip_ed_lock() -> bool { if let Ok(v) = SkipEd::::try_get() { - return matches!(v, EdHandling::SkipEdLock | EdHandling::SkipEdLockAndUnlock); + return matches!(v, types::SkipEd::Lock | types::SkipEd::LockAndUnlock); } false @@ -620,7 +615,7 @@ impl Pallet { pub fn skip_ed_unlock() -> bool { if let Ok(v) = SkipEd::::try_get() { - return matches!(v, EdHandling::SkipEdUnlock | EdHandling::SkipEdLockAndUnlock); + return matches!(v, types::SkipEd::Unlock | types::SkipEd::LockAndUnlock); } false diff --git a/pallets/route-executor/src/types.rs b/pallets/route-executor/src/types.rs new file mode 100644 index 000000000..baaf14226 --- /dev/null +++ b/pallets/route-executor/src/types.rs @@ -0,0 +1,9 @@ +use codec::{Decode, Encode, MaxEncodedLen}; +use frame_support::pallet_prelude::TypeInfo; + +#[derive(Debug, Encode, Decode, Copy, Clone, PartialEq, Eq, TypeInfo, MaxEncodedLen)] +pub enum SkipEd { + Lock, + LockAndUnlock, + Unlock, +} \ No newline at end of file From 1504970783d33105f315b327e22893f1a810ddb5 Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 25 Jul 2024 14:30:20 +0200 Subject: [PATCH 35/43] formatting --- pallets/route-executor/src/lib.rs | 4 +--- pallets/route-executor/src/types.rs | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/pallets/route-executor/src/lib.rs b/pallets/route-executor/src/lib.rs index 0cbf3dd2b..cf078c736 100644 --- a/pallets/route-executor/src/lib.rs +++ b/pallets/route-executor/src/lib.rs @@ -596,9 +596,7 @@ impl Pallet { //We optimize to set the state for middle trades only once at the first middle trade, then we change no state till the last trade match trade_index { 0 => SkipEd::::put(types::SkipEd::Lock), - trade_index if trade_index.saturating_add(1) == route_length => { - SkipEd::::put(types::SkipEd::Unlock) - } + trade_index if trade_index.saturating_add(1) == route_length => SkipEd::::put(types::SkipEd::Unlock), 1 => SkipEd::::put(types::SkipEd::LockAndUnlock), _ => (), } diff --git a/pallets/route-executor/src/types.rs b/pallets/route-executor/src/types.rs index baaf14226..f77809c12 100644 --- a/pallets/route-executor/src/types.rs +++ b/pallets/route-executor/src/types.rs @@ -3,7 +3,7 @@ use frame_support::pallet_prelude::TypeInfo; #[derive(Debug, Encode, Decode, Copy, Clone, PartialEq, Eq, TypeInfo, MaxEncodedLen)] pub enum SkipEd { - Lock, - LockAndUnlock, - Unlock, -} \ No newline at end of file + Lock, + LockAndUnlock, + Unlock, +} From aed32f5be05bb431d85bbc26100b3ed27a4c67d1 Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 25 Jul 2024 14:34:05 +0200 Subject: [PATCH 36/43] fix naming --- integration-tests/src/router.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/src/router.rs b/integration-tests/src/router.rs index 1e2acf0e5..0cd0e6b3c 100644 --- a/integration-tests/src/router.rs +++ b/integration-tests/src/router.rs @@ -1291,7 +1291,7 @@ mod omnipool_router_tests { } #[test] - fn should_no_ed_charging_disabled_when_only_one_route_with_insufficient_assets() { + fn ed_charging_should_not_be_disabled_when_only_one_trade_with_insufficient_assets() { TestNet::reset(); Hydra::execute_with(|| { From 4ee8092731ceb69fe892b1ab535cbc3111194133 Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 25 Jul 2024 14:34:32 +0200 Subject: [PATCH 37/43] remove unnecessary mutliplication with one --- integration-tests/src/router.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/src/router.rs b/integration-tests/src/router.rs index 0cd0e6b3c..98fc2a278 100644 --- a/integration-tests/src/router.rs +++ b/integration-tests/src/router.rs @@ -1350,7 +1350,7 @@ mod omnipool_router_tests { assert_ok!(Currencies::deposit(insufficient_asset_1, &ALICE.into(), amount_to_sell,)); let ed = UNITS * 11 / 10; let extra_ed_charge = UNITS / 10; - assert_balance!(ALICE.into(), HDX, 1000 * UNITS - 1 * ed); + assert_balance!(ALICE.into(), HDX, 1000 * UNITS - ed); let amount_to_sell = amount_to_sell; assert_ok!(Router::sell( From 47c7dbdf9176288bb6acd6ff35fcfd39af423d22 Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 25 Jul 2024 14:46:45 +0200 Subject: [PATCH 38/43] use config for the insufficient ED in tests --- integration-tests/src/router.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/integration-tests/src/router.rs b/integration-tests/src/router.rs index 98fc2a278..72d72989c 100644 --- a/integration-tests/src/router.rs +++ b/integration-tests/src/router.rs @@ -37,7 +37,7 @@ use sp_runtime::{ }; use orml_traits::MultiCurrency; - +use hydradx_runtime::InsufficientEDinHDX; pub const LBP_SALE_START: BlockNumber = 10; pub const LBP_SALE_END: BlockNumber = 40; @@ -1174,7 +1174,7 @@ mod omnipool_router_tests { assert_ok!(Currencies::deposit(insufficient_asset1, &ALICE.into(), 1500 * UNITS,)); - let ed = UNITS * 11 / 10; + let ed = InsufficientEDinHDX::get(); assert_balance!(ALICE.into(), HDX, 1000 * UNITS - ed); let amount_to_sell = 20 * UNITS; @@ -1348,7 +1348,7 @@ mod omnipool_router_tests { //Act let amount_to_sell = 10 * UNITS; assert_ok!(Currencies::deposit(insufficient_asset_1, &ALICE.into(), amount_to_sell,)); - let ed = UNITS * 11 / 10; + let ed = InsufficientEDinHDX::get(); let extra_ed_charge = UNITS / 10; assert_balance!(ALICE.into(), HDX, 1000 * UNITS - ed); @@ -1478,7 +1478,7 @@ mod omnipool_router_tests { assert_ok!(Currencies::deposit(insufficient_asset1, &ALICE.into(), 1500 * UNITS,)); - let ed = UNITS * 11 / 10; + let ed = InsufficientEDinHDX::get(); assert_balance!(ALICE.into(), HDX, 1000 * UNITS - ed); let amount_to_buy = 20 * UNITS; From a1e752931e05e667a10e50f1df7f0cab0ce5d513 Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 25 Jul 2024 14:50:00 +0200 Subject: [PATCH 39/43] formatting --- integration-tests/src/router.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/src/router.rs b/integration-tests/src/router.rs index 72d72989c..d6eba45cc 100644 --- a/integration-tests/src/router.rs +++ b/integration-tests/src/router.rs @@ -36,8 +36,8 @@ use sp_runtime::{ DispatchError, DispatchResult, FixedU128, Permill, TransactionOutcome, }; -use orml_traits::MultiCurrency; use hydradx_runtime::InsufficientEDinHDX; +use orml_traits::MultiCurrency; pub const LBP_SALE_START: BlockNumber = 10; pub const LBP_SALE_END: BlockNumber = 40; From 341e1285bf95520f9dbefb1e2aec9bc045b0ca6c Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 25 Jul 2024 15:17:39 +0200 Subject: [PATCH 40/43] rebenchmark on ref machine --- pallets/route-executor/src/weights.rs | 163 +++++++++--------- .../src/weights/pallet_route_executor.rs | 54 +++--- 2 files changed, 109 insertions(+), 108 deletions(-) diff --git a/pallets/route-executor/src/weights.rs b/pallets/route-executor/src/weights.rs index 85236a8f6..653099c85 100644 --- a/pallets/route-executor/src/weights.rs +++ b/pallets/route-executor/src/weights.rs @@ -19,9 +19,9 @@ //! Autogenerated weights for `pallet_route_executor` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2024-06-20, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-07-23, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `dmoka-msi-pc`, CPU: `AMD Ryzen 9 5900X 12-Core Processor` +//! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` // Executed Command: @@ -70,8 +70,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `944` // Estimated: `3590` - // Minimum execution time: 13_600_000 picoseconds. - Weight::from_parts(13_900_000, 3590) + // Minimum execution time: 13_700_000 picoseconds. + Weight::from_parts(13_874_000, 3590) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -85,7 +85,7 @@ impl WeightInfo for HydraWeight { /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Tokens::Locks` (r:1 w:1) /// Proof: `Tokens::Locks` (`max_values`: None, `max_size`: Some(1261), added: 3736, mode: `MaxEncodedLen`) - /// Storage: `Router::SkipEd` (r:1 w:0) + /// Storage: `Router::SkipEd` (r:1 w:1) /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) /// Storage: `Duster::AccountBlacklist` (r:2 w:0) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) @@ -96,12 +96,12 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `3743` // Estimated: `13905` - // Minimum execution time: 278_588_000 picoseconds. - Weight::from_parts(284_606_595, 13905) - // Standard Error: 341_686 - .saturating_add(Weight::from_parts(34_052_591, 0).saturating_mul(c.into())) + // Minimum execution time: 352_057_000 picoseconds. + Weight::from_parts(358_601_823, 13905) + // Standard Error: 319_985 + .saturating_add(Weight::from_parts(70_948_801, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(17_u64)) - .saturating_add(T::DbWeight::get().writes(7_u64)) + .saturating_add(T::DbWeight::get().writes(8_u64)) } /// Storage: `LBP::PoolData` (r:1 w:0) /// Proof: `LBP::PoolData` (`max_values`: None, `max_size`: Some(163), added: 2638, mode: `MaxEncodedLen`) @@ -113,7 +113,7 @@ impl WeightInfo for HydraWeight { /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Tokens::Locks` (r:1 w:1) /// Proof: `Tokens::Locks` (`max_values`: None, `max_size`: Some(1261), added: 3736, mode: `MaxEncodedLen`) - /// Storage: `Router::SkipEd` (r:1 w:0) + /// Storage: `Router::SkipEd` (r:1 w:1) /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) /// Storage: `Duster::AccountBlacklist` (r:2 w:0) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) @@ -124,26 +124,28 @@ impl WeightInfo for HydraWeight { fn calculate_and_execute_buy_in_lbp(c: u32, b: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `1637 + b * (2131 ±0)` - // Estimated: `6156 + b * (7749 ±0)` - // Minimum execution time: 53_520_000 picoseconds. - Weight::from_parts(54_339_000, 6156) - // Standard Error: 418_984 - .saturating_add(Weight::from_parts(1_659_710, 0).saturating_mul(c.into())) - // Standard Error: 919_791 - .saturating_add(Weight::from_parts(236_379_793, 0).saturating_mul(b.into())) + // Estimated: `6156 + b * (7749 ±245_709_589_663_843_264)` + // Minimum execution time: 94_752_000 picoseconds. + Weight::from_parts(96_589_000, 6156) + // Standard Error: 840_786 + .saturating_add(Weight::from_parts(3_341_044, 0).saturating_mul(c.into())) + // Standard Error: 1_845_765 + .saturating_add(Weight::from_parts(271_881_978, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().reads((14_u64).saturating_mul(b.into()))) - .saturating_add(T::DbWeight::get().writes((7_u64).saturating_mul(b.into()))) + .saturating_add(T::DbWeight::get().writes((8_u64).saturating_mul(b.into()))) .saturating_add(Weight::from_parts(0, 7749).saturating_mul(b.into())) } - /// Storage: `AssetRegistry::Assets` (r:6 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `EmaOracle::Oracles` (r:2 w:0) + /// Proof: `EmaOracle::Oracles` (`max_values`: None, `max_size`: Some(177), added: 2652, mode: `MaxEncodedLen`) /// Storage: `Router::Routes` (r:1 w:1) /// Proof: `Router::Routes` (`max_values`: None, `max_size`: Some(90), added: 2565, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:7 w:0) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `Tokens::Accounts` (r:15 w:0) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:6 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `XYK::ShareToken` (r:6 w:0) /// Proof: `XYK::ShareToken` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) /// Storage: `Router::SkipEd` (r:1 w:0) @@ -162,11 +164,11 @@ impl WeightInfo for HydraWeight { /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) fn set_route_for_xyk() -> Weight { // Proof Size summary in bytes: - // Measured: `6426` + // Measured: `7004` // Estimated: `39735` - // Minimum execution time: 2_085_799_000 picoseconds. - Weight::from_parts(2_111_539_000, 39735) - .saturating_add(T::DbWeight::get().reads(56_u64)) + // Minimum execution time: 1_946_884_000 picoseconds. + Weight::from_parts(1_957_705_000, 39735) + .saturating_add(T::DbWeight::get().reads(58_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `Router::Routes` (r:0 w:1) @@ -175,19 +177,28 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `1012` // Estimated: `0` - // Minimum execution time: 23_300_000 picoseconds. - Weight::from_parts(24_050_000, 0) + // Minimum execution time: 25_748_000 picoseconds. + Weight::from_parts(26_215_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } - + /// Storage: `Router::Routes` (r:1 w:0) + /// Proof: `Router::Routes` (`max_values`: None, `max_size`: Some(90), added: 2565, mode: `MaxEncodedLen`) + fn get_route() -> Weight { + // Proof Size summary in bytes: + // Measured: `800` + // Estimated: `3555` + // Minimum execution time: 7_522_000 picoseconds. + Weight::from_parts(7_689_000, 3555) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } /// Storage: `EmaOracle::Oracles` (r:2 w:0) /// Proof: `EmaOracle::Oracles` (`max_values`: None, `max_size`: Some(177), added: 2652, mode: `MaxEncodedLen`) fn get_oracle_price_for_xyk() -> Weight { // Proof Size summary in bytes: // Measured: `1452` // Estimated: `6294` - // Minimum execution time: 26_531_000 picoseconds. - Weight::from_parts(27_010_000, 6294) + // Minimum execution time: 26_571_000 picoseconds. + Weight::from_parts(27_038_000, 6294) .saturating_add(T::DbWeight::get().reads(2_u64)) } /// Storage: `EmaOracle::Oracles` (r:4 w:0) @@ -196,20 +207,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `1814` // Estimated: `11598` - // Minimum execution time: 40_726_000 picoseconds. - Weight::from_parts(41_280_000, 11598) + // Minimum execution time: 40_728_000 picoseconds. + Weight::from_parts(41_338_000, 11598) .saturating_add(T::DbWeight::get().reads(4_u64)) } - /// Storage: `Router::Routes` (r:1 w:0) - /// Proof: `Router::Routes` (`max_values`: None, `max_size`: Some(90), added: 2565, mode: `MaxEncodedLen`) - fn get_route() -> Weight { - // Proof Size summary in bytes: - // Measured: `800` - // Estimated: `3555` - // Minimum execution time: 7_562_000 picoseconds. - Weight::from_parts(7_748_000, 3555) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - } /// Storage: `LBP::PoolData` (r:1 w:0) /// Proof: `LBP::PoolData` (`max_values`: None, `max_size`: Some(163), added: 2638, mode: `MaxEncodedLen`) /// Storage: `Tokens::Locks` (r:1 w:0) @@ -220,9 +221,9 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `1674` // Estimated: `6156` - // Minimum execution time: 36_086_000 picoseconds. - Weight::from_parts(36_646_000, 6156) - .saturating_add(RocksDbWeight::get().reads(4_u64)) + // Minimum execution time: 35_793_000 picoseconds. + Weight::from_parts(36_285_000, 6156) + .saturating_add(T::DbWeight::get().reads(4_u64)) } } @@ -236,8 +237,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `944` // Estimated: `3590` - // Minimum execution time: 13_600_000 picoseconds. - Weight::from_parts(13_900_000, 3590) + // Minimum execution time: 13_700_000 picoseconds. + Weight::from_parts(13_874_000, 3590) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -251,7 +252,7 @@ impl WeightInfo for () { /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Tokens::Locks` (r:1 w:1) /// Proof: `Tokens::Locks` (`max_values`: None, `max_size`: Some(1261), added: 3736, mode: `MaxEncodedLen`) - /// Storage: `Router::SkipEd` (r:1 w:0) + /// Storage: `Router::SkipEd` (r:1 w:1) /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) /// Storage: `Duster::AccountBlacklist` (r:2 w:0) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) @@ -262,12 +263,12 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `3743` // Estimated: `13905` - // Minimum execution time: 278_588_000 picoseconds. - Weight::from_parts(284_606_595, 13905) - // Standard Error: 341_686 - .saturating_add(Weight::from_parts(34_052_591, 0).saturating_mul(c.into())) + // Minimum execution time: 352_057_000 picoseconds. + Weight::from_parts(358_601_823, 13905) + // Standard Error: 319_985 + .saturating_add(Weight::from_parts(70_948_801, 0).saturating_mul(c.into())) .saturating_add(RocksDbWeight::get().reads(17_u64)) - .saturating_add(RocksDbWeight::get().writes(7_u64)) + .saturating_add(RocksDbWeight::get().writes(8_u64)) } /// Storage: `LBP::PoolData` (r:1 w:0) /// Proof: `LBP::PoolData` (`max_values`: None, `max_size`: Some(163), added: 2638, mode: `MaxEncodedLen`) @@ -279,7 +280,7 @@ impl WeightInfo for () { /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Tokens::Locks` (r:1 w:1) /// Proof: `Tokens::Locks` (`max_values`: None, `max_size`: Some(1261), added: 3736, mode: `MaxEncodedLen`) - /// Storage: `Router::SkipEd` (r:1 w:0) + /// Storage: `Router::SkipEd` (r:1 w:1) /// Proof: `Router::SkipEd` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) /// Storage: `Duster::AccountBlacklist` (r:2 w:0) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) @@ -289,27 +290,29 @@ impl WeightInfo for () { /// The range of component `b` is `[0, 1]`. fn calculate_and_execute_buy_in_lbp(c: u32, b: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1637 + b * (1923 ±0)` - // Estimated: `6156 + b * (7749 ±228_644_766_292_339_040)` - // Minimum execution time: 94_614_000 picoseconds. - Weight::from_parts(96_046_000, 6156) - // Standard Error: 876_130 - .saturating_add(Weight::from_parts(3_658_596, 0).saturating_mul(c.into())) - // Standard Error: 1_923_356 - .saturating_add(Weight::from_parts(272_645_114, 0).saturating_mul(b.into())) + // Measured: `1637 + b * (2131 ±0)` + // Estimated: `6156 + b * (7749 ±245_709_589_663_843_264)` + // Minimum execution time: 94_752_000 picoseconds. + Weight::from_parts(96_589_000, 6156) + // Standard Error: 840_786 + .saturating_add(Weight::from_parts(3_341_044, 0).saturating_mul(c.into())) + // Standard Error: 1_845_765 + .saturating_add(Weight::from_parts(271_881_978, 0).saturating_mul(b.into())) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().reads((14_u64).saturating_mul(b.into()))) - .saturating_add(RocksDbWeight::get().writes((7_u64).saturating_mul(b.into()))) + .saturating_add(RocksDbWeight::get().writes((8_u64).saturating_mul(b.into()))) .saturating_add(Weight::from_parts(0, 7749).saturating_mul(b.into())) } - /// Storage: `AssetRegistry::Assets` (r:6 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `EmaOracle::Oracles` (r:2 w:0) + /// Proof: `EmaOracle::Oracles` (`max_values`: None, `max_size`: Some(177), added: 2652, mode: `MaxEncodedLen`) /// Storage: `Router::Routes` (r:1 w:1) /// Proof: `Router::Routes` (`max_values`: None, `max_size`: Some(90), added: 2565, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:7 w:0) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `Tokens::Accounts` (r:15 w:0) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:6 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `XYK::ShareToken` (r:6 w:0) /// Proof: `XYK::ShareToken` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) /// Storage: `Router::SkipEd` (r:1 w:0) @@ -328,11 +331,11 @@ impl WeightInfo for () { /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) fn set_route_for_xyk() -> Weight { // Proof Size summary in bytes: - // Measured: `6426` + // Measured: `7004` // Estimated: `39735` - // Minimum execution time: 2_085_799_000 picoseconds. - Weight::from_parts(2_111_539_000, 39735) - .saturating_add(RocksDbWeight::get().reads(56_u64)) + // Minimum execution time: 1_946_884_000 picoseconds. + Weight::from_parts(1_957_705_000, 39735) + .saturating_add(RocksDbWeight::get().reads(58_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: `Router::Routes` (r:0 w:1) @@ -341,8 +344,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1012` // Estimated: `0` - // Minimum execution time: 25_174_000 picoseconds. - Weight::from_parts(25_689_000, 0) + // Minimum execution time: 25_748_000 picoseconds. + Weight::from_parts(26_215_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: `Router::Routes` (r:1 w:0) @@ -351,19 +354,18 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `800` // Estimated: `3555` - // Minimum execution time: 7_562_000 picoseconds. - Weight::from_parts(7_748_000, 3555) + // Minimum execution time: 7_522_000 picoseconds. + Weight::from_parts(7_689_000, 3555) .saturating_add(RocksDbWeight::get().reads(1_u64)) } - /// Storage: `EmaOracle::Oracles` (r:2 w:0) /// Proof: `EmaOracle::Oracles` (`max_values`: None, `max_size`: Some(177), added: 2652, mode: `MaxEncodedLen`) fn get_oracle_price_for_xyk() -> Weight { // Proof Size summary in bytes: // Measured: `1452` // Estimated: `6294` - // Minimum execution time: 21_820_000 picoseconds. - Weight::from_parts(22_320_000, 6294) + // Minimum execution time: 26_571_000 picoseconds. + Weight::from_parts(27_038_000, 6294) .saturating_add(RocksDbWeight::get().reads(2_u64)) } /// Storage: `EmaOracle::Oracles` (r:4 w:0) @@ -372,11 +374,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1814` // Estimated: `11598` - // Minimum execution time: 35_720_000 picoseconds. - Weight::from_parts(36_110_000, 11598) + // Minimum execution time: 40_728_000 picoseconds. + Weight::from_parts(41_338_000, 11598) .saturating_add(RocksDbWeight::get().reads(4_u64)) } - /// Storage: `LBP::PoolData` (r:1 w:0) /// Proof: `LBP::PoolData` (`max_values`: None, `max_size`: Some(163), added: 2638, mode: `MaxEncodedLen`) /// Storage: `Tokens::Locks` (r:1 w:0) @@ -387,8 +388,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1674` // Estimated: `6156` - // Minimum execution time: 36_086_000 picoseconds. - Weight::from_parts(36_646_000, 6156) + // Minimum execution time: 35_793_000 picoseconds. + Weight::from_parts(36_285_000, 6156) .saturating_add(RocksDbWeight::get().reads(4_u64)) } } diff --git a/runtime/hydradx/src/weights/pallet_route_executor.rs b/runtime/hydradx/src/weights/pallet_route_executor.rs index 9bcf5b2ff..0d8ff8b0d 100644 --- a/runtime/hydradx/src/weights/pallet_route_executor.rs +++ b/runtime/hydradx/src/weights/pallet_route_executor.rs @@ -19,7 +19,7 @@ //! Autogenerated weights for `pallet_route_executor` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2024-07-23, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-07-25, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` @@ -60,8 +60,8 @@ impl pallet_route_executor::WeightInfo for HydraWeight< // Proof Size summary in bytes: // Measured: `944` // Estimated: `3590` - // Minimum execution time: 13_912_000 picoseconds. - Weight::from_parts(14_238_000, 3590) + // Minimum execution time: 13_700_000 picoseconds. + Weight::from_parts(13_874_000, 3590) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -86,10 +86,10 @@ impl pallet_route_executor::WeightInfo for HydraWeight< // Proof Size summary in bytes: // Measured: `3743` // Estimated: `13905` - // Minimum execution time: 351_691_000 picoseconds. - Weight::from_parts(354_925_213, 13905) - // Standard Error: 214_524 - .saturating_add(Weight::from_parts(70_325_474, 0).saturating_mul(c.into())) + // Minimum execution time: 352_057_000 picoseconds. + Weight::from_parts(358_601_823, 13905) + // Standard Error: 319_985 + .saturating_add(Weight::from_parts(70_948_801, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(17_u64)) .saturating_add(T::DbWeight::get().writes(8_u64)) } @@ -114,13 +114,13 @@ impl pallet_route_executor::WeightInfo for HydraWeight< fn calculate_and_execute_buy_in_lbp(c: u32, b: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `1637 + b * (2131 ±0)` - // Estimated: `6156 + b * (7749 ±251_795_645_551_580_832)` - // Minimum execution time: 93_322_000 picoseconds. - Weight::from_parts(94_136_000, 6156) - // Standard Error: 853_398 - .saturating_add(Weight::from_parts(3_382_286, 0).saturating_mul(c.into())) - // Standard Error: 1_873_452 - .saturating_add(Weight::from_parts(272_615_125, 0).saturating_mul(b.into())) + // Estimated: `6156 + b * (7749 ±245_709_589_663_843_264)` + // Minimum execution time: 94_752_000 picoseconds. + Weight::from_parts(96_589_000, 6156) + // Standard Error: 840_786 + .saturating_add(Weight::from_parts(3_341_044, 0).saturating_mul(c.into())) + // Standard Error: 1_845_765 + .saturating_add(Weight::from_parts(271_881_978, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().reads((14_u64).saturating_mul(b.into()))) .saturating_add(T::DbWeight::get().writes((8_u64).saturating_mul(b.into()))) @@ -156,9 +156,9 @@ impl pallet_route_executor::WeightInfo for HydraWeight< // Proof Size summary in bytes: // Measured: `7004` // Estimated: `39735` - // Minimum execution time: 1_880_149_000 picoseconds. - Weight::from_parts(1_889_973_000, 39735) - .saturating_add(T::DbWeight::get().reads(57_u64)) + // Minimum execution time: 1_946_884_000 picoseconds. + Weight::from_parts(1_957_705_000, 39735) + .saturating_add(T::DbWeight::get().reads(58_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `Router::Routes` (r:0 w:1) @@ -167,8 +167,8 @@ impl pallet_route_executor::WeightInfo for HydraWeight< // Proof Size summary in bytes: // Measured: `1012` // Estimated: `0` - // Minimum execution time: 25_566_000 picoseconds. - Weight::from_parts(26_013_000, 0) + // Minimum execution time: 25_748_000 picoseconds. + Weight::from_parts(26_215_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `Router::Routes` (r:1 w:0) @@ -177,8 +177,8 @@ impl pallet_route_executor::WeightInfo for HydraWeight< // Proof Size summary in bytes: // Measured: `800` // Estimated: `3555` - // Minimum execution time: 7_753_000 picoseconds. - Weight::from_parts(7_998_000, 3555) + // Minimum execution time: 7_522_000 picoseconds. + Weight::from_parts(7_689_000, 3555) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// Storage: `EmaOracle::Oracles` (r:2 w:0) @@ -187,8 +187,8 @@ impl pallet_route_executor::WeightInfo for HydraWeight< // Proof Size summary in bytes: // Measured: `1452` // Estimated: `6294` - // Minimum execution time: 26_531_000 picoseconds. - Weight::from_parts(27_010_000, 6294) + // Minimum execution time: 26_571_000 picoseconds. + Weight::from_parts(27_038_000, 6294) .saturating_add(T::DbWeight::get().reads(2_u64)) } /// Storage: `EmaOracle::Oracles` (r:4 w:0) @@ -197,8 +197,8 @@ impl pallet_route_executor::WeightInfo for HydraWeight< // Proof Size summary in bytes: // Measured: `1814` // Estimated: `11598` - // Minimum execution time: 40_726_000 picoseconds. - Weight::from_parts(41_280_000, 11598) + // Minimum execution time: 40_728_000 picoseconds. + Weight::from_parts(41_338_000, 11598) .saturating_add(T::DbWeight::get().reads(4_u64)) } /// Storage: `LBP::PoolData` (r:1 w:0) @@ -211,8 +211,8 @@ impl pallet_route_executor::WeightInfo for HydraWeight< // Proof Size summary in bytes: // Measured: `1674` // Estimated: `6156` - // Minimum execution time: 35_350_000 picoseconds. - Weight::from_parts(35_956_000, 6156) + // Minimum execution time: 35_793_000 picoseconds. + Weight::from_parts(36_285_000, 6156) .saturating_add(T::DbWeight::get().reads(4_u64)) } } \ No newline at end of file From 177481b388755b110d09d993dfad2cee58f53bf0 Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 25 Jul 2024 18:47:10 +0200 Subject: [PATCH 41/43] bump runtime version --- Cargo.lock | 6 +++--- runtime/hydradx/Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aa503ad1f..1770dc11b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4938,7 +4938,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "253.0.0" +version = "254.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", @@ -8936,7 +8936,7 @@ dependencies = [ [[package]] name = "pallet-route-executor" -version = "2.5.0" +version = "2.5.1" dependencies = [ "frame-benchmarking", "frame-support", @@ -11929,7 +11929,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.23.1" +version = "1.23.2" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index ec93adbf1..0b38f82bf 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "251.0.0" +version = "254.0.0" authors = ["GalacticCouncil"] edition = "2021" license = "Apache 2.0" From 4d767b41b2f09aaa5c4f299442417e20933b1259 Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 1 Aug 2024 12:56:03 +0200 Subject: [PATCH 42/43] bump runtime version --- 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 d2529b0e0..637a6669b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4938,7 +4938,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "254.0.0" +version = "255.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index 0b38f82bf..60e6e1458 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "254.0.0" +version = "255.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 f7d4e1b7e..e80d28be2 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -113,7 +113,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 254, + spec_version: 255, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 8c752705878d10e5932337a8c60346427ce9f732 Mon Sep 17 00:00:00 2001 From: dmoka Date: Fri, 9 Aug 2024 11:09:19 +0200 Subject: [PATCH 43/43] bump runtime --- 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 fb9e94cf3..12035b11c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4938,7 +4938,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "255.0.0" +version = "256.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index 60e6e1458..285bfed06 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "255.0.0" +version = "256.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 e80d28be2..8e5c13482 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -113,7 +113,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 255, + spec_version: 256, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1,