mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
Integrate ink!
This commit is contained in:
@@ -29,10 +29,15 @@ frame-system = { git = "https://github.com/serai-dex/substrate", default-feature
|
||||
frame-executive = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
frame-try-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false, optional = true }
|
||||
|
||||
pallet-randomness-collective-flip = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
pallet-timestamp = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
pallet-balances = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
pallet-transaction-payment = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
|
||||
pallet-contracts-primitives = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
pallet-contracts = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
pallet-contracts-rpc-runtime-api = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
|
||||
# Used for the node template's RPCs
|
||||
frame-system-rpc-runtime-api = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
@@ -65,10 +70,15 @@ std = [
|
||||
"frame-system/std",
|
||||
"frame-executive/std",
|
||||
|
||||
"pallet-randomness-collective-flip/std",
|
||||
"pallet-timestamp/std",
|
||||
"pallet-balances/std",
|
||||
"pallet-transaction-payment/std",
|
||||
"pallet-transaction-payment-rpc-runtime-api/std",
|
||||
|
||||
"pallet-contracts/std",
|
||||
"pallet-contracts-primitives/std",
|
||||
"pallet-contracts-rpc-runtime-api/std",
|
||||
]
|
||||
|
||||
runtime-benchmarks = [
|
||||
@@ -87,6 +97,7 @@ try-runtime = [
|
||||
"frame-try-runtime",
|
||||
"frame-system/try-runtime",
|
||||
|
||||
"pallet-randomness-collective-flip/try-runtime",
|
||||
"pallet-timestamp/try-runtime",
|
||||
"pallet-balances/try-runtime",
|
||||
"pallet-transaction-payment/try-runtime",
|
||||
|
||||
@@ -18,17 +18,19 @@ use sp_version::NativeVersion;
|
||||
use sp_version::RuntimeVersion;
|
||||
|
||||
use frame_support::{
|
||||
traits::{ConstU8, ConstU32, ConstU64},
|
||||
traits::{OnRuntimeUpgrade, ConstU8, ConstU32, ConstU64},
|
||||
weights::{
|
||||
constants::{RocksDbWeight, WEIGHT_PER_SECOND},
|
||||
IdentityFee,
|
||||
constants::{RocksDbWeight, ExtrinsicBaseWeight, BlockExecutionWeight, WEIGHT_PER_SECOND},
|
||||
IdentityFee, Weight, DispatchClass,
|
||||
},
|
||||
parameter_types, construct_runtime,
|
||||
};
|
||||
pub use frame_system::Call as SystemCall;
|
||||
|
||||
pub use pallet_timestamp::Call as TimestampCall;
|
||||
pub use pallet_balances::Call as BalancesCall;
|
||||
use pallet_transaction_payment::CurrencyAdapter;
|
||||
use pallet_contracts::{migration, DefaultContractAccessWeight};
|
||||
|
||||
/// An index to a block
|
||||
pub type BlockNumber = u32;
|
||||
@@ -90,15 +92,64 @@ pub fn native_version() -> NativeVersion {
|
||||
|
||||
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
|
||||
|
||||
/// We assume that ~10% of the block weight is consumed by `on_initialize` handlers.
|
||||
/// This is used to limit the maximal weight of a single extrinsic.
|
||||
const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
|
||||
|
||||
/// We allow for 2 seconds of compute with a 6 second average block time.
|
||||
const MAXIMUM_BLOCK_WEIGHT: Weight = 2 * WEIGHT_PER_SECOND;
|
||||
|
||||
// Prints debug output of the `contracts` pallet to stdout if the node is
|
||||
// started with `-lruntime::contracts=debug`.
|
||||
const CONTRACTS_DEBUG_OUTPUT: bool = true;
|
||||
|
||||
// Unit = the base number of indivisible units for balances
|
||||
const UNIT: Balance = 1_000_000_000_000;
|
||||
const MILLIUNIT: Balance = 1_000_000_000;
|
||||
|
||||
const fn deposit(items: u32, bytes: u32) -> Balance {
|
||||
(items as Balance * UNIT + (bytes as Balance) * (5 * MILLIUNIT / 100)) / 10
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const BlockHashCount: BlockNumber = 2400;
|
||||
pub const Version: RuntimeVersion = VERSION;
|
||||
/// Allow for 2 seconds of compute with a 6 second average block time
|
||||
pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights
|
||||
::with_sensible_defaults(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
|
||||
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
|
||||
::max_with_normal_ratio(1024 * 1024, NORMAL_DISPATCH_RATIO);
|
||||
|
||||
pub const SS58Prefix: u8 = 42; // TODO: Remove
|
||||
|
||||
// 1 MB block size limit
|
||||
pub BlockLength: frame_system::limits::BlockLength =
|
||||
frame_system::limits::BlockLength::max_with_normal_ratio(1024 * 1024, NORMAL_DISPATCH_RATIO);
|
||||
pub BlockWeights: frame_system::limits::BlockWeights =
|
||||
frame_system::limits::BlockWeights::builder()
|
||||
.base_block(BlockExecutionWeight::get())
|
||||
.for_class(DispatchClass::all(), |weights| {
|
||||
weights.base_extrinsic = ExtrinsicBaseWeight::get();
|
||||
})
|
||||
.for_class(DispatchClass::Normal, |weights| {
|
||||
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
|
||||
})
|
||||
.for_class(DispatchClass::Operational, |weights| {
|
||||
weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
|
||||
// Operational transactions have some extra reserved space, so that they
|
||||
// are included even if block reached `MAXIMUM_BLOCK_WEIGHT`.
|
||||
weights.reserved = Some(
|
||||
MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT
|
||||
);
|
||||
})
|
||||
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
|
||||
.build_or_panic();
|
||||
|
||||
pub const DepositPerItem: Balance = deposit(1, 0);
|
||||
pub const DepositPerByte: Balance = deposit(0, 1);
|
||||
pub const DeletionQueueDepth: u32 = 128;
|
||||
// The lazy deletion runs inside on_initialize.
|
||||
pub DeletionWeightLimit: Weight = BlockWeights::get()
|
||||
.per_class
|
||||
.get(DispatchClass::Normal)
|
||||
.max_total
|
||||
.unwrap_or(BlockWeights::get().max_block);
|
||||
pub Schedule: pallet_contracts::Schedule<Runtime> = Default::default();
|
||||
}
|
||||
|
||||
impl frame_system::Config for Runtime {
|
||||
@@ -131,6 +182,8 @@ impl frame_system::Config for Runtime {
|
||||
type MaxConsumers = frame_support::traits::ConstU32<16>;
|
||||
}
|
||||
|
||||
impl pallet_randomness_collective_flip::Config for Runtime {}
|
||||
|
||||
impl pallet_timestamp::Config for Runtime {
|
||||
type Moment = u64;
|
||||
type OnTimestampSet = ();
|
||||
@@ -159,6 +212,44 @@ impl pallet_transaction_payment::Config for Runtime {
|
||||
type FeeMultiplierUpdate = ();
|
||||
}
|
||||
|
||||
impl pallet_contracts::Config for Runtime {
|
||||
type Time = Timestamp;
|
||||
type Randomness = RandomnessCollectiveFlip;
|
||||
type Currency = Balances;
|
||||
type Event = Event;
|
||||
type Call = Call;
|
||||
|
||||
/// The safest default is to allow no calls at all.
|
||||
///
|
||||
/// Runtimes should whitelist dispatchables that are allowed to be called from contracts
|
||||
/// and make sure they are stable. Dispatchables exposed to contracts are not allowed to
|
||||
/// change because that would break already deployed contracts. The `Call` structure itself
|
||||
/// is not allowed to change the indices of existing pallets, too.
|
||||
type CallFilter = frame_support::traits::Nothing;
|
||||
type DepositPerItem = DepositPerItem;
|
||||
type DepositPerByte = DepositPerByte;
|
||||
type CallStack = [pallet_contracts::Frame<Self>; 31];
|
||||
type WeightPrice = pallet_transaction_payment::Pallet<Self>;
|
||||
type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
|
||||
type ChainExtension = ();
|
||||
type DeletionQueueDepth = DeletionQueueDepth;
|
||||
type DeletionWeightLimit = DeletionWeightLimit;
|
||||
type Schedule = Schedule;
|
||||
type AddressGenerator = pallet_contracts::DefaultAddressGenerator;
|
||||
type ContractAccessWeight = DefaultContractAccessWeight<BlockWeights>;
|
||||
|
||||
type MaxCodeLen = ConstU32<{ 128 * 1024 }>;
|
||||
type RelaxedMaxCodeLen = ConstU32<{ 256 * 1024 }>;
|
||||
type MaxStorageKeyLen = ConstU32<128>;
|
||||
}
|
||||
|
||||
pub struct Migrations;
|
||||
impl OnRuntimeUpgrade for Migrations {
|
||||
fn on_runtime_upgrade() -> Weight {
|
||||
migration::migrate::<Runtime>()
|
||||
}
|
||||
}
|
||||
|
||||
pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
|
||||
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
||||
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
|
||||
@@ -189,9 +280,11 @@ construct_runtime!(
|
||||
UncheckedExtrinsic = UncheckedExtrinsic
|
||||
{
|
||||
System: frame_system,
|
||||
RandomnessCollectiveFlip: pallet_randomness_collective_flip,
|
||||
Timestamp: pallet_timestamp,
|
||||
Balances: pallet_balances,
|
||||
TransactionPayment: pallet_transaction_payment
|
||||
TransactionPayment: pallet_transaction_payment,
|
||||
Contracts: pallet_contracts,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -364,6 +457,65 @@ impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber, Hash>
|
||||
for Runtime
|
||||
{
|
||||
fn call(
|
||||
origin: AccountId,
|
||||
dest: AccountId,
|
||||
value: Balance,
|
||||
gas_limit: u64,
|
||||
storage_deposit_limit: Option<Balance>,
|
||||
input_data: Vec<u8>,
|
||||
) -> pallet_contracts_primitives::ContractExecResult<Balance> {
|
||||
Contracts::bare_call(
|
||||
origin,
|
||||
dest,
|
||||
value,
|
||||
gas_limit,
|
||||
storage_deposit_limit,
|
||||
input_data,
|
||||
CONTRACTS_DEBUG_OUTPUT
|
||||
)
|
||||
}
|
||||
|
||||
fn instantiate(
|
||||
origin: AccountId,
|
||||
value: Balance,
|
||||
gas_limit: u64,
|
||||
storage_deposit_limit: Option<Balance>,
|
||||
code: pallet_contracts_primitives::Code<Hash>,
|
||||
data: Vec<u8>,
|
||||
salt: Vec<u8>,
|
||||
) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, Balance> {
|
||||
Contracts::bare_instantiate(
|
||||
origin,
|
||||
value,
|
||||
gas_limit,
|
||||
storage_deposit_limit,
|
||||
code,
|
||||
data,
|
||||
salt,
|
||||
CONTRACTS_DEBUG_OUTPUT
|
||||
)
|
||||
}
|
||||
|
||||
fn upload_code(
|
||||
origin: AccountId,
|
||||
code: Vec<u8>,
|
||||
storage_deposit_limit: Option<Balance>,
|
||||
) -> pallet_contracts_primitives::CodeUploadResult<Hash, Balance> {
|
||||
Contracts::bare_upload_code(origin, code, storage_deposit_limit)
|
||||
}
|
||||
|
||||
fn get_storage(
|
||||
address: AccountId,
|
||||
key: Vec<u8>,
|
||||
) -> pallet_contracts_primitives::GetStorageResult {
|
||||
Contracts::get_storage(address, key)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
impl frame_try_runtime::TryRuntime<Block> for Runtime {
|
||||
fn on_runtime_upgrade() -> (Weight, Weight) {
|
||||
|
||||
Reference in New Issue
Block a user