Skip to content

Commit

Permalink
feat(asset-hubs): add PoolAssetsExchanger
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoaguirre committed Jan 10, 2025
1 parent 80ac2e4 commit 5840c18
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
24 changes: 23 additions & 1 deletion system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,28 @@ pub type PoolFungiblesTransactor = FungiblesAdapter<
pub type AssetTransactors =
(FungibleTransactor, FungiblesTransactor, ForeignFungiblesTransactor, PoolFungiblesTransactor);

/// Asset converter for pool assets.
/// Used to convert one asset to another, when there is a pool available between the two.
/// This type thus allows paying delivery fees with any asset as long as there is a pool between said
/// asset and the asset required for fee payment.
pub type PoolAssetsExchanger = SingleAssetExchangeAdapter<
AssetConversion,
NativeAndAssets,
(
TrustBackedAssetsAsLocation<TrustBackedAssetsPalletLocation, Balance, xcm::v4::Location>,
ForeignAssetsConvertedConcreteId,
// `ForeignAssetsConvertedConcreteId` excludes the relay token, so we add it back here.
MatchedConvertedConcreteId<
xcm::v4::Location,
Balance,
Equals<ParentLocation>,
WithLatestLocationConverter<xcm::v4::Location>,
TryConvertInto,
>,
),
AccountId,
>;

/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
/// ready for dispatching a transaction with Xcm's `Transact`.
///
Expand Down Expand Up @@ -378,7 +400,7 @@ impl xcm_executor::Config for XcmConfig {
type PalletInstancesInfo = AllPalletsWithSystem;
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type AssetLocker = ();
type AssetExchanger = ();
type AssetExchanger = PoolAssetsExchanger;
type FeeManager = XcmFeeManagerFromComponents<
WaivedLocations,
SendXcmFeeToAccount<Self::AssetTransactor, RelayTreasuryPalletAccount>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,28 @@ pub type PoolFungiblesTransactor = FungiblesAdapter<
pub type AssetTransactors =
(FungibleTransactor, FungiblesTransactor, ForeignFungiblesTransactor, PoolFungiblesTransactor);

/// Asset converter for pool assets.
/// Used to convert one asset to another, when there is a pool available between the two.
/// This type thus allows paying delivery fees with any asset as long as there is a pool between said
/// asset and the asset required for fee payment.
pub type PoolAssetsExchanger = SingleAssetExchangeAdapter<
AssetConversion,
NativeAndAssets,
(
TrustBackedAssetsAsLocation<TrustBackedAssetsPalletLocation, Balance, xcm::v4::Location>,
ForeignAssetsConvertedConcreteId,
// `ForeignAssetsConvertedConcreteId` excludes the relay token, so we add it back here.
MatchedConvertedConcreteId<
xcm::v4::Location,
Balance,
Equals<ParentLocation>,
WithLatestLocationConverter<xcm::v4::Location>,
TryConvertInto,
>,
),
AccountId,
>;

/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
/// ready for dispatching a transaction with Xcm's `Transact`.
///
Expand Down Expand Up @@ -443,7 +465,7 @@ impl xcm_executor::Config for XcmConfig {
type PalletInstancesInfo = AllPalletsWithSystem;
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type AssetLocker = ();
type AssetExchanger = ();
type AssetExchanger = PoolAssetsExchanger;
type FeeManager = XcmFeeManagerFromComponents<
WaivedLocations,
SendXcmFeeToAccount<Self::AssetTransactor, RelayTreasuryPalletAccount>,
Expand Down

0 comments on commit 5840c18

Please sign in to comment.