Skip to content

Commit

Permalink
Support DOT reseve on AH and Snowfork bridged assets
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc committed Feb 3, 2025
1 parent adc45f5 commit 2af1741
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 7 deletions.
23 changes: 20 additions & 3 deletions runtime/acala/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ use parity_scale_codec::{Decode, Encode};
use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery;
use primitives::evm::is_system_contract;
use runtime_common::{
local_currency_location, native_currency_location, AcalaDropAssets, EnsureRootOrHalfGeneralCouncil,
local_currency_location, native_currency_location, xcm_config::RelayLocationFilter,
xcm_impl::IsBridgedConcreteAssetFrom, AcalaDropAssets, EnsureRootOrHalfGeneralCouncil,
EnsureRootOrThreeFourthsGeneralCouncil, FixedRateOfAsset, RuntimeBlockWeights,
};
use sp_runtime::Perbill;
use xcm::{prelude::*, v3::Weight as XcmWeight};
use xcm_builder::{
EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, FrameTransactionalProcessor, SignedToAccountId32,
Case, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, FrameTransactionalProcessor, SignedToAccountId32,
};

parameter_types! {
Expand Down Expand Up @@ -94,8 +95,24 @@ parameter_types! {
0
);
pub BaseRate: u128 = aca_per_second();

/// Location of Asset Hub
pub AssetHubLocation: Location = Location::new(1, [Parachain(1000)]);
pub RelayChainNativeAssetFromAssetHub: (AssetFilter, Location) = (
RelayLocationFilter::get(),
AssetHubLocation::get()
);
}

type Reserves = (
// Assets bridged from different consensus systems held in reserve on Asset Hub.
IsBridgedConcreteAssetFrom<AssetHubLocation>,
// Relaychain (DOT) from Asset Hub
Case<RelayChainNativeAssetFromAssetHub>,
// Assets which the reserve is the same as the origin.
MultiNativeAsset<AbsoluteReserveProvider>,
);

pub type Trader = (
FixedRateOfAsset<BaseRate, ToTreasury, BuyWeightRateOfTransactionFeePool<Runtime, CurrencyIdConvert>>,
FixedRateOfFungible<AcaPerSecond, ToTreasury>,
Expand All @@ -115,7 +132,7 @@ impl xcm_executor::Config for XcmConfig {
// How to withdraw and deposit an asset.
type AssetTransactor = LocalAssetTransactor;
type OriginConverter = XcmOriginToCallOrigin;
type IsReserve = MultiNativeAsset<AbsoluteReserveProvider>;
type IsReserve = Reserves;
type IsTeleporter = runtime_common::xcm_config::TrustedTeleporters;
type UniversalLocation = UniversalLocation;
type Barrier = Barrier;
Expand Down
4 changes: 4 additions & 0 deletions runtime/common/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ impl Convert<AccountId, Location> for AccountIdToLocation {

parameter_types! {
pub const RelayLocation: Location = Location::parent();
pub RelayLocationFilter: AssetFilter = Wild(AllOf {
fun: WildFungible,
id: xcm::prelude::AssetId(RelayLocation::get()),
});
}

// define assets that can be trusted to teleport by remotes
Expand Down
25 changes: 24 additions & 1 deletion runtime/common/src/xcm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

//! Common xcm implementation
use frame_support::{traits::Get, weights::constants::WEIGHT_REF_TIME_PER_SECOND};
use frame_support::{
traits::{ContainsPair, Get},
weights::constants::WEIGHT_REF_TIME_PER_SECOND,
};
use module_support::BuyWeightRate;
use orml_traits::GetByKey;
use parity_scale_codec::Encode;
Expand Down Expand Up @@ -295,6 +298,26 @@ where
}
}

/// Matches foreign assets from a given origin.
/// Foreign assets are assets bridged from other consensus systems. i.e parents > 1.
pub struct IsBridgedConcreteAssetFrom<Origin>(PhantomData<Origin>);
impl<Origin> ContainsPair<Asset, Location> for IsBridgedConcreteAssetFrom<Origin>
where
Origin: Get<Location>,
{
fn contains(asset: &Asset, origin: &Location) -> bool {
let loc = Origin::get();
&loc == origin
&& matches!(
asset,
Asset {
id: AssetId(Location { parents: 2, .. }),
fun: Fungibility::Fungible(_)
},
)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
23 changes: 20 additions & 3 deletions runtime/karura/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ use parity_scale_codec::{Decode, Encode};
use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery;
use primitives::evm::is_system_contract;
use runtime_common::{
local_currency_location, native_currency_location, AcalaDropAssets, EnsureRootOrHalfGeneralCouncil,
local_currency_location, native_currency_location, xcm_config::RelayLocationFilter,
xcm_impl::IsBridgedConcreteAssetFrom, AcalaDropAssets, EnsureRootOrHalfGeneralCouncil,
EnsureRootOrThreeFourthsGeneralCouncil, FixedRateOfAsset, RuntimeBlockWeights,
};
use sp_runtime::Perbill;
use xcm::{prelude::*, v3::Weight as XcmWeight};
use xcm_builder::{
EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, FrameTransactionalProcessor, SignedToAccountId32,
Case, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, FrameTransactionalProcessor, SignedToAccountId32,
};

parameter_types! {
Expand Down Expand Up @@ -136,8 +137,24 @@ parameter_types! {
);

pub BaseRate: u128 = kar_per_second();

/// Location of Asset Hub
pub AssetHubLocation: Location = Location::new(1, [Parachain(1000)]);
pub RelayChainNativeAssetFromAssetHub: (AssetFilter, Location) = (
RelayLocationFilter::get(),
AssetHubLocation::get()
);
}

type Reserves = (
// Assets bridged from different consensus systems held in reserve on Asset Hub.
IsBridgedConcreteAssetFrom<AssetHubLocation>,
// Relaychain (DOT) from Asset Hub
Case<RelayChainNativeAssetFromAssetHub>,
// Assets which the reserve is the same as the origin.
MultiNativeAsset<AbsoluteReserveProvider>,
);

pub type Trader = (
FixedRateOfAsset<BaseRate, ToTreasury, BuyWeightRateOfTransactionFeePool<Runtime, CurrencyIdConvert>>,
FixedRateOfFungible<KarPerSecond, ToTreasury>,
Expand All @@ -162,7 +179,7 @@ impl xcm_executor::Config for XcmConfig {
// How to withdraw and deposit an asset.
type AssetTransactor = LocalAssetTransactor;
type OriginConverter = XcmOriginToCallOrigin;
type IsReserve = MultiNativeAsset<AbsoluteReserveProvider>;
type IsReserve = Reserves;
type IsTeleporter = runtime_common::xcm_config::TrustedTeleporters;
type UniversalLocation = UniversalLocation;
type Barrier = Barrier;
Expand Down

0 comments on commit 2af1741

Please sign in to comment.