diff --git a/primitives/src/traits.rs b/primitives/src/traits.rs
index 966592ff0..ee21643ac 100644
--- a/primitives/src/traits.rs
+++ b/primitives/src/traits.rs
@@ -16,11 +16,13 @@
// along with Zeitgeist. If not, see .
mod dispute_api;
+mod market_commons_pallet_api;
mod market_id;
mod swaps;
mod zeitgeist_multi_reservable_currency;
pub use dispute_api::DisputeApi;
+pub use market_commons_pallet_api::MarketCommonsPalletApi;
pub use market_id::MarketId;
pub use swaps::Swaps;
pub use zeitgeist_multi_reservable_currency::ZeitgeistAssetManager;
diff --git a/zrml/market-commons/src/market_commons_pallet_api.rs b/primitives/src/traits/market_commons_pallet_api.rs
similarity index 98%
rename from zrml/market-commons/src/market_commons_pallet_api.rs
rename to primitives/src/traits/market_commons_pallet_api.rs
index 877f47866..246cb3a17 100644
--- a/zrml/market-commons/src/market_commons_pallet_api.rs
+++ b/primitives/src/traits/market_commons_pallet_api.rs
@@ -16,6 +16,7 @@
// along with Zeitgeist. If not, see .
#![allow(clippy::type_complexity)]
+use crate::types::{Market, PoolId};
use frame_support::{
dispatch::{DispatchError, DispatchResult},
pallet_prelude::{MaybeSerializeDeserialize, Member},
@@ -25,7 +26,6 @@ use frame_support::{
};
use parity_scale_codec::MaxEncodedLen;
use sp_runtime::traits::AtLeast32Bit;
-use zeitgeist_primitives::types::{Market, PoolId};
/// Simple disputes - Pallet Api
pub trait MarketCommonsPalletApi {
diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs
index 79cddb1e3..6614c6128 100644
--- a/runtime/common/src/lib.rs
+++ b/runtime/common/src/lib.rs
@@ -988,7 +988,6 @@ macro_rules! impl_config_traits {
// NoopLiquidityMining will be applied only to mainnet once runtimes are separated.
type LiquidityMining = NoopLiquidityMining;
// type LiquidityMining = LiquidityMining;
- type MarketCommons = MarketCommons;
type MaxCategories = MaxCategories;
type MaxDisputes = MaxDisputes;
type MinDisputeDuration = MinDisputeDuration;
diff --git a/zrml/market-commons/src/lib.rs b/zrml/market-commons/src/lib.rs
index 24080a2dd..84dca395d 100644
--- a/zrml/market-commons/src/lib.rs
+++ b/zrml/market-commons/src/lib.rs
@@ -20,13 +20,12 @@
extern crate alloc;
-mod market_commons_pallet_api;
pub mod migrations;
mod mock;
mod tests;
-pub use market_commons_pallet_api::MarketCommonsPalletApi;
pub use pallet::*;
+pub use zeitgeist_primitives::traits::MarketCommonsPalletApi;
#[frame_support::pallet]
mod pallet {
@@ -55,6 +54,12 @@ mod pallet {
pub type MomentOf = <::Timestamp as frame_support::traits::Time>::Moment;
+ type MarketOf = Market<
+ ::AccountId,
+ ::BlockNumber,
+ MomentOf,
+ >;
+
#[pallet::call]
impl Pallet {}
@@ -115,7 +120,7 @@ mod pallet {
// on the storage so next following calls will return yet another incremented number.
//
// Returns `Err` if `MarketId` addition overflows.
- fn next_market_id() -> Result {
+ pub fn next_market_id() -> Result {
let id = MarketCounter::::get();
let new_counter = id.checked_add(&1u8.into()).ok_or(ArithmeticError::Overflow)?;
>::put(new_counter);
@@ -145,25 +150,17 @@ mod pallet {
}
}
- fn market_iter() -> PrefixIterator<(
- Self::MarketId,
- Market,
- )> {
+ fn market_iter() -> PrefixIterator<(Self::MarketId, MarketOf)> {
>::iter()
}
- fn market(
- market_id: &Self::MarketId,
- ) -> Result, DispatchError>
- {
+ fn market(market_id: &Self::MarketId) -> Result, DispatchError> {
>::try_get(market_id).map_err(|_err| Error::::MarketDoesNotExist.into())
}
fn mutate_market(market_id: &Self::MarketId, cb: F) -> DispatchResult
where
- F: FnOnce(
- &mut Market,
- ) -> DispatchResult,
+ F: FnOnce(&mut MarketOf) -> DispatchResult,
{
>::try_mutate(market_id, |opt| {
if let Some(market) = opt {
@@ -174,9 +171,7 @@ mod pallet {
})
}
- fn push_market(
- market: Market,
- ) -> Result {
+ fn push_market(market: MarketOf) -> Result {
let market_id = Self::next_market_id()?;
>::insert(market_id, market);
Ok(market_id)
@@ -228,12 +223,7 @@ mod pallet {
/// Holds all markets
#[pallet::storage]
- pub type Markets = StorageMap<
- _,
- Blake2_128Concat,
- T::MarketId,
- Market>,
- >;
+ pub type Markets = StorageMap<_, Blake2_128Concat, T::MarketId, MarketOf>;
/// The number of markets that have been created (including removed markets) and the next
/// identifier for a created market.
diff --git a/zrml/market-commons/src/tests.rs b/zrml/market-commons/src/tests.rs
index e087c07b1..71ed973c9 100644
--- a/zrml/market-commons/src/tests.rs
+++ b/zrml/market-commons/src/tests.rs
@@ -18,15 +18,17 @@
#![cfg(test)]
use crate::{
- market_commons_pallet_api::MarketCommonsPalletApi,
mock::{ExtBuilder, MarketCommons, Runtime},
MarketCounter, Markets,
};
use frame_support::{assert_err, assert_noop, assert_ok};
use sp_runtime::DispatchError;
-use zeitgeist_primitives::types::{
- AccountIdTest, BlockNumber, Deadlines, Market, MarketCreation, MarketDisputeMechanism,
- MarketPeriod, MarketStatus, MarketType, Moment, ScoringRule,
+use zeitgeist_primitives::{
+ traits::MarketCommonsPalletApi,
+ types::{
+ AccountIdTest, BlockNumber, Deadlines, Market, MarketCreation, MarketDisputeMechanism,
+ MarketPeriod, MarketStatus, MarketType, Moment, ScoringRule,
+ },
};
const MARKET_DUMMY: Market = Market {
diff --git a/zrml/prediction-markets/src/benchmarks.rs b/zrml/prediction-markets/src/benchmarks.rs
index 2c6618134..ea0a96fb5 100644
--- a/zrml/prediction-markets/src/benchmarks.rs
+++ b/zrml/prediction-markets/src/benchmarks.rs
@@ -98,7 +98,7 @@ fn create_market_common(
scoring_rule,
}
.dispatch_bypass_filter(RawOrigin::Signed(caller.clone()).into())?;
- let market_id = T::MarketCommons::latest_market_id()?;
+ let market_id = >::latest_market_id()?;
Ok((caller, market_id))
}
@@ -114,7 +114,7 @@ fn create_close_and_report_market(
create_market_common::(permission, options, ScoringRule::CPMM, Some(period))?;
Call::::admin_move_market_to_closed { market_id }
.dispatch_bypass_filter(T::CloseOrigin::successful_origin())?;
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
let end: u32 = match market.period {
MarketPeriod::Timestamp(range) => range.end.saturated_into::(),
_ => {
@@ -157,7 +157,7 @@ fn setup_redeem_shares_common(
let close_origin = T::CloseOrigin::successful_origin();
let resolve_origin = T::ResolveOrigin::successful_origin();
Call::::admin_move_market_to_closed { market_id }.dispatch_bypass_filter(close_origin)?;
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
let end: u32 = match market.period {
MarketPeriod::Timestamp(range) => range.end.saturated_into::(),
_ => {
@@ -201,7 +201,7 @@ fn setup_reported_categorical_market_with_pool::admin_move_market_to_closed { market_id }
.dispatch_bypass_filter(T::CloseOrigin::successful_origin())?;
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
let end: u32 = match market.period {
MarketPeriod::Timestamp(range) => range.end.saturated_into::(),
_ => {
@@ -239,7 +239,7 @@ benchmarks! {
OutcomeReport::Categorical(0u16),
)?;
- let pool_id = T::MarketCommons::market_pool(&market_id)?;
+ let pool_id = >::market_pool(&market_id)?;
for i in 1..=d {
let outcome = OutcomeReport::Categorical((i % a).saturated_into());
@@ -249,7 +249,7 @@ benchmarks! {
let _ = Pallet::::dispute(RawOrigin::Signed(disputor).into(), market_id, outcome)?;
}
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
let (range_start, range_end) = match market.period {
MarketPeriod::Timestamp(range) => (range.start, range.end),
@@ -303,9 +303,9 @@ benchmarks! {
OutcomeReport::Categorical(0u16),
)?;
- let pool_id = T::MarketCommons::market_pool(&market_id)?;
+ let pool_id = >::market_pool(&market_id)?;
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
let (range_start, range_end) = match market.period {
MarketPeriod::Timestamp(range) => (range.start, range.end),
@@ -385,7 +385,7 @@ benchmarks! {
OutcomeReport::Scalar(u128::MAX),
)?;
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
let report_at = market.report.unwrap().at;
let resolves_at = report_at.saturating_add(market.deadlines.dispute_duration);
@@ -416,12 +416,12 @@ benchmarks! {
categories.into(),
OutcomeReport::Categorical(0u16),
)?;
- T::MarketCommons::mutate_market(&market_id, |market| {
+ >::mutate_market(&market_id, |market| {
market.dispute_mechanism = MarketDisputeMechanism::Authorized;
Ok(())
})?;
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
let report_at = market.report.unwrap().at;
let resolves_at = report_at.saturating_add(market.deadlines.dispute_duration);
@@ -454,12 +454,12 @@ benchmarks! {
OutcomeReport::Scalar(u128::MAX),
)?;
- T::MarketCommons::mutate_market(&market_id, |market| {
+ >::mutate_market(&market_id, |market| {
market.dispute_mechanism = MarketDisputeMechanism::Authorized;
Ok(())
})?;
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
if let MarketType::Scalar(range) = market.market_type {
assert!((d as u128) < *range.end());
} else {
@@ -511,7 +511,7 @@ benchmarks! {
OutcomeReport::Categorical(0u16)
)?;
- T::MarketCommons::mutate_market(&market_id, |market| {
+ >::mutate_market(&market_id, |market| {
market.dispute_mechanism = MarketDisputeMechanism::Authorized;
Ok(())
})?;
@@ -529,7 +529,7 @@ benchmarks! {
}
let disputes = Disputes::::get(market_id);
let last_dispute = disputes.last().unwrap();
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
let resolves_at = last_dispute.at.saturating_add(market.deadlines.dispute_duration);
for i in 0..r {
MarketIdsPerDisputeBlock::::try_mutate(
@@ -638,7 +638,7 @@ benchmarks! {
scoring_rule,
}
.dispatch_bypass_filter(RawOrigin::Signed(caller.clone()).into())?;
- let market_id = T::MarketCommons::latest_market_id()?;
+ let market_id = >::latest_market_id()?;
let approve_origin = T::ApproveOrigin::successful_origin();
let edit_reason = vec![0_u8; 1024];
@@ -682,7 +682,7 @@ benchmarks! {
)?;
assert!(
- Pallet::::calculate_time_frame_of_moment(T::MarketCommons::now())
+ Pallet::::calculate_time_frame_of_moment(>::now())
< Pallet::::calculate_time_frame_of_moment(range_start)
);
@@ -728,7 +728,7 @@ benchmarks! {
// We need to ensure, that period range start is now,
// because we would like to open the pool now
- let range_start: MomentOf = T::MarketCommons::now();
+ let range_start: MomentOf = >::now();
let range_end: MomentOf = 1_000_000u64.saturated_into();
let (caller, market_id) = create_market_common::(
MarketCreation::Permissionless,
@@ -737,7 +737,7 @@ benchmarks! {
Some(MarketPeriod::Timestamp(range_start..range_end)),
)?;
- let market = T::MarketCommons::market(&market_id.saturated_into())?;
+ let market = >::market(&market_id.saturated_into())?;
let max_swap_fee: BalanceOf:: = MaxSwapFee::get().saturated_into();
let min_liquidity: BalanceOf:: = MinLiquidity::get().saturated_into();
@@ -759,7 +759,7 @@ benchmarks! {
}: {
call.dispatch_bypass_filter(RawOrigin::Signed(caller).into())?;
} verify {
- let market_pool_id = T::MarketCommons::market_pool(&market_id.saturated_into())?;
+ let market_pool_id = >::market_pool(&market_id.saturated_into())?;
let pool = T::Swaps::pool(market_pool_id)?;
assert_eq!(pool.pool_status, PoolStatus::Active);
}
@@ -821,12 +821,12 @@ benchmarks! {
report_outcome,
)?;
- T::MarketCommons::mutate_market(&market_id, |market| {
+ >::mutate_market(&market_id, |market| {
market.dispute_mechanism = MarketDisputeMechanism::Authorized;
Ok(())
})?;
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
if let MarketType::Scalar(range) = market.market_type {
assert!((d as u128) < *range.end());
} else {
@@ -861,7 +861,7 @@ benchmarks! {
ScoringRule::CPMM,
Some(MarketPeriod::Timestamp(T::MinSubsidyPeriod::get()..T::MaxSubsidyPeriod::get())),
)?;
- let market = T::MarketCommons::market(&market_id.saturated_into())?;
+ let market = >::market(&market_id.saturated_into())?;
}: { Pallet::::handle_expired_advised_market(&market_id, market)? }
internal_resolve_categorical_reported {
@@ -870,15 +870,15 @@ benchmarks! {
categories.into(),
OutcomeReport::Categorical(1u16),
)?;
- T::MarketCommons::mutate_market(&market_id, |market| {
+ >::mutate_market(&market_id, |market| {
market.dispute_mechanism = MarketDisputeMechanism::Authorized;
Ok(())
})?;
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
}: {
Pallet::::on_resolution(&market_id, &market)?;
} verify {
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
assert_eq!(market.status, MarketStatus::Resolved);
}
@@ -892,7 +892,7 @@ benchmarks! {
categories.into(),
OutcomeReport::Categorical(1u16)
)?;
- T::MarketCommons::mutate_market(&market_id, |market| {
+ >::mutate_market(&market_id, |market| {
market.dispute_mechanism = MarketDisputeMechanism::Authorized;
Ok(())
})?;
@@ -905,11 +905,11 @@ benchmarks! {
OutcomeReport::Categorical((i % 2).saturated_into::()),
)?;
}
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
}: {
Pallet::::on_resolution(&market_id, &market)?;
} verify {
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
assert_eq!(market.status, MarketStatus::Resolved);
}
@@ -919,11 +919,11 @@ benchmarks! {
MarketType::Scalar(0u128..=u128::MAX),
OutcomeReport::Scalar(u128::MAX),
)?;
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
}: {
Pallet::::on_resolution(&market_id, &market)?;
} verify {
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
assert_eq!(market.status, MarketStatus::Resolved);
}
@@ -935,11 +935,11 @@ benchmarks! {
MarketType::Scalar(0u128..=u128::MAX),
OutcomeReport::Scalar(u128::MAX),
)?;
- T::MarketCommons::mutate_market(&market_id, |market| {
+ >::mutate_market(&market_id, |market| {
market.dispute_mechanism = MarketDisputeMechanism::Authorized;
Ok(())
})?;
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
if let MarketType::Scalar(range) = market.market_type {
assert!((d as u128) < *range.end());
} else {
@@ -953,11 +953,11 @@ benchmarks! {
OutcomeReport::Scalar(i.into())
)?;
}
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
}: {
Pallet::::on_resolution(&market_id, &market)?;
} verify {
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
assert_eq!(market.status, MarketStatus::Resolved);
}
@@ -1034,7 +1034,7 @@ benchmarks! {
let m in 0..63;
// ensure range.start is now to get the heaviest path
- let range_start: MomentOf = T::MarketCommons::now();
+ let range_start: MomentOf = >::now();
let range_end: MomentOf = 1_000_000u64.saturated_into();
let (caller, market_id) = create_market_common::(
MarketCreation::Permissionless,
@@ -1043,7 +1043,7 @@ benchmarks! {
Some(MarketPeriod::Timestamp(range_start..range_end)),
)?;
- T::MarketCommons::mutate_market(&market_id, |market| {
+ >::mutate_market(&market_id, |market| {
// ensure sender is oracle to succeed extrinsic call
market.oracle = caller.clone();
Ok(())
@@ -1052,7 +1052,7 @@ benchmarks! {
let outcome = OutcomeReport::Categorical(0);
let close_origin = T::CloseOrigin::successful_origin();
Pallet::::admin_move_market_to_closed(close_origin, market_id)?;
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
let end : u32 = match market.period {
MarketPeriod::Timestamp(range) => {
range.end.saturated_into::()
@@ -1103,7 +1103,7 @@ benchmarks! {
Some(MarketPeriod::Timestamp(T::MinSubsidyPeriod::get()..T::MaxSubsidyPeriod::get())),
)?;
let mut market_clone = None;
- T::MarketCommons::mutate_market(&market_id, |market| {
+ >::mutate_market(&market_id, |market| {
market.status = MarketStatus::CollectingSubsidy;
market_clone = Some(market.clone());
Ok(())
@@ -1188,7 +1188,7 @@ benchmarks! {
Some(MarketPeriod::Timestamp(range_start..range_end)),
)?;
// ensure market is reported
- T::MarketCommons::mutate_market(&market_id, |market| {
+ >::mutate_market(&market_id, |market| {
market.status = MarketStatus::Reported;
Ok(())
})?;
diff --git a/zrml/prediction-markets/src/lib.rs b/zrml/prediction-markets/src/lib.rs
index f5d603158..0d327a4d7 100644
--- a/zrml/prediction-markets/src/lib.rs
+++ b/zrml/prediction-markets/src/lib.rs
@@ -75,14 +75,13 @@ mod pallet {
pub(crate) type BalanceOf = <::AssetManager as MultiCurrency<
::AccountId,
>>::Balance;
- pub(crate) type CurrencyOf =
- <::MarketCommons as MarketCommonsPalletApi>::Currency;
+ pub(crate) type CurrencyOf = ::Currency;
pub(crate) type NegativeImbalanceOf =
as Currency<::AccountId>>::NegativeImbalance;
pub(crate) type TimeFrame = u64;
- pub(crate) type MarketIdOf =
- <::MarketCommons as MarketCommonsPalletApi>::MarketId;
- pub(crate) type MomentOf = <::MarketCommons as MarketCommonsPalletApi>::Moment;
+ pub(crate) type MarketIdOf = ::MarketId;
+ pub(crate) type MomentOf =
+ <::Timestamp as frame_support::traits::Time>::Moment;
pub type MarketOf = Market<
::AccountId,
::BlockNumber,
@@ -122,10 +121,10 @@ mod pallet {
// TODO(#618): Not implemented for Rikiddo!
T::DestroyOrigin::ensure_origin(origin)?;
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
ensure!(market.scoring_rule == ScoringRule::CPMM, Error::::InvalidScoringRule);
let market_status = market.status;
- let market_account = T::MarketCommons::market_account(market_id);
+ let market_account = >::market_account(market_id);
// Slash outstanding bonds; see
// https://github.com/zeitgeistpm/runtime-audit-1/issues/34#issuecomment-1120187097 for
@@ -159,17 +158,17 @@ mod pallet {
T::AssetManager::free_balance(Asset::Ztg, &market_account),
);
let mut category_count = 0u32;
- if let Ok(pool_id) = T::MarketCommons::market_pool(&market_id) {
+ if let Ok(pool_id) = >::market_pool(&market_id) {
let pool = T::Swaps::pool(pool_id)?;
category_count = pool.assets.len().saturated_into();
let _ = T::Swaps::destroy_pool(pool_id)?;
- T::MarketCommons::remove_market_pool(&market_id)?;
+ >::remove_market_pool(&market_id)?;
}
let open_ids_len = Self::clear_auto_open(&market_id)?;
let close_ids_len = Self::clear_auto_close(&market_id)?;
let (ids_len, disputes_len) = Self::clear_auto_resolve(&market_id)?;
- T::MarketCommons::remove_market(&market_id)?;
+ >::remove_market(&market_id)?;
Disputes::::remove(market_id);
Self::deposit_event(Event::MarketDestroyed(market_id));
@@ -229,7 +228,7 @@ mod pallet {
) -> DispatchResultWithPostInfo {
// TODO(#638): Handle Rikiddo markets!
T::CloseOrigin::ensure_origin(origin)?;
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
Self::ensure_market_is_active(&market)?;
let open_ids_len = Self::clear_auto_open(&market_id)?;
let close_ids_len = Self::clear_auto_close(&market_id)?;
@@ -273,13 +272,13 @@ mod pallet {
) -> DispatchResultWithPostInfo {
T::ResolveOrigin::ensure_origin(origin)?;
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
ensure!(
market.status == MarketStatus::Reported || market.status == MarketStatus::Disputed,
Error::::InvalidMarketStatus,
);
let (ids_len, disputes_len) = Self::clear_auto_resolve(&market_id)?;
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
let _ = Self::on_resolution(&market_id, &market)?;
let weight = match market.market_type {
MarketType::Scalar(_) => match market.status {
@@ -332,7 +331,7 @@ mod pallet {
let mut extra_weight = 0;
let mut status = MarketStatus::Active;
- T::MarketCommons::mutate_market(&market_id, |m| {
+ >::mutate_market(&market_id, |m| {
ensure!(m.status == MarketStatus::Proposed, Error::::MarketIsNotProposed);
ensure!(
!MarketIdsForEdit::::contains_key(market_id),
@@ -391,7 +390,7 @@ mod pallet {
let edit_reason: EditReason = edit_reason
.try_into()
.map_err(|_| Error::::EditReasonLengthExceedsMaxEditReasonLen)?;
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
ensure!(market.status == MarketStatus::Proposed, Error::::MarketIsNotProposed);
MarketIdsForEdit::::try_mutate(market_id, |reason| {
if reason.is_some() {
@@ -451,7 +450,7 @@ mod pallet {
let who = ensure_signed(origin)?;
let disputes = Disputes::::get(market_id);
let curr_block_num = >::block_number();
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
ensure!(
matches!(market.status, MarketStatus::Reported | MarketStatus::Disputed),
Error::::InvalidMarketStatus
@@ -564,7 +563,7 @@ mod pallet {
.ok_or(Error::::UnexpectedNoneInPostInfo)?;
// Deploy the swap pool and populate it.
- let market_id = T::MarketCommons::latest_market_id()?;
+ let market_id = >::latest_market_id()?;
let deploy_and_populate_weight = Self::deploy_swap_pool_and_additional_liquidity(
origin,
market_id,
@@ -636,8 +635,8 @@ mod pallet {
}
}
- let market_id = T::MarketCommons::push_market(market.clone())?;
- let market_account = T::MarketCommons::market_account(market_id);
+ let market_id = >::push_market(market.clone())?;
+ let market_account = >::market_account(market_id);
let mut extra_weight = 0;
if market.status == MarketStatus::CollectingSubsidy {
@@ -689,7 +688,7 @@ mod pallet {
MarketIdsForEdit::::contains_key(market_id),
Error::::MarketEditNotRequested
);
- let old_market = T::MarketCommons::market(&market_id)?;
+ let old_market = >::market(&market_id)?;
ensure!(old_market.creator == sender, Error::::EditorNotCreator);
ensure!(old_market.status == MarketStatus::Proposed, Error::::InvalidMarketStatus);
@@ -708,7 +707,7 @@ mod pallet {
old_market.report,
old_market.resolved_outcome,
)?;
- T::MarketCommons::mutate_market(&market_id, |market| {
+ >::mutate_market(&market_id, |market| {
*market = edited_market.clone();
Ok(())
})?;
@@ -812,7 +811,7 @@ mod pallet {
) -> DispatchResultWithPostInfo {
let sender = ensure_signed(origin)?;
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
ensure!(market.scoring_rule == ScoringRule::CPMM, Error::::InvalidScoringRule);
Self::ensure_market_is_active(&market)?;
@@ -860,8 +859,9 @@ mod pallet {
}
}
MarketPeriod::Timestamp(ref range) => {
- let current_time_frame =
- Self::calculate_time_frame_of_moment(T::MarketCommons::now());
+ let current_time_frame = Self::calculate_time_frame_of_moment(
+ >::now(),
+ );
let open_time_frame = Self::calculate_time_frame_of_moment(range.start);
if current_time_frame < open_time_frame {
let ids_len = MarketIdsPerOpenTimeFrame::::try_mutate(
@@ -880,7 +880,7 @@ mod pallet {
};
// This errors if a pool already exists!
- T::MarketCommons::insert_market_pool(market_id, pool_id)?;
+ >::insert_market_pool(market_id, pool_id)?;
match ids_len {
Some(market_ids_len) => {
Ok(Some(T::WeightInfo::deploy_swap_pool_for_market_future_pool(
@@ -911,8 +911,8 @@ mod pallet {
) -> DispatchResultWithPostInfo {
let sender = ensure_signed(origin)?;
- let market = T::MarketCommons::market(&market_id)?;
- let market_account = T::MarketCommons::market_account(market_id);
+ let market = >::market(&market_id)?;
+ let market_account = >::market_account(market_id);
ensure!(market.status == MarketStatus::Resolved, Error::::MarketIsNotResolved);
@@ -1053,7 +1053,7 @@ mod pallet {
reject_reason: Vec,
) -> DispatchResultWithPostInfo {
T::RejectOrigin::ensure_origin(origin)?;
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
let open_ids_len = Self::clear_auto_open(&market_id)?;
let close_ids_len = Self::clear_auto_close(&market_id)?;
let reject_reason: RejectReason = reject_reason
@@ -1087,7 +1087,7 @@ mod pallet {
let current_block = >::block_number();
let market_report = Report { at: current_block, by: sender.clone(), outcome };
- T::MarketCommons::mutate_market(&market_id, |market| {
+ >::mutate_market(&market_id, |market| {
ensure!(market.report.is_none(), Error::::MarketAlreadyReported);
Self::ensure_market_is_closed(market)?;
ensure!(
@@ -1118,7 +1118,7 @@ mod pallet {
let grace_period_in_ms =
grace_period_in_moments.saturating_mul(MILLISECS_PER_BLOCK.into());
let grace_period_end = range.end.saturating_add(grace_period_in_ms);
- let now = T::MarketCommons::now();
+ let now = >::now();
ensure!(grace_period_end <= now, Error::::NotAllowedToReportYet);
let oracle_duration_in_moments: MomentOf =
market.deadlines.oracle_duration.saturated_into::().into();
@@ -1147,7 +1147,7 @@ mod pallet {
Ok(())
})?;
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
let block_after_dispute_duration =
current_block.saturating_add(market.deadlines.dispute_duration);
let ids_len = MarketIdsPerReportBlock::::try_mutate(
@@ -1185,11 +1185,11 @@ mod pallet {
let sender = ensure_signed(origin)?;
ensure!(amount != BalanceOf::::zero(), Error::::ZeroAmount);
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
ensure!(market.scoring_rule == ScoringRule::CPMM, Error::::InvalidScoringRule);
Self::ensure_market_is_active(&market)?;
- let market_account = T::MarketCommons::market_account(market_id);
+ let market_account = >::market_account(market_id);
ensure!(
T::AssetManager::free_balance(Asset::Ztg, &market_account) >= amount,
"Market account does not have sufficient reserves.",
@@ -1242,7 +1242,7 @@ mod pallet {
#[cfg(feature = "with-global-disputes")]
{
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
ensure!(market.status == MarketStatus::Disputed, Error::::InvalidMarketStatus);
ensure!(
@@ -1306,7 +1306,7 @@ mod pallet {
}
#[pallet::config]
- pub trait Config: frame_system::Config {
+ pub trait Config: frame_system::Config + zrml_market_commons::Config {
/// The base amount of currency that must be bonded for a market approved by the
/// advisory committee.
#[pallet::constant]
@@ -1383,12 +1383,6 @@ mod pallet {
MarketId = MarketIdOf,
>;
- /// Common market parameters
- type MarketCommons: MarketCommonsPalletApi<
- AccountId = Self::AccountId,
- BlockNumber = Self::BlockNumber,
- >;
-
/// The maximum number of categories available for categorical markets.
#[pallet::constant]
type MaxCategories: Get;
@@ -1642,7 +1636,10 @@ mod pallet {
let mut total_weight: Weight = 0u64;
// TODO(#808): Use weight when Rikiddo is ready
- let _ = Self::process_subsidy_collecting_markets(now, T::MarketCommons::now());
+ let _ = Self::process_subsidy_collecting_markets(
+ now,
+ >::now(),
+ );
total_weight = total_weight
.saturating_add(T::WeightInfo::process_subsidy_collecting_markets_dummy());
@@ -1659,7 +1656,8 @@ mod pallet {
// `on_initialize` is called, so calling `now()` during `on_initialize` gives us
// the timestamp of the previous block.
let current_time_frame =
- Self::calculate_time_frame_of_moment(T::MarketCommons::now()).saturating_add(1);
+ Self::calculate_time_frame_of_moment(>::now())
+ .saturating_add(1);
// On first pass, we use current_time - 1 to ensure that the chain doesn't try to
// check all time frames since epoch.
@@ -1861,7 +1859,7 @@ mod pallet {
}
fn insert_auto_close(market_id: &MarketIdOf) -> Result {
- let market = T::MarketCommons::market(market_id)?;
+ let market = >::market(market_id)?;
match market.period {
MarketPeriod::Block(range) => MarketIdsPerCloseBlock::::try_mutate(
@@ -1883,7 +1881,7 @@ mod pallet {
// Manually remove market from cache for auto close.
fn clear_auto_close(market_id: &MarketIdOf) -> Result {
- let market = T::MarketCommons::market(market_id)?;
+ let market = >::market(market_id)?;
// No-op if market isn't cached for auto close according to its state.
match market.status {
@@ -1913,7 +1911,7 @@ mod pallet {
// Manually remove market from cache for auto open.
fn clear_auto_open(market_id: &MarketIdOf) -> Result {
- let market = T::MarketCommons::market(market_id)?;
+ let market = >::market(market_id)?;
// No-op if market isn't cached for auto open according to its state.
match market.status {
@@ -1943,7 +1941,7 @@ mod pallet {
/// Clears this market from being stored for automatic resolution.
fn clear_auto_resolve(market_id: &MarketIdOf) -> Result<(u32, u32), DispatchError> {
- let market = T::MarketCommons::market(market_id)?;
+ let market = >::market(market_id)?;
let (ids_len, disputes_len) = match market.status {
MarketStatus::Reported => {
let report = market.report.ok_or(Error::::MarketIsNotReported)?;
@@ -1989,11 +1987,11 @@ mod pallet {
Error::::NotEnoughBalance
);
- let market = T::MarketCommons::market(&market_id)?;
+ let market = >::market(&market_id)?;
ensure!(market.scoring_rule == ScoringRule::CPMM, Error::::InvalidScoringRule);
Self::ensure_market_is_active(&market)?;
- let market_account = T::MarketCommons::market_account(market_id);
+ let market_account = >::market_account(market_id);
T::AssetManager::transfer(Asset::Ztg, &who, &market_account, amount)?;
let assets = Self::outcome_assets(market_id, &market);
@@ -2030,7 +2028,7 @@ mod pallet {
creator,
T::OracleBond::get().saturating_add(advisory_bond_unreserve_amount),
);
- T::MarketCommons::remove_market(market_id)?;
+ >::remove_market(market_id)?;
MarketIdsForEdit::::remove(market_id);
Self::deposit_event(Event::MarketRejected(*market_id, reject_reason));
Self::deposit_event(Event::MarketDestroyed(*market_id));
@@ -2055,7 +2053,7 @@ mod pallet {
creator,
T::OracleBond::get(),
);
- T::MarketCommons::remove_market(market_id)?;
+ >::remove_market(market_id)?;
MarketIdsForEdit::::remove(market_id);
Self::deposit_event(Event::MarketExpired(*market_id));
Ok(T::WeightInfo::handle_expired_advised_market())
@@ -2124,12 +2122,14 @@ mod pallet {
}
MarketPeriod::Timestamp(ref range) => {
// Ensure that the market lasts at least one time frame into the future.
- let now_frame = Self::calculate_time_frame_of_moment(T::MarketCommons::now());
+ let now_frame = Self::calculate_time_frame_of_moment(
+ >::now(),
+ );
let end_frame = Self::calculate_time_frame_of_moment(range.end);
ensure!(now_frame < end_frame, Error::::InvalidMarketPeriod);
ensure!(range.start < range.end, Error::::InvalidMarketPeriod);
ensure!(
- range.end <= T::MaxMarketPeriod::get().saturated_into(),
+ range.end <= T::MaxMarketPeriod::get().saturated_into::>(),
Error::::InvalidMarketPeriod
);
}
@@ -2199,9 +2199,10 @@ mod pallet {
.saturated_into();
interval_blocks.saturating_mul(MILLISECS_PER_BLOCK.into())
}
- MarketPeriod::Timestamp(range) => {
- range.start.saturating_sub(T::MarketCommons::now()).saturated_into()
- }
+ MarketPeriod::Timestamp(range) => range
+ .start
+ .saturating_sub(>::now())
+ .saturated_into(),
};
ensure!(
@@ -2219,7 +2220,7 @@ mod pallet {
// Is no-op if market has no pool. This should never happen, but it's safer to not
// error in this case.
let mut total_weight = T::DbWeight::get().reads(1); // (For the `market_pool` read)
- if let Ok(pool_id) = T::MarketCommons::market_pool(market_id) {
+ if let Ok(pool_id) = >::market_pool(market_id) {
let open_pool_weight = T::Swaps::open_pool(pool_id)?;
total_weight = total_weight.saturating_add(open_pool_weight);
}
@@ -2227,13 +2228,13 @@ mod pallet {
}
pub(crate) fn close_market(market_id: &MarketIdOf) -> Result {
- T::MarketCommons::mutate_market(market_id, |market| {
+ >::mutate_market(market_id, |market| {
ensure!(market.status == MarketStatus::Active, Error::::InvalidMarketStatus);
market.status = MarketStatus::Closed;
Ok(())
})?;
let mut total_weight = T::DbWeight::get().reads_writes(1, 1);
- if let Ok(pool_id) = T::MarketCommons::market_pool(market_id) {
+ if let Ok(pool_id) = >::market_pool(market_id) {
let close_pool_weight = T::Swaps::close_pool(pool_id)?;
total_weight = total_weight.saturating_add(close_pool_weight);
};
@@ -2408,7 +2409,7 @@ mod pallet {
// NOTE: Currently we don't clean up outcome assets.
// TODO(#792): Remove outcome assets for accounts! Delete "resolved" assets of `orml_tokens` with storage migration.
- T::MarketCommons::mutate_market(market_id, |m| {
+ >::mutate_market(market_id, |m| {
m.status = MarketStatus::Resolved;
m.resolved_outcome = Some(resolved_outcome.clone());
Ok(())
@@ -2445,7 +2446,8 @@ mod pallet {
};
if market_ready {
- let pool_id = T::MarketCommons::market_pool(&subsidy_info.market_id);
+ let pool_id =
+ >::market_pool(&subsidy_info.market_id);
total_weight.saturating_add(one_read);
if let Ok(pool_id) = pool_id {
@@ -2456,11 +2458,13 @@ mod pallet {
if result.result {
// Sufficient subsidy, activate market.
- let mutate_result =
- T::MarketCommons::mutate_market(&subsidy_info.market_id, |m| {
+ let mutate_result = >::mutate_market(
+ &subsidy_info.market_id,
+ |m| {
m.status = MarketStatus::Active;
Ok(())
- });
+ },
+ );
total_weight =
total_weight.saturating_add(one_read).saturating_add(one_write);
@@ -2498,8 +2502,9 @@ mod pallet {
total_weight = total_weight.saturating_add(weight);
}
- let market_result =
- T::MarketCommons::mutate_market(&subsidy_info.market_id, |m| {
+ let market_result = >::mutate_market(
+ &subsidy_info.market_id,
+ |m| {
m.status = MarketStatus::InsufficientSubsidy;
// Unreserve funds reserved during market creation
@@ -2527,7 +2532,8 @@ mod pallet {
.saturating_add(dbweight.reads(2))
.saturating_add(dbweight.writes(2));
Ok(())
- });
+ },
+ );
if let Err(err) = market_result {
log::error!(
@@ -2542,8 +2548,9 @@ mod pallet {
// `remove_market_pool` can only error due to missing pool, but
// above we ensured that the pool exists.
- let _ =
- T::MarketCommons::remove_market_pool(&subsidy_info.market_id);
+ let _ = >::remove_market_pool(
+ &subsidy_info.market_id,
+ );
total_weight =
total_weight.saturating_add(one_read).saturating_add(one_write);
Self::deposit_event(Event::MarketInsufficientSubsidy(
@@ -2597,7 +2604,7 @@ mod pallet {
market_id: &MarketIdOf,
) -> DispatchResult {
if let Some(last_dispute) = disputes.last() {
- let market = T::MarketCommons::market(market_id)?;
+ let market = >::market(market_id)?;
let dispute_duration_ends_at_block =
last_dispute.at.saturating_add(market.deadlines.dispute_duration);
MarketIdsPerDisputeBlock::::mutate(dispute_duration_ends_at_block, |ids| {
@@ -2634,7 +2641,7 @@ mod pallet {
{
let market_ids_per_block = MarketIdsPerBlock::get(block_number);
for market_id in market_ids_per_block.iter() {
- let market = T::MarketCommons::market(market_id)?;
+ let market = >::market(market_id)?;
mutation(market_id, market)?;
}
MarketIdsPerBlock::remove(block_number);
@@ -2645,7 +2652,7 @@ mod pallet {
time_frame_ids_len =
time_frame_ids_len.saturating_add(market_ids_per_time_frame.len() as u32);
for market_id in market_ids_per_time_frame.iter() {
- let market = T::MarketCommons::market(market_id)?;
+ let market = >::market(market_id)?;
mutation(market_id, market)?;
}
MarketIdsPerTimeFrame::remove(time_frame);
@@ -2667,7 +2674,7 @@ mod pallet {
// Resolve all regularly reported markets.
let market_ids_per_report_block = MarketIdsPerReportBlock::::get(now);
for id in market_ids_per_report_block.iter() {
- let market = T::MarketCommons::market(id)?;
+ let market = >::market(id)?;
if let MarketStatus::Reported = market.status {
cb(id, &market)?;
}
@@ -2677,7 +2684,7 @@ mod pallet {
// Resolve any disputed markets.
let market_ids_per_dispute_block = MarketIdsPerDisputeBlock::::get(now);
for id in market_ids_per_dispute_block.iter() {
- let market = T::MarketCommons::market(id)?;
+ let market = >::market(id)?;
cb(id, &market)?;
}
MarketIdsPerDisputeBlock::::remove(now);
@@ -2694,7 +2701,7 @@ mod pallet {
market_id: &MarketIdOf,
) -> DispatchResult {
if market.status != MarketStatus::Disputed {
- T::MarketCommons::mutate_market(market_id, |m| {
+ >::mutate_market(market_id, |m| {
m.status = MarketStatus::Disputed;
Ok(())
})?;
@@ -2709,12 +2716,12 @@ mod pallet {
market_id: &MarketIdOf,
outcome_report: &OutcomeReport,
) -> Result {
- let pool_id = if let Ok(el) = T::MarketCommons::market_pool(market_id) {
+ let pool_id = if let Ok(el) = >::market_pool(market_id) {
el
} else {
return Ok(T::DbWeight::get().reads(1));
};
- let market_account = T::MarketCommons::market_account(*market_id);
+ let market_account = >::market_account(*market_id);
let weight = T::Swaps::clean_up_pool(
&market.market_type,
pool_id,
@@ -2752,7 +2759,7 @@ mod pallet {
)?;
// This errors if a pool already exists!
- T::MarketCommons::insert_market_pool(market_id, pool_id)?;
+ >::insert_market_pool(market_id, pool_id)?;
>::try_mutate(|markets| {
markets
.try_push(SubsidyUntil { market_id, period: market.period.clone() })
diff --git a/zrml/prediction-markets/src/mock.rs b/zrml/prediction-markets/src/mock.rs
index 29ffc08a7..709f75167 100644
--- a/zrml/prediction-markets/src/mock.rs
+++ b/zrml/prediction-markets/src/mock.rs
@@ -150,7 +150,6 @@ impl crate::Config for Runtime {
#[cfg(feature = "with-global-disputes")]
type GlobalDisputePeriod = GlobalDisputePeriod;
type LiquidityMining = LiquidityMining;
- type MarketCommons = MarketCommons;
type MaxCategories = MaxCategories;
type MaxDisputes = MaxDisputes;
type MinDisputeDuration = MinDisputeDuration;