Skip to content

Commit

Permalink
Implement Combinatorial Betting and Futarchy (#1364)
Browse files Browse the repository at this point in the history
* Implement Combinatorial Betting (#1354)

* Revert "New Asset System (#1295)" (#1338)

* Revert "New Asset System (#1295)"

This reverts commit a956877.

* Fix formatting

* Update copyright

* Remove pallet-assets dependency

* Fix fuzz tests

* Merge `main` into `develop` (#1345)

* Update dependencies to Polkadot v1.1.0 (#1331)

* Update dependencies (#1319)

* Update dependencies to polkadot-v1.1.0

* Format code

* Remove duplicate dependencies

* Update zrml-asset-router (#1321)

* Update zrml-primitives

* Partially update asset-router

* Finalize logic adjustments in asset-router

* Make asset-router tests compilable

* Correct Inspect routing for market assets in Currencies

* Directly invoke Inspect API for Currencies

* Add tests for remaining Unbalances functions

* Update remaining Zeitgeist pallets (#1322)

* Update zrml-asset-router (#1321)

* Upgrade zrml-market-commons

* Upgrade zrml-authorized && use MockBlock instead of MockBlockU32

* Upgrade zrml-court

* Upgrade zrml-global-disputes

* Upgrade liquidity mining

* Upgrade zrml-rikiddo

* Upgrade zrml-simple-disputes

* Upgrade zrml-styx

* Upgrade zrml-orderbook

* Upgrade zrml-parimutuel

* Upgrade zrml-swaps

* Upgrade zrml-prediction-markets

* Upgrade zrml-neo-swaps

* Upgrade zrml-hybrid-router

* Update license headers

* Update runtime (#1323)

* Update weight files & Runtime enum

* Use workspace metadata

* Always use serde serialization for asset types

* Make battery station standalone runtime compilable

* Make benchmark and try-runtime feature compilable

* Make BS build with all features

* Make parachain tests compile

* Partially fix xcm tests

* Use safe xcm version 2

* Update Zeitgeist runtime (except xcm tests)

* Format code

* Remove deprecated comment

* Integrate new xcm-emulator (#1324)

* Integrate new xcm-emulator environment

* Utilize new xcm-emulator interfaces

* Spawn relay-para network using patched xcm-emulator

* Use proper collator genesis config

* Fix Rococo tests

* Finalize Battery Station XCM tests

* Finalize Zeitgeist XCM tests

* Update client (#1327)

* Fix rpc and work on client update

* Finalize standalone client

* Update parachain client

* Use same try-runtime subcommand in every case

* Update node/src/cli.rs

Co-authored-by: Malte Kliemann <mail@maltekliemann.com>

* Update try-runtime* Makefile targets

---------

Co-authored-by: Malte Kliemann <mail@maltekliemann.com>

* Make CI succeed and add migrations (#1329)

* Fix rpc and work on client update

* Finalize standalone client

* Update parachain client

* Use same try-runtime subcommand in every case

* Satisfy Clippy

* Fix benchmarks

* Add migrations

* Satisfy Clippy

* Update moonkit depedencies

* Free disk space more aggressively

---------

Co-authored-by: Malte Kliemann <mail@maltekliemann.com>

* Update spec version, try-runtime Makefile

* Fix copyright notices

* Fix broken chain state (#1336)

* Add `StorageVersion` fix and contrats fix migrations

* Don't set pallet-balances' storage version

* Remove migrations from pallet-contracts config

* Clear storage tries of contracts

* Fix migration and info logs in try-runtime

* Fix licenses and comments

* Fix formatting

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

---------

Co-authored-by: Harald Heckmann <mail@haraldheckmann.de>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

* Merge

* Fix benchmark

* Fix compiler error

* Fix tests and imports

* Fix imports (again...)

* Fix orderbook benchmarks

* Fix fuzz tests

* Fix formatting

* Fix orderbook fuzz

---------

Co-authored-by: Harald Heckmann <mail@haraldheckmann.de>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

* Update versions to v0.5.3

* Restructure math module

* More scaffolding

* Implement combinatorial buy math

* Implement price calculation for combo

* Remove `println!`

* Implement equalization

* Implement selling

* Add tests for combinatorial buying

* Add more tests for combinatorial buying

* Add tests for equalization

* Add more tests/corner cases

* Implement full testing, fix critical bug

---------

Co-authored-by: Harald Heckmann <mail@haraldheckmann.de>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

* Implement combinatorial betting extrinsics (#1365)

* Implement classical buying using combinatorial buys

* Calculate classical sells with combinatorial math

* Implement `combo_buy`

* Implement `combo_sell`

* Fix compiler and clippy issues (#1366)

* Fix compiler and clippy issues

* Fix formatting

* Fix tests

* Scaffold combo pallet (#1367)

* Scaffold combo pallet

* Fix dependencies/features

* Implement combinatorial tokens (#1368)

* More scaffolding

* Add `IdManager` trait

* Scaffold ID manager

* Use generics

* WIP

* Rough outline of `CryptographicIdManager` implementation

* Improve `MaybeToBytes` implementation for `bool`

* Implement pseudo-root

* Add more tests

* Implement `quadratic_residue` and add tests

* Partial implementation of decompression algorithm

* Loads of cleaning up

* Refactor

* Clean up `hash_pair`

* Simplify interface

* Simplify serialization

* More cleanup

* Clean up and tests

* Better `ToBytes` implementation

* Abstract `decompressor` tests

* Reorganize tests

* Minor clean up

* More clean up

* Test `get_collection_id`, fix bugs

* Clean up

* Expose `force_max_work` parameter and test it properly

* Properly forget dummies

* Add more tests

* Fix some error handling, docs, and add missing tests

* Prettify

* Implement zrml-combo extrinsics (#1369)

* Extend `Config`

* wip

* Some refactors

* Implement splitting tokens

* Implement merging tokens

* Replace `halo2curves` and `ethnum` dependency and fix clippy issues (#1370)

* .

* Use `core::hint`

* Replace `halo2curves` dependency with `ark-*` dependency

* Fix clippy issues

* Fix formatting

* Add tests for `combinatorial-tokens` (#1371)

* Add mock for zrml-combinatorial-tokens

* Add test framework

* Add negative tests for `split_token`

* Add more tests, fix some bugs, extend `Event` object

* Add more tests

* Add more integration tests

* Add more integration tests

* Add more integration tests

* More tests

* Add merge tests

* final tests

* fixes

* Refine combinatorial betting (#1372)

* Add numerical thresholds to combinatorial betting

* Add protected `exp` for normal bets

* Ensure correctness of partitions

* Check partitions

* Update copyright notices (#1373)

* Add licenses

* Add remark about LGPL-3.0 licensing by Gnosis

* Fix compiler errors (#1374)

* Fix formatting

* Fix mess with copyright notices

* Format `Cargo.toml` files (#1375)

* Implement and test numerical limits for combinatorial betting (#1376)

* Add numerical limits and tests

* Add missing license

* Implement multi-market combinatorial betting tests (#1377)

* .

* Add more tests

* .

* Detailed testing

* .

* Add tests for `InvalidAmountKeep`

* Clippy fixes

* Scaffold futarchy pallet (#1378)

* Scaffold futarchy pallet

* Scaffold test suite

* .

* .

* .

* Implement Scheduler mock

* .

* wip

* Implement and test futarchy

* Implement Events

* Fix futarchy errors (#1380)

* Fix clippy errors

* Move `FutarchyOracle` to primitives

* Implement `FutarchyOracle` for neo-swaps

* Add missing licenses

* Fix formatting

* Fix toml formatting

* Implement benchmarking

* Fix clippy errors

* .

* .

* .

* benchmarks work

* .

* .

* Update copyright notices

* Implement and run Decision Market Oracle Benchmarks (#1381)

* Add benchmark for the decision market oracle

* Add benchmarks to `DecisionMarketOracle` calls

* Fix clippy errors

* Remove old migrations (#1379) (#1382)

* Remove old migrations

* Update licenses

* Implement integration test for zrml-futarchy (#1383)

* Implement integration test for zrml-futarchy

* Fix test

* Introduce `PoolId` (#1384)

* Implement `redeem_position` (#1385)

* Add `PayoutApi` and the corresponding mock

* Implement redeeming tokens

* Add tests for `redeem_position`

* Test `redeem_position` and dummy implement `Payout`

* Implement `Payout` for `PredictionMarkets` (#1386)

* Fix copyright and formatting

* Implement `payout_vector` and test

* Fix copyright

* Benchmark combinatorial-tokens (#1387)

* Expose benchmarking parameter

* Add security notes to code

* Update and test `TokenMerged` event

* Implement `TokenRedeemed` event

* Test `TokenRedeemed` event

* Add `CombinatorialTokensBenchmarkHelper`

* Implement `redeem_position` benchmark

* Implement first benchmarks, prediction markets benchmark helper

* Clear up errors

* Include benchmarks

* Extend tests

* Implement more benchmarks

* .

* .

* Use weight in `redeem_position`

* .

* .

* .

* First split bench

* Horizontal splits benchmarked

* .

* .

* .

* Fix formatting and license notes (#1388)

* Fix formatting

* Fix copyright

* Implement Combinatorial Pools (#1389)

* Define and implement `CombinatorialTokensApi`

* Abstract position calculation

* Implement `CombinatorialTokensUnsafeApi::combinatorial_position`

* Add `CombinatorialTokens*Api` to `neo-swaps`

* Fix formatting

* Add copyright notices

* .

* .

* Implement `deploy_combinatorial_pool`

* Replace `market_id` with `pool_id` where appropriate

* pool storage

* .

* Implement `PoolType`

* Use `PoolOperations::is_active`

* Use market ID for complete set operations

* Use PoolId more

* Rewrite `distribute_fees` to make use of all markets

* .

* Fix duplicate pool problem / adapter

* .

* Fix sell tests

* Fix really annoying problem

* clean up tests

* .

* .

* Update copyright

* Fix tests

* Fix formatting

* Fix coverage

* Mkl neo swaps benchmarks (#1390)

* clean up TODO

* First benchmark

* .

* .

* .

* Sceond bench

* Use weights

* Use asset_count in deploy_combinatorial_pool

* .

* .

* Use weights

* Add weights of new modules

* Add storage migrations for Combinatorial Tokens Upgrade (#1401)

* add todos for storage migrations

* remove todo for asset storage migration

* add storage migration and try-runtime tests

* correct migration and tests

* update todos

* update migration tests

* add migration to runtime, fix clippy

* bump storage version

* remove corrupted pools

* correct clippy

* correct CI

* Audit fixes (#1395)

* (Issue No 1)

- Clarify `ComboMath` documentation
- Make test `combo_buy_fails_on_amount_out_below_min` more precise

* Fix `log_ceil` and add extensive tests

* (Issue No 7) Enable overflow checks

* (Issue No 9) Fix incorrect test

* (Issue No 10) Resolve FIXMEs

- Won't fix FIXME asking for better error messages
- Solve FIXME in neo-swaps by adding `try_mutate_exists` to
  `PoolStorage`

* Fix formatting

* (Issue No 13) Remove TODO by avoiding a migration

* (Issue No 13) Remove TODO by keeping low-level types

* (Issue No 13) Remove TODO by keeping low-level types

* (Issue No 13) Remove already fixed TODO

* (Issue No 13) Remove won't fix TODOs

* (Issue No 13) Remove more TODOs, some by implementing `CheckedIncRes`

* (Issue No 13) Remove code quality TODO

* (Issue No 14) Define `SCHEDULE_PRIORITY`

* (Issue No 14) Increase readability

* (Issue No 14) Reuse `r_over_b`

* (Issue No 14) Add clarifying comments

* (Issue No 14) Abstract common math code away

* Add missing file

* (Issue No 2) Replace `force_max_work` with `fuel` parameter

* (Issue 6) Replace `SubmitOrigin` with root

* (Issue Nos. 5 & 6) Squashed commit of the following:

commit 4517504
Author: Malte Kliemann <mail@maltekliemann.com>
Date:   Tue Dec 10 18:51:24 2024 +0100

    Benchmark `DecisionMarketOracle`

commit 5832f0b
Author: Malte Kliemann <mail@maltekliemann.com>
Date:   Tue Dec 10 16:55:48 2024 +0100

    Implement `DecisionMarketOracle` using scoreboard

commit e684d47
Author: Malte Kliemann <mail@maltekliemann.com>
Date:   Mon Dec 9 21:24:47 2024 +0100

    Add `BlockNumber` parameter to `update`

commit 5f51378
Author: Malte Kliemann <mail@maltekliemann.com>
Date:   Mon Dec 9 21:17:20 2024 +0100

    Update oracles on each block

commit 2b831fb
Author: Malte Kliemann <mail@maltekliemann.com>
Date:   Mon Dec 9 20:40:26 2024 +0100

    Implement `try_mutate_all`

commit 59cb185
Author: Malte Kliemann <mail@maltekliemann.com>
Date:   Mon Dec 9 18:24:56 2024 +0100

    Use `ProposalStorage` and `MaxProposals`

commit 58afe87
Author: Malte Kliemann <mail@maltekliemann.com>
Date:   Mon Dec 9 17:56:53 2024 +0100

    Add `MaxProposals` value

commit 22068d8
Author: Malte Kliemann <mail@maltekliemann.com>
Date:   Mon Dec 9 14:15:33 2024 +0100

    Add `update` function to `FutarchyOracle` trait

* Fix audit decompressor security miscellaneous comments (#1402)

* Update arkworks-rs dependencies

* Extend get_collection_id comment

* Distinguish collection id generation error

* Use immutable transformations

* fmt

* Update copyrights

* Use retrieval instead of generation for collection id error

* Fix misprint

* fix clippy

* Merge oracles into audit fixes (#1399)

* Add `update` function to `FutarchyOracle` trait

* Add `MaxProposals` value

* Use `ProposalStorage` and `MaxProposals`

* Implement `try_mutate_all`

* Update oracles on each block

* Add `BlockNumber` parameter to `update`

* Implement `DecisionMarketOracle` using scoreboard

* Benchmark `DecisionMarketOracle`

---------

Co-authored-by: Chralt <chralt.developer@gmail.com>

* Add docs (#1391)

* Add some docs and remove TODOs

* More documentation

* .

* update docs to use fuel parameter

* Update zrml/combinatorial-tokens/README.md

* Update zrml/combinatorial-tokens/README.md

* fix comment

* add decision market oracle scoreboard to futarchy module doc

* update decision market oracle doc to include scoreboard

* add fuel parameter doc to complexity of deploy combinatorial pool

* correct the futarchy module documentation to use root origin for proposal

---------

Co-authored-by: Chralt98 <chralt98@gmail.com>
Co-authored-by: Chralt <chralt.developer@gmail.com>

* Add fuzz tests for combinatorial tokens, pool and futarchy (#1392)

* Implement fuzz tests for futarchy

* Minor fixes

* add first fuzz test for combo tokens

* Add test to script

* Add fuzz test for merge position

* .

* Add redeem fuzz test

* Add combinatorial pool fuzz tests

* Add neo-swaps fuzz to script

* combo buy

* Minor fixes, add to script

* Add combo sell

* use fuel parameter for fuzz tests

---------

Co-authored-by: Chralt98 <chralt98@gmail.com>

* update comments in neo-swaps

* remove duplicated numerical limits check

* correct comments in split_position.rs

* fix comments in merge_position

* correct redeem_position test function name

* use HARD_DEADLINE scheduler priority

* fix futarchy benchmarks and fmt

* add comments for combo buy

* correct combo buy test

* rename test function

* add test comment

* add test comment

* correct neo-swaps benchmark

* add reminder from the documentation

* update gnosis doc references

* update gnosis doc reference

* update copyrights

* fix copyrights

* taplo fmt

* fix neo-swaps benchmarks after existential deposit bump

* fix deploy combinatorial pool benchmark

* fix decision market oracle benchmarks

---------

Co-authored-by: Harald Heckmann <mail@haraldheckmann.de>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Your Name <you@example.com>
Co-authored-by: Chralt <chralt.developer@gmail.com>
Co-authored-by: Chralt98 <chralt98@gmail.com>
  • Loading branch information
6 people authored Feb 25, 2025
1 parent 120f528 commit 5698d45
Show file tree
Hide file tree
Showing 143 changed files with 17,137 additions and 774 deletions.
696 changes: 526 additions & 170 deletions Cargo.lock

Large diffs are not rendered by default.

32 changes: 32 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,11 +38,16 @@ members = [
"runtime/battery-station",
"runtime/zeitgeist",
"zrml/authorized",
"zrml/combinatorial-tokens",
"zrml/combinatorial-tokens/fuzz",
"zrml/court",
"zrml/futarchy",
"zrml/futarchy/fuzz",
"zrml/hybrid-router",
"zrml/global-disputes",
"zrml/market-commons",
"zrml/neo-swaps",
"zrml/neo-swaps/fuzz",
"zrml/orderbook",
"zrml/orderbook/fuzz",
"zrml/parimutuel",
Expand Down Expand Up @@ -244,7 +251,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 +273,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.5.0", default-features = false, features = ["curve"] }
ark-ff = { version = "0.5.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 All @@ -282,6 +294,15 @@ rand_chacha = { version = "0.3.1", default-features = false }
serde = { version = "1.0.198", default-features = false }
typenum = { version = "1.17.0", default-features = false }

[profile.test]
overflow-checks = true

[profile.test.package."*"]
overflow-checks = true

[profile.dev]
overflow-checks = true

[profile.dev.package]
blake2 = { opt-level = 3 }
blake2b_simd = { opt-level = 3 }
Expand Down Expand Up @@ -327,17 +348,28 @@ x25519-dalek = { opt-level = 3 }
yamux = { opt-level = 3 }
zeroize = { opt-level = 3 }

[profile.dev.package."*"]
overflow-checks = true

[profile.production]
codegen-units = 1
incremental = false
inherits = "release"
lto = true
overflow-checks = true

[profile.production.package."*"]
overflow-checks = true

[profile.release]
opt-level = 3
overflow-checks = true
# Zeitgeist runtime requires unwinding.
panic = "unwind"

[profile.release.package."*"]
overflow-checks = true


# xcm-emulator incompatible block number type fixed
# Commits:
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ decentralized court.
## Modules

- [authorized](./zrml/authorized) - Offers authorized resolution of disputes.
- [combinatorial-tokens](./zrml/combinatorial-tokens) - The module responsible
for generating Zeitgeist 2.0 outcome tokens.
- [court](./zrml/court) - An implementation of a court mechanism used to resolve
disputes in a decentralized fashion.
- [futarchy](./zrml/futarchy) - A novel on-chain governance mechanism using
prediction markets.
- [global-disputes](./zrml-global-disputes) - Global disputes sets one out of
multiple outcomes with the most locked ZTG tokens as the canonical outcome.
This is the default process if a dispute mechanism fails to resolve.
Expand Down
7 changes: 4 additions & 3 deletions primitives/src/asset.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-2024 Forecasting Technologies LTD.
// Copyright 2022-2025 Forecasting Technologies LTD.
// Copyright 2021-2022 Zeitgeist PM LLC.
//
// This file is part of Zeitgeist.
Expand All @@ -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,12 +48,13 @@ use serde::{Deserialize, Serialize};
pub enum Asset<MarketId> {
CategoricalOutcome(MarketId, CategoryIndex),
ScalarOutcome(MarketId, ScalarPosition),
CombinatorialOutcome,
CombinatorialOutcomeLegacy, // Here to avoid having to migrate all holdings on the chain.
PoolShare(PoolId),
#[default]
Ztg,
ForeignAsset(u32),
ParimutuelShare(MarketId, CategoryIndex),
CombinatorialToken(CombinatorialId),
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down
6 changes: 5 additions & 1 deletion primitives/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-2024 Forecasting Technologies LTD.
// Copyright 2022-2025 Forecasting Technologies LTD.
// Copyright 2021-2022 Zeitgeist PM LLC.
//
// This file is part of Zeitgeist.
Expand Down 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
8 changes: 7 additions & 1 deletion primitives/src/constants/base_multiples.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Forecasting Technologies LTD.
// Copyright 2024-2025 Forecasting Technologies LTD.
//
// This file is part of Zeitgeist.
//
Expand Down Expand Up @@ -39,9 +39,13 @@ 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 _200: u128 = 200 * _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 @@ -60,6 +64,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
7 changes: 6 additions & 1 deletion primitives/src/constants/mock.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-2024 Forecasting Technologies LTD.
// Copyright 2022-2025 Forecasting Technologies LTD.
// Copyright 2022 Zeitgeist PM LLC.
//
// This file is part of Zeitgeist.
Expand Down 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
19 changes: 18 additions & 1 deletion primitives/src/math/checked_ops_res.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023-2024 Forecasting Technologies LTD.
// Copyright 2023-2025 Forecasting Technologies LTD.
//
// This file is part of Zeitgeist.
//
Expand Down Expand Up @@ -64,6 +64,13 @@ where
fn checked_rem_res(&self, other: &Self) -> Result<Self, DispatchError>;
}

pub trait CheckedIncRes
where
Self: Sized,
{
fn checked_inc_res(&self) -> Result<Self, DispatchError>;
}

impl<T> CheckedAddRes for T
where
T: CheckedAdd,
Expand Down Expand Up @@ -123,3 +130,13 @@ where
self.checked_rem(other).ok_or(DispatchError::Arithmetic(ArithmeticError::DivisionByZero))
}
}

impl<T> CheckedIncRes for T
where
T: CheckedAdd + From<u8>,
{
#[inline]
fn checked_inc_res(&self) -> Result<Self, DispatchError> {
self.checked_add(&1u8.into()).ok_or(DispatchError::Arithmetic(ArithmeticError::Overflow))
}
}
16 changes: 15 additions & 1 deletion primitives/src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-2024 Forecasting Technologies LTD.
// Copyright 2022-2025 Forecasting Technologies LTD.
// Copyright 2021-2022 Zeitgeist PM LLC.
//
// This file is part of Zeitgeist.
Expand All @@ -16,26 +16,40 @@
// 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_fuel;
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_fuel::*;
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::*;
42 changes: 42 additions & 0 deletions primitives/src/traits/combinatorial_tokens_api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2024-2025 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::{traits::CombinatorialTokensFuel, types::SplitPositionDispatchInfo};
use alloc::vec::Vec;
use core::fmt::Debug;
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_runtime::DispatchError;

/// Trait that can be used to expose the internal functionality of zrml-combinatorial-tokens to
/// other pallets.
pub trait CombinatorialTokensApi {
type AccountId;
type Balance;
type CombinatorialId;
type MarketId;
type Fuel: Clone + CombinatorialTokensFuel + Debug + Decode + Encode + Eq + TypeInfo;

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: Self::Fuel,
) -> Result<SplitPositionDispatchInfo<Self::CombinatorialId, Self::MarketId>, DispatchError>;
}
32 changes: 32 additions & 0 deletions primitives/src/traits/combinatorial_tokens_benchmark_helper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2024-2025 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;

/// Trait used for setting up benchmarks of zrml-combinatorial-tokens. Must not be used in
/// production.
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;
}
27 changes: 27 additions & 0 deletions primitives/src/traits/combinatorial_tokens_fuel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2024-2025 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/>.

/// A trait for keeping track of a certain amount of work to be done.
pub trait CombinatorialTokensFuel {
/// Creates a `Fuel` object from a `total` value which indicates the total amount of work to be
/// done. This is usually done for benchmarking purposes.
fn from_total(total: u32) -> Self;

/// Returns a `u32` which indicates the total amount of work to be done. Must be `O(1)` to avoid
/// excessive calculation if this call is used when calculating extrinsic weight.
fn total(&self) -> u32;
}
Loading

0 comments on commit 5698d45

Please sign in to comment.