Skip to content

Commit

Permalink
Optimize oracle (#1318)
Browse files Browse the repository at this point in the history
* refactor: 💡 optimize orml-oracle

* fix: 🐛 MinimumTimestampInterval

* style: 💄 rename to MaximumValueInterval
  • Loading branch information
yooml authored Jul 29, 2024
1 parent 14da5c8 commit 3d2b540
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pallets/prices/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
15 changes: 12 additions & 3 deletions runtime/bifrost-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*};
Expand Down Expand Up @@ -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<BifrostDataProvider> for Runtime {
type RuntimeEvent = RuntimeEvent;
type OnNewData = ();
type CombineData =
orml_oracle::DefaultCombineData<Runtime, MinimumCount, ExpiresIn, BifrostDataProvider>;
type CombineData = orml_oracle::DefaultCombineData<
Runtime,
MinimumCount,
ExpiresIn,
MinimumTimestampInterval,
MaximumValueInterval,
BifrostDataProvider,
>;
type Time = Timestamp;
type OracleKey = CurrencyId;
type OracleValue = Price;
Expand All @@ -1624,6 +1632,7 @@ impl orml_oracle::Config<BifrostDataProvider> for Runtime {
type WeightInfo = weights::orml_oracle::WeightInfo<Runtime>;
type Members = OracleMembership;
type MaxFeedValues = ConstU32<100>;
type ControlOrigin = TechAdminOrCouncil;
}

pub type TimeStampedPrice = orml_oracle::TimestampedValue<Price, Moment>;
Expand Down
15 changes: 12 additions & 3 deletions runtime/bifrost-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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<BifrostDataProvider> for Runtime {
type RuntimeEvent = RuntimeEvent;
type OnNewData = ();
type CombineData =
orml_oracle::DefaultCombineData<Runtime, MinimumCount, ExpiresIn, BifrostDataProvider>;
type CombineData = orml_oracle::DefaultCombineData<
Runtime,
MinimumCount,
ExpiresIn,
MinimumTimestampInterval,
MaximumValueInterval,
BifrostDataProvider,
>;
type Time = Timestamp;
type OracleKey = CurrencyId;
type OracleValue = Price;
Expand All @@ -1440,6 +1448,7 @@ impl orml_oracle::Config<BifrostDataProvider> for Runtime {
type WeightInfo = weights::orml_oracle::WeightInfo<Runtime>;
type Members = OracleMembership;
type MaxFeedValues = ConstU32<100>;
type ControlOrigin = TechAdminOrCouncil;
}

pub type TimeStampedPrice = orml_oracle::TimestampedValue<Price, Moment>;
Expand Down

0 comments on commit 3d2b540

Please sign in to comment.