Skip to content

Commit

Permalink
Modify local_xcm in get_local_currency_instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
imstar15 committed Nov 15, 2023
1 parent 8a42d8b commit 27f51dd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
38 changes: 28 additions & 10 deletions pallets/xcmp-handler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,29 @@ pub mod pallet {
Ok(instructions)
}

fn get_local_xcm(asset: MultiAsset, destination: MultiLocation) -> Result<xcm::latest::Xcm<<T as pallet::Config>::RuntimeCall>, DispatchError> {
let reserve = T::ReserveProvider::reserve(&asset)
.ok_or(Error::<T>::InvalidAssetLocation)?;
let local_xcm = if reserve == MultiLocation::here() {
Xcm(vec![
WithdrawAsset::<<T as pallet::Config>::RuntimeCall>(asset.into()),
DepositAsset::<<T as pallet::Config>::RuntimeCall> {
assets: Wild(All),
beneficiary: destination,
},
])
} else if reserve == destination {
Xcm(vec![
WithdrawAsset::<<T as pallet::Config>::RuntimeCall>(asset.clone().into()),
BurnAsset::<<T as pallet::Config>::RuntimeCall>(asset.into()),
])
} else {
return Err(Error::<T>::UnsupportedFeePayment.into())
};

Ok(local_xcm)
}

/// Construct the instructions for a transact xcm with our local currency.
///
/// Local instructions
Expand Down Expand Up @@ -257,15 +280,12 @@ pub mod pallet {
let local_asset =
MultiAsset { id: Concrete(asset_location), fun: Fungibility::Fungible(fee) };

let local_xcm = Xcm(vec![
WithdrawAsset::<<T as pallet::Config>::RuntimeCall>(local_asset.clone().into()),
DepositAsset::<<T as pallet::Config>::RuntimeCall> {
assets: Wild(All),
beneficiary: destination,
},
]);
let reserve = T::ReserveProvider::reserve(&local_asset)
.ok_or(Error::<T>::InvalidAssetLocation)?;

// XCM for target chain
let local_xcm = Self::get_local_xcm(local_asset.clone(), destination.clone())?;

// XCM for target chain
let target_asset = local_asset
.clone()
.reanchored(&destination, T::UniversalLocation::get())
Expand All @@ -274,8 +294,6 @@ pub mod pallet {
// If the target_asset is a token from this chain
// use the ReserveAssetDeposited instruction;
// otherwise, use the WithdrawAsset instruction.
let reserve = T::ReserveProvider::reserve(&local_asset)
.ok_or(Error::<T>::InvalidAssetLocation)?;
let asset_reception_instruction = if reserve == MultiLocation::here() {
ReserveAssetDeposited::<()>(target_asset.clone().into())
} else if reserve == destination {
Expand Down
2 changes: 1 addition & 1 deletion runtime/neumann/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl orml_xtokens::Config for Runtime {
type BaseXcmWeight = BaseXcmWeight;
type UniversalLocation = UniversalLocation;
type MaxAssetsForTransfer = MaxAssetsForTransfer;
type ReserveProvider = AbsoluteAndRelativeReserveProvider<SelfLocation>;
type ReserveProvider = AbsoluteReserveProvider;
}

impl orml_unknown_tokens::Config for Runtime {
Expand Down
2 changes: 1 addition & 1 deletion runtime/oak/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl orml_xtokens::Config for Runtime {
type BaseXcmWeight = BaseXcmWeight;
type UniversalLocation = UniversalLocation;
type MaxAssetsForTransfer = MaxAssetsForTransfer;
type ReserveProvider = AbsoluteAndRelativeReserveProvider<SelfLocation>;
type ReserveProvider = AbsoluteReserveProvider;
}

impl orml_unknown_tokens::Config for Runtime {
Expand Down
2 changes: 1 addition & 1 deletion runtime/turing/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl orml_xtokens::Config for Runtime {
type BaseXcmWeight = BaseXcmWeight;
type UniversalLocation = UniversalLocation;
type MaxAssetsForTransfer = MaxAssetsForTransfer;
type ReserveProvider = AbsoluteAndRelativeReserveProvider<SelfLocation>;
type ReserveProvider = AbsoluteReserveProvider;
}

impl orml_unknown_tokens::Config for Runtime {
Expand Down

0 comments on commit 27f51dd

Please sign in to comment.