Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Combinatorial Betting and Futarchy #1364

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ff21a04
Implement Combinatorial Betting (#1354)
maltekliemann Sep 13, 2024
c0a0598
Implement combinatorial betting extrinsics (#1365)
maltekliemann Sep 17, 2024
d45ecf4
Fix compiler and clippy issues (#1366)
maltekliemann Sep 23, 2024
2bd5e6c
Scaffold combo pallet (#1367)
maltekliemann Sep 24, 2024
dcd4921
Implement combinatorial tokens (#1368)
maltekliemann Oct 3, 2024
a04d02e
Implement zrml-combo extrinsics (#1369)
maltekliemann Oct 4, 2024
fba1a07
Replace `halo2curves` and `ethnum` dependency and fix clippy issues (…
maltekliemann Oct 6, 2024
964e651
Add tests for `combinatorial-tokens` (#1371)
maltekliemann Oct 11, 2024
d0a07a5
Refine combinatorial betting (#1372)
maltekliemann Oct 13, 2024
45aeeb8
Update copyright notices (#1373)
maltekliemann Oct 13, 2024
d87ae7c
Fix compiler errors (#1374)
maltekliemann Oct 13, 2024
c4e50d4
Format `Cargo.toml` files (#1375)
maltekliemann Oct 13, 2024
0b0e607
Implement and test numerical limits for combinatorial betting (#1376)
maltekliemann Oct 14, 2024
e586f66
Implement multi-market combinatorial betting tests (#1377)
maltekliemann Oct 14, 2024
27b3db0
Scaffold futarchy pallet (#1378)
maltekliemann Oct 16, 2024
0e0080b
.
maltekliemann Oct 17, 2024
26d5b8a
Implement Scheduler mock
maltekliemann Oct 17, 2024
a2cc42f
.
maltekliemann Oct 17, 2024
afaf92b
wip
maltekliemann Oct 17, 2024
17ab0e0
Implement and test futarchy
maltekliemann Oct 19, 2024
f4d2779
Implement Events
maltekliemann Oct 19, 2024
fcb74fa
Fix futarchy errors (#1380)
maltekliemann Oct 19, 2024
2482bb3
Add missing licenses
maltekliemann Oct 19, 2024
d903a9b
Fix formatting
maltekliemann Oct 19, 2024
b453a7c
Fix toml formatting
maltekliemann Oct 19, 2024
e7b311e
Implement benchmarking
maltekliemann Oct 20, 2024
780704f
Fix clippy errors
maltekliemann Oct 20, 2024
60ab256
.
maltekliemann Oct 20, 2024
0411945
.
maltekliemann Oct 20, 2024
b184434
.
maltekliemann Oct 20, 2024
e93db78
benchmarks work
maltekliemann Oct 20, 2024
c9edaa4
.
maltekliemann Oct 21, 2024
2d339bc
.
maltekliemann Oct 21, 2024
eef4bda
Update copyright notices
maltekliemann Oct 21, 2024
d393cd1
Implement and run Decision Market Oracle Benchmarks (#1381)
maltekliemann Oct 21, 2024
5ba674f
Remove old migrations (#1379) (#1382)
maltekliemann Oct 21, 2024
72aa56d
Implement integration test for zrml-futarchy (#1383)
maltekliemann Oct 21, 2024
dd58dc6
Introduce `PoolId` (#1384)
maltekliemann Oct 22, 2024
f57bf6b
Implement `redeem_position` (#1385)
maltekliemann Oct 22, 2024
3bda745
Implement `Payout` for `PredictionMarkets` (#1386)
maltekliemann Oct 23, 2024
2660096
Benchmark combinatorial-tokens (#1387)
maltekliemann Oct 24, 2024
a56f929
Fix formatting and license notes (#1388)
maltekliemann Oct 24, 2024
84396ca
Implement Combinatorial Pools (#1389)
maltekliemann Oct 30, 2024
6ff1288
Fix formatting
maltekliemann Oct 30, 2024
6055847
Fix coverage
maltekliemann Oct 30, 2024
790906f
Mkl neo swaps benchmarks (#1390)
maltekliemann Oct 30, 2024
93f0663
Add weights of new modules
Nov 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
323 changes: 224 additions & 99 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ default-members = [
"runtime/battery-station",
"runtime/zeitgeist",
"zrml/authorized",
"zrml/combinatorial-tokens",
"zrml/court",
"zrml/futarchy",
"zrml/hybrid-router",
"zrml/global-disputes",
"zrml/market-commons",
Expand All @@ -36,7 +38,9 @@ members = [
"runtime/battery-station",
"runtime/zeitgeist",
"zrml/authorized",
"zrml/combinatorial-tokens",
"zrml/court",
"zrml/futarchy",
"zrml/hybrid-router",
"zrml/global-disputes",
"zrml/market-commons",
Expand Down Expand Up @@ -244,7 +248,9 @@ common-runtime = { path = "runtime/common", default-features = false }
zeitgeist-macros = { path = "macros", default-features = false }
zeitgeist-primitives = { path = "primitives", default-features = false }
zrml-authorized = { path = "zrml/authorized", default-features = false }
zrml-combinatorial-tokens = { path = "zrml/combinatorial-tokens", default-features = false }
zrml-court = { path = "zrml/court", default-features = false }
zrml-futarchy = { path = "zrml/futarchy", default-features = false }
zrml-global-disputes = { path = "zrml/global-disputes", default-features = false }
zrml-hybrid-router = { path = "zrml/hybrid-router", default-features = false }
zrml-market-commons = { path = "zrml/market-commons", default-features = false }
Expand All @@ -264,11 +270,14 @@ futures = "0.3.30"
jsonrpsee = "0.16.3"
libfuzzer-sys = "0.4.7"
more-asserts = "0.3.1"
rstest = "0.23.0"
test-case = "3.3.1"
url = "2.5.0"

# Other (wasm)
arbitrary = { version = "1.3.2", default-features = false }
ark-bn254 = { version = "0.4.0", default-features = false, features = ["curve"] }
ark-ff = { version = "0.4.0", default-features = false }
arrayvec = { version = "0.7.4", default-features = false }
cfg-if = { version = "1.0.0" }
fixed = { version = "=1.15.0", default-features = false, features = ["num-traits"] }
Expand Down
5 changes: 3 additions & 2 deletions primitives/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use crate::traits::ZeitgeistAssetEnumerator;
use crate::{
traits::PoolSharesId,
types::{CategoryIndex, PoolId},
types::{CategoryIndex, CombinatorialId, PoolId},
};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
Expand Down Expand Up @@ -48,13 +48,14 @@ use serde::{Deserialize, Serialize};
pub enum Asset<MarketId> {
CategoricalOutcome(MarketId, CategoryIndex),
ScalarOutcome(MarketId, ScalarPosition),
CombinatorialOutcome,
CombinatorialToken(CombinatorialId),
PoolShare(PoolId),
#[default]
Ztg,
ForeignAsset(u32),
ParimutuelShare(MarketId, CategoryIndex),
}
// TODO Needs storage migration

#[cfg(feature = "runtime-benchmarks")]
impl<MarketId: MaxEncodedLen> ZeitgeistAssetEnumerator<MarketId> for Asset<MarketId> {
Expand Down
4 changes: 4 additions & 0 deletions primitives/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub const BLOCKS_PER_HOUR: BlockNumber = BLOCKS_PER_MINUTE * 60; // 300
// Definitions for currency
pub const DECIMALS: u8 = 10;
pub const BASE: u128 = 10u128.pow(DECIMALS as u32);
pub const DIME: Balance = BASE / 10; // 1_000_000_000
pub const CENT: Balance = BASE / 100; // 100_000_000
pub const MILLI: Balance = CENT / 10; // 10_000_000
pub const MICRO: Balance = MILLI / 1000; // 10_000
Expand Down Expand Up @@ -70,6 +71,9 @@ parameter_types! {
/// Pallet identifier, mainly used for named balance reserves.
pub const AUTHORIZED_PALLET_ID: PalletId = PalletId(*b"zge/atzd");

// Combinatorial Tokens
pub const COMBINATORIAL_TOKENS_PALLET_ID: PalletId = PalletId(*b"zge/coto");

// Court
/// Pallet identifier, mainly used for named balance reserves.
pub const COURT_PALLET_ID: PalletId = PalletId(*b"zge/cout");
Expand Down
6 changes: 6 additions & 0 deletions primitives/src/constants/base_multiples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ pub const _36: u128 = 36 * _1;
pub const _40: u128 = 40 * _1;
pub const _70: u128 = 70 * _1;
pub const _80: u128 = 80 * _1;
pub const _99: u128 = 99 * _1;
pub const _100: u128 = 100 * _1;
pub const _101: u128 = 101 * _1;
pub const _300: u128 = 300 * _1;
pub const _321: u128 = 321 * _1;
pub const _400: u128 = 400 * _1;
pub const _444: u128 = 444 * _1;
pub const _500: u128 = 500 * _1;
pub const _777: u128 = 777 * _1;
Expand All @@ -59,6 +63,8 @@ pub const _1_5: u128 = _1 / 5;
pub const _1_6: u128 = _1 / 6;
pub const _5_6: u128 = _5 / 6;

pub const _1_7: u128 = _1 / 7;

pub const _1_10: u128 = _1 / 10;
pub const _2_10: u128 = _2 / 10;
pub const _3_10: u128 = _3 / 10;
Expand Down
5 changes: 5 additions & 0 deletions primitives/src/constants/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ parameter_types! {
pub const CorrectionPeriod: BlockNumber = 4;
}

// CombinatorialTokens
parameter_types! {
pub const CombinatorialTokensPalletId: PalletId = PalletId(*b"zge/coto");
}

// Court
parameter_types! {
pub const AppealBond: Balance = 5 * BASE;
Expand Down
12 changes: 12 additions & 0 deletions primitives/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,38 @@
// You should have received a copy of the GNU General Public License
// along with Zeitgeist. If not, see <https://www.gnu.org/licenses/>.

mod combinatorial_tokens_api;
mod combinatorial_tokens_benchmark_helper;
mod combinatorial_tokens_unsafe_api;
mod complete_set_operations_api;
mod deploy_pool_api;
mod dispute_api;
mod distribute_fees;
mod futarchy_benchmark_helper;
mod futarchy_oracle;
mod hybrid_router_amm_api;
mod hybrid_router_orderbook_api;
mod market_builder;
mod market_commons_pallet_api;
mod market_id;
mod payout_api;
mod swaps;
mod zeitgeist_asset;

pub use combinatorial_tokens_api::*;
pub use combinatorial_tokens_benchmark_helper::*;
pub use combinatorial_tokens_unsafe_api::*;
pub use complete_set_operations_api::*;
pub use deploy_pool_api::*;
pub use dispute_api::*;
pub use distribute_fees::*;
pub use futarchy_benchmark_helper::*;
pub use futarchy_oracle::*;
pub use hybrid_router_amm_api::*;
pub use hybrid_router_orderbook_api::*;
pub use market_builder::*;
pub use market_commons_pallet_api::*;
pub use market_id::*;
pub use payout_api::*;
pub use swaps::*;
pub use zeitgeist_asset::*;
36 changes: 36 additions & 0 deletions primitives/src/traits/combinatorial_tokens_api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2024 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/>.

use crate::types::SplitPositionDispatchInfo;
use alloc::vec::Vec;
use sp_runtime::DispatchError;

pub trait CombinatorialTokensApi {
type AccountId;
type Balance;
type CombinatorialId;
type MarketId;

fn split_position(
who: Self::AccountId,
parent_collection_id: Option<Self::CombinatorialId>,
market_id: Self::MarketId,
partition: Vec<Vec<bool>>,
amount: Self::Balance,
force_max_work: bool,
) -> Result<SplitPositionDispatchInfo<Self::CombinatorialId, Self::MarketId>, DispatchError>;
}
30 changes: 30 additions & 0 deletions primitives/src/traits/combinatorial_tokens_benchmark_helper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2024 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/>.

use alloc::vec::Vec;
use sp_runtime::DispatchResult;

pub trait CombinatorialTokensBenchmarkHelper {
type Balance;
type MarketId;

/// Prepares the market with the specified `market_id` to have a particular `payout`.
fn setup_payout_vector(
market_id: Self::MarketId,
payout: Option<Vec<Self::Balance>>,
) -> DispatchResult;
}
42 changes: 42 additions & 0 deletions primitives/src/traits/combinatorial_tokens_unsafe_api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2024 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/>.

use crate::types::Asset;
use alloc::vec::Vec;
use sp_runtime::DispatchResult;

// Very fast and very unsafe API for splitting and merging combinatorial tokens. Calling the exposed
// functions with a bad `assets` argument can break the reserve.
pub trait CombinatorialTokensUnsafeApi {
type AccountId;
type Balance;
type MarketId;

fn split_position_unsafe(
who: Self::AccountId,
collateral: Asset<Self::MarketId>,
assets: Vec<Asset<Self::MarketId>>,
amount: Self::Balance,
) -> DispatchResult;

fn merge_position_unsafe(
who: Self::AccountId,
collateral: Asset<Self::MarketId>,
assets: Vec<Asset<Self::MarketId>>,
amount: Self::Balance,
) -> DispatchResult;
}
22 changes: 22 additions & 0 deletions primitives/src/traits/futarchy_benchmark_helper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2024 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/>.

pub trait FutarchyBenchmarkHelper<Oracle> {
/// Creates an oracle which returns `value` when evaluated, provided that state is not modified
/// any further.
fn create_oracle(value: bool) -> Oracle;
}
24 changes: 24 additions & 0 deletions primitives/src/traits/futarchy_oracle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2024 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/>.

use frame_support::pallet_prelude::Weight;

pub trait FutarchyOracle {
/// Evaluates the query at the current block and returns the weight consumed and a `bool`
/// indicating whether the query evaluated positively.
fn evaluate(&self) -> (Weight, bool);
}
25 changes: 25 additions & 0 deletions primitives/src/traits/payout_api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2024 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/>.

use alloc::vec::Vec;

pub trait PayoutApi {
type Balance;
type MarketId;

fn payout_vector(market_id: Self::MarketId) -> Option<Vec<Self::Balance>>;
}
Loading
Loading