Skip to content

Commit

Permalink
fix:
Browse files Browse the repository at this point in the history
add new impls.rs to runtime common
add runtime: pallet_asset_rate::Config
fix runtime: pallet_democracy::Config
fix runtime: pallet_preimage::Config
  • Loading branch information
higherordertech committed Nov 25, 2024
1 parent a1ba3b9 commit 34310d2
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 38 deletions.
115 changes: 115 additions & 0 deletions parachain/runtime/common/src/impls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Copyright 2020-2024 Trust Computing GmbH.
// This file is part of Litentry.
//
// Litentry is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Litentry is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Litentry. If not, see <https://www.gnu.org/licenses/>.

/// Adapter for [`Contains`] trait to match [`VersionedLocatableAsset`] type converted to the latest
/// version of itself where it's location matched by `L` and it's asset id by `A` parameter types.
use frame_support::traits::{Contains, ContainsPair};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use sp_runtime::{traits::TryConvert, RuntimeDebug};
use xcm::{latest::{Junction, Junctions}, VersionedLocation};
use xcm_builder::LocatableAssetId;
use cumulus_primitives_core::{AssetId, Location};
use sp_std::sync::Arc;

/// Versioned locatable asset type which contains both an XCM `location` and `asset_id` to identify
/// an asset which exists on some chain.
#[derive(
Encode, Decode, Eq, PartialEq, Clone, RuntimeDebug, scale_info::TypeInfo, MaxEncodedLen,
)]
pub enum VersionedLocatableAsset {
#[codec(index = 3)]
V3 { location: xcm::v3::Location, asset_id: xcm::v3::AssetId },
#[codec(index = 4)]
V4 { location: xcm::v4::Location, asset_id: xcm::v4::AssetId },
}

/// Converts the [`VersionedLocation`] to the [`xcm::latest::Location`].
pub struct VersionedLocationConverter;
impl TryConvert<&VersionedLocation, xcm::latest::Location> for VersionedLocationConverter {
fn try_convert(
location: &VersionedLocation,
) -> Result<xcm::latest::Location, &VersionedLocation> {
let latest = match location.clone() {
VersionedLocation::V2(l) => {
let v3: xcm::v3::Location = l.try_into().map_err(|_| location)?;
v3.try_into().map_err(|_| location)?
},
VersionedLocation::V3(l) => l.try_into().map_err(|_| location)?,
VersionedLocation::V4(l) => l,
};
Ok(latest)
}
}

pub struct ContainsParts<C>(core::marker::PhantomData<C>);
impl<C> Contains<VersionedLocatableAsset> for ContainsParts<C>
where
C: ContainsPair<xcm::latest::Location, xcm::latest::Location>,
{
fn contains(asset: &VersionedLocatableAsset) -> bool {
use VersionedLocatableAsset::*;
let (location, asset_id) = match asset.clone() {
V3 { location, asset_id } => match (location.try_into(), asset_id.try_into()) {
(Ok(l), Ok(a)) => (l, a),
_ => return false,
},
V4 { location, asset_id } => (location, asset_id),
};
C::contains(&location, &asset_id.0)
}
}

/// Converts the [`VersionedLocatableAsset`] to the [`LocatableAssetId`].
pub struct LocatableAssetConverter;
impl TryConvert<VersionedLocatableAsset, LocatableAssetId>
for LocatableAssetConverter
{
fn try_convert(
asset: VersionedLocatableAsset,
) -> Result<LocatableAssetId, VersionedLocatableAsset> {
match asset {
VersionedLocatableAsset::V3 { location, asset_id } =>
Ok(LocatableAssetId {
location: location.try_into().map_err(|_| asset.clone())?,
asset_id: asset_id.try_into().map_err(|_| asset.clone())?,
}),
VersionedLocatableAsset::V4 { location, asset_id } =>
Ok(LocatableAssetId { location, asset_id }),
}
}
}

impl sp_runtime::traits::TryConvert<u32, LocatableAssetId> for LocatableAssetConverter {
fn try_convert(value: u32) -> Result<LocatableAssetId, u32> {
// let location = Location::new(1, Junctions::X1(Arc::new([Junction::Parachain(value)])));
// Ok(LocatableAssetId {
// asset_id: AssetId::from(location.clone()),
// location,
// })
Ok(LocatableAssetId {
asset_id: AssetId::from(Location::default()),
location: Location::default(),
})

}
}

impl<'a> TryConvert<&'a sp_runtime::AccountId32, Location> for VersionedLocationConverter {
fn try_convert(value: &'a sp_runtime::AccountId32) -> Result<Location, &'a sp_runtime::AccountId32> {
Ok(Location::default())
}
}
4 changes: 4 additions & 0 deletions parachain/runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extern crate core;
#[cfg(feature = "tests")]
pub mod tests;

pub mod impls;
pub mod xcm_impl;

#[cfg(feature = "runtime-benchmarks")]
Expand Down Expand Up @@ -333,3 +334,6 @@ where
}

pub type EnsureOmniAccount = pallet_omni_account::EnsureOmniAccount<AccountId>;

/// The type for looking up accounts. We don't expect more than 4 billion of them.
pub type AccountIndex = u32;
32 changes: 23 additions & 9 deletions parachain/runtime/litentry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
extern crate frame_benchmarking;

use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
use cumulus_primitives_core::{AggregateMessageOrigin, InteriorLocation, PalletInstance, ParaId};
use frame_support::{
construct_runtime, dynamic_params::{dynamic_pallet_params, dynamic_params}, parameter_types,
construct_runtime, parameter_types,
traits::{
tokens::UnityOrOuterConversion, ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, Contains, EnsureOrigin, Everything,
FindAuthor, InstanceFilter, OnFinalize, SortedMembers, TransformOrigin, WithdrawReasons,
FindAuthor, FromContains, InstanceFilter, OnFinalize, SortedMembers, TransformOrigin, WithdrawReasons,
},
weights::{constants::RocksDbWeight, ConstantMultiplier, Weight},
ConsensusEngineId, PalletId,
Expand Down Expand Up @@ -68,7 +68,7 @@ pub use core_primitives::{
};
pub use runtime_common::currency::*;
use runtime_common::{
impl_runtime_transaction_payment_fees, prod_or_fast, BlockHashCount, BlockLength,
impl_runtime_transaction_payment_fees, prod_or_fast, AccountIndex, BlockHashCount, BlockLength,
CouncilInstance, CouncilMembershipInstance, DeveloperCommitteeInstance,
DeveloperCommitteeMembershipInstance, EnsureEnclaveSigner, EnsureOmniAccount,
EnsureRootOrAllCouncil, EnsureRootOrAllTechnicalCommittee, EnsureRootOrHalfCouncil,
Expand Down Expand Up @@ -278,6 +278,18 @@ impl frame_system::Config for Runtime {
type PostTransactions = ();
}

impl pallet_asset_rate::Config for Runtime {
type WeightInfo = weights::pallet_asset_rate::WeightInfo<Runtime>;
type RuntimeEvent = RuntimeEvent;
type CreateOrigin = EnsureRoot<AccountId>;
type RemoveOrigin = EnsureRoot<AccountId>;
type UpdateOrigin = EnsureRoot<AccountId>;
type Currency = Balances;
type AssetKind = <Runtime as pallet_treasury::Config>::AssetKind;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = runtime_common::impls::benchmarks::AssetRateArguments;
}

parameter_types! {
// One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes.
pub const DepositBase: Balance = deposit(1, 88);
Expand Down Expand Up @@ -432,6 +444,7 @@ impl pallet_scheduler::Config for Runtime {
parameter_types! {
pub const PreimageMaxSize: u32 = 4096 * 1024;
pub const PreimageBaseDeposit: Balance = 1 * DOLLARS;
pub const PreimageByteDeposit: Balance = 1 * CENTS;
pub const PreimageHoldReason: RuntimeHoldReason = RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage);
}

Expand All @@ -445,8 +458,8 @@ impl pallet_preimage::Config for Runtime {
Balances,
PreimageHoldReason,
frame_support::traits::LinearStoragePrice<
dynamic_params::preimage::BaseDeposit,
dynamic_params::preimage::ByteDeposit,
PreimageBaseDeposit,
PreimageByteDeposit,
Balance,
>,
>;
Expand Down Expand Up @@ -517,7 +530,6 @@ parameter_types! {
pub const MinimumDeposit: Balance = 100 * DOLLARS;
pub EnactmentPeriod: BlockNumber = prod_or_fast!(1 * DAYS, 2 * MINUTES, "LITENTRY_ENACTMENTPERIOD");
pub CooloffPeriod: BlockNumber = prod_or_fast!(5 * DAYS, 2 * MINUTES, "LITENTRY_COOLOFFPERIOD");
pub const PreimageByteDeposit: Balance = deposit(0, 1);
}

impl pallet_democracy::Config for Runtime {
Expand Down Expand Up @@ -712,7 +724,7 @@ impl pallet_treasury::Config for Runtime {
type Paymaster = PayOverXcm<
TreasuryInteriorLocation,
crate::xcm_config::XcmRouter,
crate::XcmPallet,
crate::PolkadotXcm,
ConstU32<{ 6 * HOURS }>,
Self::Beneficiary,
Self::AssetKind,
Expand Down Expand Up @@ -938,7 +950,7 @@ impl pallet_vesting::Config for Runtime {
// highest number of schedules that encodes less than 2^10.
const MAX_VESTING_SCHEDULES: u32 = 28;
type UnvestedFundsAllowedWithdrawReasons = UnvestedFundsAllowedWithdrawReasons;
type BlockNumberProvider: BlockNumberProvider<BlockNumber = BlockNumberFor<Self>>;
type BlockNumberProvider = System;
}

parameter_types! {
Expand Down Expand Up @@ -1252,6 +1264,8 @@ construct_runtime! {
ParachainSystem: cumulus_pallet_parachain_system = 30,
ParachainInfo: parachain_info = 31,

AssetRate: pallet_asset_rate = 39,

// Collator support
// About the order of these 5 pallets, the comment in cumulus seems to be outdated.
//
Expand Down
32 changes: 23 additions & 9 deletions parachain/runtime/paseo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ extern crate frame_benchmarking;

use core_primitives::LITENTRY_PARA_ID;
use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
use cumulus_primitives_core::{AggregateMessageOrigin, InteriorLocation, PalletInstance, ParaId};
use frame_support::{
construct_runtime, dynamic_params::{dynamic_pallet_params, dynamic_params}, parameter_types,
construct_runtime, parameter_types,
traits::{
tokens::UnityOrOuterConversion, ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, Contains, ContainsLengthBound,
EnsureOrigin, Everything, FindAuthor, InstanceFilter, OnFinalize, SortedMembers, TransformOrigin,
EnsureOrigin, Everything, FindAuthor, FromContains, InstanceFilter, OnFinalize, SortedMembers, TransformOrigin,
WithdrawReasons,
},
weights::{constants::RocksDbWeight, ConstantMultiplier, Weight},
Expand Down Expand Up @@ -79,7 +79,7 @@ pub use core_primitives::{
pub use runtime_common::currency::*;

use runtime_common::{
impl_runtime_transaction_payment_fees, prod_or_fast, BlockHashCount, BlockLength,
impl_runtime_transaction_payment_fees, prod_or_fast, AccountIndex, BlockHashCount, BlockLength,
CouncilInstance, CouncilMembershipInstance, DeveloperCommitteeInstance,
DeveloperCommitteeMembershipInstance, EnsureOmniAccount, EnsureRootOrAllCouncil,
EnsureRootOrAllTechnicalCommittee, EnsureRootOrHalfCouncil, EnsureRootOrHalfTechnicalCommittee,
Expand Down Expand Up @@ -287,6 +287,18 @@ impl frame_system::Config for Runtime {
type PostTransactions = ();
}

impl pallet_asset_rate::Config for Runtime {
type WeightInfo = weights::pallet_asset_rate::WeightInfo<Runtime>;
type RuntimeEvent = RuntimeEvent;
type CreateOrigin = EnsureRoot<AccountId>;
type RemoveOrigin = EnsureRoot<AccountId>;
type UpdateOrigin = EnsureRoot<AccountId>;
type Currency = Balances;
type AssetKind = <Runtime as pallet_treasury::Config>::AssetKind;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = runtime_common::impls::benchmarks::AssetRateArguments;
}

parameter_types! {
// One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes.
pub const DepositBase: Balance = deposit(1, 88);
Expand Down Expand Up @@ -442,6 +454,7 @@ impl pallet_scheduler::Config for Runtime {
parameter_types! {
pub const PreimageMaxSize: u32 = 4096 * 1024;
pub const PreimageBaseDeposit: Balance = 1 * DOLLARS;
pub const PreimageByteDeposit: Balance = 1 * CENTS;
pub const PreimageHoldReason: RuntimeHoldReason = RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage);
}

Expand All @@ -455,8 +468,8 @@ impl pallet_preimage::Config for Runtime {
Balances,
PreimageHoldReason,
frame_support::traits::LinearStoragePrice<
dynamic_params::preimage::BaseDeposit,
dynamic_params::preimage::ByteDeposit,
PreimageBaseDeposit,
PreimageByteDeposit,
Balance,
>,
>;
Expand Down Expand Up @@ -527,7 +540,6 @@ parameter_types! {
pub const MinimumDeposit: Balance = 100 * DOLLARS;
pub EnactmentPeriod: BlockNumber = prod_or_fast!(5 * MINUTES, 2 * MINUTES, "ROCOCO_ENACTMENTPERIOD");
pub CooloffPeriod: BlockNumber = prod_or_fast!(10 * MINUTES, 2 * MINUTES, "ROCOCO_COOLOFFPERIOD");
pub const PreimageByteDeposit: Balance = deposit(0, 1);
}

impl pallet_democracy::Config for Runtime {
Expand Down Expand Up @@ -725,7 +737,7 @@ impl pallet_treasury::Config for Runtime {
type Paymaster = PayOverXcm<
TreasuryInteriorLocation,
crate::xcm_config::XcmRouter,
crate::XcmPallet,
crate::PolkadotXcm,
ConstU32<{ 6 * HOURS }>,
Self::Beneficiary,
Self::AssetKind,
Expand Down Expand Up @@ -979,7 +991,7 @@ impl pallet_vesting::Config for Runtime {
// highest number of schedules that encodes less than 2^10.
const MAX_VESTING_SCHEDULES: u32 = 28;
type UnvestedFundsAllowedWithdrawReasons = UnvestedFundsAllowedWithdrawReasons;
type BlockNumberProvider: BlockNumberProvider<BlockNumber = BlockNumberFor<Self>>;
type BlockNumberProvider = System;
}

parameter_types! {
Expand Down Expand Up @@ -1292,6 +1304,8 @@ construct_runtime! {
ParachainSystem: cumulus_pallet_parachain_system = 30,
ParachainInfo: parachain_info = 31,

AssetRate: pallet_asset_rate = 39,

// Collator support
// About the order of these 5 pallets, the comment in cumulus seems to be outdated.
//
Expand Down
Loading

0 comments on commit 34310d2

Please sign in to comment.