From 8788f42732e2e7dd0053390074d005b332d0d6c0 Mon Sep 17 00:00:00 2001 From: Harald Heckmann Date: Fri, 12 Aug 2022 15:56:44 +0200 Subject: [PATCH] Apply updated configuration to Zeitgeist runtime (#749) * Copy shared parameters into each runtime * Document parameters * Add mock constants * Use constant pallet ids --- Cargo.lock | 1 - node/src/command_helper.rs | 14 +- primitives/Cargo.toml | 1 + primitives/src/constants.rs | 121 ++++----------- primitives/src/constants/mock.rs | 103 +++++++++++++ primitives/src/pool.rs | 6 +- runtime/battery-station/src/parameters.rs | 139 +++++++++++++++++- runtime/common/src/lib.rs | 7 +- runtime/zeitgeist/src/parameters.rs | 155 ++++++++++++++++++-- zrml/authorized/Cargo.toml | 1 + zrml/authorized/src/mock.rs | 2 +- zrml/court/Cargo.toml | 1 + zrml/court/src/lib.rs | 22 +-- zrml/court/src/mock.rs | 2 +- zrml/court/src/tests.rs | 18 +-- zrml/liquidity-mining/Cargo.toml | 1 + zrml/liquidity-mining/src/mock.rs | 2 +- zrml/market-commons/Cargo.toml | 1 + zrml/market-commons/src/mock.rs | 2 +- zrml/orderbook-v1/Cargo.toml | 1 + zrml/orderbook-v1/src/mock.rs | 2 +- zrml/prediction-markets/Cargo.toml | 2 + zrml/prediction-markets/fuzz/Cargo.toml | 2 +- zrml/prediction-markets/src/benchmarks.rs | 2 +- zrml/prediction-markets/src/lib.rs | 46 +++--- zrml/prediction-markets/src/mock.rs | 2 +- zrml/prediction-markets/src/tests.rs | 171 +++++++++++++++++----- zrml/rikiddo/Cargo.toml | 1 + zrml/rikiddo/src/mock.rs | 2 +- zrml/simple-disputes/Cargo.toml | 1 + zrml/simple-disputes/src/mock.rs | 2 +- zrml/styx/Cargo.toml | 13 +- zrml/styx/src/mock.rs | 2 +- zrml/swaps/Cargo.toml | 1 + zrml/swaps/fuzz/Cargo.toml | 2 +- zrml/swaps/fuzz/utils.rs | 16 +- zrml/swaps/src/mock.rs | 2 +- 37 files changed, 640 insertions(+), 229 deletions(-) create mode 100644 primitives/src/constants/mock.rs diff --git a/Cargo.lock b/Cargo.lock index e835c67aa..752cbae1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12949,7 +12949,6 @@ dependencies = [ "sp-io", "sp-runtime", "zeitgeist-primitives", - "zrml-styx", ] [[package]] diff --git a/node/src/command_helper.rs b/node/src/command_helper.rs index 1cfdef0e6..16f783b27 100644 --- a/node/src/command_helper.rs +++ b/node/src/command_helper.rs @@ -25,7 +25,7 @@ use sp_inherents::{InherentData, InherentDataProvider}; use sp_keyring::Sr25519Keyring; use sp_runtime::{OpaqueExtrinsic, SaturatedConversion}; use std::{sync::Arc, time::Duration}; -use zeitgeist_primitives::{constants::BlockHashCount, types::Signature}; +use zeitgeist_primitives::types::Signature; /// Generates extrinsics for the `benchmark overhead` command. /// @@ -92,8 +92,10 @@ pub fn create_benchmark_extrinsic_zeitgeist< let best_hash = client.chain_info().best_hash; let best_block = client.chain_info().best_number; - let period = - BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2) as u64; + let period = zeitgeist_runtime::BlockHashCount::get() + .checked_next_power_of_two() + .map(|c| c / 2) + .unwrap_or(2) as u64; let extra: zeitgeist_runtime::SignedExtra = ( zeitgeist_runtime::CheckNonZeroSender::::new(), zeitgeist_runtime::CheckSpecVersion::::new(), @@ -148,8 +150,10 @@ pub fn create_benchmark_extrinsic_battery_station< let best_hash = client.chain_info().best_hash; let best_block = client.chain_info().best_number; - let period = - BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2) as u64; + let period = battery_station_runtime::BlockHashCount::get() + .checked_next_power_of_two() + .map(|c| c / 2) + .unwrap_or(2) as u64; let extra: battery_station_runtime::SignedExtra = ( battery_station_runtime::CheckNonZeroSender::::new(), battery_station_runtime::CheckSpecVersion::::new(), diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index 33f871188..aab57d3db 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -16,6 +16,7 @@ test-case = "2.0.2" [features] default = ["std"] +mock = [] std = [ "frame-support/std", "frame-system/std", diff --git a/primitives/src/constants.rs b/primitives/src/constants.rs index 25f7f8d91..d3558854f 100644 --- a/primitives/src/constants.rs +++ b/primitives/src/constants.rs @@ -21,14 +21,12 @@ clippy::integer_arithmetic )] +#[cfg(feature = "mock")] +pub mod mock; pub mod ztg; -use crate::{ - asset::Asset, - types::{Balance, BlockNumber, CurrencyId, Moment}, -}; +use crate::types::{Balance, BlockNumber}; use frame_support::{parameter_types, PalletId}; -use orml_traits::parameter_type_with_key; // Definitions for time pub const BLOCKS_PER_DAY: BlockNumber = BLOCKS_PER_HOUR * 24; @@ -62,95 +60,28 @@ parameter_types! { } // Authorized -parameter_types! { - pub const AuthorizedPalletId: PalletId = PalletId(*b"zge/atzd"); -} +/// Pallet identifier, mainly used for named balance reserves. +pub const AUTHORIZED_PALLET_ID: PalletId = PalletId(*b"zge/atzd"); // Court -parameter_types! { - pub const CourtCaseDuration: u64 = BLOCKS_PER_DAY; - pub const CourtPalletId: PalletId = PalletId(*b"zge/cout"); - pub const StakeWeight: u128 = 2 * BASE; -} - -// Liquidity Mining parameters -parameter_types! { - pub const LiquidityMiningPalletId: PalletId = PalletId(*b"zge/lymg"); -} - -// Prediction Market parameters -parameter_types! { - pub const AdvisoryBond: Balance = 25 * CENT; - pub const DisputeBond: Balance = 5 * BASE; - pub const DisputeFactor: Balance = 2 * BASE; - pub const DisputePeriod: BlockNumber = BLOCKS_PER_DAY; - pub const MaxCategories: u16 = 10; - pub const MaxDisputes: u16 = 6; - pub const MinCategories: u16 = 2; - // 60_000 = 1 minute. Should be raised to something more reasonable in the future. - pub const MinSubsidyPeriod: Moment = 60_000; - // 2_678_400_000 = 31 days. - pub const MaxSubsidyPeriod: Moment = 2_678_400_000; - // Requirements: MaxPeriod + ReportingPeriod + MaxDisputes * DisputePeriod < u64::MAX. - pub const MaxMarketPeriod: Moment = u64::MAX / 2; - pub const OracleBond: Balance = 50 * CENT; - pub const PmPalletId: PalletId = PalletId(*b"zge/pred"); - pub const ReportingPeriod: u32 = BLOCKS_PER_DAY as _; - pub const ValidityBond: Balance = 50 * CENT; -} - -// Simple disputes parameters -parameter_types! { - pub const SimpleDisputesPalletId: PalletId = PalletId(*b"zge/sedp"); -} - -// Swaps parameters -parameter_types! { - pub const ExitFee: Balance = 3 * BASE / 1000; // 0.3% - pub const MinAssets: u16 = 2; - pub const MaxAssets: u16 = MaxCategories::get() + 1; - pub const MaxInRatio: Balance = (BASE / 3) + 1; - pub const MaxOutRatio: Balance = (BASE / 3) + 1; - pub const MaxSwapFee: Balance = BASE / 10; // 10% - pub const MaxTotalWeight: Balance = 50 * BASE; - pub const MaxWeight: Balance = 50 * BASE; - pub const MinLiquidity: Balance = 100 * BASE; - pub const MinSubsidy: Balance = MinLiquidity::get(); - pub const MinSubsidyPerAccount: Balance = MinSubsidy::get(); - pub const MinWeight: Balance = BASE; - pub const SwapsPalletId: PalletId = PalletId(*b"zge/swap"); -} - -// Shared within tests -// Balance -parameter_types! { - pub const ExistentialDeposit: u128 = CENT; - pub const MaxLocks: u32 = 50; - pub const MaxReserves: u32 = 50; -} - -// ORML -parameter_types! { - // ORML - pub const GetNativeCurrencyId: CurrencyId = Asset::Ztg; -} - -parameter_type_with_key! { - // Well, not every asset is a currency ¯\_(ツ)_/¯ - pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance { - match currency_id { - Asset::Ztg => ExistentialDeposit::get(), - _ => 0 - } - }; -} - -// System -parameter_types! { - pub const BlockHashCount: u64 = 250; -} - -// Time -parameter_types! { - pub const MinimumPeriod: u64 = MILLISECS_PER_BLOCK as u64 / 2; -} +/// Pallet identifier, mainly used for named balance reserves. +pub const COURT_PALLET_ID: PalletId = PalletId(*b"zge/cout"); + +// Liqudity Mining +/// Pallet identifier, mainly used for named balance reserves. +pub const LM_PALLET_ID: PalletId = PalletId(*b"zge/lymg"); + +// Prediction Markets +/// Max. categories in a prediction market. +pub const MAX_CATEGORIES: u16 = 10; +/// 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; +/// Pallet identifier, mainly used for named balance reserves. +pub const SWAPS_PALLET_ID: PalletId = PalletId(*b"zge/swap"); diff --git a/primitives/src/constants/mock.rs b/primitives/src/constants/mock.rs new file mode 100644 index 000000000..0ea728082 --- /dev/null +++ b/primitives/src/constants/mock.rs @@ -0,0 +1,103 @@ +#![cfg(feature = "mock")] + +pub use super::*; +use crate::{ + asset::Asset, + types::{Balance, BlockNumber, CurrencyId, Moment}, +}; +use frame_support::{parameter_types, PalletId}; +use orml_traits::parameter_type_with_key; + +// Authorized +parameter_types! { + pub const AuthorizedPalletId: PalletId = PalletId(*b"zge/atzd"); +} + +// Court +parameter_types! { + pub const CourtCaseDuration: u64 = BLOCKS_PER_DAY; + pub const CourtPalletId: PalletId = PalletId(*b"zge/cout"); + pub const StakeWeight: u128 = 2 * BASE; +} + +// Liquidity Mining parameters +parameter_types! { + pub const LiquidityMiningPalletId: PalletId = PalletId(*b"zge/lymg"); +} + +// Prediction Market parameters +parameter_types! { + pub const AdvisoryBond: Balance = 25 * CENT; + pub const DisputeBond: Balance = 5 * BASE; + pub const DisputeFactor: Balance = 2 * BASE; + pub const DisputePeriod: BlockNumber = BLOCKS_PER_DAY; + pub const MaxCategories: u16 = 10; + pub const MaxDisputes: u16 = 6; + pub const MinCategories: u16 = 2; + // 60_000 = 1 minute. Should be raised to something more reasonable in the future. + pub const MinSubsidyPeriod: Moment = 60_000; + // 2_678_400_000 = 31 days. + pub const MaxSubsidyPeriod: Moment = 2_678_400_000; + // Requirements: MaxPeriod + ReportingPeriod + MaxDisputes * DisputePeriod < u64::MAX. + pub const MaxMarketPeriod: Moment = u64::MAX / 2; + pub const OracleBond: Balance = 50 * CENT; + pub const PmPalletId: PalletId = PalletId(*b"zge/pred"); + pub const ReportingPeriod: u32 = BLOCKS_PER_DAY as _; + pub const ValidityBond: Balance = 50 * CENT; +} + +// Simple disputes parameters +parameter_types! { + pub const SimpleDisputesPalletId: PalletId = PalletId(*b"zge/sedp"); +} + +// Swaps parameters +parameter_types! { + pub const ExitFee: Balance = 3 * BASE / 1000; // 0.3% + pub const MinAssets: u16 = 2; + pub const MaxAssets: u16 = MaxCategories::get() + 1; + pub const MaxInRatio: Balance = (BASE / 3) + 1; + pub const MaxOutRatio: Balance = (BASE / 3) + 1; + pub const MaxSwapFee: Balance = BASE / 10; // 10% + pub const MaxTotalWeight: Balance = 50 * BASE; + pub const MaxWeight: Balance = 50 * BASE; + pub const MinLiquidity: Balance = 100 * BASE; + pub const MinSubsidy: Balance = MinLiquidity::get(); + pub const MinSubsidyPerAccount: Balance = MinSubsidy::get(); + pub const MinWeight: Balance = BASE; + pub const SwapsPalletId: PalletId = PalletId(*b"zge/swap"); +} + +// Shared within tests +// Balance +parameter_types! { + pub const ExistentialDeposit: u128 = CENT; + pub const MaxLocks: u32 = 50; + pub const MaxReserves: u32 = 50; +} + +// ORML +parameter_types! { + // ORML + pub const GetNativeCurrencyId: CurrencyId = Asset::Ztg; +} + +parameter_type_with_key! { + // Well, not every asset is a currency ¯\_(ツ)_/¯ + pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance { + match currency_id { + Asset::Ztg => ExistentialDeposit::get(), + _ => 0 + } + }; +} + +// System +parameter_types! { + pub const BlockHashCount: u64 = 250; +} + +// Time +parameter_types! { + pub const MinimumPeriod: u64 = MILLISECS_PER_BLOCK as u64 / 2; +} diff --git a/primitives/src/pool.rs b/primitives/src/pool.rs index 0ed038bc0..bafa0e4af 100644 --- a/primitives/src/pool.rs +++ b/primitives/src/pool.rs @@ -16,7 +16,7 @@ // along with Zeitgeist. If not, see . use crate::{ - constants::MaxAssets, + constants::MAX_ASSETS, types::{Asset, PoolStatus}, }; use alloc::{collections::BTreeMap, vec::Vec}; @@ -61,13 +61,13 @@ where fn max_encoded_len() -> usize { let max_encoded_length_bytes = >::max_encoded_len(); let b_tree_map_size = 1usize - .saturating_add(MaxAssets::get().saturated_into::().saturating_mul( + .saturating_add(MAX_ASSETS.saturated_into::().saturating_mul( >::max_encoded_len().saturating_add(u128::max_encoded_len()), )) .saturating_add(max_encoded_length_bytes); >::max_encoded_len() - .saturating_mul(MaxAssets::get().saturated_into::()) + .saturating_mul(MAX_ASSETS.saturated_into::()) .saturating_add(max_encoded_length_bytes) .saturating_add(>>::max_encoded_len()) .saturating_add(MarketId::max_encoded_len()) diff --git a/runtime/battery-station/src/parameters.rs b/runtime/battery-station/src/parameters.rs index c7028a3c4..527912837 100644 --- a/runtime/battery-station/src/parameters.rs +++ b/runtime/battery-station/src/parameters.rs @@ -31,6 +31,7 @@ use frame_support::{ PalletId, }; use frame_system::limits::{BlockLength, BlockWeights}; +use orml_traits::parameter_type_with_key; use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment}; use sp_runtime::{traits::AccountIdConversion, FixedPointNumber, Perbill, Permill, Perquintill}; use sp_version::RuntimeVersion; @@ -41,9 +42,17 @@ pub(crate) const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND / 2; pub(crate) const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); parameter_types! { + // Authorized + pub const AuthorizedPalletId: PalletId = AUTHORIZED_PALLET_ID; + // Authority pub const MaxAuthorities: u32 = 32; + // Balance + pub const ExistentialDeposit: u128 = 5 * CENT; + pub const MaxLocks: u32 = 50; + pub const MaxReserves: u32 = 50; + // Collective // Note: MaxMembers does not influence the pallet logic, but the worst-case weight estimation. pub const AdvisoryCommitteeMaxMembers: u32 = 100; @@ -56,6 +65,15 @@ parameter_types! { pub const TechnicalCommitteeMaxProposals: u32 = 64; pub const TechnicalCommitteeMotionDuration: BlockNumber = 7 * BLOCKS_PER_DAY; + // Court + /// Duration of a single court case. + pub const CourtCaseDuration: u64 = BLOCKS_PER_DAY; + /// Pallet identifier, mainly used for named balance reserves. + pub const CourtPalletId: PalletId = COURT_PALLET_ID; + /// This value is multiplied by the current number of jurors to determine the stake + /// the juror has to pay. + pub const StakeWeight: u128 = 2 * BASE; + // Democracy /// How often (in blocks) new public referenda are launched. pub const LaunchPeriod: BlockNumber = 5 * BLOCKS_PER_DAY; @@ -85,13 +103,27 @@ parameter_types! { pub const MaxProposals: u32 = 100; // Identity + /// The amount held on deposit for a registered identity pub const BasicDeposit: Balance = 8 * BASE; + /// The amount held on deposit per additional field for a registered identity. pub const FieldDeposit: Balance = 256 * CENT; + /// Maximum number of additional fields that may be stored in an ID. Needed to bound the I/O + /// required to access an identity, but can be pretty high. pub const MaxAdditionalFields: u32 = 64; + /// Maxmimum number of registrars allowed in the system. Needed to bound the complexity + /// of, e.g., updating judgements. pub const MaxRegistrars: u32 = 8; + /// The maximum number of sub-accounts allowed per identified account. pub const MaxSubAccounts: u32 = 64; + /// The amount held on deposit for a registered subaccount. This should account for the fact + /// that one storage item's value will increase by the size of an account ID, and there will + /// be another trie item whose value is the size of an account ID plus 32 bytes. pub const SubAccountDeposit: Balance = 2 * BASE; + // Liquidity Mining parameters + /// Pallet identifier, mainly used for named balance reserves. + pub const LiquidityMiningPalletId: PalletId = LM_PALLET_ID; + // Multisig // One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes. pub const DepositBase: Balance = deposit(1, 88); @@ -99,8 +131,48 @@ parameter_types! { pub const DepositFactor: Balance = deposit(0, 32); // ORML + pub const GetNativeCurrencyId: CurrencyId = Asset::Ztg; pub DustAccount: AccountId = PalletId(*b"orml/dst").into_account(); + // Prediction Market parameters + /// (Slashable) Bond that is provided for creating an advised market that needs approval. + /// Slashed in case the market is rejected. + pub const AdvisoryBond: Balance = 25 * CENT; + /// (Slashable) Bond that is provided for disputing the outcome. + /// Slashed in case the final outcome does not match the dispute for which the `DisputeBond` + /// was deposited. + pub const DisputeBond: Balance = 5 * BASE; + /// `DisputeBond` is increased by this factor after every dispute. + pub const DisputeFactor: Balance = 2 * BASE; + /// After reporting the outcome and after every dispute, the dispute period is extended + /// by `DisputePeriod`. + pub const DisputePeriod: BlockNumber = BLOCKS_PER_DAY; + /// Maximum Categories a prediciton market can have (excluding base asset). + pub const MaxCategories: u16 = MAX_CATEGORIES; + /// Maximum number of disputes. + pub const MaxDisputes: u16 = 6; + /// Minimum number of categories. The trivial minimum is 2, which represents a binary market. + pub const MinCategories: u16 = 2; + // 60_000 = 1 minute. Should be raised to something more reasonable in the future. + /// Minimum number of milliseconds a Rikiddo market must be in subsidy gathering phase. + pub const MinSubsidyPeriod: Moment = 60_000; + // 2_678_400_000 = 31 days. + /// Maximum number of milliseconds a Rikiddo market can be in subsidy gathering phase. + pub const MaxSubsidyPeriod: Moment = 2_678_400_000; + // Requirements: MaxPeriod + ReportingPeriod + MaxDisputes * DisputePeriod < u64::MAX. + /// The maximum market period. + pub const MaxMarketPeriod: Moment = u64::MAX / 2; + /// (Slashable) The orcale bond. Slashed in case the final outcome does not match the + /// outcome the oracle reported. + pub const OracleBond: Balance = 50 * CENT; + /// Pallet identifier, mainly used for named balance reserves. + pub const PmPalletId: PalletId = PM_PALLET_ID; + /// Timeframe during which the oracle can report the final outcome after the market closed. + pub const ReportingPeriod: u32 = BLOCKS_PER_DAY as u32; + /// (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; + // Preimage pub const PreimageMaxSize: u32 = 4096 * 1024; pub PreimageBaseDeposit: Balance = deposit(2, 64); @@ -120,7 +192,42 @@ parameter_types! { // No hard limit, used for worst-case weight estimation 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; + + // Swaps parameters + /// A precentage from the withdrawal amount a liquidity provider wants to withdraw + /// from a pool before the pool is closed. + pub const ExitFee: Balance = 3 * BASE / 1000; // 0.3% + /// Minimum number of assets. + pub const MinAssets: u16 = 2; + /// Maximum number of assets. `MaxCategories` plus one base asset. + pub const MaxAssets: u16 = MAX_ASSETS; + /// Mathematical constraint set by the Balancer algorithm. DO NOT CHANGE. + pub const MaxInRatio: Balance = (BASE / 3) + 1; + /// Mathematical constraint set by the Balancer algorithm. DO NOT CHANGE. + pub const MaxOutRatio: Balance = (BASE / 3) + 1; + /// The maximum fee that is charged for swaps and single asset LP operations. + pub const MaxSwapFee: Balance = BASE / 10; // 10% + /// The sum of all weights of the assets within the pool is limited by `MaxTotalWeight`. + pub const MaxTotalWeight: Balance = 128 * BASE; + /// The maximum weight a single asset can have. + pub const MaxWeight: Balance = 64 * BASE; + /// Minimum amount of liquidity required to launch a CPMM pool. + pub const MinLiquidity: Balance = 100 * BASE; + /// Minimum subsidy required to launch a Rikiddo pool. + pub const MinSubsidy: Balance = MinLiquidity::get(); + /// Minimum subsidy a single account can provide. + pub const MinSubsidyPerAccount: Balance = MinSubsidy::get(); + /// Minimum weight a single asset can have. + pub const MinWeight: Balance = BASE; + /// Pallet identifier, mainly used for named balance reserves. + pub const SwapsPalletId: PalletId = SWAPS_PALLET_ID; + // System + pub const BlockHashCount: u64 = 250; pub const SS58Prefix: u8 = 73; pub const Version: RuntimeVersion = VERSION; pub RuntimeBlockLength: BlockLength = BlockLength::max_with_normal_ratio( @@ -144,31 +251,57 @@ parameter_types! { .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO) .build_or_panic(); + // Timestamp + pub const MinimumPeriod: u64 = MILLISECS_PER_BLOCK as u64 / 2; + // Transaction payment + /// A fee mulitplier for Operational extrinsics to compute “virtual tip” + /// to boost their priority. pub const OperationalFeeMultiplier: u8 = 5; + /// The fee that's paid for every byte in the transaction. pub const TransactionByteFee: Balance = 100 * MICRO; + /// Once the dispatchables in a block consume that percentage of the total weight + /// that's available for dispatchables in a block, the fee adjustment will start. pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(10); // With a target block time of 12 seconds (7200 blocks per day) // the weight fees can increase by at most ~21.46% per day, given extreme congestion. - // See https://paritytech.github.io/substrate/master/pallet_transaction_payment/struct.TargetedFeeAdjustment.html for details. + /// See https://paritytech.github.io/substrate/master/pallet_transaction_payment/struct.TargetedFeeAdjustment.html for details. pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(3, 100_000); - // Minimum amount of the multiplier. The test `multiplier_can_grow_from_zero` ensures - // that this value is not too low. + /// Minimum amount of the multiplier. The test `multiplier_can_grow_from_zero` ensures + /// that this value is not too low. pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000u128); // Treasury + /// Percentage of spare funds (if any) that are burnt per spend period. pub const Burn: Permill = Permill::from_percent(50); + /// The maximum number of approvals that can wait in the spending queue. pub const MaxApprovals: u32 = 100; + /// Fraction of a proposal's value that should be bonded in order to place the proposal. + /// An accepted proposal gets these back. A rejected proposal does not. pub const ProposalBond: Permill = Permill::from_percent(5); + /// Minimum amount of funds that should be placed in a deposit for making a proposal. pub const ProposalBondMinimum: Balance = 10 * BASE; + /// Maximum amount of funds that should be placed in a deposit for making a proposal. pub const ProposalBondMaximum: Balance = 500 * BASE; + /// Period between successive spends. pub const SpendPeriod: BlockNumber = 24 * BLOCKS_PER_DAY; + /// Pallet identifier, mainly used for named balance reserves. pub const TreasuryPalletId: PalletId = PalletId(*b"zge/tsry"); // Vesting pub const MinVestedTransfer: Balance = CENT; } +parameter_type_with_key! { + // Well, not every asset is a currency ¯\_(ツ)_/¯ + pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance { + match currency_id { + Asset::Ztg => ExistentialDeposit::get(), + _ => 0 + } + }; +} + // Parameterized slow adjusting fee updated based on // https://research.web3.foundation/en/latest/polkadot/overview/2-token-economics.html#-2.-slow-adjusting-mechanism pub type SlowAdjustingFeeUpdate = diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 2fbc09acc..b1d7d488c 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -1354,9 +1354,12 @@ macro_rules! create_common_benchmark_logic { pub(crate) mod benchmarks { pub(crate) mod currencies { use super::utils::{lookup_of_account, set_balance}; - use crate::{AccountId, Amount, AssetManager, Balance, CurrencyId, Runtime}; + use crate::{ + AccountId, Amount, AssetManager, Balance, CurrencyId, ExistentialDeposit, + GetNativeCurrencyId, Runtime + }; use zeitgeist_primitives::{ - constants::{ExistentialDeposit, GetNativeCurrencyId, BASE}, + constants::BASE, types::Asset, }; diff --git a/runtime/zeitgeist/src/parameters.rs b/runtime/zeitgeist/src/parameters.rs index c7028a3c4..0f5413ddd 100644 --- a/runtime/zeitgeist/src/parameters.rs +++ b/runtime/zeitgeist/src/parameters.rs @@ -31,6 +31,7 @@ use frame_support::{ PalletId, }; use frame_system::limits::{BlockLength, BlockWeights}; +use orml_traits::parameter_type_with_key; use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment}; use sp_runtime::{traits::AccountIdConversion, FixedPointNumber, Perbill, Permill, Perquintill}; use sp_version::RuntimeVersion; @@ -41,9 +42,17 @@ pub(crate) const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND / 2; pub(crate) const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); parameter_types! { + // Authorized + pub const AuthorizedPalletId: PalletId = AUTHORIZED_PALLET_ID; + // Authority pub const MaxAuthorities: u32 = 32; + // Balance + pub const ExistentialDeposit: u128 = 5 * CENT; + pub const MaxLocks: u32 = 50; + pub const MaxReserves: u32 = 50; + // Collective // Note: MaxMembers does not influence the pallet logic, but the worst-case weight estimation. pub const AdvisoryCommitteeMaxMembers: u32 = 100; @@ -56,13 +65,22 @@ parameter_types! { pub const TechnicalCommitteeMaxProposals: u32 = 64; pub const TechnicalCommitteeMotionDuration: BlockNumber = 7 * BLOCKS_PER_DAY; + // Court + /// Duration of a single court case. + pub const CourtCaseDuration: u64 = BLOCKS_PER_DAY; + /// Pallet identifier, mainly used for named balance reserves. DO NOT CHANGE. + pub const CourtPalletId: PalletId = COURT_PALLET_ID; + /// This value is multiplied by the current number of jurors to determine the stake + /// the juror has to pay. + pub const StakeWeight: u128 = 2 * BASE; + // Democracy /// How often (in blocks) new public referenda are launched. pub const LaunchPeriod: BlockNumber = 5 * BLOCKS_PER_DAY; /// How often (in blocks) to check for new votes. pub const VotingPeriod: BlockNumber = 5 * BLOCKS_PER_DAY; /// Minimum voting period allowed for a fast-track referendum. - pub const FastTrackVotingPeriod: BlockNumber = 3 * BLOCKS_PER_HOUR; + pub const FastTrackVotingPeriod: BlockNumber = BLOCKS_PER_DAY; /// The minimum amount to be used as a deposit for a public referendum proposal. pub const MinimumDeposit: Balance = 100 * BASE; /// The period between a proposal being approved and enacted. @@ -73,7 +91,7 @@ parameter_types! { /// The minimum period of vote locking. /// It should be no shorter than enactment period to ensure that in the case of an approval, /// those successful voters are locked into the consequences that their votes entail. - pub const VoteLockingPeriod: BlockNumber = VotingPeriod::get() + EnactmentPeriod::get(); + pub const VoteLockingPeriod: BlockNumber = EnactmentPeriod::get(); /// Period in blocks where an external proposal may not be re-submitted after being vetoed. pub const CooloffPeriod: BlockNumber = 7 * BLOCKS_PER_DAY; /// Indicator for whether an emergency origin is even allowed to happen. @@ -85,12 +103,26 @@ parameter_types! { pub const MaxProposals: u32 = 100; // Identity - pub const BasicDeposit: Balance = 8 * BASE; - pub const FieldDeposit: Balance = 256 * CENT; - pub const MaxAdditionalFields: u32 = 64; - pub const MaxRegistrars: u32 = 8; - pub const MaxSubAccounts: u32 = 64; - pub const SubAccountDeposit: Balance = 2 * BASE; + /// The amount held on deposit for a registered identity + pub const BasicDeposit: Balance = 100 * BASE; + /// The amount held on deposit per additional field for a registered identity. + pub const FieldDeposit: Balance = 25 * BASE; + /// Maximum number of additional fields that may be stored in an ID. Needed to bound the I/O + /// required to access an identity, but can be pretty high. + pub const MaxAdditionalFields: u32 = 16; + /// Maxmimum number of registrars allowed in the system. Needed to bound the complexity + /// of, e.g., updating judgements. + pub const MaxRegistrars: u32 = 4; + /// The maximum number of sub-accounts allowed per identified account. + pub const MaxSubAccounts: u32 = 128; + /// The amount held on deposit for a registered subaccount. This should account for the fact + /// that one storage item's value will increase by the size of an account ID, and there will + /// be another trie item whose value is the size of an account ID plus 32 bytes. + pub const SubAccountDeposit: Balance = 20 * BASE; + + // Liquidity Mining parameters + /// Pallet identifier, mainly used for named balance reserves. DO NOT CHANGE. + pub const LiquidityMiningPalletId: PalletId = LM_PALLET_ID; // Multisig // One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes. @@ -99,8 +131,48 @@ parameter_types! { pub const DepositFactor: Balance = deposit(0, 32); // ORML + pub const GetNativeCurrencyId: CurrencyId = Asset::Ztg; pub DustAccount: AccountId = PalletId(*b"orml/dst").into_account(); + // Prediction Market parameters + /// (Slashable) Bond that is provided for creating an advised market that needs approval. + /// Slashed in case the market is rejected. + pub const AdvisoryBond: Balance = 200 * BASE; + /// (Slashable) Bond that is provided for disputing the outcome. + /// Slashed in case the final outcome does not match the dispute for which the `DisputeBond` + /// was deposited. + pub const DisputeBond: Balance = 2_000 * BASE; + /// `DisputeBond` is increased by this factor after every dispute. + pub const DisputeFactor: Balance = 2 * BASE; + /// After reporting the outcome and after every dispute, the dispute period is extended + /// by `DisputePeriod`. + pub const DisputePeriod: BlockNumber = 4 * BLOCKS_PER_DAY; + /// Maximum Categories a prediciton market can have (excluding base asset). + pub const MaxCategories: u16 = MAX_CATEGORIES; + /// Maximum number of disputes. + pub const MaxDisputes: u16 = 1; + /// Minimum number of categories. The trivial minimum is 2, which represents a binary market. + pub const MinCategories: u16 = 2; + // 60_000 = 1 minute. Should be raised to something more reasonable in the future. + /// Minimum number of milliseconds a Rikiddo market must be in subsidy gathering phase. + pub const MinSubsidyPeriod: Moment = 60_000; + // 2_678_400_000 = 31 days. + /// Maximum number of milliseconds a Rikiddo market can be in subsidy gathering phase. + pub const MaxSubsidyPeriod: Moment = 2_678_400_000; + // Requirements: MaxPeriod + ReportingPeriod + MaxDisputes * DisputePeriod < u64::MAX. + /// The maximum market period. + pub const MaxMarketPeriod: Moment = u64::MAX / 2; + /// (Slashable) The orcale bond. Slashed in case the final outcome does not match the + /// outcome the oracle reported. + pub const OracleBond: Balance = 200 * BASE; + /// Pallet identifier, mainly used for named balance reserves. DO NOT CHANGE. + pub const PmPalletId: PalletId = PM_PALLET_ID; + /// Timeframe during which the oracle can report the final outcome after the market closed. + pub const ReportingPeriod: u32 = 4 * BLOCKS_PER_DAY as u32; + /// (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; + // Preimage pub const PreimageMaxSize: u32 = 4096 * 1024; pub PreimageBaseDeposit: Balance = deposit(2, 64); @@ -120,7 +192,42 @@ parameter_types! { // No hard limit, used for worst-case weight estimation 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; + + // Swaps parameters + /// A precentage from the withdrawal amount a liquidity provider wants to withdraw + /// from a pool before the pool is closed. + pub const ExitFee: Balance = BASE / 10_000; // 0.01% + /// Minimum number of assets. + pub const MinAssets: u16 = 2; + /// Maximum number of assets. `MaxCategories` plus one base asset. + pub const MaxAssets: u16 = MAX_ASSETS; + /// Mathematical constraint set by the Balancer algorithm. DO NOT CHANGE. + pub const MaxInRatio: Balance = (BASE / 3) + 1; + /// Mathematical constraint set by the Balancer algorithm. DO NOT CHANGE. + pub const MaxOutRatio: Balance = (BASE / 3) + 1; + /// The maximum fee that is charged for swaps and single asset LP operations. + pub const MaxSwapFee: Balance = BASE / 10; // 10% + /// The sum of all weights of the assets within the pool is limited by `MaxTotalWeight`. + pub const MaxTotalWeight: Balance = 128 * BASE; + /// The maximum weight a single asset can have. + pub const MaxWeight: Balance = 64 * BASE; + /// Minimum amount of liquidity required to launch a CPMM pool. + pub const MinLiquidity: Balance = 100 * BASE; + /// Minimum subsidy required to launch a Rikiddo pool. + pub const MinSubsidy: Balance = MinLiquidity::get(); + /// Minimum subsidy a single account can provide. + pub const MinSubsidyPerAccount: Balance = MinSubsidy::get(); + /// Minimum weight a single asset can have. + pub const MinWeight: Balance = BASE; + /// Pallet identifier, mainly used for named balance reserves. DO NOT CHANGE. + pub const SwapsPalletId: PalletId = SWAPS_PALLET_ID; + // System + pub const BlockHashCount: u64 = 250; pub const SS58Prefix: u8 = 73; pub const Version: RuntimeVersion = VERSION; pub RuntimeBlockLength: BlockLength = BlockLength::max_with_normal_ratio( @@ -144,31 +251,57 @@ parameter_types! { .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO) .build_or_panic(); + // Timestamp + pub const MinimumPeriod: u64 = MILLISECS_PER_BLOCK as u64 / 2; + // Transaction payment + /// A fee mulitplier for Operational extrinsics to compute “virtual tip” + /// to boost their priority. pub const OperationalFeeMultiplier: u8 = 5; + /// The fee that's paid for every byte in the transaction. pub const TransactionByteFee: Balance = 100 * MICRO; + /// Once the dispatchables in a block consume that percentage of the total weight + /// that's available for dispatchables in a block, the fee adjustment will start. pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(10); // With a target block time of 12 seconds (7200 blocks per day) // the weight fees can increase by at most ~21.46% per day, given extreme congestion. - // See https://paritytech.github.io/substrate/master/pallet_transaction_payment/struct.TargetedFeeAdjustment.html for details. + /// See https://paritytech.github.io/substrate/master/pallet_transaction_payment/struct.TargetedFeeAdjustment.html for details. pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(3, 100_000); - // Minimum amount of the multiplier. The test `multiplier_can_grow_from_zero` ensures - // that this value is not too low. + /// Minimum amount of the multiplier. The test `multiplier_can_grow_from_zero` ensures + /// that this value is not too low. pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000u128); // Treasury + /// Percentage of spare funds (if any) that are burnt per spend period. pub const Burn: Permill = Permill::from_percent(50); + /// The maximum number of approvals that can wait in the spending queue. pub const MaxApprovals: u32 = 100; + /// Fraction of a proposal's value that should be bonded in order to place the proposal. + /// An accepted proposal gets these back. A rejected proposal does not. pub const ProposalBond: Permill = Permill::from_percent(5); + /// Minimum amount of funds that should be placed in a deposit for making a proposal. pub const ProposalBondMinimum: Balance = 10 * BASE; + /// Maximum amount of funds that should be placed in a deposit for making a proposal. pub const ProposalBondMaximum: Balance = 500 * BASE; + /// Period between successive spends. pub const SpendPeriod: BlockNumber = 24 * BLOCKS_PER_DAY; + /// Pallet identifier, mainly used for named balance reserves. DO NOT CHANGE. pub const TreasuryPalletId: PalletId = PalletId(*b"zge/tsry"); // Vesting pub const MinVestedTransfer: Balance = CENT; } +parameter_type_with_key! { + // Well, not every asset is a currency ¯\_(ツ)_/¯ + pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance { + match currency_id { + Asset::Ztg => ExistentialDeposit::get(), + _ => 0 + } + }; +} + // Parameterized slow adjusting fee updated based on // https://research.web3.foundation/en/latest/polkadot/overview/2-token-economics.html#-2.-slow-adjusting-mechanism pub type SlowAdjustingFeeUpdate = diff --git a/zrml/authorized/Cargo.toml b/zrml/authorized/Cargo.toml index 468155cef..996714383 100644 --- a/zrml/authorized/Cargo.toml +++ b/zrml/authorized/Cargo.toml @@ -12,6 +12,7 @@ zrml-market-commons = { default-features = false, path = "../market-commons" } pallet-balances = { branch = "moonbeam-polkadot-v0.9.19", git = "https://github.com/purestake/substrate" } pallet-timestamp = { branch = "moonbeam-polkadot-v0.9.19", git = "https://github.com/purestake/substrate"} sp-io = { branch = "moonbeam-polkadot-v0.9.19", git = "https://github.com/purestake/substrate" } +zeitgeist-primitives = { default-features = false, features = ["mock"], path = "../../primitives" } [features] default = ["std"] diff --git a/zrml/authorized/src/mock.rs b/zrml/authorized/src/mock.rs index 5f1a7035e..8f4ceb01c 100644 --- a/zrml/authorized/src/mock.rs +++ b/zrml/authorized/src/mock.rs @@ -24,7 +24,7 @@ use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, }; use zeitgeist_primitives::{ - constants::{AuthorizedPalletId, BlockHashCount, MaxReserves, MinimumPeriod, BASE}, + constants::mock::{AuthorizedPalletId, BlockHashCount, MaxReserves, MinimumPeriod, BASE}, types::{ AccountIdTest, Balance, BlockNumber, BlockTest, Hash, Index, MarketId, Moment, UncheckedExtrinsicTest, diff --git a/zrml/court/Cargo.toml b/zrml/court/Cargo.toml index e5e1851cb..1eb264e06 100644 --- a/zrml/court/Cargo.toml +++ b/zrml/court/Cargo.toml @@ -15,6 +15,7 @@ pallet-balances = { branch = "moonbeam-polkadot-v0.9.19", git = "https://github. pallet-randomness-collective-flip = { branch = "moonbeam-polkadot-v0.9.19", git = "https://github.com/purestake/substrate" } pallet-timestamp = { branch = "moonbeam-polkadot-v0.9.19", git = "https://github.com/purestake/substrate"} sp-io = { branch = "moonbeam-polkadot-v0.9.19", git = "https://github.com/purestake/substrate" } +zeitgeist-primitives = { default-features = false, features = ["mock"], path = "../../primitives" } [features] default = ["std"] diff --git a/zrml/court/src/lib.rs b/zrml/court/src/lib.rs index 77d8c7317..ee386e04a 100644 --- a/zrml/court/src/lib.rs +++ b/zrml/court/src/lib.rs @@ -65,14 +65,11 @@ mod pallet { ArithmeticError, DispatchError, SaturatedConversion, }; use zeitgeist_primitives::{ - constants::CourtPalletId, traits::DisputeApi, types::{Market, MarketDispute, MarketDisputeMechanism, OutcomeReport}, }; use zrml_market_commons::MarketCommonsPalletApi; - pub(crate) const RESERVE_ID: [u8; 8] = CourtPalletId::get().0; - // Number of jurors for an initial market dispute const INITIAL_JURORS_NUM: usize = 3; const MAX_RANDOM_JURORS: usize = 13; @@ -115,7 +112,7 @@ mod pallet { let jurors_num = Jurors::::count() as usize; let jurors_num_plus_one = jurors_num.checked_add(1).ok_or(ArithmeticError::Overflow)?; let stake = Self::current_required_stake(jurors_num_plus_one); - CurrencyOf::::reserve_named(&RESERVE_ID, &who, stake)?; + CurrencyOf::::reserve_named(&Self::reserve_id(), &who, stake)?; let juror = Juror { status: JurorStatus::Ok }; Jurors::::insert(&who, juror.clone()); Self::deposit_event(Event::JoinedJuror(who, juror)); @@ -227,6 +224,12 @@ mod pallet { jurors.choose_multiple(rng, actual_len).collect() } + /// The reserve ID of the court pallet. + #[inline] + pub fn reserve_id() -> [u8; 8] { + T::PalletId::get().0 + } + // Returns a pseudo random number generator implementation based on the seed // provided by the `Config::Random` type and the `JurorsSelectionNonce` storage. pub(crate) fn rng() -> impl RngCore { @@ -303,13 +306,13 @@ mod pallet { let treasury_account_id = Self::treasury_account_id(); let slash_and_remove_juror = |ai: &T::AccountId| { - let all_reserved = CurrencyOf::::reserved_balance_named(&RESERVE_ID, ai); + let all_reserved = CurrencyOf::::reserved_balance_named(&Self::reserve_id(), ai); // Unsigned division will never overflow let slash = all_reserved .checked_div(&BalanceOf::::from(TARDY_PUNISHMENT_DIVISOR)) .ok_or(DispatchError::Other("Zero division"))?; let _ = CurrencyOf::::repatriate_reserved_named( - &RESERVE_ID, + &Self::reserve_id(), ai, &treasury_account_id, slash, @@ -391,12 +394,13 @@ mod pallet { if outcome == &winner_outcome { total_winners = total_winners.saturating_add(BalanceOf::::from(1u8)); } else { - let all_reserved = CurrencyOf::::reserved_balance_named(&RESERVE_ID, jai); + let all_reserved = + CurrencyOf::::reserved_balance_named(&Self::reserve_id(), jai); // Unsigned division will never overflow let slash = all_reserved .checked_div(&BalanceOf::::from(2u8)) .ok_or(DispatchError::Other("Zero division"))?; - CurrencyOf::::slash_reserved_named(&RESERVE_ID, jai, slash); + CurrencyOf::::slash_reserved_named(&Self::reserve_id(), jai, slash); total_incentives = total_incentives.saturating_add(slash); } } @@ -465,7 +469,7 @@ mod pallet { // Obliterates all stored references of a juror un-reserving balances. fn remove_juror_from_all_courts_of_all_markets(ai: &T::AccountId) { - CurrencyOf::::unreserve_all_named(&RESERVE_ID, ai); + CurrencyOf::::unreserve_all_named(&Self::reserve_id(), ai); Jurors::::remove(ai); let mut market_ids = BTreeSet::new(); market_ids.extend(RequestedJurors::::iter().map(|el| el.0)); diff --git a/zrml/court/src/mock.rs b/zrml/court/src/mock.rs index 555c54253..7d2c76934 100644 --- a/zrml/court/src/mock.rs +++ b/zrml/court/src/mock.rs @@ -24,7 +24,7 @@ use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, }; use zeitgeist_primitives::{ - constants::{ + constants::mock::{ BlockHashCount, CourtCaseDuration, CourtPalletId, MaxReserves, MinimumPeriod, StakeWeight, BASE, }, diff --git a/zrml/court/src/tests.rs b/zrml/court/src/tests.rs index 465f29aee..6aeee3128 100644 --- a/zrml/court/src/tests.rs +++ b/zrml/court/src/tests.rs @@ -22,7 +22,7 @@ use crate::{ Balances, Court, ExtBuilder, Origin, RandomnessCollectiveFlip, Runtime, System, ALICE, BOB, CHARLIE, INITIAL_BALANCE, }, - Error, Juror, JurorStatus, Jurors, RequestedJurors, Votes, RESERVE_ID, + Error, Juror, JurorStatus, Jurors, RequestedJurors, Votes, }; use frame_support::{ assert_noop, assert_ok, @@ -67,11 +67,11 @@ fn exit_court_successfully_removes_a_juror_and_frees_balances() { assert_ok!(Court::join_court(Origin::signed(ALICE))); assert_eq!(Jurors::::iter().count(), 1); assert_eq!(Balances::free_balance(ALICE), 998 * BASE); - assert_eq!(Balances::reserved_balance_named(&RESERVE_ID, &ALICE), 2 * BASE); + assert_eq!(Balances::reserved_balance_named(&Court::reserve_id(), &ALICE), 2 * BASE); assert_ok!(Court::exit_court(Origin::signed(ALICE))); assert_eq!(Jurors::::iter().count(), 0); assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE); - assert_eq!(Balances::reserved_balance_named(&RESERVE_ID, &ALICE), 0); + assert_eq!(Balances::reserved_balance_named(&Court::reserve_id(), &ALICE), 0); }); } @@ -91,12 +91,12 @@ fn join_court_reserves_balance_according_to_the_number_of_jurors() { assert_eq!(Balances::free_balance(ALICE), 1000 * BASE); assert_ok!(Court::join_court(Origin::signed(ALICE))); assert_eq!(Balances::free_balance(ALICE), 998 * BASE); - assert_eq!(Balances::reserved_balance_named(&RESERVE_ID, &ALICE), 2 * BASE); + assert_eq!(Balances::reserved_balance_named(&Court::reserve_id(), &ALICE), 2 * BASE); assert_eq!(Balances::free_balance(BOB), 1000 * BASE); assert_ok!(Court::join_court(Origin::signed(BOB))); assert_eq!(Balances::free_balance(BOB), 996 * BASE); - assert_eq!(Balances::reserved_balance_named(&RESERVE_ID, &BOB), 4 * BASE); + assert_eq!(Balances::reserved_balance_named(&Court::reserve_id(), &BOB), 4 * BASE); }); } @@ -175,11 +175,11 @@ fn on_resolution_awards_winners_and_slashes_losers() { Court::vote(Origin::signed(CHARLIE), 0, OutcomeReport::Scalar(3)).unwrap(); let _ = Court::on_resolution(&[], &0, &DEFAULT_MARKET).unwrap(); assert_eq!(Balances::free_balance(ALICE), 998 * BASE + 3 * BASE); - assert_eq!(Balances::reserved_balance_named(&RESERVE_ID, &ALICE), 2 * BASE); + assert_eq!(Balances::reserved_balance_named(&Court::reserve_id(), &ALICE), 2 * BASE); assert_eq!(Balances::free_balance(BOB), 996 * BASE); - assert_eq!(Balances::reserved_balance_named(&RESERVE_ID, &BOB), 4 * BASE); + assert_eq!(Balances::reserved_balance_named(&Court::reserve_id(), &BOB), 4 * BASE); assert_eq!(Balances::free_balance(CHARLIE), 994 * BASE); - assert_eq!(Balances::reserved_balance_named(&RESERVE_ID, &CHARLIE), 3 * BASE); + assert_eq!(Balances::reserved_balance_named(&Court::reserve_id(), &CHARLIE), 3 * BASE); }); } @@ -243,7 +243,7 @@ fn on_resolution_punishes_tardy_jurors_that_failed_to_vote_a_second_time() { let slash = join_court_stake / 5; assert_eq!(Balances::free_balance(Court::treasury_account_id()), INITIAL_BALANCE + slash); assert_eq!(Balances::free_balance(BOB), INITIAL_BALANCE - slash); - assert_eq!(Balances::reserved_balance_named(&RESERVE_ID, &BOB), 0); + assert_eq!(Balances::reserved_balance_named(&Court::reserve_id(), &BOB), 0); }); } diff --git a/zrml/liquidity-mining/Cargo.toml b/zrml/liquidity-mining/Cargo.toml index 1b1b13ba7..414cd85c0 100644 --- a/zrml/liquidity-mining/Cargo.toml +++ b/zrml/liquidity-mining/Cargo.toml @@ -13,6 +13,7 @@ zrml-market-commons = { default-features = false, path = "../market-commons" } pallet-balances = { branch = "moonbeam-polkadot-v0.9.19", git = "https://github.com/purestake/substrate" } pallet-timestamp = { branch = "moonbeam-polkadot-v0.9.19", git = "https://github.com/purestake/substrate" } sp-io = { branch = "moonbeam-polkadot-v0.9.19", git = "https://github.com/purestake/substrate" } +zeitgeist-primitives = { default-features = false, features = ["mock"], path = "../../primitives" } [features] default = ["std"] diff --git a/zrml/liquidity-mining/src/mock.rs b/zrml/liquidity-mining/src/mock.rs index 3cfd69645..b0c2661a2 100644 --- a/zrml/liquidity-mining/src/mock.rs +++ b/zrml/liquidity-mining/src/mock.rs @@ -27,7 +27,7 @@ use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, }; use zeitgeist_primitives::{ - constants::{ + constants::mock::{ BlockHashCount, ExistentialDeposit, LiquidityMiningPalletId, MaxLocks, MaxReserves, MinimumPeriod, BASE, }, diff --git a/zrml/market-commons/Cargo.toml b/zrml/market-commons/Cargo.toml index 003ab6d22..8f01d67f8 100644 --- a/zrml/market-commons/Cargo.toml +++ b/zrml/market-commons/Cargo.toml @@ -11,6 +11,7 @@ scale-info = { version = "2.1.1", default-features = false, features = ["derive" pallet-balances = { branch = "moonbeam-polkadot-v0.9.19", git = "https://github.com/purestake/substrate" } pallet-timestamp = { branch = "moonbeam-polkadot-v0.9.19", git = "https://github.com/purestake/substrate"} sp-io = { branch = "moonbeam-polkadot-v0.9.19", git = "https://github.com/purestake/substrate" } +zeitgeist-primitives = { default-features = false, features = ["mock"], path = "../../primitives" } [features] default = ["std"] diff --git a/zrml/market-commons/src/mock.rs b/zrml/market-commons/src/mock.rs index 482f771de..61a69d98d 100644 --- a/zrml/market-commons/src/mock.rs +++ b/zrml/market-commons/src/mock.rs @@ -24,7 +24,7 @@ use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, }; use zeitgeist_primitives::{ - constants::{BlockHashCount, MaxReserves, MinimumPeriod}, + constants::mock::{BlockHashCount, MaxReserves, MinimumPeriod}, types::{ AccountIdTest, Balance, BlockNumber, BlockTest, Hash, Index, MarketId, Moment, UncheckedExtrinsicTest, diff --git a/zrml/orderbook-v1/Cargo.toml b/zrml/orderbook-v1/Cargo.toml index 5feca7b10..59be5b236 100644 --- a/zrml/orderbook-v1/Cargo.toml +++ b/zrml/orderbook-v1/Cargo.toml @@ -23,6 +23,7 @@ mock = [ "orml-tokens", "pallet-balances", "sp-io", + "zeitgeist-primitives/mock", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/zrml/orderbook-v1/src/mock.rs b/zrml/orderbook-v1/src/mock.rs index b4f662203..d71409a68 100644 --- a/zrml/orderbook-v1/src/mock.rs +++ b/zrml/orderbook-v1/src/mock.rs @@ -24,7 +24,7 @@ use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, }; use zeitgeist_primitives::{ - constants::{ + constants::mock::{ BlockHashCount, ExistentialDeposit, ExistentialDeposits, MaxLocks, MaxReserves, BASE, }, types::{ diff --git a/zrml/prediction-markets/Cargo.toml b/zrml/prediction-markets/Cargo.toml index 6154568de..44b66670c 100644 --- a/zrml/prediction-markets/Cargo.toml +++ b/zrml/prediction-markets/Cargo.toml @@ -44,6 +44,7 @@ mock = [ "sp-api", "sp-io", "substrate-fixed", + "zeitgeist-primitives/mock", "zrml-prediction-markets-runtime-api", "zrml-rikiddo", "zrml-swaps", @@ -52,6 +53,7 @@ runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", + "zeitgeist-primitives/mock", ] std = [ "frame-benchmarking?/std", diff --git a/zrml/prediction-markets/fuzz/Cargo.toml b/zrml/prediction-markets/fuzz/Cargo.toml index b45b6911c..36754ec85 100644 --- a/zrml/prediction-markets/fuzz/Cargo.toml +++ b/zrml/prediction-markets/fuzz/Cargo.toml @@ -8,7 +8,7 @@ test = false arbitrary = { features = ["derive"], version = "1.0" } frame-support = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/substrate" } libfuzzer-sys = "0.4" -zeitgeist-primitives = { features = ["arbitrary"], default-features = false, path = "../../../primitives" } +zeitgeist-primitives = { features = ["arbitrary", "mock"], default-features = false, path = "../../../primitives" } zrml-prediction-markets = { features = ["mock"], path = ".." } zrml-simple-disputes = { path = "../../simple-disputes" } diff --git a/zrml/prediction-markets/src/benchmarks.rs b/zrml/prediction-markets/src/benchmarks.rs index 82b7688d9..01f6e41dd 100644 --- a/zrml/prediction-markets/src/benchmarks.rs +++ b/zrml/prediction-markets/src/benchmarks.rs @@ -35,7 +35,7 @@ use frame_system::RawOrigin; use orml_traits::MultiCurrency; use sp_runtime::traits::{One, SaturatedConversion, Zero}; use zeitgeist_primitives::{ - constants::{MaxSwapFee, MinLiquidity, MinWeight, BASE}, + constants::mock::{MaxSwapFee, MinLiquidity, MinWeight, BASE}, traits::DisputeApi, types::{ Asset, MarketCreation, MarketDisputeMechanism, MarketPeriod, MarketStatus, MarketType, diff --git a/zrml/prediction-markets/src/lib.rs b/zrml/prediction-markets/src/lib.rs index d1f5eece4..b98f3cfbc 100644 --- a/zrml/prediction-markets/src/lib.rs +++ b/zrml/prediction-markets/src/lib.rs @@ -118,7 +118,7 @@ mod pallet { DispatchError, DispatchResult, SaturatedConversion, }; use zeitgeist_primitives::{ - constants::{PmPalletId, MILLISECS_PER_BLOCK}, + constants::MILLISECS_PER_BLOCK, traits::{DisputeApi, Swaps, ZeitgeistAssetManager}, types::{ Asset, Market, MarketCreation, MarketDispute, MarketDisputeMechanism, MarketPeriod, @@ -129,8 +129,6 @@ mod pallet { use zrml_liquidity_mining::LiquidityMiningPalletApi; use zrml_market_commons::MarketCommonsPalletApi; - pub const RESERVE_ID: [u8; 8] = PmPalletId::get().0; - /// The current storage version. const STORAGE_VERSION: StorageVersion = StorageVersion::new(4); @@ -181,7 +179,7 @@ mod pallet { // details. let slash_market_creator = |amount| { T::AssetManager::slash_reserved_named( - &RESERVE_ID, + &Self::reserve_id(), Asset::Ztg, &market.creator, amount, @@ -346,7 +344,7 @@ mod pallet { } T::AssetManager::unreserve_named( - &RESERVE_ID, + &Self::reserve_id(), Asset::Ztg, &m.creator, T::AdvisoryBond::get(), @@ -403,7 +401,7 @@ mod pallet { let num_disputes: u32 = disputes.len().saturated_into(); Self::validate_dispute(&disputes, &market, num_disputes, &outcome)?; T::AssetManager::reserve_named( - &RESERVE_ID, + &Self::reserve_id(), Asset::Ztg, &who, default_dispute_bond::(disputes.len()), @@ -558,7 +556,7 @@ mod pallet { MarketCreation::Permissionless => { let required_bond = T::ValidityBond::get().saturating_add(T::OracleBond::get()); T::AssetManager::reserve_named( - &RESERVE_ID, + &Self::reserve_id(), Asset::Ztg, &sender, required_bond, @@ -572,7 +570,7 @@ mod pallet { MarketCreation::Advised => { let required_bond = T::AdvisoryBond::get().saturating_add(T::OracleBond::get()); T::AssetManager::reserve_named( - &RESERVE_ID, + &Self::reserve_id(), Asset::Ztg, &sender, required_bond, @@ -1557,13 +1555,13 @@ mod pallet { ensure!(market.status == MarketStatus::Proposed, Error::::InvalidMarketStatus); let creator = &market.creator; T::AssetManager::slash_reserved_named( - &RESERVE_ID, + &Self::reserve_id(), Asset::Ztg, creator, T::AdvisoryBond::get(), ); T::AssetManager::unreserve_named( - &RESERVE_ID, + &Self::reserve_id(), Asset::Ztg, creator, T::OracleBond::get(), @@ -1581,13 +1579,13 @@ mod pallet { ensure!(market.status == MarketStatus::Proposed, Error::::InvalidMarketStatus); let creator = &market.creator; T::AssetManager::unreserve_named( - &RESERVE_ID, + &Self::reserve_id(), Asset::Ztg, creator, T::AdvisoryBond::get(), ); T::AssetManager::unreserve_named( - &RESERVE_ID, + &Self::reserve_id(), Asset::Ztg, creator, T::OracleBond::get(), @@ -1830,7 +1828,7 @@ mod pallet { ) -> Result { if market.creation == MarketCreation::Permissionless { T::AssetManager::unreserve_named( - &RESERVE_ID, + &Self::reserve_id(), Asset::Ztg, &market.creator, T::ValidityBond::get(), @@ -1847,14 +1845,14 @@ mod pallet { // the oracle bond gets returned if the reporter was the oracle if report.by == market.oracle { T::AssetManager::unreserve_named( - &RESERVE_ID, + &Self::reserve_id(), Asset::Ztg, &market.creator, T::OracleBond::get(), ); } else { let excess = T::AssetManager::slash_reserved_named( - &RESERVE_ID, + &Self::reserve_id(), Asset::Ztg, &market.creator, T::OracleBond::get(), @@ -1899,14 +1897,14 @@ mod pallet { // pay the correct reporters. if report.outcome == resolved_outcome { T::AssetManager::unreserve_named( - &RESERVE_ID, + &Self::reserve_id(), Asset::Ztg, &market.creator, T::OracleBond::get(), ); } else { let excess = T::AssetManager::slash_reserved_named( - &RESERVE_ID, + &Self::reserve_id(), Asset::Ztg, &market.creator, T::OracleBond::get(), @@ -1921,7 +1919,7 @@ mod pallet { let actual_bond = default_dispute_bond::(i); if dispute.outcome == resolved_outcome { T::AssetManager::unreserve_named( - &RESERVE_ID, + &Self::reserve_id(), Asset::Ztg, &dispute.by, actual_bond, @@ -1930,7 +1928,7 @@ mod pallet { correct_reporters.push(dispute.by.clone()); } else { let excess = T::AssetManager::slash_reserved_named( - &RESERVE_ID, + &Self::reserve_id(), Asset::Ztg, &dispute.by, actual_bond, @@ -2087,7 +2085,7 @@ mod pallet { let required_bond = T::ValidityBond::get() .saturating_add(T::OracleBond::get()); T::AssetManager::unreserve_named( - &RESERVE_ID, + &Self::reserve_id(), Asset::Ztg, &m.creator, required_bond, @@ -2096,7 +2094,7 @@ mod pallet { // AdvisoryBond was already returned when the market // was approved. Approval is inevitable to reach this. T::AssetManager::unreserve_named( - &RESERVE_ID, + &Self::reserve_id(), Asset::Ztg, &m.creator, T::OracleBond::get(), @@ -2185,6 +2183,12 @@ mod pallet { Ok(()) } + /// The reserve ID of the prediction-markets pallet. + #[inline] + pub fn reserve_id() -> [u8; 8] { + T::PalletId::get().0 + } + pub(crate) fn market_status_manager( block_number: T::BlockNumber, last_time_frame: TimeFrame, diff --git a/zrml/prediction-markets/src/mock.rs b/zrml/prediction-markets/src/mock.rs index 8f087a9e8..cd14f0320 100644 --- a/zrml/prediction-markets/src/mock.rs +++ b/zrml/prediction-markets/src/mock.rs @@ -34,7 +34,7 @@ use sp_runtime::{ }; use substrate_fixed::{types::extra::U33, FixedI128, FixedU128}; use zeitgeist_primitives::{ - constants::{ + constants::mock::{ AuthorizedPalletId, BalanceFractionalDecimals, BlockHashCount, CourtCaseDuration, CourtPalletId, DisputeFactor, ExistentialDeposit, ExistentialDeposits, ExitFee, GetNativeCurrencyId, LiquidityMiningPalletId, MaxAssets, MaxCategories, MaxDisputes, diff --git a/zrml/prediction-markets/src/tests.rs b/zrml/prediction-markets/src/tests.rs index f29693c4e..f5b1c3112 100644 --- a/zrml/prediction-markets/src/tests.rs +++ b/zrml/prediction-markets/src/tests.rs @@ -20,7 +20,7 @@ use crate::{ mock::*, Config, Error, Event, LastTimeFrame, MarketIdsPerCloseBlock, MarketIdsPerDisputeBlock, - MarketIdsPerOpenBlock, MarketIdsPerReportBlock, RESERVE_ID, + MarketIdsPerOpenBlock, MarketIdsPerReportBlock, }; use core::ops::{Range, RangeInclusive}; use frame_support::{ @@ -33,7 +33,7 @@ use test_case::test_case; use orml_traits::MultiCurrency; use sp_runtime::traits::AccountIdConversion; use zeitgeist_primitives::{ - constants::{DisputeFactor, BASE, CENT, MILLISECS_PER_BLOCK}, + constants::mock::{DisputeFactor, BASE, CENT, MILLISECS_PER_BLOCK}, traits::Swaps as SwapsPalletApi, types::{ Asset, BlockNumber, Market, MarketCreation, MarketDisputeMechanism, MarketPeriod, @@ -218,10 +218,17 @@ fn admin_destroy_market_correctly_slashes_permissionless_market_active() { ScoringRule::CPMM, ); assert_ok!(AssetManager::deposit(Asset::Ztg, &ALICE, 2 * SENTINEL_AMOUNT)); - assert_ok!(Balances::reserve_named(&RESERVE_ID, &ALICE, SENTINEL_AMOUNT)); + assert_ok!(Balances::reserve_named( + &PredictionMarkets::reserve_id(), + &ALICE, + SENTINEL_AMOUNT + )); let balance_free_before_alice = Balances::free_balance(&ALICE); assert_ok!(PredictionMarkets::admin_destroy_market(Origin::signed(SUDO), 0)); - assert_eq!(Balances::reserved_balance_named(&RESERVE_ID, &ALICE), SENTINEL_AMOUNT); + assert_eq!( + Balances::reserved_balance_named(&PredictionMarkets::reserve_id(), &ALICE), + SENTINEL_AMOUNT + ); let balance_free_after_alice = Balances::free_balance(&ALICE); assert_eq!(balance_free_before_alice, balance_free_after_alice); }); @@ -243,10 +250,17 @@ fn admin_destroy_market_correctly_slashes_permissionless_market_reported() { OutcomeReport::Categorical(1) )); assert_ok!(AssetManager::deposit(Asset::Ztg, &ALICE, 2 * SENTINEL_AMOUNT)); - assert_ok!(Balances::reserve_named(&RESERVE_ID, &ALICE, SENTINEL_AMOUNT)); + assert_ok!(Balances::reserve_named( + &PredictionMarkets::reserve_id(), + &ALICE, + SENTINEL_AMOUNT + )); let balance_free_before_alice = Balances::free_balance(&ALICE); assert_ok!(PredictionMarkets::admin_destroy_market(Origin::signed(SUDO), 0)); - assert_eq!(Balances::reserved_balance_named(&RESERVE_ID, &ALICE), SENTINEL_AMOUNT); + assert_eq!( + Balances::reserved_balance_named(&PredictionMarkets::reserve_id(), &ALICE), + SENTINEL_AMOUNT + ); let balance_free_after_alice = Balances::free_balance(&ALICE); assert_eq!(balance_free_before_alice, balance_free_after_alice); }); @@ -273,10 +287,17 @@ fn admin_destroy_market_correctly_slashes_permissionless_market_disputed() { OutcomeReport::Categorical(0) )); assert_ok!(AssetManager::deposit(Asset::Ztg, &ALICE, 2 * SENTINEL_AMOUNT)); - assert_ok!(Balances::reserve_named(&RESERVE_ID, &ALICE, SENTINEL_AMOUNT)); + assert_ok!(Balances::reserve_named( + &PredictionMarkets::reserve_id(), + &ALICE, + SENTINEL_AMOUNT + )); let balance_free_before_alice = Balances::free_balance(&ALICE); assert_ok!(PredictionMarkets::admin_destroy_market(Origin::signed(SUDO), 0)); - assert_eq!(Balances::reserved_balance_named(&RESERVE_ID, &ALICE), SENTINEL_AMOUNT); + assert_eq!( + Balances::reserved_balance_named(&PredictionMarkets::reserve_id(), &ALICE), + SENTINEL_AMOUNT + ); let balance_free_after_alice = Balances::free_balance(&ALICE); assert_eq!(balance_free_before_alice, balance_free_after_alice); }); @@ -298,12 +319,19 @@ fn admin_destroy_market_correctly_slashes_permissionless_market_resolved() { OutcomeReport::Categorical(1) )); run_blocks(::DisputePeriod::get()); - assert_eq!(Balances::reserved_balance_named(&RESERVE_ID, &ALICE), 0); + assert_eq!(Balances::reserved_balance_named(&PredictionMarkets::reserve_id(), &ALICE), 0); assert_ok!(AssetManager::deposit(Asset::Ztg, &ALICE, 2 * SENTINEL_AMOUNT)); - assert_ok!(Balances::reserve_named(&RESERVE_ID, &ALICE, SENTINEL_AMOUNT)); + assert_ok!(Balances::reserve_named( + &PredictionMarkets::reserve_id(), + &ALICE, + SENTINEL_AMOUNT + )); let balance_free_before_alice = Balances::free_balance(&ALICE); assert_ok!(PredictionMarkets::admin_destroy_market(Origin::signed(SUDO), 0)); - assert_eq!(Balances::reserved_balance_named(&RESERVE_ID, &ALICE), SENTINEL_AMOUNT); + assert_eq!( + Balances::reserved_balance_named(&PredictionMarkets::reserve_id(), &ALICE), + SENTINEL_AMOUNT + ); let balance_free_after_alice = Balances::free_balance(&ALICE); assert_eq!(balance_free_before_alice, balance_free_after_alice); }); @@ -318,10 +346,17 @@ fn admin_destroy_market_correctly_slashes_advised_market_proposed() { ScoringRule::CPMM, ); assert_ok!(AssetManager::deposit(Asset::Ztg, &ALICE, 2 * SENTINEL_AMOUNT)); - assert_ok!(Balances::reserve_named(&RESERVE_ID, &ALICE, SENTINEL_AMOUNT)); + assert_ok!(Balances::reserve_named( + &PredictionMarkets::reserve_id(), + &ALICE, + SENTINEL_AMOUNT + )); let balance_free_before_alice = Balances::free_balance(&ALICE); assert_ok!(PredictionMarkets::admin_destroy_market(Origin::signed(SUDO), 0)); - assert_eq!(Balances::reserved_balance_named(&RESERVE_ID, &ALICE), SENTINEL_AMOUNT); + assert_eq!( + Balances::reserved_balance_named(&PredictionMarkets::reserve_id(), &ALICE), + SENTINEL_AMOUNT + ); let balance_free_after_alice = Balances::free_balance(&ALICE); assert_eq!(balance_free_before_alice, balance_free_after_alice); }); @@ -337,10 +372,17 @@ fn admin_destroy_market_correctly_slashes_advised_market_active() { ); assert_ok!(PredictionMarkets::approve_market(Origin::signed(SUDO), 0)); assert_ok!(AssetManager::deposit(Asset::Ztg, &ALICE, 2 * SENTINEL_AMOUNT)); - assert_ok!(Balances::reserve_named(&RESERVE_ID, &ALICE, SENTINEL_AMOUNT)); + assert_ok!(Balances::reserve_named( + &PredictionMarkets::reserve_id(), + &ALICE, + SENTINEL_AMOUNT + )); let balance_free_before_alice = Balances::free_balance(&ALICE); assert_ok!(PredictionMarkets::admin_destroy_market(Origin::signed(SUDO), 0)); - assert_eq!(Balances::reserved_balance_named(&RESERVE_ID, &ALICE), SENTINEL_AMOUNT); + assert_eq!( + Balances::reserved_balance_named(&PredictionMarkets::reserve_id(), &ALICE), + SENTINEL_AMOUNT + ); let balance_free_after_alice = Balances::free_balance(&ALICE); assert_eq!(balance_free_before_alice, balance_free_after_alice); }); @@ -363,10 +405,17 @@ fn admin_destroy_market_correctly_slashes_advised_market_reported() { OutcomeReport::Categorical(1) )); assert_ok!(AssetManager::deposit(Asset::Ztg, &ALICE, 2 * SENTINEL_AMOUNT)); - assert_ok!(Balances::reserve_named(&RESERVE_ID, &ALICE, SENTINEL_AMOUNT)); + assert_ok!(Balances::reserve_named( + &PredictionMarkets::reserve_id(), + &ALICE, + SENTINEL_AMOUNT + )); let balance_free_before_alice = Balances::free_balance(&ALICE); assert_ok!(PredictionMarkets::admin_destroy_market(Origin::signed(SUDO), 0)); - assert_eq!(Balances::reserved_balance_named(&RESERVE_ID, &ALICE), SENTINEL_AMOUNT); + assert_eq!( + Balances::reserved_balance_named(&PredictionMarkets::reserve_id(), &ALICE), + SENTINEL_AMOUNT + ); let balance_free_after_alice = Balances::free_balance(&ALICE); assert_eq!(balance_free_before_alice, balance_free_after_alice); }); @@ -394,10 +443,17 @@ fn admin_destroy_market_correctly_slashes_advised_market_disputed() { OutcomeReport::Categorical(0) )); assert_ok!(AssetManager::deposit(Asset::Ztg, &ALICE, 2 * SENTINEL_AMOUNT)); - assert_ok!(Balances::reserve_named(&RESERVE_ID, &ALICE, SENTINEL_AMOUNT)); + assert_ok!(Balances::reserve_named( + &PredictionMarkets::reserve_id(), + &ALICE, + SENTINEL_AMOUNT + )); let balance_free_before_alice = Balances::free_balance(&ALICE); assert_ok!(PredictionMarkets::admin_destroy_market(Origin::signed(SUDO), 0)); - assert_eq!(Balances::reserved_balance_named(&RESERVE_ID, &ALICE), SENTINEL_AMOUNT); + assert_eq!( + Balances::reserved_balance_named(&PredictionMarkets::reserve_id(), &ALICE), + SENTINEL_AMOUNT + ); let balance_free_after_alice = Balances::free_balance(&ALICE); assert_eq!(balance_free_before_alice, balance_free_after_alice); }); @@ -420,12 +476,19 @@ fn admin_destroy_market_correctly_slashes_advised_market_resolved() { OutcomeReport::Categorical(1) )); run_blocks(::ReportingPeriod::get().into()); // Wait until market resolves - assert_eq!(Balances::reserved_balance_named(&RESERVE_ID, &ALICE), 0); + assert_eq!(Balances::reserved_balance_named(&PredictionMarkets::reserve_id(), &ALICE), 0); assert_ok!(AssetManager::deposit(Asset::Ztg, &ALICE, 2 * SENTINEL_AMOUNT)); - assert_ok!(Balances::reserve_named(&RESERVE_ID, &ALICE, SENTINEL_AMOUNT)); + assert_ok!(Balances::reserve_named( + &PredictionMarkets::reserve_id(), + &ALICE, + SENTINEL_AMOUNT + )); let balance_free_before_alice = Balances::free_balance(&ALICE); assert_ok!(PredictionMarkets::admin_destroy_market(Origin::signed(SUDO), 0)); - assert_eq!(Balances::reserved_balance_named(&RESERVE_ID, &ALICE), SENTINEL_AMOUNT); + assert_eq!( + Balances::reserved_balance_named(&PredictionMarkets::reserve_id(), &ALICE), + SENTINEL_AMOUNT + ); let balance_free_after_alice = Balances::free_balance(&ALICE); assert_eq!(balance_free_before_alice, balance_free_after_alice); }); @@ -531,9 +594,14 @@ fn admin_move_market_to_resolved_resolves_reported_market() { // Give ALICE `SENTINEL_AMOUNT` free and reserved ZTG; we record the free balance to check // that the correct bonds are unreserved! assert_ok!(AssetManager::deposit(Asset::Ztg, &ALICE, 2 * SENTINEL_AMOUNT)); - assert_ok!(Balances::reserve_named(&RESERVE_ID, &ALICE, SENTINEL_AMOUNT)); + assert_ok!(Balances::reserve_named( + &PredictionMarkets::reserve_id(), + &ALICE, + SENTINEL_AMOUNT + )); let balance_free_before = Balances::free_balance(&ALICE); - let balance_reserved_before = Balances::reserved_balance_named(&RESERVE_ID, &ALICE); + let balance_reserved_before = + Balances::reserved_balance_named(&PredictionMarkets::reserve_id(), &ALICE); run_to_block(end); let category = 1; @@ -557,7 +625,7 @@ fn admin_move_market_to_resolved_resolves_reported_market() { ); assert_eq!( - Balances::reserved_balance_named(&RESERVE_ID, &ALICE), + Balances::reserved_balance_named(&PredictionMarkets::reserve_id(), &ALICE), balance_reserved_before - ::OracleBond::get() - ::ValidityBond::get() @@ -779,16 +847,22 @@ fn reject_market_unreserves_oracle_bond_and_slashes_advisory_bond() { // Give ALICE `SENTINEL_AMOUNT` free and reserved ZTG; we record the free balance to check // that the AdvisoryBond gets slashed but the OracleBond gets unreserved. assert_ok!(AssetManager::deposit(Asset::Ztg, &ALICE, 2 * SENTINEL_AMOUNT)); - assert_ok!(Balances::reserve_named(&RESERVE_ID, &ALICE, SENTINEL_AMOUNT)); + assert_ok!(Balances::reserve_named( + &PredictionMarkets::reserve_id(), + &ALICE, + SENTINEL_AMOUNT + )); let balance_free_before_alice = Balances::free_balance(&ALICE); - let balance_reserved_before_alice = Balances::reserved_balance_named(&RESERVE_ID, &ALICE); + let balance_reserved_before_alice = + Balances::reserved_balance_named(&PredictionMarkets::reserve_id(), &ALICE); assert_ok!(PredictionMarkets::reject_market(Origin::signed(SUDO), 0)); // AdvisoryBond gets slashed after reject_market // OracleBond gets unreserved after reject_market - let balance_reserved_after_alice = Balances::reserved_balance_named(&RESERVE_ID, &ALICE); + let balance_reserved_after_alice = + Balances::reserved_balance_named(&PredictionMarkets::reserve_id(), &ALICE); assert_eq!( balance_reserved_after_alice, balance_reserved_before_alice @@ -837,9 +911,14 @@ fn on_market_close_auto_rejects_expired_advised_market() { // Give ALICE `SENTINEL_AMOUNT` free and reserved ZTG; we record the free balance to check // that the AdvisoryBond and the OracleBond gets unreserved, when the advised market expires. assert_ok!(AssetManager::deposit(Asset::Ztg, &ALICE, 2 * SENTINEL_AMOUNT)); - assert_ok!(Balances::reserve_named(&RESERVE_ID, &ALICE, SENTINEL_AMOUNT)); + assert_ok!(Balances::reserve_named( + &PredictionMarkets::reserve_id(), + &ALICE, + SENTINEL_AMOUNT + )); let balance_free_before_alice = Balances::free_balance(&ALICE); - let balance_reserved_before_alice = Balances::reserved_balance_named(&RESERVE_ID, &ALICE); + let balance_reserved_before_alice = + Balances::reserved_balance_named(&PredictionMarkets::reserve_id(), &ALICE); let end = 33; simple_create_categorical_market::( @@ -852,7 +931,7 @@ fn on_market_close_auto_rejects_expired_advised_market() { run_to_block(end); assert_eq!( - Balances::reserved_balance_named(&RESERVE_ID, &ALICE), + Balances::reserved_balance_named(&PredictionMarkets::reserve_id(), &ALICE), balance_reserved_before_alice ); assert_eq!(Balances::free_balance(&ALICE), balance_free_before_alice); @@ -2530,7 +2609,11 @@ fn approve_market_correctly_unreserves_advisory_bond() { ScoringRule::CPMM, )); // Reserve a sentinel amount to check that we don't unreserve too much. - assert_ok!(Balances::reserve_named(&RESERVE_ID, &ALICE, SENTINEL_AMOUNT)); + assert_ok!(Balances::reserve_named( + &PredictionMarkets::reserve_id(), + &ALICE, + SENTINEL_AMOUNT + )); let alice_balance_before = Balances::free_balance(&ALICE); assert_eq!( Balances::reserved_balance(&ALICE), @@ -2558,7 +2641,11 @@ fn on_resolution_correctly_reserves_and_unreserves_bonds_for_permissionless_mark ScoringRule::CPMM, )); // Reserve a sentinel amount to check that we don't unreserve too much. - assert_ok!(Balances::reserve_named(&RESERVE_ID, &ALICE, SENTINEL_AMOUNT)); + assert_ok!(Balances::reserve_named( + &PredictionMarkets::reserve_id(), + &ALICE, + SENTINEL_AMOUNT + )); let alice_balance_before = Balances::free_balance(&ALICE); assert_eq!( Balances::reserved_balance(&ALICE), @@ -2693,7 +2780,11 @@ fn on_resolution_correctly_reserves_and_unreserves_bonds_for_permissionless_mark ScoringRule::CPMM, )); // Reserve a sentinel amount to check that we don't unreserve too much. - assert_ok!(Balances::reserve_named(&RESERVE_ID, &ALICE, SENTINEL_AMOUNT)); + assert_ok!(Balances::reserve_named( + &PredictionMarkets::reserve_id(), + &ALICE, + SENTINEL_AMOUNT + )); let alice_balance_before = Balances::free_balance(&ALICE); assert_eq!( Balances::reserved_balance(&ALICE), @@ -2728,7 +2819,11 @@ fn on_resolution_correctly_reserves_and_unreserves_bonds_for_approved_advised_ma ScoringRule::CPMM, )); // Reserve a sentinel amount to check that we don't unreserve too much. - assert_ok!(Balances::reserve_named(&RESERVE_ID, &ALICE, SENTINEL_AMOUNT)); + assert_ok!(Balances::reserve_named( + &PredictionMarkets::reserve_id(), + &ALICE, + SENTINEL_AMOUNT + )); assert_ok!(PredictionMarkets::approve_market(Origin::signed(SUDO), 0)); let alice_balance_before = Balances::free_balance(&ALICE); assert_eq!(Balances::reserved_balance(&ALICE), SENTINEL_AMOUNT + OracleBond::get()); @@ -2761,7 +2856,11 @@ fn on_resolution_correctly_reserves_and_unreserves_bonds_for_approved_advised_ma ScoringRule::CPMM, )); // Reserve a sentinel amount to check that we don't unreserve too much. - assert_ok!(Balances::reserve_named(&RESERVE_ID, &ALICE, SENTINEL_AMOUNT)); + assert_ok!(Balances::reserve_named( + &PredictionMarkets::reserve_id(), + &ALICE, + SENTINEL_AMOUNT + )); assert_ok!(PredictionMarkets::approve_market(Origin::signed(SUDO), 0)); let alice_balance_before = Balances::free_balance(&ALICE); assert_eq!(Balances::reserved_balance(&ALICE), SENTINEL_AMOUNT + OracleBond::get()); diff --git a/zrml/rikiddo/Cargo.toml b/zrml/rikiddo/Cargo.toml index 29d277d6a..27ea1dcc9 100644 --- a/zrml/rikiddo/Cargo.toml +++ b/zrml/rikiddo/Cargo.toml @@ -23,6 +23,7 @@ mock = [ "pallet-balances", "pallet-timestamp", "sp-io", + "zeitgeist-primitives/mock", ] std = [ "frame-support/std", diff --git a/zrml/rikiddo/src/mock.rs b/zrml/rikiddo/src/mock.rs index e743e503d..3b951a497 100644 --- a/zrml/rikiddo/src/mock.rs +++ b/zrml/rikiddo/src/mock.rs @@ -31,7 +31,7 @@ use sp_runtime::{ }; use substrate_fixed::{types::extra::U33, FixedI128, FixedU128}; use zeitgeist_primitives::{ - constants::{BlockHashCount, ExistentialDeposit, MaxReserves, BASE}, + constants::mock::{BlockHashCount, ExistentialDeposit, MaxReserves, BASE}, types::{ AccountIdTest, Balance, BlockNumber, BlockTest, Hash, Index, Moment, PoolId, UncheckedExtrinsicTest, diff --git a/zrml/simple-disputes/Cargo.toml b/zrml/simple-disputes/Cargo.toml index c3b8c2529..1e7eb81f6 100644 --- a/zrml/simple-disputes/Cargo.toml +++ b/zrml/simple-disputes/Cargo.toml @@ -12,6 +12,7 @@ zrml-market-commons = { default-features = false, path = "../market-commons" } pallet-balances = { branch = "moonbeam-polkadot-v0.9.19", git = "https://github.com/purestake/substrate" } sp-io = { branch = "moonbeam-polkadot-v0.9.19", git = "https://github.com/purestake/substrate" } pallet-timestamp = { branch = "moonbeam-polkadot-v0.9.19", git = "https://github.com/purestake/substrate" } +zeitgeist-primitives = { default-features = false, features = ["mock"], path = "../../primitives" } [features] default = ["std"] diff --git a/zrml/simple-disputes/src/mock.rs b/zrml/simple-disputes/src/mock.rs index aa303a36b..3553c5aa9 100644 --- a/zrml/simple-disputes/src/mock.rs +++ b/zrml/simple-disputes/src/mock.rs @@ -24,7 +24,7 @@ use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, }; use zeitgeist_primitives::{ - constants::{BlockHashCount, MaxReserves, MinimumPeriod, SimpleDisputesPalletId}, + constants::mock::{BlockHashCount, MaxReserves, MinimumPeriod, SimpleDisputesPalletId}, types::{ AccountIdTest, Balance, BlockNumber, BlockTest, Hash, Index, MarketId, Moment, UncheckedExtrinsicTest, diff --git a/zrml/styx/Cargo.toml b/zrml/styx/Cargo.toml index e416414fa..3e1520c63 100644 --- a/zrml/styx/Cargo.toml +++ b/zrml/styx/Cargo.toml @@ -2,24 +2,19 @@ frame-benchmarking = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, optional = true, git = "https://github.com/purestake/substrate" } frame-support = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/substrate" } frame-system = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/substrate" } -pallet-balances = { branch = "moonbeam-polkadot-v0.9.19", git = "https://github.com/purestake/substrate", optional = true } -pallet-timestamp = { branch = "moonbeam-polkadot-v0.9.19", git = "https://github.com/purestake/substrate", optional = true } parity-scale-codec = { default-features = false, features = ["derive", "max-encoded-len"], version = "3.0.0" } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-io = { branch = "moonbeam-polkadot-v0.9.19", git = "https://github.com/purestake/substrate", optional = true } sp-runtime = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/substrate" } zeitgeist-primitives = { default-features = false, path = "../../primitives" } [dev-dependencies] -zrml-styx = { features = ["mock"], path = "." } +pallet-balances = { branch = "moonbeam-polkadot-v0.9.19", git = "https://github.com/purestake/substrate" } +pallet-timestamp = { branch = "moonbeam-polkadot-v0.9.19", git = "https://github.com/purestake/substrate" } +sp-io = { branch = "moonbeam-polkadot-v0.9.19", git = "https://github.com/purestake/substrate" } +zeitgeist-primitives = { default-features = false, features = ["mock"], path = "../../primitives" } [features] default = ["std"] -mock = [ - "pallet-balances", - "pallet-timestamp", - "sp-io", -] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", diff --git a/zrml/styx/src/mock.rs b/zrml/styx/src/mock.rs index 109f1b79c..b147fe247 100644 --- a/zrml/styx/src/mock.rs +++ b/zrml/styx/src/mock.rs @@ -25,7 +25,7 @@ use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, }; use zeitgeist_primitives::{ - constants::{BlockHashCount, MaxReserves, BASE}, + constants::mock::{BlockHashCount, MaxReserves, BASE}, types::{AccountIdTest, Balance, BlockNumber, BlockTest, Hash, Index, UncheckedExtrinsicTest}, }; diff --git a/zrml/swaps/Cargo.toml b/zrml/swaps/Cargo.toml index 066e30b1d..4d1c078d0 100644 --- a/zrml/swaps/Cargo.toml +++ b/zrml/swaps/Cargo.toml @@ -36,6 +36,7 @@ mock = [ "pallet-timestamp", "sp-api", "sp-io", + "zeitgeist-primitives/mock", "zrml-swaps-runtime-api", ] runtime-benchmarks = [ diff --git a/zrml/swaps/fuzz/Cargo.toml b/zrml/swaps/fuzz/Cargo.toml index 069540b16..5be51cf57 100644 --- a/zrml/swaps/fuzz/Cargo.toml +++ b/zrml/swaps/fuzz/Cargo.toml @@ -56,7 +56,7 @@ test = false arbitrary = { features = ["derive"], version = "1.0" } libfuzzer-sys = "0.4" zrml-swaps = { features = ["mock"], path = ".." } -zeitgeist-primitives = { path = "../../../primitives" } +zeitgeist-primitives = { features = ["mock"], path = "../../../primitives" } sp-runtime = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/substrate" } frame-support = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/substrate" } orml-traits = { branch = "2022-06-v0.9.19", default-features = false, git = "https://github.com/zeitgeistpm/open-runtime-module-library" } diff --git a/zrml/swaps/fuzz/utils.rs b/zrml/swaps/fuzz/utils.rs index 69828232d..ec6e54171 100644 --- a/zrml/swaps/fuzz/utils.rs +++ b/zrml/swaps/fuzz/utils.rs @@ -21,22 +21,14 @@ clippy::type_complexity, )] -use zeitgeist_primitives::constants::{ - MaxAssets, MaxTotalWeight, MaxWeight, MinAssets, MinLiquidity, MinWeight, BASE, -}; - use arbitrary::{Arbitrary, Result, Unstructured}; - use rand::{rngs::ThreadRng, seq::SliceRandom, Rng}; - -use zeitgeist_primitives::{ - constants::MaxSwapFee, - types::{Asset, ScalarPosition, SerdeWrapper}, -}; - use zeitgeist_primitives::{ + constants::mock::{ + MaxAssets, MaxSwapFee, MaxTotalWeight, MaxWeight, MinAssets, MinLiquidity, MinWeight, BASE, + }, traits::Swaps as SwapsTrait, - types::{PoolId, ScoringRule}, + types::{Asset, PoolId, ScalarPosition, ScoringRule, SerdeWrapper}, }; use zrml_swaps::mock::Swaps; diff --git a/zrml/swaps/src/mock.rs b/zrml/swaps/src/mock.rs index 725c0478d..eb823ff14 100644 --- a/zrml/swaps/src/mock.rs +++ b/zrml/swaps/src/mock.rs @@ -35,7 +35,7 @@ use sp_runtime::{ }; use substrate_fixed::{types::extra::U33, FixedI128, FixedU128}; use zeitgeist_primitives::{ - constants::{ + constants::mock::{ BalanceFractionalDecimals, BlockHashCount, ExistentialDeposit, ExistentialDeposits, GetNativeCurrencyId, LiquidityMiningPalletId, MaxAssets, MaxInRatio, MaxLocks, MaxOutRatio, MaxReserves, MaxSwapFee, MaxTotalWeight, MaxWeight, MinAssets, MinLiquidity, MinSubsidy,