Skip to content

Commit

Permalink
Merge branch 'chralt98-remove-market-commons-currency' of github.com:…
Browse files Browse the repository at this point in the history
…zeitgeistpm/zeitgeist into chralt98-remove-market-commons-currency
  • Loading branch information
Chralt98 committed Oct 9, 2023
2 parents 99a486a + 3f9d58c commit 50b0f7d
Show file tree
Hide file tree
Showing 18 changed files with 719 additions and 32 deletions.
18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ default-members = [
"zrml/liquidity-mining",
"zrml/market-commons",
"zrml/orderbook-v1",
"zrml/parimutuel",
"zrml/prediction-markets",
"zrml/prediction-markets/runtime-api",
"zrml/rikiddo",
Expand All @@ -33,6 +34,7 @@ members = [
"zrml/market-commons",
"zrml/orderbook-v1",
"zrml/orderbook-v1/fuzz",
"zrml/parimutuel",
"zrml/prediction-markets",
"zrml/prediction-markets/fuzz",
"zrml/prediction-markets/runtime-api",
Expand Down
17 changes: 14 additions & 3 deletions primitives/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ use crate::types::{CategoryIndex, PoolId, SerdeWrapper};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;

/// The `Outcome` enum represents all types of outcomes available in the Zeitgeist
/// system.
#[cfg_attr(feature = "std", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
#[derive(
Clone, Copy, Debug, Decode, Eq, Encode, MaxEncodedLen, Ord, PartialEq, PartialOrd, TypeInfo,
)]
pub enum Outcome<MarketId: MaxEncodedLen> {
CategoricalOutcome(MarketId, CategoryIndex),
ScalarOutcome(MarketId, ScalarPosition),
}

/// The `Asset` enum represents all types of assets available in the Zeitgeist
/// system.
///
Expand All @@ -43,13 +55,12 @@ use scale_info::TypeInfo;
TypeInfo,
)]
pub enum Asset<MI: MaxEncodedLen> {
CategoricalOutcome(MI, CategoryIndex),
ScalarOutcome(MI, ScalarPosition),
CombinatorialOutcome,
Outcome(Outcome<MI>),
PoolShare(SerdeWrapper<PoolId>),
#[default]
Ztg,
ForeignAsset(u32),
ParimutuelShare(Outcome<MI>),
}

/// In a scalar market, users can either choose a `Long` position,
Expand Down
2 changes: 2 additions & 0 deletions primitives/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
// along with Zeitgeist. If not, see <https://www.gnu.org/licenses/>.

mod dispute_api;
mod distribute_fees;
mod market_commons_pallet_api;
mod market_id;
mod swaps;
mod zeitgeist_multi_reservable_currency;

pub use dispute_api::{DisputeApi, DisputeMaxWeightApi, DisputeResolutionApi};
pub use distribute_fees::DistributeFees;
pub use market_commons_pallet_api::MarketCommonsPalletApi;
pub use market_id::MarketId;
pub use swaps::Swaps;
Expand Down
43 changes: 43 additions & 0 deletions primitives/src/traits/distribute_fees.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2023 Forecasting Technologies LTD.
//
// 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 <https://www.gnu.org/licenses/>.

/// Trait for distributing fees collected from trading to external recipients like the treasury.
pub trait DistributeFees {
type Asset;
type AccountId;
type Balance;
type MarketId;

/// Deduct and distribute the swap fees of the pool from the specified amount and returns the
/// deducted fees.
///
/// # Arguments
///
/// - `market_id`: The market on which the fees are taken.
/// - `asset`: The asset the fee is paid in.
/// - `account`: The account which pays the fees.
/// - `amount`: The gross amount from which fees are deducted.
///
/// Note that this function is infallible. If distribution is impossible or fails midway, it
/// should return the balance of the already successfully deducted fees.
fn distribute(
market_id: Self::MarketId,
asset: Self::Asset,
account: Self::AccountId,
amount: Self::Balance,
) -> Self::Balance;
}
7 changes: 4 additions & 3 deletions runtime/battery-station/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,9 @@ parameter_type_with_key! {
// Explicit match arms are used to ensure new asset types are respected.
pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {
match currency_id {
Asset::CategoricalOutcome(_,_) => ExistentialDeposit::get(),
Asset::CombinatorialOutcome => ExistentialDeposit::get(),
Asset::Outcome(zeitgeist_primitives::types::Outcome::CategoricalOutcome(_,_)) => ExistentialDeposit::get(),
Asset::Outcome(zeitgeist_primitives::types::Outcome::ScalarOutcome(_,_)) => ExistentialDeposit::get(),
Asset::PoolShare(_) => ExistentialDeposit::get(),
Asset::ScalarOutcome(_,_) => ExistentialDeposit::get(),
#[cfg(feature = "parachain")]
Asset::ForeignAsset(id) => {
let maybe_metadata = <
Expand All @@ -462,6 +461,8 @@ parameter_type_with_key! {
#[cfg(not(feature = "parachain"))]
Asset::ForeignAsset(_) => ExistentialDeposit::get(),
Asset::Ztg => ExistentialDeposit::get(),
Asset::ParimutuelShare(zeitgeist_primitives::types::Outcome::CategoricalOutcome(_, _)) => 2 * ExistentialDeposit::get(),
Asset::ParimutuelShare(zeitgeist_primitives::types::Outcome::ScalarOutcome(_, _)) => 2 * ExistentialDeposit::get(),
}
};
}
Expand Down
7 changes: 4 additions & 3 deletions runtime/zeitgeist/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,9 @@ parameter_type_with_key! {
// Explicit match arms are used to ensure new asset types are respected.
pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {
match currency_id {
Asset::CategoricalOutcome(_,_) => ExistentialDeposit::get(),
Asset::CombinatorialOutcome => ExistentialDeposit::get(),
Asset::Outcome(zeitgeist_primitives::types::Outcome::CategoricalOutcome(_,_)) => ExistentialDeposit::get(),
Asset::Outcome(zeitgeist_primitives::types::Outcome::ScalarOutcome(_,_)) => ExistentialDeposit::get(),
Asset::PoolShare(_) => ExistentialDeposit::get(),
Asset::ScalarOutcome(_,_) => ExistentialDeposit::get(),
#[cfg(feature = "parachain")]
Asset::ForeignAsset(id) => {
let maybe_metadata = <
Expand All @@ -462,6 +461,8 @@ parameter_type_with_key! {
#[cfg(not(feature = "parachain"))]
Asset::ForeignAsset(_) => ExistentialDeposit::get(),
Asset::Ztg => ExistentialDeposit::get(),
Asset::ParimutuelShare(zeitgeist_primitives::types::Outcome::CategoricalOutcome(_,_)) => 2 * ExistentialDeposit::get(),
Asset::ParimutuelShare(zeitgeist_primitives::types::Outcome::ScalarOutcome(_,_)) => 2 * ExistentialDeposit::get(),
}
};
}
Expand Down
8 changes: 4 additions & 4 deletions zrml/orderbook-v1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use sp_runtime::{
};
use zeitgeist_primitives::{
traits::MarketCommonsPalletApi,
types::{Asset, Market, MarketStatus, MarketType, ScalarPosition, ScoringRule},
types::{Asset, Market, MarketStatus, MarketType, Outcome, ScalarPosition, ScoringRule},
};

#[cfg(feature = "runtime-benchmarks")]
Expand Down Expand Up @@ -441,14 +441,14 @@ mod pallet {
MarketType::Categorical(categories) => {
let mut assets = Vec::new();
for i in 0..categories {
assets.push(Asset::CategoricalOutcome(market_id, i));
assets.push(Asset::Outcome(Outcome::CategoricalOutcome(market_id, i)));
}
assets
}
MarketType::Scalar(_) => {
vec![
Asset::ScalarOutcome(market_id, ScalarPosition::Long),
Asset::ScalarOutcome(market_id, ScalarPosition::Short),
Asset::Outcome(Outcome::ScalarOutcome(market_id, ScalarPosition::Long)),
Asset::Outcome(Outcome::ScalarOutcome(market_id, ScalarPosition::Short)),
]
}
}
Expand Down
42 changes: 42 additions & 0 deletions zrml/parimutuel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[dependencies]
frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-system = { 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 }
orml-traits = { workspace = true }

[dev-dependencies]
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 <[email protected]>"]
edition = "2021"
name = "zrml-parimutuel"
version = "0.3.11"
1 change: 1 addition & 0 deletions zrml/parimutuel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Authorized Module
56 changes: 56 additions & 0 deletions zrml/parimutuel/src/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2022-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 <https://www.gnu.org/licenses/>.

#![allow(
// Auto-generated code is a no man's land
clippy::arithmetic_side_effects
)]
#![cfg(feature = "runtime-benchmarks")]

use crate::{
market_mock, AuthorizedOutcomeReports, Call, Config, NegativeImbalanceOf, Pallet as Authorized,
Pallet as Parimutuel,
};
use frame_benchmarking::v2::*;
use frame_support::{
dispatch::UnfilteredDispatchable,
traits::{EnsureOrigin, Get, Imbalance},
};
use sp_runtime::traits::Saturating;
use zeitgeist_primitives::{
traits::{DisputeApi, DisputeResolutionApi},
types::{AuthorityReport, OutcomeReport},
};
use zrml_market_commons::MarketCommonsPalletApi;

#[benchmarks]
mod benchmarks {
use super::*;

#[benchmark]
fn buy() {}

#[benchmark]
fn claim_reward() {}

impl_benchmark_test_suite!(
Parimutuel,
crate::mock::ExtBuilder::default().build(),
crate::mock::Runtime
);
}
Loading

0 comments on commit 50b0f7d

Please sign in to comment.