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

New Asset System #1295

Merged
merged 15 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# Ignore everything but mod.rs in /runtime/common/src/weights/
/runtime/common/src/weights/*
/runtime/common/src/weights/mod.rs @sea212
/zrml/asset-router/ @sea212
/zrml/authorized/ @Chralt98
/zrml/court/ @Chralt98
/zrml/global-disputes/ @Chralt98
Expand Down
51 changes: 51 additions & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ default-members = [
"runtime/battery-station",
"runtime/zeitgeist",
"zrml/authorized",
"zrml/asset-router",
"zrml/court",
"zrml/global-disputes",
"zrml/liquidity-mining",
Expand All @@ -31,6 +32,7 @@ members = [
"runtime/battery-station",
"runtime/zeitgeist",
"zrml/authorized",
"zrml/asset-router",
"zrml/court",
"zrml/global-disputes",
"zrml/liquidity-mining",
Expand Down Expand Up @@ -163,6 +165,7 @@ frame-system-benchmarking = { git = "https://github.com/paritytech/substrate", b
frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false }
frame-try-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false }
pallet-asset-tx-payment = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false }
pallet-assets = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false }
pallet-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false }
pallet-bounties = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38", default-features = false }
Expand Down Expand Up @@ -232,6 +235,7 @@ zrml-swaps-rpc = { path = "zrml/swaps/rpc" }
common-runtime = { path = "runtime/common", default-features = false }
zeitgeist-macros = { path = "macros", default-features = false }
zeitgeist-primitives = { path = "primitives", default-features = false }
zrml-asset-router = { path = "zrml/asset-router", default-features = false }
zrml-authorized = { path = "zrml/authorized", default-features = false }
zrml-court = { path = "zrml/court", default-features = false }
zrml-global-disputes = { path = "zrml/global-disputes", default-features = false }
Expand Down Expand Up @@ -262,6 +266,7 @@ 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"] }
impl-trait-for-tuples = { version = "0.2.2" }
# 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 = "v21.1.1", default-features = false }
# Hashbrown works in no_std by default and default features are used in Rikiddo
Expand Down Expand Up @@ -331,6 +336,7 @@ opt-level = 3
panic = "unwind"

[patch."https://github.com/paritytech/substrate"]
pallet-assets = { git = "https://github.com/zeitgeistpm/substrate.git", branch = "polkadot-v0.9.38-assets-managed-destroy" }
substrate-wasm-builder = { git = "https://github.com/zeitgeistpm/substrate.git", branch = "polkadot-v0.9.38-fix-new-rustc-build" }

[patch."https://github.com/paritytech/polkadot"]
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ decentralized court.

## Modules

- [asset-router](./zrml/asset-router) - Routes all asset classes to the
respective pallets and provides a garbage collection for destructible assets.
- [authorized](./zrml/authorized) - Offers authorized resolution of disputes.
- [court](./zrml/court) - An implementation of a court mechanism used to resolve
disputes in a decentralized fashion.
Expand Down
105 changes: 96 additions & 9 deletions docs/changelog_for_devs.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,114 @@ 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.5.1

[#1197]: https://github.com/zeitgeistpm/zeitgeist/pull/1197
[pallet-asset]:
https://github.com/paritytech/polkadot-sdk/tree/master/substrate/frame/assets

### Added

- [#1197] New asset classes:
- `CampaignAssetClass` - Can be registered by gov and council and be used in
markets and to pay transaction fees.
- `CustomAssetClass` - Allows any user to register their custom assets (can't
be used in markets yet).
- `MarketAssetClass` - Contains all asset types used in markets.
- `CurrencyClass` - Contains all non-ztg currencies, currently only
`ForeignAsset`. Temporarily also contains outcome asset types as they are
being lazily migrated to `MarketAssetClass`
- Subclasses (they are composites of multiple types from potentially various
asset classes):
- `BaseAssetClass` - Contains all assets that can be used as base asset /
collateral in prediction markets.
- `XcmAssetClass` - Contains all assets that can be transferred via XCM
(used in XCM related pallets like XTokens).
- `ParimutuelAssetClass` - Contains all assets that can be used in
parimutuel markets.
- All asset classes can be converted into the overarching asset class `Assets`
(that contains all asset types) by using `Into` or simply decoding their
scale codec representation into the `Assets` type.
- `Assets` provides `TryInto` into all other asset classes, which fails if the
asset type is not existent in the asset class.
- [#1197] Added [pallet-asset], which is a Substrate pallet that provides fine
grained control over asset creation, destruction, management (mint, burn,
freeze, admin account) and much more. It is used for `CampaignAssetClass`,
`CustomAssetClass` and `MarketAssetClass`.
- [#1197] Added zrml-asset-router (AssetRouter). This pallet is an abstraction
layer over multiple pallets (like orml-tokens and pallet-assets) that handles
routing calls, managing asset destruction and the lazy migrating market assets
from `CurrencyClass` to `MarketAssetClass`. It does not have any dispatchable
calls or events, but custom errors that might be relayed to the dispatchable
calls of the pallets that it uses within it's routing mechanism.
`orml-currencies` (AssetManager) is ought to be used when interacting with the
chain via transactions and can be used when developing pallets. In the latter
case, some functionalities can only be used when directly interacting with
zrml-asset-router.
- [#1197] Campaign assets have to be created and destroyed by gov or the
council. Custom assets have to be created and destroyed via transactions.
Market assets are automatically created and destroyed. In all non automatic
cases, destroying is achieved by calling `start_destroy`.
- [#1197] Transaction fee payment is now possible with campaign assets. The fee
is calculated as follows (with `CampaignAssetFeeMultiplier = 100`):

```rust
if ztg_supply / campaign_asset_supply >= 100 {
return native_fee;
} else {
return native_fee * campaign_asset_supply * 100 / ztg_supply;
}
```

### Changed

- [#1197] `Assets` does not contain the `CombinatorialOutcome` asset type
anymore, but has been extended by all existing asset types.
- [#1197] The transaction fee asset type has been changed from `u32` to
`Assets`.
- [#1197] The prediction market base asset type has been changed in the `Market`
storage and market creation dispatchable calls to `BaseAssetClass`.
- [#1197] The asset type for XCM has been changed to `XcmAssetClass`. It is used
in `orml-xtokens` (XTokens) and `orml-asset-registry` (AssetRegistry).

### Removed

- [#1197] `SerdeWrapper` has been removed.

### Deprecated

- [#1197] Market outcome asset types are no longer handled by `orml-tokens`
(Tokens), except for existing markets which still used market asset types
within `CurrencyClass`. `pallet-assets` (MarketAssets) now handles market
outcome asset types from the `MarketAssetClass`.

## v0.5.0

[#1197]: https://github.com/zeitgeistpm/zeitgeist/pull/1197
[#1178]: https://github.com/zeitgeistpm/zeitgeist/pull/1178

### Changes
### Changed

- ⚠️ Move the `zeitgeist_primitives::Pool` struct to `zrml_swaps::types::Pool` and change the following fields ([#1197]):
- Remove `market_id`
- Make `swap_fee` non-optional
- Remove `total_subsidy`
- Make `total_weight` non-optional
- Make `weights` non-optional
- ⚠️ Change the type of `liquidity_shares_manager` in `zrml_neo_swaps::types::Pool` from `zrml_neo_swaps::types::SoloLp` to `zrml_neo_swaps::types::LiquidityTree`. Details on the liquidity tree can be found in the `README.md` of zrml-neo-swaps and the documentation of the `LiquidityTree` object ([#1179]).
- ⚠️ Move the `zeitgeist_primitives::Pool` struct to `zrml_swaps::types::Pool`
and change the following fields ([#1197]):
- Remove `market_id`
- Make `swap_fee` non-optional
- Remove `total_subsidy`
- Make `total_weight` non-optional
- Make `weights` non-optional
- ⚠️ Change the type of `liquidity_shares_manager` in
`zrml_neo_swaps::types::Pool` from `zrml_neo_swaps::types::SoloLp` to
`zrml_neo_swaps::types::LiquidityTree`. Details on the liquidity tree can be
found in the `README.md` of zrml-neo-swaps and the documentation of the
`LiquidityTree` object ([#1179]).

### Migrations

- Closed all CPMM pools. Withdrawals are still allowed. Creating new pools will
be impossible until further updates are deployed. ([#1197])
- Remove all Rikiddo storage elements. ([#1197])
- Migrate neo-swaps `Pools` storage. The market creator's liquidity position is translated into a position in the liquidity tree of the same value ([#1178]).
- Migrate neo-swaps `Pools` storage. The market creator's liquidity position is
translated into a position in the liquidity tree of the same value ([#1178]).

### Removed

Expand Down
8 changes: 4 additions & 4 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ macro_rules! create_b_tree_map {
#[macro_export]
macro_rules! unreachable_non_terminating {
($condition: expr, $message: literal, $($message_args: tt)*) => {
let message = format!($message, $($message_args)*);
let message = alloc::format!($message, $($message_args)*);

#[cfg(test)]
assert!($condition, "{}", message);
Expand All @@ -60,7 +60,7 @@ macro_rules! unreachable_non_terminating {
}
};
($condition: expr, $log_target: ident, $message: literal, $($message_args: tt)*) => {
let message = format!($message, $($message_args)*);
let message = alloc::format!($message, $($message_args)*);

#[cfg(test)]
assert!($condition, "{}", message);
Expand All @@ -70,7 +70,7 @@ macro_rules! unreachable_non_terminating {
}
};
($condition: expr, $extra_code: expr, $message: literal, $($message_args: tt)*) => {
let message = format!($message, $($message_args)*);
let message = alloc::format!($message, $($message_args)*);

#[cfg(test)]
assert!($condition, "{}", message);
Expand All @@ -81,7 +81,7 @@ macro_rules! unreachable_non_terminating {
}
};
($condition: expr, $log_target: ident, $extra_code: expr, $message: literal, $($message_args: tt)*) => {
let message = format!($message, $($message_args)*);
let message = alloc::format!($message, $($message_args)*);

#[cfg(test)]
assert!($condition, "{}", message);
Expand Down
1 change: 1 addition & 0 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ arbitrary = { workspace = true, optional = true }
fixed = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
impl-trait-for-tuples = { workspace = true }
num-traits = { workspace = true }
orml-currencies = { workspace = true }
orml-tokens = { workspace = true }
Expand Down
Loading
Loading