Skip to content

Commit

Permalink
ORML comeback (#290)
Browse files Browse the repository at this point in the history
* plain re-inject orml without fixing

* fix build

* fmt
  • Loading branch information
brenzi authored Jun 3, 2024
1 parent 2f1b06c commit 0f155f5
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 2 deletions.
93 changes: 93 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ frame-system = { version = "32.0.0", default-features = false }
frame-system-benchmarking = { version = "32.0.0", default-features = false }
frame-system-rpc-runtime-api = { version = "30.0.0", default-features = false }
frame-try-runtime = { version = "0.38.0", default-features = false }
orml-traits = { version = "0.10", default-features = false }
orml-xcm = { version = "0.10", default-features = false }
orml-xcm-support = { version = "0.10", default-features = false }
orml-xtokens = { version = "0.10", default-features = false }
pallet-asset-conversion = { version = "14.0.0", default-features = false }
pallet-assets = { version = "33.0.0", default-features = false }
pallet-aura = { version = "31.0.0", default-features = false }
Expand Down
11 changes: 11 additions & 0 deletions polkadot-parachains/integritee-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ frame-support = { workspace = true }
frame-system = { workspace = true }
frame-system-rpc-runtime-api = { workspace = true }
frame-try-runtime = { workspace = true, optional = true }
orml-traits = { workspace = true }
orml-xcm = { workspace = true }
orml-xcm-support = { workspace = true }
orml-xtokens = { workspace = true }
pallet-asset-conversion = { workspace = true }
pallet-asset-registry = { workspace = true }
pallet-assets = { workspace = true }
Expand Down Expand Up @@ -119,6 +123,10 @@ std = [
"frame-try-runtime?/std",
"integritee-parachains-common/std",
"log/std",
"orml-traits/std",
"orml-xcm-support/std",
"orml-xcm/std",
"orml-xtokens/std",
"pallet-assets/std",
"pallet-asset-conversion/std",
"pallet-asset-registry/std",
Expand Down Expand Up @@ -183,6 +191,7 @@ runtime-benchmarks = [
"frame-system-benchmarking/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"hex-literal",
"orml-xtokens/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-asset-conversion/runtime-benchmarks",
"pallet-asset-registry/runtime-benchmarks",
Expand Down Expand Up @@ -224,6 +233,8 @@ try-runtime = [
"frame-executive/try-runtime",
"frame-system/try-runtime",
"frame-try-runtime/try-runtime",
"orml-xcm/try-runtime",
"orml-xtokens/try-runtime",
"pallet-assets/try-runtime",
"pallet-asset-conversion/try-runtime",
"pallet-asset-registry/try-runtime",
Expand Down
9 changes: 7 additions & 2 deletions polkadot-parachains/integritee-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,11 @@ impl pallet_democracy::Config for Runtime {
type SubmitOrigin = frame_system::EnsureSigned<AccountId>;
}

impl orml_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type SovereignOrigin = EnsureRoot<AccountId>;
}

pub type AssetBalance = Balance;

/// always denies creation of assets
Expand Down Expand Up @@ -976,8 +981,8 @@ construct_runtime!(
PolkadotXcm: pallet_xcm = 31,
CumulusXcm: cumulus_pallet_xcm = 32,
MessageQueue: pallet_message_queue = 33,
//XTokens: orml_xtokens = 34,
//OrmlXcm: orml_xcm = 35,
XTokens: orml_xtokens = 34,
OrmlXcm: orml_xcm = 35,
XcmTransactor: pallet_xcm_transactor = 36,

// fungibles
Expand Down
82 changes: 82 additions & 0 deletions polkadot-parachains/integritee-runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ use frame_support::{
};
use frame_system::EnsureRoot;
use integritee_parachains_common::xcm_config::IsNativeConcrete;
use orml_traits::{
location::{RelativeReserveProvider, Reserve},
parameter_type_with_key,
};
use pallet_xcm::XcmPassthrough;
use parachains_common::{message_queue::ParaIdToSibling, AssetIdForTrustBackedAssets};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
Expand Down Expand Up @@ -479,3 +483,81 @@ impl Convert<CurrencyId, Option<Location>> for CurrencyIdConvert {
}
}
}

parameter_types! {
pub SelfReserveAlias: Location = Location::new(
0, [TEER_GENERAL_KEY]
);
// This is how we are going to detect whether the asset is a Reserve asset
pub SelfLocation: Location = Location::here();
// We need this to be able to catch when someone is trying to execute a non-
// cross-chain transfer in xtokens through the absolute path way
pub SelfLocationAbsolute: Location = Location::new(
1,
[Parachain(ParachainInfo::parachain_id().into())]
);

}

/// This struct offers uses RelativeReserveProvider to output relative views of Locations
/// However, additionally accepts a Location that aims at representing the chain part
/// (parent: 1, Parachain(paraId)) of the absolute representation of our chain.
/// If a token reserve matches against this absolute view, we return Some(Location::here())
/// This helps users by preventing errors when they try to transfer a token through xtokens
/// to our chain (either inserting the relative or the absolute value).
pub struct AbsoluteAndRelativeReserve<AbsoluteLocation>(PhantomData<AbsoluteLocation>);

impl<AbsoluteLocation> Reserve for AbsoluteAndRelativeReserve<AbsoluteLocation>
where
AbsoluteLocation: Get<Location>,
{
fn reserve(asset: &Asset) -> Option<Location> {
RelativeReserveProvider::reserve(asset).map(|relative_reserve| {
if relative_reserve == AbsoluteLocation::get() {
Location::here()
} else {
relative_reserve
}
})
}
}

pub struct AccountIdToLocation;

impl Convert<AccountId, Location> for AccountIdToLocation {
fn convert(account: AccountId) -> Location {
Location::new(0, [Junction::AccountId32 { network: None, id: account.into() }])
}
}

// The min fee amount in fee asset is split into two parts:
//
// - fee asset sent to fee reserve chain = fee_amount - min_xcm_fee
// - fee asset sent to dest reserve chain = min_xcm_fee
// Check out for more information:
// https://github.com/open-web3-stack/open-runtime-module-library/tree/master/xtokens#transfer-multiple-currencies

parameter_type_with_key! {
pub ParachainMinFee: |_location: Location| -> Option<u128> {
None
};
}

impl orml_xtokens::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type CurrencyId = CurrencyId;
type CurrencyIdConvert = CurrencyIdConvert;
type AccountIdToLocation = AccountIdToLocation;
type SelfLocation = SelfLocation;
type XcmExecutor = XcmExecutor<XcmConfig>;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type BaseXcmWeight = BaseXcmWeight;
type UniversalLocation = UniversalLocation;
type MaxAssetsForTransfer = MaxAssetsForTransfer;
type MinXcmFee = ParachainMinFee;
type LocationsFilter = Everything;
type ReserveProvider = AbsoluteAndRelativeReserve<SelfLocationAbsolute>;
type RateLimiterId = ();
type RateLimiter = ();
}

0 comments on commit 0f155f5

Please sign in to comment.