Skip to content

Commit

Permalink
Merge branch 'master' into gui-tasks-instantiable-pallets
Browse files Browse the repository at this point in the history
  • Loading branch information
gui1117 authored Oct 24, 2024
2 parents 392431a + 5682f9a commit 671913d
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 8 deletions.
2 changes: 2 additions & 0 deletions bridges/snowbridge/primitives/router/src/inbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ where
// Final destination is a 32-byte account on AssetHub
Destination::AccountId32 { id } =>
Ok(Location::new(0, [AccountId32 { network: None, id }])),
// Forwarding to a destination parachain is not allowed for PNA and is validated on the
// Ethereum side. https://github.com/Snowfork/snowbridge/blob/e87ddb2215b513455c844463a25323bb9c01ff36/contracts/src/Assets.sol#L216-L224
_ => Err(ConvertMessageError::InvalidDestination),
}?;

Expand Down
26 changes: 20 additions & 6 deletions bridges/snowbridge/primitives/router/src/outbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ where

fn convert(&mut self) -> Result<(Command, [u8; 32]), XcmConverterError> {
let result = match self.peek() {
Ok(ReserveAssetDeposited { .. }) => self.send_native_tokens_message(),
Ok(ReserveAssetDeposited { .. }) => self.make_mint_foreign_token_command(),
// Get withdraw/deposit and make native tokens create message.
Ok(WithdrawAsset { .. }) => self.send_tokens_message(),
Ok(WithdrawAsset { .. }) => self.make_unlock_native_token_command(),
Err(e) => Err(e),
_ => return Err(XcmConverterError::UnexpectedInstruction),
}?;
Expand All @@ -222,7 +222,9 @@ where
Ok(result)
}

fn send_tokens_message(&mut self) -> Result<(Command, [u8; 32]), XcmConverterError> {
fn make_unlock_native_token_command(
&mut self,
) -> Result<(Command, [u8; 32]), XcmConverterError> {
use XcmConverterError::*;

// Get the reserve assets from WithdrawAsset.
Expand Down Expand Up @@ -271,7 +273,12 @@ where
ensure!(reserve_assets.len() == 1, TooManyAssets);
let reserve_asset = reserve_assets.get(0).ok_or(AssetResolutionFailed)?;

// If there was a fee specified verify it.
// Fees are collected on AH, up front and directly from the user, to cover the
// complete cost of the transfer. Any additional fees provided in the XCM program are
// refunded to the beneficiary. We only validate the fee here if its provided to make sure
// the XCM program is well formed. Another way to think about this from an XCM perspective
// would be that the user offered to pay X amount in fees, but we charge 0 of that X amount
// (no fee) and refund X to the user.
if let Some(fee_asset) = fee_asset {
// The fee asset must be the same as the reserve asset.
if fee_asset.id != reserve_asset.id || fee_asset.fun > reserve_asset.fun {
Expand Down Expand Up @@ -328,7 +335,9 @@ where
/// # BuyExecution
/// # DepositAsset
/// # SetTopic
fn send_native_tokens_message(&mut self) -> Result<(Command, [u8; 32]), XcmConverterError> {
fn make_mint_foreign_token_command(
&mut self,
) -> Result<(Command, [u8; 32]), XcmConverterError> {
use XcmConverterError::*;

// Get the reserve assets.
Expand Down Expand Up @@ -377,7 +386,12 @@ where
ensure!(reserve_assets.len() == 1, TooManyAssets);
let reserve_asset = reserve_assets.get(0).ok_or(AssetResolutionFailed)?;

// If there was a fee specified verify it.
// Fees are collected on AH, up front and directly from the user, to cover the
// complete cost of the transfer. Any additional fees provided in the XCM program are
// refunded to the beneficiary. We only validate the fee here if its provided to make sure
// the XCM program is well formed. Another way to think about this from an XCM perspective
// would be that the user offered to pay X amount in fees, but we charge 0 of that X amount
// (no fee) and refund X to the user.
if let Some(fee_asset) = fee_asset {
// The fee asset must be the same as the reserve asset.
if fee_asset.id != reserve_asset.id || fee_asset.fun > reserve_asset.fun {
Expand Down
14 changes: 13 additions & 1 deletion polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ use sp_staking::SessionIndex;
#[cfg(any(feature = "std", test))]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use xcm::{latest::prelude::*, VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm};
use xcm::{
latest::prelude::*, VersionedAsset, VersionedAssetId, VersionedAssets, VersionedLocation,
VersionedXcm,
};
use xcm_builder::PayOverXcm;

pub use frame_system::Call as SystemCall;
Expand Down Expand Up @@ -2622,6 +2625,15 @@ sp_api::impl_runtime_apis! {
genesis_config_presets::preset_names()
}
}

impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
XcmPallet::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
XcmPallet::is_trusted_teleporter(asset, location)
}
}
}

#[cfg(all(test, feature = "try-runtime"))]
Expand Down
14 changes: 13 additions & 1 deletion polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ use sp_staking::SessionIndex;
#[cfg(any(feature = "std", test))]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use xcm::{latest::prelude::*, VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm};
use xcm::{
latest::prelude::*, VersionedAsset, VersionedAssetId, VersionedAssets, VersionedLocation,
VersionedXcm,
};
use xcm_builder::PayOverXcm;

use xcm_runtime_apis::{
Expand Down Expand Up @@ -2791,4 +2794,13 @@ sp_api::impl_runtime_apis! {
genesis_config_presets::preset_names()
}
}

impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
XcmPallet::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
XcmPallet::is_trusted_teleporter(asset, location)
}
}
}
32 changes: 32 additions & 0 deletions prdoc/pr_6212.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: "Added Trusted Query API calls for Westend and Rococo chains"

doc:
- audience: Runtime Dev
description: |
Added is_trusted_reserve and is_trusted_teleporter API calls to relay chains.
Given an asset and a location, they return if the chain trusts that location as a reserve or teleporter for that asset respectively.
You can implement them on your runtime by simply calling a helper function on `pallet-xcm`.
```rust
impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}
```

- audience: Runtime User
description: |
There's a new runtime API to check if a chain trust a Location as a reserve or teleporter for a given Asset.
It's implemented in all the relays and system parachains in Westend and Rococo.

crates:
- name: westend-runtime
bump: minor
- name: rococo-runtime
bump: minor

0 comments on commit 671913d

Please sign in to comment.