diff --git a/Cargo.lock b/Cargo.lock index 0d708521b9..fce781887e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -208,6 +208,8 @@ dependencies = [ "orml-currencies", "orml-tokens", "orml-traits", + "orml-xcm-support", + "orml-xtokens", "pallet-aura", "pallet-authorship", "pallet-balances", @@ -2162,6 +2164,8 @@ dependencies = [ "orml-currencies", "orml-tokens", "orml-traits", + "orml-xcm-support", + "orml-xtokens", "pallet-aura", "pallet-authorship", "pallet-balances", @@ -5312,6 +5316,39 @@ dependencies = [ "sp-std", ] +[[package]] +name = "orml-xcm-support" +version = "0.4.1-dev" +source = "git+https://github.com/open-web3-stack/open-runtime-module-library?rev=650ef607d023e4537d3f2932baa5e50bc3a349cb#650ef607d023e4537d3f2932baa5e50bc3a349cb" +dependencies = [ + "frame-support", + "orml-traits", + "parity-scale-codec", + "sp-runtime", + "sp-std", + "xcm", + "xcm-executor", +] + +[[package]] +name = "orml-xtokens" +version = "0.4.1-dev" +source = "git+https://github.com/open-web3-stack/open-runtime-module-library?rev=650ef607d023e4537d3f2932baa5e50bc3a349cb#650ef607d023e4537d3f2932baa5e50bc3a349cb" +dependencies = [ + "cumulus-primitives-core", + "frame-support", + "frame-system", + "orml-traits", + "orml-xcm-support", + "parity-scale-codec", + "serde", + "sp-io", + "sp-runtime", + "sp-std", + "xcm", + "xcm-executor", +] + [[package]] name = "owning_ref" version = "0.4.1" diff --git a/Cargo.toml b/Cargo.toml index 69ac5ada6a..bf54eb5182 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -195,3 +195,5 @@ zenlink-protocol-runtime-api = { git = "ssh://git@github.com/bifrost-finance/Zen orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "650ef607d023e4537d3f2932baa5e50bc3a349cb" } orml-currencies = {git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "650ef607d023e4537d3f2932baa5e50bc3a349cb" } orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "650ef607d023e4537d3f2932baa5e50bc3a349cb" } +orml-xtokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "650ef607d023e4537d3f2932baa5e50bc3a349cb" } +orml-xcm-support = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "650ef607d023e4537d3f2932baa5e50bc3a349cb" } \ No newline at end of file diff --git a/runtime/asgard/Cargo.toml b/runtime/asgard/Cargo.toml index a363a7ccba..ff7adb8377 100644 --- a/runtime/asgard/Cargo.toml +++ b/runtime/asgard/Cargo.toml @@ -89,12 +89,15 @@ bifrost-salp = { path = "../../pallets/salp", default-features = false } bifrost-vsbond-auction = { path = "../../pallets/vsbond-auction", default-features = false } bifrost-vtoken-mint = { path = "../../pallets/vtoken-mint", default-features = false } pallet-vesting = { package = "bifrost-vesting", path = "../../pallets/vesting", default-features = false } +xcm-support = { path = "../../xcm-support", default-features = false } # orml 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 } -xcm-support = { path = "../../xcm-support", default-features = false } +orml-xtokens = { version = "0.4.1-dev", default-features = false } +orml-xcm-support = { version = "0.4.1-dev", default-features = false } + zenlink-protocol = { version = "*", default-features = false } zenlink-protocol-runtime-api = { version = "*", default-features = false } @@ -170,10 +173,12 @@ std = [ "bifrost-salp/std", "bifrost-vsbond-auction/std", "bifrost-vtoken-mint/std", + "xcm-support/std", "orml-currencies/std", "orml-traits/std", "orml-tokens/std", - "xcm-support/std", + "orml-xtokens/std", + "orml-xcm-support/std", "zenlink-protocol/std", "zenlink-protocol-runtime-api/std", ] diff --git a/runtime/asgard/src/lib.rs b/runtime/asgard/src/lib.rs index 3dde2028a1..00c3e92b47 100644 --- a/runtime/asgard/src/lib.rs +++ b/runtime/asgard/src/lib.rs @@ -66,12 +66,14 @@ use sp_std::{marker::PhantomData, prelude::*}; #[cfg(feature = "std")] use sp_version::NativeVersion; use sp_version::RuntimeVersion; +use xcm_support::Get; /// Constant values used within the runtime. pub mod constants; use bifrost_flexible_fee::fee_dealer::FixedCurrencyFeeRate; use bifrost_runtime_common::xcm_impl::{ - BifrostAssetMatcher, BifrostCurrencyIdConvert, BifrostFilteredAssets, BifrostXcmTransactFilter, + BifrostAccountIdToMultiLocation, BifrostAssetMatcher, BifrostCurrencyIdConvert, + BifrostFilteredAssets, BifrostXcmTransactFilter, }; use codec::{Decode, Encode}; use constants::{currency::*, time::*}; @@ -1144,6 +1146,22 @@ impl orml_currencies::Config for Runtime { type WeightInfo = (); } +parameter_types! { + pub SelfLocation: MultiLocation = X2(Parent, Parachain(ParachainInfo::get().into())); +} + +impl orml_xtokens::Config for Runtime { + type Event = Event; + type Balance = Balance; + type CurrencyId = CurrencyId; + type CurrencyIdConvert = BifrostCurrencyIdConvert; + type AccountIdToMultiLocation = BifrostAccountIdToMultiLocation; + type SelfLocation = SelfLocation; + type XcmExecutor = XcmExecutor; + type Weigher = FixedWeightBounds; + type BaseXcmWeight = XcmWeight; +} + // orml runtime end construct_runtime! { @@ -1200,7 +1218,7 @@ construct_runtime! { // Third party modules ZenlinkProtocol: zenlink_protocol::{Pallet, Call, Storage, Event} = 61, - // XTokens: orml_xtokens::{Pallet, Storage, Call, Event} = 70, + XTokens: orml_xtokens::{Pallet, Call, Event} = 70, Tokens: orml_tokens::{Pallet, Call, Storage, Event, Config} = 71, Currencies: orml_currencies::{Pallet, Call, Event} = 72, diff --git a/runtime/common/src/xcm_impl.rs b/runtime/common/src/xcm_impl.rs index ffb48e1349..6a88c1934a 100644 --- a/runtime/common/src/xcm_impl.rs +++ b/runtime/common/src/xcm_impl.rs @@ -114,10 +114,10 @@ fn native_currency_location(id: CurrencyId, para_id: ParaId) -> MultiLocation { pub struct BifrostCurrencyIdConvert(sp_std::marker::PhantomData); impl> Convert> for BifrostCurrencyIdConvert { fn convert(id: CurrencyId) -> Option { - use CurrencyId::Token; + use CurrencyId::{Native, Token}; match id { - Token(TokenSymbol::KSM) | Token(TokenSymbol::DOT) => Some(X1(Parent)), - Token(TokenSymbol::ASG) | Token(TokenSymbol::BNC) => + Token(TokenSymbol::KSM) => Some(X1(Parent)), + Native(TokenSymbol::ASG) | Native(TokenSymbol::BNC) => Some(native_currency_location(id, T::get())), _ => None, } @@ -125,7 +125,7 @@ impl> Convert> for BifrostCurre } impl> Convert> for BifrostCurrencyIdConvert { fn convert(location: MultiLocation) -> Option { - use CurrencyId::Token; + use CurrencyId::{Native, Token}; use TokenSymbol::*; match location { X1(Parent) => Some(Token(KSM)), @@ -136,7 +136,7 @@ impl> Convert> for BifrostCurre if let Ok(currency_id) = CurrencyId::decode(&mut &key[..]) { // check `currency_id` is cross-chain asset match currency_id { - Token(TokenSymbol::ASG) | Token(TokenSymbol::BNC) => Some(currency_id), + Native(TokenSymbol::ASG) | Native(TokenSymbol::BNC) => Some(currency_id), _ => None, } } else { @@ -156,3 +156,10 @@ impl> Convert> for BifrostCurrency } } } + +pub struct BifrostAccountIdToMultiLocation; +impl Convert for BifrostAccountIdToMultiLocation { + fn convert(account: AccountId) -> MultiLocation { + X1(AccountId32 { network: NetworkId::Any, id: account.into() }) + } +} diff --git a/runtime/dev/Cargo.toml b/runtime/dev/Cargo.toml index 97042e061d..b63c71c156 100644 --- a/runtime/dev/Cargo.toml +++ b/runtime/dev/Cargo.toml @@ -90,12 +90,14 @@ bifrost-salp = { path = "../../pallets/salp", default-features = false } bifrost-vsbond-auction = { path = "../../pallets/vsbond-auction", default-features = false } bifrost-vtoken-mint = { path = "../../pallets/vtoken-mint", default-features = false } pallet-vesting = { package = "bifrost-vesting", path = "../../pallets/vesting", default-features = false } +xcm-support = { path = "../../xcm-support", default-features = false } # orml 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 } -xcm-support = { path = "../../xcm-support", default-features = false } +orml-xtokens = { version = "0.4.1-dev", default-features = false } +orml-xcm-support = { version = "0.4.1-dev", default-features = false } zenlink-protocol = { version = "*", default-features = false } zenlink-protocol-runtime-api = { version = "*", default-features = false } @@ -172,10 +174,12 @@ std = [ "bifrost-salp/std", "bifrost-vsbond-auction/std", "bifrost-vtoken-mint/std", + "xcm-support/std", "orml-currencies/std", "orml-traits/std", "orml-tokens/std", - "xcm-support/std", + "orml-xtokens/std", + "orml-xcm-support/std", "zenlink-protocol/std", "zenlink-protocol-runtime-api/std", ] diff --git a/runtime/dev/src/lib.rs b/runtime/dev/src/lib.rs index 889cd3a7b4..d570403c5b 100644 --- a/runtime/dev/src/lib.rs +++ b/runtime/dev/src/lib.rs @@ -69,12 +69,14 @@ use sp_std::{marker::PhantomData, prelude::*}; #[cfg(feature = "std")] use sp_version::NativeVersion; use sp_version::RuntimeVersion; +use xcm_support::Get; /// Constant values used within the runtime. pub mod constants; use bifrost_flexible_fee::fee_dealer::FixedCurrencyFeeRate; use bifrost_runtime_common::xcm_impl::{ - BifrostAssetMatcher, BifrostCurrencyIdConvert, BifrostFilteredAssets, BifrostXcmTransactFilter, + BifrostAccountIdToMultiLocation, BifrostAssetMatcher, BifrostCurrencyIdConvert, + BifrostFilteredAssets, BifrostXcmTransactFilter, }; use codec::{Decode, Encode}; use constants::{currency::*, time::*}; @@ -1115,6 +1117,22 @@ impl orml_currencies::Config for Runtime { type WeightInfo = (); } +parameter_types! { + pub SelfLocation: MultiLocation = X2(Parent, Parachain(ParachainInfo::get().into())); +} + +impl orml_xtokens::Config for Runtime { + type Event = Event; + type Balance = Balance; + type CurrencyId = CurrencyId; + type CurrencyIdConvert = BifrostCurrencyIdConvert; + type AccountIdToMultiLocation = BifrostAccountIdToMultiLocation; + type SelfLocation = SelfLocation; + type XcmExecutor = XcmExecutor; + type Weigher = FixedWeightBounds; + type BaseXcmWeight = XcmWeight; +} + // orml runtime end construct_runtime! { @@ -1167,7 +1185,7 @@ construct_runtime! { // Third party modules ZenlinkProtocol: zenlink_protocol::{Pallet, Call, Storage, Event} = 61, - // XTokens: orml_xtokens::{Pallet, Storage, Call, Event} = 70, + XTokens: orml_xtokens::{Pallet, Call, Event} = 70, Tokens: orml_tokens::{Pallet, Call, Storage, Event, Config} = 71, Currencies: orml_currencies::{Pallet, Call, Event} = 72,