contracts_parachain_runtime/
contracts_config.rs

1use crate::{
2	Balance, Balances, BalancesCall, Perbill, RandomnessCollectiveFlip, Runtime, RuntimeCall,
3	RuntimeEvent, RuntimeHoldReason, Timestamp,
4};
5use frame_support::{
6	parameter_types,
7	traits::{ConstBool, ConstU32},
8};
9use frame_system::EnsureSigned;
10
11pub enum AllowBalancesCall {}
12
13impl frame_support::traits::Contains<RuntimeCall> for AllowBalancesCall {
14	fn contains(call: &RuntimeCall) -> bool {
15		matches!(call, RuntimeCall::Balances(BalancesCall::transfer_allow_death { .. }))
16	}
17}
18
19// Unit = the base number of indivisible units for balances
20const UNIT: Balance = 1_000_000_000_000;
21const MILLIUNIT: Balance = 1_000_000_000;
22
23const fn deposit(items: u32, bytes: u32) -> Balance {
24	(items as Balance * UNIT + (bytes as Balance) * (5 * MILLIUNIT / 100)) / 10
25}
26
27fn schedule<T: pallet_contracts::Config>() -> pallet_contracts::Schedule<T> {
28	pallet_contracts::Schedule {
29		limits: pallet_contracts::Limits {
30			runtime_memory: 1024 * 1024 * 1024,
31			validator_runtime_memory: 1024 * 1024 * 1024 * 2,
32			..Default::default()
33		},
34		..Default::default()
35	}
36}
37
38parameter_types! {
39	pub const DepositPerItem: Balance = deposit(1, 0);
40	pub const DepositPerByte: Balance = deposit(0, 1);
41	pub Schedule: pallet_contracts::Schedule<Runtime> = schedule::<Runtime>();
42	pub const DefaultDepositLimit: Balance = deposit(1024, 1024 * 1024);
43	pub const CodeHashLockupDepositPercent: Perbill = Perbill::from_percent(0);
44	pub const MaxDelegateDependencies: u32 = 32;
45}
46
47impl pallet_contracts::Config for Runtime {
48	type Time = Timestamp;
49	type Randomness = RandomnessCollectiveFlip;
50	type Currency = Balances;
51	type RuntimeEvent = RuntimeEvent;
52	type RuntimeCall = RuntimeCall;
53
54	/// The safest default is to allow no calls at all.
55	///
56	/// Runtimes should whitelist dispatchables that are allowed to be called from contracts
57	/// and make sure they are stable. Dispatchables exposed to contracts are not allowed to
58	/// change because that would break already deployed contracts. The `RuntimeCall` structure
59	/// itself is not allowed to change the indices of existing pallets, too.
60	type CallFilter = AllowBalancesCall;
61	type DepositPerItem = DepositPerItem;
62	type DepositPerByte = DepositPerByte;
63	type CallStack = [pallet_contracts::Frame<Self>; 23];
64	type WeightPrice = pallet_transaction_payment::Pallet<Self>;
65	type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
66	type ChainExtension = ();
67	type Schedule = Schedule;
68	type AddressGenerator = pallet_contracts::DefaultAddressGenerator;
69	// This node is geared towards development and testing of contracts.
70	// We decided to increase the default allowed contract size for this
71	// reason (the default is `128 * 1024`).
72	//
73	// Our reasoning is that the error code `CodeTooLarge` is thrown
74	// if a too-large contract is uploaded. We noticed that it poses
75	// less friction during development when the requirement here is
76	// just more lax.
77	type MaxCodeLen = ConstU32<{ 256 * 1024 }>;
78	type DefaultDepositLimit = DefaultDepositLimit;
79	type MaxStorageKeyLen = ConstU32<128>;
80	type MaxTransientStorageSize = ConstU32<{ 1024 * 1024 }>;
81	type MaxDebugBufferLen = ConstU32<{ 2 * 1024 * 1024 }>;
82	type UnsafeUnstableInterface = ConstBool<true>;
83	type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
84	type MaxDelegateDependencies = MaxDelegateDependencies;
85	type RuntimeHoldReason = RuntimeHoldReason;
86
87	type Environment = ();
88	type Debug = ();
89	type ApiVersion = ();
90	type Migrations = ();
91	#[cfg(feature = "parachain")]
92	type Xcm = pallet_xcm::Pallet<Self>;
93	#[cfg(not(feature = "parachain"))]
94	type Xcm = ();
95
96	type UploadOrigin = EnsureSigned<Self::AccountId>;
97	type InstantiateOrigin = EnsureSigned<Self::AccountId>;
98}