Skip to content

Commit

Permalink
Added new Ext to insert parachain asset mapping (#963)
Browse files Browse the repository at this point in the history
## Describe your changes

## Issue ticket number and link
Added new Ext to insert parachain asset mapping.
  • Loading branch information
Gauthamastro authored Jun 3, 2024
2 parents 38b9bec + 391562f commit 5f77a40
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion pallets/xcm-helper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ pub mod pallet {
Box<MultiLocation>,
Box<MultiAsset>,
polkadex_primitives::AssetId,
u128, // Amount
ExtraData,
),
/// Sibling Deposit
Expand Down Expand Up @@ -300,6 +301,10 @@ pub mod pallet {
NotAbleToHandleDestination,
/// Xcm sibling deposit failed
XcmSiblingDepositFailed(Box<MultiLocation>, Box<MultiAsset>),
/// Parachain asset mapped
ParachainAssetMapped(polkadex_primitives::AssetId, Box<AssetId>),
/// Parachain asset not mapped
ParachainAssetNotMapped,
}

// Errors inform users that something went wrong.
Expand Down Expand Up @@ -401,6 +406,22 @@ pub mod pallet {
Self::deposit_event(Event::<T>::XcmFeeTransferred(to, amount.saturated_into()));
Ok(())
}

#[pallet::call_index(4)]
#[pallet::weight(T::WeightInfo::transfer_fee(1))]
pub fn insert_asset(
origin: OriginFor<T>,
asset_id: polkadex_primitives::AssetId,
asset_multilocation: AssetId,
) -> DispatchResult {
T::AssetCreateUpdateOrigin::ensure_origin(origin)?;
<ParachainAssets<T>>::insert(asset_id, asset_multilocation);
Self::deposit_event(Event::<T>::ParachainAssetMapped(
asset_id,
Box::new(asset_multilocation),
));
Ok(())
}
}

impl<T: Config> Convert<polkadex_primitives::AssetId, Option<MultiLocation>> for Pallet<T> {
Expand Down Expand Up @@ -470,6 +491,7 @@ pub mod pallet {
Box::new(*who),
Box::new(what.clone()),
asset_id,
amount,
extra,
));
}
Expand Down Expand Up @@ -838,7 +860,7 @@ pub mod pallet {
}
} else {
log::error!(target:"xcm-helper","Withdrawal failed: Not able to handle dest");
Self::deposit_event(Event::<T>::NotAbleToDecodeDestination);
Self::deposit_event(Event::<T>::ParachainAssetNotMapped);
failed_withdrawal.push(withdrawal);
}
} else if Self::handle_deposit(withdrawal.clone(), destination).is_err() {
Expand Down
1 change: 1 addition & 0 deletions polkadex-xcm-simulator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"



Expand Down
22 changes: 21 additions & 1 deletion polkadex-xcm-simulator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<thea_primitives::types::Withdraw> =
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);
})
}
}

0 comments on commit 5f77a40

Please sign in to comment.