From ffabb9bac7d42e8dbece110ead87526fcbd92c14 Mon Sep 17 00:00:00 2001 From: zktony Date: Mon, 3 Jun 2024 14:00:28 +0530 Subject: [PATCH 1/2] Added new ext --- Cargo.lock | 1 + pallets/xcm-helper/src/lib.rs | 19 ++++++++++++++++++- polkadex-xcm-simulator/Cargo.toml | 1 + polkadex-xcm-simulator/src/lib.rs | 22 +++++++++++++++++++++- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 830e9023b..c1a358138 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8010,6 +8010,7 @@ version = "1.0.0" dependencies = [ "frame-support", "frame-system", + "hex", "log", "orml-traits", "orml-xcm-support", diff --git a/pallets/xcm-helper/src/lib.rs b/pallets/xcm-helper/src/lib.rs index f2ddd6090..66aa321f6 100644 --- a/pallets/xcm-helper/src/lib.rs +++ b/pallets/xcm-helper/src/lib.rs @@ -300,6 +300,10 @@ pub mod pallet { NotAbleToHandleDestination, /// Xcm sibling deposit failed XcmSiblingDepositFailed(Box, Box), + /// Parachain asset mapped + ParachainAssetMapped(polkadex_primitives::AssetId, AssetId), + /// Parachain asset not mapped + ParachainAssetNotMapped, } // Errors inform users that something went wrong. @@ -401,6 +405,19 @@ pub mod pallet { Self::deposit_event(Event::::XcmFeeTransferred(to, amount.saturated_into())); Ok(()) } + + #[pallet::call_index(4)] + #[pallet::weight(T::WeightInfo::transfer_fee(1))] + pub fn insert_asset( + origin: OriginFor, + asset_id: polkadex_primitives::AssetId, + asset_multilocation: AssetId, + ) -> DispatchResult { + T::AssetCreateUpdateOrigin::ensure_origin(origin)?; + >::insert(asset_id, asset_multilocation); + Self::deposit_event(Event::::ParachainAssetMapped(asset_id, asset_multilocation)); + Ok(()) + } } impl Convert> for Pallet { @@ -838,7 +855,7 @@ pub mod pallet { } } else { log::error!(target:"xcm-helper","Withdrawal failed: Not able to handle dest"); - Self::deposit_event(Event::::NotAbleToDecodeDestination); + Self::deposit_event(Event::::ParachainAssetNotMapped); failed_withdrawal.push(withdrawal); } } else if Self::handle_deposit(withdrawal.clone(), destination).is_err() { diff --git a/polkadex-xcm-simulator/Cargo.toml b/polkadex-xcm-simulator/Cargo.toml index 282d8e64d..a6b630800 100644 --- a/polkadex-xcm-simulator/Cargo.toml +++ b/polkadex-xcm-simulator/Cargo.toml @@ -41,6 +41,7 @@ xcm-helper = { path = "../pallets/xcm-helper" } thea-message-handler = { path = "../pallets/thea-message-handler" } thea = { path = "../pallets/thea" } smallvec = "1.13.1" +hex = "0.4.3" diff --git a/polkadex-xcm-simulator/src/lib.rs b/polkadex-xcm-simulator/src/lib.rs index ac5930ad6..fa7102c24 100644 --- a/polkadex-xcm-simulator/src/lib.rs +++ b/polkadex-xcm-simulator/src/lib.rs @@ -153,7 +153,7 @@ mod tests { use super::*; use crate::parachain::{Balances, XcmHelper}; - use codec::Encode; + use codec::{Decode, Encode}; use frame_support::traits::fungible::Mutate; use frame_support::{assert_ok, weights::Weight}; use thea_primitives::extras::ExtraData; @@ -633,4 +633,24 @@ mod tests { ))); }) } + + #[test] + fn test_with_thea_payload() { + MockNet::reset(); + ParaA::execute_with(|| { + let hex = hex::decode("0400000000c9104ef90d846adb8cd6727f57c8e46d010010a5d4e800000000000000000000007003010200511f03007b9a3a0bd813c61006d94c7206137052f1cd6ce100000000").unwrap(); + let payload: Vec = + Decode::decode(&mut &hex[..]).unwrap(); + let block_no = 1; + let multlocation = + MultiLocation { parents: 1, interior: Junctions::X1(Junction::Parachain(1)) }; + let pdex_asset_id = AssetId::Concrete(multlocation); + XcmHelper::insert_parachain_asset( + pdex_asset_id, + polkadex_primitives::AssetId::Polkadex, + ); + XcmHelper::insert_pending_withdrawal(block_no, payload.first().unwrap().clone()); + XcmHelper::handle_new_pending_withdrawals(block_no); + }) + } } From 391562f09e50b2ac183709d510b7410ca52f97f0 Mon Sep 17 00:00:00 2001 From: zktony Date: Mon, 3 Jun 2024 16:22:19 +0530 Subject: [PATCH 2/2] Resolved clippy warnings --- pallets/xcm-helper/src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pallets/xcm-helper/src/lib.rs b/pallets/xcm-helper/src/lib.rs index 66aa321f6..889fadbf0 100644 --- a/pallets/xcm-helper/src/lib.rs +++ b/pallets/xcm-helper/src/lib.rs @@ -273,6 +273,7 @@ pub mod pallet { Box, Box, polkadex_primitives::AssetId, + u128, // Amount ExtraData, ), /// Sibling Deposit @@ -301,7 +302,7 @@ pub mod pallet { /// Xcm sibling deposit failed XcmSiblingDepositFailed(Box, Box), /// Parachain asset mapped - ParachainAssetMapped(polkadex_primitives::AssetId, AssetId), + ParachainAssetMapped(polkadex_primitives::AssetId, Box), /// Parachain asset not mapped ParachainAssetNotMapped, } @@ -415,7 +416,10 @@ pub mod pallet { ) -> DispatchResult { T::AssetCreateUpdateOrigin::ensure_origin(origin)?; >::insert(asset_id, asset_multilocation); - Self::deposit_event(Event::::ParachainAssetMapped(asset_id, asset_multilocation)); + Self::deposit_event(Event::::ParachainAssetMapped( + asset_id, + Box::new(asset_multilocation), + )); Ok(()) } } @@ -487,6 +491,7 @@ pub mod pallet { Box::new(*who), Box::new(what.clone()), asset_id, + amount, extra, )); }