Skip to content

Commit

Permalink
MultiCurrencyTransact (#119)
Browse files Browse the repository at this point in the history
* Add bifrost asset transact&Upgrade to v0.9.3

* fix dependency&add copyright

* fix markdown format

* rename to xcm-support
  • Loading branch information
yrong committed Jun 3, 2021
1 parent 2f07c09 commit dda824e
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 57 deletions.
24 changes: 22 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ members = [
"pallets/voucher",
"pallets/charge-transaction-fee",
"pallets/vsbond-auction",
"xcm-support",
]

# The list of dependencies below (which can be both direct and indirect dependencies) are crates
Expand Down
4 changes: 2 additions & 2 deletions node/runtime/asgard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ orml-currencies = { version = "0.4.1-dev", default-features = false }
orml-tokens = { version = "0.4.1-dev", default-features = false }
orml-traits = { version = "0.4.1-dev", default-features = false }
#orml-xtokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "master" }
#orml-xcm-support = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "master" }
xcm-support = { path = "../../../xcm-support", default-features = false }

zenlink-protocol = { version = "0.4.0", default-features = false }
zenlink-protocol-runtime-api = { version = "0.4.0", default-features = false }
Expand Down Expand Up @@ -144,7 +144,7 @@ std = [
"orml-traits/std",
"orml-tokens/std",
# "orml-xtokens/std",
# "orml-xcm-support/std",
"xcm-support/std",
"zenlink-protocol/std",
"zenlink-protocol-runtime-api/std",
]
24 changes: 18 additions & 6 deletions node/runtime/asgard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ use polkadot_parachain::primitives::Sibling;
use xcm::v0::{BodyId, Junction::*, MultiAsset, MultiLocation, MultiLocation::*, NetworkId, Xcm};
use xcm_builder::{
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,
EnsureXcmOrigin, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset,
EnsureXcmOrigin, FixedWeightBounds, IsConcrete, LocationInverter,
ParentAsSuperuser, ParentIsDefault, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,
Expand All @@ -80,6 +80,8 @@ use frame_system::{EnsureRoot, EnsureOneOf};
// orml imports
use orml_currencies::BasicCurrencyAdapter;
use orml_traits::MultiCurrency;
use xcm_support::{BifrostAssetMatcher, BifrostCurrencyAdapter, BifrostCurrencyIdConvert, BifrostXcmTransactFilter, BifrostFilteredAssets};


// zenlink imports
use zenlink_protocol::{ZenlinkMultiAssets, LocalAssetHandler, MultiAssetsHandler, make_x2_location, AssetId, AssetBalance, PairInfo};
Expand Down Expand Up @@ -400,7 +402,7 @@ pub type LocationToAccountId = (
// Sibling parachain origins convert to AccountId via the `ParaId::into`.
SiblingParachainConvertsVia<Sibling, AccountId>,
// Straight up local `AccountId32` origins just alias directly to `AccountId`.
AccountId32Aliases<RococoNetwork, AccountId>,
AccountId32Aliases<AnyNetwork, AccountId>,
);

/// Means for transacting assets on this chain.
Expand Down Expand Up @@ -436,7 +438,7 @@ pub type XcmOriginToTransactDispatchOrigin = (
ParentAsSuperuser<Origin>,
// Native signed account converter; this just converts an `AccountId32` origin into a normal
// `Origin::Signed` origin of the same 32-byte value.
SignedAccountId32AsNative<RococoNetwork, Origin>,
SignedAccountId32AsNative<AnyNetwork, Origin>,
// Xcm origins can be represented natively under the Xcm pallet's Xcm origin.
XcmPassthrough<Origin>,
);
Expand All @@ -457,19 +459,29 @@ match_type! {
pub type Barrier = (
TakeWeightCredit,
AllowTopLevelPaidExecutionFrom<All<MultiLocation>>,
AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,
// ^^^ Parent & its unit plurality gets free execution
AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,
BifrostXcmTransactFilter<All<MultiLocation>>,
);

pub type BifrostAssetTransactor = BifrostCurrencyAdapter<
Assets,
BifrostAssetMatcher<CurrencyId, BifrostCurrencyIdConvert>,
AccountId,
LocationToAccountId,
CurrencyId,
BifrostCurrencyIdConvert,
>;

pub struct XcmConfig;
impl Config for XcmConfig {
type Call = Call;
type XcmSender = XcmRouter;
// How to withdraw and deposit an asset.
type AssetTransactor = LocalAssetTransactor;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
type IsReserve = NativeAsset;
type IsTeleporter = NativeAsset; // <- should be enough to allow teleportation of ROC
type IsReserve = BifrostFilteredAssets;
type IsTeleporter = BifrostFilteredAssets;
type LocationInverter = LocationInverter<Ancestry>;
type Barrier = Barrier;
type Weigher = FixedWeightBounds<UnitWeightCost, Call>;
Expand Down
50 changes: 3 additions & 47 deletions node/runtime/bifrost/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
/// Constant values used within the runtime.
pub mod constants;
use constants::{currency::*, time::*};
use node_primitives::Moment;
use node_primitives::{Moment};

// XCM imports
use polkadot_parachain::primitives::Sibling;
Expand Down Expand Up @@ -457,55 +457,11 @@ match_type! {
};
}

/// Transparent XcmTransact Barrier for sybil demo. Polkadot will probably come up with a
/// better solution for this. Currently, they have not setup a barrier config for `XcmTransact`
pub struct AllowXcmTransactFrom<T>(PhantomData<T>);
impl<T: Contains<MultiLocation>> ShouldExecute for AllowXcmTransactFrom<T> {
fn should_execute<Call>(
_origin: &MultiLocation,
_top_level: bool,
message: &Xcm<Call>,
_shallow_weight: Weight,
_weight_credit: &mut Weight,
) -> Result<(), ()> {
match message {
Xcm::Transact { origin_type: _ , require_weight_at_most: _, call: _ } => Ok(()),
_ => Err(())
}
}
}

pub type Barrier = (
TakeWeightCredit,
AllowTopLevelPaidExecutionFrom<All<MultiLocation>>,
// ^^^ Parent & its unit plurality gets free execution
AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,
AllowXcmTransactFrom<All<MultiLocation>>,
);

pub struct CrosschainConcreteAsset;
impl FilterAssetLocation for CrosschainConcreteAsset {
fn filter_asset_location(asset: &MultiAsset, origin: &MultiLocation) -> bool {
match asset {
MultiAsset::ConcreteFungible {..} => {
match origin {
Null | X1(Plurality { .. }) => true,
X1(AccountId32 { .. }) => true,
X1(Parent { .. }) => true,
X1(Parachain { .. }) => true,
X2(Parachain{..}, _ ) => true,
X2(Parent{..}, _ ) => true,
_ => false
}
},
_ => false
}
}
}

pub type ReserveAsset = (
NativeAsset,
CrosschainConcreteAsset,
);

pub struct XcmConfig;
Expand All @@ -515,8 +471,8 @@ impl Config for XcmConfig {
// How to withdraw and deposit an asset.
type AssetTransactor = LocalAssetTransactor;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
type IsReserve = ReserveAsset;
type IsTeleporter = ReserveAsset; // <- should be enough to allow teleportation of ROC
type IsReserve = NativeAsset;
type IsTeleporter = NativeAsset; // <- should be enough to allow teleportation of ROC
type LocationInverter = LocationInverter<Ancestry>;
type Barrier = Barrier;
type Weigher = FixedWeightBounds<UnitWeightCost, Call>;
Expand Down
31 changes: 31 additions & 0 deletions xcm-support/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "xcm-support"
description = "Supporting module for XCM integration."
license = "Apache-2.0"
version = "0.4.1-dev"
authors = ["Bifrost Developers"]
edition = "2018"

[dependencies]
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.3", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.3", default-features = false }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.3", default-features = false }
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.3" }
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.3" }
xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.3", default-features = false }
xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.3" }
xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.3", default-features = false }
orml-traits = { version = "0.4.1-dev", default-features = false }
node-primitives = { default-features = false, path = "../node/primitives" }

[features]
default = ["std"]
std = [
"sp-std/std",
"sp-runtime/std",
"frame-support/std",
"xcm/std",
"xcm-executor/std",
"orml-traits/std",
]
6 changes: 6 additions & 0 deletions xcm-support/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# XCM Support Module

## Overview

The XCM support module provides supporting traits, types and implementations,
to support cross-chain message(XCM) integration with ORML modules.
Loading

0 comments on commit dda824e

Please sign in to comment.