From b3ebe07cdd5deffa2ee338c8a925668dfda58480 Mon Sep 17 00:00:00 2001 From: str-mv Date: Mon, 17 Jan 2022 08:19:57 +0000 Subject: [PATCH] Karura --- --- a/README.md +++ b/README.md @@ -333,3 +333,35 @@ */ ``` + + +## Karura token transfer + +To get started, you need to open the hrmr channel. +Next, we need to register our asset in Karura. + +assetRegistry -> registerForeignAsset(location, metadata) +location: + V0(X2(Parent, Parachain(PARA_ID))) +metadata: + name OPL + symbol OPL + decimals 15 +minimalBalance 1 + +Next, we can send tokens of our chain: +polkadotXcm -> reserveTransferAssets +dest: + V0(X2(Parent, Parachain(KARURA_PARA_ID))) +beneficiary: + X1(AccountId(Any, ACCOUNT)) +assets: + V1(Concrete(0,Here), Fungible(AMOUNT)) +feeAssetItem: + 0 +weightLimit: + Limit + + +The result will be displayed in ChainState +tokens -> accounts --- a/launch-config.json +++ b/launch-config.json @@ -9,7 +9,8 @@ "rpcPort": 9843, "port": 30444, "flags": [ - "-lparachain::candidate_validation=debug" + "-lparachain::candidate_validation=debug", + "-lxcm=trace" ] }, { @@ -18,7 +19,8 @@ "rpcPort": 9854, "port": 30555, "flags": [ - "-lparachain::candidate_validation=debug" + "-lparachain::candidate_validation=debug", + "-lxcm=trace" ] }, { @@ -67,7 +69,8 @@ "flags": [ "--rpc-cors=all", "--unsafe-rpc-external", - "--unsafe-ws-external" + "--unsafe-ws-external", + "-lxcm=trace" ] }, { @@ -78,13 +81,46 @@ "flags": [ "--rpc-cors=all", "--unsafe-rpc-external", - "--unsafe-ws-external" + "--unsafe-ws-external", + "-lxcm=trace" ] } ] + }, + { + "bin": "../Acala/target/release/acala", + "id": "2000", + "chain": "karura-dev", + "balance": "1000000000000000000000", + "nodes": [ + { + "wsPort": 9988, + "port": 31200, + "name": "alice", + "flags": [ + "--rpc-cors=all", + "--unsafe-rpc-external", + "--unsafe-ws-external", + "-lxcm=trace" + ] + } + ] + } + ], + "simpleParachains": [], + "hrmpChannels": [ + { + "sender": 2000, + "recipient": 1000, + "maxCapacity": 8, + "maxMessageSize": 512 + }, + { + "sender": 1000, + "recipient": 2000, + "maxCapacity": 8, + "maxMessageSize": 512 } ], - "simpleParachains": [], - "hrmpChannels": [], "finalization": false } --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -82,13 +82,22 @@ use xcm::v1::{BodyId, Junction::*, MultiLocation, NetworkId, Junctions::*}; use xcm_builder::{ AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter, - EnsureXcmOrigin, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset, + EnsureXcmOrigin, FixedWeightBounds, LocationInverter, NativeAsset, ParentAsSuperuser, ParentIsDefault, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, }; use xcm_executor::{Config, XcmExecutor}; +use xcm::latest::{ +// Xcm, + AssetId::{Concrete}, + Fungibility::Fungible as XcmFungible, + MultiAsset +}; +use xcm_executor::traits::MatchesFungible; +use sp_runtime::traits::CheckedConversion; + // mod chain_extension; // use crate::chain_extension::{NFTExtension, Imbalance}; @@ -616,12 +625,24 @@ AccountId32Aliases, ); + +pub struct OnlySelfCurrency; +impl> MatchesFungible for OnlySelfCurrency { + fn matches_fungible(a: &MultiAsset) -> Option { + match (&a.id, &a.fun) { + (Concrete(_), XcmFungible(ref amount)) => + CheckedConversion::checked_from(*amount), + _ => None, + } + } +} + /// Means for transacting assets on this chain. pub type LocalAssetTransactor = CurrencyAdapter< // Use this currency: Balances, // Use this currency when it is a fungible asset matching the given location or name: - IsConcrete, + OnlySelfCurrency, // Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID: LocationToAccountId, // Our chain's account ID type (we can't get away without mentioning it explicitly): -- gitstuff