Skip to content

Commit

Permalink
Merge branch 'main' into release-v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sea212 committed Oct 10, 2023
2 parents 628c559 + 575ebec commit e459e29
Show file tree
Hide file tree
Showing 49 changed files with 1,841 additions and 1,842 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ jobs:

- name: Install build tools
run: ./scripts/init.sh

- uses: actions-rs/[email protected]
with:
crate: taplo-cli

# TODO(#1125): Use actions-rs/install for Taplo once stable
# - uses: actions-rs/[email protected]
# with:
# crate: taplo-cli

- name: Cache Dependencies
uses: Swatinem/rust-cache@v1
Expand Down
17 changes: 2 additions & 15 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,9 @@ mark the PR with the following labels according to

## Style Guide

- Use `rustfmt` to format your contributions.
- Avoid panickers like `unwrap()` even if there's proof that they are
infallible.
- Dispatches that don't use `#[transactional]` macro **must** contain a comment
including `MARK(non-transactional): ...` followed by a short explanation why
the dispatch doesn't require `#[transactional]`.
- Functions are written in snake case, i.e. `my_function`, anything else is
declared in CamelCase (starting with a capital first letter).
- Indentations consist of spaces, unless the language used requires tabs.
- Anything that is publicly visible must be documented. This encompasses but is
not limited to whole crates (top level documentation), public types and
functions, dispatachble functions (functions that can be called by
transactions), the `Error` and `Event` enum as well as the `Config` trait.
- Any newly added or modified functionality must be subject to at least one test
case. A full code coverage is the targeted goal.
- Refer to the [style guide].

[rules]: #Rules
[docs/changelog_for_devs.md]: docs/changelog_for_devs.md
[style guide]: docs/STYLE_GUIDE.md
[zeitgeistpm]: https://github.com/zeitgeistpm
6 changes: 6 additions & 0 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions docs/STYLE_GUIDE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Style guide

As a basis, the
[Substrate Style Guide](https://docs.substrate.io/build/troubleshoot-your-code/)
should be taken into account. In addition to that, the following sections
further elaborate the style guide used in this repository.

## Comments

- Comments **must** be wrapped at 100 chars per line.
Expand Down
20 changes: 11 additions & 9 deletions misc/frame_weight_template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ impl<T: frame_system::Config> {{pallet}}::weights::WeightInfo for WeightInfo<T>
{{#each benchmark.comments as |comment|}}
/// {{comment}}
{{/each}}
{{#each benchmark.component_ranges as |range|}}
/// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`.
{{/each}}
fn {{benchmark.name~}}
(
{{~#each benchmark.components as |c| ~}}
Expand All @@ -34,27 +37,26 @@ impl<T: frame_system::Config> {{pallet}}::weights::WeightInfo for WeightInfo<T>
// Measured: `{{benchmark.base_recorded_proof_size}}{{#each benchmark.component_recorded_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}`
// Estimated: `{{benchmark.base_calculated_proof_size}}{{#each benchmark.component_calculated_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}`
// Minimum execution time: {{underscore benchmark.min_execution_time}} nanoseconds.
{{#if (ne benchmark.base_calculated_proof_size "0")}}
Weight::from_parts({{underscore benchmark.base_weight}}, {{benchmark.base_calculated_proof_size}})
{{else}}
Weight::from_ref_time({{underscore benchmark.base_weight}})
{{/if}}
{{#each benchmark.component_weight as |cw|}}
// Standard Error: {{underscore cw.error}}
.saturating_add(Weight::from_ref_time({{underscore cw.slope}}).saturating_mul({{cw.name}}.into()))
.saturating_add(Weight::from_parts({{underscore cw.slope}}, 0).saturating_mul({{cw.name}}.into()))
{{/each}}
{{#if (ne benchmark.base_reads "0")}}
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}}_u64))
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}}))
{{/if}}
{{#each benchmark.component_reads as |cr|}}
.saturating_add(T::DbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into())))
{{/each}}
{{#if (ne benchmark.base_writes "0")}}
.saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}}_u64))
.saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}}))
{{/if}}
{{#each benchmark.component_writes as |cw|}}
.saturating_add(T::DbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into())))
{{/each}}
{{#each benchmark.component_calculated_proof_size as |cp|}}
.saturating_add(Weight::from_proof_size({{cp.slope}}).saturating_mul({{cp.name}}.into()))
{{/each}}
.saturating_add(Weight::from_parts(0, {{cp.slope}}).saturating_mul({{cp.name}}.into()))
{{/each}}
}
{{/each}}
}
20 changes: 11 additions & 9 deletions misc/orml_weight_template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ impl<T: frame_system::Config> {{pallet}}::WeightInfo for WeightInfo<T> {
{{#each benchmark.comments as |comment|}}
/// {{comment}}
{{/each}}
{{#each benchmark.component_ranges as |range|}}
/// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`.
{{/each}}
fn {{benchmark.name~}}
(
{{~#each benchmark.components as |c| ~}}
Expand All @@ -34,27 +37,26 @@ impl<T: frame_system::Config> {{pallet}}::WeightInfo for WeightInfo<T> {
// Measured: `{{benchmark.base_recorded_proof_size}}{{#each benchmark.component_recorded_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}`
// Estimated: `{{benchmark.base_calculated_proof_size}}{{#each benchmark.component_calculated_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}`
// Minimum execution time: {{underscore benchmark.min_execution_time}} nanoseconds.
{{#if (ne benchmark.base_calculated_proof_size "0")}}
Weight::from_parts({{underscore benchmark.base_weight}}, {{benchmark.base_calculated_proof_size}})
{{else}}
Weight::from_ref_time({{underscore benchmark.base_weight}})
{{/if}}
{{#each benchmark.component_weight as |cw|}}
// Standard Error: {{underscore cw.error}}
.saturating_add(Weight::from_ref_time({{underscore cw.slope}}).saturating_mul({{cw.name}}.into()))
.saturating_add(Weight::from_parts({{underscore cw.slope}}, 0).saturating_mul({{cw.name}}.into()))
{{/each}}
{{#if (ne benchmark.base_reads "0")}}
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}}_u64))
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}}))
{{/if}}
{{#each benchmark.component_reads as |cr|}}
.saturating_add(T::DbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into())))
{{/each}}
{{#if (ne benchmark.base_writes "0")}}
.saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}}_u64))
.saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}}))
{{/if}}
{{#each benchmark.component_writes as |cw|}}
.saturating_add(T::DbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into())))
{{/each}}
{{#each benchmark.component_calculated_proof_size as |cp|}}
.saturating_add(Weight::from_proof_size({{cp.slope}}).saturating_mul({{cp.name}}.into()))
{{/each}}
.saturating_add(Weight::from_parts(0, {{cp.slope}}).saturating_mul({{cp.name}}.into()))
{{/each}}
}
{{/each}}
}
20 changes: 11 additions & 9 deletions misc/weight_template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ impl<T: frame_system::Config> WeightInfoZeitgeist for WeightInfo<T> {
{{#each benchmark.comments as |comment|}}
/// {{comment}}
{{/each}}
{{#each benchmark.component_ranges as |range|}}
/// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`.
{{/each}}
fn {{benchmark.name~}}
(
{{~#each benchmark.components as |c| ~}}
Expand All @@ -46,27 +49,26 @@ impl<T: frame_system::Config> WeightInfoZeitgeist for WeightInfo<T> {
// Measured: `{{benchmark.base_recorded_proof_size}}{{#each benchmark.component_recorded_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}`
// Estimated: `{{benchmark.base_calculated_proof_size}}{{#each benchmark.component_calculated_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}`
// Minimum execution time: {{underscore benchmark.min_execution_time}} nanoseconds.
{{#if (ne benchmark.base_calculated_proof_size "0")}}
Weight::from_parts({{underscore benchmark.base_weight}}, {{benchmark.base_calculated_proof_size}})
{{else}}
Weight::from_ref_time({{underscore benchmark.base_weight}})
{{/if}}
{{#each benchmark.component_weight as |cw|}}
// Standard Error: {{underscore cw.error}}
.saturating_add(Weight::from_ref_time({{underscore cw.slope}}).saturating_mul({{cw.name}}.into()))
.saturating_add(Weight::from_parts({{underscore cw.slope}}, 0).saturating_mul({{cw.name}}.into()))
{{/each}}
{{#if (ne benchmark.base_reads "0")}}
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}}_u64))
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}}))
{{/if}}
{{#each benchmark.component_reads as |cr|}}
.saturating_add(T::DbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into())))
{{/each}}
{{#if (ne benchmark.base_writes "0")}}
.saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}}_u64))
.saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}}))
{{/if}}
{{#each benchmark.component_writes as |cw|}}
.saturating_add(T::DbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into())))
{{/each}}
{{#each benchmark.component_calculated_proof_size as |cp|}}
.saturating_add(Weight::from_proof_size({{cp.slope}}).saturating_mul({{cp.name}}.into()))
{{/each}}
.saturating_add(Weight::from_parts(0, {{cp.slope}}).saturating_mul({{cp.name}}.into()))
{{/each}}
}
{{/each}}
}
3 changes: 3 additions & 0 deletions primitives/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ pub const MAX_ASSETS: u16 = MAX_CATEGORIES + 1;
/// Pallet identifier, mainly used for named balance reserves.
pub const SWAPS_PALLET_ID: PalletId = PalletId(*b"zge/swap");

// Orderbook
pub const ORDERBOOK_PALLET_ID: PalletId = PalletId(*b"zge/ordb");

// Treasury
/// Pallet identifier, used to derive treasury account
pub const TREASURY_PALLET_ID: PalletId = PalletId(*b"zge/tsry");
5 changes: 5 additions & 0 deletions primitives/src/constants/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ parameter_types! {
pub const SwapsPalletId: PalletId = PalletId(*b"zge/swap");
}

// Orderbook parameters
parameter_types! {
pub const OrderbookPalletId: PalletId = PalletId(*b"zge/ordb");
}

// Shared within tests
// Balance
parameter_types! {
Expand Down
6 changes: 3 additions & 3 deletions primitives/src/market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub struct Market<AI, BA, BN, M, A> {
/// The resolved outcome.
pub resolved_outcome: Option<OutcomeReport>,
/// See [`MarketDisputeMechanism`].
pub dispute_mechanism: MarketDisputeMechanism,
pub dispute_mechanism: Option<MarketDisputeMechanism>,
/// The bonds reserved for this market.
pub bonds: MarketBonds<AI, BA>,
}
Expand Down Expand Up @@ -162,7 +162,7 @@ where
.saturating_add(MarketStatus::max_encoded_len())
.saturating_add(<Option<Report<AI, BN>>>::max_encoded_len())
.saturating_add(<Option<OutcomeReport>>::max_encoded_len())
.saturating_add(<MarketDisputeMechanism>::max_encoded_len())
.saturating_add(<Option<MarketDisputeMechanism>>::max_encoded_len())
.saturating_add(<MarketBonds<AI, BA>>::max_encoded_len())
}
}
Expand Down Expand Up @@ -393,7 +393,7 @@ mod tests {
status: MarketStatus::Active,
report: None,
resolved_outcome: None,
dispute_mechanism: MarketDisputeMechanism::Authorized,
dispute_mechanism: Some(MarketDisputeMechanism::Authorized),
bonds: MarketBonds::default(),
};
assert_eq!(market.matches_outcome_report(&outcome_report), expected);
Expand Down
2 changes: 2 additions & 0 deletions primitives/src/pool.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 Down Expand Up @@ -83,4 +84,5 @@ where
pub enum ScoringRule {
CPMM,
RikiddoSigmoidFeeMarketEma,
Orderbook,
}
4 changes: 4 additions & 0 deletions runtime/battery-station/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ zrml-court = { workspace = true }
zrml-global-disputes = { workspace = true, optional = true }
zrml-liquidity-mining = { workspace = true }
zrml-market-commons = { workspace = true }
zrml-orderbook-v1 = { workspace = true }
zrml-prediction-markets = { workspace = true }
zrml-rikiddo = { workspace = true }
zrml-simple-disputes = { workspace = true }
Expand Down Expand Up @@ -214,6 +215,7 @@ runtime-benchmarks = [
"zrml-global-disputes/runtime-benchmarks",
"zrml-styx/runtime-benchmarks",
"zrml-swaps/runtime-benchmarks",
"zrml-orderbook-v1/runtime-benchmarks",
]
std = [
"frame-executive/std",
Expand Down Expand Up @@ -328,6 +330,7 @@ std = [
"zrml-styx/std",
"zrml-swaps-runtime-api/std",
"zrml-swaps/std",
"zrml-orderbook-v1/std",
]
try-runtime = [
"frame-executive/try-runtime",
Expand Down Expand Up @@ -380,6 +383,7 @@ try-runtime = [
"zrml-global-disputes/try-runtime",
"zrml-styx/try-runtime",
"zrml-swaps/try-runtime",
"zrml-orderbook-v1/try-runtime",

# Parachain
"pallet-author-inherent?/try-runtime",
Expand Down
12 changes: 6 additions & 6 deletions runtime/battery-station/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@ impl Contains<RuntimeCall> for ContractsCallfilter {
dispute { .. } => true,
// Only allow CPMM markets using Authorized or SimpleDisputes dispute mechanism
create_market {
dispute_mechanism: MarketDisputeMechanism::Authorized,
dispute_mechanism: Some(MarketDisputeMechanism::Authorized),
scoring_rule: ScoringRule::CPMM,
..
} => true,
create_cpmm_market_and_deploy_assets {
dispute_mechanism: MarketDisputeMechanism::Authorized,
dispute_mechanism: Some(MarketDisputeMechanism::Authorized),
..
} => true,
edit_market {
dispute_mechanism: MarketDisputeMechanism::Authorized,
dispute_mechanism: Some(MarketDisputeMechanism::Authorized),
scoring_rule: ScoringRule::CPMM,
..
} => true,
Expand Down Expand Up @@ -180,18 +180,18 @@ impl Contains<RuntimeCall> for IsCallable {
scoring_rule: ScoringRule::RikiddoSigmoidFeeMarketEma, ..
} => false,
create_market {
dispute_mechanism: MarketDisputeMechanism::SimpleDisputes,
dispute_mechanism: Some(MarketDisputeMechanism::SimpleDisputes),
..
} => false,
edit_market {
scoring_rule: ScoringRule::RikiddoSigmoidFeeMarketEma, ..
} => false,
create_cpmm_market_and_deploy_assets {
dispute_mechanism: MarketDisputeMechanism::SimpleDisputes,
dispute_mechanism: Some(MarketDisputeMechanism::SimpleDisputes),
..
} => false,
edit_market {
dispute_mechanism: MarketDisputeMechanism::SimpleDisputes,
dispute_mechanism: Some(MarketDisputeMechanism::SimpleDisputes),
..
} => false,
_ => true,
Expand Down
3 changes: 3 additions & 0 deletions runtime/battery-station/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ parameter_types! {
/// Pallet identifier, mainly used for named balance reserves.
pub const SwapsPalletId: PalletId = SWAPS_PALLET_ID;

// Orderbook parameters
pub const OrderbookPalletId: PalletId = ORDERBOOK_PALLET_ID;

// System
pub const BlockHashCount: u64 = 250;
pub const SS58Prefix: u8 = 73;
Expand Down
Loading

0 comments on commit e459e29

Please sign in to comment.