@@ -58,7 +58,7 @@ pub mod pallet {
5858 use polkadot_parachain:: primitives:: Sibling ;
5959 use sp_runtime:: traits:: { AccountIdConversion , Convert , SaturatedConversion } ;
6060 use sp_std:: prelude:: * ;
61- use xcm:: { latest:: prelude:: * , VersionedMultiLocation } ;
61+ use xcm:: latest:: prelude:: * ;
6262 use xcm_executor:: traits:: { InvertLocation , WeightBounds } ;
6363
6464 type ParachainId = u32 ;
@@ -157,13 +157,11 @@ pub mod pallet {
157157 ErrorGettingCallWeight ,
158158 /// Currency not supported
159159 CurrencyNotSupported ,
160- /// The version of the `VersionedMultiLocation` value used is not able
161- /// to be interpreted.
162- BadVersion ,
163160 }
164161
165162 /// Stores all data needed to send an XCM message for chain/currency pair.
166- #[ derive( Clone , Debug , Encode , Decode , PartialEq , TypeInfo ) ]
163+ #[ derive( Clone , Copy , Debug , Encode , Decode , PartialEq , TypeInfo ) ]
164+ #[ cfg_attr( feature = "std" , derive( Serialize , Deserialize ) ) ]
167165 pub struct XcmCurrencyData {
168166 /// Is the token native to the chain?
169167 pub native : bool ,
@@ -172,7 +170,6 @@ pub mod pallet {
172170 pub instruction_weight : u64 ,
173171 /// The desired instruction flow for the target chain
174172 pub flow : XcmFlow ,
175- pub location : Option < VersionedMultiLocation > ,
176173 }
177174
178175 /// Stores XCM data for a chain/currency pair.
@@ -237,10 +234,8 @@ pub mod pallet {
237234 let xcm_data = XcmChainCurrencyData :: < T > :: get ( para_id, currency_id)
238235 . ok_or ( Error :: < T > :: CurrencyChainComboNotFound ) ?;
239236
240- let ( _, target_instructions) =
241- Self :: xcm_instruction_skeleton ( para_id, xcm_data. clone ( ) ) ?;
237+ let ( _, target_instructions) = Self :: xcm_instruction_skeleton ( para_id, xcm_data) ?;
242238 let weight = xcm_data
243- . clone ( )
244239 . instruction_weight
245240 . checked_mul ( target_instructions. len ( ) as u64 )
246241 . ok_or ( Error :: < T > :: WeightOverflow ) ?
@@ -286,29 +281,21 @@ pub mod pallet {
286281 . try_into ( )
287282 . map_err ( |_| Error :: < T > :: FailedMultiLocationToJunction ) ?;
288283
289- let location = match xcm_data. location {
290- Some ( loc) => loc. clone ( ) . try_into ( ) . map_err ( |( ) | Error :: < T > :: BadVersion ) ?,
291- _ => MultiLocation :: new ( 0 , Here ) ,
292- } ;
293-
294- let target_asset =
295- MultiAsset { id : Concrete ( location) , fun : Fungibility :: Fungible ( fee) } ;
296-
297284 let instructions = match xcm_data. flow {
298285 XcmFlow :: Normal => Self :: get_local_currency_instructions (
299286 para_id,
300- target_asset,
301287 descend_location,
302288 transact_encoded_call,
303289 transact_encoded_call_weight,
304290 weight,
291+ fee,
305292 ) ?,
306293 XcmFlow :: Alternate => Self :: get_alternate_flow_instructions (
307- target_asset,
308294 descend_location,
309295 transact_encoded_call,
310296 transact_encoded_call_weight,
311297 weight,
298+ fee,
312299 ) ?,
313300 } ;
314301
@@ -330,15 +317,21 @@ pub mod pallet {
330317 /// - DepositAsset
331318 pub fn get_local_currency_instructions (
332319 para_id : ParachainId ,
333- local_asset : MultiAsset ,
334320 descend_location : Junctions ,
335321 transact_encoded_call : Vec < u8 > ,
336322 transact_encoded_call_weight : u64 ,
337323 xcm_weight : u64 ,
324+ fee : u128 ,
338325 ) -> Result <
339326 ( xcm:: latest:: Xcm < <T as pallet:: Config >:: Call > , xcm:: latest:: Xcm < ( ) > ) ,
340327 DispatchError ,
341328 > {
329+ // XCM for local chain
330+ let local_asset = MultiAsset {
331+ id : Concrete ( MultiLocation :: new ( 0 , Here ) ) ,
332+ fun : Fungibility :: Fungible ( fee) ,
333+ } ;
334+
342335 let local_xcm = Xcm ( vec ! [
343336 WithdrawAsset :: <<T as pallet:: Config >:: Call >( local_asset. clone( ) . into( ) ) ,
344337 DepositAsset :: <<T as pallet:: Config >:: Call > {
@@ -391,15 +384,21 @@ pub mod pallet {
391384 /// - RefundSurplus
392385 /// - DepositAsset
393386 fn get_alternate_flow_instructions (
394- target_asset : MultiAsset ,
395387 descend_location : Junctions ,
396388 transact_encoded_call : Vec < u8 > ,
397389 transact_encoded_call_weight : u64 ,
398390 xcm_weight : u64 ,
391+ fee : u128 ,
399392 ) -> Result <
400393 ( xcm:: latest:: Xcm < <T as pallet:: Config >:: Call > , xcm:: latest:: Xcm < ( ) > ) ,
401394 DispatchError ,
402395 > {
396+ // Default to native currency of target chain
397+ let target_asset = MultiAsset {
398+ id : Concrete ( MultiLocation :: new ( 0 , Here ) ) ,
399+ fun : Fungibility :: Fungible ( fee) ,
400+ } ;
401+
403402 let target_xcm = Xcm ( vec ! [
404403 DescendOrigin :: <( ) >( descend_location. clone( ) ) ,
405404 WithdrawAsset :: <( ) >( target_asset. clone( ) . into( ) ) ,
@@ -540,37 +539,29 @@ pub mod pallet {
540539 . try_into ( )
541540 . map_err ( |_| Error :: < T > :: FailedMultiLocationToJunction ) ?;
542541
543- let location = match xcm_data. location {
544- Some ( loc) => loc. clone ( ) . try_into ( ) . map_err ( |( ) | Error :: < T > :: BadVersion ) ?,
545- _ => MultiLocation :: new ( 0 , Here ) ,
546- } ;
547-
548- let target_asset =
549- MultiAsset { id : Concrete ( location) , fun : Fungibility :: Fungible ( 0u128 ) } ;
550-
551542 match xcm_data. flow {
552543 XcmFlow :: Normal => Self :: get_local_currency_instructions (
553544 para_id,
554- target_asset,
555545 nobody,
556546 Default :: default ( ) ,
557547 0u64 ,
558548 0u64 ,
549+ 0u128 ,
559550 ) ,
560551 XcmFlow :: Alternate => Self :: get_alternate_flow_instructions (
561- target_asset,
562552 nobody,
563553 Default :: default ( ) ,
564554 0u64 ,
565555 0u64 ,
556+ 0u128 ,
566557 ) ,
567558 }
568559 }
569560 }
570561
571562 #[ pallet:: genesis_config]
572563 pub struct GenesisConfig < T : Config > {
573- pub chain_data : Vec < ( u32 , T :: CurrencyId , bool , u128 , u64 , XcmFlow , Vec < u8 > ) > ,
564+ pub chain_data : Vec < ( u32 , T :: CurrencyId , bool , u128 , u64 , XcmFlow ) > ,
574565 }
575566
576567 #[ cfg( feature = "std" ) ]
@@ -583,18 +574,9 @@ pub mod pallet {
583574 #[ pallet:: genesis_build]
584575 impl < T : Config > GenesisBuild < T > for GenesisConfig < T > {
585576 fn build ( & self ) {
586- for (
587- para_id,
588- currency_id,
589- native,
590- fee_per_second,
591- instruction_weight,
592- flow,
593- location_encoded,
594- ) in self . chain_data . iter ( )
577+ for ( para_id, currency_id, native, fee_per_second, instruction_weight, flow) in
578+ self . chain_data . iter ( )
595579 {
596- let location = Option :: < VersionedMultiLocation > :: decode ( & mut & location_encoded[ ..] )
597- . expect ( "Error decoding VersionedMultiLocation" ) ;
598580 XcmChainCurrencyData :: < T > :: insert (
599581 para_id,
600582 currency_id,
@@ -603,7 +585,6 @@ pub mod pallet {
603585 fee_per_second : * fee_per_second,
604586 instruction_weight : * instruction_weight,
605587 flow : * flow,
606- location,
607588 } ,
608589 ) ;
609590 }
@@ -688,7 +669,6 @@ impl<T: Config> XcmpTransactor<T::AccountId, T::CurrencyId> for Pallet<T> {
688669 fee_per_second : 416_000_000_000 ,
689670 instruction_weight : 600_000_000 ,
690671 flow : XcmFlow :: Normal ,
691- location : None ,
692672 } ;
693673
694674 XcmChainCurrencyData :: < T > :: insert ( para_id, currency_id, xcm_data) ;
0 commit comments