Skip to content

Commit 3d9bbff

Browse files
maltekliemannsea212Chralt98
authored
Implement AMM 2.0-light (#1092)
* Implement neo-swaps * Fix compile issues * Implement `DeployPoolsApi` as noop * Fix formatting * Add missing copyright notices * Fix clippy issues * Fix more clippy issues and rename `balances` to `reserves` * Remove `println!` * Add missing copyright notice * . * Add benchmarking and include `NeoSwaps` in Runtime * Add neo-swaps benchmarks; remove `split` (for now) * Add benchmarks for `create_market_and_deploy_pool` * Properly implement `DeployPool` * Fix benchmarks, remove unnecessary parameter * Fix formatting * Fix dependencies * Add math docs * Fix typo * Make me codeowner of neo-swaps * Add neo-swaps to main README and fix link to PDF * Fix link * Update versions to v0.4.0 (#1098) * Update weights (#1101) * Remove unnecessary comment from toml * Use default features * Bump version * Use checked math in `SoloLp` * Make match expression explicit * Add comment about saturation * Use `MultiCurrency` instead of `ZeitgeistAssetManager` * Apply suggestions from code review Co-authored-by: Harald Heckmann <[email protected]> * Remove superfluous inserts * Fix error documentation * Abstract reserve updates into `Pool` * Make complete set operations require transactional * Make test name not coffee-based * Update zrml/neo-swaps/src/mock.rs Co-authored-by: Harald Heckmann <[email protected]> * Update zrml/neo-swaps/src/mock.rs Co-authored-by: Harald Heckmann <[email protected]> * Reorganize tests * Format * Fix comment * Remove `macros.rs` * Fix benchmarks * Fix formatting * Update benchmark script and add preliminary benchmarks * Update ED buffer handling * Fix documentation * Implement market creation fees for neo-swaps * Use `MarketCreatorFee` in runtime * Add missing files * Add weights * Reduce length of `MarketsCollectingSubsidy` (#1118) * Add bad block of the proof size fiasko to Battery Station chain spec (#1119) Add bad block to Battery Station chain spec * Update weights v0.4.0 (#1121) * Update moonbeam dependencies (bench fix) * Update weights * Fix docs * Rename `IndexType` and change its type value * Remove commented code * Fix order of config parameters * Specify order of assets * Remove commented code * Apply suggestions from code review Co-authored-by: Chralt <[email protected]> * Fix `u16`/`u32` casts * Update zrml/prediction-markets/src/benchmarks.rs Co-authored-by: Chralt <[email protected]> * Update zrml/prediction-markets/src/benchmarks.rs Co-authored-by: Chralt <[email protected]> * Update zrml/neo-swaps/src/math.rs Co-authored-by: Chralt <[email protected]> * Update primitives/src/math/fixed.rs Co-authored-by: Chralt <[email protected]> * Update primitives/src/math/fixed.rs Co-authored-by: Chralt <[email protected]> * Fix formatting * Fix conflicts * Fix dispute period * Format code --------- Co-authored-by: Harald Heckmann <[email protected]> Co-authored-by: Chralt <[email protected]>
1 parent fdda998 commit 3d9bbff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+6720
-130
lines changed

CODEOWNERS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
/zrml/authorized/ @Chralt98
1212
/zrml/court/ @Chralt98
1313
/zrml/global-disputes/ @Chralt98
14+
/zrml/neo-swaps/ @maltekliemann
1415
/zrml/prediction-markets/ @maltekliemann
1516
/zrml/rikiddo/ @sea212
1617
/zrml/simple-disputes/ @Chralt98
@@ -19,4 +20,4 @@
1920

2021
# Skip weight and Cargo.toml files
2122
**/weights.rs
22-
**/Cargo.toml
23+
**/Cargo.toml

Cargo.lock

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ default-members = [
1010
"zrml/global-disputes",
1111
"zrml/liquidity-mining",
1212
"zrml/market-commons",
13+
"zrml/neo-swaps",
1314
"zrml/orderbook-v1",
1415
"zrml/prediction-markets",
1516
"zrml/prediction-markets/runtime-api",
@@ -31,6 +32,7 @@ members = [
3132
"zrml/global-disputes",
3233
"zrml/liquidity-mining",
3334
"zrml/market-commons",
35+
"zrml/neo-swaps",
3436
"zrml/orderbook-v1",
3537
"zrml/orderbook-v1/fuzz",
3638
"zrml/prediction-markets",
@@ -229,6 +231,7 @@ zrml-court = { path = "zrml/court", default-features = false }
229231
zrml-global-disputes = { path = "zrml/global-disputes", default-features = false }
230232
zrml-liquidity-mining = { path = "zrml/liquidity-mining", default-features = false }
231233
zrml-market-commons = { path = "zrml/market-commons", default-features = false }
234+
zrml-neo-swaps = { path = "zrml/neo-swaps", default-features = false }
232235
zrml-orderbook-v1 = { path = "zrml/orderbook-v1", default-features = false }
233236
zrml-prediction-markets = { path = "zrml/prediction-markets", default-features = false }
234237
zrml-prediction-markets-runtime-api = { path = "zrml/prediction-markets/runtime-api", default-features = false }
@@ -250,6 +253,9 @@ url = "2.2.2"
250253
arbitrary = { version = "1.3.0", default-features = false }
251254
arrayvec = { version = "0.7.4", default-features = false }
252255
cfg-if = { version = "1.0.0" }
256+
fixed = { version = "=1.15.0", default-features = false, features = ["num-traits"] }
257+
# Using math code directly from the HydraDX node repository as https://github.com/galacticcouncil/hydradx-math is outdated and has been archived in May 2023.
258+
hydra-dx-math = { git = "https://github.com/galacticcouncil/HydraDX-node", package = "hydra-dx-math", tag = "v18.0.0", default-features = false }
253259
# Hashbrown works in no_std by default and default features are used in Rikiddo
254260
hashbrown = { version = "0.12.3", default-features = true }
255261
hex-literal = { version = "0.3.4", default-features = false }
@@ -258,6 +264,7 @@ num-traits = { version = "0.2.15", default-features = false }
258264
rand = { version = "0.8.5", default-features = false }
259265
rand_chacha = { version = "0.3.1", default-features = false }
260266
serde = { version = "1.0.152", default-features = false }
267+
typenum = { version = "1.15.0", default-features = false }
261268

262269
[profile.dev.package]
263270
blake2 = { opt-level = 3 }

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44

55
# Zeitgeist: An Evolving Blockchain for Prediction Markets and Futarchy
66

7-
![Rust](https://github.com/zeitgeistpm/zeitgeist/workflows/Rust/badge.svg) [![Codecov](https://codecov.io/gh/zeitgeistpm/zeitgeist/branch/main/graph/badge.svg)](https://codecov.io/gh/zeitgeistpm/zeitgeist) [![Discord](https://img.shields.io/badge/discord-https%3A%2F%2Fdiscord.gg%2FMD3TbH3ctv-purple)](https://discord.gg/MD3TbH3ctv) [![Telegram](https://img.shields.io/badge/telegram-https%3A%2F%2Ft.me%2Fzeitgeist__official-blue)](https://t.me/zeitgeist_official)
7+
![Rust](https://github.com/zeitgeistpm/zeitgeist/workflows/Rust/badge.svg)
8+
[![Codecov](https://codecov.io/gh/zeitgeistpm/zeitgeist/branch/main/graph/badge.svg)](https://codecov.io/gh/zeitgeistpm/zeitgeist)
9+
[![Discord](https://img.shields.io/badge/discord-https%3A%2F%2Fdiscord.gg%2FMD3TbH3ctv-purple)](https://discord.gg/MD3TbH3ctv)
10+
[![Telegram](https://img.shields.io/badge/telegram-https%3A%2F%2Ft.me%2Fzeitgeist__official-blue)](https://t.me/zeitgeist_official)
811

912
Zeitgeist is a decentralized network for creating, betting on, and resolving
1013
prediction markets. The platform's native currency, the ZTG, is used to sway the
1114
direction of the network, and as a means of last-call dispute resolution.
1215
Additionally, Zeitgeist is a protocol for efficient trading of prediction market
1316
shares and will one day become the backbone of the decentralized finance
14-
ecosystem by allowing traders to create complex financial contracts on
15-
virtually _anything_.
17+
ecosystem by allowing traders to create complex financial contracts on virtually
18+
_anything_.
1619

1720
## Modules
1821

@@ -27,6 +30,9 @@ virtually _anything_.
2730
liquidity to swap pools.
2831
- [market-commons](./zrml/market-commons) - Contains common operations on
2932
markets that are used by multiple pallets.
33+
- [neo-swaps](./zrml/neo-swaps) - An implementation of the Logarithmic Market
34+
Scoring Rule as constant function market maker, tailor-made for decentralized
35+
combinatorial markets and Futarchy.
3036
- [orderbook-v1](./zrml/orderbook-v1) - A naive orderbook implementation that's
3137
only part of Zeitgeist's PoC. Will be replaced by a v2 orderbook that uses
3238
0x-style hybrid on-chain and off-chain trading.

docs/changelog_for_devs.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,38 @@ As of 0.3.9, the changelog's format is based on
1212
components which query the chain's storage, the extrinsics or the runtime
1313
APIs/RPC interface.
1414

15+
## v0.4.1
16+
17+
### Added
18+
19+
- Implement AMM-2.0-light in the form of zrml-neo-swaps. The new pallet has the
20+
following dispatchables:
21+
22+
- `buy`: Buy outcome tokens from the specified market.
23+
- `sell`: Sell outcome tokens to the specified market.
24+
- `join`: Join the liquidity pool for the specified market.
25+
- `exit`: Exit the liquidity pool for the specified market.
26+
- `withdraw_fees`: Withdraw swap fees from the specified market.
27+
- `deploy_pool`: Deploy a pool for the specified market and provide liquidity.
28+
29+
The new pallet has the following events:
30+
31+
- `BuyExecuted { who, market_id, asset_out, amount_in, amount_out, swap_fee_amount, external_fee_amount }`:
32+
Informant bought a position.
33+
- `SellExecuted { who, market_id, asset_in, amount_in, amount_out, swap_fee_amount, external_fee_amount }`:
34+
Informants sold a position.
35+
- `FeesWithdrawn { who }`: Liquidity provider withdrew fees.
36+
- `JoinExecuted { who, market_id, pool_shares_amount, amounts_in, new_liquidity_parameter }`:
37+
Liquidity provider joined the pool.
38+
- `ExitExecuted { who, market_id, pool_shares_amount, amounts_out, new_liquidity_parameter }`:
39+
Liquidity provider left the pool.
40+
- `PoolDeployed { who, market_id, pool_shares_amount, amounts_in, liquidity_parameter }`:
41+
Pool was created.
42+
- `PoolDestroyed { who, market_id, pool_shares_amount, amounts_out }`: Pool
43+
was destroyed.
44+
45+
For details, please refer to the `README.md` and the in-file documentation.
46+
1547
## v0.4.0
1648

1749
[#976]: https://github.com/zeitgeistpm/zeitgeist/pull/976

primitives/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[dependencies]
22
arbitrary = { workspace = true, optional = true }
3+
fixed = { workspace = true }
34
frame-support = { workspace = true }
45
frame-system = { workspace = true }
56
orml-currencies = { workspace = true }
@@ -13,7 +14,9 @@ sp-core = { workspace = true }
1314
sp-runtime = { workspace = true }
1415

1516
[dev-dependencies]
17+
more-asserts = { workspace = true }
1618
test-case = { workspace = true }
19+
typenum = { workspace = true }
1720

1821
[features]
1922
default = ["std"]

primitives/src/constants.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ pub const BLOCKS_PER_MINUTE: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as Bloc
3737
pub const BLOCKS_PER_HOUR: BlockNumber = BLOCKS_PER_MINUTE * 60; // 300
3838

3939
// Definitions for currency
40-
pub const BASE: u128 = 10_000_000_000;
40+
pub const DECIMALS: u8 = 10;
41+
pub const BASE: u128 = 10u128.pow(DECIMALS as u32);
4142
pub const CENT: Balance = BASE / 100; // 100_000_000
4243
pub const MILLI: Balance = CENT / 10; // 10_000_000
4344
pub const MICRO: Balance = MILLI / 1000; // 10_000
@@ -82,6 +83,9 @@ pub const GLOBAL_DISPUTES_LOCK_ID: [u8; 8] = *b"zge/gdlk";
8283
/// Pallet identifier, mainly used for named balance reserves.
8384
pub const LM_PALLET_ID: PalletId = PalletId(*b"zge/lymg");
8485

86+
// NeoSwaps
87+
pub const NS_PALLET_ID: PalletId = PalletId(*b"zge/neos");
88+
8589
// Prediction Markets
8690
/// The maximum allowed market life time, measured in blocks.
8791
pub const MAX_MARKET_LIFETIME: BlockNumber = 4 * BLOCKS_PER_YEAR;

primitives/src/constants/mock.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ parameter_types! {
7070
pub const LiquidityMiningPalletId: PalletId = PalletId(*b"zge/lymg");
7171
}
7272

73+
// NeoSwaps
74+
parameter_types! {
75+
pub storage NeoExitFee: Balance = CENT;
76+
pub const NeoMaxSwapFee: Balance = 10 * CENT;
77+
pub const NeoSwapsPalletId: PalletId = PalletId(*b"zge/neos");
78+
}
79+
7380
// Prediction Market parameters
7481
parameter_types! {
7582
pub const AdvisoryBond: Balance = 25 * CENT;
@@ -146,11 +153,10 @@ parameter_types! {
146153
}
147154

148155
parameter_type_with_key! {
149-
// Well, not every asset is a currency ¯\_(ツ)_/¯
150156
pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {
151157
match currency_id {
152158
Asset::Ztg => ExistentialDeposit::get(),
153-
_ => 0
159+
_ => 10
154160
}
155161
};
156162
}

primitives/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Copyright 2023 Forecasting Technologies LTD.
12
// Copyright 2021-2022 Zeitgeist PM LLC.
23
//
34
// This file is part of Zeitgeist.
@@ -22,6 +23,7 @@ extern crate alloc;
2223
mod asset;
2324
pub mod constants;
2425
mod market;
26+
pub mod math;
2527
mod max_runtime_usize;
2628
mod outcome_report;
2729
mod pool;

0 commit comments

Comments
 (0)