From 3d2b54096baec763eb291281170b0ff8e9066bd0 Mon Sep 17 00:00:00 2001 From: yooml Date: Mon, 29 Jul 2024 22:04:32 +0800 Subject: [PATCH] Optimize oracle (#1318) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 💡 optimize orml-oracle * fix: 🐛 MinimumTimestampInterval * style: 💄 rename to MaximumValueInterval --- Cargo.lock | 16 ++++++++-------- pallets/prices/src/lib.rs | 2 +- runtime/bifrost-kusama/src/lib.rs | 15 ++++++++++++--- runtime/bifrost-polkadot/src/lib.rs | 15 ++++++++++++--- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 59ff69c81..fabfe194f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7829,7 +7829,7 @@ dependencies = [ [[package]] name = "orml-oracle" version = "0.13.0" -source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.13.0#809507e5290453afde82e8954c502260e7e59bd7" +source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.13.0#a7ea052e958275502022b25f1fc1e5b0e146fe51" dependencies = [ "frame-benchmarking", "frame-support", @@ -7848,7 +7848,7 @@ dependencies = [ [[package]] name = "orml-tokens" version = "0.13.0" -source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.13.0#809507e5290453afde82e8954c502260e7e59bd7" +source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.13.0#a7ea052e958275502022b25f1fc1e5b0e146fe51" dependencies = [ "frame-support", "frame-system", @@ -7865,7 +7865,7 @@ dependencies = [ [[package]] name = "orml-traits" version = "0.13.0" -source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.13.0#809507e5290453afde82e8954c502260e7e59bd7" +source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.13.0#a7ea052e958275502022b25f1fc1e5b0e146fe51" dependencies = [ "frame-support", "impl-trait-for-tuples", @@ -7885,7 +7885,7 @@ dependencies = [ [[package]] name = "orml-unknown-tokens" version = "0.13.0" -source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.13.0#809507e5290453afde82e8954c502260e7e59bd7" +source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.13.0#a7ea052e958275502022b25f1fc1e5b0e146fe51" dependencies = [ "frame-support", "frame-system", @@ -7900,7 +7900,7 @@ dependencies = [ [[package]] name = "orml-utilities" version = "0.13.0" -source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.13.0#809507e5290453afde82e8954c502260e7e59bd7" +source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.13.0#a7ea052e958275502022b25f1fc1e5b0e146fe51" dependencies = [ "frame-support", "parity-scale-codec", @@ -7915,7 +7915,7 @@ dependencies = [ [[package]] name = "orml-xcm" version = "0.13.0" -source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.13.0#809507e5290453afde82e8954c502260e7e59bd7" +source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.13.0#a7ea052e958275502022b25f1fc1e5b0e146fe51" dependencies = [ "frame-support", "frame-system", @@ -7929,7 +7929,7 @@ dependencies = [ [[package]] name = "orml-xcm-support" version = "0.13.0" -source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.13.0#809507e5290453afde82e8954c502260e7e59bd7" +source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.13.0#a7ea052e958275502022b25f1fc1e5b0e146fe51" dependencies = [ "frame-support", "orml-traits", @@ -7943,7 +7943,7 @@ dependencies = [ [[package]] name = "orml-xtokens" version = "0.13.0" -source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.13.0#809507e5290453afde82e8954c502260e7e59bd7" +source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.13.0#a7ea052e958275502022b25f1fc1e5b0e146fe51" dependencies = [ "frame-support", "frame-system", diff --git a/pallets/prices/src/lib.rs b/pallets/prices/src/lib.rs index 28339aa0b..3668e2b1e 100644 --- a/pallets/prices/src/lib.rs +++ b/pallets/prices/src/lib.rs @@ -27,7 +27,7 @@ use bifrost_primitives::*; use frame_support::{dispatch::DispatchClass, pallet_prelude::*, transactional}; use frame_system::pallet_prelude::*; use log; -use orml_traits::{DataFeeder, DataProvider, DataProviderExtended}; +use orml_oracle::{DataFeeder, DataProvider, DataProviderExtended}; pub use pallet::*; use pallet_traits::*; use sp_runtime::{traits::CheckedDiv, FixedU128}; diff --git a/runtime/bifrost-kusama/src/lib.rs b/runtime/bifrost-kusama/src/lib.rs index bc8e30c08..9118a5d5b 100644 --- a/runtime/bifrost-kusama/src/lib.rs +++ b/runtime/bifrost-kusama/src/lib.rs @@ -56,7 +56,7 @@ use sp_runtime::{ AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, StaticLookup, Zero, }, transaction_validity::{TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, DispatchError, DispatchResult, Perbill, Permill, RuntimeDebug, + ApplyExtrinsicResult, DispatchError, DispatchResult, FixedU128, Perbill, Permill, RuntimeDebug, SaturatedConversion, }; use sp_std::{marker::PhantomData, prelude::*}; @@ -1608,14 +1608,22 @@ parameter_types! { pub const ExpiresIn: Moment = 1000 * 60 * 60; // 60 mins pub const MaxHasDispatchedSize: u32 = 100; pub OracleRootOperatorAccountId: AccountId = OraclePalletId::get().into_account_truncating(); + pub const MinimumTimestampInterval: Moment = 1000 * 60 * 10; // 10 mins + pub const MaximumValueInterval: Price = FixedU128::from_inner(3_000_000_000_000_000); // 0.3% } type BifrostDataProvider = orml_oracle::Instance1; impl orml_oracle::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OnNewData = (); - type CombineData = - orml_oracle::DefaultCombineData; + type CombineData = orml_oracle::DefaultCombineData< + Runtime, + MinimumCount, + ExpiresIn, + MinimumTimestampInterval, + MaximumValueInterval, + BifrostDataProvider, + >; type Time = Timestamp; type OracleKey = CurrencyId; type OracleValue = Price; @@ -1624,6 +1632,7 @@ impl orml_oracle::Config for Runtime { type WeightInfo = weights::orml_oracle::WeightInfo; type Members = OracleMembership; type MaxFeedValues = ConstU32<100>; + type ControlOrigin = TechAdminOrCouncil; } pub type TimeStampedPrice = orml_oracle::TimestampedValue; diff --git a/runtime/bifrost-polkadot/src/lib.rs b/runtime/bifrost-polkadot/src/lib.rs index c015b9b11..771777e8c 100644 --- a/runtime/bifrost-polkadot/src/lib.rs +++ b/runtime/bifrost-polkadot/src/lib.rs @@ -56,7 +56,7 @@ use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, traits::{AccountIdConversion, BlakeTwo256, Block as BlockT, Zero}, transaction_validity::{TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, DispatchError, DispatchResult, Perbill, Permill, RuntimeDebug, + ApplyExtrinsicResult, DispatchError, DispatchResult, FixedU128, Perbill, Permill, RuntimeDebug, }; use sp_std::{marker::PhantomData, prelude::*}; #[cfg(feature = "std")] @@ -1424,14 +1424,22 @@ parameter_types! { pub const ExpiresIn: Moment = 1000 * 60 * 60; // 60 mins pub const MaxHasDispatchedSize: u32 = 100; pub OracleRootOperatorAccountId: AccountId = OraclePalletId::get().into_account_truncating(); + pub const MinimumTimestampInterval: Moment = 1000 * 60 * 10; // 10 mins + pub const MaximumValueInterval: Price = FixedU128::from_inner(3_000_000_000_000_000); // 0.3% } type BifrostDataProvider = orml_oracle::Instance1; impl orml_oracle::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OnNewData = (); - type CombineData = - orml_oracle::DefaultCombineData; + type CombineData = orml_oracle::DefaultCombineData< + Runtime, + MinimumCount, + ExpiresIn, + MinimumTimestampInterval, + MaximumValueInterval, + BifrostDataProvider, + >; type Time = Timestamp; type OracleKey = CurrencyId; type OracleValue = Price; @@ -1440,6 +1448,7 @@ impl orml_oracle::Config for Runtime { type WeightInfo = weights::orml_oracle::WeightInfo; type Members = OracleMembership; type MaxFeedValues = ConstU32<100>; + type ControlOrigin = TechAdminOrCouncil; } pub type TimeStampedPrice = orml_oracle::TimestampedValue;