Skip to content

Commit

Permalink
fix major clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Chralt98 committed Sep 28, 2023
1 parent cf12471 commit 6a0f32b
Show file tree
Hide file tree
Showing 17 changed files with 287 additions and 17 deletions.
1 change: 1 addition & 0 deletions primitives/src/market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ mod tests {
resolved_outcome: None,
dispute_mechanism: Some(MarketDisputeMechanism::Authorized),
bonds: MarketBonds::default(),
premature_close: None,
};
assert_eq!(market.matches_outcome_report(&outcome_report), expected);
}
Expand Down
16 changes: 16 additions & 0 deletions runtime/battery-station/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ parameter_types! {
pub const AdvisoryBond: Balance = 25 * CENT;
/// The percentage of the advisory bond that gets slashed when a market is rejected.
pub const AdvisoryBondSlashPercentage: Percent = Percent::from_percent(0);
/// (Slashable) Bond that is provided for disputing an early market close by the market creator.
pub const CloseDisputeBond: Balance = 50 * BASE;
// 43_200_000 = 12 hours. Fat-finger protection for the advisory committe to reject
// the early market schedule.
pub const CloseProtectionTimeFramePeriod: Moment = 43_200_000;
// Fat-finger protection for the advisory committe to reject
// the early market schedule.
pub const CloseProtectionBlockPeriod: BlockNumber = 12 * BLOCKS_PER_HOUR;
/// (Slashable) Bond that is provided for scheduling an early market close.
pub const CloseRequestBond: Balance = 25 * BASE;
/// (Slashable) Bond that is provided for disputing the outcome.
/// Unreserved in case the dispute was justified otherwise slashed.
/// This is when the resolved outcome is different to the default (reported) outcome.
Expand Down Expand Up @@ -244,6 +254,12 @@ parameter_types! {
pub const OutsiderBond: Balance = 2 * OracleBond::get();
/// Pallet identifier, mainly used for named balance reserves.
pub const PmPalletId: PalletId = PM_PALLET_ID;
// Waiting time for market creator to close
// the market after an early close schedule.
pub const PrematureCloseBlockPeriod: BlockNumber = 5 * BLOCKS_PER_DAY;
// 432_000_000 = 5 days. Waiting time for market creator to close
// the market after an early close schedule.
pub const PrematureCloseTimeFramePeriod: Moment = 432_000_000;
/// (Slashable) A bond for creation markets that do not require approval. Slashed in case
/// the market is forcefully destroyed.
pub const ValidityBond: Balance = 50 * CENT;
Expand Down
11 changes: 9 additions & 2 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ macro_rules! decl_common_types {
type Address = sp_runtime::MultiAddress<AccountId, ()>;

#[cfg(feature = "parachain")]
type Migrations = (zrml_prediction_markets::migrations::MigrateMarkets<Runtime>,);
type Migrations = (zrml_prediction_markets::migrations::AddEarlyCloseBonds<Runtime>,);

#[cfg(not(feature = "parachain"))]
type Migrations = (zrml_prediction_markets::migrations::MigrateMarkets<Runtime>,);
type Migrations = (zrml_prediction_markets::migrations::AddEarlyCloseBonds<Runtime>,);

pub type Executive = frame_executive::Executive<
Runtime,
Expand Down Expand Up @@ -1113,7 +1113,12 @@ macro_rules! impl_config_traits {
type ApproveOrigin = EnsureRootOrMoreThanOneThirdAdvisoryCommittee;
type Authorized = Authorized;
type Court = Court;
type CloseDisputeBond = CloseDisputeBond;
type CloseMarketEarlyOrigin = EnsureRootOrMoreThanOneThirdAdvisoryCommittee;
type CloseOrigin = EnsureRoot<AccountId>;
type CloseProtectionTimeFramePeriod = CloseProtectionTimeFramePeriod;
type CloseProtectionBlockPeriod = CloseProtectionBlockPeriod;
type CloseRequestBond = CloseRequestBond;
type DestroyOrigin = EnsureRootOrAllAdvisoryCommittee;
type DisputeBond = DisputeBond;
type RuntimeEvent = RuntimeEvent;
Expand All @@ -1139,6 +1144,8 @@ macro_rules! impl_config_traits {
type OracleBond = OracleBond;
type OutsiderBond = OutsiderBond;
type PalletId = PmPalletId;
type PrematureCloseBlockPeriod = PrematureCloseBlockPeriod;
type PrematureCloseTimeFramePeriod = PrematureCloseTimeFramePeriod;
type RejectOrigin = EnsureRootOrMoreThanTwoThirdsAdvisoryCommittee;
type RequestEditOrigin = EnsureRootOrMoreThanOneThirdAdvisoryCommittee;
type ResolveOrigin = EnsureRoot<AccountId>;
Expand Down
16 changes: 16 additions & 0 deletions runtime/zeitgeist/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ parameter_types! {
pub const AdvisoryBond: Balance = 200 * BASE;
/// The percentage of the advisory bond that gets slashed when a market is rejected.
pub const AdvisoryBondSlashPercentage: Percent = Percent::from_percent(0);
/// (Slashable) Bond that is provided for disputing an early market close by the market creator.
pub const CloseDisputeBond: Balance = 2_000 * BASE;
// 43_200_000 = 12 hours. Fat-finger protection for the advisory committe to reject
// the early market schedule.
pub const CloseProtectionTimeFramePeriod: Moment = 43_200_000;
// Fat-finger protection for the advisory committe to reject
// the early market schedule.
pub const CloseProtectionBlockPeriod: BlockNumber = 12 * BLOCKS_PER_HOUR;
/// (Slashable) Bond that is provided for scheduling an early market close.
pub const CloseRequestBond: Balance = 200 * BASE;
/// (Slashable) Bond that is provided for disputing the outcome.
/// Unreserved in case the dispute was justified otherwise slashed.
/// This is when the resolved outcome is different to the default (reported) outcome.
Expand Down Expand Up @@ -244,6 +254,12 @@ parameter_types! {
pub const OutsiderBond: Balance = 2 * OracleBond::get();
/// Pallet identifier, mainly used for named balance reserves. DO NOT CHANGE.
pub const PmPalletId: PalletId = PM_PALLET_ID;
// Waiting time for market creator to close
// the market after an early close schedule.
pub const PrematureCloseBlockPeriod: BlockNumber = 5 * BLOCKS_PER_DAY;
// 432_000_000 = 5 days. Waiting time for market creator to close
// the market after an early close schedule.
pub const PrematureCloseTimeFramePeriod: Moment = 432_000_000;
/// (Slashable) A bond for creation markets that do not require approval. Slashed in case
/// the market is forcefully destroyed.
pub const ValidityBond: Balance = 1_000 * BASE;
Expand Down
3 changes: 2 additions & 1 deletion zrml/authorized/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ where
{
use frame_support::traits::Get;
use sp_runtime::traits::AccountIdConversion;
use zeitgeist_primitives::types::{Asset, MarketBonds, ScoringRule};
use zeitgeist_primitives::types::{Asset, MarketBonds, MarketDisputeMechanism, ScoringRule};

zeitgeist_primitives::types::Market {
base_asset: Asset::Ztg,
Expand All @@ -387,5 +387,6 @@ where
scoring_rule: ScoringRule::CPMM,
status: zeitgeist_primitives::types::MarketStatus::Disputed,
bonds: MarketBonds::default(),
premature_close: None,
}
}
10 changes: 9 additions & 1 deletion zrml/court/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,15 @@ where
resolved_outcome: None,
status: MarketStatus::Disputed,
scoring_rule: ScoringRule::CPMM,
bonds: MarketBonds { creation: None, oracle: None, outsider: None, dispute: None },
bonds: MarketBonds {
creation: None,
oracle: None,
outsider: None,
dispute: None,
close_dispute: None,
close_request: None,
},
premature_close: None,
}
}

Expand Down
10 changes: 9 additions & 1 deletion zrml/court/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,15 @@ const DEFAULT_MARKET: MarketOf<Runtime> = Market {
resolved_outcome: None,
status: MarketStatus::Disputed,
scoring_rule: ScoringRule::CPMM,
bonds: MarketBonds { creation: None, oracle: None, outsider: None, dispute: None },
bonds: MarketBonds {
creation: None,
oracle: None,
outsider: None,
dispute: None,
close_dispute: None,
close_request: None,
},
premature_close: None,
};

fn initialize_court() -> CourtId {
Expand Down
1 change: 1 addition & 0 deletions zrml/global-disputes/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@ where
scoring_rule: ScoringRule::CPMM,
status: zeitgeist_primitives::types::MarketStatus::Disputed,
bonds: Default::default(),
premature_close: None,
}
}
1 change: 1 addition & 0 deletions zrml/liquidity-mining/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ fn create_default_market(market_id: u128, period: Range<u64>) {
status: MarketStatus::Closed,
scoring_rule: ScoringRule::CPMM,
bonds: MarketBonds::default(),
premature_close: None,
},
);
}
Expand Down
10 changes: 9 additions & 1 deletion zrml/market-commons/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ const MARKET_DUMMY: Market<AccountIdTest, Balance, BlockNumber, Moment, Asset<Ma
resolved_outcome: None,
scoring_rule: ScoringRule::CPMM,
status: MarketStatus::Disputed,
bonds: MarketBonds { creation: None, oracle: None, outsider: None, dispute: None },
bonds: MarketBonds {
creation: None,
oracle: None,
outsider: None,
dispute: None,
close_dispute: None,
close_request: None,
},
premature_close: None,
};

#[test]
Expand Down
18 changes: 9 additions & 9 deletions zrml/prediction-markets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,8 @@ mod pallet {
get_new_period(block_period, time_frame_period)?
}
Some(p) => {
ensure!(is_authorized, Error::<T>::OnlyAuthorizedCanScheduleEarlyClose);

match p.state {
// in these case the market period got already reset to the old period
PrematureCloseState::Disputed => {
Expand All @@ -546,8 +548,6 @@ mod pallet {
}
}

ensure!(is_authorized, Error::<T>::OnlyAuthorizedCanScheduleEarlyClose);

get_new_period(
T::CloseProtectionBlockPeriod::get(),
T::CloseProtectionTimeFramePeriod::get(),
Expand Down Expand Up @@ -716,7 +716,7 @@ mod pallet {

if let Some(disputor_bond) = market.bonds.close_dispute.as_ref() {
let close_disputor = &disputor_bond.who;
Self::repatriate_close_request_bond(&market_id, &close_disputor)?;
Self::repatriate_close_request_bond(&market_id, close_disputor)?;
Self::unreserve_close_dispute_bond(&market_id)?;
}

Expand Down Expand Up @@ -2787,19 +2787,19 @@ mod pallet {
Some(p) => {
match p.state {
PrematureCloseState::ScheduledAsMarketCreator => {
if Self::is_close_request_bond_pending(&market_id, &market, false) {
Self::unreserve_close_request_bond(&market_id)?;
if Self::is_close_request_bond_pending(market_id, market, false) {
Self::unreserve_close_request_bond(market_id)?;
}
}
PrematureCloseState::Disputed => {
// this is the case that the original close happened,
// although requested early close or disputed
// there was no decision made via `reject` or `approve`
if Self::is_close_dispute_bond_pending(&market_id, &market, false) {
Self::unreserve_close_dispute_bond(&market_id)?;
if Self::is_close_dispute_bond_pending(market_id, market, false) {
Self::unreserve_close_dispute_bond(market_id)?;
}
if Self::is_close_request_bond_pending(&market_id, &market, false) {
Self::unreserve_close_request_bond(&market_id)?;
if Self::is_close_request_bond_pending(market_id, market, false) {
Self::unreserve_close_request_bond(market_id)?;
}
}
PrematureCloseState::ScheduledAsOther
Expand Down
2 changes: 1 addition & 1 deletion zrml/prediction-markets/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl<T: Config + zrml_market_commons::Config> OnRuntimeUpgrade for AddEarlyClose
assert_eq!(new_market.status, old_market.status);
assert_eq!(new_market.report, old_market.report);
assert_eq!(new_market.resolved_outcome, old_market.resolved_outcome);
assert_eq!(new_market.dispute_mechanism, Some(old_market.dispute_mechanism.clone()));
assert_eq!(new_market.dispute_mechanism, old_market.dispute_mechanism);
assert_eq!(new_market.bonds.oracle, old_market.bonds.oracle);
assert_eq!(new_market.bonds.creation, old_market.bonds.creation);
assert_eq!(new_market.bonds.outsider, old_market.bonds.outsider);
Expand Down
Loading

0 comments on commit 6a0f32b

Please sign in to comment.