-
Notifications
You must be signed in to change notification settings - Fork 40
/
lib.rs
208 lines (190 loc) · 8.51 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// Copyright 2022-2023 Forecasting Technologies LTD.
// Copyright 2021-2022 Zeitgeist PM LLC.
//
// This file is part of Zeitgeist.
//
// Zeitgeist is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at
// your option) any later version.
//
// Zeitgeist is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Zeitgeist. If not, see <https://www.gnu.org/licenses/>.
#![cfg_attr(not(feature = "std"), no_std)]
#![recursion_limit = "512"]
extern crate alloc;
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
use common_runtime::{
create_common_benchmark_logic, create_common_tests, create_runtime, create_runtime_api,
create_runtime_with_additional_pallets, decl_common_types, impl_config_traits,
};
pub use frame_system::{
Call as SystemCall, CheckEra, CheckGenesis, CheckNonZeroSender, CheckNonce, CheckSpecVersion,
CheckTxVersion, CheckWeight,
};
#[cfg(feature = "parachain")]
pub use pallet_author_slot_filter::EligibilityValue;
pub use pallet_balances::Call as BalancesCall;
#[cfg(feature = "parachain")]
pub use crate::parachain_params::*;
pub use crate::parameters::*;
use alloc::vec;
use frame_support::{
traits::{ConstU16, ConstU32, Contains, EitherOfDiverse, EqualPrivilegeOnly, InstanceFilter},
weights::{constants::RocksDbWeight, ConstantMultiplier, IdentityFee},
};
use frame_system::EnsureRoot;
use pallet_collective::{EnsureProportionAtLeast, EnsureProportionMoreThan, PrimeDefaultVote};
use pallet_transaction_payment::ChargeTransactionPayment;
use sp_runtime::traits::{AccountIdConversion, AccountIdLookup, BlakeTwo256};
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use substrate_fixed::{types::extra::U33, FixedI128, FixedU128};
use zeitgeist_primitives::{constants::*, types::*};
use zrml_rikiddo::types::{EmaMarketVolume, FeeSigmoid, RikiddoSigmoidMV};
#[cfg(feature = "parachain")]
use {
frame_support::traits::{AsEnsureOriginWithArg, Everything, Nothing},
xcm_builder::{EnsureXcmOrigin, FixedWeightBounds, LocationInverter},
xcm_config::{
asset_registry::CustomAssetProcessor,
config::{LocalOriginToLocation, XcmConfig, XcmOriginToTransactDispatchOrigin, XcmRouter},
},
};
use frame_support::construct_runtime;
use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
create_runtime_str,
traits::Block as BlockT,
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult,
};
#[cfg(feature = "parachain")]
use nimbus_primitives::CanAuthor;
use sp_version::RuntimeVersion;
#[cfg(test)]
pub mod integration_tests;
#[cfg(feature = "parachain")]
pub mod parachain_params;
pub mod parameters;
#[cfg(feature = "parachain")]
pub mod xcm_config;
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("zeitgeist"),
impl_name: create_runtime_str!("zeitgeist"),
authoring_version: 1,
spec_version: 42,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 19,
state_version: 1,
};
#[derive(scale_info::TypeInfo)]
pub struct IsCallable;
// Currently disables Court, Rikiddo and creation of markets using Court or SimpleDisputes
// dispute mechanism.
impl Contains<Call> for IsCallable {
fn contains(call: &Call) -> bool {
#[cfg(feature = "parachain")]
use cumulus_pallet_dmp_queue::Call::service_overweight;
use frame_system::Call::{
kill_prefix, kill_storage, set_code, set_code_without_checks, set_storage,
};
use orml_currencies::Call::update_balance;
use pallet_balances::Call::{force_transfer, set_balance};
use pallet_collective::Call::set_members;
use pallet_vesting::Call::force_vested_transfer;
use zeitgeist_primitives::types::{
MarketDisputeMechanism::{Court, SimpleDisputes},
ScoringRule::RikiddoSigmoidFeeMarketEma,
};
use zrml_prediction_markets::Call::{
create_cpmm_market_and_deploy_assets, create_market, edit_market,
};
#[allow(clippy::match_like_matches_macro)]
match call {
// Membership is managed by the respective Membership instance
Call::AdvisoryCommittee(set_members { .. }) => false,
// See "balance.set_balance"
Call::AssetManager(update_balance { .. }) => false,
Call::Balances(inner_call) => {
match inner_call {
// Balances should not be set. All newly generated tokens be minted by well
// known and approved processes, like staking. However, this could be used
// in some cases to fund system accounts like the parachain sorveign account
// in case something goes terribly wrong (like a hack that draws the funds
// from such an account, see Maganta hack). Invoking this function one can
// also easily mess up consistency in regards to reserved tokens and locks.
set_balance { .. } => false,
// There should be no reason to force an account to transfer funds.
force_transfer { .. } => false,
_ => true,
}
}
// Membership is managed by the respective Membership instance
Call::Council(set_members { .. }) => false,
Call::Court(_) => false,
#[cfg(feature = "parachain")]
Call::DmpQueue(service_overweight { .. }) => false,
Call::LiquidityMining(_) => false,
Call::PredictionMarkets(inner_call) => {
match inner_call {
// Disable Rikiddo markets
create_market { scoring_rule: RikiddoSigmoidFeeMarketEma, .. } => false,
edit_market { scoring_rule: RikiddoSigmoidFeeMarketEma, .. } => false,
// Disable Court & SimpleDisputes dispute resolution mechanism
create_market { dispute_mechanism: Court | SimpleDisputes, .. } => false,
edit_market { dispute_mechanism: Court | SimpleDisputes, .. } => false,
create_cpmm_market_and_deploy_assets {
dispute_mechanism: Court | SimpleDisputes,
..
} => false,
_ => true,
}
}
Call::System(inner_call) => {
match inner_call {
// Some "waste" storage will never impact proper operation.
// Cleaning up storage should be done by pallets or independent migrations.
kill_prefix { .. } => false,
// See "killPrefix"
kill_storage { .. } => false,
// A parachain uses ParachainSystem to enact and authorized a runtime upgrade.
// This ensure proper synchronization with the relay chain.
// Calling `setCode` will wreck the chain.
set_code { .. } => false,
// See "setCode"
set_code_without_checks { .. } => false,
// Setting the storage directly is a dangerous operation that can lead to an
// inconsistent state. There might be scenarios where this is helpful, however,
// a well reviewed migration is better suited for that.
set_storage { .. } => false,
_ => true,
}
}
// Membership is managed by the respective Membership instance
Call::TechnicalCommittee(set_members { .. }) => false,
// There should be no reason to force vested transfer.
Call::Vesting(force_vested_transfer { .. }) => false,
_ => true,
}
}
}
decl_common_types!();
#[cfg(feature = "with-global-disputes")]
create_runtime_with_additional_pallets!(
GlobalDisputes: zrml_global_disputes::{Call, Event<T>, Pallet, Storage} = 59,
);
#[cfg(not(feature = "with-global-disputes"))]
create_runtime_with_additional_pallets!();
impl_config_traits!();
create_runtime_api!();
create_common_benchmark_logic!();
create_common_tests!();