violet_node_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			..Default::default()
32		},
33		..Default::default()
34	}
35}
36
37parameter_types! {
38	pub const DepositPerItem: Balance = deposit(1, 0);
39	pub const DepositPerByte: Balance = deposit(0, 1);
40	pub Schedule: pallet_contracts::Schedule<Runtime> = schedule::<Runtime>();
41	pub const DefaultDepositLimit: Balance = deposit(1024, 1024 * 1024);
42	pub const CodeHashLockupDepositPercent: Perbill = Perbill::from_percent(0);
43	pub const MaxDelegateDependencies: u32 = 32;
44}
45
46impl pallet_contracts::Config for Runtime {
47	type Time = Timestamp;
48	type Randomness = RandomnessCollectiveFlip;
49	type Currency = Balances;
50	type RuntimeEvent = RuntimeEvent;
51	type RuntimeCall = RuntimeCall;
52
53	/// The safest default is to allow no calls at all.
54	///
55	/// Runtimes should whitelist dispatchables that are allowed to be called from contracts
56	/// and make sure they are stable. Dispatchables exposed to contracts are not allowed to
57	/// change because that would break already deployed contracts. The `RuntimeCall` structure
58	/// itself is not allowed to change the indices of existing pallets, too.
59	type CallFilter = AllowBalancesCall;
60	type DepositPerItem = DepositPerItem;
61	type DepositPerByte = DepositPerByte;
62	type CallStack = [pallet_contracts::Frame<Self>; 23];
63	type WeightPrice = pallet_transaction_payment::Pallet<Self>;
64	type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
65	type ChainExtension = ();
66	type Schedule = Schedule;
67	type AddressGenerator = pallet_contracts::DefaultAddressGenerator;
68	// This node is geared towards development and testing of contracts.
69	// We decided to increase the default allowed contract size for this
70	// reason (the default is `128 * 1024`).
71	//
72	// Our reasoning is that the error code `CodeTooLarge` is thrown
73	// if a too-large contract is uploaded. We noticed that it poses
74	// less friction during development when the requirement here is
75	// just more lax.
76	type MaxCodeLen = ConstU32<{ 256 * 1024 }>;
77	type DefaultDepositLimit = DefaultDepositLimit;
78	type MaxStorageKeyLen = ConstU32<128>;
79	type MaxDebugBufferLen = ConstU32<{ 2 * 1024 * 1024 }>;
80	type UnsafeUnstableInterface = ConstBool<true>;
81	type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
82	type MaxDelegateDependencies = MaxDelegateDependencies;
83	type RuntimeHoldReason = RuntimeHoldReason;
84
85	type Environment = ();
86	type Debug = ();
87	type ApiVersion = ();
88	type Migrations = ();
89	#[cfg(feature = "parachain")]
90	type Xcm = pallet_xcm::Pallet<Self>;
91	#[cfg(not(feature = "parachain"))]
92	type Xcm = ();
93
94	type UploadOrigin = EnsureSigned<Self::AccountId>;
95	type InstantiateOrigin = EnsureSigned<Self::AccountId>;
96}