Skip to content

Commit

Permalink
Fixed warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
zktony committed May 30, 2024
1 parent 9316a6c commit 95832aa
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 59 deletions.
42 changes: 24 additions & 18 deletions pallets/xcm-helper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub mod pallet {
},
prelude::Parachain,
v3::AssetId,
IntoVersion, VersionedMultiAssets, VersionedMultiLocation,
VersionedMultiAssets, VersionedMultiLocation,
};
use xcm_executor::{
traits::{ConvertLocation as MoreConvert, TransactAsset},
Expand Down Expand Up @@ -290,6 +290,14 @@ pub mod pallet {
NativeAssetIdMappingRegistered(polkadex_primitives::AssetId, Box<AssetId>),
/// Whitelisted Token removed
WhitelistedTokenRemoved(polkadex_primitives::AssetId),
/// Not able too decode Destination
NotAbleToDecodeDestination,
/// Not able to mint token
NotAbleToMintToken,
/// Not able to Make Xcm Call
NotAbleToMakeXcmCall,
/// Not able to handle Destination
NotAbleToHandleDestination,
}

// Errors inform users that something went wrong.
Expand Down Expand Up @@ -412,9 +420,7 @@ pub mod pallet {
// Create approved deposit
let MultiAsset { id, fun } = what;
let asset_id = Self::generate_asset_id_for_parachain(*id);
if let (Some(account)) =
(T::SiblingAddressConverter::convert_location(who))
{
if let Some(account) = T::SiblingAddressConverter::convert_location(who) {
let pallet_account: T::AccountId =
T::AssetHandlerPalletId::get().into_account_truncating();
let amount: u128 = Self::get_amount(fun).ok_or(XcmError::Trap(101))?;
Expand Down Expand Up @@ -484,7 +490,7 @@ pub mod pallet {
&who_account,
pallet_account,
)
.map_err(|err| XcmError::Trap(110))?;
.map_err(|_| XcmError::Trap(110))?;
Ok(what.clone().into())
}

Expand Down Expand Up @@ -600,10 +606,9 @@ pub mod pallet {
== AssetId::Concrete(MultiLocation {
parents: 1,
interior: Junctions::X1(Parachain(T::ParachainId::get())),
}) || asset == AssetId::Concrete(MultiLocation {
parents: 0,
interior: Junctions::Here,
}) {
}) || asset
== AssetId::Concrete(MultiLocation { parents: 0, interior: Junctions::Here })
{
return polkadex_primitives::AssetId::Polkadex;
}
// If it's not native, then hash and generate the asset id
Expand Down Expand Up @@ -672,6 +677,8 @@ pub mod pallet {
Err(_) => {
failed_withdrawal.push(withdrawal);
log::error!(target:"xcm-helper","Withdrawal failed: Not able to decode destination");
// Emit Event
Self::deposit_event(Event::<T>::NotAbleToDecodeDestination);
continue;
},
};
Expand All @@ -693,14 +700,6 @@ pub mod pallet {
};
let pallet_account: T::AccountId =
T::AssetHandlerPalletId::get().into_account_truncating();
let destination_location = match destination {
VersionedMultiLocation::V3(location) => location,
_ => {
failed_withdrawal.push(withdrawal);
log::error!(target:"xcm-helper","Withdrawal failed: Not able to decode destination");
continue;
},
};
if Self::resolve_deposit_parachain(
withdrawal.asset_id.into(),
withdrawal.amount,
Expand All @@ -713,6 +712,7 @@ pub mod pallet {
{
failed_withdrawal.push(withdrawal.clone());
log::error!(target:"xcm-helper","Withdrawal failed: Not able to mint token");
Self::deposit_event(Event::<T>::NotAbleToMintToken);
};
// Deposit Fee
if Self::resolve_deposit_parachain(
Expand All @@ -727,6 +727,7 @@ pub mod pallet {
{
failed_withdrawal.push(withdrawal.clone());
log::error!(target:"xcm-helper","Withdrawal failed: Not able to mint token");
Self::deposit_event(Event::<T>::NotAbleToMintToken);
};
if let Err(err) =
orml_xtokens::module::Pallet::<T>::transfer_multiassets(
Expand All @@ -741,6 +742,7 @@ pub mod pallet {
cumulus_primitives_core::WeightLimit::Unlimited,
) {
failed_withdrawal.push(withdrawal.clone());
Self::deposit_event(Event::<T>::NotAbleToMakeXcmCall);
log::error!(target:"xcm-helper","Withdrawal failed: Not able to make xcm calls: {:?}", err);
} else {
// Deposit event
Expand All @@ -762,6 +764,7 @@ pub mod pallet {
_ => {
failed_withdrawal.push(withdrawal);
log::error!(target:"xcm-helper","Withdrawal failed: Not able to decode destination");
Self::deposit_event(Event::<T>::NotAbleToDecodeDestination);
continue;
},
};
Expand Down Expand Up @@ -817,6 +820,7 @@ pub mod pallet {
) {
failed_withdrawal.push(withdrawal.clone());
log::error!(target:"xcm-helper","Withdrawal failed: Not able to make xcm calls {:?}", err);
Self::deposit_event(Event::<T>::NotAbleToMakeXcmCall);
} else {
// Deposit event
Self::deposit_event(Event::<T>::AssetWithdrawn(
Expand All @@ -826,10 +830,12 @@ pub mod pallet {
}
} else {
log::error!(target:"xcm-helper","Withdrawal failed: Not able to handle dest");
failed_withdrawal.push(withdrawal)
Self::deposit_event(Event::<T>::NotAbleToDecodeDestination);
failed_withdrawal.push(withdrawal);
}
} else if Self::handle_deposit(withdrawal.clone(), destination).is_err() {
failed_withdrawal.push(withdrawal);
Self::deposit_event(Event::<T>::NotAbleToHandleDestination);
log::error!(target:"xcm-helper","Withdrawal failed: Not able to handle dest");
}
} else {
Expand Down
1 change: 0 additions & 1 deletion polkadex-xcm-simulator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ xcm-helper = { path = "../pallets/xcm-helper" }
thea-message-handler = { path = "../pallets/thea-message-handler" }
thea = { path = "../pallets/thea" }
smallvec = "1.13.1"
#polkadot-runtime-common = { workspace = true, default-features = false }



Expand Down
40 changes: 25 additions & 15 deletions polkadex-xcm-simulator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,7 @@ mod tests {
extra: ExtraData::None,
};
assert_ok!(Balances::mint_into(&XcmHelper::get_pallet_account(), 100000000000000000));
XcmHelper::insert_parachain_asset(
asset_id_ml,
polkadex_primitives::AssetId::Polkadex,
);
XcmHelper::insert_parachain_asset(asset_id_ml, polkadex_primitives::AssetId::Polkadex);
let block_no = 1;
XcmHelper::insert_pending_withdrawal(block_no, deposit.clone());
XcmHelper::handle_new_pending_withdrawals(block_no);
Expand All @@ -561,16 +558,30 @@ mod tests {
MockNet::reset();

ParaC::execute_with(|| {
let multlocation =
MultiLocation { parents: 0, interior: Junctions::Here };
let multlocation = MultiLocation { parents: 0, interior: Junctions::Here };
let pdex_asset_id = AssetId::Concrete(multlocation);
assert_ok!(Balances::mint_into(&XcmHelper::get_pallet_account(), 100_000_000_000_000_000));
let para_a = MultiLocation { parents: 1, interior: Junctions::X1(Junction::Parachain(1)) };
let para_b = MultiLocation { parents: 1, interior: Junctions::X1(Junction::Parachain(2)) };
let para_c = MultiLocation { parents: 1, interior: Junctions::X1(Junction::Parachain(3)) };
assert_ok!(Balances::mint_into(&XcmHelper::sibling_account_converter(para_a).unwrap(), 100_000_000_000_000_000));
assert_ok!(Balances::mint_into(&XcmHelper::sibling_account_converter(para_b).unwrap(), 100_000_000_000_000_000));
assert_ok!(Balances::mint_into(&XcmHelper::sibling_account_converter(para_c).unwrap(), 100_000_000_000_000_000));
assert_ok!(Balances::mint_into(
&XcmHelper::get_pallet_account(),
100_000_000_000_000_000
));
let para_a =
MultiLocation { parents: 1, interior: Junctions::X1(Junction::Parachain(1)) };
let para_b =
MultiLocation { parents: 1, interior: Junctions::X1(Junction::Parachain(2)) };
let para_c =
MultiLocation { parents: 1, interior: Junctions::X1(Junction::Parachain(3)) };
assert_ok!(Balances::mint_into(
&XcmHelper::sibling_account_converter(para_a).unwrap(),
100_000_000_000_000_000
));
assert_ok!(Balances::mint_into(
&XcmHelper::sibling_account_converter(para_b).unwrap(),
100_000_000_000_000_000
));
assert_ok!(Balances::mint_into(
&XcmHelper::sibling_account_converter(para_c).unwrap(),
100_000_000_000_000_000
));
XcmHelper::insert_parachain_asset(
pdex_asset_id,
polkadex_primitives::AssetId::Polkadex,
Expand Down Expand Up @@ -606,8 +617,7 @@ mod tests {
XcmHelper::handle_new_pending_withdrawals(block_no);
});
ParaC::execute_with(|| {
let multlocation =
MultiLocation { parents: 0, interior: Junctions::Here };
let multlocation = MultiLocation { parents: 0, interior: Junctions::Here };
let pdex_asset_id = AssetId::Concrete(multlocation);
assert_ok!(Balances::mint_into(&XcmHelper::get_pallet_account(), 100000000000000000));
XcmHelper::insert_parachain_asset(
Expand Down
42 changes: 18 additions & 24 deletions polkadex-xcm-simulator/src/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ use frame_support::{
PalletId,
};
use frame_system::{EnsureRoot, EnsureSigned};
use orml_traits::location::{AbsoluteReserveProvider, RelativeReserveProvider};
use orml_traits::location::AbsoluteReserveProvider;
use orml_traits::parameter_type_with_key;
use orml_xcm_support::MultiNativeAsset;
use pallet_xcm::XcmPassthrough;
use polkadot_core_primitives::BlockNumber as RelayBlockNumber;
use polkadot_parachain_primitives::primitives::{
Expand All @@ -45,17 +44,13 @@ use thea::ecdsa::AuthorityId;
use thea::ecdsa::AuthoritySignature;
use xcm::{latest::prelude::*, VersionedXcm};
use xcm_builder::{
Account32Hash, AccountId32Aliases, AllowUnpaidExecutionFrom, ConvertedConcreteId,
CurrencyAdapter as XcmCurrencyAdapter, CurrencyAdapter, EnsureXcmOrigin, FixedRateOfFungible,
FixedWeightBounds, IsConcrete, NativeAsset, NoChecking, NonFungiblesAdapter, ParentIsPreset,
Account32Hash, AccountId32Aliases, AllowUnpaidExecutionFrom, EnsureXcmOrigin,
FixedRateOfFungible, FixedWeightBounds, NativeAsset, ParentIsPreset,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeRevenue, UsingComponents,
SovereignSignedViaLocation, TakeRevenue,
};
use xcm_executor::traits::WeightTrader;
use xcm_executor::{
traits::{ConvertLocation, JustTry},
Config, XcmExecutor,
};
use xcm_executor::{traits::ConvertLocation, Config, XcmExecutor};
use xcm_helper::{AssetIdConverter, WhitelistedTokenHandler};

pub type SovereignAccountOf = (
Expand Down Expand Up @@ -216,18 +211,19 @@ parameter_types! {
pub PdexLocation: MultiLocation = Here.into();
}

pub type LocalAssetTransactor = CurrencyAdapter<
// Use this currency:
Balances,
// Use this currency when it is a fungible asset matching the given location or name:
IsConcrete<RelayLocation>,
// Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID:
LocationToAccountId,
// Our chain's account ID type (we can't get away without mentioning it explicitly):
AccountId,
// We don't track any teleports.
(),
>;
// Can be used later
// pub type LocalAssetTransactor = CurrencyAdapter<
// // Use this currency:
// Balances,
// // Use this currency when it is a fungible asset matching the given location or name:
// IsConcrete<RelayLocation>,
// // Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID:
// LocationToAccountId,
// // Our chain's account ID type (we can't get away without mentioning it explicitly):
// AccountId,
// // We don't track any teleports.
// (),
// >;

pub type XcmRouter = super::ParachainXcmRouter<MsgQueue>;
pub type Barrier = AllowUnpaidExecutionFrom<Everything>;
Expand Down Expand Up @@ -466,8 +462,6 @@ parameter_types! {
pub RelayTokenForRelay: (MultiLocation, MultiAssetFilter) = (Parent.into(), Wild(AllOf { id: Concrete(Parent.into()), fun: WildFungible }));
}

pub type TrustedLockers = TrustedLockerCase<RelayTokenForRelay>;

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
Expand Down
2 changes: 1 addition & 1 deletion primitives/polkadex/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub trait Resolver<
who: &AccountId,
admin: AccountId,
min_balance: Balance,
locking_account: AccountId,
_locking_account: AccountId,
) -> Result<(), DispatchError> {
if asset == NativeAssetId::get() {
Native::mint_into(who, amount.saturated_into())?;
Expand Down
3 changes: 3 additions & 0 deletions runtimes/parachain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ impl xcm_helper::Config for Runtime {
type SubstrateNetworkId = ParachainNetworkId;
type NativeAssetId = PolkadexAssetid;
type WeightInfo = xcm_helper::weights::WeightInfo<Runtime>;
type SiblingAddressConverter = SiblingParachainConvertsVia<Sibling, AccountId>;
}

parameter_types! {
Expand Down Expand Up @@ -538,6 +539,8 @@ impl pallet_assets::Config for Runtime {
pub struct AssetU128;
#[cfg(feature = "runtime-benchmarks")]
use pallet_assets::BenchmarkHelper;
use polkadot_parachain::primitives::Sibling;
use xcm_builder::SiblingParachainConvertsVia;

#[cfg(feature = "runtime-benchmarks")]
impl BenchmarkHelper<parity_scale_codec::Compact<u128>> for AssetU128 {
Expand Down

0 comments on commit 95832aa

Please sign in to comment.