Skip to content

Commit

Permalink
Merge branch 'main' into mkl-neo-swaps
Browse files Browse the repository at this point in the history
  • Loading branch information
maltekliemann authored Oct 4, 2023
2 parents 4c98579 + 575ebec commit 3f7bb11
Show file tree
Hide file tree
Showing 24 changed files with 1,185 additions and 498 deletions.
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.

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 @@ -117,6 +117,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 @@ -127,6 +127,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
1 change: 1 addition & 0 deletions primitives/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,5 @@ pub enum ScoringRule {
CPMM,
RikiddoSigmoidFeeMarketEma,
Lmsr,
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-global-disputes = { workspace = true, optional = true }
zrml-liquidity-mining = { workspace = true }
zrml-market-commons = { workspace = true }
zrml-neo-swaps = { 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 @@ -215,6 +216,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 @@ -330,6 +332,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 @@ -383,6 +386,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
3 changes: 3 additions & 0 deletions runtime/battery-station/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,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
18 changes: 18 additions & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ macro_rules! decl_common_types {
CourtPalletId::get(),
GlobalDisputesPalletId::get(),
LiquidityMiningPalletId::get(),
OrderbookPalletId::get(),
PmPalletId::get(),
SimpleDisputesPalletId::get(),
SwapsPalletId::get(),
Expand Down Expand Up @@ -313,6 +314,7 @@ macro_rules! create_runtime {
Styx: zrml_styx::{Call, Event<T>, Pallet, Storage} = 58,
GlobalDisputes: zrml_global_disputes::{Call, Event<T>, Pallet, Storage} = 59,
NeoSwaps: zrml_neo_swaps::{Call, Event<T>, Pallet, Storage} = 60,
Orderbook: zrml_orderbook_v1::{Call, Event<T>, Pallet, Storage} = 61,

$($additional_pallets)*
}
Expand Down Expand Up @@ -858,6 +860,9 @@ macro_rules! impl_config_traits {
c,
RuntimeCall::Swaps(zrml_swaps::Call::swap_exact_amount_in { .. })
| RuntimeCall::Swaps(zrml_swaps::Call::swap_exact_amount_out { .. })
| RuntimeCall::Orderbook(zrml_orderbook_v1::Call::place_order { .. })
| RuntimeCall::Orderbook(zrml_orderbook_v1::Call::fill_order { .. })
| RuntimeCall::Orderbook(zrml_orderbook_v1::Call::remove_order { .. })
),
ProxyType::HandleAssets => matches!(
c,
Expand All @@ -877,6 +882,9 @@ macro_rules! impl_config_traits {
| RuntimeCall::PredictionMarkets(
zrml_prediction_markets::Call::deploy_swap_pool_and_additional_liquidity { .. }
)
| RuntimeCall::Orderbook(zrml_orderbook_v1::Call::place_order { .. })
| RuntimeCall::Orderbook(zrml_orderbook_v1::Call::fill_order { .. })
| RuntimeCall::Orderbook(zrml_orderbook_v1::Call::remove_order { .. })
),
}
}
Expand Down Expand Up @@ -1243,6 +1251,14 @@ macro_rules! impl_config_traits {
type MaxSwapFee = NeoSwapsMaxSwapFee;
type PalletId = NeoSwapsPalletId;
}

impl zrml_orderbook_v1::Config for Runtime {
type AssetManager = AssetManager;
type RuntimeEvent = RuntimeEvent;
type MarketCommons = MarketCommons;
type PalletId = OrderbookPalletId;
type WeightInfo = zrml_orderbook_v1::weights::WeightInfo<Runtime>;
}
}
}

Expand Down Expand Up @@ -1351,6 +1367,7 @@ macro_rules! create_runtime_api {
list_benchmark!(list, extra, zrml_court, Court);
list_benchmark!(list, extra, zrml_simple_disputes, SimpleDisputes);
list_benchmark!(list, extra, zrml_global_disputes, GlobalDisputes);
list_benchmark!(list, extra, zrml_orderbook_v1, Orderbook);
#[cfg(not(feature = "parachain"))]
list_benchmark!(list, extra, zrml_prediction_markets, PredictionMarkets);
list_benchmark!(list, extra, zrml_liquidity_mining, LiquidityMining);
Expand Down Expand Up @@ -1453,6 +1470,7 @@ macro_rules! create_runtime_api {
add_benchmark!(params, batches, zrml_court, Court);
add_benchmark!(params, batches, zrml_simple_disputes, SimpleDisputes);
add_benchmark!(params, batches, zrml_global_disputes, GlobalDisputes);
add_benchmark!(params, batches, zrml_orderbook_v1, Orderbook);
#[cfg(not(feature = "parachain"))]
add_benchmark!(params, batches, zrml_prediction_markets, PredictionMarkets);
add_benchmark!(params, batches, zrml_liquidity_mining, LiquidityMining);
Expand Down
4 changes: 4 additions & 0 deletions runtime/zeitgeist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ zrml-global-disputes = { workspace = true, optional = true }
zrml-liquidity-mining = { workspace = true }
zrml-market-commons = { workspace = true }
zrml-neo-swaps = { 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 @@ -213,6 +214,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 @@ -320,6 +322,7 @@ std = [
"zrml-swaps-runtime-api/std",
"zrml-styx/std",
"zrml-swaps/std",
"zrml-orderbook-v1/std",
]
try-runtime = [
"frame-executive/try-runtime",
Expand Down Expand Up @@ -373,6 +376,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
3 changes: 3 additions & 0 deletions runtime/zeitgeist/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ parameter_types! {
/// Pallet identifier, mainly used for named balance reserves. DO NOT CHANGE.
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
7 changes: 7 additions & 0 deletions zrml/orderbook-v1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,25 @@ sp-runtime = { workspace = true }
zeitgeist-primitives = { workspace = true }

# Mock
orml-currencies = { workspace = true, optional = true }
orml-tokens = { workspace = true, optional = true }
pallet-balances = { workspace = true, optional = true }
pallet-timestamp = { workspace = true, optional = true }
sp-io = { workspace = true, optional = true }
zrml-market-commons = { workspace = true, optional = true }

[dev-dependencies]
test-case = { workspace = true }
zrml-orderbook-v1 = { workspace = true, features = ["mock", "default"] }

[features]
default = ["std"]
mock = [
"orml-tokens/default",
"pallet-balances/default",
"pallet-timestamp/default",
"zrml-market-commons/default",
"orml-currencies/default",
"sp-io/default",
"zeitgeist-primitives/mock",
]
Expand Down
Loading

0 comments on commit 3f7bb11

Please sign in to comment.