From ed0cb7ada47b9920e041d80eca35260447ea4481 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Tue, 5 Mar 2024 16:24:41 +0100 Subject: [PATCH 01/13] manual_oracle_activation --- Cargo.lock | 1 + integration-tests/src/oracle.rs | 54 ++++++ pallets/dca/src/tests/mock.rs | 3 +- pallets/ema-oracle/Cargo.toml | 1 + pallets/ema-oracle/src/benchmarking.rs | 49 +++++- pallets/ema-oracle/src/lib.rs | 66 ++++++- .../src/tests/add_and_remove_oracle.rs | 161 ++++++++++++++++++ pallets/ema-oracle/src/tests/mock.rs | 11 +- pallets/ema-oracle/src/tests/mod.rs | 5 +- pallets/ema-oracle/src/weights.rs | 14 ++ .../src/tests/mock.rs | 3 +- runtime/hydradx/src/assets.rs | 3 +- runtime/hydradx/src/weights/ema_oracle.rs | 6 + 13 files changed, 363 insertions(+), 14 deletions(-) create mode 100644 pallets/ema-oracle/src/tests/add_and_remove_oracle.rs diff --git a/Cargo.lock b/Cargo.lock index 147584418..d3a041131 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7622,6 +7622,7 @@ dependencies = [ "sp-io", "sp-runtime", "sp-std", + "test-utils", ] [[package]] diff --git a/integration-tests/src/oracle.rs b/integration-tests/src/oracle.rs index 860c4f0f3..08238a1c2 100644 --- a/integration-tests/src/oracle.rs +++ b/integration-tests/src/oracle.rs @@ -192,3 +192,57 @@ fn xyk_trades_with_insufficient_asset_are_not_tracked_by_oracle() { } }); } + +#[test] +fn xyk_trades_with_insufficient_asset_are_tracked_by_oracle_when_asset_is_whitelisted() { + TestNet::reset(); + + Hydra::execute_with(|| { + // arrange + hydradx_run_to_next_block(); + + assert_ok!(hydradx_runtime::Tokens::mint_into( + INSUFFICIENT_ASSET, + &ALICE.into(), + 200 * UNITS, + )); + + assert_ok!(hydradx_runtime::XYK::create_pool( + RuntimeOrigin::signed(ALICE.into()), + HDX, + 100 * UNITS, + INSUFFICIENT_ASSET, + 100 * UNITS, + )); + + assert_ok!(EmaOracle::add_oracle( + RuntimeOrigin::root(), + XYK_SOURCE, + (HDX, INSUFFICIENT_ASSET) + )); + + assert_ok!(hydradx_runtime::XYK::buy( + RuntimeOrigin::signed(ALICE.into()), + HDX, + INSUFFICIENT_ASSET, + 2 * UNITS, + 200 * UNITS, + false, + )); + + // act + // will store the data received in the sell as oracle values + hydradx_run_to_next_block(); + + // assert + for supported_period in SUPPORTED_PERIODS { + assert!(EmaOracle::get_price(HDX, INSUFFICIENT_ASSET, *supported_period, XYK_SOURCE).is_ok(),); + } + for unsupported_period in UNSUPPORTED_PERIODS { + assert_eq!( + EmaOracle::get_price(HDX, INSUFFICIENT_ASSET, *unsupported_period, XYK_SOURCE), + Err(OracleError::NotPresent) + ); + } + }); +} diff --git a/pallets/dca/src/tests/mock.rs b/pallets/dca/src/tests/mock.rs index b412d1644..73fd4bc0d 100644 --- a/pallets/dca/src/tests/mock.rs +++ b/pallets/dca/src/tests/mock.rs @@ -146,13 +146,14 @@ parameter_types! { impl pallet_ema_oracle::Config for Test { type RuntimeEvent = RuntimeEvent; - type WeightInfo = (); + type AuthorityOrigin = EnsureRoot; type BlockNumberProvider = MockBlockNumberProvider; type SupportedPeriods = SupportedPeriods; type OracleFilter = Everything; type MaxUniqueEntries = ConstU32<20>; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = (); + type WeightInfo = (); } impl BlockNumberProvider for MockBlockNumberProvider { diff --git a/pallets/ema-oracle/Cargo.toml b/pallets/ema-oracle/Cargo.toml index c00b39c92..3a67ec480 100644 --- a/pallets/ema-oracle/Cargo.toml +++ b/pallets/ema-oracle/Cargo.toml @@ -35,6 +35,7 @@ pretty_assertions = "1.3.0" proptest = "1.0.0" rug = { version = "1.17.0", features = ["num-traits"] } sp-io = { workspace = true } +test-utils = { workspace = true } [features] default = ['std'] diff --git a/pallets/ema-oracle/src/benchmarking.rs b/pallets/ema-oracle/src/benchmarking.rs index 040884ac3..4fc6815a6 100644 --- a/pallets/ema-oracle/src/benchmarking.rs +++ b/pallets/ema-oracle/src/benchmarking.rs @@ -23,7 +23,7 @@ pub const HDX: AssetId = 1_000; pub const DOT: AssetId = 2_000; use frame_benchmarking::benchmarks; -use frame_support::{assert_ok, traits::Hooks}; +use frame_support::{assert_ok, dispatch::RawOrigin, traits::Hooks}; #[cfg(test)] use pretty_assertions::assert_eq; @@ -33,7 +33,36 @@ use crate::Pallet as EmaOracle; /// Default oracle source. const SOURCE: Source = *b"dummysrc"; +fn fill_whitelist_storage(n: u32) { + for i in 0..n { + assert_ok!(EmaOracle::::add_oracle(RawOrigin::Root.into(), SOURCE, (HDX, i))); + } +} benchmarks! { + add_oracle { + let max_entries = <::MaxUniqueEntries as Get>::get(); + fill_whitelist_storage::(max_entries - 1); + + assert_eq!(WhitelistedAssets::::get().len(), (max_entries - 1) as usize); + + }: _(RawOrigin::Root, SOURCE, (HDX, DOT)) + verify { + assert!(WhitelistedAssets::::get().contains(&(SOURCE, (HDX, DOT)))); + } + + remove_oracle { + let max_entries = <::MaxUniqueEntries as Get>::get(); + fill_whitelist_storage::(max_entries - 1); + + assert_ok!(EmaOracle::::add_oracle(RawOrigin::Root.into(), SOURCE, (HDX, DOT))); + + assert_eq!(WhitelistedAssets::::get().len(), max_entries as usize); + + }: _(RawOrigin::Root, SOURCE, (HDX, DOT)) + verify { + assert!(!WhitelistedAssets::::get().contains(&(SOURCE, (HDX, DOT)))); + } + on_finalize_no_entry { let block_num: u32 = 5; }: { EmaOracle::::on_finalize(block_num.into()); } @@ -42,6 +71,9 @@ benchmarks! { #[extra] on_finalize_insert_one_token { + let max_entries = <::MaxUniqueEntries as Get>::get(); + fill_whitelist_storage::(max_entries); + let block_num: BlockNumberFor = 5u32.into(); let prev_block = block_num.saturating_sub(One::one()); @@ -78,6 +110,9 @@ benchmarks! { #[extra] on_finalize_update_one_token { + let max_entries = <::MaxUniqueEntries as Get>::get(); + fill_whitelist_storage::(max_entries); + let initial_data_block: BlockNumberFor = 5u32.into(); // higher update time difference might make exponentiation more expensive let block_num = initial_data_block.saturating_add(1_000_000u32.into()); @@ -119,6 +154,9 @@ benchmarks! { on_finalize_multiple_tokens { let b in 1 .. (T::MaxUniqueEntries::get() - 1); + let max_entries = <::MaxUniqueEntries as Get>::get(); + fill_whitelist_storage::(max_entries); + let initial_data_block: BlockNumberFor = 5u32.into(); let block_num = initial_data_block.saturating_add(1_000_000u32.into()); @@ -167,6 +205,9 @@ benchmarks! { on_trade_multiple_tokens { let b in 1 .. (T::MaxUniqueEntries::get() - 1); + let max_entries = <::MaxUniqueEntries as Get>::get(); + fill_whitelist_storage::(max_entries); + let initial_data_block: BlockNumberFor = 5u32.into(); let block_num = initial_data_block.saturating_add(1_000_000u32.into()); @@ -227,6 +268,9 @@ benchmarks! { on_liquidity_changed_multiple_tokens { let b in 1 .. (T::MaxUniqueEntries::get() - 1); + let max_entries = <::MaxUniqueEntries as Get>::get(); + fill_whitelist_storage::(max_entries); + let initial_data_block: BlockNumberFor = 5u32.into(); let block_num = initial_data_block.saturating_add(1_000_000u32.into()); @@ -291,6 +335,9 @@ benchmarks! { } get_entry { + let max_entries = <::MaxUniqueEntries as Get>::get(); + fill_whitelist_storage::(max_entries); + let initial_data_block: BlockNumberFor = 5u32.into(); let oracle_age: BlockNumberFor = 999_999u32.into(); let block_num = initial_data_block.saturating_add(oracle_age.saturating_add(One::one())); diff --git a/pallets/ema-oracle/src/lib.rs b/pallets/ema-oracle/src/lib.rs index e23c3d55f..506e79383 100644 --- a/pallets/ema-oracle/src/lib.rs +++ b/pallets/ema-oracle/src/lib.rs @@ -115,8 +115,8 @@ impl BenchmarkHelper for () { #[frame_support::pallet] pub mod pallet { use super::*; - use frame_support::BoundedBTreeMap; - use frame_system::pallet_prelude::BlockNumberFor; + use frame_support::{BoundedBTreeMap, BoundedBTreeSet}; + use frame_system::pallet_prelude::{BlockNumberFor, OriginFor}; #[pallet::pallet] pub struct Pallet(_); @@ -128,6 +128,9 @@ pub mod pallet { /// Weight information for the extrinsics. type WeightInfo: WeightInfo; + /// Origin that can enable oracle for assets that would be rejected by `OracleWhitelist` otherwise. + type AuthorityOrigin: EnsureOrigin; + /// Provider for the current block number. type BlockNumberProvider: BlockNumberProvider>; @@ -149,10 +152,17 @@ pub mod pallet { pub enum Error { TooManyUniqueEntries, OnTradeValueZero, + OracleNotFound, } #[pallet::event] - pub enum Event {} + #[pallet::generate_deposit(pub(crate) fn deposit_event)] + pub enum Event { + /// Oracle was added to the whitelist. + OracleAdded { source: Source, assets: (AssetId, AssetId) }, + /// Oracle was removed from the whitelist. + OracleRemoved { source: Source, assets: (AssetId, AssetId) }, + } /// Accumulator for oracle data in current block that will be recorded at the end of the block. #[pallet::storage] @@ -163,7 +173,7 @@ pub mod pallet { ValueQuery, >; - /// Orace storage keyed by data source, involved asset ids and the period length of the oracle. + /// Oracle storage keyed by data source, involved asset ids and the period length of the oracle. /// /// Stores the data entry as well as the block number when the oracle was first initialized. #[pallet::storage] @@ -179,6 +189,11 @@ pub mod pallet { OptionQuery, >; + /// Assets that are whitelisted and tracked by the pallet. + #[pallet::storage] + pub type WhitelistedAssets = + StorageValue<_, BoundedBTreeSet<(Source, (AssetId, AssetId)), T::MaxUniqueEntries>, ValueQuery>; + #[pallet::genesis_config] #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig { @@ -232,7 +247,43 @@ pub mod pallet { } #[pallet::call] - impl Pallet {} + impl Pallet { + #[pallet::call_index(0)] + #[pallet::weight(::WeightInfo::add_oracle())] + pub fn add_oracle(origin: OriginFor, source: Source, assets: (AssetId, AssetId)) -> DispatchResult { + T::AuthorityOrigin::ensure_origin(origin)?; + + let assets = ordered_pair(assets.0, assets.1); + + WhitelistedAssets::::mutate(|list| { + list.try_insert((source, (assets))) + .map_err(|_| Error::::TooManyUniqueEntries) + })?; + + Self::deposit_event(Event::OracleAdded { source, assets }); + + Ok(()) + } + + #[pallet::call_index(1)] + #[pallet::weight(::WeightInfo::remove_oracle())] + pub fn remove_oracle(origin: OriginFor, source: Source, assets: (AssetId, AssetId)) -> DispatchResult { + T::AuthorityOrigin::ensure_origin(origin)?; + + let assets = ordered_pair(assets.0, assets.1); + + WhitelistedAssets::::mutate(|list| { + let was_removed = list.remove(&(source, (assets))); + ensure!(was_removed, Error::::OracleNotFound); + + Ok::<(), DispatchError>(()) + })?; + + Self::deposit_event(Event::OracleRemoved { source, assets }); + + Ok(()) + } + } } impl Pallet { @@ -243,7 +294,10 @@ impl Pallet { assets: (AssetId, AssetId), oracle_entry: OracleEntry>, ) -> Result<(), ()> { - if !T::OracleFilter::contains(&(src, assets.0, assets.1)) { + if !(T::OracleFilter::contains(&(src, assets.0, assets.1)) + || WhitelistedAssets::::get().contains(&(src, (assets.0, assets.1)))) + { + // if we don't track oracle for given asset pair, don't throw error return Ok(()); } diff --git a/pallets/ema-oracle/src/tests/add_and_remove_oracle.rs b/pallets/ema-oracle/src/tests/add_and_remove_oracle.rs new file mode 100644 index 000000000..5eca31520 --- /dev/null +++ b/pallets/ema-oracle/src/tests/add_and_remove_oracle.rs @@ -0,0 +1,161 @@ +// This file is part of pallet-ema-oracle. + +// Copyright (C) 2022-2023 Intergalactic, Limited (GIB). +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use super::*; +pub use mock::{expect_events, EmaOracle, RuntimeOrigin, Test, DOT, HDX}; + +use frame_support::{assert_noop, assert_ok}; +use pretty_assertions::assert_eq; + +pub fn new_test_ext() -> sp_io::TestExternalities { + ExtBuilder::default().build() +} + +#[test] +fn add_oracle_should_add_entry_to_storage() { + new_test_ext().execute_with(|| { + assert_ok!(EmaOracle::add_oracle(RuntimeOrigin::root(), SOURCE, (HDX, DOT))); + + expect_events(vec![Event::OracleAdded { + source: SOURCE, + assets: (HDX, DOT), + } + .into()]); + }); +} + +#[test] +fn add_oracle_should_store_assets_in_correct_order() { + new_test_ext().execute_with(|| { + assert_ok!(EmaOracle::add_oracle(RuntimeOrigin::root(), SOURCE, (DOT, HDX))); + + expect_events(vec![Event::OracleAdded { + source: SOURCE, + assets: (HDX, DOT), + } + .into()]); + + assert!(WhitelistedAssets::::get().contains(&(SOURCE, (HDX, DOT)))); + }); +} + +#[test] +fn add_oracle_should_not_fail_when_storage_entry_already_added() { + new_test_ext().execute_with(|| { + assert_ok!(EmaOracle::add_oracle(RuntimeOrigin::root(), SOURCE, (HDX, DOT))); + assert_ok!(EmaOracle::add_oracle(RuntimeOrigin::root(), SOURCE, (HDX, DOT))); + }); +} + +#[test] +fn add_oracle_should_fail_when_storage_is_full() { + new_test_ext().execute_with(|| { + let max_entries = <::MaxUniqueEntries as Get>::get(); + + for i in 0..max_entries { + assert_ok!(EmaOracle::add_oracle(RuntimeOrigin::root(), SOURCE, (HDX, i))); + } + + assert_eq!(WhitelistedAssets::::get().len(), max_entries as usize); + + assert_noop!( + EmaOracle::add_oracle(RuntimeOrigin::root(), SOURCE, (HDX, DOT)), + Error::::TooManyUniqueEntries + ); + }); +} + +#[test] +fn remove_oracle_should_remove_entry_from_storage() { + new_test_ext().execute_with(|| { + assert_ok!(EmaOracle::add_oracle(RuntimeOrigin::root(), SOURCE, (HDX, DOT))); + assert!(WhitelistedAssets::::get().contains(&(SOURCE, (HDX, DOT)))); + + assert_ok!(EmaOracle::remove_oracle(RuntimeOrigin::root(), SOURCE, (HDX, DOT))); + assert!(!WhitelistedAssets::::get().contains(&(SOURCE, (HDX, DOT)))); + + expect_events(vec![Event::OracleRemoved { + source: SOURCE, + assets: (HDX, DOT), + } + .into()]); + }); +} + +#[test] +fn remove_oracle_should_fail_when_oracle_not_tracked() { + new_test_ext().execute_with(|| { + assert_noop!( + EmaOracle::remove_oracle(RuntimeOrigin::root(), SOURCE, (HDX, DOT)), + Error::::OracleNotFound + ); + }); +} + +#[test] +fn on_trade_should_include_whitelisted_oracle_for_correct_source() { + new_test_ext().execute_with(|| { + assert_ok!(EmaOracle::add_oracle( + RuntimeOrigin::root(), + SOURCE, + (HDX, INSUFFICIENT_ASSET) + )); + + assert_eq!(get_accumulator_entry(SOURCE, (HDX, INSUFFICIENT_ASSET)), None); + + assert_ok!(OnActivityHandler::::on_trade( + SOURCE, + HDX, + INSUFFICIENT_ASSET, + 1_000, + 500, + 2_000, + 1_000, + Price::new(2_000, 1_000) + )); + + assert!(get_accumulator_entry(SOURCE, (HDX, INSUFFICIENT_ASSET)).is_some()); + assert!(get_accumulator_entry([0; 8], (HDX, INSUFFICIENT_ASSET)).is_none()); + }); +} + +#[test] +fn on_liquidity_changed_should_include_whitelisted_oracle_for_correct_source() { + new_test_ext().execute_with(|| { + assert_ok!(EmaOracle::add_oracle( + RuntimeOrigin::root(), + SOURCE, + (HDX, INSUFFICIENT_ASSET) + )); + + assert_eq!(get_accumulator_entry(SOURCE, (HDX, INSUFFICIENT_ASSET)), None); + + assert_ok!(OnActivityHandler::::on_liquidity_changed( + SOURCE, + HDX, + INSUFFICIENT_ASSET, + 1_000, + 500, + 2_000, + 1_000, + Price::new(2_000, 1_000), + )); + + assert!(get_accumulator_entry(SOURCE, (HDX, INSUFFICIENT_ASSET)).is_some()); + assert!(get_accumulator_entry([0; 8], (HDX, INSUFFICIENT_ASSET)).is_none()); + }); +} diff --git a/pallets/ema-oracle/src/tests/mock.rs b/pallets/ema-oracle/src/tests/mock.rs index ad8db1154..2473fbcce 100644 --- a/pallets/ema-oracle/src/tests/mock.rs +++ b/pallets/ema-oracle/src/tests/mock.rs @@ -27,6 +27,7 @@ use frame_support::sp_runtime::{ }; use frame_support::traits::{Contains, Everything}; use frame_support::BoundedVec; +use frame_system::EnsureRoot; use hydradx_traits::OraclePeriod::{self, *}; use hydradx_traits::Source; use hydradx_traits::{AssetPairAccountIdFor, Liquidity, Volume}; @@ -34,6 +35,7 @@ use sp_core::H256; use crate::types::{AssetId, Balance, Price}; pub type BlockNumber = u64; +pub type AccountId = u64; type Block = frame_system::mocking::MockBlock; @@ -134,13 +136,14 @@ impl Contains<(Source, AssetId, AssetId)> for OracleFilter { impl Config for Test { type RuntimeEvent = RuntimeEvent; - type WeightInfo = (); + type AuthorityOrigin = EnsureRoot; type BlockNumberProvider = System; type SupportedPeriods = SupportedPeriods; type OracleFilter = OracleFilter; type MaxUniqueEntries = ConstU32<45>; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = (); + type WeightInfo = (); } pub type InitialDataEntry = (Source, (AssetId, AssetId), Price, Liquidity); @@ -167,8 +170,12 @@ impl ExtBuilder { let mut ext: sp_io::TestExternalities = t.into(); ext.execute_with(|| { - System::set_block_number(0); + System::set_block_number(1); }); ext } } + +pub fn expect_events(e: Vec) { + test_utils::expect_events::(e); +} diff --git a/pallets/ema-oracle/src/tests/mod.rs b/pallets/ema-oracle/src/tests/mod.rs index 1d061b0b3..062cfc283 100644 --- a/pallets/ema-oracle/src/tests/mod.rs +++ b/pallets/ema-oracle/src/tests/mod.rs @@ -15,6 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +mod add_and_remove_oracle; mod invariants; mod mock; @@ -474,13 +475,13 @@ fn oracle_volume_should_factor_in_asset_order() { price: Price::new(2_000, 1), volume: Volume::from_a_in_b_out(2_000_000, 1_000), liquidity: (2_000, 1).into(), - updated_at: 0, + updated_at: 1, }; let second_entry = OracleEntry { price: Price::new(2_000, 1), volume: Volume::from_a_out_b_in(2_000_000, 1_000), liquidity: (2_000, 1).into(), - updated_at: 0, + updated_at: 1, }; let result = second_entry.with_added_volume_from(&first_entry); diff --git a/pallets/ema-oracle/src/weights.rs b/pallets/ema-oracle/src/weights.rs index 0e3fc21c0..7c2019f1d 100644 --- a/pallets/ema-oracle/src/weights.rs +++ b/pallets/ema-oracle/src/weights.rs @@ -51,6 +51,8 @@ use sp_std::marker::PhantomData; /// Weight functions needed for pallet_ema_oracle. pub trait WeightInfo { + fn add_oracle() -> Weight; + fn remove_oracle() -> Weight; fn on_finalize_no_entry() -> Weight; fn on_finalize_multiple_tokens(b: u32) -> Weight; fn on_trade_multiple_tokens(b: u32) -> Weight; @@ -61,6 +63,12 @@ pub trait WeightInfo { pub struct BasiliskWeight(PhantomData); impl WeightInfo for BasiliskWeight { + fn add_oracle() -> Weight { + Weight::zero() + } + fn remove_oracle() -> Weight { + Weight::zero() + } /// Storage: `EmaOracle::Accumulator` (r:1 w:0) /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) fn on_finalize_no_entry() -> Weight { @@ -130,6 +138,12 @@ impl WeightInfo for BasiliskWeight { // For backwards compatibility and tests impl WeightInfo for () { + fn add_oracle() -> Weight { + Weight::zero() + } + fn remove_oracle() -> Weight { + Weight::zero() + } /// Storage: `EmaOracle::Accumulator` (r:1 w:0) /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) fn on_finalize_no_entry() -> Weight { diff --git a/pallets/omnipool-liquidity-mining/src/tests/mock.rs b/pallets/omnipool-liquidity-mining/src/tests/mock.rs index 649175923..4490023cb 100644 --- a/pallets/omnipool-liquidity-mining/src/tests/mock.rs +++ b/pallets/omnipool-liquidity-mining/src/tests/mock.rs @@ -247,13 +247,14 @@ parameter_types! { impl pallet_ema_oracle::Config for Test { type RuntimeEvent = RuntimeEvent; - type WeightInfo = (); + type AuthorityOrigin = EnsureRoot; type BlockNumberProvider = MockBlockNumberProvider; type SupportedPeriods = SupportedPeriods; type OracleFilter = Everything; type MaxUniqueEntries = ConstU32<20>; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = (); + type WeightInfo = (); } parameter_types! { diff --git a/runtime/hydradx/src/assets.rs b/runtime/hydradx/src/assets.rs index 2692694ae..f933176e0 100644 --- a/runtime/hydradx/src/assets.rs +++ b/runtime/hydradx/src/assets.rs @@ -506,7 +506,7 @@ impl Contains<(Source, AssetId, AssetId)> for SufficientAssetsFilter { impl pallet_ema_oracle::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type WeightInfo = weights::ema_oracle::HydraWeight; + type AuthorityOrigin = SuperMajorityTechCommittee; /// The definition of the oracle time periods currently assumes a 6 second block time. /// We use the parachain blocks anyway, because we want certain guarantees over how many blocks correspond /// to which smoothing factor. @@ -516,6 +516,7 @@ impl pallet_ema_oracle::Config for Runtime { /// With every asset trading against LRNA we will only have as many pairs as there will be assets, so /// 40 seems a decent upper bound for the foreseeable future. type MaxUniqueEntries = ConstU32<40>; + type WeightInfo = weights::ema_oracle::HydraWeight; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = RegisterAsset; } diff --git a/runtime/hydradx/src/weights/ema_oracle.rs b/runtime/hydradx/src/weights/ema_oracle.rs index 621a35424..709010e73 100644 --- a/runtime/hydradx/src/weights/ema_oracle.rs +++ b/runtime/hydradx/src/weights/ema_oracle.rs @@ -50,6 +50,12 @@ use pallet_ema_oracle::weights::WeightInfo; /// Weight functions for `pallet_ema_oracle`. pub struct HydraWeight(PhantomData); impl WeightInfo for HydraWeight { + fn add_oracle() -> Weight { + Weight::zero() + } + fn remove_oracle() -> Weight { + Weight::zero() + } /// Storage: `EmaOracle::Accumulator` (r:1 w:0) /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) fn on_finalize_no_entry() -> Weight { From 644a61425c3116f862fc1c0c3f36b536b72c26a7 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Tue, 5 Mar 2024 16:55:12 +0100 Subject: [PATCH 02/13] fix name of the config param --- pallets/ema-oracle/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/ema-oracle/src/lib.rs b/pallets/ema-oracle/src/lib.rs index bb0e99e24..e803772a9 100644 --- a/pallets/ema-oracle/src/lib.rs +++ b/pallets/ema-oracle/src/lib.rs @@ -294,7 +294,7 @@ impl Pallet { assets: (AssetId, AssetId), oracle_entry: OracleEntry>, ) -> Result<(), ()> { - if !(T::OracleFilter::contains(&(src, assets.0, assets.1)) + if !(T::OracleWhitelist::contains(&(src, assets.0, assets.1)) || WhitelistedAssets::::get().contains(&(src, (assets.0, assets.1)))) { // if we don't track oracle for given asset pair, don't throw error From e802938250a934d6652ac0ecd530dbd937fd5f65 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Tue, 5 Mar 2024 18:46:46 +0100 Subject: [PATCH 03/13] rebenchmark ema oracle pallet --- pallets/ema-oracle/src/weights.rs | 138 +++++++++++++--------- runtime/hydradx/src/weights/ema_oracle.rs | 62 ++++++---- 2 files changed, 123 insertions(+), 77 deletions(-) diff --git a/pallets/ema-oracle/src/weights.rs b/pallets/ema-oracle/src/weights.rs index 36133fb6c..9f5677c51 100644 --- a/pallets/ema-oracle/src/weights.rs +++ b/pallets/ema-oracle/src/weights.rs @@ -18,26 +18,24 @@ //! Autogenerated weights for `pallet_ema_oracle` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-03-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` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-ema-oracle +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet-ema-oracle +// --output=weights-1.1.0/oracle.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/ema_oracle.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs #![allow(unused_parens)] #![allow(unused_imports)] @@ -63,11 +61,27 @@ pub trait WeightInfo { pub struct BasiliskWeight(PhantomData); impl WeightInfo for BasiliskWeight { + /// Storage: `EmaOracle::WhitelistedAssets` (r:1 w:1) + /// Proof: `EmaOracle::WhitelistedAssets` (`max_values`: Some(1), `max_size`: Some(641), added: 1136, mode: `MaxEncodedLen`) fn add_oracle() -> Weight { - Weight::zero() + // Proof Size summary in bytes: + // Measured: `860` + // Estimated: `2126` + // Minimum execution time: 21_341_000 picoseconds. + Weight::from_parts(21_667_000, 2126) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } + /// Storage: `EmaOracle::WhitelistedAssets` (r:1 w:1) + /// Proof: `EmaOracle::WhitelistedAssets` (`max_values`: Some(1), `max_size`: Some(641), added: 1136, mode: `MaxEncodedLen`) fn remove_oracle() -> Weight { - Weight::zero() + // Proof Size summary in bytes: + // Measured: `876` + // Estimated: `2126` + // Minimum execution time: 21_553_000 picoseconds. + Weight::from_parts(21_866_000, 2126) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `EmaOracle::Accumulator` (r:1 w:0) /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) @@ -75,8 +89,8 @@ impl WeightInfo for BasiliskWeight { // Proof Size summary in bytes: // Measured: `208` // Estimated: `7406` - // Minimum execution time: 3_261_000 picoseconds. - Weight::from_parts(3_342_000, 7406).saturating_add(T::DbWeight::get().reads(1)) + // Minimum execution time: 3_165_000 picoseconds. + Weight::from_parts(3_271_000, 7406).saturating_add(T::DbWeight::get().reads(1)) } /// Storage: `EmaOracle::Accumulator` (r:1 w:1) /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) @@ -85,12 +99,12 @@ impl WeightInfo for BasiliskWeight { /// The range of component `b` is `[1, 39]`. fn on_finalize_multiple_tokens(b: u32) -> Weight { // Proof Size summary in bytes: - // Measured: `270 + b * (626 ±0)` + // Measured: `304 + b * (626 ±0)` // Estimated: `7406 + b * (7956 ±0)` - // Minimum execution time: 49_005_000 picoseconds. - Weight::from_parts(11_980_224, 7406) - // Standard Error: 17_790 - .saturating_add(Weight::from_parts(36_916_571, 0).saturating_mul(b.into())) + // Minimum execution time: 48_505_000 picoseconds. + Weight::from_parts(12_673_348, 7406) + // Standard Error: 31_644 + .saturating_add(Weight::from_parts(36_427_193, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(b.into()))) .saturating_add(T::DbWeight::get().writes(1)) @@ -104,12 +118,12 @@ impl WeightInfo for BasiliskWeight { /// The range of component `b` is `[1, 39]`. fn on_trade_multiple_tokens(b: u32) -> Weight { // Proof Size summary in bytes: - // Measured: `718 + b * (163 ±0)` + // Measured: `751 + b * (163 ±0)` // Estimated: `7406` - // Minimum execution time: 18_948_000 picoseconds. - Weight::from_parts(19_508_272, 7406) - // Standard Error: 3_859 - .saturating_add(Weight::from_parts(435_799, 0).saturating_mul(b.into())) + // Minimum execution time: 18_943_000 picoseconds. + Weight::from_parts(19_294_596, 7406) + // Standard Error: 3_556 + .saturating_add(Weight::from_parts(423_769, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -120,12 +134,12 @@ impl WeightInfo for BasiliskWeight { /// The range of component `b` is `[1, 39]`. fn on_liquidity_changed_multiple_tokens(b: u32) -> Weight { // Proof Size summary in bytes: - // Measured: `718 + b * (163 ±0)` + // Measured: `751 + b * (163 ±0)` // Estimated: `7406` - // Minimum execution time: 18_875_000 picoseconds. - Weight::from_parts(19_397_429, 7406) - // Standard Error: 4_124 - .saturating_add(Weight::from_parts(438_627, 0).saturating_mul(b.into())) + // Minimum execution time: 19_079_000 picoseconds. + Weight::from_parts(19_403_394, 7406) + // Standard Error: 3_730 + .saturating_add(Weight::from_parts(422_560, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -133,20 +147,36 @@ impl WeightInfo for BasiliskWeight { /// Proof: `EmaOracle::Oracles` (`max_values`: None, `max_size`: Some(177), added: 2652, mode: `MaxEncodedLen`) fn get_entry() -> Weight { // Proof Size summary in bytes: - // Measured: `604` + // Measured: `638` // Estimated: `6294` - // Minimum execution time: 18_746_000 picoseconds. - Weight::from_parts(19_158_000, 6294).saturating_add(T::DbWeight::get().reads(2)) + // Minimum execution time: 18_991_000 picoseconds. + Weight::from_parts(19_258_000, 6294).saturating_add(T::DbWeight::get().reads(2)) } } // For backwards compatibility and tests impl WeightInfo for () { + /// Storage: `EmaOracle::WhitelistedAssets` (r:1 w:1) + /// Proof: `EmaOracle::WhitelistedAssets` (`max_values`: Some(1), `max_size`: Some(641), added: 1136, mode: `MaxEncodedLen`) fn add_oracle() -> Weight { - Weight::zero() + // Proof Size summary in bytes: + // Measured: `860` + // Estimated: `2126` + // Minimum execution time: 21_341_000 picoseconds. + Weight::from_parts(21_667_000, 2126) + .saturating_add(RocksDbWeight::get().reads(1)) + .saturating_add(RocksDbWeight::get().writes(1)) } + /// Storage: `EmaOracle::WhitelistedAssets` (r:1 w:1) + /// Proof: `EmaOracle::WhitelistedAssets` (`max_values`: Some(1), `max_size`: Some(641), added: 1136, mode: `MaxEncodedLen`) fn remove_oracle() -> Weight { - Weight::zero() + // Proof Size summary in bytes: + // Measured: `876` + // Estimated: `2126` + // Minimum execution time: 21_553_000 picoseconds. + Weight::from_parts(21_866_000, 2126) + .saturating_add(RocksDbWeight::get().reads(1)) + .saturating_add(RocksDbWeight::get().writes(1)) } /// Storage: `EmaOracle::Accumulator` (r:1 w:0) /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) @@ -154,8 +184,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `208` // Estimated: `7406` - // Minimum execution time: 3_261_000 picoseconds. - Weight::from_parts(3_342_000, 7406).saturating_add(RocksDbWeight::get().reads(1)) + // Minimum execution time: 3_165_000 picoseconds. + Weight::from_parts(3_271_000, 7406).saturating_add(RocksDbWeight::get().reads(1)) } /// Storage: `EmaOracle::Accumulator` (r:1 w:1) /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) @@ -164,12 +194,12 @@ impl WeightInfo for () { /// The range of component `b` is `[1, 39]`. fn on_finalize_multiple_tokens(b: u32) -> Weight { // Proof Size summary in bytes: - // Measured: `270 + b * (626 ±0)` + // Measured: `304 + b * (626 ±0)` // Estimated: `7406 + b * (7956 ±0)` - // Minimum execution time: 49_005_000 picoseconds. - Weight::from_parts(11_980_224, 7406) - // Standard Error: 17_790 - .saturating_add(Weight::from_parts(36_916_571, 0).saturating_mul(b.into())) + // Minimum execution time: 48_505_000 picoseconds. + Weight::from_parts(12_673_348, 7406) + // Standard Error: 31_644 + .saturating_add(Weight::from_parts(36_427_193, 0).saturating_mul(b.into())) .saturating_add(RocksDbWeight::get().reads(1)) .saturating_add(RocksDbWeight::get().reads((3_u64).saturating_mul(b.into()))) .saturating_add(RocksDbWeight::get().writes(1)) @@ -183,12 +213,12 @@ impl WeightInfo for () { /// The range of component `b` is `[1, 39]`. fn on_trade_multiple_tokens(b: u32) -> Weight { // Proof Size summary in bytes: - // Measured: `718 + b * (163 ±0)` + // Measured: `751 + b * (163 ±0)` // Estimated: `7406` - // Minimum execution time: 18_948_000 picoseconds. - Weight::from_parts(19_508_272, 7406) - // Standard Error: 3_859 - .saturating_add(Weight::from_parts(435_799, 0).saturating_mul(b.into())) + // Minimum execution time: 18_943_000 picoseconds. + Weight::from_parts(19_294_596, 7406) + // Standard Error: 3_556 + .saturating_add(Weight::from_parts(423_769, 0).saturating_mul(b.into())) .saturating_add(RocksDbWeight::get().reads(3)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -199,12 +229,12 @@ impl WeightInfo for () { /// The range of component `b` is `[1, 39]`. fn on_liquidity_changed_multiple_tokens(b: u32) -> Weight { // Proof Size summary in bytes: - // Measured: `718 + b * (163 ±0)` + // Measured: `751 + b * (163 ±0)` // Estimated: `7406` - // Minimum execution time: 18_875_000 picoseconds. - Weight::from_parts(19_397_429, 7406) - // Standard Error: 4_124 - .saturating_add(Weight::from_parts(438_627, 0).saturating_mul(b.into())) + // Minimum execution time: 19_079_000 picoseconds. + Weight::from_parts(19_403_394, 7406) + // Standard Error: 3_730 + .saturating_add(Weight::from_parts(422_560, 0).saturating_mul(b.into())) .saturating_add(RocksDbWeight::get().reads(3)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -212,9 +242,9 @@ impl WeightInfo for () { /// Proof: `EmaOracle::Oracles` (`max_values`: None, `max_size`: Some(177), added: 2652, mode: `MaxEncodedLen`) fn get_entry() -> Weight { // Proof Size summary in bytes: - // Measured: `604` + // Measured: `638` // Estimated: `6294` - // Minimum execution time: 18_746_000 picoseconds. - Weight::from_parts(19_158_000, 6294).saturating_add(RocksDbWeight::get().reads(2)) + // Minimum execution time: 18_991_000 picoseconds. + Weight::from_parts(19_258_000, 6294).saturating_add(RocksDbWeight::get().reads(2)) } } diff --git a/runtime/hydradx/src/weights/ema_oracle.rs b/runtime/hydradx/src/weights/ema_oracle.rs index 1c0f79c7c..521b361eb 100644 --- a/runtime/hydradx/src/weights/ema_oracle.rs +++ b/runtime/hydradx/src/weights/ema_oracle.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for `pallet_ema_oracle` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-02-29, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-03-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` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 @@ -50,11 +50,27 @@ use pallet_ema_oracle::weights::WeightInfo; /// Weight functions for `pallet_ema_oracle`. pub struct HydraWeight(PhantomData); impl WeightInfo for HydraWeight { + /// Storage: `EmaOracle::WhitelistedAssets` (r:1 w:1) + /// Proof: `EmaOracle::WhitelistedAssets` (`max_values`: Some(1), `max_size`: Some(641), added: 1136, mode: `MaxEncodedLen`) fn add_oracle() -> Weight { - Weight::zero() + // Proof Size summary in bytes: + // Measured: `860` + // Estimated: `2126` + // Minimum execution time: 21_341_000 picoseconds. + Weight::from_parts(21_667_000, 2126) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } + /// Storage: `EmaOracle::WhitelistedAssets` (r:1 w:1) + /// Proof: `EmaOracle::WhitelistedAssets` (`max_values`: Some(1), `max_size`: Some(641), added: 1136, mode: `MaxEncodedLen`) fn remove_oracle() -> Weight { - Weight::zero() + // Proof Size summary in bytes: + // Measured: `876` + // Estimated: `2126` + // Minimum execution time: 21_553_000 picoseconds. + Weight::from_parts(21_866_000, 2126) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `EmaOracle::Accumulator` (r:1 w:0) /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) @@ -62,8 +78,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `208` // Estimated: `7406` - // Minimum execution time: 3_261_000 picoseconds. - Weight::from_parts(3_342_000, 7406) + // Minimum execution time: 3_165_000 picoseconds. + Weight::from_parts(3_271_000, 7406) .saturating_add(T::DbWeight::get().reads(1)) } /// Storage: `EmaOracle::Accumulator` (r:1 w:1) @@ -73,12 +89,12 @@ impl WeightInfo for HydraWeight { /// The range of component `b` is `[1, 39]`. fn on_finalize_multiple_tokens(b: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `270 + b * (626 ±0)` + // Measured: `304 + b * (626 ±0)` // Estimated: `7406 + b * (7956 ±0)` - // Minimum execution time: 49_005_000 picoseconds. - Weight::from_parts(11_980_224, 7406) - // Standard Error: 17_790 - .saturating_add(Weight::from_parts(36_916_571, 0).saturating_mul(b.into())) + // Minimum execution time: 48_505_000 picoseconds. + Weight::from_parts(12_673_348, 7406) + // Standard Error: 31_644 + .saturating_add(Weight::from_parts(36_427_193, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(b.into()))) .saturating_add(T::DbWeight::get().writes(1)) @@ -92,12 +108,12 @@ impl WeightInfo for HydraWeight { /// The range of component `b` is `[1, 39]`. fn on_trade_multiple_tokens(b: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `718 + b * (163 ±0)` + // Measured: `751 + b * (163 ±0)` // Estimated: `7406` - // Minimum execution time: 18_948_000 picoseconds. - Weight::from_parts(19_508_272, 7406) - // Standard Error: 3_859 - .saturating_add(Weight::from_parts(435_799, 0).saturating_mul(b.into())) + // Minimum execution time: 18_943_000 picoseconds. + Weight::from_parts(19_294_596, 7406) + // Standard Error: 3_556 + .saturating_add(Weight::from_parts(423_769, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -108,12 +124,12 @@ impl WeightInfo for HydraWeight { /// The range of component `b` is `[1, 39]`. fn on_liquidity_changed_multiple_tokens(b: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `718 + b * (163 ±0)` + // Measured: `751 + b * (163 ±0)` // Estimated: `7406` - // Minimum execution time: 18_875_000 picoseconds. - Weight::from_parts(19_397_429, 7406) - // Standard Error: 4_124 - .saturating_add(Weight::from_parts(438_627, 0).saturating_mul(b.into())) + // Minimum execution time: 19_079_000 picoseconds. + Weight::from_parts(19_403_394, 7406) + // Standard Error: 3_730 + .saturating_add(Weight::from_parts(422_560, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -121,10 +137,10 @@ impl WeightInfo for HydraWeight { /// Proof: `EmaOracle::Oracles` (`max_values`: None, `max_size`: Some(177), added: 2652, mode: `MaxEncodedLen`) fn get_entry() -> Weight { // Proof Size summary in bytes: - // Measured: `604` + // Measured: `638` // Estimated: `6294` - // Minimum execution time: 18_746_000 picoseconds. - Weight::from_parts(19_158_000, 6294) + // Minimum execution time: 18_991_000 picoseconds. + Weight::from_parts(19_258_000, 6294) .saturating_add(T::DbWeight::get().reads(2)) } } From 4e3067b937e48c89639b10323e2a39b0192c4bc3 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Tue, 5 Mar 2024 19:24:04 +0100 Subject: [PATCH 04/13] bump crate versions --- Cargo.lock | 10 +++++----- integration-tests/Cargo.toml | 2 +- pallets/dca/Cargo.toml | 2 +- pallets/ema-oracle/Cargo.toml | 2 +- pallets/omnipool-liquidity-mining/Cargo.toml | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8406c5c61..99f2c51d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4621,7 +4621,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "221.0.0" +version = "222.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -7403,7 +7403,7 @@ dependencies = [ [[package]] name = "pallet-dca" -version = "1.4.0" +version = "1.4.1" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -7605,7 +7605,7 @@ dependencies = [ [[package]] name = "pallet-ema-oracle" -version = "1.2.1" +version = "1.3.0" dependencies = [ "frame-benchmarking", "frame-support", @@ -8152,7 +8152,7 @@ dependencies = [ [[package]] name = "pallet-omnipool-liquidity-mining" -version = "2.1.2" +version = "2.1.3" dependencies = [ "frame-benchmarking", "frame-support", @@ -11364,7 +11364,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.19.6" +version = "1.19.7" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index a0e40d004..664721008 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.19.6" +version = "1.19.7" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/pallets/dca/Cargo.toml b/pallets/dca/Cargo.toml index 6a379fcc5..c921e6f6e 100644 --- a/pallets/dca/Cargo.toml +++ b/pallets/dca/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-dca' -version = "1.4.0" +version = "1.4.1" description = 'A pallet to manage DCA scheduling' authors = ['GalacticCouncil'] edition = '2021' diff --git a/pallets/ema-oracle/Cargo.toml b/pallets/ema-oracle/Cargo.toml index 51f980def..3dd10c436 100644 --- a/pallets/ema-oracle/Cargo.toml +++ b/pallets/ema-oracle/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-ema-oracle' -version = '1.2.1' +version = '1.3.0' description = 'Exponential moving average oracle for AMM pools' authors = ['GalacticCouncil'] edition = '2021' diff --git a/pallets/omnipool-liquidity-mining/Cargo.toml b/pallets/omnipool-liquidity-mining/Cargo.toml index 692a5e726..c1315670b 100644 --- a/pallets/omnipool-liquidity-mining/Cargo.toml +++ b/pallets/omnipool-liquidity-mining/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-omnipool-liquidity-mining" -version = "2.1.2" +version = "2.1.3" authors = ['GalacticCouncil'] edition = "2021" license = "Apache-2.0" diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index dc6a4713b..3ccdfd0b1 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "221.0.0" +version = "222.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 b505b5536..25304c6f1 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -108,7 +108,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 221, + spec_version: 222, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 4d38a394efef2b3070c73816bef6906f7e2529a4 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Tue, 12 Mar 2024 10:16:33 -0500 Subject: [PATCH 05/13] bump crate 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 a2537538f..043aa5400 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4621,7 +4621,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "222.0.0" +version = "223.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -11364,7 +11364,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.19.7" +version = "1.19.8" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 664721008..c0e678965 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.19.7" +version = "1.19.8" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index 3ccdfd0b1..e3c818bbe 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "222.0.0" +version = "223.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 25304c6f1..08ef12903 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -108,7 +108,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 222, + spec_version: 223, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 37a090c2bfd732a666c756e11b03126c6d3b6879 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Thu, 14 Mar 2024 17:22:01 -0500 Subject: [PATCH 06/13] bump crate version --- Cargo.lock | 2 +- integration-tests/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 043aa5400..b6e4feefe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11364,7 +11364,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.19.8" +version = "1.19.9" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index c0e678965..4e6999ae0 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.19.8" +version = "1.19.9" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" From 0b2ceb5072260115751380782d983b55c045638f Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Mon, 18 Mar 2024 09:31:49 -0500 Subject: [PATCH 07/13] bump crate 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 5fc972a15..2d2afb371 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4621,7 +4621,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "223.0.0" +version = "224.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -11366,7 +11366,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.19.9" +version = "1.19.10" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 4e6999ae0..7684cc98a 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.19.9" +version = "1.19.10" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index e3c818bbe..c90d4e2a5 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "223.0.0" +version = "224.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 0731cf3ff..f6586e87d 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: 223, + spec_version: 224, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 11772015b03a49f3bd2faa016e28386668093831 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Tue, 19 Mar 2024 14:29:33 -0500 Subject: [PATCH 08/13] bump crate versions --- Cargo.lock | 6 +++--- integration-tests/Cargo.toml | 2 +- pallets/dca/Cargo.toml | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5f13cd2cd..f9c415e8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4621,7 +4621,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "225.0.0" +version = "226.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -7403,7 +7403,7 @@ dependencies = [ [[package]] name = "pallet-dca" -version = "1.4.1" +version = "1.4.2" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -11367,7 +11367,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.19.11" +version = "1.19.12" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 9c63774af..01e988202 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.19.11" +version = "1.19.12" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/pallets/dca/Cargo.toml b/pallets/dca/Cargo.toml index c921e6f6e..4b50dba37 100644 --- a/pallets/dca/Cargo.toml +++ b/pallets/dca/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-dca' -version = "1.4.1" +version = "1.4.2" description = 'A pallet to manage DCA scheduling' authors = ['GalacticCouncil'] edition = '2021' diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index aceda94c3..1a498d709 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "225.0.0" +version = "226.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 8e2faf1c4..3a6bf8879 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: 225, + spec_version: 226, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 781a31d10b6815cd82eb03048440a4f836483a8f Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Mon, 8 Apr 2024 10:46:50 -0500 Subject: [PATCH 09/13] rename events --- pallets/ema-oracle/src/lib.rs | 8 ++++---- pallets/ema-oracle/src/tests/add_and_remove_oracle.rs | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pallets/ema-oracle/src/lib.rs b/pallets/ema-oracle/src/lib.rs index e803772a9..a513a29d7 100644 --- a/pallets/ema-oracle/src/lib.rs +++ b/pallets/ema-oracle/src/lib.rs @@ -159,9 +159,9 @@ pub mod pallet { #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { /// Oracle was added to the whitelist. - OracleAdded { source: Source, assets: (AssetId, AssetId) }, + AddedToWhitelist { source: Source, assets: (AssetId, AssetId) }, /// Oracle was removed from the whitelist. - OracleRemoved { source: Source, assets: (AssetId, AssetId) }, + RemovedFromWhitelist { source: Source, assets: (AssetId, AssetId) }, } /// Accumulator for oracle data in current block that will be recorded at the end of the block. @@ -260,7 +260,7 @@ pub mod pallet { .map_err(|_| Error::::TooManyUniqueEntries) })?; - Self::deposit_event(Event::OracleAdded { source, assets }); + Self::deposit_event(Event::AddedToWhitelist { source, assets }); Ok(()) } @@ -279,7 +279,7 @@ pub mod pallet { Ok::<(), DispatchError>(()) })?; - Self::deposit_event(Event::OracleRemoved { source, assets }); + Self::deposit_event(Event::RemovedFromWhitelist { source, assets }); Ok(()) } diff --git a/pallets/ema-oracle/src/tests/add_and_remove_oracle.rs b/pallets/ema-oracle/src/tests/add_and_remove_oracle.rs index 5eca31520..c291bd526 100644 --- a/pallets/ema-oracle/src/tests/add_and_remove_oracle.rs +++ b/pallets/ema-oracle/src/tests/add_and_remove_oracle.rs @@ -30,7 +30,7 @@ fn add_oracle_should_add_entry_to_storage() { new_test_ext().execute_with(|| { assert_ok!(EmaOracle::add_oracle(RuntimeOrigin::root(), SOURCE, (HDX, DOT))); - expect_events(vec![Event::OracleAdded { + expect_events(vec![Event::AddedToWhitelist { source: SOURCE, assets: (HDX, DOT), } @@ -43,7 +43,7 @@ fn add_oracle_should_store_assets_in_correct_order() { new_test_ext().execute_with(|| { assert_ok!(EmaOracle::add_oracle(RuntimeOrigin::root(), SOURCE, (DOT, HDX))); - expect_events(vec![Event::OracleAdded { + expect_events(vec![Event::AddedToWhitelist { source: SOURCE, assets: (HDX, DOT), } @@ -88,7 +88,7 @@ fn remove_oracle_should_remove_entry_from_storage() { assert_ok!(EmaOracle::remove_oracle(RuntimeOrigin::root(), SOURCE, (HDX, DOT))); assert!(!WhitelistedAssets::::get().contains(&(SOURCE, (HDX, DOT)))); - expect_events(vec![Event::OracleRemoved { + expect_events(vec![Event::RemovedFromWhitelist { source: SOURCE, assets: (HDX, DOT), } From 5d6eda886c45a00d4ac813974ec76a0ddd9c75ab Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Mon, 8 Apr 2024 15:17:30 -0500 Subject: [PATCH 10/13] remove_oracle removes entries from the storage --- pallets/ema-oracle/src/lib.rs | 12 ++++++-- .../src/tests/add_and_remove_oracle.rs | 29 ++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/pallets/ema-oracle/src/lib.rs b/pallets/ema-oracle/src/lib.rs index a513a29d7..7ab95aa82 100644 --- a/pallets/ema-oracle/src/lib.rs +++ b/pallets/ema-oracle/src/lib.rs @@ -273,12 +273,20 @@ pub mod pallet { let assets = ordered_pair(assets.0, assets.1); WhitelistedAssets::::mutate(|list| { - let was_removed = list.remove(&(source, (assets))); - ensure!(was_removed, Error::::OracleNotFound); + ensure!(list.remove(&(source, (assets))), Error::::OracleNotFound); Ok::<(), DispatchError>(()) })?; + // remove oracle from the storage + for period in T::SupportedPeriods::get().into_iter() { + let _ = Accumulator::::mutate(|accumulator| { + accumulator.remove(&(source, assets)); + Ok::<(), ()>(()) + }); + Oracles::::remove((source, assets, period)); + } + Self::deposit_event(Event::RemovedFromWhitelist { source, assets }); Ok(()) diff --git a/pallets/ema-oracle/src/tests/add_and_remove_oracle.rs b/pallets/ema-oracle/src/tests/add_and_remove_oracle.rs index c291bd526..5a6711541 100644 --- a/pallets/ema-oracle/src/tests/add_and_remove_oracle.rs +++ b/pallets/ema-oracle/src/tests/add_and_remove_oracle.rs @@ -16,7 +16,7 @@ // limitations under the License. use super::*; -pub use mock::{expect_events, EmaOracle, RuntimeOrigin, Test, DOT, HDX}; +pub use mock::{expect_events, EmaOracle, RuntimeOrigin, Test, DOT, HDX, ORACLE_ENTRY_1}; use frame_support::{assert_noop, assert_ok}; use pretty_assertions::assert_eq; @@ -85,9 +85,36 @@ fn remove_oracle_should_remove_entry_from_storage() { assert_ok!(EmaOracle::add_oracle(RuntimeOrigin::root(), SOURCE, (HDX, DOT))); assert!(WhitelistedAssets::::get().contains(&(SOURCE, (HDX, DOT)))); + System::set_block_number(5); + EmaOracle::on_initialize(5); + + assert_ok!(EmaOracle::on_trade(SOURCE, ordered_pair(HDX, DOT), ORACLE_ENTRY_1)); + + EmaOracle::on_finalize(5); + System::set_block_number(6); + EmaOracle::on_initialize(6); + + for period in ::SupportedPeriods::get() { + assert_eq!( + get_oracle_entry(HDX, DOT, period), + Some(ORACLE_ENTRY_1), + ); + } + assert_ok!(EmaOracle::remove_oracle(RuntimeOrigin::root(), SOURCE, (HDX, DOT))); assert!(!WhitelistedAssets::::get().contains(&(SOURCE, (HDX, DOT)))); + for period in ::SupportedPeriods::get() { + assert_eq!( + get_oracle_entry(HDX, DOT, period), + None, + ); + } + + EmaOracle::on_finalize(6); + System::set_block_number(7); + EmaOracle::on_initialize(7); + expect_events(vec![Event::RemovedFromWhitelist { source: SOURCE, assets: (HDX, DOT), From 1a6c3183054007537281dca1548df49fc1f2c878 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Mon, 8 Apr 2024 16:38:02 -0500 Subject: [PATCH 11/13] refactor oracle whitelist --- pallets/asset-registry/src/lib.rs | 11 +++++++++++ pallets/ema-oracle/src/lib.rs | 14 ++++++++++---- .../ema-oracle/src/tests/add_and_remove_oracle.rs | 14 ++++---------- pallets/ema-oracle/src/tests/mock.rs | 8 ++++---- runtime/hydradx/src/assets.rs | 13 +++++++++---- 5 files changed, 38 insertions(+), 22 deletions(-) diff --git a/pallets/asset-registry/src/lib.rs b/pallets/asset-registry/src/lib.rs index c91188006..70be130e7 100644 --- a/pallets/asset-registry/src/lib.rs +++ b/pallets/asset-registry/src/lib.rs @@ -21,6 +21,7 @@ use frame_support::pallet_prelude::*; use frame_support::require_transactional; use frame_support::sp_runtime::traits::CheckedAdd; use frame_support::traits::tokens::fungibles::{Inspect as FungiblesInspect, Mutate as FungiblesMutate}; +use frame_support::traits::Contains; use frame_system::pallet_prelude::*; use scale_info::TypeInfo; use sp_arithmetic::traits::BaseArithmetic; @@ -752,3 +753,13 @@ impl Create for Pallet { } } } + +/// Oracle whitelist based on the asset sufficiency. +pub struct OracleWhitelist(PhantomData); +impl Contains<(hydradx_traits::Source, ::AssetId, ::AssetId)> + for OracleWhitelist +{ + fn contains(t: &(hydradx_traits::Source, ::AssetId, ::AssetId)) -> bool { + Pallet::::is_sufficient(t.1) && Pallet::::is_sufficient(t.2) + } +} diff --git a/pallets/ema-oracle/src/lib.rs b/pallets/ema-oracle/src/lib.rs index 7ab95aa82..b62ac2e63 100644 --- a/pallets/ema-oracle/src/lib.rs +++ b/pallets/ema-oracle/src/lib.rs @@ -282,7 +282,7 @@ pub mod pallet { for period in T::SupportedPeriods::get().into_iter() { let _ = Accumulator::::mutate(|accumulator| { accumulator.remove(&(source, assets)); - Ok::<(), ()>(()) + Ok::<(), ()>(()) }); Oracles::::remove((source, assets, period)); } @@ -302,9 +302,7 @@ impl Pallet { assets: (AssetId, AssetId), oracle_entry: OracleEntry>, ) -> Result<(), ()> { - if !(T::OracleWhitelist::contains(&(src, assets.0, assets.1)) - || WhitelistedAssets::::get().contains(&(src, (assets.0, assets.1)))) - { + if !T::OracleWhitelist::contains(&(src, assets.0, assets.1)) { // if we don't track oracle for given asset pair, don't throw error return Ok(()); } @@ -654,3 +652,11 @@ impl AggregatedPriceOracle, Price> for Pal Self::get_entry_weight() } } + +/// Oracle whitelist based on the pallet's storage. +pub struct OracleWhitelist(PhantomData); +impl Contains<(Source, AssetId, AssetId)> for OracleWhitelist { + fn contains(t: &(Source, AssetId, AssetId)) -> bool { + WhitelistedAssets::::get().contains(&(t.0, (t.1, t.2))) + } +} diff --git a/pallets/ema-oracle/src/tests/add_and_remove_oracle.rs b/pallets/ema-oracle/src/tests/add_and_remove_oracle.rs index 5a6711541..17773c034 100644 --- a/pallets/ema-oracle/src/tests/add_and_remove_oracle.rs +++ b/pallets/ema-oracle/src/tests/add_and_remove_oracle.rs @@ -95,20 +95,14 @@ fn remove_oracle_should_remove_entry_from_storage() { EmaOracle::on_initialize(6); for period in ::SupportedPeriods::get() { - assert_eq!( - get_oracle_entry(HDX, DOT, period), - Some(ORACLE_ENTRY_1), - ); + assert_eq!(get_oracle_entry(HDX, DOT, period), Some(ORACLE_ENTRY_1),); } assert_ok!(EmaOracle::remove_oracle(RuntimeOrigin::root(), SOURCE, (HDX, DOT))); assert!(!WhitelistedAssets::::get().contains(&(SOURCE, (HDX, DOT)))); for period in ::SupportedPeriods::get() { - assert_eq!( - get_oracle_entry(HDX, DOT, period), - None, - ); + assert!(get_oracle_entry(HDX, DOT, period).is_none()); } EmaOracle::on_finalize(6); @@ -142,7 +136,7 @@ fn on_trade_should_include_whitelisted_oracle_for_correct_source() { (HDX, INSUFFICIENT_ASSET) )); - assert_eq!(get_accumulator_entry(SOURCE, (HDX, INSUFFICIENT_ASSET)), None); + assert!(get_accumulator_entry(SOURCE, (HDX, INSUFFICIENT_ASSET)).is_none()); assert_ok!(OnActivityHandler::::on_trade( SOURCE, @@ -169,7 +163,7 @@ fn on_liquidity_changed_should_include_whitelisted_oracle_for_correct_source() { (HDX, INSUFFICIENT_ASSET) )); - assert_eq!(get_accumulator_entry(SOURCE, (HDX, INSUFFICIENT_ASSET)), None); + assert!(get_accumulator_entry(SOURCE, (HDX, INSUFFICIENT_ASSET)).is_none()); assert_ok!(OnActivityHandler::::on_liquidity_changed( SOURCE, diff --git a/pallets/ema-oracle/src/tests/mock.rs b/pallets/ema-oracle/src/tests/mock.rs index 6c063f375..cb492235b 100644 --- a/pallets/ema-oracle/src/tests/mock.rs +++ b/pallets/ema-oracle/src/tests/mock.rs @@ -126,10 +126,10 @@ parameter_types! { pub SupportedPeriods: BoundedVec> = bounded_vec![LastBlock, TenMinutes, Day, Week]; } -pub struct SufficientAssetsFilter; -impl Contains<(Source, AssetId, AssetId)> for SufficientAssetsFilter { +pub struct OracleWhitelist; +impl Contains<(Source, AssetId, AssetId)> for OracleWhitelist { fn contains(t: &(Source, AssetId, AssetId)) -> bool { - t.1 != INSUFFICIENT_ASSET && t.2 != INSUFFICIENT_ASSET + (t.1 != INSUFFICIENT_ASSET && t.2 != INSUFFICIENT_ASSET) || ema_oracle::OracleWhitelist::::contains(t) } } @@ -138,7 +138,7 @@ impl Config for Test { type AuthorityOrigin = EnsureRoot; type BlockNumberProvider = System; type SupportedPeriods = SupportedPeriods; - type OracleWhitelist = SufficientAssetsFilter; + type OracleWhitelist = OracleWhitelist; type MaxUniqueEntries = ConstU32<45>; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = (); diff --git a/runtime/hydradx/src/assets.rs b/runtime/hydradx/src/assets.rs index 297b031c5..88d547502 100644 --- a/runtime/hydradx/src/assets.rs +++ b/runtime/hydradx/src/assets.rs @@ -497,10 +497,15 @@ parameter_types! { OraclePeriod::LastBlock, OraclePeriod::Short, OraclePeriod::TenMinutes]); } -pub struct SufficientAssetsFilter; -impl Contains<(Source, AssetId, AssetId)> for SufficientAssetsFilter { +pub struct OracleWhitelist(PhantomData); +impl Contains<(Source, AssetId, AssetId)> for OracleWhitelist +where + Runtime: pallet_ema_oracle::Config + pallet_asset_registry::Config, + AssetId: From<::AssetId>, +{ fn contains(t: &(Source, AssetId, AssetId)) -> bool { - AssetRegistry::is_sufficient(t.1) && AssetRegistry::is_sufficient(t.2) + pallet_asset_registry::OracleWhitelist::::contains(t) + || pallet_ema_oracle::OracleWhitelist::::contains(t) } } @@ -512,7 +517,7 @@ impl pallet_ema_oracle::Config for Runtime { /// to which smoothing factor. type BlockNumberProvider = System; type SupportedPeriods = SupportedPeriods; - type OracleWhitelist = SufficientAssetsFilter; + type OracleWhitelist = OracleWhitelist; /// With every asset trading against LRNA we will only have as many pairs as there will be assets, so /// 40 seems a decent upper bound for the foreseeable future. type MaxUniqueEntries = ConstU32<40>; From e4b3176b8b961585042274bbb4a4502d2485ca0c Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Tue, 9 Apr 2024 09:59:20 -0500 Subject: [PATCH 12/13] bump crate versions --- Cargo.lock | 4 ++-- integration-tests/Cargo.toml | 2 +- pallets/asset-registry/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f9c415e8c..520d8e8e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6985,7 +6985,7 @@ checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" [[package]] name = "pallet-asset-registry" -version = "3.1.1" +version = "3.1.2" dependencies = [ "frame-benchmarking", "frame-support", @@ -11367,7 +11367,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.19.12" +version = "1.19.13" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 01e988202..aa3541eba 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.19.12" +version = "1.19.13" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/pallets/asset-registry/Cargo.toml b/pallets/asset-registry/Cargo.toml index a4cdc9cf9..edb446cc9 100644 --- a/pallets/asset-registry/Cargo.toml +++ b/pallets/asset-registry/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-asset-registry" -version = "3.1.1" +version = "3.1.2" description = "Pallet for asset registry management" authors = ["GalacticCouncil"] edition = "2021" From 249a797726baccaea8ee0f04198f76c5e78bc7cc Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Tue, 9 Apr 2024 11:54:14 -0500 Subject: [PATCH 13/13] bump crate versions --- Cargo.lock | 10 +++++----- integration-tests/Cargo.toml | 2 +- pallets/asset-registry/Cargo.toml | 2 +- pallets/dca/Cargo.toml | 2 +- pallets/omnipool-liquidity-mining/Cargo.toml | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ecb8f3b11..9da7cfe8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4621,7 +4621,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "226.0.0" +version = "227.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -6986,7 +6986,7 @@ checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" [[package]] name = "pallet-asset-registry" -version = "3.2.0" +version = "3.2.1" dependencies = [ "frame-benchmarking", "frame-support", @@ -7404,7 +7404,7 @@ dependencies = [ [[package]] name = "pallet-dca" -version = "1.4.2" +version = "1.4.3" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -8154,7 +8154,7 @@ dependencies = [ [[package]] name = "pallet-omnipool-liquidity-mining" -version = "2.1.3" +version = "2.1.4" dependencies = [ "frame-benchmarking", "frame-support", @@ -11392,7 +11392,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.20.0" +version = "1.20.1" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 30341369a..15d4791e9 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.20.0" +version = "1.20.1" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/pallets/asset-registry/Cargo.toml b/pallets/asset-registry/Cargo.toml index fe331df95..27b006698 100644 --- a/pallets/asset-registry/Cargo.toml +++ b/pallets/asset-registry/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-asset-registry" -version = "3.2.0" +version = "3.2.1" description = "Pallet for asset registry management" authors = ["GalacticCouncil"] edition = "2021" diff --git a/pallets/dca/Cargo.toml b/pallets/dca/Cargo.toml index 4b50dba37..bf038aee2 100644 --- a/pallets/dca/Cargo.toml +++ b/pallets/dca/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-dca' -version = "1.4.2" +version = "1.4.3" description = 'A pallet to manage DCA scheduling' authors = ['GalacticCouncil'] edition = '2021' diff --git a/pallets/omnipool-liquidity-mining/Cargo.toml b/pallets/omnipool-liquidity-mining/Cargo.toml index c1315670b..f4998e812 100644 --- a/pallets/omnipool-liquidity-mining/Cargo.toml +++ b/pallets/omnipool-liquidity-mining/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-omnipool-liquidity-mining" -version = "2.1.3" +version = "2.1.4" authors = ['GalacticCouncil'] edition = "2021" license = "Apache-2.0" diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index 1202cae2b..ff05f3b82 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "226.0.0" +version = "227.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 a4af2b3ad..36a3c5bb2 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: 226, + spec_version: 227, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1,