phink_lib/contract/
runtime.rs

1// This is a Substrate runtime configuration that includes the `pallet_contracts`
2// to execute ink! smart contracts. However, this runtime configuration is flexible
3// and the `pallet_contracts` can be replaced or customized as needed. The design
4// allows for the combination of multiple pallets to tailor blockchain functionalities
5// to specific use cases. Developers are encouraged to modify the types and behaviors
6// according to their project requirements while retaining essential components.
7
8use crate::contract::remote::BalanceOf;
9use frame_support::{
10    construct_runtime,
11    derive_impl,
12    parameter_types,
13    traits,
14    traits::{
15        ConstU16,
16        ConstU32,
17    },
18    weights::{
19        constants::RocksDbWeight,
20        ConstantMultiplier,
21        IdentityFee,
22    },
23};
24use frame_system::EnsureSigned;
25pub use pallet_transaction_payment::{
26    Multiplier,
27    TargetedFeeAdjustment,
28};
29use sp_core::ConstBool;
30use sp_runtime::{
31    generic,
32    testing::H256,
33    traits::{
34        BlakeTwo256,
35        Bounded,
36        IdentifyAccount,
37        IdentityLookup,
38        Verify,
39    },
40    FixedPointNumber,
41    MultiSignature,
42    Perbill,
43    Perquintill,
44};
45use traits::Nothing;
46
47pub type BlockNumber = u32;
48
49pub type Signature = MultiSignature;
50
51pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
52
53pub type Balance = u128;
54
55pub type Moment = u64;
56
57pub type Nonce = u32;
58
59pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
60
61pub type SignedExtra = (
62    frame_system::CheckNonZeroSender<Runtime>,
63    frame_system::CheckSpecVersion<Runtime>,
64    frame_system::CheckTxVersion<Runtime>,
65    frame_system::CheckGenesis<Runtime>,
66    frame_system::CheckEra<Runtime>,
67    frame_system::CheckNonce<Runtime>,
68    frame_system::CheckWeight<Runtime>,
69    pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
70);
71
72pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
73
74pub type UncheckedExtrinsic =
75    generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
76
77pub type Block = generic::Block<Header, UncheckedExtrinsic>;
78
79pub const MILLISECS_PER_BLOCK: Moment = 3000;
80pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK;
81pub const MILLICENTS: Balance = 1_000_000_000;
82
83impl pallet_insecure_randomness_collective_flip::Config for Runtime {}
84parameter_types! {
85    pub static DepositPerByte: BalanceOf<Runtime> = 1;
86    pub const DepositPerItem: BalanceOf<Runtime> = 2;
87    pub static DefaultDepositLimit: BalanceOf<Runtime> = 10_000_000;
88    pub const MaxDelegateDependencies: u32 = 32;
89    pub const CodeHashLockupDepositPercent: Perbill = Perbill::from_percent(10);
90    pub Schedule: pallet_contracts::Schedule<Runtime> = Default::default();
91    pub const MinimumPeriod: Moment = SLOT_DURATION / 2;
92        pub const TransactionByteFee: Balance = 10 * MILLICENTS;
93    pub const OperationalFeeMultiplier: u8 = 5;
94    pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25);
95    pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(1, 100_000);
96    pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000_000u128);
97    pub MaximumMultiplier: Multiplier = Bounded::max_value();
98         pub static ExistentialDeposit: u64 = 1;
99    pub const MaxLocks: u32 = 50;
100    pub const MaxReserves: u32 = 50;
101    pub const BlockHashCount: BlockNumber = 100;
102
103}
104#[derive_impl(frame_system::config_preludes::SolochainDefaultConfig as frame_system::DefaultConfig)]
105impl frame_system::Config for Runtime {
106    type BaseCallFilter = traits::Everything;
107    type BlockWeights = ();
108    type BlockLength = ();
109    type DbWeight = RocksDbWeight;
110    type Nonce = Nonce;
111    type Hash = H256;
112    type Hashing = BlakeTwo256;
113
114    type AccountId = AccountId;
115    type Lookup = IdentityLookup<Self::AccountId>;
116    type Block = Block;
117    type BlockHashCount = BlockHashCount;
118    type Version = ();
119    type AccountData = pallet_balances::AccountData<Balance>;
120    type SystemWeightInfo = frame_system::weights::SubstrateWeight<Runtime>;
121    type SS58Prefix = ConstU16<42>;
122    type MaxConsumers = ConstU32<16>;
123}
124
125impl pallet_balances::Config for Runtime {
126    type RuntimeEvent = RuntimeEvent;
127    type RuntimeHoldReason = RuntimeHoldReason;
128    type RuntimeFreezeReason = RuntimeFreezeReason;
129    type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
130    type Balance = Balance;
131    type DustRemoval = ();
132    type ExistentialDeposit = ExistentialDeposit;
133    type AccountStore = frame_system::Pallet<Runtime>;
134    type ReserveIdentifier = [u8; 8];
135    type FreezeIdentifier = RuntimeFreezeReason;
136    type MaxLocks = MaxLocks;
137    type MaxReserves = MaxReserves;
138    type MaxFreezes = ConstU32<1>;
139}
140
141impl pallet_transaction_payment::Config for Runtime {
142    type RuntimeEvent = RuntimeEvent;
143    #[allow(deprecated)]
144    type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>;
145    type WeightToFee = IdentityFee<Balance>;
146    type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
147    type FeeMultiplierUpdate = TargetedFeeAdjustment<
148        Self,
149        TargetBlockFullness,
150        AdjustmentVariable,
151        MinimumMultiplier,
152        MaximumMultiplier,
153    >;
154    type OperationalFeeMultiplier = OperationalFeeMultiplier;
155}
156
157impl pallet_timestamp::Config for Runtime {
158    type Moment = Moment;
159    type OnTimestampSet = ();
160    type MinimumPeriod = MinimumPeriod;
161    type WeightInfo = pallet_timestamp::weights::SubstrateWeight<Runtime>;
162}
163
164impl pallet_contracts::Config for Runtime {
165    type Time = Timestamp;
166    type Randomness = Randomness;
167    type Currency = Balances;
168    type RuntimeEvent = RuntimeEvent;
169    type RuntimeCall = RuntimeCall;
170    type RuntimeHoldReason = RuntimeHoldReason;
171    type CallFilter = Nothing;
172    type WeightPrice = pallet_transaction_payment::Pallet<Self>;
173    type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
174    type ChainExtension = ();
175    type Schedule = Schedule;
176    type CallStack = [pallet_contracts::Frame<Self>; 5];
177    type DepositPerByte = DepositPerByte;
178    type DefaultDepositLimit = DefaultDepositLimit;
179    type DepositPerItem = DepositPerItem;
180    type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
181    type AddressGenerator = pallet_contracts::DefaultAddressGenerator;
182    #[cfg(test)] // Bypass crashes for integrity tests
183    type MaxCodeLen = ConstU32<128500>;
184    #[cfg(not(test))]
185    type MaxCodeLen = ConstU32<{ u32::MAX }>;
186    type MaxStorageKeyLen = ConstU32<128>;
187    type MaxTransientStorageSize = ConstU32<{ 1024 * 1024 }>;
188    type MaxDelegateDependencies = MaxDelegateDependencies;
189    /// `UnsafeUnstableInterface` must **always** be `true` in order to get proper coverage feedback
190    type UnsafeUnstableInterface = ConstBool<true>;
191    type MaxDebugBufferLen = ConstU32<{ u32::MAX }>;
192    type UploadOrigin = EnsureSigned<Self::AccountId>;
193    type InstantiateOrigin = EnsureSigned<Self::AccountId>;
194    type Migrations = ();
195    type Debug = ();
196    type Environment = ();
197    type ApiVersion = ();
198    type Xcm = ();
199}
200
201construct_runtime!(
202    pub enum Runtime {
203        System: frame_system,
204        Timestamp: pallet_timestamp,
205        Balances: pallet_balances,
206        TransactionPayment: pallet_transaction_payment,
207        Randomness: pallet_insecure_randomness_collective_flip,
208        Contracts: pallet_contracts
209    }
210);