Skip to content
Merged
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
63 changes: 14 additions & 49 deletions xtokens/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(clippy::from_over_into)]
#![allow(clippy::unused_unit)]
#![allow(clippy::large_enum_variant)]

pub use module::*;

Expand Down Expand Up @@ -89,19 +90,11 @@ pub mod module {

/// Transferred to parachain. \[x_currency_id, src, para_id, dest,
/// dest_network, amount\]
TransferredToParachain(XCurrencyId, T::AccountId, ParaId, T::AccountId, NetworkId, T::Balance),
TransferredToParachain(XCurrencyId, T::AccountId, ParaId, MultiLocation, T::Balance),

/// Transfer to parachain failed. \[x_currency_id, src, para_id, dest,
/// dest_network, amount, error\]
TransferToParachainFailed(
XCurrencyId,
T::AccountId,
ParaId,
T::AccountId,
NetworkId,
T::Balance,
XcmError,
),
TransferToParachainFailed(XCurrencyId, T::AccountId, ParaId, MultiLocation, T::Balance, XcmError),
}

#[pallet::error]
Expand Down Expand Up @@ -164,8 +157,7 @@ pub mod module {
origin: OriginFor<T>,
x_currency_id: XCurrencyId,
para_id: ParaId,
dest: T::AccountId,
dest_network: NetworkId,
dest: MultiLocation,
amount: T::Balance,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
Expand All @@ -175,25 +167,16 @@ pub mod module {
}

let xcm = match x_currency_id.chain_id {
ChainId::RelayChain => {
Self::transfer_relay_chain_tokens_to_parachain(para_id, &dest, dest_network.clone(), amount)
}
ChainId::RelayChain => Self::transfer_relay_chain_tokens_to_parachain(para_id, dest.clone(), amount),
ChainId::ParaChain(reserve_chain) => {
if T::ParaId::get() == reserve_chain {
Self::transfer_owned_tokens_to_parachain(
x_currency_id.clone(),
para_id,
&dest,
dest_network.clone(),
amount,
)
Self::transfer_owned_tokens_to_parachain(x_currency_id.clone(), para_id, dest.clone(), amount)
} else {
Self::transfer_non_owned_tokens_to_parachain(
reserve_chain,
x_currency_id.clone(),
para_id,
&dest,
dest_network.clone(),
dest.clone(),
amount,
)
}
Expand All @@ -209,15 +192,13 @@ pub mod module {
who,
para_id,
dest,
dest_network,
amount,
)),
Err(err) => Self::deposit_event(Event::<T>::TransferToParachainFailed(
x_currency_id,
who,
para_id,
dest,
dest_network,
amount,
err,
)),
Expand All @@ -228,12 +209,7 @@ pub mod module {
}

impl<T: Config> Pallet<T> {
fn transfer_relay_chain_tokens_to_parachain(
para_id: ParaId,
dest: &T::AccountId,
dest_network: NetworkId,
amount: T::Balance,
) -> Xcm {
fn transfer_relay_chain_tokens_to_parachain(para_id: ParaId, dest: MultiLocation, amount: T::Balance) -> Xcm {
Xcm::WithdrawAsset {
assets: vec![MultiAsset::ConcreteFungible {
id: MultiLocation::X1(Junction::Parent),
Expand All @@ -244,14 +220,11 @@ pub mod module {
reserve: MultiLocation::X1(Junction::Parent),
effects: vec![Order::DepositReserveAsset {
assets: vec![MultiAsset::All],
// `dest` is children parachain(of parent).
// Reserve asset deposit dest is children parachain(of parent).
dest: MultiLocation::X1(Junction::Parachain { id: para_id.into() }),
effects: vec![Order::DepositAsset {
assets: vec![MultiAsset::All],
dest: MultiLocation::X1(Junction::AccountId32 {
network: dest_network,
id: T::AccountId32Convert::convert(dest.clone()),
}),
dest,
}],
}],
}],
Expand All @@ -265,8 +238,7 @@ pub mod module {
fn transfer_owned_tokens_to_parachain(
x_currency_id: XCurrencyId,
para_id: ParaId,
dest: &T::AccountId,
dest_network: NetworkId,
dest: MultiLocation,
amount: T::Balance,
) -> Xcm {
Xcm::WithdrawAsset {
Expand All @@ -279,10 +251,7 @@ pub mod module {
dest: MultiLocation::X2(Junction::Parent, Junction::Parachain { id: para_id.into() }),
effects: vec![Order::DepositAsset {
assets: vec![MultiAsset::All],
dest: MultiLocation::X1(Junction::AccountId32 {
network: dest_network,
id: T::AccountId32Convert::convert(dest.clone()),
}),
dest,
}],
}],
}
Expand All @@ -294,16 +263,12 @@ pub mod module {
reserve_chain: ParaId,
x_currency_id: XCurrencyId,
para_id: ParaId,
dest: &T::AccountId,
dest_network: NetworkId,
dest: MultiLocation,
amount: T::Balance,
) -> Xcm {
let deposit_to_dest = Order::DepositAsset {
assets: vec![MultiAsset::All],
dest: MultiLocation::X1(Junction::AccountId32 {
network: dest_network,
id: T::AccountId32Convert::convert(dest.clone()),
}),
dest,
};
// If transfer to reserve chain, deposit to `dest` on reserve chain,
// else deposit reserve asset.
Expand Down