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

Enable certain dispatchable calls in smart contracts #1041

Merged
merged 41 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
60eb70b
Enable certain dispatchable calls in smart contracts
sea212 Jul 16, 2023
41e1b86
Cargo fmt
sea212 Jul 17, 2023
7e82892
Remove unnecessary and wrong comments
sea212 Jul 17, 2023
fb3c372
Update runtime/battery-station/src/lib.rs
sea212 Jul 20, 2023
a8d6dfe
Update runtime/battery-station/src/lib.rs
sea212 Jul 20, 2023
d4d743e
Update runtime/battery-station/src/lib.rs
sea212 Jul 20, 2023
25aeaac
Improve style
sea212 Jul 20, 2023
9648d8d
Use unstable contracts interface on Battery Station
sea212 Jul 20, 2023
935d026
Prettify Cargo.toml
sea212 Jul 20, 2023
9b0a64a
Unify dependencies in workspace
sea212 Aug 1, 2023
bd5e08a
Make all zrml crates compatible with workspace deps
sea212 Aug 1, 2023
58cac7e
Use workspace dependencies
sea212 Aug 1, 2023
51d9980
Fix bugs
sea212 Aug 1, 2023
13f54fd
More bug fixes
sea212 Aug 1, 2023
e177aa4
Fix more bugs
sea212 Aug 1, 2023
ca572d4
Add comment
sea212 Aug 1, 2023
bad1e86
Fix all remaining bugs
sea212 Aug 1, 2023
f4edbd9
Use default instead of std features in std environment
sea212 Aug 1, 2023
8982d46
Align dependency defintion structure
sea212 Aug 1, 2023
354f72f
Format
sea212 Aug 1, 2023
edff233
Use default features when mock is enabled
sea212 Aug 1, 2023
43e76e2
Update all dependencies
sea212 Aug 1, 2023
fcb39f3
Partially adjust runtime
sea212 Aug 1, 2023
4e18333
Make standalone Zeitgeist runtime compilable
sea212 Aug 2, 2023
097ef46
Make standalone Zeitgeist runtime compile with all features
sea212 Aug 2, 2023
c0ec18f
Make --all-features build
sea212 Aug 2, 2023
d7549f5
Make battery-station compilable
sea212 Aug 2, 2023
cadac3a
Add migrations
sea212 Aug 2, 2023
c031b36
Format
sea212 Aug 2, 2023
67f69f8
Update standalone node
sea212 Aug 2, 2023
409dce0
Update parachain client
sea212 Aug 2, 2023
046c1fe
Merge branch 'main' into sea212-upgrade-v0.9.37
sea212 Aug 2, 2023
f5ce270
Update copyright notice
sea212 Aug 2, 2023
91de54d
Satisfy license checker
sea212 Aug 2, 2023
f9d0fdf
Merge branch 'main' into sea212-enable-sc-calls
sea212 Aug 2, 2023
d646156
Enable serde/std in std feature
sea212 Aug 3, 2023
d015f8d
Revert changes
sea212 Aug 3, 2023
b171c2f
Merge branch 'main' into sea212-upgrade-v0.9.37
sea212 Aug 3, 2023
9420415
Merge branch 'main' into sea212-enable-sc-calls
sea212 Aug 3, 2023
44dcccc
Merge branch 'sea212-upgrade-v0.9.37' into sea212-enable-sc-calls
sea212 Aug 3, 2023
db0b263
Merge branch 'main' into sea212-enable-sc-calls
sea212 Aug 4, 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
91 changes: 79 additions & 12 deletions runtime/battery-station/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use frame_support::{
weights::{constants::RocksDbWeight, ConstantMultiplier, IdentityFee, Weight},
};
use frame_system::EnsureRoot;
use orml_currencies::Call::transfer;
use pallet_collective::{EnsureProportionAtLeast, PrimeDefaultVote};
use pallet_transaction_payment::ChargeTransactionPayment;
use sp_runtime::{
Expand All @@ -56,7 +57,17 @@ use sp_runtime::{
use sp_version::NativeVersion;
use substrate_fixed::{types::extra::U33, FixedI128, FixedU128};
use zeitgeist_primitives::{constants::*, types::*};
use zrml_prediction_markets::Call::{
buy_complete_set, create_cpmm_market_and_deploy_assets, create_market,
deploy_swap_pool_and_additional_liquidity, deploy_swap_pool_for_market, dispute, edit_market,
redeem_shares, report, sell_complete_set, start_global_dispute,
};
use zrml_rikiddo::types::{EmaMarketVolume, FeeSigmoid, RikiddoSigmoidMV};
use zrml_swaps::Call::{
pool_exit, pool_exit_subsidy, pool_exit_with_exact_asset_amount,
pool_exit_with_exact_pool_amount, pool_join, pool_join_with_exact_asset_amount,
pool_join_with_exact_pool_amount, swap_exact_amount_in, swap_exact_amount_out,
};
#[cfg(feature = "parachain")]
use {
frame_support::traits::{AsEnsureOriginWithArg, Everything, Nothing},
Expand Down Expand Up @@ -101,32 +112,88 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
state_version: 1,
};

#[derive(scale_info::TypeInfo)]
pub struct ContractsCallfilter;

impl Contains<RuntimeCall> for ContractsCallfilter {
fn contains(runtime_call: &RuntimeCall) -> bool {
#[allow(clippy::match_like_matches_macro)]
match runtime_call {
RuntimeCall::AssetManager(transfer { .. }) => true,
maltekliemann marked this conversation as resolved.
Show resolved Hide resolved
RuntimeCall::PredictionMarkets(inner_call) => {
match inner_call {
buy_complete_set { .. } => true,
deploy_swap_pool_and_additional_liquidity { .. } => true,
deploy_swap_pool_for_market { .. } => true,
dispute { .. } => true,
// Only allow CPMM markets using Authorized or SimpleDisputes dispute mechanism
create_market {
dispute_mechanism:
MarketDisputeMechanism::Authorized | MarketDisputeMechanism::SimpleDisputes,
scoring_rule: ScoringRule::CPMM,
..
} => true,
create_cpmm_market_and_deploy_assets {
dispute_mechanism:
MarketDisputeMechanism::Authorized | MarketDisputeMechanism::SimpleDisputes,
..
} => true,
edit_market {
dispute_mechanism:
MarketDisputeMechanism::Authorized | MarketDisputeMechanism::SimpleDisputes,
scoring_rule: ScoringRule::CPMM,
..
} => true,
sea212 marked this conversation as resolved.
Show resolved Hide resolved
sea212 marked this conversation as resolved.
Show resolved Hide resolved
redeem_shares { .. } => true,
report { .. } => true,
sell_complete_set { .. } => true,
start_global_dispute { .. } => true,
sea212 marked this conversation as resolved.
Show resolved Hide resolved
_ => false,
}
}
RuntimeCall::Swaps(inner_call) => match inner_call {
pool_exit { .. } => true,
pool_exit_subsidy { .. } => true,
sea212 marked this conversation as resolved.
Show resolved Hide resolved
pool_exit_with_exact_asset_amount { .. } => true,
pool_exit_with_exact_pool_amount { .. } => true,
pool_join { .. } => true,
pool_join_with_exact_asset_amount { .. } => true,
pool_join_with_exact_pool_amount { .. } => true,
swap_exact_amount_in { .. } => true,
swap_exact_amount_out { .. } => true,
_ => false,
},
_ => false,
}
}
}

#[derive(scale_info::TypeInfo)]
pub struct IsCallable;

// Currently disables Court, Rikiddo and creation of markets using Court.
impl Contains<RuntimeCall> for IsCallable {
fn contains(call: &RuntimeCall) -> bool {
use zeitgeist_primitives::types::{
MarketDisputeMechanism::Court, ScoringRule::RikiddoSigmoidFeeMarketEma,
};
sea212 marked this conversation as resolved.
Show resolved Hide resolved
use zrml_prediction_markets::Call::{
create_cpmm_market_and_deploy_assets, create_market, edit_market,
};

#[allow(clippy::match_like_matches_macro)]
match call {
RuntimeCall::Court(_) => false,
RuntimeCall::LiquidityMining(_) => false,
RuntimeCall::PredictionMarkets(inner_call) => {
match inner_call {
// Disable Rikiddo markets
create_market { scoring_rule: RikiddoSigmoidFeeMarketEma, .. } => false,
edit_market { scoring_rule: RikiddoSigmoidFeeMarketEma, .. } => false,
create_market {
scoring_rule: ScoringRule::RikiddoSigmoidFeeMarketEma, ..
} => false,
edit_market {
scoring_rule: ScoringRule::RikiddoSigmoidFeeMarketEma, ..
} => false,
// Disable Court dispute resolution mechanism
create_market { dispute_mechanism: Court, .. } => false,
create_cpmm_market_and_deploy_assets { dispute_mechanism: Court, .. } => false,
edit_market { dispute_mechanism: Court, .. } => false,
create_market { dispute_mechanism: MarketDisputeMechanism::Court, .. } => false,
create_cpmm_market_and_deploy_assets {
dispute_mechanism: MarketDisputeMechanism::Court,
..
} => false,
edit_market { dispute_mechanism: MarketDisputeMechanism::Court, .. } => false,
_ => true,
}
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ macro_rules! impl_config_traits {

impl pallet_contracts::Config for Runtime {
type AddressGenerator = pallet_contracts::DefaultAddressGenerator;
type CallFilter = frame_support::traits::Nothing;
type CallFilter = ContractsCallfilter;
type CallStack = [pallet_contracts::Frame::<Runtime>; 5];
type ChainExtension = ();
type Currency = Balances;
Expand Down
8 changes: 6 additions & 2 deletions runtime/zeitgeist/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ pub use crate::parachain_params::*;
pub use crate::parameters::*;
use alloc::vec;
use frame_support::{
traits::{ConstU16, ConstU32, Contains, EitherOfDiverse, EqualPrivilegeOnly, InstanceFilter},
traits::{
ConstU16, ConstU32, Contains, EitherOfDiverse, EqualPrivilegeOnly, InstanceFilter, Nothing,
},
weights::{constants::RocksDbWeight, ConstantMultiplier, IdentityFee, Weight},
};
use frame_system::EnsureRoot;
Expand All @@ -58,7 +60,7 @@ use zeitgeist_primitives::{constants::*, types::*};
use zrml_rikiddo::types::{EmaMarketVolume, FeeSigmoid, RikiddoSigmoidMV};
#[cfg(feature = "parachain")]
use {
frame_support::traits::{AsEnsureOriginWithArg, Everything, Nothing},
frame_support::traits::{AsEnsureOriginWithArg, Everything},
xcm_builder::{EnsureXcmOrigin, FixedWeightBounds, LocationInverter},
xcm_config::{
asset_registry::CustomAssetProcessor,
Expand Down Expand Up @@ -100,6 +102,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
state_version: 1,
};

pub type ContractsCallfilter = Nothing;
sea212 marked this conversation as resolved.
Show resolved Hide resolved

#[derive(scale_info::TypeInfo)]
pub struct IsCallable;

Expand Down
Loading