use crate::{transfer::TransferOverXcmHelperT, TransferOverXcmHelper};
use core::marker::PhantomData;
use pezframe_support::traits::{
tokens::{Pay, PaymentStatus},
Get,
};
use pezsp_runtime::traits::TryConvert;
use xcm::prelude::*;
use xcm_executor::traits::WaiveDeliveryFees;
pub type PayOverXcm<
Interior,
Router,
Querier,
Timeout,
Beneficiary,
AssetKind,
AssetKindToLocatableAsset,
BeneficiaryRefToLocation,
> = PayOverXcmWithHelper<
Interior,
TransferOverXcmHelper<
Router,
Querier,
WaiveDeliveryFees,
Timeout,
Beneficiary,
AssetKind,
AssetKindToLocatableAsset,
BeneficiaryRefToLocation,
>,
>;
pub struct PayOverXcmWithHelper<Interior, TransferOverXcmHelper>(
PhantomData<(Interior, TransferOverXcmHelper)>,
);
impl<Interior, TransferOverXcmHelper> Pay for PayOverXcmWithHelper<Interior, TransferOverXcmHelper>
where
Interior: Get<InteriorLocation>,
TransferOverXcmHelper: TransferOverXcmHelperT<Balance = u128, QueryId = QueryId>,
{
type Balance = u128;
type Beneficiary = TransferOverXcmHelper::Beneficiary;
type AssetKind = TransferOverXcmHelper::AssetKind;
type Id = TransferOverXcmHelper::QueryId;
type Error = xcm::latest::Error;
fn pay(
who: &Self::Beneficiary,
asset_kind: Self::AssetKind,
amount: Self::Balance,
) -> Result<Self::Id, Self::Error> {
TransferOverXcmHelper::send_remote_transfer_xcm(
Interior::get().into(),
who,
asset_kind,
amount,
None,
)
}
fn check_payment(id: Self::Id) -> PaymentStatus {
TransferOverXcmHelper::check_transfer(id)
}
#[cfg(feature = "runtime-benchmarks")]
fn ensure_successful(
beneficiary: &Self::Beneficiary,
asset_kind: Self::AssetKind,
balance: Self::Balance,
) {
TransferOverXcmHelper::ensure_successful(beneficiary, asset_kind, balance);
}
#[cfg(feature = "runtime-benchmarks")]
fn ensure_concluded(id: Self::Id) {
TransferOverXcmHelper::ensure_concluded(id);
}
}
pub type PayAccountId32OnChainOverXcm<
DestinationChain,
Interior,
Router,
Querier,
Timeout,
Beneficiary,
AssetKind,
> = PayOverXcm<
Interior,
Router,
Querier,
Timeout,
Beneficiary,
AssetKind,
crate::AliasesIntoAccountId32<(), Beneficiary>,
FixedLocation<DestinationChain>,
>;
pub struct LocatableAssetId {
pub asset_id: AssetId,
pub location: Location,
}
pub struct FixedLocation<FixedLocationValue>(core::marker::PhantomData<FixedLocationValue>);
impl<FixedLocationValue: Get<Location>, AssetKind: Into<AssetId>>
TryConvert<AssetKind, LocatableAssetId> for FixedLocation<FixedLocationValue>
{
fn try_convert(value: AssetKind) -> Result<LocatableAssetId, AssetKind> {
Ok(LocatableAssetId { asset_id: value.into(), location: FixedLocationValue::get() })
}
}