Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes for xcm conversion of KAR and KUSD #238

Merged
merged 5 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pallets/flexible-fee/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ parameter_types! {

impl system::Config for Test {
type AccountData = balances::AccountData<u64>;
type AccountId = AccountId32;
type AccountId = AccountId;
type BaseCallFilter = ();
type BlockHashCount = BlockHashCount;
type BlockLength = ();
Expand Down
8 changes: 4 additions & 4 deletions runtime/bifrost/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ use sp_runtime::traits::ConvertInto;
use xcm::v0::{BodyId, Junction::*, MultiAsset, MultiLocation, MultiLocation::*, NetworkId, Xcm};
use xcm_builder::{
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,
EnsureXcmOrigin, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset,
ParentAsSuperuser, ParentIsDefault, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,
EnsureXcmOrigin, FixedWeightBounds, IsConcrete, LocationInverter, ParentAsSuperuser,
ParentIsDefault, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
UsingComponents,
};
use xcm_executor::{Config, XcmExecutor};
use xcm_support::BifrostCurrencyAdapter;
Expand Down
31 changes: 22 additions & 9 deletions runtime/common/src/xcm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,35 +114,48 @@ fn native_currency_location(id: CurrencyId, para_id: ParaId) -> MultiLocation {
pub struct BifrostCurrencyIdConvert<T>(sp_std::marker::PhantomData<T>);
impl<T: Get<ParaId>> Convert<CurrencyId, Option<MultiLocation>> for BifrostCurrencyIdConvert<T> {
fn convert(id: CurrencyId) -> Option<MultiLocation> {
use CurrencyId::{Native, Token};
use CurrencyId::{Native, Stable, Token};
match id {
Token(TokenSymbol::KSM) => Some(X1(Parent)),
Native(TokenSymbol::ASG) | Native(TokenSymbol::BNC) =>
Some(native_currency_location(id, T::get())),
// Karura currencyId types
Token(TokenSymbol::KAR) | Stable(TokenSymbol::KUSD) =>
Some(X3(Parent, Parachain(2000), GeneralKey(id.encode()))),
_ => None,
}
}
}
impl<T: Get<ParaId>> Convert<MultiLocation, Option<CurrencyId>> for BifrostCurrencyIdConvert<T> {
fn convert(location: MultiLocation) -> Option<CurrencyId> {
use CurrencyId::{Native, Token};
use CurrencyId::{Native, Stable, Token};
use TokenSymbol::*;
match location {
X1(Parent) => Some(Token(KSM)),
X3(Parent, Junction::Parachain(id), GeneralKey(key))
if ParaId::from(id) == T::get() =>
{
X3(Parent, Junction::Parachain(id), GeneralKey(key)) => {
// decode the general key
if let Ok(currency_id) = CurrencyId::decode(&mut &key[..]) {
// check `currency_id` is cross-chain asset
match currency_id {
Native(TokenSymbol::ASG) | Native(TokenSymbol::BNC) => Some(currency_id),
_ => None,
if ParaId::from(id) == T::get() {
match currency_id {
Native(TokenSymbol::ASG) | Native(TokenSymbol::BNC) =>
Some(currency_id),
_ => None,
}
// Kurara CurrencyId types
} else if id == 2000 {
match currency_id {
Token(TokenSymbol::KAR) | Stable(TokenSymbol::KUSD) =>
Some(currency_id),
_ => None,
}
} else {
None
}
} else {
None
}
}
},
_ => None,
}
}
Expand Down