diff --git a/Cargo.lock b/Cargo.lock index 77d2375b..f0b3cb88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4677,7 +4677,6 @@ dependencies = [ "pallet-standard-oracle", "pallet-standard-vault", "pallet-sudo", - "pallet-template", "pallet-timestamp", "pallet-tips", "pallet-transaction-payment", @@ -10279,7 +10278,6 @@ dependencies = [ "pallet-standard-oracle", "pallet-standard-vault", "pallet-sudo", - "pallet-template", "pallet-timestamp", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", diff --git a/node/opportunity/src/chain_spec.rs b/node/opportunity/src/chain_spec.rs index f029b61e..838f657e 100644 --- a/node/opportunity/src/chain_spec.rs +++ b/node/opportunity/src/chain_spec.rs @@ -303,8 +303,9 @@ fn opportunity_testnet_config_genesis( next_asset_id: 5, }, oracle: OracleConfig { - oracles: [get_account_id_from_seed::("Alice")].to_vec(), - }, + oracles: [get_account_id_from_seed::("Alice")].to_vec(), + provider_count: 5 + }, democracy: DemocracyConfig::default(), elections: ElectionsConfig::default(), council: CouncilConfig::default(), diff --git a/node/standard/src/chain_spec.rs b/node/standard/src/chain_spec.rs index 52f7b4b8..38634394 100644 --- a/node/standard/src/chain_spec.rs +++ b/node/standard/src/chain_spec.rs @@ -186,7 +186,8 @@ fn make_genesis( next_asset_id: 5, }, oracle: OracleConfig { - oracles: [get_account_id_from_seed::("Alice")].to_vec(), - }, + oracles: [get_account_id_from_seed::("Alice")].to_vec(), + provider_count: 5 + }, } } diff --git a/pallets/asset-registry/src/mock.rs b/pallets/asset-registry/src/mock.rs index 7de8d36e..48bc1b30 100644 --- a/pallets/asset-registry/src/mock.rs +++ b/pallets/asset-registry/src/mock.rs @@ -8,7 +8,7 @@ use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, }; -use crate::{self as asset_registry, Config, Module}; +use crate::{self as asset_registry, Config, Pallet}; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; @@ -19,8 +19,8 @@ frame_support::construct_runtime!( NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic, { - System: frame_system::{Module, Call, Config, Storage, Event}, - Registry: asset_registry::{Module, Call, Storage}, + System: frame_system::{Pallet, Call, Config, Storage, Event}, + Registry: asset_registry::{Pallet, Call, Storage}, } ); @@ -56,7 +56,7 @@ impl system::Config for Test { impl Config for Test { type AssetId = u32; } -pub type AssetRegistryModule = Module; +pub type AssetRegistryModule = Pallet; pub fn new_test_ext() -> sp_io::TestExternalities { system::GenesisConfig::default().build_storage::().unwrap().into() diff --git a/pallets/oracle/src/lib.rs b/pallets/oracle/src/lib.rs index b352cbe3..aa9f22fc 100644 --- a/pallets/oracle/src/lib.rs +++ b/pallets/oracle/src/lib.rs @@ -3,9 +3,12 @@ use frame_support::{decl_error, decl_event, decl_module, decl_storage, ensure}; use frame_system::{ensure_root, ensure_signed}; -use primitives::{AssetId, Balance}; -use sp_runtime::{DispatchError, DispatchResult}; +use primitives::{AssetId, Balance, EraIndex, SocketIndex}; +use sp_runtime::{DispatchError, DispatchResult, Percent}; use sp_std::prelude::*; +mod math; +pub mod weights; +pub use weights::WeightInfo; #[cfg(test)] mod mock; @@ -16,14 +19,9 @@ mod tests; pub trait Config: frame_system::Config { /// The overarching event type. type Event: From> + Into<::Event>; -} -// Uniquely identify a request's specification understood by an Operator -pub type SpecIndex = Vec; -// Uniquely identify a request for a considered Operator -pub type RequestIdentifier = u64; -// The version of the serialized data format -pub type DataVersion = u64; + type WeightInfo: WeightInfo; +} decl_module! { pub struct Module for enum Call where origin: T::Origin { @@ -36,14 +34,11 @@ decl_module! { // Register a new Operator. // Fails with `OperatorAlreadyRegistered` if this Operator (identified by `origin`) has already been registered. #[weight = 10_000] - pub fn register_operator(origin, who: T::AccountId) -> DispatchResult { + pub fn register_operator(origin, _socket: SocketIndex, _who: T::AccountId) -> DispatchResult { ensure_root(origin)?; - - //ensure!(!>::get(&who), Error::::OperatorAlreadyRegistered); - - Operators::::insert(&who, true); - - Self::deposit_event(RawEvent::OperatorRegistered(who)); + Providers::::insert(&_who, true); + Sockets::::insert(_socket, _who.clone()); + Self::deposit_event(RawEvent::OperatorRegistered(_who)); Ok(()) } @@ -51,10 +46,10 @@ decl_module! { // Unregisters an existing Operator // TODO check weight #[weight = 10_000] - pub fn unregister_operator(origin) -> DispatchResult { + pub fn deregister_operator(origin) -> DispatchResult { let who : ::AccountId = ensure_signed(origin)?; - if Operators::::take(who.clone()) { + if Providers::::take(who.clone()) { Self::deposit_event(RawEvent::OperatorUnregistered(who)); Ok(()) } else { @@ -63,43 +58,123 @@ decl_module! { } #[weight = 0] - fn report(origin, _id: AssetId, _price: Balance) { + fn report(origin, _socket: SocketIndex, _id: AssetId, _price: Balance) -> DispatchResult { let who : ::AccountId = ensure_signed(origin)?; - ensure!(Operators::::contains_key(who), Error::::WrongOperator); + ensure!(Providers::::contains_key(who.clone()), Error::::WrongOperator); + ensure!(Sockets::::get(_socket) == who.clone(), Error::::WrongSocket); let results = match Self::asset_price(_id) { Some(mut x) => { - x.push(_price); + x[_socket as usize] = _price; x }, + Some(x) if x.len() != Self::provider_count() as usize => { + let oracles = Self::provider_count(); + let mut batch = vec!{0; oracles as usize}; + batch[_socket as usize] = _price; + batch + } _ => { - vec!{_price} + let oracles = Self::provider_count(); + let mut batch = vec!{0; oracles as usize}; + batch[_socket as usize] = _price; + batch } }; Prices::insert(_id, results); + Self::deposit_event(RawEvent::PriceSubmitted(_socket, who, _price)); + + Ok(()) + } + + /// Slash the validator for a given amount of balance. This can grow the value + /// For now, it just checks the value is an outlier and excludes from the provider slot + /// Effects will be felt at the beginning of the next era. + /// + /// + /// # + /// ---------- + /// Weight: O(1) + /// DB Weight: + /// - Read: Sockets, Prices + /// - Write: Sockets New Account, Sockets Old Account + /// # + #[weight = 10_000] + fn slash(origin, _socket: SocketIndex, _id: AssetId) -> DispatchResult { + let batch = Prices::get(_id).unwrap(); + let value = batch[_socket as usize]; + let det = Self::determine_outlier(batch, value); + ensure!(det, Error::::NotOutlier); + // Add provider to the slash list of the current era + let provider = Self::provider_at(_socket); + Slashes::::insert(1, vec!{provider}); + // remove provider from the slot + Sockets::::remove(_socket); + Ok(()) + } + + #[weight = 10_000] + fn remove_batch(origin, _id: AssetId) { + ensure_root(origin)?; + + Prices::remove(_id); + } + + /// Sets the ideal number of validators. + /// + /// The dispatch origin must be Root. + /// + /// # + /// Weight: O(1) + /// Write: Validator Count + /// # + #[weight = T::WeightInfo::set_validator_count()] + fn set_validator_count(origin, #[compact] new: u32) { + ensure_root(origin)?; + ProviderCount::put(new); + } + + /// Increments the ideal number of validators. + /// + /// The dispatch origin must be Root. + /// + /// # + /// Same as [`set_validator_count`]. + /// # + #[weight = T::WeightInfo::set_validator_count()] + fn increase_validator_count(origin, #[compact] additional: u32) { + ensure_root(origin)?; + ProviderCount::mutate(|n| *n += additional); + } + + /// Scale up the ideal number of validators by a factor. + /// + /// The dispatch origin must be Root. + /// + /// # + /// Same as [`set_validator_count`]. + /// # + #[weight = T::WeightInfo::set_validator_count()] + fn scale_validator_count(origin, factor: Percent) { + ensure_root(origin)?; + ProviderCount::mutate(|n| *n += factor * *n); } + } } decl_event! { pub enum Event where ::AccountId, - Balance = Balance, { - // A request has been accepted. Corresponding fee paiement is reserved - OracleRequest(AccountId, SpecIndex, RequestIdentifier, AccountId, DataVersion, Vec, Vec, Balance), - - // A request has been answered. Corresponding fee paiement is transfered - OracleAnswer(AccountId, RequestIdentifier, AccountId, Vec, Balance), - // A new operator has been registered OperatorRegistered(AccountId), // An existing operator has been unregistered OperatorUnregistered(AccountId), - // A request didn't receive any result in time - KillRequest(RequestIdentifier), + // Price reported by an oracle provider + PriceSubmitted(SocketIndex, AccountId, u128), } } @@ -123,25 +198,39 @@ decl_error! { InsufficientFee, // Price does not exist PriceDoesNotExist, + // Wrong slot to submit + WrongSocket, + // Outlier not determined + NotOutlier } } decl_storage! { trait Store for Module as Oracle { - // the result of the oracle call - pub Result get(fn get_result): i128; // A set of all registered Operator - pub Operators get(fn operator): map hasher(blake2_128_concat) ::AccountId => bool; - + pub Providers get(fn operator): map hasher(blake2_128_concat) ::AccountId => bool; + // Price batch from oracle providers pub Prices get(fn asset_price): map hasher(blake2_128_concat) AssetId => Option>; + // Oracles: key as t + pub Oracles get(fn oracle): map hasher(blake2_128_concat) ::AccountId => Option; + + // Sockets: key as the oracle slot index, value as the oracle provider + pub Sockets get(fn provider_at): map hasher(blake2_128_concat) SocketIndex => ::AccountId; + + // Slash: key as the oracle slot index, value as the array of slashed accounts + pub Slashes get(fn slashes_at): map hasher(blake2_128_concat) EraIndex => Vec<::AccountId>; + + /// The ideal number of staking participants. + pub ProviderCount get(fn provider_count) config(): u32; + } add_extra_genesis { config(oracles): Vec<::AccountId>; build(|config: &GenesisConfig| { for oracle in &config.oracles { - Operators::::insert(oracle, true); + Providers::::insert(oracle, true); } }); } @@ -151,14 +240,37 @@ decl_storage! { impl Module { pub fn price(id: AssetId) -> sp_std::result::Result { match Self::asset_price(id) { - Some(mut reports) => { + Some(reports) => { // get median value - reports.sort(); - let mid = reports.len() / 2; - let median = reports[mid]; - return Ok(median) - }, - None => return Err(DispatchError::from(crate::Error::::PriceDoesNotExist).into()), + let median = Self::get_median(reports); + return Ok(median); + } + None => { + return Err(DispatchError::from(crate::Error::::PriceDoesNotExist).into()); + } } } + + pub fn determine_outlier(batch: Vec, value: Balance) -> bool { + let processed = Self::preprocess(batch); + let len = processed.len(); + let mid = len / 2; + let quartile = mid/2; + let q3 = mid + quartile; + let q1 = mid - quartile; + let iqr = 3 * (processed[q3] - processed[q1]) / 2; + return processed[q3] + iqr < value || processed[q1] - iqr > value; + } + + pub fn get_median(batch: Vec) -> Balance { + let processed = Self::preprocess(batch); + let mid = processed.len() / 2; + processed[mid] + } + + pub fn preprocess(mut batch: Vec) -> Vec { + batch.retain(|&i|i != 0); + batch.sort(); + batch + } } diff --git a/pallets/oracle/src/math.rs b/pallets/oracle/src/math.rs new file mode 100644 index 00000000..3b0eb222 --- /dev/null +++ b/pallets/oracle/src/math.rs @@ -0,0 +1,15 @@ +use crate::Config; +use primitives::Balance; + +/* +pub fn absdiff( + x: Balance, + y: Balance, +) -> Balance { + let z = match x < y { + true => y-x, + _ => x-y, + }; + z +} +*/ diff --git a/pallets/oracle/src/mock.rs b/pallets/oracle/src/mock.rs index d0bbffbd..b659857a 100644 --- a/pallets/oracle/src/mock.rs +++ b/pallets/oracle/src/mock.rs @@ -1,169 +1,107 @@ -#![cfg(test)] - -use crate::{sp_api_hidden_includes_decl_storage::hidden_include::StorageValue, *}; -use frame_support::{impl_outer_event, impl_outer_origin, parameter_types, weights::Weight}; -use frame_system as system; -use pallet_balances as balances; -use pallet_chainlink::CallbackWithParameter; +use crate as oracle; +use crate::*; +use frame_support::{ + assert_ok, parameter_types, + traits::{Currency, FindAuthor, Get, OnInitialize, OneSessionHandler}, + weights::constants::RocksDbWeight, +}; +use pallet_balances; use sp_core::H256; +use sp_io; use sp_runtime::{ - testing::Header, - traits::{BlakeTwo256, IdentityLookup}, - ModuleId, Perbill, + curve::PiecewiseLinear, + testing::{Header, TestXt, UintAuthorityId}, + traits::{IdentityLookup, Zero}, }; -impl_outer_origin! { - pub enum Origin for Test {} -} - -pub mod oracle { - // Re-export needed for `impl_outer_event!`. - pub use super::super::*; -} - -impl_outer_event! { - pub enum TestEvent for Test { - system, - pallet_balances, - pallet_chainlink, - } -} - +/// The AccountId alias in this test module. +pub(crate) type AccountId = u64; +pub(crate) type AccountIndex = u64; +pub(crate) type BlockNumber = u64; pub(crate) type Balance = u128; -// Configure a mock runtime to test the pallet. +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; -#[derive(Clone, Eq, PartialEq)] -pub struct Test; parameter_types! { pub const BlockHashCount: u64 = 250; - pub const MaximumBlockWeight: Weight = 1024; - pub const MaximumBlockLength: u32 = 2 * 1024; - pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75); + pub BlockWeights: frame_system::limits::BlockWeights = + frame_system::limits::BlockWeights::simple_max( + frame_support::weights::constants::WEIGHT_PER_SECOND * 2 + ); + pub const MaxLocks: u32 = 1024; + pub static ExistentialDeposit: Balance = 1; + pub static SlashDeferDuration: EraIndex = 0; + pub static Period: BlockNumber = 5; + pub static Offset: BlockNumber = 0; } -impl system::Config for Test { +impl frame_system::Config for Test { type BaseCallFilter = (); + type BlockWeights = (); + type BlockLength = (); + type DbWeight = RocksDbWeight; type Origin = Origin; - type Call = (); - type Index = u64; - type BlockNumber = u64; + type Index = AccountIndex; + type BlockNumber = BlockNumber; + type Call = Call; type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = u64; - type Header = Header; - type Event = (); + type Hashing = ::sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; type Lookup = IdentityLookup; + type Header = Header; + type Event = Event; type BlockHashCount = BlockHashCount; - type MaximumBlockWeight = MaximumBlockWeight; - type DbWeight = (); - type BlockExecutionWeight = (); - type ExtrinsicBaseWeight = (); - type MaximumExtrinsicWeight = MaximumBlockWeight; - type MaximumBlockLength = MaximumBlockLength; - type AvailableBlockRatio = AvailableBlockRatio; type Version = (); - type PalletInfo = (); - type AccountData = pallet_balances::AccountData; + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); type SystemWeightInfo = (); + type SS58Prefix = (); } - -parameter_types! { - pub const ExistentialDeposit: Balance = 1; - pub const AssetModuleId: ModuleId = ModuleId(*b"stnd/ast"); - pub const ValidityPeriod: u64 = 10; -} - impl pallet_balances::Config for Test { - type Balance = Balance; - type Event = (); + type MaxLocks = (); + type Balance = u128; + type Event = Event; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = (); - type MaxLocks = (); } -impl pallet_standard_token::Config for Test { +impl Config for Test { type WeightInfo = (); - type ModuleId = AssetModuleId; - type Event = (); - type AssetId = u64; -} - -impl pallet_chainlink::Config for Test { - type Event = (); - type Currency = pallet_balances::Module; - type Callback = module2::Call; - type ValidityPeriod = ValidityPeriod; -} - -impl Trait for Test { - type Event = (); + type Event = Event; } -impl module2::Trait for Test {} - -//TODO: make mockup for chainlink integration. -//BLOCKER: chainlink overrides existing events for runtime modules. -pub mod module2 { - use super::*; - - pub trait Trait: frame_system::Trait {} - - frame_support::decl_module! { - pub struct Module for enum Call - where origin: ::Origin - { - #[weight = 0] - pub fn callback(_origin, result: Vec) -> frame_support::dispatch::DispatchResult { - let r : u128 = u128::decode(&mut &result[..]).map_err(|err| err.what())?; - ::put(r); - Ok(()) - } - } +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Pallet, Call, Config, Storage, Event}, + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, + Oracle: oracle::{Pallet, Call, Config, Storage, Event} } - - frame_support::decl_storage! { - trait Store for Module as TestStorage { - pub Result: u128; - } - } - - impl CallbackWithParameter for Call { - fn with_result(&self, result: Vec) -> Option { - match *self { - Call::callback(_) => Some(Call::callback(result)), - _ => None, - } - } - } -} - -pub type System = system::Module; -type Chainlink = pallet_chainlink::Module; -pub type Balances = balances::Module; -pub type Token = pallet_standard_token::Module; -pub type Market = Module; +); pub fn new_test_ext() -> sp_io::TestExternalities { - let mut t = system::GenesisConfig::default().build_storage::().unwrap(); - pallet_balances::GenesisConfig:: { - // Total issuance will be 200 with treasury account initialized at ED. - balances: vec![(0, 100000), (1, 100000), (2, 100000)], + let mut storage = frame_system::GenesisConfig::default() + .build_storage::() + .unwrap(); + + let oracles: Vec = vec![1]; + let provider_count = 5; + oracle::GenesisConfig:: { + oracles, + provider_count, } - .assimilate_storage(&mut t) + .assimilate_storage(&mut storage) .unwrap(); - t.into() -} -pub fn last_event() -> RawEvent { - System::events() - .into_iter() - .map(|r| r.event) - .filter_map(|e| if let TestEvent::chainlink(inner) = e { Some(inner) } else { None }) - .last() - .unwrap() + let mut ext = sp_io::TestExternalities::new(storage); + ext.execute_with(|| System::set_block_number(1)); + ext } diff --git a/pallets/oracle/src/tests.rs b/pallets/oracle/src/tests.rs index 4d9126d4..5c1a9eeb 100644 --- a/pallets/oracle/src/tests.rs +++ b/pallets/oracle/src/tests.rs @@ -1,131 +1,139 @@ #![cfg(test)] use crate::{mock::*, Error}; +use frame_support::error::BadOrigin; use frame_support::{assert_noop, assert_ok}; #[test] -fn operators_can_be_registered() { +fn add_oracle_provider_works() { new_test_ext().execute_with(|| { - System::set_block_number(1); - assert!(!::operator(1)); - assert!(::register_operator(Origin::signed(1)).is_ok()); - assert_eq!(last_event(), RawEvent::OperatorRegistered(1)); - assert!(::operator(1)); - assert!(::unregister_operator(Origin::signed(1)).is_ok()); - assert!(!::operator(1)); - assert_eq!(last_event(), RawEvent::OperatorUnregistered(1)); - }); + // Adding operator requires root. + assert_noop!( + Oracle::register_operator(Origin::signed(11), 1, 1u64), + BadOrigin + ); + assert_ok!(Oracle::register_operator(Origin::root(), 1, 2)); + }) +} +#[test] +fn oracle_report_works() { new_test_ext().execute_with(|| { - assert!(::unregister_operator(Origin::signed(1)).is_err()); - assert!(!::operator(1)); - }); + let provider = 1u64; + + assert_ok!(Oracle::register_operator(Origin::root(), 1, provider)); + + assert_ok!(Oracle::report(Origin::signed(provider.into()), 1, 1, 2)); + + // Oracle should only be able to submit data in a given slot + assert_noop!(Oracle::report(Origin::signed(provider.into()), 2, 1, 2), Error::::WrongSlot); + + assert_eq!(Oracle::asset_price(1), Some(vec! {0,2,0,0,0})); + }) } #[test] -fn initiate_requests() { +fn oracle_slash_works() { new_test_ext().execute_with(|| { - assert!(::register_operator(Origin::signed(1)).is_ok()); - assert!(::initiate_request( - Origin::signed(2), - 1, - vec![], - 1, - vec![], - 0, - module2::Call::::callback(vec![]).into() - ) - .is_err()); - }); + let provider_1 = 1u64; + let provider_2 = 2u64; + let provider_3 = 3u64; + let provider_4 = 4u64; + let provider_5 = 5u64; + let slasher = 6u64; - new_test_ext().execute_with(|| { - assert!(::initiate_request( - Origin::signed(2), - 1, - vec![], - 1, - vec![], - 1, - module2::Call::::callback(vec![]).into() - ) - .is_err()); - }); + // setup batch of oracle providers + assert_ok!(Oracle::register_operator(Origin::root(), 0, provider_1)); + assert_ok!(Oracle::register_operator(Origin::root(), 1, provider_2)); + assert_ok!(Oracle::register_operator(Origin::root(), 2, provider_3)); + assert_ok!(Oracle::register_operator(Origin::root(), 3, provider_4)); + assert_ok!(Oracle::register_operator(Origin::root(), 4, provider_5)); - new_test_ext().execute_with(|| { - assert!(::register_operator(Origin::signed(1)).is_ok()); - assert!(::initiate_request( - Origin::signed(2), - 1, - vec![], - 1, - vec![], - 2, - module2::Call::::callback(vec![]).into() - ) - .is_ok()); - assert!(::callback(Origin::signed(3), 0, 10.encode()).is_err()); - }); + // setup batch of oracle values [1,2,1,2,1] + assert_ok!(Oracle::report(Origin::signed(provider_1.into()), 0, 1, 1)); + assert_ok!(Oracle::report(Origin::signed(provider_2.into()), 1, 1, 2)); + assert_ok!(Oracle::report(Origin::signed(provider_3.into()), 2, 1, 1)); + assert_ok!(Oracle::report(Origin::signed(provider_4.into()), 3, 1, 2)); + assert_ok!(Oracle::report(Origin::signed(provider_5.into()), 4, 1, 1)); + assert_eq!(Oracle::asset_price(1), Some(vec! {1,2,1,2,1})); - new_test_ext().execute_with(|| { - assert!(::callback(Origin::signed(1), 0, 10.encode()).is_err()); - }); + // and one of providers submit an manipulated value which goes out of acceptable error range + assert_ok!(Oracle::report(Origin::signed(provider_1.into()), 0, 1, 4)); + assert_eq!(Oracle::asset_price(1), Some(vec! {4,2,1,2,1})); + // should detect outlier and slash the provider + assert_ok!(Oracle::slash(Origin::signed(slasher), 0, 1)); + // slot for oracle submission is now empty + assert_eq!(Oracle::provider_at(0), 0); + }) +} +#[test] +fn oracle_excludes_zeros_and_return_median() { new_test_ext().execute_with(|| { - System::set_block_number(1); - assert!(::register_operator(Origin::signed(1)).is_ok()); - assert_eq!(last_event(), RawEvent::OperatorRegistered(1)); - - let parameters = ("a", "b"); - let data = parameters.encode(); - assert!(::initiate_request( - Origin::signed(2), - 1, - vec![], - 1, - data.clone(), - 2, - module2::Call::::callback(vec![]).into() - ) - .is_ok()); - assert_eq!( - last_event(), - RawEvent::OracleRequest( - 1, - vec![], - 0, - 2, - 1, - data.clone(), - "Chainlink.callback".into(), - 2 - ) + let provider_1 = 1u64; + let provider_2 = 2u64; + let provider_3 = 3u64; + let provider_4 = 4u64; + let provider_5 = 5u64; + // Adding operator requires root. + assert_noop!( + Oracle::register_operator(Origin::signed(11), 1, provider_1), + BadOrigin ); + // setup batch of oracle providers + assert_ok!(Oracle::register_operator(Origin::root(), 0, provider_1)); + assert_ok!(Oracle::register_operator(Origin::root(), 1, provider_2)); + assert_ok!(Oracle::register_operator(Origin::root(), 2, provider_3)); + assert_ok!(Oracle::register_operator(Origin::root(), 3, provider_4)); + assert_ok!(Oracle::register_operator(Origin::root(), 4, provider_5)); - let r = <(Vec, Vec)>::decode(&mut &data[..]).unwrap().0; - assert_eq!("a", std::str::from_utf8(&r).unwrap()); + // setup batch of oracle values [0,0,1,2,3,4] + assert_ok!(Oracle::report(Origin::signed(provider_1.into()), 0, 1, 0)); + assert_ok!(Oracle::report(Origin::signed(provider_2.into()), 1, 1, 0)); + assert_ok!(Oracle::report(Origin::signed(provider_3.into()), 2, 1, 1)); + assert_ok!(Oracle::report(Origin::signed(provider_4.into()), 3, 1, 2)); + assert_ok!(Oracle::report(Origin::signed(provider_5.into()), 4, 1, 3)); + assert_eq!(Oracle::asset_price(1), Some(vec! {0,0,1,2,3})); - let result = 10; - assert!(::callback(Origin::signed(1), 0, result.encode()).is_ok()); - assert_eq!(module2::Result::get(), result); - }); + // and the median should be 2 + assert_eq!(Oracle::get_median(Oracle::asset_price(1).unwrap()), 2); + + }) } #[test] -pub fn on_finalize() { +fn oracle_excludes_zeros_and_return_median_even() { new_test_ext().execute_with(|| { - assert!(::register_operator(Origin::signed(1)).is_ok()); - assert!(::initiate_request( - Origin::signed(2), - 1, - vec![], - 1, - vec![], - 2, - module2::Call::::callback(vec![]).into() - ) - .is_ok()); - >::on_finalize(20); - // Request has been killed, too old - assert!(::callback(Origin::signed(1), 0, 10.encode()).is_err()); - }); + let provider_1 = 1u64; + let provider_2 = 2u64; + let provider_3 = 3u64; + let provider_4 = 4u64; + let provider_5 = 5u64; + let provider_6 = 6u64; + // Setting provider count requires root. + assert_ok!( + Oracle::set_validator_count(Origin::root(), 6) + ); + // setup batch of oracle providers + assert_ok!(Oracle::register_operator(Origin::root(), 0, provider_1)); + assert_ok!(Oracle::register_operator(Origin::root(), 1, provider_2)); + assert_ok!(Oracle::register_operator(Origin::root(), 2, provider_3)); + assert_ok!(Oracle::register_operator(Origin::root(), 3, provider_4)); + assert_ok!(Oracle::register_operator(Origin::root(), 4, provider_5)); + assert_ok!(Oracle::register_operator(Origin::root(), 5, provider_6)); + + + // setup batch of oracle values [0,0,1,2,3,4] + assert_ok!(Oracle::report(Origin::signed(provider_1.into()), 0, 1, 0)); + assert_ok!(Oracle::report(Origin::signed(provider_2.into()), 1, 1, 0)); + assert_ok!(Oracle::report(Origin::signed(provider_3.into()), 2, 1, 1)); + assert_ok!(Oracle::report(Origin::signed(provider_4.into()), 3, 1, 2)); + assert_ok!(Oracle::report(Origin::signed(provider_5.into()), 4, 1, 3)); + assert_ok!(Oracle::report(Origin::signed(provider_6.into()), 5, 1, 4)); + assert_eq!(Oracle::asset_price(1), Some(vec! {0,0,1,2,3,4})); + + // and the median should be 3 + assert_eq!(Oracle::get_median(Oracle::asset_price(1).unwrap()), 3); + + }) } diff --git a/pallets/oracle/src/weights.rs b/pallets/oracle/src/weights.rs new file mode 100644 index 00000000..54ecdf91 --- /dev/null +++ b/pallets/oracle/src/weights.rs @@ -0,0 +1,382 @@ +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use sp_std::marker::PhantomData; + +/// Weight functions needed for pallet_staking. +pub trait WeightInfo { + fn bond() -> Weight; + fn bond_extra() -> Weight; + fn unbond() -> Weight; + fn withdraw_unbonded_update(s: u32, ) -> Weight; + fn withdraw_unbonded_kill(s: u32, ) -> Weight; + fn validate() -> Weight; + fn kick(k: u32, ) -> Weight; + fn nominate(n: u32, ) -> Weight; + fn chill() -> Weight; + fn set_payee() -> Weight; + fn set_controller() -> Weight; + fn set_validator_count() -> Weight; + fn force_no_eras() -> Weight; + fn force_new_era() -> Weight; + fn force_new_era_always() -> Weight; + fn set_invulnerables(v: u32, ) -> Weight; + fn force_unstake(s: u32, ) -> Weight; + fn cancel_deferred_slash(s: u32, ) -> Weight; + fn payout_stakers_dead_controller(n: u32, ) -> Weight; + fn payout_stakers_alive_staked(n: u32, ) -> Weight; + fn rebond(l: u32, ) -> Weight; + fn set_history_depth(e: u32, ) -> Weight; + fn reap_stash(s: u32, ) -> Weight; + fn new_era(v: u32, n: u32, ) -> Weight; + fn submit_solution_better(v: u32, n: u32, a: u32, w: u32, ) -> Weight; +} + +/// Weights for pallet_staking using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + fn bond() -> Weight { + (76_281_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + fn bond_extra() -> Weight { + (62_062_000 as Weight) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + fn unbond() -> Weight { + (57_195_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + fn withdraw_unbonded_update(s: u32, ) -> Weight { + (58_043_000 as Weight) + // Standard Error: 1_000 + .saturating_add((52_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + fn withdraw_unbonded_kill(s: u32, ) -> Weight { + (89_920_000 as Weight) + // Standard Error: 3_000 + .saturating_add((2_526_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(7 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) + .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) + } + fn validate() -> Weight { + (20_228_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + fn kick(k: u32, ) -> Weight { + (31_066_000 as Weight) + // Standard Error: 11_000 + .saturating_add((17_754_000 as Weight).saturating_mul(k as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(k as Weight))) + .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(k as Weight))) + } + fn nominate(n: u32, ) -> Weight { + (33_494_000 as Weight) + // Standard Error: 23_000 + .saturating_add((5_253_000 as Weight).saturating_mul(n as Weight)) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(n as Weight))) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + fn chill() -> Weight { + (19_396_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + fn set_payee() -> Weight { + (13_449_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn set_controller() -> Weight { + (29_184_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + fn set_validator_count() -> Weight { + (2_266_000 as Weight) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn force_no_eras() -> Weight { + (2_462_000 as Weight) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn force_new_era() -> Weight { + (2_483_000 as Weight) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn force_new_era_always() -> Weight { + (2_495_000 as Weight) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn set_invulnerables(v: u32, ) -> Weight { + (2_712_000 as Weight) + // Standard Error: 0 + .saturating_add((9_000 as Weight).saturating_mul(v as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn force_unstake(s: u32, ) -> Weight { + (60_508_000 as Weight) + // Standard Error: 1_000 + .saturating_add((2_525_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) + .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) + } + fn cancel_deferred_slash(s: u32, ) -> Weight { + (5_886_772_000 as Weight) + // Standard Error: 393_000 + .saturating_add((34_849_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn payout_stakers_dead_controller(n: u32, ) -> Weight { + (127_627_000 as Weight) + // Standard Error: 27_000 + .saturating_add((49_354_000 as Weight).saturating_mul(n as Weight)) + .saturating_add(T::DbWeight::get().reads(11 as Weight)) + .saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(n as Weight))) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(n as Weight))) + } + fn payout_stakers_alive_staked(n: u32, ) -> Weight { + (156_838_000 as Weight) + // Standard Error: 24_000 + .saturating_add((62_653_000 as Weight).saturating_mul(n as Weight)) + .saturating_add(T::DbWeight::get().reads(12 as Weight)) + .saturating_add(T::DbWeight::get().reads((5 as Weight).saturating_mul(n as Weight))) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(n as Weight))) + } + fn rebond(l: u32, ) -> Weight { + (40_110_000 as Weight) + // Standard Error: 1_000 + .saturating_add((78_000 as Weight).saturating_mul(l as Weight)) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + fn set_history_depth(e: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 70_000 + .saturating_add((32_883_000 as Weight).saturating_mul(e as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + .saturating_add(T::DbWeight::get().writes((7 as Weight).saturating_mul(e as Weight))) + } + fn reap_stash(s: u32, ) -> Weight { + (64_605_000 as Weight) + // Standard Error: 1_000 + .saturating_add((2_506_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) + .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) + } + fn new_era(v: u32, n: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 926_000 + .saturating_add((548_212_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 46_000 + .saturating_add((78_343_000 as Weight).saturating_mul(n as Weight)) + .saturating_add(T::DbWeight::get().reads(7 as Weight)) + .saturating_add(T::DbWeight::get().reads((4 as Weight).saturating_mul(v as Weight))) + .saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(n as Weight))) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) + .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(v as Weight))) + } + fn submit_solution_better(v: u32, n: u32, a: u32, w: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 48_000 + .saturating_add((937_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 19_000 + .saturating_add((657_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 48_000 + .saturating_add((70_669_000 as Weight).saturating_mul(a as Weight)) + // Standard Error: 101_000 + .saturating_add((7_658_000 as Weight).saturating_mul(w as Weight)) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().reads((4 as Weight).saturating_mul(a as Weight))) + .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(w as Weight))) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } +} + +// For backwards compatibility and tests +impl WeightInfo for () { + fn bond() -> Weight { + (76_281_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(5 as Weight)) + .saturating_add(RocksDbWeight::get().writes(4 as Weight)) + } + fn bond_extra() -> Weight { + (62_062_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(4 as Weight)) + .saturating_add(RocksDbWeight::get().writes(2 as Weight)) + } + fn unbond() -> Weight { + (57_195_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(5 as Weight)) + .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + } + fn withdraw_unbonded_update(s: u32, ) -> Weight { + (58_043_000 as Weight) + // Standard Error: 1_000 + .saturating_add((52_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(RocksDbWeight::get().reads(5 as Weight)) + .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + } + fn withdraw_unbonded_kill(s: u32, ) -> Weight { + (89_920_000 as Weight) + // Standard Error: 3_000 + .saturating_add((2_526_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(RocksDbWeight::get().reads(7 as Weight)) + .saturating_add(RocksDbWeight::get().writes(8 as Weight)) + .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) + } + fn validate() -> Weight { + (20_228_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + .saturating_add(RocksDbWeight::get().writes(2 as Weight)) + } + fn kick(k: u32, ) -> Weight { + (31_066_000 as Weight) + // Standard Error: 11_000 + .saturating_add((17_754_000 as Weight).saturating_mul(k as Weight)) + .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(k as Weight))) + .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(k as Weight))) + } + fn nominate(n: u32, ) -> Weight { + (33_494_000 as Weight) + // Standard Error: 23_000 + .saturating_add((5_253_000 as Weight).saturating_mul(n as Weight)) + .saturating_add(RocksDbWeight::get().reads(4 as Weight)) + .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(n as Weight))) + .saturating_add(RocksDbWeight::get().writes(2 as Weight)) + } + fn chill() -> Weight { + (19_396_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + .saturating_add(RocksDbWeight::get().writes(2 as Weight)) + } + fn set_payee() -> Weight { + (13_449_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(1 as Weight)) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } + fn set_controller() -> Weight { + (29_184_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(3 as Weight)) + .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + } + fn set_validator_count() -> Weight { + (2_266_000 as Weight) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } + fn force_no_eras() -> Weight { + (2_462_000 as Weight) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } + fn force_new_era() -> Weight { + (2_483_000 as Weight) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } + fn force_new_era_always() -> Weight { + (2_495_000 as Weight) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } + fn set_invulnerables(v: u32, ) -> Weight { + (2_712_000 as Weight) + // Standard Error: 0 + .saturating_add((9_000 as Weight).saturating_mul(v as Weight)) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } + fn force_unstake(s: u32, ) -> Weight { + (60_508_000 as Weight) + // Standard Error: 1_000 + .saturating_add((2_525_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(RocksDbWeight::get().reads(4 as Weight)) + .saturating_add(RocksDbWeight::get().writes(8 as Weight)) + .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) + } + fn cancel_deferred_slash(s: u32, ) -> Weight { + (5_886_772_000 as Weight) + // Standard Error: 393_000 + .saturating_add((34_849_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(RocksDbWeight::get().reads(1 as Weight)) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } + fn payout_stakers_dead_controller(n: u32, ) -> Weight { + (127_627_000 as Weight) + // Standard Error: 27_000 + .saturating_add((49_354_000 as Weight).saturating_mul(n as Weight)) + .saturating_add(RocksDbWeight::get().reads(11 as Weight)) + .saturating_add(RocksDbWeight::get().reads((3 as Weight).saturating_mul(n as Weight))) + .saturating_add(RocksDbWeight::get().writes(2 as Weight)) + .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(n as Weight))) + } + fn payout_stakers_alive_staked(n: u32, ) -> Weight { + (156_838_000 as Weight) + // Standard Error: 24_000 + .saturating_add((62_653_000 as Weight).saturating_mul(n as Weight)) + .saturating_add(RocksDbWeight::get().reads(12 as Weight)) + .saturating_add(RocksDbWeight::get().reads((5 as Weight).saturating_mul(n as Weight))) + .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + .saturating_add(RocksDbWeight::get().writes((3 as Weight).saturating_mul(n as Weight))) + } + fn rebond(l: u32, ) -> Weight { + (40_110_000 as Weight) + // Standard Error: 1_000 + .saturating_add((78_000 as Weight).saturating_mul(l as Weight)) + .saturating_add(RocksDbWeight::get().reads(4 as Weight)) + .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + } + fn set_history_depth(e: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 70_000 + .saturating_add((32_883_000 as Weight).saturating_mul(e as Weight)) + .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + .saturating_add(RocksDbWeight::get().writes(4 as Weight)) + .saturating_add(RocksDbWeight::get().writes((7 as Weight).saturating_mul(e as Weight))) + } + fn reap_stash(s: u32, ) -> Weight { + (64_605_000 as Weight) + // Standard Error: 1_000 + .saturating_add((2_506_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(RocksDbWeight::get().reads(4 as Weight)) + .saturating_add(RocksDbWeight::get().writes(8 as Weight)) + .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) + } + fn new_era(v: u32, n: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 926_000 + .saturating_add((548_212_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 46_000 + .saturating_add((78_343_000 as Weight).saturating_mul(n as Weight)) + .saturating_add(RocksDbWeight::get().reads(7 as Weight)) + .saturating_add(RocksDbWeight::get().reads((4 as Weight).saturating_mul(v as Weight))) + .saturating_add(RocksDbWeight::get().reads((3 as Weight).saturating_mul(n as Weight))) + .saturating_add(RocksDbWeight::get().writes(8 as Weight)) + .saturating_add(RocksDbWeight::get().writes((3 as Weight).saturating_mul(v as Weight))) + } + fn submit_solution_better(v: u32, n: u32, a: u32, w: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 48_000 + .saturating_add((937_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 19_000 + .saturating_add((657_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 48_000 + .saturating_add((70_669_000 as Weight).saturating_mul(a as Weight)) + // Standard Error: 101_000 + .saturating_add((7_658_000 as Weight).saturating_mul(w as Weight)) + .saturating_add(RocksDbWeight::get().reads(6 as Weight)) + .saturating_add(RocksDbWeight::get().reads((4 as Weight).saturating_mul(a as Weight))) + .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(w as Weight))) + .saturating_add(RocksDbWeight::get().writes(2 as Weight)) + } +} \ No newline at end of file diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 939f5cc8..fd3d36f6 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -3,11 +3,29 @@ use sp_runtime::{generic, traits::{BlakeTwo256}, OpaqueExtrinsic}; pub type BlockNumber = u32; +pub type Header = generic::Header; +pub type Block = generic::Block; + +/// Balance for and account pub type Balance = u128; + +/// Index for identifying an asset pub type AssetId = u32; + +/// Amount to send a currency pub type Amount = i128; + +/// Index for identifying currency pub type CurrencyId = u32; -pub type Header = generic::Header; -pub type Block = generic::Block; + +/// Counter for the number of eras that have passed. +pub type EraIndex = u64; + +/// Index for oracle to provide information +pub type SocketIndex = u32; pub const CORE_ASSET_ID: AssetId = 0; + + + + diff --git a/runtime/opportunity/Cargo.toml b/runtime/opportunity/Cargo.toml index ce1e76aa..6bcf58ed 100644 --- a/runtime/opportunity/Cargo.toml +++ b/runtime/opportunity/Cargo.toml @@ -40,7 +40,6 @@ pallet-staking-reward-curve = { default-features = false, version = '3.0.0', git pallet-standard-market = { path = '../../pallets/market', default_features = false } pallet-standard-oracle = { path = "../../pallets/oracle", default-features = false } pallet-standard-vault = { path = '../../pallets/vault', default_features = false } -pallet-template = { path = "../../pallets/template", default-features = false } pallet-tips = { version = "3.0.0", default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.6" } pallet-treasury = { version = "3.0.0", default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.6" } # consensus pallet @@ -237,7 +236,6 @@ runtime-benchmarks = [ 'frame-system/runtime-benchmarks', 'pallet-balances/runtime-benchmarks', 'pallet-timestamp/runtime-benchmarks', - 'pallet-template/runtime-benchmarks', ] std = [ 'codec/std', diff --git a/runtime/opportunity/src/lib.rs b/runtime/opportunity/src/lib.rs index 86a6b498..45d26d89 100644 --- a/runtime/opportunity/src/lib.rs +++ b/runtime/opportunity/src/lib.rs @@ -60,8 +60,6 @@ use orml_traits::parameter_type_with_key; use primitives::{AssetId, Balance}; -/// Import the template pallet. -pub use pallet_template; pub mod constants; /// Constant values used within the runtime. use constants::{currency::*, time::*}; @@ -776,15 +774,6 @@ impl pallet_sudo::Config for Runtime { pub type Amount = i128; pub type CurrencyId = u32; -parameter_types! { - pub const TemplatePalletId: PalletId = PalletId(*b"template"); -} - -impl pallet_template::Config for Runtime { - type Event = Event; - type PalletId = TemplatePalletId; -} - parameter_type_with_key! { pub ExistentialDeposits: |_currency_id: CurrencyId| -> Balance { Zero::zero() @@ -792,6 +781,7 @@ parameter_type_with_key! { } parameter_types! { + pub const TemplatePalletId: PalletId = PalletId(*b"template"); pub TreasuryModuleAccount: AccountId = TemplatePalletId::get().into_account(); } @@ -824,6 +814,7 @@ impl pallet_asset_registry::Config for Runtime { impl pallet_standard_oracle::Config for Runtime { type Event = Event; + type WeightInfo = pallet_standard_oracle::weights::SubstrateWeight; } parameter_types! { @@ -905,8 +896,6 @@ construct_runtime!( Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event}, Bounties: pallet_bounties::{Pallet, Call, Storage, Event}, Tips: pallet_tips::{Pallet, Call, Storage, Event}, - // Include the custom logic from the template pallet in the runtime. - TemplateModule: pallet_template::{Pallet, Call, Storage, Event}, Tokens: orml_tokens::{Pallet, Storage, Call, Event, Config}, Currencies: orml_currencies::{Pallet, Storage, Call, Event}, AssetRegistry: pallet_asset_registry::{Pallet, Storage, Config}, @@ -1133,4 +1122,4 @@ sp_api::impl_runtime_apis! { Ok(batches) } } -} +} \ No newline at end of file diff --git a/runtime/standard/Cargo.toml b/runtime/standard/Cargo.toml index 9b5dbc51..fcc480ac 100644 --- a/runtime/standard/Cargo.toml +++ b/runtime/standard/Cargo.toml @@ -69,11 +69,6 @@ xcm = { git = "https://github.com/paritytech/polkadot", default-features = false xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.6" } xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.6" } -[dependencies.template] -default-features = false -package = 'pallet-template' -path = '../../pallets/template' - [build-dependencies] substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.6", default-features = false } @@ -133,5 +128,4 @@ std = [ 'pallet-standard-oracle/std', 'pallet-standard-market/std', 'pallet-standard-vault/std', - 'template/std', -] +] \ No newline at end of file diff --git a/runtime/standard/src/lib.rs b/runtime/standard/src/lib.rs index edb72f51..c39f3643 100644 --- a/runtime/standard/src/lib.rs +++ b/runtime/standard/src/lib.rs @@ -55,7 +55,6 @@ pub use sp_runtime::BuildStorage; use orml_currencies::BasicCurrencyAdapter; use orml_traits::parameter_type_with_key; use primitives::{Amount, AssetId, Balance, CurrencyId}; -pub use template; /// Constant values used within the runtime. pub mod constants; @@ -453,7 +452,8 @@ parameter_type_with_key! { } parameter_types! { - pub TreasuryModuleAccount: AccountId = TemplatePalletId::get().into_account(); + pub const TreasuryPalletId: PalletId = PalletId(*b"ty/trsry"); + pub TreasuryModuleAccount: AccountId = TreasuryPalletId::get().into_account(); } impl orml_tokens::Config for Runtime { @@ -485,6 +485,7 @@ impl pallet_asset_registry::Config for Runtime { impl pallet_standard_oracle::Config for Runtime { type Event = Event; + type WeightInfo = pallet_standard_oracle::weights::SubstrateWeight; } parameter_types! { @@ -516,15 +517,6 @@ parameter_types! { pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000_000u128); } -parameter_types! { - pub const TemplatePalletId: PalletId = PalletId(*b"template"); -} - -impl template::Config for Runtime { - type Event = Event; - type PalletId = TemplatePalletId; -} - impl pallet_transaction_payment::Config for Runtime { type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter; type TransactionByteFee = TransactionByteFee; @@ -582,7 +574,6 @@ construct_runtime!( Tokens: orml_tokens::{Pallet, Storage, Call, Event, Config}, Currencies: orml_currencies::{Pallet, Call, Event}, - TemplatePallet: template::{Pallet, Call, Storage, Event}, AssetRegistry: pallet_asset_registry::{Pallet, Storage, Config}, Market: pallet_standard_market::{Pallet, Call, Storage, Event}, Oracle: pallet_standard_oracle::{Pallet, Call, Storage, Event, Config}, @@ -767,4 +758,4 @@ cumulus_pallet_parachain_system::register_validate_block! { Runtime = Runtime, BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::, CheckInherents = CheckInherents, -} +} \ No newline at end of file