Skip to content

Commit

Permalink
feat: fix XcmPaymentApi::query_weight_to_asset_fee version conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoaguirre committed Dec 1, 2024
1 parent 0da88b2 commit 21b2e71
Show file tree
Hide file tree
Showing 16 changed files with 22 additions and 466 deletions.
325 changes: 13 additions & 312 deletions Cargo.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,8 @@ bp-bridge-hub-westend.workspace = true
snowbridge-router-primitives.workspace = true

[dev-dependencies]
<<<<<<< HEAD
asset-test-utils = { default-features = true, path = "../test-utils" }
=======
asset-test-utils = { workspace = true, default-features = true }
parachains-runtimes-test-utils = { workspace = true, default-features = true }
>>>>>>> 139691b1 (Fix `XcmPaymentApi::query_weight_to_asset_fee` version conversion (#6459))

[build-dependencies]
substrate-wasm-builder = { optional = true, workspace = true, default-features = true }
Expand Down
21 changes: 0 additions & 21 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1329,18 +1329,10 @@ 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.
<<<<<<< HEAD
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);
=======
acceptable_assets.extend(
assets_common::PoolAdapter::<Runtime>::get_assets_in_pool_with(native_token)
.map_err(|()| XcmPaymentApiError::VersionedConversionFailed)?
);
>>>>>>> 139691b1 (Fix `XcmPaymentApi::query_weight_to_asset_fee` version conversion (#6459))
PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets)
}

Expand All @@ -1354,22 +1346,9 @@ impl_runtime_apis! {
Ok(fee_in_native)
},
Ok(asset_id) => {
<<<<<<< HEAD
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) {
pallet_asset_conversion::Pallet::<Runtime>::quote_price_tokens_for_exact_tokens(
asset_id.clone().0,
=======
// Try to get current price of `asset_id` in `native_asset`.
if let Ok(Some(swapped_in_native)) = assets_common::PoolAdapter::<Runtime>::quote_price_tokens_for_exact_tokens(
asset_id.0.clone(),
>>>>>>> 139691b1 (Fix `XcmPaymentApi::query_weight_to_asset_fee` version conversion (#6459))
native_asset,
fee_in_native,
true, // We include the fee.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1355,8 +1355,6 @@ fn change_xcm_bridge_hub_ethereum_base_fee_by_governance_works() {
},
)
}
<<<<<<< HEAD
=======

#[test]
fn location_conversion_works() {
Expand Down Expand Up @@ -1482,4 +1480,3 @@ fn xcm_payment_api_works() {
Block,
>();
}
>>>>>>> 139691b1 (Fix `XcmPaymentApi::query_weight_to_asset_fee` version conversion (#6459))
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,8 @@ bp-bridge-hub-westend.workspace = true
snowbridge-router-primitives.workspace = true

[dev-dependencies]
<<<<<<< HEAD
asset-test-utils = { default-features = true, path = "../test-utils" }
=======
asset-test-utils = { workspace = true, default-features = true }
parachains-runtimes-test-utils = { workspace = true, default-features = true }
>>>>>>> 139691b1 (Fix `XcmPaymentApi::query_weight_to_asset_fee` version conversion (#6459))

[build-dependencies]
substrate-wasm-builder = { optional = true, workspace = true, default-features = true }
Expand Down
22 changes: 0 additions & 22 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1362,18 +1362,10 @@ 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.
<<<<<<< HEAD
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);
=======
acceptable_assets.extend(
assets_common::PoolAdapter::<Runtime>::get_assets_in_pool_with(native_token)
.map_err(|()| XcmPaymentApiError::VersionedConversionFailed)?
);
>>>>>>> 139691b1 (Fix `XcmPaymentApi::query_weight_to_asset_fee` version conversion (#6459))
PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets)
}

Expand All @@ -1387,23 +1379,9 @@ impl_runtime_apis! {
Ok(fee_in_native)
},
Ok(asset_id) => {
<<<<<<< HEAD
// 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) {
pallet_asset_conversion::Pallet::<Runtime>::quote_price_tokens_for_exact_tokens(
asset_id.clone().0,
=======
// Try to get current price of `asset_id` in `native_asset`.
if let Ok(Some(swapped_in_native)) = assets_common::PoolAdapter::<Runtime>::quote_price_tokens_for_exact_tokens(
asset_id.0.clone(),
>>>>>>> 139691b1 (Fix `XcmPaymentApi::query_weight_to_asset_fee` version conversion (#6459))
native_asset,
fee_in_native,
true, // We include the fee.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1329,8 +1329,6 @@ fn reserve_transfer_native_asset_to_non_teleport_para_works() {
WeightLimit::Unlimited,
);
}
<<<<<<< HEAD
=======

#[test]
fn location_conversion_works() {
Expand Down Expand Up @@ -1456,4 +1454,3 @@ fn xcm_payment_api_works() {
Block,
>();
}
>>>>>>> 139691b1 (Fix `XcmPaymentApi::query_weight_to_asset_fee` version conversion (#6459))
23 changes: 0 additions & 23 deletions cumulus/parachains/runtimes/assets/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,6 @@ workspace = true

[dependencies]
codec = { features = ["derive", "max-encoded-len"], workspace = true }
<<<<<<< HEAD
frame-support.workspace = true
frame-system.workspace = true
pallet-assets.workspace = true
pallet-balances.workspace = true
pallet-timestamp.workspace = true
pallet-session.workspace = true
sp-io.workspace = true
sp-runtime.workspace = true
cumulus-pallet-parachain-system.workspace = true
cumulus-pallet-xcmp-queue.workspace = true
pallet-collator-selection.workspace = true
parachains-common.workspace = true
cumulus-primitives-core.workspace = true
parachain-info.workspace = true
parachains-runtimes-test-utils.workspace = true
xcm.workspace = true
xcm-builder.workspace = true
xcm-executor.workspace = true
pallet-xcm.workspace = true
pallet-xcm-bridge-hub-router.workspace = true
=======

# Substrate
frame-support = { workspace = true }
Expand Down Expand Up @@ -63,7 +41,6 @@ xcm-runtime-apis = { workspace = true }

# Bridges
pallet-xcm-bridge-hub-router = { workspace = true }
>>>>>>> 139691b1 (Fix `XcmPaymentApi::query_weight_to_asset_fee` version conversion (#6459))

[dev-dependencies]
hex-literal = { workspace = true, default-features = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,7 @@ where
AssetId = u32,
Balance = <Runtime as pallet_balances::Config>::Balance,
> + pallet_asset_conversion::Config<
AssetKind = xcm::v5::Location,
AssetKind = xcm::v4::Location,
Balance = <Runtime as pallet_balances::Config>::Balance,
>,
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
Expand Down Expand Up @@ -1660,7 +1660,7 @@ where
));
let execution_fees = Runtime::query_weight_to_asset_fee(
xcm_weight.unwrap(),
asset_not_in_pool.clone().into(),
VersionedAssetId::from(AssetId(asset_not_in_pool.clone())),
);
assert_eq!(execution_fees, Err(XcmPaymentApiError::AssetNotFound));

Expand All @@ -1672,7 +1672,7 @@ where
));
let execution_fees = Runtime::query_weight_to_asset_fee(
xcm_weight.unwrap(),
asset_not_in_pool.clone().into(),
VersionedAssetId::from(AssetId(asset_not_in_pool.clone())),
);
// Still not enough because it doesn't have any liquidity.
assert_eq!(execution_fees, Err(XcmPaymentApiError::AssetNotFound));
Expand All @@ -1696,7 +1696,7 @@ where
test_account
));
let execution_fees =
Runtime::query_weight_to_asset_fee(xcm_weight.unwrap(), asset_not_in_pool.into());
Runtime::query_weight_to_asset_fee(xcm_weight.unwrap(), VersionedAssetId::from(AssetId(asset_not_in_pool)));
// Now it works!
assert_ok!(execution_fees);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,12 @@ snowbridge-runtime-common.workspace = true
bridge-hub-common.workspace = true

[dev-dependencies]
<<<<<<< HEAD
bridge-hub-test-utils = { default-features = true, path = "../test-utils" }
bridge-runtime-common = { features = ["integrity-test"], default-features = true, path = "../../../../../bridges/bin/runtime-common" }
pallet-bridge-relayers = { features = ["integrity-test"], path = "../../../../../bridges/modules/relayers", default-features = false }
sp-keyring = { default-features = true, path = "../../../../../substrate/primitives/keyring" }
snowbridge-runtime-test-common = { default-features = true, path = "../../../../../bridges/snowbridge/runtime/test-common" }
=======
sp-keyring = { workspace = true }
bridge-hub-test-utils = { workspace = true, default-features = true }
bridge-runtime-common = { features = ["integrity-test"], workspace = true, default-features = true }
pallet-bridge-relayers = { features = ["integrity-test"], workspace = true }
snowbridge-runtime-test-common = { workspace = true, default-features = true }
parachains-runtimes-test-utils = { workspace = true, default-features = true }
>>>>>>> 139691b1 (Fix `XcmPaymentApi::query_weight_to_asset_fee` version conversion (#6459))

[features]
default = ["std"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,11 @@

use bp_polkadot_core::Signature;
use bridge_hub_rococo_runtime::{
<<<<<<< HEAD
bridge_common_config, bridge_to_bulletin_config,
bridge_to_ethereum_config::EthereumGatewayAddress,
bridge_to_westend_config,
xcm_config::{LocationToAccountId, RelayNetwork, TokenLocation, XcmConfig},
AllPalletsWithoutSystem, BridgeRejectObsoleteHeadersAndMessages, Executive, ExistentialDeposit,
ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, SessionKeys,
SignedExtra, TransactionPayment, UncheckedExtrinsic,
=======
bridge_common_config, bridge_to_bulletin_config, bridge_to_westend_config,
xcm_config::{RelayNetwork, TokenLocation, XcmConfig},
xcm_config::{LocationToAccountId, RelayNetwork, TokenLocation, XcmConfig},
AllPalletsWithoutSystem, Block, BridgeRejectObsoleteHeadersAndMessages, Executive,
ExistentialDeposit, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent,
RuntimeOrigin, SessionKeys, TransactionPayment, TxExtension, UncheckedExtrinsic,
>>>>>>> 139691b1 (Fix `XcmPaymentApi::query_weight_to_asset_fee` version conversion (#6459))
RuntimeOrigin, SessionKeys, SignedExtra, TransactionPayment, TxExtension, UncheckedExtrinsic,
};
use bridge_hub_test_utils::SlotDurations;
use codec::{Decode, Encode};
Expand Down Expand Up @@ -723,8 +713,6 @@ mod bridge_hub_bulletin_tests {
)
}
}
<<<<<<< HEAD
=======

#[test]
fn change_required_stake_by_governance_works() {
Expand Down Expand Up @@ -866,4 +854,3 @@ fn xcm_payment_api_works() {
Block,
>();
}
>>>>>>> 139691b1 (Fix `XcmPaymentApi::query_weight_to_asset_fee` version conversion (#6459))
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,12 @@ snowbridge-runtime-common.workspace = true


[dev-dependencies]
<<<<<<< HEAD
bridge-hub-test-utils = { default-features = true, path = "../test-utils" }
bridge-runtime-common = { features = ["integrity-test"], default-features = true, path = "../../../../../bridges/bin/runtime-common" }
pallet-bridge-relayers = { features = ["integrity-test"], path = "../../../../../bridges/modules/relayers", default-features = false }
sp-keyring = { default-features = true, path = "../../../../../substrate/primitives/keyring" }
snowbridge-runtime-test-common = { default-features = true, path = "../../../../../bridges/snowbridge/runtime/test-common" }
=======
sp-keyring = { workspace = true, default-features = true }
bridge-hub-test-utils = { workspace = true, default-features = true }
bridge-runtime-common = { features = ["integrity-test"], workspace = true, default-features = true }
pallet-bridge-relayers = { features = ["integrity-test"], workspace = true }
snowbridge-runtime-test-common = { workspace = true, default-features = true }
parachains-runtimes-test-utils = { workspace = true, default-features = true }
>>>>>>> 139691b1 (Fix `XcmPaymentApi::query_weight_to_asset_fee` version conversion (#6459))

[features]
default = ["std"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,9 @@ use bridge_hub_westend_runtime::{
bridge_common_config, bridge_to_rococo_config,
bridge_to_rococo_config::RococoGlobalConsensusNetwork,
xcm_config::{LocationToAccountId, RelayNetwork, WestendLocation, XcmConfig},
<<<<<<< HEAD
AllPalletsWithoutSystem, BridgeRejectObsoleteHeadersAndMessages, Executive, ExistentialDeposit,
ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, SessionKeys,
SignedExtra, TransactionPayment, UncheckedExtrinsic,
=======
AllPalletsWithoutSystem, Block, BridgeRejectObsoleteHeadersAndMessages, Executive,
ExistentialDeposit, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent,
RuntimeOrigin, SessionKeys, TransactionPayment, TxExtension, UncheckedExtrinsic,
>>>>>>> 139691b1 (Fix `XcmPaymentApi::query_weight_to_asset_fee` version conversion (#6459))
RuntimeOrigin, SessionKeys, SignedExtra, TransactionPayment, TxExtension, UncheckedExtrinsic,
};
use bridge_to_rococo_config::{
BridgeGrandpaRococoInstance, BridgeHubRococoLocation, BridgeParachainRococoInstance,
Expand Down Expand Up @@ -408,8 +402,6 @@ pub fn can_calculate_fee_for_standalone_message_confirmation_transaction() {
),
)
}
<<<<<<< HEAD
=======

#[test]
fn location_conversion_works() {
Expand Down Expand Up @@ -529,4 +521,3 @@ fn xcm_payment_api_works() {
Block,
>();
}
>>>>>>> 139691b1 (Fix `XcmPaymentApi::query_weight_to_asset_fee` version conversion (#6459))
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,8 @@ testnet-parachains-constants = { features = ["westend"], workspace = true }
substrate-wasm-builder = { optional = true, workspace = true, default-features = true }

[dev-dependencies]
<<<<<<< HEAD
sp-io = { features = ["std"], default-features = true, path = "../../../../../substrate/primitives/io" }
=======
sp-io = { features = ["std"], workspace = true, default-features = true }
parachains-runtimes-test-utils = { workspace = true, default-features = true }
>>>>>>> 139691b1 (Fix `XcmPaymentApi::query_weight_to_asset_fee` version conversion (#6459))

[features]
default = ["std"]
Expand Down
25 changes: 0 additions & 25 deletions cumulus/parachains/runtimes/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,6 @@ workspace = true

[dependencies]
codec = { features = ["derive", "max-encoded-len"], workspace = true }
<<<<<<< HEAD
frame-support.workspace = true
frame-system.workspace = true
pallet-balances.workspace = true
pallet-session.workspace = true
pallet-timestamp.workspace = true
sp-consensus-aura.workspace = true
sp-io.workspace = true
sp-runtime.workspace = true
sp-tracing.workspace = true
sp-tracing.default-features = true
sp-core.workspace = true
cumulus-pallet-parachain-system.workspace = true
cumulus-pallet-xcmp-queue.workspace = true
pallet-collator-selection.workspace = true
parachain-info.workspace = true
cumulus-primitives-core.workspace = true
cumulus-primitives-parachain-inherent.workspace = true
cumulus-test-relay-sproof-builder.workspace = true
xcm.workspace = true
xcm-executor.workspace = true
pallet-xcm.workspace = true
polkadot-parachain-primitives.workspace = true
=======

# Substrate
frame-support = { workspace = true }
Expand Down Expand Up @@ -64,7 +40,6 @@ xcm-executor = { workspace = true }
pallet-xcm = { workspace = true }
xcm-runtime-apis = { workspace = true }
polkadot-parachain-primitives = { workspace = true }
>>>>>>> 139691b1 (Fix `XcmPaymentApi::query_weight_to_asset_fee` version conversion (#6459))

[dev-dependencies]
hex-literal = { workspace = true, default-features = true }
Expand Down
File renamed without changes.

0 comments on commit 21b2e71

Please sign in to comment.