diff --git a/CODEOWNERS b/CODEOWNERS index 56bde7a4d..775772f66 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -17,7 +17,6 @@ /zrml/orderbook/ @Chralt98 /zrml/parimutuel/ @Chralt98 /zrml/prediction-markets/ @maltekliemann -/zrml/simple-disputes/ @Chralt98 /zrml/styx/ @yornaath /zrml/swaps/ @maltekliemann diff --git a/Cargo.lock b/Cargo.lock index 845c2e649..d7cc116a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -629,7 +629,6 @@ dependencies = [ "zrml-orderbook", "zrml-parimutuel", "zrml-prediction-markets", - "zrml-simple-disputes", "zrml-styx", "zrml-swaps", "zrml-swaps-runtime-api", @@ -14500,7 +14499,6 @@ dependencies = [ "zrml-orderbook", "zrml-parimutuel", "zrml-prediction-markets", - "zrml-simple-disputes", "zrml-styx", "zrml-swaps", "zrml-swaps-runtime-api", @@ -14647,7 +14645,6 @@ dependencies = [ "zrml-neo-swaps", "zrml-orderbook", "zrml-prediction-markets", - "zrml-simple-disputes", ] [[package]] @@ -14709,7 +14706,6 @@ dependencies = [ "zrml-neo-swaps", "zrml-prediction-markets", "zrml-prediction-markets-runtime-api", - "zrml-simple-disputes", ] [[package]] @@ -14810,7 +14806,6 @@ dependencies = [ "zrml-market-commons", "zrml-prediction-markets", "zrml-prediction-markets-runtime-api", - "zrml-simple-disputes", ] [[package]] @@ -14823,7 +14818,6 @@ dependencies = [ "sp-arithmetic", "zeitgeist-primitives", "zrml-prediction-markets", - "zrml-simple-disputes", ] [[package]] @@ -14835,27 +14829,6 @@ dependencies = [ "zeitgeist-primitives", ] -[[package]] -name = "zrml-simple-disputes" -version = "0.5.2" -dependencies = [ - "env_logger 0.10.1", - "frame-benchmarking", - "frame-support", - "frame-system", - "orml-currencies", - "orml-tokens", - "orml-traits", - "pallet-balances", - "pallet-timestamp", - "parity-scale-codec", - "scale-info", - "sp-io", - "sp-runtime", - "zeitgeist-primitives", - "zrml-market-commons", -] - [[package]] name = "zrml-styx" version = "0.5.2" diff --git a/Cargo.toml b/Cargo.toml index 84ee7457e..7d6f55976 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,6 @@ default-members = [ "zrml/parimutuel", "zrml/prediction-markets", "zrml/prediction-markets/runtime-api", - "zrml/simple-disputes", "zrml/swaps", "zrml/swaps/rpc", "zrml/swaps/runtime-api", @@ -43,7 +42,6 @@ members = [ "zrml/prediction-markets", "zrml/prediction-markets/fuzz", "zrml/prediction-markets/runtime-api", - "zrml/simple-disputes", "zrml/swaps", "zrml/swaps/fuzz", "zrml/swaps/rpc", @@ -241,7 +239,6 @@ zrml-orderbook = { path = "zrml/orderbook", default-features = false } zrml-parimutuel = { path = "zrml/parimutuel", default-features = false } zrml-prediction-markets = { path = "zrml/prediction-markets", default-features = false } zrml-prediction-markets-runtime-api = { path = "zrml/prediction-markets/runtime-api", default-features = false } -zrml-simple-disputes = { path = "zrml/simple-disputes", default-features = false } zrml-styx = { path = "zrml/styx", default-features = false } zrml-swaps = { path = "zrml/swaps", default-features = false } zrml-swaps-runtime-api = { path = "zrml/swaps/runtime-api", default-features = false } diff --git a/primitives/src/constants.rs b/primitives/src/constants.rs index 19724325b..320c2bba9 100644 --- a/primitives/src/constants.rs +++ b/primitives/src/constants.rs @@ -114,9 +114,6 @@ pub const MAX_ORACLE_DURATION: BlockNumber = 14 * BLOCKS_PER_DAY; /// Pallet identifier, mainly used for named balance reserves. pub const PM_PALLET_ID: PalletId = PalletId(*b"zge/pred"); -// Simple Disputes -pub const SD_PALLET_ID: PalletId = PalletId(*b"zge/sedp"); - // Swaps /// Max. assets in a swap pool. pub const MAX_ASSETS: u16 = MAX_CATEGORIES + 1; diff --git a/primitives/src/constants/mock.rs b/primitives/src/constants/mock.rs index ce19b9247..e79e5a69d 100644 --- a/primitives/src/constants/mock.rs +++ b/primitives/src/constants/mock.rs @@ -126,13 +126,6 @@ parameter_types! { pub const ValidityBond: Balance = 50 * CENT; } -// Simple disputes parameters -parameter_types! { - pub const SimpleDisputesPalletId: PalletId = PalletId(*b"zge/sedp"); - pub const OutcomeBond: Balance = 5 * BASE; - pub const OutcomeFactor: Balance = 2 * BASE; -} - // Swaps parameters parameter_types! { pub const ExitFee: Balance = 3 * BASE / 1000; // 0.3% diff --git a/primitives/src/market.rs b/primitives/src/market.rs index 46b1deef8..6f4f2e464 100644 --- a/primitives/src/market.rs +++ b/primitives/src/market.rs @@ -310,7 +310,6 @@ pub struct MarketDispute { pub enum MarketDisputeMechanism { Authorized, Court, - SimpleDisputes, } /// Defines whether the period is represented as a blocknumber or a timestamp. diff --git a/runtime/battery-station/Cargo.toml b/runtime/battery-station/Cargo.toml index 0643f9893..70b9d5c32 100644 --- a/runtime/battery-station/Cargo.toml +++ b/runtime/battery-station/Cargo.toml @@ -118,7 +118,6 @@ zrml-neo-swaps = { workspace = true } zrml-orderbook = { workspace = true } zrml-parimutuel = { workspace = true } zrml-prediction-markets = { workspace = true } -zrml-simple-disputes = { workspace = true } zrml-styx = { workspace = true } zrml-swaps = { workspace = true } zrml-swaps-runtime-api = { workspace = true } @@ -216,7 +215,6 @@ runtime-benchmarks = [ "zrml-neo-swaps/runtime-benchmarks", "zrml-parimutuel/runtime-benchmarks", "zrml-prediction-markets/runtime-benchmarks", - "zrml-simple-disputes/runtime-benchmarks", "zrml-global-disputes/runtime-benchmarks", "zrml-styx/runtime-benchmarks", "zrml-swaps/runtime-benchmarks", @@ -331,7 +329,6 @@ std = [ "zrml-neo-swaps/std", "zrml-parimutuel/std", "zrml-prediction-markets/std", - "zrml-simple-disputes/std", "zrml-global-disputes/std", "zrml-styx/std", "zrml-swaps-runtime-api/std", @@ -388,7 +385,6 @@ try-runtime = [ "zrml-neo-swaps/try-runtime", "zrml-parimutuel/try-runtime", "zrml-prediction-markets/try-runtime", - "zrml-simple-disputes/try-runtime", "zrml-global-disputes/try-runtime", "zrml-styx/try-runtime", "zrml-swaps/try-runtime", diff --git a/runtime/battery-station/src/lib.rs b/runtime/battery-station/src/lib.rs index 5ffc4f81b..d3150560b 100644 --- a/runtime/battery-station/src/lib.rs +++ b/runtime/battery-station/src/lib.rs @@ -191,18 +191,6 @@ impl Contains for IsCallable { finish_destroy { .. } => false, _ => true, }, - RuntimeCall::SimpleDisputes(_) => false, - RuntimeCall::PredictionMarkets(inner_call) => match inner_call { - create_market { - dispute_mechanism: Some(MarketDisputeMechanism::SimpleDisputes), - .. - } => false, - edit_market { - dispute_mechanism: Some(MarketDisputeMechanism::SimpleDisputes), - .. - } => false, - _ => true, - }, RuntimeCall::Swaps(inner_call) => match inner_call { force_pool_exit { .. } => true, _ => false, diff --git a/runtime/battery-station/src/parameters.rs b/runtime/battery-station/src/parameters.rs index cecc69f4f..190a0f8e5 100644 --- a/runtime/battery-station/src/parameters.rs +++ b/runtime/battery-station/src/parameters.rs @@ -327,16 +327,6 @@ parameter_types! { pub const MaxScheduledPerBlock: u32 = 50; pub const NoPreimagePostponement: Option = Some(5 * BLOCKS_PER_MINUTE); - // Simple disputes parameters - /// Pallet identifier, mainly used for named balance reserves. - pub const SimpleDisputesPalletId: PalletId = SD_PALLET_ID; - /// (Slashable) Bond that is provided for overriding the last outcome addition. - /// Slashed in case the final outcome does not match the dispute for which the `OutcomeBond` - /// was deposited. - pub const OutcomeBond: Balance = 5 * BASE; - /// `OutcomeBond` is increased by this factor after every new outcome addition. - pub const OutcomeFactor: Balance = 2 * BASE; - // Swaps parameters /// A precentage from the withdrawal amount a liquidity provider wants to withdraw /// from a pool before the pool is closed. diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 11388747f..ea946aa6d 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -55,17 +55,13 @@ macro_rules! decl_common_types { use orml_traits::MultiCurrency; use sp_runtime::{generic, DispatchError, DispatchResult, SaturatedConversion}; use zeitgeist_primitives::traits::{DeployPoolApi, DistributeFees, MarketCommonsPalletApi}; - use zrml_market_commons::migrations::MigrateScoringRuleAmmCdaHybridAndMarketId; - use zrml_neo_swaps::migration::MigratePoolReservesToBoundedBTreeMap; + use zrml_market_commons::migrations::MigrateDisputeMechanism; pub type Block = generic::Block; type Address = sp_runtime::MultiAddress; - type Migrations = ( - MigrateScoringRuleAmmCdaHybridAndMarketId, - MigratePoolReservesToBoundedBTreeMap, - ); + type Migrations = (MigrateDisputeMechanism); pub type Executive = frame_executive::Executive< Runtime, @@ -198,7 +194,6 @@ macro_rules! decl_common_types { OrderbookPalletId::get(), ParimutuelPalletId::get(), PmPalletId::get(), - SimpleDisputesPalletId::get(), SwapsPalletId::get(), TreasuryPalletId::get(), ]; @@ -259,8 +254,8 @@ macro_rules! create_runtime { use alloc::{boxed::Box, vec::Vec}; // Pallets are enumerated based on the dependency graph. // - // For example, `PredictionMarkets` is pĺaced after `SimpleDisputes` because - // `PredictionMarkets` depends on `SimpleDisputes`. + // For example, `PredictionMarkets` is pĺaced after `MarketCommons` because + // `PredictionMarkets` depends on `MarketCommons`. construct_runtime!( pub enum Runtime where @@ -310,7 +305,6 @@ macro_rules! create_runtime { MarketCommons: zrml_market_commons::{Pallet, Storage} = 50, Authorized: zrml_authorized::{Call, Event, Pallet, Storage} = 51, Court: zrml_court::{Call, Event, Pallet, Storage} = 52, - SimpleDisputes: zrml_simple_disputes::{Call, Event, Pallet, Storage} = 55, Swaps: zrml_swaps::{Call, Event, Pallet, Storage} = 56, PredictionMarkets: zrml_prediction_markets::{Call, Event, Pallet, Storage} = 57, Styx: zrml_styx::{Call, Event, Pallet, Storage} = 58, @@ -1271,24 +1265,11 @@ macro_rules! impl_config_traits { type RejectOrigin = EnsureRootOrMoreThanTwoThirdsAdvisoryCommittee; type RequestEditOrigin = EnsureRootOrMoreThanOneThirdAdvisoryCommittee; type ResolveOrigin = EnsureRoot; - type SimpleDisputes = SimpleDisputes; type Slash = Treasury; type ValidityBond = ValidityBond; type WeightInfo = zrml_prediction_markets::weights::WeightInfo; } - impl zrml_simple_disputes::Config for Runtime { - type Currency = Balances; - type OutcomeBond = OutcomeBond; - type OutcomeFactor = OutcomeFactor; - type DisputeResolution = zrml_prediction_markets::Pallet; - type RuntimeEvent = RuntimeEvent; - type MarketCommons = MarketCommons; - type MaxDisputes = MaxDisputes; - type PalletId = SimpleDisputesPalletId; - type WeightInfo = zrml_simple_disputes::weights::WeightInfo; - } - impl zrml_global_disputes::Config for Runtime { type AddOutcomePeriod = AddOutcomePeriod; type Currency = Balances; @@ -1484,7 +1465,6 @@ macro_rules! create_runtime_api { list_benchmark!(list, extra, zrml_swaps, Swaps); list_benchmark!(list, extra, zrml_authorized, Authorized); list_benchmark!(list, extra, zrml_court, Court); - list_benchmark!(list, extra, zrml_simple_disputes, SimpleDisputes); list_benchmark!(list, extra, zrml_global_disputes, GlobalDisputes); list_benchmark!(list, extra, zrml_orderbook, Orderbook); list_benchmark!(list, extra, zrml_parimutuel, Parimutuel); @@ -1589,7 +1569,6 @@ macro_rules! create_runtime_api { add_benchmark!(params, batches, zrml_swaps, Swaps); add_benchmark!(params, batches, zrml_authorized, Authorized); add_benchmark!(params, batches, zrml_court, Court); - add_benchmark!(params, batches, zrml_simple_disputes, SimpleDisputes); add_benchmark!(params, batches, zrml_global_disputes, GlobalDisputes); add_benchmark!(params, batches, zrml_orderbook, Orderbook); add_benchmark!(params, batches, zrml_parimutuel, Parimutuel); @@ -2202,7 +2181,6 @@ macro_rules! create_common_tests { #[test_case(AuthorizedPalletId::get(); "authorized")] #[test_case(CourtPalletId::get(); "court")] #[test_case(PmPalletId::get(); "prediction_markets")] - #[test_case(SimpleDisputesPalletId::get(); "simple_disputes")] #[test_case(SwapsPalletId::get(); "swaps")] #[test_case(TreasuryPalletId::get(); "treasury")] fn whitelisted_pallet_accounts_dont_get_reaped(pallet_id: PalletId) { diff --git a/runtime/zeitgeist/Cargo.toml b/runtime/zeitgeist/Cargo.toml index c6348444a..2fe834082 100644 --- a/runtime/zeitgeist/Cargo.toml +++ b/runtime/zeitgeist/Cargo.toml @@ -117,7 +117,6 @@ zrml-neo-swaps = { workspace = true } zrml-orderbook = { workspace = true } zrml-parimutuel = { workspace = true } zrml-prediction-markets = { workspace = true } -zrml-simple-disputes = { workspace = true } zrml-styx = { workspace = true } zrml-swaps = { workspace = true } zrml-swaps-runtime-api = { workspace = true } @@ -214,7 +213,6 @@ runtime-benchmarks = [ "zrml-neo-swaps/runtime-benchmarks", "zrml-parimutuel/runtime-benchmarks", "zrml-prediction-markets/runtime-benchmarks", - "zrml-simple-disputes/runtime-benchmarks", "zrml-global-disputes/runtime-benchmarks", "zrml-styx/runtime-benchmarks", "zrml-swaps/runtime-benchmarks", @@ -321,7 +319,6 @@ std = [ "zrml-neo-swaps/std", "zrml-parimutuel/std", "zrml-prediction-markets/std", - "zrml-simple-disputes/std", "zrml-global-disputes/std", "zrml-swaps-runtime-api/std", "zrml-styx/std", @@ -378,7 +375,6 @@ try-runtime = [ "zrml-neo-swaps/try-runtime", "zrml-parimutuel/try-runtime", "zrml-prediction-markets/try-runtime", - "zrml-simple-disputes/try-runtime", "zrml-global-disputes/try-runtime", "zrml-styx/try-runtime", "zrml-swaps/try-runtime", diff --git a/runtime/zeitgeist/src/lib.rs b/runtime/zeitgeist/src/lib.rs index 0e528318b..4c359e73f 100644 --- a/runtime/zeitgeist/src/lib.rs +++ b/runtime/zeitgeist/src/lib.rs @@ -120,9 +120,8 @@ impl Contains for IsCallable { set_code as set_code_contracts, }; use pallet_vesting::Call::force_vested_transfer; - use zeitgeist_primitives::types::MarketDisputeMechanism::SimpleDisputes; use zrml_prediction_markets::Call::{ - admin_move_market_to_closed, admin_move_market_to_resolved, create_market, edit_market, + admin_move_market_to_closed, admin_move_market_to_resolved, }; use zrml_swaps::Call::force_pool_exit; @@ -180,17 +179,11 @@ impl Contains for IsCallable { RuntimeCall::Council(set_members { .. }) => false, #[cfg(feature = "parachain")] RuntimeCall::DmpQueue(service_overweight { .. }) => false, - RuntimeCall::PredictionMarkets(inner_call) => { - match inner_call { - // Disable SimpleDisputes dispute resolution mechanism - create_market { dispute_mechanism: Some(SimpleDisputes), .. } => false, - edit_market { dispute_mechanism: Some(SimpleDisputes), .. } => false, - admin_move_market_to_closed { .. } => false, - admin_move_market_to_resolved { .. } => false, - _ => true, - } - } - RuntimeCall::SimpleDisputes(_) => false, + RuntimeCall::PredictionMarkets(inner_call) => match inner_call { + admin_move_market_to_closed { .. } => false, + admin_move_market_to_resolved { .. } => false, + _ => true, + }, RuntimeCall::Swaps(inner_call) => match inner_call { force_pool_exit { .. } => true, _ => false, diff --git a/runtime/zeitgeist/src/parameters.rs b/runtime/zeitgeist/src/parameters.rs index ce4526cf4..e54c88369 100644 --- a/runtime/zeitgeist/src/parameters.rs +++ b/runtime/zeitgeist/src/parameters.rs @@ -325,16 +325,6 @@ parameter_types! { pub const MaxScheduledPerBlock: u32 = 50; pub const NoPreimagePostponement: Option = Some(5 * BLOCKS_PER_MINUTE); - // Simple disputes parameters - /// Pallet identifier, mainly used for named balance reserves. DO NOT CHANGE. - pub const SimpleDisputesPalletId: PalletId = SD_PALLET_ID; - /// (Slashable) Bond that is provided for overriding the last outcome addition. - /// Slashed in case the final outcome does not match the dispute for which the `OutcomeBond` - /// was deposited. - pub const OutcomeBond: Balance = 2_000 * BASE; - /// `OutcomeBond` is increased by this factor after every new outcome addition. - pub const OutcomeFactor: Balance = 2 * BASE; - // Swaps parameters /// A precentage from the withdrawal amount a liquidity provider wants to withdraw /// from a pool before the pool is closed. diff --git a/zrml/court/src/tests.rs b/zrml/court/src/tests.rs index b0c80d6dc..730f98af2 100644 --- a/zrml/court/src/tests.rs +++ b/zrml/court/src/tests.rs @@ -1740,7 +1740,7 @@ fn check_appealable_market_fails_if_dispute_mechanism_wrong() { let market_id = >::get(court_id).unwrap(); MarketCommons::mutate_market(&market_id, |market| { - market.dispute_mechanism = Some(MarketDisputeMechanism::SimpleDisputes); + market.dispute_mechanism = Some(MarketDisputeMechanism::Authorized); Ok(()) }) .unwrap(); @@ -2450,7 +2450,7 @@ fn reassign_court_stakes_rewards_treasury_if_no_winner() { fn on_dispute_denies_non_court_markets() { ExtBuilder::default().build().execute_with(|| { let mut market = DEFAULT_MARKET; - market.dispute_mechanism = Some(MarketDisputeMechanism::SimpleDisputes); + market.dispute_mechanism = Some(MarketDisputeMechanism::Authorized); assert_noop!( Court::on_dispute(&0, &market), Error::::MarketDoesNotHaveCourtMechanism @@ -2487,7 +2487,7 @@ fn on_resolution_fails_if_court_not_found() { fn on_resolution_denies_non_court_markets() { ExtBuilder::default().build().execute_with(|| { let mut market = DEFAULT_MARKET; - market.dispute_mechanism = Some(MarketDisputeMechanism::SimpleDisputes); + market.dispute_mechanism = Some(MarketDisputeMechanism::Authorized); assert_noop!( Court::on_resolution(&0, &market), Error::::MarketDoesNotHaveCourtMechanism @@ -2499,7 +2499,7 @@ fn on_resolution_denies_non_court_markets() { fn exchange_fails_if_non_court_markets() { ExtBuilder::default().build().execute_with(|| { let mut market = DEFAULT_MARKET; - market.dispute_mechanism = Some(MarketDisputeMechanism::SimpleDisputes); + market.dispute_mechanism = Some(MarketDisputeMechanism::Authorized); assert_noop!( Court::exchange(&0, &market, &ORACLE_REPORT, NegativeImbalance::::zero()), Error::::MarketDoesNotHaveCourtMechanism @@ -2610,7 +2610,7 @@ fn on_global_dispute_removes_draws() { fn on_global_dispute_fails_if_wrong_dispute_mechanism() { ExtBuilder::default().build().execute_with(|| { let mut market = DEFAULT_MARKET; - market.dispute_mechanism = Some(MarketDisputeMechanism::SimpleDisputes); + market.dispute_mechanism = Some(MarketDisputeMechanism::Authorized); assert_noop!( Court::on_global_dispute(&0, &market), Error::::MarketDoesNotHaveCourtMechanism diff --git a/zrml/global-disputes/src/utils.rs b/zrml/global-disputes/src/utils.rs index dabebc965..411ce19dc 100644 --- a/zrml/global-disputes/src/utils.rs +++ b/zrml/global-disputes/src/utils.rs @@ -43,9 +43,7 @@ where creator_fee: sp_runtime::Perbill::zero(), creator: T::GlobalDisputesPalletId::get().into_account_truncating(), market_type: zeitgeist_primitives::types::MarketType::Scalar(0..=u128::MAX), - dispute_mechanism: Some( - zeitgeist_primitives::types::MarketDisputeMechanism::SimpleDisputes, - ), + dispute_mechanism: Some(zeitgeist_primitives::types::MarketDisputeMechanism::Authorized), metadata: Default::default(), oracle: T::GlobalDisputesPalletId::get().into_account_truncating(), period: zeitgeist_primitives::types::MarketPeriod::Block(Default::default()), diff --git a/zrml/hybrid-router/Cargo.toml b/zrml/hybrid-router/Cargo.toml index b0c7a5b06..f4e910888 100644 --- a/zrml/hybrid-router/Cargo.toml +++ b/zrml/hybrid-router/Cargo.toml @@ -30,7 +30,6 @@ zrml-global-disputes = { workspace = true, optional = true } zrml-neo-swaps = { workspace = true, optional = true } zrml-orderbook = { workspace = true, optional = true } zrml-prediction-markets = { workspace = true, optional = true } -zrml-simple-disputes = { workspace = true, optional = true } [dev-dependencies] env_logger = { workspace = true } @@ -59,7 +58,6 @@ mock = [ "zrml-orderbook/default", "zrml-prediction-markets/default", "zrml-prediction-markets/mock", - "zrml-simple-disputes/default", "zrml-authorized/default", "zrml-court/default", "zrml-global-disputes/default", diff --git a/zrml/hybrid-router/src/mock.rs b/zrml/hybrid-router/src/mock.rs index 68ddae2b9..4c6108652 100644 --- a/zrml/hybrid-router/src/mock.rs +++ b/zrml/hybrid-router/src/mock.rs @@ -57,10 +57,9 @@ use zeitgeist_primitives::{ MaxLiquidityTreeDepth, MaxLocks, MaxMarketLifetime, MaxOracleDuration, MaxOrders, MaxOwners, MaxRejectReasonLen, MaxReserves, MaxSelectedDraws, MaxYearlyInflation, MinCategories, MinDisputeDuration, MinJurorStake, MinOracleDuration, MinOutcomeVoteAmount, - MinimumPeriod, NeoMaxSwapFee, NeoSwapsPalletId, OrderbookPalletId, OutcomeBond, - OutcomeFactor, OutsiderBond, PmPalletId, RemoveKeysLimit, RequestInterval, - SimpleDisputesPalletId, TreasuryPalletId, VotePeriod, VotingOutcomeFee, BASE, CENT, - MAX_ASSETS, + MinimumPeriod, NeoMaxSwapFee, NeoSwapsPalletId, OrderbookPalletId, OutsiderBond, + PmPalletId, RemoveKeysLimit, RequestInterval, TreasuryPalletId, VotePeriod, + VotingOutcomeFee, BASE, CENT, MAX_ASSETS, }, traits::DistributeFees, types::{ @@ -178,7 +177,6 @@ construct_runtime!( MarketCommons: zrml_market_commons::{Pallet, Storage}, PredictionMarkets: zrml_prediction_markets::{Event, Pallet, Storage}, RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage}, - SimpleDisputes: zrml_simple_disputes::{Event, Pallet, Storage}, GlobalDisputes: zrml_global_disputes::{Event, Pallet, Storage}, System: frame_system::{Call, Config, Event, Pallet, Storage}, Timestamp: pallet_timestamp::{Pallet}, @@ -384,7 +382,6 @@ impl zrml_prediction_markets::Config for Runtime { type RequestEditOrigin = EnsureSignedBy; type ResolveOrigin = EnsureSignedBy; type AssetManager = AssetManager; - type SimpleDisputes = SimpleDisputes; type Slash = Treasury; type ValidityBond = ValidityBond; type WeightInfo = zrml_prediction_markets::weights::WeightInfo; @@ -502,18 +499,6 @@ impl pallet_timestamp::Config for Runtime { type WeightInfo = (); } -impl zrml_simple_disputes::Config for Runtime { - type Currency = Balances; - type RuntimeEvent = RuntimeEvent; - type OutcomeBond = OutcomeBond; - type OutcomeFactor = OutcomeFactor; - type DisputeResolution = zrml_prediction_markets::Pallet; - type MarketCommons = MarketCommons; - type MaxDisputes = MaxDisputes; - type PalletId = SimpleDisputesPalletId; - type WeightInfo = zrml_simple_disputes::weights::WeightInfo; -} - impl zrml_global_disputes::Config for Runtime { type AddOutcomePeriod = AddOutcomePeriod; type RuntimeEvent = RuntimeEvent; diff --git a/zrml/market-commons/src/migrations.rs b/zrml/market-commons/src/migrations.rs index 2569b4a79..89ad67dcd 100644 --- a/zrml/market-commons/src/migrations.rs +++ b/zrml/market-commons/src/migrations.rs @@ -16,7 +16,9 @@ // You should have received a copy of the GNU General Public License // along with Zeitgeist. If not, see . -use crate::{AccountIdOf, BalanceOf, BlockNumberOf, Config, MomentOf, Pallet as MarketCommons}; +use crate::{ + AccountIdOf, BalanceOf, BlockNumberOf, Config, MarketIdOf, MomentOf, Pallet as MarketCommons, +}; use alloc::vec::Vec; use core::marker::PhantomData; use frame_support::{ @@ -34,7 +36,6 @@ use zeitgeist_primitives::types::{ #[cfg(feature = "try-runtime")] use { - crate::MarketIdOf, alloc::{collections::BTreeMap, format}, frame_support::migration::storage_key_iter, }; @@ -48,48 +49,73 @@ const MARKET_COMMONS: &[u8] = b"MarketCommons"; const MARKETS: &[u8] = b"Markets"; #[derive(Clone, Decode, Encode, Eq, PartialEq, RuntimeDebug, TypeInfo)] -pub struct OldMarket { - pub base_asset: A, - pub creator: AI, +pub struct OldMarket { + pub market_id: MarketId, + /// Base asset of the market. + pub base_asset: Asset, + /// Creator of this market. + pub creator: AccountId, + /// Creation type. pub creation: MarketCreation, + /// A fee that is charged each trade and given to the market creator. pub creator_fee: Perbill, - pub oracle: AI, + /// Oracle that reports the outcome of this market. + pub oracle: AccountId, + /// Metadata for the market, usually a content address of IPFS + /// hosted JSON. Currently limited to 66 bytes (see `MaxEncodedLen` implementation) pub metadata: Vec, + /// The type of the market. pub market_type: MarketType, - pub period: MarketPeriod, - pub deadlines: Deadlines, - pub scoring_rule: OldScoringRule, + /// Market start and end + pub period: MarketPeriod, + /// Market deadlines. + pub deadlines: Deadlines, + /// The scoring rule used for the market. + pub scoring_rule: ScoringRule, + /// The current status of the market. pub status: MarketStatus, - pub report: Option>, + /// The report of the market. Only `Some` if it has been reported. + pub report: Option>, + /// The resolved outcome. pub resolved_outcome: Option, - pub dispute_mechanism: Option, - pub bonds: MarketBonds, - pub early_close: Option>, + /// See [`MarketDisputeMechanism`]. + pub dispute_mechanism: Option, + /// The bonds reserved for this market. + pub bonds: MarketBonds, + /// The time at which the market was closed early. + pub early_close: Option>, } -type OldMarketOf = - OldMarket, BalanceOf, BlockNumberOf, MomentOf, BaseAsset>; +type OldMarketOf = OldMarket< + AccountIdOf, + BalanceOf, + BlockNumberOf, + MomentOf, + BaseAsset, + MarketIdOf, +>; #[derive(TypeInfo, Clone, Copy, Encode, Eq, Decode, MaxEncodedLen, PartialEq, RuntimeDebug)] -pub enum OldScoringRule { - Lmsr, - Orderbook, - Parimutuel, +pub enum OldMarketDisputeMechanism { + Authorized, + Court, + SimpleDisputes, } -const MARKET_COMMONS_REQUIRED_STORAGE_VERSION: u16 = 10; -const MARKET_COMMONS_NEXT_STORAGE_VERSION: u16 = 11; +const MARKET_COMMONS_REQUIRED_STORAGE_VERSION: u16 = 11; +const MARKET_COMMONS_NEXT_STORAGE_VERSION: u16 = 12; #[cfg(feature = "try-runtime")] #[frame_support::storage_alias] pub(crate) type Markets = StorageMap, Blake2_128Concat, MarketIdOf, OldMarketOf>; -pub struct MigrateScoringRuleAmmCdaHybridAndMarketId(PhantomData); +pub struct MigrateDisputeMechanism(PhantomData); -/// Migrates AMM and CDA markets to the new combined scoring rule and adds the market's ID to the -/// struct. -impl OnRuntimeUpgrade for MigrateScoringRuleAmmCdaHybridAndMarketId +/// Removes the `SimpleDisputes` MDM by switching markets that use `SimpleDisputes` to `Authorized`. +/// Note that this migration does not unreserve any funds bonded with zrml-simple-dispute's reserve +/// ID. +impl OnRuntimeUpgrade for MigrateDisputeMechanism where T: Config, { @@ -98,25 +124,24 @@ where let market_commons_version = StorageVersion::get::>(); if market_commons_version != MARKET_COMMONS_REQUIRED_STORAGE_VERSION { log::info!( - "MigrateScoringRuleAmmCdaHybridAndMarketId: market-commons version is {:?}, but \ - {:?} is required", + "MigrateDisputeMechanism: market-commons version is {:?}, but {:?} is required", market_commons_version, MARKET_COMMONS_REQUIRED_STORAGE_VERSION, ); return total_weight; } - log::info!("MigrateScoringRuleAmmCdaHybridAndMarketId: Starting..."); + log::info!("MigrateDisputeMechanism: Starting..."); let mut translated = 0u64; - crate::Markets::::translate::, _>(|market_id, old_market| { + crate::Markets::::translate::, _>(|_, old_market| { translated.saturating_inc(); - let scoring_rule = match old_market.scoring_rule { - OldScoringRule::Lmsr => ScoringRule::AmmCdaHybrid, - OldScoringRule::Orderbook => ScoringRule::AmmCdaHybrid, - OldScoringRule::Parimutuel => ScoringRule::Parimutuel, + let dispute_mechanism = match old_market.dispute_mechanism { + Some(OldMarketDisputeMechanism::Court) => Some(MarketDisputeMechanism::Court), + Some(_) => Some(MarketDisputeMechanism::Authorized), + None => None, }; let new_market = Market { - market_id, + market_id: old_market.market_id, base_asset: old_market.base_asset, creator: old_market.creator, creation: old_market.creation, @@ -126,23 +151,23 @@ where market_type: old_market.market_type, period: old_market.period, deadlines: old_market.deadlines, - scoring_rule, + scoring_rule: old_market.scoring_rule, status: old_market.status, report: old_market.report, resolved_outcome: old_market.resolved_outcome, - dispute_mechanism: old_market.dispute_mechanism, + dispute_mechanism, bonds: old_market.bonds, early_close: old_market.early_close, }; Some(new_market) }); - log::info!("MigrateScoringRuleAmmCdaHybridAndMarketId: Upgraded {} markets.", translated); + log::info!("MigrateDisputeMechanism: Upgraded {} markets.", translated); total_weight = total_weight.saturating_add(T::DbWeight::get().reads_writes(translated, translated)); StorageVersion::new(MARKET_COMMONS_NEXT_STORAGE_VERSION).put::>(); total_weight = total_weight.saturating_add(T::DbWeight::get().writes(1)); - log::info!("MigrateScoringRuleAmmCdaHybridAndMarketId: Done!"); + log::info!("MigrateDisputeMechanism: Done!"); total_weight } @@ -179,7 +204,7 @@ where let old_market = old_markets .get(&market_id) .expect(&format!("Market {:?} not found", market_id)[..]); - assert_eq!(market_id, new_market.market_id); + assert_eq!(old_market.market_id, new_market.market_id); assert_eq!(old_market.base_asset, new_market.base_asset); assert_eq!(old_market.creator, new_market.creator); assert_eq!(old_market.creation, new_market.creation); @@ -192,14 +217,10 @@ where assert_eq!(old_market.status, new_market.status); assert_eq!(old_market.report, new_market.report); assert_eq!(old_market.resolved_outcome, new_market.resolved_outcome); - assert_eq!(old_market.dispute_mechanism, new_market.dispute_mechanism); assert_eq!(old_market.bonds, new_market.bonds); assert_eq!(old_market.early_close, new_market.early_close); } - log::info!( - "MigrateScoringRuleAmmCdaHybridAndMarketId: Post-upgrade market count is {}!", - new_market_count - ); + log::info!("MigrateDisputeMechanism: Post-upgrade market count is {}!", new_market_count); Ok(()) } } @@ -224,7 +245,7 @@ mod tests { fn on_runtime_upgrade_increments_the_storage_version() { ExtBuilder::default().build().execute_with(|| { set_up_version(); - MigrateScoringRuleAmmCdaHybridAndMarketId::::on_runtime_upgrade(); + MigrateDisputeMechanism::::on_runtime_upgrade(); assert_eq!( StorageVersion::get::>(), MARKET_COMMONS_NEXT_STORAGE_VERSION @@ -232,26 +253,31 @@ mod tests { }); } - #[test_case(OldScoringRule::Orderbook, ScoringRule::AmmCdaHybrid)] - #[test_case(OldScoringRule::Lmsr, ScoringRule::AmmCdaHybrid)] - #[test_case(OldScoringRule::Parimutuel, ScoringRule::Parimutuel)] + #[test_case(None, None)] + #[test_case( + Some(OldMarketDisputeMechanism::Authorized), + Some(MarketDisputeMechanism::Authorized) + )] + #[test_case(Some(OldMarketDisputeMechanism::Court), Some(MarketDisputeMechanism::Court))] + #[test_case( + Some(OldMarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Authorized) + )] fn on_runtime_upgrade_works_as_expected( - old_scoring_rule: OldScoringRule, - new_scoring_rule: ScoringRule, + old_scoring_rule: Option, + new_scoring_rule: Option, ) { ExtBuilder::default().build().execute_with(|| { set_up_version(); - let (old_markets, new_markets) = + let (old_market, new_market) = construct_old_new_tuple(old_scoring_rule, new_scoring_rule); populate_test_data::>( MARKET_COMMONS, MARKETS, - old_markets, + vec![old_market], ); - MigrateScoringRuleAmmCdaHybridAndMarketId::::on_runtime_upgrade(); - assert_eq!(crate::Markets::::get(0).unwrap(), new_markets[0]); - assert_eq!(crate::Markets::::get(1).unwrap(), new_markets[1]); - assert_eq!(crate::Markets::::get(2).unwrap(), new_markets[2]); + MigrateDisputeMechanism::::on_runtime_upgrade(); + assert_eq!(crate::Markets::::get(0).unwrap(), new_market); }); } @@ -288,7 +314,7 @@ mod tests { }; crate::Markets::::insert(333, market); let tmp = storage_root(StateVersion::V1); - MigrateScoringRuleAmmCdaHybridAndMarketId::::on_runtime_upgrade(); + MigrateDisputeMechanism::::on_runtime_upgrade(); assert_eq!(tmp, storage_root(StateVersion::V1)); }); } @@ -299,10 +325,12 @@ mod tests { } fn construct_old_new_tuple( - old_scoring_rule: OldScoringRule, - new_scoring_rule: ScoringRule, - ) -> (Vec>, Vec>) { + old_dispute_mechanism: Option, + new_dispute_mechanism: Option, + ) -> (OldMarketOf, MarketOf) { + let market_id = 0; let base_asset = BaseAsset::Ztg; + let creator = 1; let creation = MarketCreation::Advised; let creator_fee = Perbill::from_rational(2u32, 3u32); let oracle = 4; @@ -310,10 +338,10 @@ mod tests { let market_type = MarketType::Scalar(6..=7); let period = MarketPeriod::Block(8..9); let deadlines = Deadlines { grace_period: 10, oracle_duration: 11, dispute_duration: 12 }; + let scoring_rule = ScoringRule::AmmCdaHybrid; let status = MarketStatus::Resolved; let report = Some(Report { at: 13, by: 14, outcome: OutcomeReport::Categorical(15) }); let resolved_outcome = Some(OutcomeReport::Categorical(16)); - let dispute_mechanism = Some(MarketDisputeMechanism::Court); let bonds = MarketBonds { creation: Some(Bond { who: 17, value: 18, is_settled: true }), oracle: Some(Bond { who: 19, value: 20, is_settled: true }), @@ -327,51 +355,45 @@ mod tests { new: MarketPeriod::Block(31..32), state: EarlyCloseState::Disputed, }); - let sentinels = (0..3).map(|i| 10 - i); - let old_markets = sentinels - .clone() - .map(|sentinel| OldMarket { - base_asset, - creator: sentinel, - creation: creation.clone(), - creator_fee, - oracle, - metadata: metadata.clone(), - market_type: market_type.clone(), - period: period.clone(), - deadlines, - scoring_rule: old_scoring_rule, - status, - report: report.clone(), - resolved_outcome: resolved_outcome.clone(), - dispute_mechanism: dispute_mechanism.clone(), - bonds: bonds.clone(), - early_close: early_close.clone(), - }) - .collect(); - let new_markets = sentinels - .enumerate() - .map(|(index, sentinel)| Market { - market_id: index as u128, - base_asset, - creator: sentinel, - creation: creation.clone(), - creator_fee, - oracle, - metadata: metadata.clone(), - market_type: market_type.clone(), - period: period.clone(), - deadlines, - scoring_rule: new_scoring_rule, - status, - report: report.clone(), - resolved_outcome: resolved_outcome.clone(), - dispute_mechanism: dispute_mechanism.clone(), - bonds: bonds.clone(), - early_close: early_close.clone(), - }) - .collect(); - (old_markets, new_markets) + let old_markets = OldMarket { + market_id, + base_asset, + creator, + creation: creation.clone(), + creator_fee, + oracle, + metadata: metadata.clone(), + market_type: market_type.clone(), + period: period.clone(), + deadlines, + scoring_rule, + status, + report: report.clone(), + resolved_outcome: resolved_outcome.clone(), + dispute_mechanism: old_dispute_mechanism, + bonds: bonds.clone(), + early_close: early_close.clone(), + }; + let new_market = Market { + market_id, + base_asset, + creator, + creation: creation.clone(), + creator_fee, + oracle, + metadata: metadata.clone(), + market_type: market_type.clone(), + period: period.clone(), + deadlines, + scoring_rule, + status, + report: report.clone(), + resolved_outcome: resolved_outcome.clone(), + dispute_mechanism: new_dispute_mechanism, + bonds: bonds.clone(), + early_close: early_close.clone(), + }; + (old_markets, new_market) } #[allow(unused)] diff --git a/zrml/neo-swaps/Cargo.toml b/zrml/neo-swaps/Cargo.toml index 955d73ce9..28e595746 100644 --- a/zrml/neo-swaps/Cargo.toml +++ b/zrml/neo-swaps/Cargo.toml @@ -36,7 +36,6 @@ zrml-court = { workspace = true, optional = true } zrml-global-disputes = { workspace = true, optional = true } zrml-prediction-markets = { workspace = true, optional = true } zrml-prediction-markets-runtime-api = { workspace = true, optional = true } -zrml-simple-disputes = { workspace = true, optional = true } [dev-dependencies] more-asserts = { workspace = true } @@ -68,7 +67,6 @@ mock = [ "zrml-court/std", "zrml-asset-router/std", "zrml-authorized/std", - "zrml-simple-disputes/std", "zrml-global-disputes/std", "zrml-prediction-markets/std", "zrml-prediction-markets/mock", diff --git a/zrml/neo-swaps/src/mock.rs b/zrml/neo-swaps/src/mock.rs index 413c28ba8..d39733dc5 100644 --- a/zrml/neo-swaps/src/mock.rs +++ b/zrml/neo-swaps/src/mock.rs @@ -58,9 +58,8 @@ use zeitgeist_primitives::{ MaxLocks, MaxMarketLifetime, MaxOracleDuration, MaxOwners, MaxRejectReasonLen, MaxReserves, MaxSelectedDraws, MaxYearlyInflation, MinCategories, MinDisputeDuration, MinJurorStake, MinOracleDuration, MinOutcomeVoteAmount, MinimumPeriod, NeoMaxSwapFee, - NeoSwapsPalletId, OutcomeBond, OutcomeFactor, OutsiderBond, PmPalletId, - RemoveKeysLimit, RequestInterval, SimpleDisputesPalletId, TreasuryPalletId, VotePeriod, - VotingOutcomeFee, BASE, CENT, + NeoSwapsPalletId, OutsiderBond, PmPalletId, RemoveKeysLimit, RequestInterval, + TreasuryPalletId, VotePeriod, VotingOutcomeFee, BASE, CENT, }, }, math::fixed::FixedMul, @@ -187,7 +186,6 @@ construct_runtime!( MarketCommons: zrml_market_commons::{Pallet, Storage}, PredictionMarkets: zrml_prediction_markets::{Event, Pallet, Storage}, RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage}, - SimpleDisputes: zrml_simple_disputes::{Event, Pallet, Storage}, GlobalDisputes: zrml_global_disputes::{Event, Pallet, Storage}, System: frame_system::{Call, Config, Event, Pallet, Storage}, Timestamp: pallet_timestamp::{Pallet}, @@ -369,7 +367,6 @@ impl zrml_prediction_markets::Config for Runtime { type RequestEditOrigin = EnsureSignedBy; type ResolveOrigin = EnsureSignedBy; type AssetManager = AssetManager; - type SimpleDisputes = SimpleDisputes; type Slash = Treasury; type ValidityBond = ValidityBond; type WeightInfo = zrml_prediction_markets::weights::WeightInfo; @@ -487,18 +484,6 @@ impl pallet_timestamp::Config for Runtime { type WeightInfo = (); } -impl zrml_simple_disputes::Config for Runtime { - type Currency = Balances; - type RuntimeEvent = RuntimeEvent; - type OutcomeBond = OutcomeBond; - type OutcomeFactor = OutcomeFactor; - type DisputeResolution = zrml_prediction_markets::Pallet; - type MarketCommons = MarketCommons; - type MaxDisputes = MaxDisputes; - type PalletId = SimpleDisputesPalletId; - type WeightInfo = zrml_simple_disputes::weights::WeightInfo; -} - impl zrml_global_disputes::Config for Runtime { type AddOutcomePeriod = AddOutcomePeriod; type RuntimeEvent = RuntimeEvent; diff --git a/zrml/prediction-markets/Cargo.toml b/zrml/prediction-markets/Cargo.toml index b4f24633a..037e183f0 100644 --- a/zrml/prediction-markets/Cargo.toml +++ b/zrml/prediction-markets/Cargo.toml @@ -14,7 +14,6 @@ zrml-authorized = { workspace = true } zrml-court = { workspace = true } zrml-global-disputes = { workspace = true } zrml-market-commons = { workspace = true } -zrml-simple-disputes = { workspace = true } # Mock @@ -83,7 +82,6 @@ std = [ "zrml-authorized/std", "zrml-court/std", "zrml-market-commons/std", - "zrml-simple-disputes/std", "zrml-global-disputes/std", "xcm?/std", ] diff --git a/zrml/prediction-markets/fuzz/Cargo.toml b/zrml/prediction-markets/fuzz/Cargo.toml index 4f88a31d2..e8f744e4d 100644 --- a/zrml/prediction-markets/fuzz/Cargo.toml +++ b/zrml/prediction-markets/fuzz/Cargo.toml @@ -11,7 +11,6 @@ libfuzzer-sys = { workspace = true } sp-arithmetic = { workspace = true, features = ["default"] } zeitgeist-primitives = { workspace = true, features = ["arbitrary", "mock", "default"] } zrml-prediction-markets = { workspace = true, features = ["mock", "default"] } -zrml-simple-disputes = { workspace = true, features = ["default"] } [package] authors = ["Automatically generated"] diff --git a/zrml/prediction-markets/fuzz/pm_full_workflow.rs b/zrml/prediction-markets/fuzz/pm_full_workflow.rs index f3799a127..974201c68 100644 --- a/zrml/prediction-markets/fuzz/pm_full_workflow.rs +++ b/zrml/prediction-markets/fuzz/pm_full_workflow.rs @@ -134,7 +134,6 @@ fn market_dispute_mechanism(seed: u8) -> Option { match seed % 4 { 0 => Some(MarketDisputeMechanism::Authorized), 1 => Some(MarketDisputeMechanism::Court), - 2 => Some(MarketDisputeMechanism::SimpleDisputes), _ => None, } } diff --git a/zrml/prediction-markets/src/benchmarks.rs b/zrml/prediction-markets/src/benchmarks.rs index 01903a795..8b874c025 100644 --- a/zrml/prediction-markets/src/benchmarks.rs +++ b/zrml/prediction-markets/src/benchmarks.rs @@ -231,7 +231,7 @@ fn create_spot_prices(asset_count: u16) -> Vec> { benchmarks! { where_clause { where - T: pallet_timestamp::Config + zrml_authorized::Config + zrml_simple_disputes::Config + zrml_court::Config, + T: pallet_timestamp::Config + zrml_authorized::Config + zrml_court::Config, <::MarketCommons as MarketCommonsPalletApi>::MarketId: From<::MarketId>, } diff --git a/zrml/prediction-markets/src/lib.rs b/zrml/prediction-markets/src/lib.rs index 94949f26e..dc179aca8 100644 --- a/zrml/prediction-markets/src/lib.rs +++ b/zrml/prediction-markets/src/lib.rs @@ -556,11 +556,7 @@ mod pallet { /// Complexity: `O(n)`, where `n` is the number of outstanding disputes. #[pallet::call_index(6)] #[pallet::weight( - T::WeightInfo::dispute_authorized().saturating_add( - T::Court::on_dispute_max_weight().saturating_add( - T::SimpleDisputes::on_dispute_max_weight() - ) - ) + T::WeightInfo::dispute_authorized().saturating_add(T::Court::on_dispute_max_weight()) )] #[transactional] pub fn dispute( @@ -585,12 +581,6 @@ mod pallet { .saturating_sub(T::Authorized::on_dispute_max_weight()) .saturating_add(court_weight) } - MarketDisputeMechanism::SimpleDisputes => { - let sd_weight = T::SimpleDisputes::on_dispute(&market_id, &market)?.weight; - T::WeightInfo::dispute_authorized() - .saturating_sub(T::Authorized::on_dispute_max_weight()) - .saturating_add(sd_weight) - } }; let dispute_bond = T::DisputeBond::get(); @@ -1016,9 +1006,6 @@ mod pallet { T::Authorized::has_failed(&market_id, &market)? } MarketDisputeMechanism::Court => T::Court::has_failed(&market_id, &market)?, - MarketDisputeMechanism::SimpleDisputes => { - T::SimpleDisputes::has_failed(&market_id, &market)? - } }; let has_failed = res_0.result; ensure!(has_failed, Error::::MarketDisputeMechanismNotFailed); @@ -1028,9 +1015,6 @@ mod pallet { T::Authorized::on_global_dispute(&market_id, &market)? } MarketDisputeMechanism::Court => T::Court::on_global_dispute(&market_id, &market)?, - MarketDisputeMechanism::SimpleDisputes => { - T::SimpleDisputes::on_global_dispute(&market_id, &market)? - } }; let mut initial_items: Vec> = Vec::new(); @@ -1731,17 +1715,6 @@ mod pallet { /// The origin that is allowed to resolve markets. type ResolveOrigin: EnsureOrigin; - /// See [`DisputeApi`]. - type SimpleDisputes: zrml_simple_disputes::SimpleDisputesPalletApi< - AccountId = Self::AccountId, - Balance = BalanceOf, - NegativeImbalance = NegativeImbalanceOf, - BlockNumber = Self::BlockNumber, - MarketId = MarketIdOf, - Moment = MomentOf, - Origin = Self::RuntimeOrigin, - >; - /// Handler for slashed funds. type Slash: OnUnbalanced>; @@ -2273,9 +2246,6 @@ mod pallet { MarketDisputeMechanism::Court => { T::Court::get_auto_resolve(market_id, &market) } - MarketDisputeMechanism::SimpleDisputes => { - T::SimpleDisputes::get_auto_resolve(market_id, &market) - } }; if let Some(auto_resolve_block) = auto_resolve_block_opt { let ids_len = remove_auto_resolve::(market_id, auto_resolve_block); @@ -2638,17 +2608,6 @@ mod pallet { weight = weight.saturating_add(res.weight); remainder } - MarketDisputeMechanism::SimpleDisputes => { - let res = T::SimpleDisputes::exchange( - market_id, - market, - &resolved_outcome, - imbalance_left, - )?; - let remainder = res.result; - weight = weight.saturating_add(res.weight); - remainder - } }; T::Slash::on_unbalanced(remainder); @@ -2687,11 +2646,6 @@ mod pallet { weight = weight.saturating_add(res.weight); res.result } - MarketDisputeMechanism::SimpleDisputes => { - let res = T::SimpleDisputes::on_resolution(market_id, market)?; - weight = weight.saturating_add(res.weight); - res.result - } }; } diff --git a/zrml/prediction-markets/src/mock.rs b/zrml/prediction-markets/src/mock.rs index f811b0040..eec8501c7 100644 --- a/zrml/prediction-markets/src/mock.rs +++ b/zrml/prediction-markets/src/mock.rs @@ -57,9 +57,9 @@ use zeitgeist_primitives::{ MaxEditReasonLen, MaxGlobalDisputeVotes, MaxGracePeriod, MaxMarketLifetime, MaxOracleDuration, MaxOwners, MaxRejectReasonLen, MaxReserves, MaxSelectedDraws, MaxYearlyInflation, MinCategories, MinDisputeDuration, MinJurorStake, MinOracleDuration, - MinOutcomeVoteAmount, MinimumPeriod, OutcomeBond, OutcomeFactor, OutsiderBond, PmPalletId, - RemoveKeysLimit, RequestInterval, SimpleDisputesPalletId, TreasuryPalletId, VotePeriod, - VotingOutcomeFee, BASE, CENT, MILLISECS_PER_BLOCK, + MinOutcomeVoteAmount, MinimumPeriod, OutsiderBond, PmPalletId, RemoveKeysLimit, + RequestInterval, TreasuryPalletId, VotePeriod, VotingOutcomeFee, BASE, CENT, + MILLISECS_PER_BLOCK, }, traits::{DeployPoolApi, MarketTransitionApi}, types::{ @@ -234,7 +234,6 @@ construct_runtime!( MarketCommons: zrml_market_commons::{Pallet, Storage}, PredictionMarkets: prediction_markets::{Event, Pallet, Storage}, RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage}, - SimpleDisputes: zrml_simple_disputes::{Event, Pallet, Storage}, GlobalDisputes: zrml_global_disputes::{Event, Pallet, Storage}, System: frame_system::{Call, Config, Event, Pallet, Storage}, Timestamp: pallet_timestamp::{Pallet}, @@ -286,7 +285,6 @@ impl crate::Config for Runtime { type RejectOrigin = EnsureSignedBy; type RequestEditOrigin = EnsureSignedBy; type ResolveOrigin = EnsureSignedBy; - type SimpleDisputes = SimpleDisputes; type Slash = Treasury; type ValidityBond = ValidityBond; type WeightInfo = prediction_markets::weights::WeightInfo; @@ -534,18 +532,6 @@ impl zrml_market_commons::Config for Runtime { type Timestamp = Timestamp; } -impl zrml_simple_disputes::Config for Runtime { - type Currency = Balances; - type RuntimeEvent = RuntimeEvent; - type OutcomeBond = OutcomeBond; - type OutcomeFactor = OutcomeFactor; - type DisputeResolution = prediction_markets::Pallet; - type MarketCommons = MarketCommons; - type MaxDisputes = MaxDisputes; - type PalletId = SimpleDisputesPalletId; - type WeightInfo = zrml_simple_disputes::weights::WeightInfo; -} - impl zrml_global_disputes::Config for Runtime { type AddOutcomePeriod = AddOutcomePeriod; type RuntimeEvent = RuntimeEvent; diff --git a/zrml/prediction-markets/src/tests/admin_move_market_to_closed.rs b/zrml/prediction-markets/src/tests/admin_move_market_to_closed.rs index 90896a335..2daa4259a 100644 --- a/zrml/prediction-markets/src/tests/admin_move_market_to_closed.rs +++ b/zrml/prediction-markets/src/tests/admin_move_market_to_closed.rs @@ -67,7 +67,7 @@ fn admin_move_market_to_closed_successfully_closes_market_and_sets_end_timestamp gen_metadata(2), MarketCreation::Permissionless, MarketType::Categorical(::MinCategories::get()), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid )); let market_id = 0; @@ -148,7 +148,7 @@ fn admin_move_market_to_closed_correctly_clears_auto_close_blocks() { gen_metadata(50), MarketCreation::Permissionless, MarketType::Categorical(category_count), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, )); assert_ok!(PredictionMarkets::create_market( @@ -161,7 +161,7 @@ fn admin_move_market_to_closed_correctly_clears_auto_close_blocks() { gen_metadata(50), MarketCreation::Permissionless, MarketType::Categorical(category_count), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, )); assert_ok!(PredictionMarkets::admin_move_market_to_closed( diff --git a/zrml/prediction-markets/src/tests/approve_market.rs b/zrml/prediction-markets/src/tests/approve_market.rs index 6eabd8566..4c42ebfe0 100644 --- a/zrml/prediction-markets/src/tests/approve_market.rs +++ b/zrml/prediction-markets/src/tests/approve_market.rs @@ -125,7 +125,7 @@ fn approve_market_correctly_unreserves_advisory_bond() { gen_metadata(2), MarketCreation::Advised, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, )); let market_id = 0; diff --git a/zrml/prediction-markets/src/tests/create_market.rs b/zrml/prediction-markets/src/tests/create_market.rs index bb2baf79d..4e990882e 100644 --- a/zrml/prediction-markets/src/tests/create_market.rs +++ b/zrml/prediction-markets/src/tests/create_market.rs @@ -52,7 +52,7 @@ fn fails_if_user_cannot_afford_bonds_advised( gen_metadata(2), market_creation, MarketType::Scalar(0..=1), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, ), pallet_balances::Error::::InsufficientBalance @@ -75,7 +75,7 @@ fn fails_on_fee_too_high() { gen_metadata(2), MarketCreation::Permissionless, MarketType::Scalar(0..=1), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, ), Error::::FeeTooHigh @@ -101,7 +101,7 @@ fn fails_on_invalid_multihash() { multihash, MarketCreation::Permissionless, MarketType::Scalar(0..=1), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, ), Error::::InvalidMultihash @@ -124,7 +124,7 @@ fn create_scalar_market_fails_on_invalid_range(range: RangeInclusive) { gen_metadata(2), MarketCreation::Permissionless, MarketType::Scalar(range), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, ), Error::::InvalidOutcomeRange @@ -151,7 +151,7 @@ fn create_market_fails_on_min_dispute_period() { gen_metadata(2), MarketCreation::Permissionless, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, ), Error::::DisputeDurationSmallerThanMinDisputeDuration @@ -178,7 +178,7 @@ fn create_market_fails_on_min_oracle_duration() { gen_metadata(2), MarketCreation::Permissionless, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, ), Error::::OracleDurationSmallerThanMinOracleDuration @@ -205,7 +205,7 @@ fn create_market_fails_on_max_dispute_period() { gen_metadata(2), MarketCreation::Permissionless, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, ), Error::::DisputeDurationGreaterThanMaxDisputeDuration @@ -232,7 +232,7 @@ fn create_market_fails_on_max_grace_period() { gen_metadata(2), MarketCreation::Permissionless, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, ), Error::::GracePeriodGreaterThanMaxGracePeriod @@ -259,7 +259,7 @@ fn create_market_fails_on_max_oracle_duration() { gen_metadata(2), MarketCreation::Permissionless, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, ), Error::::OracleDurationGreaterThanMaxOracleDuration @@ -291,7 +291,7 @@ fn create_market_with_foreign_assets() { gen_metadata(2), MarketCreation::Permissionless, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, ), Error::::InvalidBaseAsset, @@ -308,7 +308,7 @@ fn create_market_with_foreign_assets() { gen_metadata(2), MarketCreation::Permissionless, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, ), Error::::UnregisteredForeignAsset, @@ -324,7 +324,7 @@ fn create_market_with_foreign_assets() { gen_metadata(2), MarketCreation::Permissionless, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, )); let market = MarketCommons::market(&0).unwrap(); @@ -346,7 +346,7 @@ fn it_does_not_create_market_with_too_few_categories() { gen_metadata(2), MarketCreation::Advised, MarketType::Categorical(::MinCategories::get() - 1), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid ), Error::::NotEnoughCategories @@ -368,7 +368,7 @@ fn it_does_not_create_market_with_too_many_categories() { gen_metadata(2), MarketCreation::Advised, MarketType::Categorical(::MaxCategories::get() + 1), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid ), Error::::TooManyCategories diff --git a/zrml/prediction-markets/src/tests/edit_market.rs b/zrml/prediction-markets/src/tests/edit_market.rs index a1d5d3e93..46b8282fe 100644 --- a/zrml/prediction-markets/src/tests/edit_market.rs +++ b/zrml/prediction-markets/src/tests/edit_market.rs @@ -61,7 +61,7 @@ fn only_creator_can_edit_market() { get_deadlines(), gen_metadata(2), MarketType::Categorical(::MinCategories::get()), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid ), Error::::EditorNotCreator @@ -104,7 +104,7 @@ fn edit_cycle_for_proposed_markets() { get_deadlines(), gen_metadata(2), MarketType::Categorical(::MinCategories::get()), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid )); let edited_market = MarketCommons::market(&0).expect("Market not found"); @@ -155,7 +155,7 @@ fn edit_market_with_foreign_asset() { get_deadlines(), gen_metadata(2), MarketType::Categorical(::MinCategories::get()), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid ), Error::::UnregisteredForeignAsset @@ -171,7 +171,7 @@ fn edit_market_with_foreign_asset() { get_deadlines(), gen_metadata(2), MarketType::Categorical(::MinCategories::get()), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid ), Error::::InvalidBaseAsset, @@ -186,7 +186,7 @@ fn edit_market_with_foreign_asset() { get_deadlines(), gen_metadata(2), MarketType::Categorical(::MinCategories::get()), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid )); let market = MarketCommons::market(&0).unwrap(); diff --git a/zrml/prediction-markets/src/tests/integration.rs b/zrml/prediction-markets/src/tests/integration.rs index 4ea7749ff..09c1860e4 100644 --- a/zrml/prediction-markets/src/tests/integration.rs +++ b/zrml/prediction-markets/src/tests/integration.rs @@ -153,7 +153,7 @@ fn the_entire_market_lifecycle_works_with_timestamps() { gen_metadata(2), MarketCreation::Permissionless, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid )); @@ -193,7 +193,7 @@ fn full_scalar_market_lifecycle() { gen_metadata(3), MarketCreation::Permissionless, MarketType::Scalar(10..=30), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Authorized), ScoringRule::AmmCdaHybrid )); @@ -234,20 +234,15 @@ fn full_scalar_market_lifecycle() { // dispute assert_ok!(PredictionMarkets::dispute(RuntimeOrigin::signed(DAVE), 0)); - assert_ok!(SimpleDisputes::suggest_outcome( - RuntimeOrigin::signed(DAVE), + assert_ok!(Authorized::authorize_market_outcome( + RuntimeOrigin::signed(AuthorizedDisputeResolutionUser::get()), 0, OutcomeReport::Scalar(25) )); - let disputes = zrml_simple_disputes::Disputes::::get(0); - assert_eq!(disputes.len(), 1); - - run_blocks(market.deadlines.dispute_duration); + run_blocks(::CorrectionPeriod::get()); let market_after_resolve = MarketCommons::market(&0).unwrap(); assert_eq!(market_after_resolve.status, MarketStatus::Resolved); - let disputes = zrml_simple_disputes::Disputes::::get(0); - assert_eq!(disputes.len(), 0); // give EVE some shares assert_ok!(AssetManager::transfer( @@ -441,8 +436,6 @@ fn authorized_correctly_resolves_disputed_market() { let market_after = MarketCommons::market(&0).unwrap(); assert_eq!(market_after.status, MarketStatus::Resolved); - let disputes = zrml_simple_disputes::Disputes::::get(0); - assert_eq!(disputes.len(), 0); assert_ok!(PredictionMarkets::redeem_shares(RuntimeOrigin::signed(CHARLIE), 0)); @@ -735,7 +728,7 @@ fn outsider_reports_wrong_outcome() { gen_metadata(2), MarketCreation::Permissionless, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Authorized), ScoringRule::AmmCdaHybrid, )); @@ -759,21 +752,17 @@ fn outsider_reports_wrong_outcome() { assert_ok!(PredictionMarkets::dispute(RuntimeOrigin::signed(EVE), 0,)); check_reserve(&EVE, ::DisputeBond::get()); - assert_ok!(SimpleDisputes::suggest_outcome( - RuntimeOrigin::signed(DAVE), + assert_ok!(Authorized::authorize_market_outcome( + RuntimeOrigin::signed(AuthorizedDisputeResolutionUser::get()), 0, OutcomeReport::Categorical(0) )); - let outcome_bond = zrml_simple_disputes::default_outcome_bond::(0); - - check_reserve(&DAVE, outcome_bond); - let eve_balance_before = Balances::free_balance(EVE); let dave_balance_before = Balances::free_balance(DAVE); // on_resolution called - run_blocks(market.deadlines.dispute_duration); + run_blocks(::CorrectionPeriod::get()); assert_eq!( Balances::free_balance(ALICE), @@ -792,7 +781,7 @@ fn outsider_reports_wrong_outcome() { + ::OracleBond::get() ); // DAVE gets his outcome bond back - assert_eq!(Balances::free_balance(DAVE), dave_balance_before + outcome_bond); + assert_eq!(Balances::free_balance(DAVE), dave_balance_before); }; ExtBuilder::default().build().execute_with(|| { test(BaseAsset::CampaignAsset(100)); diff --git a/zrml/prediction-markets/src/tests/manually_close_market.rs b/zrml/prediction-markets/src/tests/manually_close_market.rs index 8af1ee78c..72fb97b67 100644 --- a/zrml/prediction-markets/src/tests/manually_close_market.rs +++ b/zrml/prediction-markets/src/tests/manually_close_market.rs @@ -44,7 +44,7 @@ fn manually_close_market_after_long_stall() { gen_metadata(50), MarketCreation::Permissionless, MarketType::Categorical(category_count), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, )); assert_ok!(PredictionMarkets::create_market( @@ -57,7 +57,7 @@ fn manually_close_market_after_long_stall() { gen_metadata(50), MarketCreation::Permissionless, MarketType::Categorical(category_count), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, )); @@ -113,7 +113,7 @@ fn manually_close_market_fails_if_market_not_in_close_time_frame_list() { gen_metadata(50), MarketCreation::Permissionless, MarketType::Categorical(category_count), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, )); @@ -154,7 +154,7 @@ fn manually_close_market_fails_if_not_allowed_for_block_based_markets() { gen_metadata(50), MarketCreation::Permissionless, MarketType::Categorical(category_count), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, )); diff --git a/zrml/prediction-markets/src/tests/mod.rs b/zrml/prediction-markets/src/tests/mod.rs index 662ff84f8..c97ac073d 100644 --- a/zrml/prediction-markets/src/tests/mod.rs +++ b/zrml/prediction-markets/src/tests/mod.rs @@ -143,7 +143,7 @@ fn simple_create_scalar_market( gen_metadata(2), creation, MarketType::Scalar(100..=200), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), scoring_rule )); } diff --git a/zrml/prediction-markets/src/tests/on_initialize.rs b/zrml/prediction-markets/src/tests/on_initialize.rs index b8c5588c1..b3d3c36d8 100644 --- a/zrml/prediction-markets/src/tests/on_initialize.rs +++ b/zrml/prediction-markets/src/tests/on_initialize.rs @@ -39,7 +39,7 @@ fn on_initialize_skips_the_genesis_block() { gen_metadata(50), MarketCreation::Permissionless, MarketType::Categorical(category_count), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, )); diff --git a/zrml/prediction-markets/src/tests/on_market_close.rs b/zrml/prediction-markets/src/tests/on_market_close.rs index 866797798..7da842c05 100644 --- a/zrml/prediction-markets/src/tests/on_market_close.rs +++ b/zrml/prediction-markets/src/tests/on_market_close.rs @@ -148,7 +148,7 @@ fn on_market_close_successfully_auto_closes_market_with_blocks() { gen_metadata(50), MarketCreation::Permissionless, MarketType::Categorical(category_count), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, )); let market_id = 0; @@ -180,7 +180,7 @@ fn on_market_close_successfully_auto_closes_market_with_timestamps() { gen_metadata(50), MarketCreation::Permissionless, MarketType::Categorical(category_count), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, )); let market_id = 0; @@ -220,7 +220,7 @@ fn on_market_close_successfully_auto_closes_multiple_markets_after_stall() { gen_metadata(50), MarketCreation::Permissionless, MarketType::Categorical(category_count), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, )); assert_ok!(PredictionMarkets::create_market( @@ -233,7 +233,7 @@ fn on_market_close_successfully_auto_closes_multiple_markets_after_stall() { gen_metadata(50), MarketCreation::Permissionless, MarketType::Categorical(category_count), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, )); @@ -271,7 +271,7 @@ fn on_market_close_market_status_manager_exceeds_max_recovery_time_frames_after_ gen_metadata(50), MarketCreation::Permissionless, MarketType::Categorical(category_count), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, )); assert_ok!(PredictionMarkets::create_market( @@ -284,7 +284,7 @@ fn on_market_close_market_status_manager_exceeds_max_recovery_time_frames_after_ gen_metadata(50), MarketCreation::Permissionless, MarketType::Categorical(category_count), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, )); diff --git a/zrml/prediction-markets/src/tests/on_resolution.rs b/zrml/prediction-markets/src/tests/on_resolution.rs index 08b965073..caaa5e80e 100644 --- a/zrml/prediction-markets/src/tests/on_resolution.rs +++ b/zrml/prediction-markets/src/tests/on_resolution.rs @@ -97,7 +97,7 @@ fn on_resolution_correctly_reserves_and_unreserves_bonds_for_approved_advised_ma gen_metadata(2), MarketCreation::Advised, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, )); assert_ok!(PredictionMarkets::approve_market( @@ -149,7 +149,7 @@ fn on_resolution_correctly_reserves_and_unreserves_bonds_for_approved_advised_ma gen_metadata(2), MarketCreation::Advised, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, )); assert_ok!(PredictionMarkets::approve_market( @@ -202,7 +202,7 @@ fn on_resolution_correctly_reserves_and_unreserves_bonds_for_permissionless_mark gen_metadata(2), MarketCreation::Permissionless, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Authorized), ScoringRule::AmmCdaHybrid, )); let alice_balance_before = Balances::free_balance(ALICE); @@ -216,12 +216,12 @@ fn on_resolution_correctly_reserves_and_unreserves_bonds_for_permissionless_mark OutcomeReport::Categorical(0) )); assert_ok!(PredictionMarkets::dispute(RuntimeOrigin::signed(CHARLIE), 0,)); - assert_ok!(SimpleDisputes::suggest_outcome( - RuntimeOrigin::signed(CHARLIE), + assert_ok!(Authorized::authorize_market_outcome( + RuntimeOrigin::signed(AuthorizedDisputeResolutionUser::get()), 0, OutcomeReport::Categorical(1) )); - run_blocks(market.deadlines.dispute_duration); + run_blocks(::CorrectionPeriod::get()); check_reserve(&ALICE, 0); // ValidityBond bond is returned but OracleBond is slashed assert_eq!(Balances::free_balance(ALICE), alice_balance_before + ValidityBond::get()); @@ -256,7 +256,7 @@ fn on_resolution_correctly_reserves_and_unreserves_bonds_for_approved_advised_ma gen_metadata(2), MarketCreation::Advised, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Authorized), ScoringRule::AmmCdaHybrid, )); assert_ok!(PredictionMarkets::approve_market( @@ -274,12 +274,12 @@ fn on_resolution_correctly_reserves_and_unreserves_bonds_for_approved_advised_ma OutcomeReport::Categorical(0) )); assert_ok!(PredictionMarkets::dispute(RuntimeOrigin::signed(CHARLIE), 0,)); - assert_ok!(SimpleDisputes::suggest_outcome( - RuntimeOrigin::signed(CHARLIE), + assert_ok!(Authorized::authorize_market_outcome( + RuntimeOrigin::signed(AuthorizedDisputeResolutionUser::get()), 0, OutcomeReport::Categorical(1) )); - run_blocks(market.deadlines.dispute_duration); + run_blocks(::CorrectionPeriod::get()); check_reserve(&ALICE, 0); // ValidityBond bond is returned but OracleBond is slashed assert_eq!(Balances::free_balance(ALICE), alice_balance_before); @@ -314,7 +314,7 @@ fn on_resolution_correctly_reserves_and_unreserves_bonds_for_permissionless_mark gen_metadata(2), MarketCreation::Permissionless, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Authorized), ScoringRule::AmmCdaHybrid, )); let alice_balance_before = Balances::free_balance(ALICE); @@ -328,18 +328,12 @@ fn on_resolution_correctly_reserves_and_unreserves_bonds_for_permissionless_mark OutcomeReport::Categorical(0) )); assert_ok!(PredictionMarkets::dispute(RuntimeOrigin::signed(EVE), 0,)); - // EVE disputes with wrong outcome - assert_ok!(SimpleDisputes::suggest_outcome( - RuntimeOrigin::signed(EVE), - 0, - OutcomeReport::Categorical(1) - )); - assert_ok!(SimpleDisputes::suggest_outcome( - RuntimeOrigin::signed(CHARLIE), + assert_ok!(Authorized::authorize_market_outcome( + RuntimeOrigin::signed(AuthorizedDisputeResolutionUser::get()), 0, OutcomeReport::Categorical(0) )); - run_blocks(market.deadlines.dispute_duration); + run_blocks(::CorrectionPeriod::get()); check_reserve(&ALICE, 0); // ValidityBond bond is returned but OracleBond is not slashed assert_eq!( @@ -377,7 +371,7 @@ fn on_resolution_correctly_reserves_and_unreserves_bonds_for_advised_approved_ma gen_metadata(2), MarketCreation::Advised, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Authorized), ScoringRule::AmmCdaHybrid, )); assert_ok!(PredictionMarkets::approve_market( @@ -395,18 +389,12 @@ fn on_resolution_correctly_reserves_and_unreserves_bonds_for_advised_approved_ma OutcomeReport::Categorical(0) )); assert_ok!(PredictionMarkets::dispute(RuntimeOrigin::signed(EVE), 0,)); - // EVE disputes with wrong outcome - assert_ok!(SimpleDisputes::suggest_outcome( - RuntimeOrigin::signed(EVE), - 0, - OutcomeReport::Categorical(1) - )); - assert_ok!(SimpleDisputes::suggest_outcome( - RuntimeOrigin::signed(CHARLIE), + assert_ok!(Authorized::authorize_market_outcome( + RuntimeOrigin::signed(AuthorizedDisputeResolutionUser::get()), 0, OutcomeReport::Categorical(0) )); - run_blocks(market.deadlines.dispute_duration); + run_blocks(::CorrectionPeriod::get()); check_reserve(&ALICE, 0); // ValidityBond bond is returned but OracleBond is not slashed assert_eq!(Balances::free_balance(ALICE), alice_balance_before + OracleBond::get()); @@ -441,7 +429,7 @@ fn on_resolution_correctly_reserves_and_unreserves_bonds_for_permissionless_mark gen_metadata(2), MarketCreation::Permissionless, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Authorized), ScoringRule::AmmCdaHybrid, )); @@ -464,18 +452,12 @@ fn on_resolution_correctly_reserves_and_unreserves_bonds_for_permissionless_mark check_reserve(&outsider, ::OutsiderBond::get()); assert_ok!(PredictionMarkets::dispute(RuntimeOrigin::signed(EVE), 0,)); - // EVE disputes with wrong outcome - assert_ok!(SimpleDisputes::suggest_outcome( - RuntimeOrigin::signed(EVE), - 0, - OutcomeReport::Categorical(1) - )); - assert_ok!(SimpleDisputes::suggest_outcome( - RuntimeOrigin::signed(FRED), + assert_ok!(Authorized::authorize_market_outcome( + RuntimeOrigin::signed(AuthorizedDisputeResolutionUser::get()), 0, OutcomeReport::Categorical(0) )); - run_blocks(market.deadlines.dispute_duration); + run_blocks(::CorrectionPeriod::get()); check_reserve(&ALICE, 0); // ValidityBond bond is returned but OracleBond is slashed assert_eq!(Balances::free_balance(ALICE), alice_balance_before + ValidityBond::get()); @@ -516,7 +498,7 @@ fn on_resolution_correctly_reserves_and_unreserves_bonds_for_advised_approved_ma gen_metadata(2), MarketCreation::Advised, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Authorized), ScoringRule::AmmCdaHybrid, )); @@ -542,18 +524,12 @@ fn on_resolution_correctly_reserves_and_unreserves_bonds_for_advised_approved_ma check_reserve(&outsider, ::OutsiderBond::get()); assert_ok!(PredictionMarkets::dispute(RuntimeOrigin::signed(EVE), 0,)); - // EVE disputes with wrong outcome - assert_ok!(SimpleDisputes::suggest_outcome( - RuntimeOrigin::signed(EVE), - 0, - OutcomeReport::Categorical(1) - )); - assert_ok!(SimpleDisputes::suggest_outcome( - RuntimeOrigin::signed(FRED), + assert_ok!(Authorized::authorize_market_outcome( + RuntimeOrigin::signed(AuthorizedDisputeResolutionUser::get()), 0, OutcomeReport::Categorical(0) )); - run_blocks(market.deadlines.dispute_duration); + run_blocks(::CorrectionPeriod::get()); check_reserve(&ALICE, 0); // ValidityBond bond is returned but OracleBond is slashed assert_eq!(Balances::free_balance(ALICE), alice_balance_before); @@ -642,7 +618,7 @@ fn on_resolution_correctly_reserves_and_unreserves_bonds_for_permissionless_mark gen_metadata(2), MarketCreation::Permissionless, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Authorized), ScoringRule::AmmCdaHybrid, )); let alice_balance_before = Balances::free_balance(ALICE); @@ -691,7 +667,7 @@ fn on_resolution_correctly_reserves_and_unreserves_bonds_for_permissionless_mark gen_metadata(2), MarketCreation::Permissionless, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid, )); let alice_balance_before = Balances::free_balance(ALICE); diff --git a/zrml/prediction-markets/src/tests/report.rs b/zrml/prediction-markets/src/tests/report.rs index 34f5e72d6..8d7225545 100644 --- a/zrml/prediction-markets/src/tests/report.rs +++ b/zrml/prediction-markets/src/tests/report.rs @@ -142,7 +142,7 @@ fn it_allows_only_oracle_to_report_the_outcome_of_a_market_during_oracle_duratio gen_metadata(2), MarketCreation::Permissionless, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid )); @@ -290,7 +290,7 @@ fn report_fails_on_market_state_proposed() { gen_metadata(2), MarketCreation::Advised, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid )); assert_noop!( @@ -313,7 +313,7 @@ fn report_fails_on_market_state_closed_for_advised_market() { gen_metadata(2), MarketCreation::Advised, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid )); assert_noop!( @@ -336,7 +336,7 @@ fn report_fails_on_market_state_active() { gen_metadata(2), MarketCreation::Permissionless, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid )); assert_noop!( @@ -359,7 +359,7 @@ fn report_fails_on_market_state_resolved() { gen_metadata(2), MarketCreation::Advised, MarketType::Categorical(2), - Some(MarketDisputeMechanism::SimpleDisputes), + Some(MarketDisputeMechanism::Court), ScoringRule::AmmCdaHybrid )); let _ = MarketCommons::mutate_market(&0, |market| { @@ -373,7 +373,7 @@ fn report_fails_on_market_state_resolved() { }); } -#[test_case(Some(MarketDisputeMechanism::SimpleDisputes); "with_dispute_mechanism")] +#[test_case(Some(MarketDisputeMechanism::Court); "with_dispute_mechanism")] #[test_case(None; "without_dispute_mechanism")] fn does_trigger_market_transition_api(dispute_mechanism: Option) { ExtBuilder::default().build().execute_with(|| { diff --git a/zrml/simple-disputes/Cargo.toml b/zrml/simple-disputes/Cargo.toml deleted file mode 100644 index 75265192f..000000000 --- a/zrml/simple-disputes/Cargo.toml +++ /dev/null @@ -1,45 +0,0 @@ -[dependencies] -frame-benchmarking = { workspace = true, optional = true } -frame-support = { workspace = true } -frame-system = { workspace = true } -orml-traits = { workspace = true } -parity-scale-codec = { workspace = true, features = ["derive", "max-encoded-len"] } -scale-info = { workspace = true, features = ["derive"] } -sp-runtime = { workspace = true } -zeitgeist-primitives = { workspace = true } -zrml-market-commons = { workspace = true } - -[dev-dependencies] -env_logger = { workspace = true } -orml-currencies = { workspace = true, features = ["default"] } -orml-tokens = { workspace = true, features = ["default"] } -pallet-balances = { workspace = true, features = ["default"] } -pallet-timestamp = { workspace = true, features = ["default"] } -sp-io = { workspace = true, features = ["default"] } -zeitgeist-primitives = { workspace = true, features = ["mock", "default"] } - -[features] -default = ["std"] -runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", -] -std = [ - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", - "parity-scale-codec/std", - "sp-runtime/std", - "zeitgeist-primitives/std", - "zrml-market-commons/std", -] -try-runtime = [ - "frame-support/try-runtime", -] - -[package] -authors = ["Zeitgeist PM "] -edition = "2021" -name = "zrml-simple-disputes" -version = "0.5.2" diff --git a/zrml/simple-disputes/README.md b/zrml/simple-disputes/README.md deleted file mode 100644 index e178939ba..000000000 --- a/zrml/simple-disputes/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Simple Disputes Module - -Manages market disputes and resolutions. diff --git a/zrml/simple-disputes/src/benchmarks.rs b/zrml/simple-disputes/src/benchmarks.rs deleted file mode 100644 index 2f06b5652..000000000 --- a/zrml/simple-disputes/src/benchmarks.rs +++ /dev/null @@ -1,176 +0,0 @@ -// Copyright 2023 Forecasting Technologies LTD. -// Copyright 2021-2022 Zeitgeist PM LLC. -// -// This file is part of Zeitgeist. -// -// Zeitgeist is free software: you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the -// Free Software Foundation, either version 3 of the License, or (at -// your option) any later version. -// -// Zeitgeist is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Zeitgeist. If not, see . - -#![allow( - // Auto-generated code is a no man's land - clippy::arithmetic_side_effects -)] -#![allow(clippy::type_complexity)] -#![cfg(feature = "runtime-benchmarks")] - -use crate::Pallet as SimpleDisputes; - -use super::*; -use frame_benchmarking::{account, benchmarks, whitelisted_caller}; -use frame_support::{ - dispatch::RawOrigin, - traits::{Currency, Get, Imbalance}, -}; -use sp_runtime::traits::{One, Saturating}; -use zrml_market_commons::MarketCommonsPalletApi; - -fn fill_disputes(market_id: MarketIdOf, d: u32) { - for i in 0..d { - let now = >::block_number(); - let disputor = account("disputor", i, 0); - let bond = default_outcome_bond::(i as usize); - let _ = T::Currency::deposit_creating(&disputor, bond); - let outcome = OutcomeReport::Scalar((2 + i).into()); - SimpleDisputes::::suggest_outcome( - RawOrigin::Signed(disputor).into(), - market_id, - outcome, - ) - .unwrap(); - >::set_block_number(now.saturating_add(T::BlockNumber::one())); - } -} - -benchmarks! { - suggest_outcome { - let d in 1..(T::MaxDisputes::get() - 1); - let r in 1..63; - let e in 1..63; - - let caller: T::AccountId = whitelisted_caller(); - let market_id = 0u32.into(); - let market = market_mock::(); - T::MarketCommons::push_market(market.clone()).unwrap(); - - fill_disputes::(market_id, d); - let disputes = Disputes::::get(market_id); - let last_dispute = disputes.last().unwrap(); - let auto_resolve = last_dispute.at.saturating_add(market.deadlines.dispute_duration); - for i in 0..r { - let id = T::MarketCommons::push_market(market_mock::()).unwrap(); - T::DisputeResolution::add_auto_resolve(&id, auto_resolve).unwrap(); - } - - let now = >::block_number(); - - let dispute_duration_ends_at_block = - now.saturating_add(market.deadlines.dispute_duration); - for i in 0..e { - let id = T::MarketCommons::push_market(market_mock::()).unwrap(); - T::DisputeResolution::add_auto_resolve(&id, dispute_duration_ends_at_block).unwrap(); - } - - let outcome = OutcomeReport::Scalar(1); - let bond = default_outcome_bond::(T::MaxDisputes::get() as usize); - let _ = T::Currency::deposit_creating(&caller, bond); - }: _(RawOrigin::Signed(caller.clone()), market_id, outcome) - - on_dispute_weight { - let market_id = 0u32.into(); - let market = market_mock::(); - T::MarketCommons::push_market(market.clone()).unwrap(); - }: { - SimpleDisputes::::on_dispute(&market_id, &market).unwrap(); - } - - on_resolution_weight { - let d in 1..T::MaxDisputes::get(); - - let market_id = 0u32.into(); - let market = market_mock::(); - T::MarketCommons::push_market(market.clone()).unwrap(); - - fill_disputes::(market_id, d); - }: { - SimpleDisputes::::on_resolution(&market_id, &market).unwrap(); - } - - exchange_weight { - let d in 1..T::MaxDisputes::get(); - - let market_id = 0u32.into(); - let market = market_mock::(); - T::MarketCommons::push_market(market.clone()).unwrap(); - - fill_disputes::(market_id, d); - - let outcome = OutcomeReport::Scalar(1); - let imb = NegativeImbalanceOf::::zero(); - }: { - SimpleDisputes::::exchange(&market_id, &market, &outcome, imb).unwrap(); - } - - get_auto_resolve_weight { - let d in 1..T::MaxDisputes::get(); - - let market_id = 0u32.into(); - let market = market_mock::(); - T::MarketCommons::push_market(market.clone()).unwrap(); - - fill_disputes::(market_id, d); - }: { - SimpleDisputes::::get_auto_resolve(&market_id, &market); - } - - has_failed_weight { - let d in 1..T::MaxDisputes::get(); - - let market_id = 0u32.into(); - let market = market_mock::(); - T::MarketCommons::push_market(market.clone()).unwrap(); - - fill_disputes::(market_id, d); - }: { - SimpleDisputes::::has_failed(&market_id, &market).unwrap(); - } - - on_global_dispute_weight { - let d in 1..T::MaxDisputes::get(); - - let market_id = 0u32.into(); - let market = market_mock::(); - T::MarketCommons::push_market(market.clone()).unwrap(); - - fill_disputes::(market_id, d); - }: { - SimpleDisputes::::on_global_dispute(&market_id, &market).unwrap(); - } - - clear_weight { - let d in 1..T::MaxDisputes::get(); - - let market_id = 0u32.into(); - let market = market_mock::(); - T::MarketCommons::push_market(market.clone()).unwrap(); - - fill_disputes::(market_id, d); - }: { - SimpleDisputes::::clear(&market_id, &market).unwrap(); - } - - impl_benchmark_test_suite!( - SimpleDisputes, - crate::mock::ExtBuilder::default().build(), - crate::mock::Runtime, - ); -} diff --git a/zrml/simple-disputes/src/lib.rs b/zrml/simple-disputes/src/lib.rs deleted file mode 100644 index ba02d764b..000000000 --- a/zrml/simple-disputes/src/lib.rs +++ /dev/null @@ -1,586 +0,0 @@ -// Copyright 2022-2024 Forecasting Technologies LTD. -// Copyright 2021-2022 Zeitgeist PM LLC. -// -// This file is part of Zeitgeist. -// -// Zeitgeist is free software: you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the -// Free Software Foundation, either version 3 of the License, or (at -// your option) any later version. -// -// Zeitgeist is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Zeitgeist. If not, see . - -#![doc = include_str!("../README.md")] -#![cfg_attr(not(feature = "std"), no_std)] - -extern crate alloc; - -#[cfg(feature = "runtime-benchmarks")] -mod benchmarks; -mod mock; -mod simple_disputes_pallet_api; -mod tests; -pub mod weights; - -pub use pallet::*; -pub use simple_disputes_pallet_api::SimpleDisputesPalletApi; -use zeitgeist_primitives::{ - traits::{DisputeApi, DisputeMaxWeightApi, DisputeResolutionApi}, - types::{ - BaseAsset, GlobalDisputeItem, Market, MarketDispute, MarketDisputeMechanism, MarketStatus, - OutcomeReport, Report, ResultWithWeightInfo, - }, -}; - -#[frame_support::pallet] -mod pallet { - use super::*; - use crate::{weights::WeightInfoZeitgeist, SimpleDisputesPalletApi}; - use alloc::vec::Vec; - use core::marker::PhantomData; - use frame_support::{ - dispatch::DispatchResult, - ensure, - pallet_prelude::{ - Blake2_128Concat, ConstU32, DispatchResultWithPostInfo, StorageMap, ValueQuery, Weight, - }, - traits::{Currency, Get, Hooks, Imbalance, IsType, NamedReservableCurrency}, - transactional, BoundedVec, PalletId, - }; - use frame_system::pallet_prelude::*; - use sp_runtime::{ - traits::{CheckedDiv, Saturating, Zero}, - DispatchError, SaturatedConversion, - }; - - use zrml_market_commons::MarketCommonsPalletApi; - - #[pallet::config] - pub trait Config: frame_system::Config { - type Currency: NamedReservableCurrency; - - /// Event - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - - /// The base amount of currency that must be bonded in order to create a dispute. - #[pallet::constant] - type OutcomeBond: Get>; - - type DisputeResolution: DisputeResolutionApi< - AccountId = Self::AccountId, - BlockNumber = Self::BlockNumber, - MarketId = MarketIdOf, - Moment = MomentOf, - >; - - /// The additional amount of currency that must be bonded when creating a subsequent - /// dispute. - #[pallet::constant] - type OutcomeFactor: Get>; - - /// The identifier of individual markets. - type MarketCommons: MarketCommonsPalletApi< - AccountId = Self::AccountId, - BlockNumber = Self::BlockNumber, - Balance = BalanceOf, - >; - - /// The maximum number of disputes allowed on any single market. - #[pallet::constant] - type MaxDisputes: Get; - - /// The pallet identifier. - #[pallet::constant] - type PalletId: Get; - - /// Weights generated by benchmarks - type WeightInfo: WeightInfoZeitgeist; - } - - pub(crate) type BalanceOf = - <::Currency as Currency<::AccountId>>::Balance; - pub(crate) type NegativeImbalanceOf = <::Currency as Currency< - ::AccountId, - >>::NegativeImbalance; - pub type MarketIdOf = <::MarketCommons as MarketCommonsPalletApi>::MarketId; - pub(crate) type MomentOf = <::MarketCommons as MarketCommonsPalletApi>::Moment; - pub(crate) type MarketOf = Market< - ::AccountId, - BalanceOf, - ::BlockNumber, - MomentOf, - BaseAsset, - MarketIdOf, - >; - pub(crate) type DisputesOf = BoundedVec< - MarketDispute< - ::AccountId, - ::BlockNumber, - BalanceOf, - >, - ::MaxDisputes, - >; - pub type CacheSize = ConstU32<64>; - - #[pallet::pallet] - pub struct Pallet(PhantomData); - - /// For each market, this holds the dispute information for each dispute that's - /// been issued. - #[pallet::storage] - pub type Disputes = - StorageMap<_, Blake2_128Concat, MarketIdOf, DisputesOf, ValueQuery>; - - #[pallet::event] - #[pallet::generate_deposit(fn deposit_event)] - pub enum Event - where - T: Config, - { - OutcomeReserved { - market_id: MarketIdOf, - dispute: MarketDispute>, - }, - } - - #[pallet::error] - pub enum Error { - /// 1. Any resolution must either have a `Disputed` or `Reported` market status - /// 2. If status is `Disputed`, then at least one dispute must exist - InvalidMarketStatus, - /// On dispute or resolution, someone tried to pass a non-simple-disputes market type - MarketDoesNotHaveSimpleDisputesMechanism, - StorageOverflow, - OutcomeMismatch, - CannotDisputeSameOutcome, - MarketIsNotReported, - /// The maximum number of disputes has been reached. - MaxDisputesReached, - } - - #[pallet::hooks] - impl Hooks for Pallet {} - - #[pallet::call] - impl Pallet { - #[pallet::call_index(0)] - #[pallet::weight(T::WeightInfo::suggest_outcome( - T::MaxDisputes::get(), - CacheSize::get(), - CacheSize::get(), - ))] - #[transactional] - pub fn suggest_outcome( - origin: OriginFor, - #[pallet::compact] market_id: MarketIdOf, - outcome: OutcomeReport, - ) -> DispatchResultWithPostInfo { - let who = ensure_signed(origin)?; - let market = T::MarketCommons::market(&market_id)?; - Self::ensure_dispute_mechanism(&market)?; - ensure!(market.status == MarketStatus::Disputed, Error::::InvalidMarketStatus); - ensure!(market.matches_outcome_report(&outcome), Error::::OutcomeMismatch); - let report = market.report.as_ref().ok_or(Error::::MarketIsNotReported)?; - - let now = >::block_number(); - let disputes = Disputes::::get(market_id); - let num_disputes: u32 = disputes.len().saturated_into(); - - Self::ensure_can_not_dispute_the_same_outcome(&disputes, report, &outcome)?; - Self::ensure_disputes_does_not_exceed_max_disputes(num_disputes)?; - - let bond = default_outcome_bond::(disputes.len()); - - T::Currency::reserve_named(&Self::reserve_id(), &who, bond)?; - - let market_dispute = MarketDispute { at: now, by: who, outcome, bond }; - >::try_mutate(market_id, |disputes| { - disputes.try_push(market_dispute.clone()).map_err(|_| >::StorageOverflow) - })?; - - // each dispute resets dispute_duration - let r = Self::remove_auto_resolve(disputes.as_slice(), &market_id, &market); - let dispute_duration_ends_at_block = - now.saturating_add(market.deadlines.dispute_duration); - let e = - T::DisputeResolution::add_auto_resolve(&market_id, dispute_duration_ends_at_block)?; - - Self::deposit_event(Event::OutcomeReserved { market_id, dispute: market_dispute }); - - Ok((Some(T::WeightInfo::suggest_outcome(num_disputes, r, e))).into()) - } - } - - impl Pallet { - #[inline] - pub fn reserve_id() -> [u8; 8] { - T::PalletId::get().0 - } - - fn ensure_can_not_dispute_the_same_outcome( - disputes: &[MarketDispute>], - report: &Report, - outcome: &OutcomeReport, - ) -> DispatchResult { - if let Some(last_dispute) = disputes.last() { - ensure!(&last_dispute.outcome != outcome, Error::::CannotDisputeSameOutcome); - } else { - ensure!(&report.outcome != outcome, Error::::CannotDisputeSameOutcome); - } - - Ok(()) - } - - #[inline] - fn ensure_disputes_does_not_exceed_max_disputes(num_disputes: u32) -> DispatchResult { - ensure!(num_disputes < T::MaxDisputes::get(), Error::::MaxDisputesReached); - Ok(()) - } - - #[inline] - fn ensure_dispute_mechanism(market: &MarketOf) -> DispatchResult { - ensure!( - market.dispute_mechanism == Some(MarketDisputeMechanism::SimpleDisputes), - Error::::MarketDoesNotHaveSimpleDisputesMechanism - ); - Ok(()) - } - - fn get_auto_resolve( - disputes: &[MarketDispute>], - market: &MarketOf, - ) -> Option { - disputes.last().map(|last_dispute| { - last_dispute.at.saturating_add(market.deadlines.dispute_duration) - }) - } - - fn remove_auto_resolve( - disputes: &[MarketDispute>], - market_id: &MarketIdOf, - market: &MarketOf, - ) -> u32 { - if let Some(dispute_duration_ends_at_block) = Self::get_auto_resolve(disputes, market) { - return T::DisputeResolution::remove_auto_resolve( - market_id, - dispute_duration_ends_at_block, - ); - } - 0u32 - } - } - - impl DisputeMaxWeightApi for Pallet - where - T: Config, - { - fn on_dispute_max_weight() -> Weight { - T::WeightInfo::on_dispute_weight() - } - - fn on_resolution_max_weight() -> Weight { - T::WeightInfo::on_resolution_weight(T::MaxDisputes::get()) - } - - fn exchange_max_weight() -> Weight { - T::WeightInfo::exchange_weight(T::MaxDisputes::get()) - } - - fn get_auto_resolve_max_weight() -> Weight { - T::WeightInfo::get_auto_resolve_weight(T::MaxDisputes::get()) - } - - fn has_failed_max_weight() -> Weight { - T::WeightInfo::has_failed_weight(T::MaxDisputes::get()) - } - - fn on_global_dispute_max_weight() -> Weight { - T::WeightInfo::on_global_dispute_weight(T::MaxDisputes::get()) - } - - fn clear_max_weight() -> Weight { - T::WeightInfo::clear_weight(T::MaxDisputes::get()) - } - } - - impl DisputeApi for Pallet - where - T: Config, - { - type AccountId = T::AccountId; - type Balance = BalanceOf; - type NegativeImbalance = NegativeImbalanceOf; - type BlockNumber = T::BlockNumber; - type MarketId = MarketIdOf; - type Moment = MomentOf; - type Origin = T::RuntimeOrigin; - - fn on_dispute( - _: &Self::MarketId, - market: &MarketOf, - ) -> Result, DispatchError> { - Self::ensure_dispute_mechanism(market)?; - - let res = - ResultWithWeightInfo { result: (), weight: T::WeightInfo::on_dispute_weight() }; - - Ok(res) - } - - fn on_resolution( - market_id: &Self::MarketId, - market: &MarketOf, - ) -> Result>, DispatchError> { - Self::ensure_dispute_mechanism(market)?; - ensure!(market.status == MarketStatus::Disputed, Error::::InvalidMarketStatus); - - let disputes = Disputes::::get(market_id); - - let last_dispute = match disputes.last() { - Some(l) => l, - // if there are no disputes, then the market is resolved with the default report - None => { - return Ok(ResultWithWeightInfo { - result: None, - weight: T::WeightInfo::on_resolution_weight(disputes.len() as u32), - }); - } - }; - - let res = ResultWithWeightInfo { - result: Some(last_dispute.outcome.clone()), - weight: T::WeightInfo::on_resolution_weight(disputes.len() as u32), - }; - - Ok(res) - } - - fn exchange( - market_id: &Self::MarketId, - market: &MarketOf, - resolved_outcome: &OutcomeReport, - mut overall_imbalance: NegativeImbalanceOf, - ) -> Result>, DispatchError> { - Self::ensure_dispute_mechanism(market)?; - ensure!(market.status == MarketStatus::Disputed, Error::::InvalidMarketStatus); - - let disputes = Disputes::::get(market_id); - - let mut correct_reporters: Vec = Vec::new(); - - for dispute in disputes.iter() { - if &dispute.outcome == resolved_outcome { - let missing = T::Currency::unreserve_named( - &Self::reserve_id(), - &dispute.by, - dispute.bond.saturated_into::().saturated_into(), - ); - debug_assert!( - missing.is_zero(), - "Could not unreserve all of the amount. reserve_id: {:?}, who: {:?}, \ - amount: {:?}, missing: {:?}", - Self::reserve_id(), - &dispute.by, - dispute.bond.saturated_into::(), - missing, - ); - - correct_reporters.push(dispute.by.clone()); - } else { - let (imbalance, missing) = T::Currency::slash_reserved_named( - &Self::reserve_id(), - &dispute.by, - dispute.bond.saturated_into::().saturated_into(), - ); - debug_assert!( - missing.is_zero(), - "Could not slash all of the amount. reserve_id {:?}, who: {:?}, amount: \ - {:?}.", - &Self::reserve_id(), - &dispute.by, - dispute.bond.saturated_into::(), - ); - overall_imbalance.subsume(imbalance); - } - } - - // Fold all the imbalances into one and reward the correct reporters. The - // number of correct reporters might be zero if the market defaults to the - // report after abandoned dispute. In that case, the rewards remain slashed. - if let Some(reward_per_each) = - overall_imbalance.peek().checked_div(&correct_reporters.len().saturated_into()) - { - for correct_reporter in &correct_reporters { - let (actual_reward, leftover) = overall_imbalance.split(reward_per_each); - overall_imbalance = leftover; - T::Currency::resolve_creating(correct_reporter, actual_reward); - } - } - - Disputes::::remove(market_id); - - let res = ResultWithWeightInfo { - result: overall_imbalance, - weight: T::WeightInfo::exchange_weight(disputes.len() as u32), - }; - - Ok(res) - } - - fn get_auto_resolve( - market_id: &Self::MarketId, - market: &MarketOf, - ) -> ResultWithWeightInfo> { - if market.dispute_mechanism != Some(MarketDisputeMechanism::SimpleDisputes) { - return ResultWithWeightInfo { - result: None, - weight: T::WeightInfo::get_auto_resolve_weight(T::MaxDisputes::get()), - }; - } - - let disputes = Disputes::::get(market_id); - - let res = ResultWithWeightInfo { - result: Self::get_auto_resolve(disputes.as_slice(), market), - weight: T::WeightInfo::get_auto_resolve_weight(disputes.len() as u32), - }; - - res - } - - fn has_failed( - market_id: &Self::MarketId, - market: &MarketOf, - ) -> Result, DispatchError> { - Self::ensure_dispute_mechanism(market)?; - let disputes = >::get(market_id); - let disputes_len = disputes.len() as u32; - - let res = ResultWithWeightInfo { - result: disputes_len == T::MaxDisputes::get(), - weight: T::WeightInfo::has_failed_weight(disputes_len), - }; - - Ok(res) - } - - fn on_global_dispute( - market_id: &Self::MarketId, - market: &MarketOf, - ) -> Result< - ResultWithWeightInfo>>, - DispatchError, - > { - Self::ensure_dispute_mechanism(market)?; - - let disputes_len = >::decode_len(market_id).unwrap_or(0) as u32; - - let res = ResultWithWeightInfo { - result: >::get(market_id) - .iter() - .map(|dispute| GlobalDisputeItem { - outcome: dispute.outcome.clone(), - owner: dispute.by.clone(), - initial_vote_amount: dispute.bond, - }) - .collect(), - weight: T::WeightInfo::on_global_dispute_weight(disputes_len), - }; - - Ok(res) - } - - fn clear( - market_id: &Self::MarketId, - market: &MarketOf, - ) -> Result, DispatchError> { - Self::ensure_dispute_mechanism(market)?; - - let mut disputes_len = 0u32; - // `Disputes` is emtpy unless the market is disputed, so this is just a defensive - // check. - if market.status == MarketStatus::Disputed { - disputes_len = Disputes::::decode_len(market_id).unwrap_or(0) as u32; - for dispute in Disputes::::take(market_id).iter() { - let missing = T::Currency::unreserve_named( - &Self::reserve_id(), - &dispute.by, - dispute.bond.saturated_into::().saturated_into(), - ); - debug_assert!( - missing.is_zero(), - "Could not unreserve all of the amount. reserve_id: {:?}, who: {:?}, \ - amount: {:?}, missing: {:?}", - Self::reserve_id(), - &dispute.by, - dispute.bond.saturated_into::(), - missing, - ); - } - } - - let res = ResultWithWeightInfo { - result: (), - weight: T::WeightInfo::clear_weight(disputes_len), - }; - - Ok(res) - } - } - - impl SimpleDisputesPalletApi for Pallet where T: Config {} - - // No-one can bound more than BalanceOf, therefore, this functions saturates - pub fn default_outcome_bond(n: usize) -> BalanceOf - where - T: Config, - { - T::OutcomeBond::get().saturating_add( - T::OutcomeFactor::get().saturating_mul(n.saturated_into::().into()), - ) - } -} - -#[cfg(feature = "runtime-benchmarks")] -pub(crate) fn market_mock() -> MarketOf -where - T: crate::Config, -{ - use frame_support::traits::Get; - use sp_runtime::{traits::AccountIdConversion, SaturatedConversion}; - use zeitgeist_primitives::types::{MarketBonds, ScoringRule}; - - zeitgeist_primitives::types::Market { - market_id: Default::default(), - base_asset: BaseAsset::Ztg, - creation: zeitgeist_primitives::types::MarketCreation::Permissionless, - creator_fee: sp_runtime::Perbill::zero(), - creator: T::PalletId::get().into_account_truncating(), - market_type: zeitgeist_primitives::types::MarketType::Scalar(0..=100), - dispute_mechanism: Some(MarketDisputeMechanism::SimpleDisputes), - metadata: Default::default(), - oracle: T::PalletId::get().into_account_truncating(), - period: zeitgeist_primitives::types::MarketPeriod::Block(Default::default()), - deadlines: zeitgeist_primitives::types::Deadlines { - grace_period: 1_u32.into(), - oracle_duration: 1_u32.into(), - dispute_duration: 42_u32.into(), - }, - report: Some(zeitgeist_primitives::types::Report { - outcome: OutcomeReport::Scalar(0), - at: 0u64.saturated_into(), - by: T::PalletId::get().into_account_truncating(), - }), - resolved_outcome: None, - scoring_rule: ScoringRule::AmmCdaHybrid, - status: zeitgeist_primitives::types::MarketStatus::Disputed, - bonds: MarketBonds::default(), - early_close: None, - } -} diff --git a/zrml/simple-disputes/src/mock.rs b/zrml/simple-disputes/src/mock.rs deleted file mode 100644 index b74e497f0..000000000 --- a/zrml/simple-disputes/src/mock.rs +++ /dev/null @@ -1,225 +0,0 @@ -// Copyright 2022-2024 Forecasting Technologies LTD. -// Copyright 2021-2022 Zeitgeist PM LLC. -// -// This file is part of Zeitgeist. -// -// Zeitgeist is free software: you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the -// Free Software Foundation, either version 3 of the License, or (at -// your option) any later version. -// -// Zeitgeist is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Zeitgeist. If not, see . - -#![cfg(test)] - -use crate::{self as zrml_simple_disputes}; -use frame_support::{ - construct_runtime, ord_parameter_types, - pallet_prelude::{DispatchError, Weight}, - traits::Everything, -}; -use sp_runtime::{ - testing::Header, - traits::{BlakeTwo256, IdentityLookup}, -}; -use zeitgeist_primitives::{ - constants::mock::{ - BlockHashCount, ExistentialDepositsAssets, GetNativeCurrencyId, MaxDisputes, MaxReserves, - MinimumPeriod, OutcomeBond, OutcomeFactor, SimpleDisputesPalletId, BASE, - }, - traits::{DisputeResolutionApi, MarketOfDisputeResolutionApi}, - types::{ - AccountIdTest, Amount, Assets, Balance, BasicCurrencyAdapter, BlockNumber, BlockTest, Hash, - Index, MarketId, Moment, UncheckedExtrinsicTest, - }, -}; - -pub const ALICE: AccountIdTest = 0; -pub const BOB: AccountIdTest = 1; -pub const CHARLIE: AccountIdTest = 2; -pub const DAVE: AccountIdTest = 3; -pub const EVE: AccountIdTest = 4; -pub const FRED: AccountIdTest = 5; -pub const SUDO: AccountIdTest = 69; - -pub const INITIAL_BALANCE: u128 = 1_000 * BASE; - -ord_parameter_types! { - pub const Sudo: AccountIdTest = SUDO; -} - -construct_runtime!( - pub enum Runtime - where - Block = BlockTest, - NodeBlock = BlockTest, - UncheckedExtrinsic = UncheckedExtrinsicTest, - { - AssetManager: orml_currencies::{Call, Pallet, Storage}, - Balances: pallet_balances::{Call, Config, Event, Pallet, Storage}, - MarketCommons: zrml_market_commons::{Pallet, Storage}, - SimpleDisputes: zrml_simple_disputes::{Event, Pallet, Storage}, - System: frame_system::{Call, Config, Event, Pallet, Storage}, - Timestamp: pallet_timestamp::{Pallet}, - Tokens: orml_tokens::{Config, Event, Pallet, Storage}, - } -); - -// NoopResolution implements DisputeResolutionApi with no-ops. -pub struct NoopResolution; - -impl DisputeResolutionApi for NoopResolution { - type AccountId = AccountIdTest; - type Balance = Balance; - type BlockNumber = BlockNumber; - type MarketId = MarketId; - type Moment = Moment; - - fn resolve( - _market_id: &Self::MarketId, - _market: &MarketOfDisputeResolutionApi, - ) -> Result { - Ok(Weight::zero()) - } - - fn add_auto_resolve( - _market_id: &Self::MarketId, - _resolve_at: Self::BlockNumber, - ) -> Result { - Ok(0u32) - } - - fn auto_resolve_exists(_market_id: &Self::MarketId, _resolve_at: Self::BlockNumber) -> bool { - false - } - - fn remove_auto_resolve(_market_id: &Self::MarketId, _resolve_at: Self::BlockNumber) -> u32 { - 0u32 - } -} - -impl crate::Config for Runtime { - type Currency = Balances; - type RuntimeEvent = (); - type DisputeResolution = NoopResolution; - type MarketCommons = MarketCommons; - type MaxDisputes = MaxDisputes; - type OutcomeBond = OutcomeBond; - type OutcomeFactor = OutcomeFactor; - type PalletId = SimpleDisputesPalletId; - type WeightInfo = zrml_simple_disputes::weights::WeightInfo; -} - -impl frame_system::Config for Runtime { - type AccountData = pallet_balances::AccountData; - type AccountId = AccountIdTest; - type BaseCallFilter = Everything; - type BlockHashCount = BlockHashCount; - type BlockLength = (); - type BlockNumber = BlockNumber; - type BlockWeights = (); - type RuntimeCall = RuntimeCall; - type DbWeight = (); - type RuntimeEvent = (); - type Hash = Hash; - type Hashing = BlakeTwo256; - type Header = Header; - type Index = Index; - type Lookup = IdentityLookup; - type MaxConsumers = frame_support::traits::ConstU32<16>; - type OnKilledAccount = (); - type OnNewAccount = (); - type RuntimeOrigin = RuntimeOrigin; - type PalletInfo = PalletInfo; - type SS58Prefix = (); - type SystemWeightInfo = (); - type Version = (); - type OnSetCode = (); -} - -impl pallet_balances::Config for Runtime { - type AccountStore = System; - type Balance = Balance; - type DustRemoval = (); - type RuntimeEvent = (); - type ExistentialDeposit = (); - type MaxLocks = (); - type MaxReserves = MaxReserves; - type ReserveIdentifier = [u8; 8]; - type WeightInfo = (); -} - -impl orml_currencies::Config for Runtime { - type GetNativeCurrencyId = GetNativeCurrencyId; - type MultiCurrency = Tokens; - type NativeCurrency = BasicCurrencyAdapter; - type WeightInfo = (); -} - -impl orml_tokens::Config for Runtime { - type Amount = Amount; - type Balance = Balance; - type CurrencyId = Assets; - type DustRemovalWhitelist = Everything; - type RuntimeEvent = (); - type ExistentialDeposits = ExistentialDepositsAssets; - type MaxLocks = (); - type MaxReserves = MaxReserves; - type CurrencyHooks = (); - type ReserveIdentifier = [u8; 8]; - type WeightInfo = (); -} - -impl zrml_market_commons::Config for Runtime { - type Balance = Balance; - type MarketId = MarketId; - type Timestamp = Timestamp; -} - -impl pallet_timestamp::Config for Runtime { - type MinimumPeriod = MinimumPeriod; - type Moment = Moment; - type OnTimestampSet = (); - type WeightInfo = (); -} - -pub struct ExtBuilder { - balances: Vec<(AccountIdTest, Balance)>, -} - -impl Default for ExtBuilder { - fn default() -> Self { - Self { - balances: vec![ - (ALICE, INITIAL_BALANCE), - (BOB, INITIAL_BALANCE), - (CHARLIE, INITIAL_BALANCE), - (DAVE, INITIAL_BALANCE), - (EVE, INITIAL_BALANCE), - (FRED, INITIAL_BALANCE), - (SUDO, INITIAL_BALANCE), - ], - } - } -} - -impl ExtBuilder { - pub fn build(self) -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - - // see the logs in tests when using `RUST_LOG=debug cargo test -- --nocapture` - let _ = env_logger::builder().is_test(true).try_init(); - - pallet_balances::GenesisConfig:: { balances: self.balances } - .assimilate_storage(&mut t) - .unwrap(); - - t.into() - } -} diff --git a/zrml/simple-disputes/src/simple_disputes_pallet_api.rs b/zrml/simple-disputes/src/simple_disputes_pallet_api.rs deleted file mode 100644 index f01588aaa..000000000 --- a/zrml/simple-disputes/src/simple_disputes_pallet_api.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2023 Forecasting Technologies LTD. -// Copyright 2021-2022 Zeitgeist PM LLC. -// -// This file is part of Zeitgeist. -// -// Zeitgeist is free software: you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the -// Free Software Foundation, either version 3 of the License, or (at -// your option) any later version. -// -// Zeitgeist is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Zeitgeist. If not, see . - -use zeitgeist_primitives::traits::{DisputeApi, DisputeMaxWeightApi}; - -pub trait SimpleDisputesPalletApi: DisputeApi + DisputeMaxWeightApi {} diff --git a/zrml/simple-disputes/src/tests.rs b/zrml/simple-disputes/src/tests.rs deleted file mode 100644 index d8d51098c..000000000 --- a/zrml/simple-disputes/src/tests.rs +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2022-2024 Forecasting Technologies LTD. -// Copyright 2021-2022 Zeitgeist PM LLC. -// -// This file is part of Zeitgeist. -// -// Zeitgeist is free software: you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the -// Free Software Foundation, either version 3 of the License, or (at -// your option) any later version. -// -// Zeitgeist is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Zeitgeist. If not, see . - -#![cfg(test)] - -use crate::{ - mock::{ExtBuilder, Runtime, SimpleDisputes}, - Disputes, Error, MarketOf, -}; -use frame_support::{assert_noop, BoundedVec}; -use zeitgeist_primitives::{ - constants::mock::{OutcomeBond, OutcomeFactor}, - traits::DisputeApi, - types::{ - BaseAsset, Deadlines, Market, MarketBonds, MarketCreation, MarketDispute, - MarketDisputeMechanism, MarketPeriod, MarketStatus, MarketType, OutcomeReport, ScoringRule, - }, -}; - -const DEFAULT_MARKET: MarketOf = Market { - market_id: 0, - base_asset: BaseAsset::Ztg, - creation: MarketCreation::Permissionless, - creator_fee: sp_runtime::Perbill::zero(), - creator: 0, - market_type: MarketType::Scalar(0..=100), - dispute_mechanism: Some(MarketDisputeMechanism::SimpleDisputes), - metadata: vec![], - oracle: 0, - period: MarketPeriod::Block(0..100), - deadlines: Deadlines { grace_period: 1_u64, oracle_duration: 1_u64, dispute_duration: 1_u64 }, - report: None, - resolved_outcome: None, - scoring_rule: ScoringRule::AmmCdaHybrid, - status: MarketStatus::Disputed, - bonds: MarketBonds { - creation: None, - oracle: None, - outsider: None, - dispute: None, - close_dispute: None, - close_request: None, - }, - early_close: None, -}; - -#[test] -fn on_dispute_denies_non_simple_disputes_markets() { - ExtBuilder::default().build().execute_with(|| { - let mut market = DEFAULT_MARKET; - market.dispute_mechanism = Some(MarketDisputeMechanism::Court); - assert_noop!( - SimpleDisputes::on_dispute(&0, &market), - Error::::MarketDoesNotHaveSimpleDisputesMechanism - ); - }); -} - -#[test] -fn on_resolution_denies_non_simple_disputes_markets() { - ExtBuilder::default().build().execute_with(|| { - let mut market = DEFAULT_MARKET; - market.dispute_mechanism = Some(MarketDisputeMechanism::Court); - assert_noop!( - SimpleDisputes::on_resolution(&0, &market), - Error::::MarketDoesNotHaveSimpleDisputesMechanism - ); - }); -} - -#[test] -fn on_resolution_sets_the_last_dispute_of_disputed_markets_as_the_canonical_outcome() { - ExtBuilder::default().build().execute_with(|| { - let mut market = DEFAULT_MARKET; - market.status = MarketStatus::Disputed; - let disputes = BoundedVec::try_from( - [ - MarketDispute { - at: 0, - by: 0, - outcome: OutcomeReport::Scalar(0), - bond: OutcomeBond::get(), - }, - MarketDispute { - at: 0, - by: 0, - outcome: OutcomeReport::Scalar(20), - bond: OutcomeFactor::get() * OutcomeBond::get(), - }, - ] - .to_vec(), - ) - .unwrap(); - Disputes::::insert(0, &disputes); - assert_eq!( - &SimpleDisputes::on_resolution(&0, &market).unwrap().result.unwrap(), - &disputes.last().unwrap().outcome - ) - }); -} - -// TODO test `suggest_outcome` functionality and API functionality diff --git a/zrml/simple-disputes/src/weights.rs b/zrml/simple-disputes/src/weights.rs deleted file mode 100644 index bfbc6cc8c..000000000 --- a/zrml/simple-disputes/src/weights.rs +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright 2023 Forecasting Technologies LTD. -// Copyright 2021-2022 Zeitgeist PM LLC. -// -// This file is part of Zeitgeist. -// -// Zeitgeist is free software: you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the -// Free Software Foundation, either version 3 of the License, or (at -// your option) any later version. -// -// Zeitgeist is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Zeitgeist. If not, see . - -//! Autogenerated weights for zrml_simple_disputes -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-01-19, STEPS: `10`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! EXECUTION: Some(Native), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 - -// Executed Command: -// ./target/debug/zeitgeist -// benchmark -// pallet -// --chain=dev -// --steps=10 -// --repeat=10 -// --pallet=zrml_simple_disputes -// --extrinsic=* -// --execution=Native -// --wasm-execution=compiled -// --heap-pages=4096 -// --output=./zrml/simple-disputes/src/weights2.rs -// --template=./misc/weight_template.hbs - -#![allow(unused_parens)] -#![allow(unused_imports)] - -use core::marker::PhantomData; -use frame_support::{traits::Get, weights::Weight}; - -/// Trait containing the required functions for weight retrival within -/// zrml_simple_disputes (automatically generated) -pub trait WeightInfoZeitgeist { - fn suggest_outcome(d: u32, r: u32, e: u32) -> Weight; - fn on_dispute_weight() -> Weight; - fn on_resolution_weight(d: u32) -> Weight; - fn exchange_weight(d: u32) -> Weight; - fn get_auto_resolve_weight(d: u32) -> Weight; - fn has_failed_weight(d: u32) -> Weight; - fn on_global_dispute_weight(d: u32) -> Weight; - fn clear_weight(d: u32) -> Weight; -} - -/// Weight functions for zrml_simple_disputes (automatically generated) -pub struct WeightInfo(PhantomData); -impl WeightInfoZeitgeist for WeightInfo { - // Storage: MarketCommons Markets (r:1 w:0) - // Storage: SimpleDisputes Disputes (r:1 w:1) - // Storage: Balances Reserves (r:1 w:1) - // Storage: PredictionMarkets MarketIdsPerDisputeBlock (r:2 w:2) - fn suggest_outcome(d: u32, r: u32, e: u32) -> Weight { - Weight::from_ref_time(400_160_000) - // Standard Error: 1_302_000 - .saturating_add(Weight::from_ref_time(3_511_000).saturating_mul(d.into())) - // Standard Error: 69_000 - .saturating_add(Weight::from_ref_time(324_000).saturating_mul(r.into())) - // Standard Error: 69_000 - .saturating_add(Weight::from_ref_time(311_000).saturating_mul(e.into())) - .saturating_add(T::DbWeight::get().reads(5)) - .saturating_add(T::DbWeight::get().writes(4)) - } - - fn on_dispute_weight() -> Weight { - Weight::from_ref_time(0) - } - // Storage: SimpleDisputes Disputes (r:1 w:0) - fn on_resolution_weight(d: u32) -> Weight { - Weight::from_ref_time(5_464_000) - // Standard Error: 3_000 - .saturating_add(Weight::from_ref_time(210_000).saturating_mul(d.into())) - .saturating_add(T::DbWeight::get().reads(1)) - } - // Storage: SimpleDisputes Disputes (r:1 w:1) - // Storage: Balances Reserves (r:1 w:1) - // Storage: System Account (r:1 w:1) - fn exchange_weight(d: u32) -> Weight { - Weight::from_ref_time(18_573_000) - // Standard Error: 14_000 - .saturating_add(Weight::from_ref_time(19_710_000).saturating_mul(d.into())) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(d.into()))) - .saturating_add(T::DbWeight::get().writes(1)) - .saturating_add(T::DbWeight::get().writes((2_u64).saturating_mul(d.into()))) - } - // Storage: SimpleDisputes Disputes (r:1 w:0) - fn get_auto_resolve_weight(d: u32) -> Weight { - Weight::from_ref_time(5_535_000) - // Standard Error: 3_000 - .saturating_add(Weight::from_ref_time(145_000).saturating_mul(d.into())) - .saturating_add(T::DbWeight::get().reads(1)) - } - // Storage: SimpleDisputes Disputes (r:1 w:0) - fn has_failed_weight(d: u32) -> Weight { - Weight::from_ref_time(5_685_000) - // Standard Error: 2_000 - .saturating_add(Weight::from_ref_time(117_000).saturating_mul(d.into())) - .saturating_add(T::DbWeight::get().reads(1)) - } - // Storage: SimpleDisputes Disputes (r:1 w:0) - fn on_global_dispute_weight(d: u32) -> Weight { - Weight::from_ref_time(5_815_000) - // Standard Error: 2_000 - .saturating_add(Weight::from_ref_time(66_000).saturating_mul(d.into())) - .saturating_add(T::DbWeight::get().reads(1)) - } - // Storage: SimpleDisputes Disputes (r:1 w:1) - // Storage: Balances Reserves (r:1 w:1) - // Storage: System Account (r:1 w:1) - fn clear_weight(d: u32) -> Weight { - Weight::from_ref_time(15_958_000) - // Standard Error: 17_000 - .saturating_add(Weight::from_ref_time(13_085_000).saturating_mul(d.into())) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(d.into()))) - .saturating_add(T::DbWeight::get().writes(1)) - .saturating_add(T::DbWeight::get().writes((2_u64).saturating_mul(d.into()))) - } -}