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

refactor: Use VersionedLocation in RestrictedTransferLocation #1861

9 changes: 4 additions & 5 deletions libs/types/src/locations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@ use frame_support::RuntimeDebugNoBound;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_core::crypto::AccountId32;
// Please note that if this version change,
// a migration could be required in those places where
// RestrictedTransferLocation is stored
use staging_xcm::v4::Location;
use sp_std::boxed::Box;
use staging_xcm::VersionedLocation;

use crate::domain_address::DomainAddress;

/// Location types for destinations that can receive restricted transfers
#[derive(Clone, RuntimeDebugNoBound, Encode, Decode, Eq, PartialEq, MaxEncodedLen, TypeInfo)]
pub enum RestrictedTransferLocation {
/// Local chain account sending destination.
Local(AccountId),
/// XCM Location sending destinations.
Xcm(Location),
Xcm(Box<VersionedLocation>),
/// DomainAddress sending location from a liquidity pools' instance
Address(DomainAddress),
}
Expand Down
42 changes: 12 additions & 30 deletions pallets/restricted-xtokens/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,37 +51,37 @@ use staging_xcm::{v4::prelude::*, VersionedAsset, VersionedAssets, VersionedLoca
pub enum TransferEffects<AccountId, CurrencyId, Balance> {
Transfer {
sender: AccountId,
destination: Location,
destination: VersionedLocation,
currency_id: CurrencyId,
amount: Balance,
},
TransferMultiAsset {
sender: AccountId,
destination: Location,
destination: VersionedLocation,
asset: Asset,
},
TransferWithFee {
sender: AccountId,
destination: Location,
destination: VersionedLocation,
currency_id: CurrencyId,
amount: Balance,
fee: Balance,
},
TransferMultiAssetWithFee {
sender: AccountId,
destination: Location,
destination: VersionedLocation,
asset: Asset,
fee_asset: Asset,
},
TransferMultiCurrencies {
sender: AccountId,
destination: Location,
destination: VersionedLocation,
currencies: Vec<(CurrencyId, Balance)>,
fee: (CurrencyId, Balance),
},
TransferMultiAssets {
sender: AccountId,
destination: Location,
destination: VersionedLocation,
assets: Assets,
fee_asset: Asset,
},
Expand Down Expand Up @@ -130,14 +130,11 @@ pub mod pallet {
dest: Box<VersionedLocation>,
dest_weight_limit: WeightLimit,
) -> DispatchResult {
let destination: Location = (*dest.clone())
.try_into()
.map_err(|()| Error::<T>::BadVersion)?;
let sender = ensure_signed(origin.clone())?;

T::PreTransfer::check(TransferEffects::Transfer {
sender,
destination,
destination: (*dest.clone()),
currency_id: currency_id.clone(),
amount,
})?;
Expand Down Expand Up @@ -175,13 +172,10 @@ pub mod pallet {
let multi_asset: Asset = (*asset.clone())
.try_into()
.map_err(|()| Error::<T>::BadVersion)?;
let destination: Location = (*dest.clone())
.try_into()
.map_err(|()| Error::<T>::BadVersion)?;

T::PreTransfer::check(TransferEffects::TransferMultiAsset {
sender,
destination,
destination: (*dest.clone()),
asset: multi_asset,
})?;

Expand Down Expand Up @@ -220,13 +214,10 @@ pub mod pallet {
dest_weight_limit: WeightLimit,
) -> DispatchResult {
let sender = ensure_signed(origin.clone())?;
let destination: Location = (*dest.clone())
.try_into()
.map_err(|()| Error::<T>::BadVersion)?;

T::PreTransfer::check(TransferEffects::TransferWithFee {
sender,
destination,
destination: (*dest.clone()),
currency_id: currency_id.clone(),
amount,
fee,
Expand Down Expand Up @@ -279,13 +270,10 @@ pub mod pallet {
let fee_asset: Asset = (*fee.clone())
.try_into()
.map_err(|()| Error::<T>::BadVersion)?;
let destination: Location = (*dest.clone())
.try_into()
.map_err(|()| Error::<T>::BadVersion)?;
Comment on lines -282 to -284
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! It seems like the it wanted to be so 👍🏻


T::PreTransfer::check(TransferEffects::TransferMultiAssetWithFee {
sender,
destination,
destination: (*dest.clone()),
asset: multi_asset,
fee_asset,
})?;
Expand Down Expand Up @@ -324,16 +312,13 @@ pub mod pallet {
dest_weight_limit: WeightLimit,
) -> DispatchResult {
let sender = ensure_signed(origin.clone())?;
let destination: Location = (*dest.clone())
.try_into()
.map_err(|()| Error::<T>::BadVersion)?;
let fee = currencies
.get(fee_item as usize)
.ok_or(orml_xtokens::Error::<T>::AssetIndexNonExistent)?;

T::PreTransfer::check(TransferEffects::TransferMultiCurrencies {
sender,
destination,
destination: (*dest.clone()),
currencies: currencies.clone(),
fee: fee.clone(),
})?;
Expand Down Expand Up @@ -375,16 +360,13 @@ pub mod pallet {
let multi_assets: Assets = (*assets.clone())
.try_into()
.map_err(|()| Error::<T>::BadVersion)?;
let destination: Location = (*dest.clone())
.try_into()
.map_err(|()| Error::<T>::BadVersion)?;
let fee_asset: &Asset = multi_assets
.get(fee_item as usize)
.ok_or(orml_xtokens::Error::<T>::AssetIndexNonExistent)?;

T::PreTransfer::check(TransferEffects::TransferMultiAssets {
sender,
destination,
destination: (*dest.clone()),
assets: multi_assets.clone(),
fee_asset: fee_asset.clone(),
})?;
Expand Down
Loading
Loading