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 AMM 2.0-light #1092

Merged
merged 81 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
249eb33
Implement neo-swaps
maltekliemann Sep 4, 2023
5f55298
Fix compile issues
maltekliemann Sep 5, 2023
85252b0
Implement `DeployPoolsApi` as noop
maltekliemann Sep 5, 2023
61bacd4
Fix formatting
maltekliemann Sep 5, 2023
fdabb40
Add missing copyright notices
maltekliemann Sep 5, 2023
b14373b
Fix clippy issues
maltekliemann Sep 5, 2023
29b20e5
Fix more clippy issues and rename `balances` to `reserves`
maltekliemann Sep 5, 2023
e5b73fd
Remove `println!`
maltekliemann Sep 5, 2023
f0586d3
Add missing copyright notice
maltekliemann Sep 5, 2023
ac4eec2
.
maltekliemann Sep 6, 2023
7b6129e
Add benchmarking and include `NeoSwaps` in Runtime
maltekliemann Sep 6, 2023
e279746
Add neo-swaps benchmarks; remove `split` (for now)
maltekliemann Sep 6, 2023
6585807
Add benchmarks for `create_market_and_deploy_pool`
maltekliemann Sep 7, 2023
5c7a1a5
Properly implement `DeployPool`
maltekliemann Sep 7, 2023
a8ccf91
Fix benchmarks, remove unnecessary parameter
maltekliemann Sep 7, 2023
7419b6a
Fix formatting
maltekliemann Sep 7, 2023
7f40343
Fix dependencies
maltekliemann Sep 7, 2023
f4a0d99
Add math docs
maltekliemann Sep 8, 2023
3aaf3b7
Fix typo
maltekliemann Sep 8, 2023
e9e34ca
Make me codeowner of neo-swaps
maltekliemann Sep 8, 2023
744c3b5
Add neo-swaps to main README and fix link to PDF
maltekliemann Sep 8, 2023
ffdbd84
Fix link
maltekliemann Sep 8, 2023
1fbf3d5
Update versions to v0.4.0 (#1098)
sea212 Sep 11, 2023
bb0e671
Update weights (#1101)
sea212 Sep 12, 2023
36e0b52
Remove unnecessary comment from toml
maltekliemann Sep 14, 2023
fd4e49e
Use default features
maltekliemann Sep 14, 2023
eeb5e20
Bump version
maltekliemann Sep 14, 2023
31f48d8
Use checked math in `SoloLp`
maltekliemann Sep 14, 2023
780727f
Make match expression explicit
maltekliemann Sep 14, 2023
13f5c3e
Add comment about saturation
maltekliemann Sep 14, 2023
1559412
Use `MultiCurrency` instead of `ZeitgeistAssetManager`
maltekliemann Sep 14, 2023
9aeaae3
Apply suggestions from code review
maltekliemann Sep 14, 2023
9e02d06
Remove superfluous inserts
maltekliemann Sep 14, 2023
eb6d7a1
Fix error documentation
maltekliemann Sep 14, 2023
bf48133
Abstract reserve updates into `Pool`
maltekliemann Sep 14, 2023
dfd80ea
Make complete set operations require transactional
maltekliemann Sep 14, 2023
8c04059
Make test name not coffee-based
maltekliemann Sep 14, 2023
ec1416a
Update zrml/neo-swaps/src/mock.rs
maltekliemann Sep 14, 2023
05aad36
Update zrml/neo-swaps/src/mock.rs
maltekliemann Sep 14, 2023
deec29c
Reorganize tests
maltekliemann Sep 14, 2023
5e469da
Format
maltekliemann Sep 14, 2023
7a3bac8
Merge branch 'mkl-neo-swaps' of github.com:zeitgeistpm/zeitgeist into…
maltekliemann Sep 14, 2023
ffe0533
Fix comment
maltekliemann Sep 14, 2023
f8cbccc
Remove `macros.rs`
maltekliemann Sep 14, 2023
2ef5d61
Fix benchmarks
maltekliemann Sep 14, 2023
112e89d
Fix formatting
maltekliemann Sep 14, 2023
29af75d
Update benchmark script and add preliminary benchmarks
maltekliemann Sep 15, 2023
7cfc5c6
Update ED buffer handling
maltekliemann Sep 15, 2023
d8bbacc
Fix documentation
maltekliemann Sep 15, 2023
ce2b067
Merge branch 'main' into mkl-neo-swaps
maltekliemann Sep 15, 2023
cba23be
Implement market creation fees for neo-swaps
maltekliemann Sep 15, 2023
5c3a29d
Merge branch 'mkl-neo-swaps' into mkl-neo-swaps-benchmarks
maltekliemann Sep 15, 2023
b78728b
Use `MarketCreatorFee` in runtime
maltekliemann Sep 15, 2023
009af87
Add missing files
maltekliemann Sep 15, 2023
ce5bcfa
Add weights
maltekliemann Sep 15, 2023
785f10e
Merge branch 'mkl-neo-swaps-docs' into mkl-neo-swaps
maltekliemann Sep 15, 2023
c3e39c4
Reduce length of `MarketsCollectingSubsidy` (#1118)
maltekliemann Sep 19, 2023
40ad4b5
Add bad block of the proof size fiasko to Battery Station chain spec …
maltekliemann Sep 19, 2023
a12b24c
Update weights v0.4.0 (#1121)
sea212 Sep 20, 2023
8a50a78
Merge branch 'release-v0.4.0' into mkl-neo-swaps
maltekliemann Sep 20, 2023
64d3f59
Fix docs
maltekliemann Sep 23, 2023
4e38a45
Rename `IndexType` and change its type value
maltekliemann Sep 23, 2023
c8a2b24
Remove commented code
maltekliemann Sep 24, 2023
1cdaeed
Fix order of config parameters
maltekliemann Sep 24, 2023
647b943
Specify order of assets
maltekliemann Sep 24, 2023
d738cfb
Remove commented code
maltekliemann Sep 24, 2023
e11f262
Apply suggestions from code review
maltekliemann Sep 24, 2023
2ea7b8c
Fix `u16`/`u32` casts
maltekliemann Sep 24, 2023
d0c6808
Update zrml/prediction-markets/src/benchmarks.rs
maltekliemann Sep 24, 2023
0c7d643
Update zrml/prediction-markets/src/benchmarks.rs
maltekliemann Sep 24, 2023
b587582
Merge branch 'main' into mkl-neo-swaps
maltekliemann Sep 28, 2023
d96dd37
Update zrml/neo-swaps/src/math.rs
maltekliemann Sep 28, 2023
f4f4427
Update primitives/src/math/fixed.rs
maltekliemann Sep 28, 2023
7b796ee
Update primitives/src/math/fixed.rs
maltekliemann Sep 28, 2023
b4d9e8d
Fix formatting
maltekliemann Sep 28, 2023
7e347b2
Merge branch 'main' into mkl-neo-swaps
maltekliemann Sep 29, 2023
3e223ca
Fix conflicts
maltekliemann Sep 29, 2023
4c98579
Fix dispute period
maltekliemann Sep 29, 2023
3f7bb11
Merge branch 'main' into mkl-neo-swaps
maltekliemann Oct 4, 2023
65d2168
Format code
maltekliemann Oct 4, 2023
7211f85
Merge branch 'main' into mkl-neo-swaps
maltekliemann Oct 11, 2023
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
3 changes: 2 additions & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/zrml/authorized/ @Chralt98
/zrml/court/ @Chralt98
/zrml/global-disputes/ @Chralt98
/zrml/neo-swaps/ @maltekliemann
/zrml/prediction-markets/ @maltekliemann
/zrml/rikiddo/ @sea212
/zrml/simple-disputes/ @Chralt98
Expand All @@ -19,4 +20,4 @@

# Skip weight and Cargo.toml files
**/weights.rs
**/Cargo.toml
**/Cargo.toml
95 changes: 95 additions & 0 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ default-members = [
"zrml/global-disputes",
"zrml/liquidity-mining",
"zrml/market-commons",
"zrml/neo-swaps",
"zrml/orderbook-v1",
"zrml/prediction-markets",
"zrml/prediction-markets/runtime-api",
Expand All @@ -31,6 +32,7 @@ members = [
"zrml/global-disputes",
"zrml/liquidity-mining",
"zrml/market-commons",
"zrml/neo-swaps",
"zrml/orderbook-v1",
"zrml/orderbook-v1/fuzz",
"zrml/prediction-markets",
Expand Down Expand Up @@ -229,6 +231,7 @@ zrml-court = { path = "zrml/court", default-features = false }
zrml-global-disputes = { path = "zrml/global-disputes", default-features = false }
zrml-liquidity-mining = { path = "zrml/liquidity-mining", default-features = false }
zrml-market-commons = { path = "zrml/market-commons", default-features = false }
zrml-neo-swaps = { path = "zrml/neo-swaps", default-features = false }
zrml-orderbook-v1 = { path = "zrml/orderbook-v1", default-features = false }
zrml-prediction-markets = { path = "zrml/prediction-markets", default-features = false }
zrml-prediction-markets-runtime-api = { path = "zrml/prediction-markets/runtime-api", default-features = false }
Expand All @@ -250,6 +253,9 @@ url = "2.2.2"
arbitrary = { version = "1.3.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"] }
# 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.
hydra-dx-math = { git = "https://github.com/galacticcouncil/HydraDX-node", package = "hydra-dx-math", tag = "v18.0.0", default-features = false }
# Hashbrown works in no_std by default and default features are used in Rikiddo
hashbrown = { version = "0.12.3", default-features = true }
hex-literal = { version = "0.3.4", default-features = false }
Expand All @@ -258,6 +264,7 @@ num-traits = { version = "0.2.15", default-features = false }
rand = { version = "0.8.5", default-features = false }
rand_chacha = { version = "0.3.1", default-features = false }
serde = { version = "1.0.152", default-features = false }
typenum = { version = "1.15.0", default-features = false }

[profile.dev.package]
blake2 = { opt-level = 3 }
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@

# Zeitgeist: An Evolving Blockchain for Prediction Markets and Futarchy

![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)
![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)

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

## Modules

Expand All @@ -27,6 +30,9 @@ virtually _anything_.
liquidity to swap pools.
- [market-commons](./zrml/market-commons) - Contains common operations on
markets that are used by multiple pallets.
- [neo-swaps](./zrml/neo-swaps) - An implementation of the Logarithmic Market
Scoring Rule as constant function market maker, tailor-made for decentralized
combinatorial markets and Futarchy.
- [orderbook-v1](./zrml/orderbook-v1) - A naive orderbook implementation that's
only part of Zeitgeist's PoC. Will be replaced by a v2 orderbook that uses
0x-style hybrid on-chain and off-chain trading.
Expand Down
32 changes: 32 additions & 0 deletions docs/changelog_for_devs.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@ As of 0.3.9, the changelog's format is based on
components which query the chain's storage, the extrinsics or the runtime
APIs/RPC interface.

## v0.4.1

### Added

- Implement AMM-2.0-light in the form of zrml-neo-swaps. The new pallet has the
following dispatchables:

- `buy`: Buy outcome tokens from the specified market.
- `sell`: Sell outcome tokens to the specified market.
- `join`: Join the liquidity pool for the specified market.
- `exit`: Exit the liquidity pool for the specified market.
- `withdraw_fees`: Withdraw swap fees from the specified market.
- `deploy_pool`: Deploy a pool for the specified market and provide liquidity.
Chralt98 marked this conversation as resolved.
Show resolved Hide resolved

The new pallet has the following events:

- `BuyExecuted { who, market_id, asset_out, amount_in, amount_out, swap_fee_amount, external_fee_amount }`:
Informant bought a position.
- `SellExecuted { who, market_id, asset_in, amount_in, amount_out, swap_fee_amount, external_fee_amount }`:
Informants sold a position.
- `FeesWithdrawn { who }`: Liquidity provider withdrew fees.
- `JoinExecuted { who, market_id, pool_shares_amount, amounts_in, new_liquidity_parameter }`:
Liquidity provider joined the pool.
- `ExitExecuted { who, market_id, pool_shares_amount, amounts_out, new_liquidity_parameter }`:
Liquidity provider left the pool.
- `PoolDeployed { who, market_id, pool_shares_amount, amounts_in, liquidity_parameter }`:
Pool was created.
- `PoolDestroyed { who, market_id, pool_shares_amount, amounts_out }`: Pool
was destroyed.

For details, please refer to the `README.md` and the in-file documentation.

## v0.4.0

[#976]: https://github.com/zeitgeistpm/zeitgeist/pull/976
Expand Down
3 changes: 3 additions & 0 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[dependencies]
arbitrary = { workspace = true, optional = true }
fixed = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
orml-currencies = { workspace = true }
Expand All @@ -13,7 +14,9 @@ sp-core = { workspace = true }
sp-runtime = { workspace = true }

[dev-dependencies]
more-asserts = { workspace = true }
test-case = { workspace = true }
typenum = { workspace = true }

[features]
default = ["std"]
Expand Down
6 changes: 5 additions & 1 deletion primitives/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ pub const BLOCKS_PER_MINUTE: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as Bloc
pub const BLOCKS_PER_HOUR: BlockNumber = BLOCKS_PER_MINUTE * 60; // 300

// Definitions for currency
pub const BASE: u128 = 10_000_000_000;
pub const DECIMALS: u8 = 10;
pub const BASE: u128 = 10u128.pow(DECIMALS as u32);
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 @@ -82,6 +83,9 @@ pub const GLOBAL_DISPUTES_LOCK_ID: [u8; 8] = *b"zge/gdlk";
/// Pallet identifier, mainly used for named balance reserves.
pub const LM_PALLET_ID: PalletId = PalletId(*b"zge/lymg");

// NeoSwaps
pub const NS_PALLET_ID: PalletId = PalletId(*b"zge/neos");

// Prediction Markets
/// The maximum allowed market life time, measured in blocks.
pub const MAX_MARKET_LIFETIME: BlockNumber = 4 * BLOCKS_PER_YEAR;
Expand Down
10 changes: 8 additions & 2 deletions primitives/src/constants/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ parameter_types! {
pub const LiquidityMiningPalletId: PalletId = PalletId(*b"zge/lymg");
}

// NeoSwaps
parameter_types! {
pub storage NeoExitFee: Balance = CENT;
pub const NeoMaxSwapFee: Balance = 10 * CENT;
pub const NeoSwapsPalletId: PalletId = PalletId(*b"zge/neos");
}

// Prediction Market parameters
parameter_types! {
pub const AdvisoryBond: Balance = 25 * CENT;
Expand Down Expand Up @@ -146,11 +153,10 @@ parameter_types! {
}

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
_ => 10
}
};
}
Expand Down
2 changes: 2 additions & 0 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright 2023 Forecasting Technologies LTD.
// Copyright 2021-2022 Zeitgeist PM LLC.
//
// This file is part of Zeitgeist.
Expand All @@ -22,6 +23,7 @@ extern crate alloc;
mod asset;
pub mod constants;
mod market;
pub mod math;
mod max_runtime_usize;
mod outcome_report;
mod pool;
Expand Down
Loading
Loading