From 46ec202bdcd3533b0dd88aeeb996571d30a63ce4 Mon Sep 17 00:00:00 2001 From: yooml Date: Mon, 29 Jul 2024 17:13:42 +0800 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20optimize=20orml-?= =?UTF-8?q?oracle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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..678c2bd1b 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#95c1fe4d281fd23711ad4f7be034acbb89ea6a34" 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#95c1fe4d281fd23711ad4f7be034acbb89ea6a34" 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#95c1fe4d281fd23711ad4f7be034acbb89ea6a34" 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#95c1fe4d281fd23711ad4f7be034acbb89ea6a34" 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#95c1fe4d281fd23711ad4f7be034acbb89ea6a34" 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#95c1fe4d281fd23711ad4f7be034acbb89ea6a34" 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#95c1fe4d281fd23711ad4f7be034acbb89ea6a34" 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#95c1fe4d281fd23711ad4f7be034acbb89ea6a34" 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..308e5074e 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 = 10 * 1000; // 10 mins + pub const MinimumValueInterval: 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, + MinimumValueInterval, + 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..6714ec5c2 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 = 10 * 1000; // 10 mins + pub const MinimumValueInterval: 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, + MinimumValueInterval, + 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; From db35ab7f3f5c66d573a634edbf991a5835d08343 Mon Sep 17 00:00:00 2001 From: yooml Date: Mon, 29 Jul 2024 17:53:07 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=F0=9F=90=9B=20MinimumTimestampInter?= =?UTF-8?q?val?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/bifrost-kusama/src/lib.rs | 2 +- runtime/bifrost-polkadot/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/bifrost-kusama/src/lib.rs b/runtime/bifrost-kusama/src/lib.rs index 308e5074e..e1d9a8c92 100644 --- a/runtime/bifrost-kusama/src/lib.rs +++ b/runtime/bifrost-kusama/src/lib.rs @@ -1608,7 +1608,7 @@ 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 = 10 * 1000; // 10 mins + pub const MinimumTimestampInterval: Moment = 1000 * 60 * 10; // 10 mins pub const MinimumValueInterval: Price = FixedU128::from_inner(3_000_000_000_000_000); // 0.3% } diff --git a/runtime/bifrost-polkadot/src/lib.rs b/runtime/bifrost-polkadot/src/lib.rs index 6714ec5c2..978fdfd51 100644 --- a/runtime/bifrost-polkadot/src/lib.rs +++ b/runtime/bifrost-polkadot/src/lib.rs @@ -1424,7 +1424,7 @@ 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 = 10 * 1000; // 10 mins + pub const MinimumTimestampInterval: Moment = 1000 * 60 * 10; // 10 mins pub const MinimumValueInterval: Price = FixedU128::from_inner(3_000_000_000_000_000); // 0.3% } From c84ec508582cb726e2ea59149911a729376fce01 Mon Sep 17 00:00:00 2001 From: yooml Date: Mon, 29 Jul 2024 20:52:51 +0800 Subject: [PATCH 3/3] =?UTF-8?q?style:=20=F0=9F=92=84=20rename=20to=20Maxim?= =?UTF-8?q?umValueInterval?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 16 ++++++++-------- runtime/bifrost-kusama/src/lib.rs | 4 ++-- runtime/bifrost-polkadot/src/lib.rs | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 678c2bd1b..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#95c1fe4d281fd23711ad4f7be034acbb89ea6a34" +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#95c1fe4d281fd23711ad4f7be034acbb89ea6a34" +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#95c1fe4d281fd23711ad4f7be034acbb89ea6a34" +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#95c1fe4d281fd23711ad4f7be034acbb89ea6a34" +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#95c1fe4d281fd23711ad4f7be034acbb89ea6a34" +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#95c1fe4d281fd23711ad4f7be034acbb89ea6a34" +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#95c1fe4d281fd23711ad4f7be034acbb89ea6a34" +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#95c1fe4d281fd23711ad4f7be034acbb89ea6a34" +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/runtime/bifrost-kusama/src/lib.rs b/runtime/bifrost-kusama/src/lib.rs index e1d9a8c92..9118a5d5b 100644 --- a/runtime/bifrost-kusama/src/lib.rs +++ b/runtime/bifrost-kusama/src/lib.rs @@ -1609,7 +1609,7 @@ parameter_types! { pub const MaxHasDispatchedSize: u32 = 100; pub OracleRootOperatorAccountId: AccountId = OraclePalletId::get().into_account_truncating(); pub const MinimumTimestampInterval: Moment = 1000 * 60 * 10; // 10 mins - pub const MinimumValueInterval: Price = FixedU128::from_inner(3_000_000_000_000_000); // 0.3% + pub const MaximumValueInterval: Price = FixedU128::from_inner(3_000_000_000_000_000); // 0.3% } type BifrostDataProvider = orml_oracle::Instance1; @@ -1621,7 +1621,7 @@ impl orml_oracle::Config for Runtime { MinimumCount, ExpiresIn, MinimumTimestampInterval, - MinimumValueInterval, + MaximumValueInterval, BifrostDataProvider, >; type Time = Timestamp; diff --git a/runtime/bifrost-polkadot/src/lib.rs b/runtime/bifrost-polkadot/src/lib.rs index 978fdfd51..771777e8c 100644 --- a/runtime/bifrost-polkadot/src/lib.rs +++ b/runtime/bifrost-polkadot/src/lib.rs @@ -1425,7 +1425,7 @@ parameter_types! { pub const MaxHasDispatchedSize: u32 = 100; pub OracleRootOperatorAccountId: AccountId = OraclePalletId::get().into_account_truncating(); pub const MinimumTimestampInterval: Moment = 1000 * 60 * 10; // 10 mins - pub const MinimumValueInterval: Price = FixedU128::from_inner(3_000_000_000_000_000); // 0.3% + pub const MaximumValueInterval: Price = FixedU128::from_inner(3_000_000_000_000_000); // 0.3% } type BifrostDataProvider = orml_oracle::Instance1; @@ -1437,7 +1437,7 @@ impl orml_oracle::Config for Runtime { MinimumCount, ExpiresIn, MinimumTimestampInterval, - MinimumValueInterval, + MaximumValueInterval, BifrostDataProvider, >; type Time = Timestamp;