-
Notifications
You must be signed in to change notification settings - Fork 709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assets in pool with native can be used in query_weight_to_asset_fee
#6080
Changes from all commits
17b080b
375908a
aec5b5b
dcbb796
30cf711
a4e80ac
e4e1ca0
9121790
9b1f15b
932becb
86b9da8
860856b
4b01538
66897ac
385137b
2ff5cf7
db4040b
88d2f2d
14eb027
e650905
82ada8a
010299d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1412,31 +1412,41 @@ impl_runtime_apis! { | |||||||||||
// We accept the native token to pay fees. | ||||||||||||
let mut acceptable_assets = vec![AssetId(native_token.clone())]; | ||||||||||||
// We also accept all assets in a pool with the native token. | ||||||||||||
acceptable_assets.extend( | ||||||||||||
pallet_asset_conversion::Pools::<Runtime>::iter_keys().filter_map( | ||||||||||||
|(asset_1, asset_2)| { | ||||||||||||
if asset_1 == native_token { | ||||||||||||
Some(asset_2.clone().into()) | ||||||||||||
} else if asset_2 == native_token { | ||||||||||||
Some(asset_1.clone().into()) | ||||||||||||
} else { | ||||||||||||
None | ||||||||||||
} | ||||||||||||
}, | ||||||||||||
), | ||||||||||||
); | ||||||||||||
let assets_in_pool_with_native = assets_common::get_assets_in_pool_with::< | ||||||||||||
Runtime, | ||||||||||||
xcm::v4::Location | ||||||||||||
>(&native_token).map_err(|()| XcmPaymentApiError::VersionedConversionFailed)?.into_iter(); | ||||||||||||
acceptable_assets.extend(assets_in_pool_with_native); | ||||||||||||
PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets) | ||||||||||||
} | ||||||||||||
|
||||||||||||
fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> { | ||||||||||||
let native_asset = xcm_config::TokenLocation::get(); | ||||||||||||
let fee_in_native = WeightToFee::weight_to_fee(&weight); | ||||||||||||
match asset.try_as::<AssetId>() { | ||||||||||||
Ok(asset_id) if asset_id.0 == xcm_config::TokenLocation::get() => { | ||||||||||||
Ok(asset_id) if asset_id.0 == native_asset => { | ||||||||||||
// for native token | ||||||||||||
Ok(WeightToFee::weight_to_fee(&weight)) | ||||||||||||
Ok(fee_in_native) | ||||||||||||
}, | ||||||||||||
Ok(asset_id) => { | ||||||||||||
log::trace!(target: "xcm::xcm_runtime_apis", "query_weight_to_asset_fee - unhandled asset_id: {asset_id:?}!"); | ||||||||||||
Err(XcmPaymentApiError::AssetNotFound) | ||||||||||||
let assets_in_pool_with_this_asset: Vec<_> = assets_common::get_assets_in_pool_with::< | ||||||||||||
Runtime, | ||||||||||||
xcm::v4::Location | ||||||||||||
>(&asset_id.0).map_err(|()| XcmPaymentApiError::VersionedConversionFailed)?; | ||||||||||||
if assets_in_pool_with_this_asset | ||||||||||||
.into_iter() | ||||||||||||
.map(|asset_id| asset_id.0) | ||||||||||||
.any(|location| location == native_asset) { | ||||||||||||
Comment on lines
+1437
to
+1439
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if this compiles like this or maybe
Suggested change
|
||||||||||||
pallet_asset_conversion::Pallet::<Runtime>::quote_price_tokens_for_exact_tokens( | ||||||||||||
asset_id.clone().0, | ||||||||||||
native_asset, | ||||||||||||
fee_in_native, | ||||||||||||
true, // We include the fee. | ||||||||||||
).ok_or(XcmPaymentApiError::AssetNotFound) | ||||||||||||
} else { | ||||||||||||
log::trace!(target: "xcm::xcm_runtime_apis", "query_weight_to_asset_fee - unhandled asset_id: {asset_id:?}!"); | ||||||||||||
Err(XcmPaymentApiError::AssetNotFound) | ||||||||||||
} | ||||||||||||
}, | ||||||||||||
Err(_) => { | ||||||||||||
log::trace!(target: "xcm::xcm_runtime_apis", "query_weight_to_asset_fee - failed to convert asset: {asset:?}!"); | ||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1450,31 +1450,42 @@ impl_runtime_apis! { | |||||||||||
// We accept the native token to pay fees. | ||||||||||||
let mut acceptable_assets = vec![AssetId(native_token.clone())]; | ||||||||||||
// We also accept all assets in a pool with the native token. | ||||||||||||
acceptable_assets.extend( | ||||||||||||
pallet_asset_conversion::Pools::<Runtime>::iter_keys().filter_map( | ||||||||||||
|(asset_1, asset_2)| { | ||||||||||||
if asset_1 == native_token { | ||||||||||||
Some(asset_2.clone().into()) | ||||||||||||
} else if asset_2 == native_token { | ||||||||||||
Some(asset_1.clone().into()) | ||||||||||||
} else { | ||||||||||||
None | ||||||||||||
} | ||||||||||||
}, | ||||||||||||
), | ||||||||||||
); | ||||||||||||
let assets_in_pool_with_native = assets_common::get_assets_in_pool_with::< | ||||||||||||
Runtime, | ||||||||||||
xcm::v4::Location | ||||||||||||
>(&native_token).map_err(|()| XcmPaymentApiError::VersionedConversionFailed)?.into_iter(); | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think
Suggested change
|
||||||||||||
acceptable_assets.extend(assets_in_pool_with_native); | ||||||||||||
PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets) | ||||||||||||
} | ||||||||||||
|
||||||||||||
fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> { | ||||||||||||
let native_asset = xcm_config::WestendLocation::get(); | ||||||||||||
let fee_in_native = WeightToFee::weight_to_fee(&weight); | ||||||||||||
match asset.try_as::<AssetId>() { | ||||||||||||
Ok(asset_id) if asset_id.0 == xcm_config::WestendLocation::get() => { | ||||||||||||
// for native token | ||||||||||||
Ok(WeightToFee::weight_to_fee(&weight)) | ||||||||||||
Ok(asset_id) if asset_id.0 == native_asset => { | ||||||||||||
// for native asset | ||||||||||||
Ok(fee_in_native) | ||||||||||||
}, | ||||||||||||
Ok(asset_id) => { | ||||||||||||
log::trace!(target: "xcm::xcm_runtime_apis", "query_weight_to_asset_fee - unhandled asset_id: {asset_id:?}!"); | ||||||||||||
Err(XcmPaymentApiError::AssetNotFound) | ||||||||||||
// We recognize assets in a pool with the native one. | ||||||||||||
let assets_in_pool_with_this_asset: Vec<_> = assets_common::get_assets_in_pool_with::< | ||||||||||||
Runtime, | ||||||||||||
xcm::v4::Location | ||||||||||||
>(&asset_id.0).map_err(|()| XcmPaymentApiError::VersionedConversionFailed)?; | ||||||||||||
if assets_in_pool_with_this_asset | ||||||||||||
.into_iter() | ||||||||||||
.map(|asset_id| asset_id.0) | ||||||||||||
.any(|location| location == native_asset) { | ||||||||||||
Comment on lines
+1476
to
+1478
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
pallet_asset_conversion::Pallet::<Runtime>::quote_price_tokens_for_exact_tokens( | ||||||||||||
asset_id.clone().0, | ||||||||||||
native_asset, | ||||||||||||
fee_in_native, | ||||||||||||
true, // We include the fee. | ||||||||||||
).ok_or(XcmPaymentApiError::AssetNotFound) | ||||||||||||
} else { | ||||||||||||
log::trace!(target: "xcm::xcm_runtime_apis", "query_weight_to_asset_fee - unhandled asset_id: {asset_id:?}!"); | ||||||||||||
Err(XcmPaymentApiError::AssetNotFound) | ||||||||||||
} | ||||||||||||
}, | ||||||||||||
Err(_) => { | ||||||||||||
log::trace!(target: "xcm::xcm_runtime_apis", "query_weight_to_asset_fee - failed to convert asset: {asset:?}!"); | ||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# 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: Assets in pool with native can be used in query_weight_to_asset_fee in Asset Hubs | ||
|
||
doc: | ||
- audience: Runtime User | ||
description: | | ||
`query_weight_to_asset_fee` now works with assets in a pool with the native asset in both | ||
Westend and Rococo asset hubs. | ||
This means all the information you get from `query_acceptable_payment_assets` can be used | ||
directly in `query_weight_to_asset_fee` to get the correct fees that need to be paid. | ||
|
||
crates: | ||
- name: assets-common | ||
bump: minor | ||
- name: asset-hub-westend-runtime | ||
bump: minor | ||
- name: asset-hub-rococo-runtime | ||
bump: minor | ||
- name: emulated-integration-tests-common | ||
bump: minor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.