From 49131940c0f68ce097d3c96ed936b36096534ab2 Mon Sep 17 00:00:00 2001 From: zjb0807 Date: Thu, 19 Jun 2025 11:41:23 +0800 Subject: [PATCH 01/12] fix tests --- Cargo.lock | 1 + runtime/acala/src/lib.rs | 22 +++++++++++----- runtime/acala/src/xcm_config.rs | 2 +- runtime/integration-tests/Cargo.toml | 1 + runtime/integration-tests/src/runtime.rs | 33 +++++++++++++++++------- runtime/karura/src/lib.rs | 24 +++++++++++------ runtime/karura/src/xcm_config.rs | 4 +-- runtime/mandala/src/lib.rs | 18 +++++++++---- 8 files changed, 73 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 418d2d15e..81790a615 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6554,6 +6554,7 @@ dependencies = [ "pallet-utility", "pallet-xcm", "parity-scale-codec", + "polkadot-parachain-primitives", "runtime-common", "serde_json", "smallvec", diff --git a/runtime/acala/src/lib.rs b/runtime/acala/src/lib.rs index 0979e12af..530977134 100644 --- a/runtime/acala/src/lib.rs +++ b/runtime/acala/src/lib.rs @@ -31,6 +31,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); use parity_scale_codec::{Decode, DecodeLimit, Encode}; +use polkadot_parachain_primitives::primitives::Sibling; use scale_info::TypeInfo; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H160}; @@ -86,7 +87,7 @@ pub use pallet_collective::MemberCount; pub use sp_runtime::BuildStorage; pub use authority::AuthorityConfigImpl; -pub use constants::{fee::*, time::*}; +pub use constants::{fee::*, parachains, time::*}; use module_support::{ExchangeRateProvider, FractionalRate}; use primitives::currency::AssetIds; pub use primitives::{ @@ -1571,7 +1572,7 @@ parameter_types! { pub DefaultExchangeRate: ExchangeRate = ExchangeRate::saturating_from_rational(1, 10); pub HomaTreasuryAccount: AccountId = HomaTreasuryPalletId::get().into_account_truncating(); pub ActiveSubAccountsIndexList: Vec = vec![ - 0, // 15sr8Dvq3AT3Z2Z1y8FnQ4VipekAHhmQnrkgzegUr1tNgbcn + 0, // 12pw22Qyy3o28BLshjce9yrSMs3fhSiLsAjqLPAzGktbXYV7 ]; pub MintThreshold: Balance = dollar(DOT); pub RedeemThreshold: Balance = 5 * dollar(LDOT); @@ -1641,10 +1642,17 @@ impl module_nominees_election::Config for Runtime { pub fn create_x2_parachain_location(index: u16) -> Location { Location::new( 1, - AccountId32 { - network: None, - id: Utility::derivative_account_id(ParachainInfo::get().into_account_truncating(), index).into(), - }, + [ + Parachain(parachains::asset_hub_polkadot::ID), + AccountId32 { + network: None, + id: Utility::derivative_account_id( + Sibling::from(ParachainInfo::get()).into_account_truncating(), + index, + ) + .into(), + }, + ], ) } @@ -1656,7 +1664,7 @@ impl Convert for SubAccountIndexLocationConvertor { } parameter_types! { - pub ParachainAccount: AccountId = ParachainInfo::get().into_account_truncating(); + pub ParachainAccount: AccountId = Sibling::from(ParachainInfo::get()).into_account_truncating(); } impl module_xcm_interface::Config for Runtime { diff --git a/runtime/acala/src/xcm_config.rs b/runtime/acala/src/xcm_config.rs index 73d483e57..c6118f7ff 100644 --- a/runtime/acala/src/xcm_config.rs +++ b/runtime/acala/src/xcm_config.rs @@ -97,7 +97,7 @@ parameter_types! { pub BaseRate: u128 = aca_per_second(); /// Location of Asset Hub - pub AssetHubLocation: Location = Location::new(1, [Parachain(1000)]); + pub AssetHubLocation: Location = Location::new(1, [Parachain(parachains::asset_hub_polkadot::ID)]); pub RelayChainNativeAssetFromAssetHub: (AssetFilter, Location) = ( RelayLocationFilter::get(), AssetHubLocation::get() diff --git a/runtime/integration-tests/Cargo.toml b/runtime/integration-tests/Cargo.toml index e4c17899c..72ced16cb 100644 --- a/runtime/integration-tests/Cargo.toml +++ b/runtime/integration-tests/Cargo.toml @@ -66,6 +66,7 @@ xcm = { workspace = true, features = ["std"] } xcm-executor = { workspace = true, features = ["std"] } xcm-builder = { workspace = true, features = ["std"] } pallet-xcm = { workspace = true, features = ["std"] } +polkadot-parachain-primitives = { workspace = true, features = ["std"] } # orml orml-auction = { workspace = true, features = ["std"] } diff --git a/runtime/integration-tests/src/runtime.rs b/runtime/integration-tests/src/runtime.rs index e578315fe..a823f415c 100644 --- a/runtime/integration-tests/src/runtime.rs +++ b/runtime/integration-tests/src/runtime.rs @@ -290,30 +290,45 @@ fn currency_id_convert() { #[test] fn parachain_subaccounts_are_unique() { ExtBuilder::default().build().execute_with(|| { - let parachain: AccountId = ParachainInfo::parachain_id().into_account_truncating(); + let parachain: AccountId = ParachainInfo::get().into_account_truncating(); assert_eq!( parachain, hex_literal::hex!["70617261d0070000000000000000000000000000000000000000000000000000"].into() ); + let sibling: AccountId = + polkadot_parachain_primitives::primitives::Sibling::from(ParachainInfo::get()).into_account_truncating(); + assert_eq!( + sibling, + hex_literal::hex!["7369626cd0070000000000000000000000000000000000000000000000000000"].into() + ); + assert_eq!( create_x2_parachain_location(0), Location::new( 1, - [Junction::AccountId32 { - network: None, - id: hex_literal::hex!["d7b8926b326dd349355a9a7cca6606c1e0eb6fd2b506066b518c7155ff0d8297"].into(), - }] + [ + Parachain(1000), + Junction::AccountId32 { + network: None, + id: hex_literal::hex!["50ca9b6bf6c83ca2a918b9861788d6facd26e5fd78a07f9848070697683745b3"] + .into(), + } + ] ), ); assert_eq!( create_x2_parachain_location(1), Location::new( 1, - [Junction::AccountId32 { - network: None, - id: hex_literal::hex!["74d37d762e06c6841a5dad64463a9afe0684f7e45245f6a7296ca613cca74669"].into(), - }] + [ + Parachain(1000), + Junction::AccountId32 { + network: None, + id: hex_literal::hex!["025f1ca0b76b0d646f33b799a040df9fc14e06b7486770656766e8e8381f6c6f"] + .into(), + } + ] ), ); }); diff --git a/runtime/karura/src/lib.rs b/runtime/karura/src/lib.rs index dfd7e325a..65cf55b72 100644 --- a/runtime/karura/src/lib.rs +++ b/runtime/karura/src/lib.rs @@ -31,6 +31,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); use parity_scale_codec::{Decode, DecodeLimit, Encode}; +use polkadot_parachain_primitives::primitives::Sibling; use scale_info::TypeInfo; use sp_api::impl_runtime_apis; use sp_consensus_aura::sr25519::AuthorityId as AuraId; @@ -1594,9 +1595,9 @@ parameter_types! { pub DefaultExchangeRate: ExchangeRate = ExchangeRate::saturating_from_rational(1, 10); pub HomaTreasuryAccount: AccountId = HomaTreasuryPalletId::get().into_account_truncating(); pub ActiveSubAccountsIndexList: Vec = vec![ - 0, // HTAeD1dokCVs9MwnC1q9s2a7d2kQ52TAjrxE1y5mj5MFLLA - 1, // FDVu3RdH5WsE2yTdXN3QMq6v1XVDK8GKjhq5oFjXe8wZYpL - 2, // EMrKvFy7xLgzzdgruXT9oXERt553igEScqgSjoDm3GewPSA + 0, // EQFY1VnjdYUSJ9oWoNgunPHeqLFooyPF3r6ZkTbCU5a6Eez + 1, // CdRsH6LC4yVvSH4XC2qmtPhuAoQEqedBdmnfaYPSVh5TDZ7 + 2, // HZyWwhbi8yWGK6HJGjgYWQtszPvggLUrQDX9PR6StbmPwHP ]; pub MintThreshold: Balance = 10 * cent(KSM); pub RedeemThreshold: Balance = 50 * cent(LKSM); @@ -1666,10 +1667,17 @@ impl module_nominees_election::Config for Runtime { pub fn create_x2_parachain_location(index: u16) -> Location { Location::new( 1, - AccountId32 { - network: None, - id: Utility::derivative_account_id(ParachainInfo::get().into_account_truncating(), index).into(), - }, + [ + Parachain(parachains::asset_hub_kusama::ID), + AccountId32 { + network: None, + id: Utility::derivative_account_id( + Sibling::from(ParachainInfo::get()).into_account_truncating(), + index, + ) + .into(), + }, + ], ) } @@ -1681,7 +1689,7 @@ impl Convert for SubAccountIndexLocationConvertor { } parameter_types! { - pub ParachainAccount: AccountId = ParachainInfo::get().into_account_truncating(); + pub ParachainAccount: AccountId = Sibling::from(ParachainInfo::get()).into_account_truncating(); } impl module_xcm_interface::Config for Runtime { diff --git a/runtime/karura/src/xcm_config.rs b/runtime/karura/src/xcm_config.rs index 41e8421da..3035860ea 100644 --- a/runtime/karura/src/xcm_config.rs +++ b/runtime/karura/src/xcm_config.rs @@ -139,7 +139,7 @@ parameter_types! { pub BaseRate: u128 = kar_per_second(); /// Location of Asset Hub - pub AssetHubLocation: Location = Location::new(1, [Parachain(1000)]); + pub AssetHubLocation: Location = Location::new(1, [Parachain(parachains::asset_hub_kusama::ID)]); pub RelayChainNativeAssetFromAssetHub: (AssetFilter, Location) = ( RelayLocationFilter::get(), AssetHubLocation::get() @@ -149,7 +149,7 @@ parameter_types! { type Reserves = ( // Assets bridged from different consensus systems held in reserve on Asset Hub. IsBridgedConcreteAssetFrom, - // Relaychain (DOT) from Asset Hub + // Relaychain (KSM) from Asset Hub Case, // Assets which the reserve is the same as the origin. MultiNativeAsset, diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index dca63f971..7a942702b 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -56,6 +56,7 @@ use module_relaychain::RelayChainCallBuilder; use module_support::{AddressMapping, AssetIdMapping, DispatchableTask, ExchangeRateProvider, FractionalRate, PoolId}; use module_transaction_payment::TargetedFeeAdjustment; use parity_scale_codec::{Decode, DecodeLimit, Encode}; +use polkadot_parachain_primitives::primitives::Sibling; use scale_info::TypeInfo; use orml_tokens::CurrencyAdapter; @@ -1414,10 +1415,17 @@ parameter_types! { pub fn create_x2_parachain_location(index: u16) -> Location { Location::new( 1, - AccountId32 { - network: None, - id: Utility::derivative_account_id(ParachainInfo::get().into_account_truncating(), index).into(), - }, + [ + Parachain(1000), + AccountId32 { + network: None, + id: Utility::derivative_account_id( + Sibling::from(ParachainInfo::get()).into_account_truncating(), + index, + ) + .into(), + }, + ], ) } @@ -1492,7 +1500,7 @@ impl module_nominees_election::Config for Runtime { } parameter_types! { - pub ParachainAccount: AccountId = ParachainInfo::get().into_account_truncating(); + pub ParachainAccount: AccountId = Sibling::from(ParachainInfo::get()).into_account_truncating(); } pub struct SubAccountIndexLocationConvertor; From fdaef8101c0369dc1d59b4edffc17a471514e2af Mon Sep 17 00:00:00 2001 From: zjb0807 Date: Sun, 22 Jun 2025 15:27:11 +0800 Subject: [PATCH 02/12] rename relaychain to assethub --- Cargo.lock | 44 ++++----- Cargo.toml | 2 +- modules/{relaychain => assethub}/Cargo.toml | 2 +- modules/{relaychain => assethub}/src/lib.rs | 90 +++++++++---------- modules/homa-validator-list/src/lib.rs | 72 +++++++-------- modules/homa-validator-list/src/mock.rs | 2 +- modules/homa-validator-list/src/tests.rs | 8 +- modules/homa/src/lib.rs | 56 ++++++------ modules/homa/src/mock.rs | 4 +- .../src/{relaychain.rs => assethub.rs} | 55 ++++++------ modules/support/src/homa.rs | 14 +-- modules/support/src/lib.rs | 2 +- modules/xcm-interface/Cargo.toml | 2 +- modules/xcm-interface/src/lib.rs | 60 ++++++------- modules/xcm-interface/src/mocks/kusama.rs | 2 +- modules/xcm-interface/src/mocks/mod.rs | 8 +- modules/xcm-interface/src/mocks/polkadot.rs | 2 +- runtime/acala/Cargo.toml | 4 +- runtime/acala/src/lib.rs | 8 +- runtime/common/src/precompile/mock.rs | 4 +- runtime/integration-tests/Cargo.toml | 2 +- runtime/karura/Cargo.toml | 4 +- runtime/karura/src/lib.rs | 8 +- runtime/mandala/Cargo.toml | 4 +- runtime/mandala/src/lib.rs | 8 +- 25 files changed, 228 insertions(+), 239 deletions(-) rename modules/{relaychain => assethub}/Cargo.toml (96%) rename modules/{relaychain => assethub}/src/lib.rs (62%) rename modules/support/src/{relaychain.rs => assethub.rs} (73%) diff --git a/Cargo.lock b/Cargo.lock index 81790a615..7ae7c8f04 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -63,6 +63,7 @@ dependencies = [ "log", "module-aggregated-dex", "module-asset-registry", + "module-assethub", "module-auction-manager", "module-cdp-engine", "module-cdp-treasury", @@ -87,7 +88,6 @@ dependencies = [ "module-nft", "module-nominees-election", "module-prices", - "module-relaychain", "module-session-manager", "module-support", "module-transaction-pause", @@ -2804,6 +2804,7 @@ dependencies = [ "log", "module-aggregated-dex", "module-asset-registry", + "module-assethub", "module-auction-manager", "module-cdp-engine", "module-cdp-treasury", @@ -2828,7 +2829,6 @@ dependencies = [ "module-nft", "module-nominees-election", "module-prices", - "module-relaychain", "module-session-manager", "module-support", "module-transaction-pause", @@ -3216,6 +3216,7 @@ dependencies = [ "log", "module-aggregated-dex", "module-asset-registry", + "module-assethub", "module-auction-manager", "module-cdp-engine", "module-cdp-treasury", @@ -3241,7 +3242,6 @@ dependencies = [ "module-nft", "module-nominees-election", "module-prices", - "module-relaychain", "module-session-manager", "module-support", "module-transaction-pause", @@ -3488,6 +3488,23 @@ dependencies = [ "staging-xcm", ] +[[package]] +name = "module-assethub" +version = "2.30.0" +dependencies = [ + "acala-primitives", + "cumulus-primitives-core", + "frame-support", + "frame-system", + "module-support", + "parity-scale-codec", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "staging-xcm", +] + [[package]] name = "module-auction-manager" version = "2.30.0" @@ -4073,23 +4090,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "module-relaychain" -version = "2.30.0" -dependencies = [ - "acala-primitives", - "cumulus-primitives-core", - "frame-support", - "frame-system", - "module-support", - "parity-scale-codec", - "sp-core", - "sp-io", - "sp-runtime", - "sp-std", - "staging-xcm", -] - [[package]] name = "module-session-manager" version = "2.30.0" @@ -4187,8 +4187,8 @@ dependencies = [ "frame-system", "insta", "log", + "module-assethub", "module-currencies", - "module-relaychain", "module-support", "orml-tokens", "orml-traits", @@ -6496,6 +6496,7 @@ dependencies = [ "mandala-runtime", "module-aggregated-dex", "module-asset-registry", + "module-assethub", "module-auction-manager", "module-cdp-engine", "module-cdp-treasury", @@ -6513,7 +6514,6 @@ dependencies = [ "module-loans", "module-nft", "module-prices", - "module-relaychain", "module-session-manager", "module-support", "module-transaction-payment", diff --git a/Cargo.toml b/Cargo.toml index fc661507f..e74d343c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -201,7 +201,7 @@ module-nft = { path = "modules/nft", default-features = false } module-xnft = { path = "modules/xnft", default-features = false } module-nominees-election = { path = "modules/nominees-election", default-features = false } module-prices = { path = "modules/prices", default-features = false } -module-relaychain = { path = "modules/relaychain", default-features = false } +module-assethub = { path = "modules/assethub", default-features = false } module-session-manager = { path = "modules/session-manager", default-features = false } module-support = { path = "modules/support", default-features = false } module-transaction-pause = { path = "modules/transaction-pause", default-features = false } diff --git a/modules/relaychain/Cargo.toml b/modules/assethub/Cargo.toml similarity index 96% rename from modules/relaychain/Cargo.toml rename to modules/assethub/Cargo.toml index a7188611d..7ee9f483d 100644 --- a/modules/relaychain/Cargo.toml +++ b/modules/assethub/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "module-relaychain" +name = "module-assethub" version = { workspace = true } authors = { workspace = true } edition = { workspace = true } diff --git a/modules/relaychain/src/lib.rs b/modules/assethub/src/lib.rs similarity index 62% rename from modules/relaychain/src/lib.rs rename to modules/assethub/src/lib.rs index a390b8fe2..e3438e459 100644 --- a/modules/relaychain/src/lib.rs +++ b/modules/assethub/src/lib.rs @@ -16,9 +16,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -//! # Module RelayChain +//! # Module AssetHub //! -//! This module is in charge of handling relaychain related utilities and business logic. +//! This module is in charge of handling assethub related utilities and business logic. #![cfg_attr(not(feature = "std"), no_std)] #![allow(clippy::unused_unit)] @@ -28,17 +28,17 @@ use parity_scale_codec::{Decode, Encode, FullCodec}; use sp_runtime::{traits::StaticLookup, RuntimeDebug}; use frame_support::traits::Get; -use module_support::relaychain::*; +use module_support::assethub::*; use primitives::{AccountId, Balance}; use sp_std::{boxed::Box, marker::PhantomData, prelude::*}; pub use cumulus_primitives_core::ParaId; use xcm::v4::{prelude::*, Weight as XcmWeight}; -/// The encoded index corresponds to Kusama's Runtime module configuration. +/// The encoded index corresponds to AssetHub's Runtime module configuration. /// https://github.com/paritytech/polkadot/blob/444e96ae34bcec8362f0f947a07bd912b32ca48f/runtime/kusama/src/lib.rs#L1379 #[derive(Encode, Decode, RuntimeDebug)] -pub enum KusamaRelayChainCall { +pub enum KusamaAssetHubCall { #[codec(index = 4)] Balances(BalancesCall), #[codec(index = 6)] @@ -51,32 +51,32 @@ pub enum KusamaRelayChainCall { XcmPallet(XcmCall), } -impl RelayChainCall for KusamaRelayChainCall { +impl AssetHubCall for KusamaAssetHubCall { fn balances(call: BalancesCall) -> Self { - KusamaRelayChainCall::Balances(call) + KusamaAssetHubCall::Balances(call) } fn staking(call: StakingCall) -> Self { - KusamaRelayChainCall::Staking(call) + KusamaAssetHubCall::Staking(call) } fn utility(call: UtilityCall) -> Self { - KusamaRelayChainCall::Utility(Box::new(call)) + KusamaAssetHubCall::Utility(Box::new(call)) } fn proxy(call: ProxyCall) -> Self { - KusamaRelayChainCall::Proxy(Box::new(call)) + KusamaAssetHubCall::Proxy(Box::new(call)) } fn xcm_pallet(call: XcmCall) -> Self { - KusamaRelayChainCall::XcmPallet(call) + KusamaAssetHubCall::XcmPallet(call) } } -/// The encoded index corresponds to Polkadot's Runtime module configuration. +/// The encoded index corresponds to AssetHub's Runtime module configuration. /// https://github.com/paritytech/polkadot/blob/84a3962e76151ac5ed3afa4ef1e0af829531ab42/runtime/polkadot/src/lib.rs#L1040 #[derive(Encode, Decode, RuntimeDebug)] -pub enum PolkadotRelayChainCall { +pub enum PolkadotAssetHubCall { #[codec(index = 5)] Balances(BalancesCall), #[codec(index = 7)] @@ -89,63 +89,63 @@ pub enum PolkadotRelayChainCall { XcmPallet(XcmCall), } -impl RelayChainCall for PolkadotRelayChainCall { +impl AssetHubCall for PolkadotAssetHubCall { fn balances(call: BalancesCall) -> Self { - PolkadotRelayChainCall::Balances(call) + PolkadotAssetHubCall::Balances(call) } fn staking(call: StakingCall) -> Self { - PolkadotRelayChainCall::Staking(call) + PolkadotAssetHubCall::Staking(call) } fn utility(call: UtilityCall) -> Self { - PolkadotRelayChainCall::Utility(Box::new(call)) + PolkadotAssetHubCall::Utility(Box::new(call)) } fn proxy(call: ProxyCall) -> Self { - PolkadotRelayChainCall::Proxy(Box::new(call)) + PolkadotAssetHubCall::Proxy(Box::new(call)) } fn xcm_pallet(call: XcmCall) -> Self { - PolkadotRelayChainCall::XcmPallet(call) + PolkadotAssetHubCall::XcmPallet(call) } } -pub struct RelayChainCallBuilder(PhantomData<(ParachainId, RCC)>); +pub struct AssetHubCallBuilder(PhantomData<(ParachainId, AHC)>); -impl CallBuilder for RelayChainCallBuilder +impl CallBuilder for AssetHubCallBuilder where ParachainId: Get, - RCC: RelayChainCall + FullCodec, + AHC: AssetHubCall + FullCodec, { - type RelayChainAccountId = AccountId; + type AssetHubAccountId = AccountId; type Balance = Balance; - type RelayChainCall = RCC; + type AssetHubCall = AHC; - fn utility_as_derivative_call(call: RCC, index: u16) -> RCC { - RCC::utility(UtilityCall::AsDerivative(index, call)) + fn utility_as_derivative_call(call: AHC, index: u16) -> AHC { + AHC::utility(UtilityCall::AsDerivative(index, call)) } - fn staking_bond_extra(amount: Self::Balance) -> RCC { - RCC::staking(StakingCall::BondExtra(amount)) + fn staking_bond_extra(amount: Self::Balance) -> AHC { + AHC::staking(StakingCall::BondExtra(amount)) } - fn staking_unbond(amount: Self::Balance) -> RCC { - RCC::staking(StakingCall::Unbond(amount)) + fn staking_unbond(amount: Self::Balance) -> AHC { + AHC::staking(StakingCall::Unbond(amount)) } - fn staking_withdraw_unbonded(num_slashing_spans: u32) -> RCC { - RCC::staking(StakingCall::WithdrawUnbonded(num_slashing_spans)) + fn staking_withdraw_unbonded(num_slashing_spans: u32) -> AHC { + AHC::staking(StakingCall::WithdrawUnbonded(num_slashing_spans)) } - fn staking_nominate(targets: Vec) -> RCC { - RCC::staking(StakingCall::Nominate( - targets.iter().map(|a| RelayChainLookup::unlookup(a.clone())).collect(), + fn staking_nominate(targets: Vec) -> AHC { + AHC::staking(StakingCall::Nominate( + targets.iter().map(|a| AssetHubLookup::unlookup(a.clone())).collect(), )) } - fn balances_transfer_keep_alive(to: Self::RelayChainAccountId, amount: Self::Balance) -> RCC { - RCC::balances(BalancesCall::TransferKeepAlive(RelayChainLookup::unlookup(to), amount)) + fn balances_transfer_keep_alive(to: Self::AssetHubAccountId, amount: Self::Balance) -> AHC { + AHC::balances(BalancesCall::TransferKeepAlive(AssetHubLookup::unlookup(to), amount)) } fn xcm_pallet_reserve_transfer_assets( @@ -153,8 +153,8 @@ where beneficiary: Location, assets: Assets, fee_assets_item: u32, - ) -> RCC { - RCC::xcm_pallet(XcmCall::LimitedReserveTransferAssets( + ) -> AHC { + AHC::xcm_pallet(XcmCall::LimitedReserveTransferAssets( dest.into_versioned(), beneficiary.into_versioned(), assets.into(), @@ -163,11 +163,11 @@ where )) } - fn proxy_call(real: Self::RelayChainAccountId, call: RCC) -> RCC { - RCC::proxy(ProxyCall::Proxy(RelayChainLookup::unlookup(real), None, call)) + fn proxy_call(real: Self::AssetHubAccountId, call: AHC) -> AHC { + AHC::proxy(ProxyCall::Proxy(AssetHubLookup::unlookup(real), None, call)) } - fn finalize_call_into_xcm_message(call: RCC, extra_fee: Self::Balance, weight: XcmWeight) -> Xcm<()> { + fn finalize_call_into_xcm_message(call: AHC, extra_fee: Self::Balance, weight: XcmWeight) -> Xcm<()> { let asset = Asset { id: AssetId(Location::here()), fun: Fungibility::Fungible(extra_fee), @@ -185,7 +185,7 @@ where }, RefundSurplus, DepositAsset { - assets: AllCounted(1).into(), // there is only 1 asset on relaychain + assets: AllCounted(1).into(), // there is only 1 asset on assethub beneficiary: Location { parents: 0, interior: Parachain(ParachainId::get().into()).into(), @@ -194,7 +194,7 @@ where ]) } - fn finalize_multiple_calls_into_xcm_message(calls: Vec<(RCC, XcmWeight)>, extra_fee: Self::Balance) -> Xcm<()> { + fn finalize_multiple_calls_into_xcm_message(calls: Vec<(AHC, XcmWeight)>, extra_fee: Self::Balance) -> Xcm<()> { let asset = Asset { id: AssetId(Location::here()), fun: Fungibility::Fungible(extra_fee), @@ -221,7 +221,7 @@ where vec![ RefundSurplus, DepositAsset { - assets: AllCounted(1).into(), // there is only 1 asset on relaychain + assets: AllCounted(1).into(), // there is only 1 asset on assethub beneficiary: Location { parents: 0, interior: Parachain(ParachainId::get().into()).into(), diff --git a/modules/homa-validator-list/src/lib.rs b/modules/homa-validator-list/src/lib.rs index 08f772328..4ff259a30 100644 --- a/modules/homa-validator-list/src/lib.rs +++ b/modules/homa-validator-list/src/lib.rs @@ -111,14 +111,14 @@ impl Guarantee { } } -/// Information on a relay chain validator's slash +/// Information on a assethub validator's slash #[derive(Encode, Decode, Clone, RuntimeDebug, Eq, PartialEq, MaxEncodedLen, TypeInfo)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub struct SlashInfo { - /// Address of a validator on the relay chain - pub validator: RelayChainAccountId, - /// The amount of tokens a validator has in backing on the relay chain - pub relaychain_token_amount: Balance, +pub struct SlashInfo { + /// Address of a validator on the assethub + pub validator: ValidatorId, + /// The amount of tokens a validator has in backing on the assethub + pub token_amount: Balance, } /// Validator insurance and frozen status @@ -138,16 +138,10 @@ pub mod module { /// The overarching event type. type RuntimeEvent: From> + IsType<::RuntimeEvent>; - /// The AccountId of a relay chain account. - type RelayChainAccountId: Parameter - + Member - + MaybeSerializeDeserialize - + Debug - + MaybeDisplay - + Ord - + MaxEncodedLen; + /// The AccountId of a assethub account. + type ValidatorId: Parameter + Member + MaybeSerializeDeserialize + Debug + MaybeDisplay + Ord + MaxEncodedLen; - /// The liquid representation of the staking token on the relay chain. + /// The liquid representation of the staking token on the assethub. type LiquidTokenCurrency: BasicLockableCurrency; /// The minimum amount of tokens that can be bonded to a validator. @@ -185,47 +179,47 @@ pub mod module { #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { FreezeValidator { - validator: T::RelayChainAccountId, + validator: T::ValidatorId, }, ThawValidator { - validator: T::RelayChainAccountId, + validator: T::ValidatorId, }, BondGuarantee { who: T::AccountId, - validator: T::RelayChainAccountId, + validator: T::ValidatorId, bond: Balance, }, UnbondGuarantee { who: T::AccountId, - validator: T::RelayChainAccountId, + validator: T::ValidatorId, bond: Balance, }, WithdrawnGuarantee { who: T::AccountId, - validator: T::RelayChainAccountId, + validator: T::ValidatorId, bond: Balance, }, SlashGuarantee { who: T::AccountId, - validator: T::RelayChainAccountId, + validator: T::ValidatorId, bond: Balance, }, RebondGuarantee { who: T::AccountId, - validator: T::RelayChainAccountId, + validator: T::ValidatorId, bond: Balance, }, } - /// The slash guarantee deposits for relaychain validators. + /// The slash guarantee deposits for assethub validators. /// - /// Guarantees: double_map RelayChainAccountId, AccountId => Option + /// Guarantees: double_map ValidatorId, AccountId => Option #[pallet::storage] #[pallet::getter(fn guarantees)] pub type Guarantees = StorageDoubleMap< _, Blake2_128Concat, - T::RelayChainAccountId, + T::ValidatorId, Twox64Concat, T::AccountId, Guarantee, @@ -241,11 +235,11 @@ pub mod module { /// Total deposit for validators. /// - /// ValidatorBackings: map RelayChainAccountId => Option + /// ValidatorBackings: map ValidatorId => Option #[pallet::storage] #[pallet::getter(fn validator_backings)] pub type ValidatorBackings = - StorageMap<_, Blake2_128Concat, T::RelayChainAccountId, ValidatorBacking, OptionQuery>; + StorageMap<_, Blake2_128Concat, T::ValidatorId, ValidatorBacking, OptionQuery>; #[pallet::pallet] pub struct Pallet(_); @@ -264,7 +258,7 @@ pub mod module { #[pallet::weight(T::WeightInfo::bond())] pub fn bond( origin: OriginFor, - validator: T::RelayChainAccountId, + validator: T::ValidatorId, #[pallet::compact] amount: Balance, ) -> DispatchResult { let guarantor = ensure_signed(origin)?; @@ -303,7 +297,7 @@ pub mod module { #[pallet::weight(T::WeightInfo::unbond())] pub fn unbond( origin: OriginFor, - validator: T::RelayChainAccountId, + validator: T::ValidatorId, #[pallet::compact] amount: Balance, ) -> DispatchResult { let guarantor = ensure_signed(origin)?; @@ -339,7 +333,7 @@ pub mod module { #[pallet::weight(T::WeightInfo::rebond())] pub fn rebond( origin: OriginFor, - validator: T::RelayChainAccountId, + validator: T::ValidatorId, #[pallet::compact] amount: Balance, ) -> DispatchResult { let guarantor = ensure_signed(origin)?; @@ -368,7 +362,7 @@ pub mod module { /// - `validator`: The AccountId of a validator on the relay chain to withdraw from #[pallet::call_index(3)] #[pallet::weight(T::WeightInfo::withdraw_unbonded())] - pub fn withdraw_unbonded(origin: OriginFor, validator: T::RelayChainAccountId) -> DispatchResult { + pub fn withdraw_unbonded(origin: OriginFor, validator: T::ValidatorId) -> DispatchResult { let guarantor = ensure_signed(origin)?; ensure!( !Self::validator_backings(&validator).unwrap_or_default().is_frozen, @@ -399,7 +393,7 @@ pub mod module { /// - `validators`: The AccountIds of the validators on the relay chain to freeze #[pallet::call_index(4)] #[pallet::weight(T::WeightInfo::freeze(validators.len() as u32))] - pub fn freeze(origin: OriginFor, validators: Vec) -> DispatchResult { + pub fn freeze(origin: OriginFor, validators: Vec) -> DispatchResult { T::GovernanceOrigin::ensure_origin(origin)?; validators.iter().for_each(|validator| { ValidatorBackings::::mutate_exists(validator, |maybe_validator| { @@ -422,7 +416,7 @@ pub mod module { /// - `validators`: The AccountIds of the validators on the relay chain to unfreeze #[pallet::call_index(5)] #[pallet::weight(T::WeightInfo::thaw(validators.len() as u32))] - pub fn thaw(origin: OriginFor, validators: Vec) -> DispatchResult { + pub fn thaw(origin: OriginFor, validators: Vec) -> DispatchResult { T::GovernanceOrigin::ensure_origin(origin)?; validators.iter().for_each(|validator| { ValidatorBackings::::mutate_exists(validator, |maybe_validator| { @@ -445,7 +439,7 @@ pub mod module { /// - `slashes`: The SlashInfos of the validators to be slashed #[pallet::call_index(6)] #[pallet::weight(T::WeightInfo::slash(slashes.len() as u32))] - pub fn slash(origin: OriginFor, slashes: Vec>) -> DispatchResult { + pub fn slash(origin: OriginFor, slashes: Vec>) -> DispatchResult { T::GovernanceOrigin::ensure_origin(origin)?; let liquid_staking_exchange_rate = T::LiquidStakingExchangeRateProvider::get_exchange_rate(); let staking_liquid_exchange_rate = liquid_staking_exchange_rate.reciprocal().unwrap_or_default(); @@ -453,12 +447,12 @@ pub mod module { for SlashInfo { validator, - relaychain_token_amount, + token_amount, } in slashes { let ValidatorBacking { total_insurance, .. } = Self::validator_backings(&validator).unwrap_or_default(); let insurance_loss = staking_liquid_exchange_rate - .saturating_mul_int(relaychain_token_amount) + .saturating_mul_int(token_amount) .min(total_insurance); for (guarantor, _) in Guarantees::::iter_prefix(&validator) { @@ -490,7 +484,7 @@ pub mod module { impl Pallet { fn update_guarantee( guarantor: &T::AccountId, - validator: &T::RelayChainAccountId, + validator: &T::ValidatorId, f: impl FnOnce(&mut Guarantee) -> DispatchResult, ) -> DispatchResult { Guarantees::::try_mutate_exists(validator, guarantor, |maybe_guarantee| -> DispatchResult { @@ -549,8 +543,8 @@ impl Pallet { } } -impl Contains for Pallet { - fn contains(account: &T::RelayChainAccountId) -> bool { +impl Contains for Pallet { + fn contains(account: &T::ValidatorId) -> bool { ValidatorBackings::::get(account) .is_some_and(|vb| vb.total_insurance >= T::ValidatorInsuranceThreshold::get() && !vb.is_frozen) } diff --git a/modules/homa-validator-list/src/mock.rs b/modules/homa-validator-list/src/mock.rs index 839811613..bf84f2999 100644 --- a/modules/homa-validator-list/src/mock.rs +++ b/modules/homa-validator-list/src/mock.rs @@ -121,7 +121,7 @@ parameter_types! { impl Config for Runtime { type RuntimeEvent = RuntimeEvent; - type RelayChainAccountId = AccountId; + type ValidatorId = AccountId; type LiquidTokenCurrency = LDOTCurrency; type MinBondAmount = ConstU128<100>; type BondingDuration = BondingDuration; diff --git a/modules/homa-validator-list/src/tests.rs b/modules/homa-validator-list/src/tests.rs index ac745093a..ef60181c9 100644 --- a/modules/homa-validator-list/src/tests.rs +++ b/modules/homa-validator-list/src/tests.rs @@ -701,11 +701,11 @@ fn slash_work() { vec![ SlashInfo { validator: VALIDATOR_1, - relaychain_token_amount: 90 + token_amount: 90 }, SlashInfo { validator: VALIDATOR_2, - relaychain_token_amount: 50 + token_amount: 50 }, ] ), @@ -717,11 +717,11 @@ fn slash_work() { vec![ SlashInfo { validator: VALIDATOR_1, - relaychain_token_amount: 90 + token_amount: 90 }, SlashInfo { validator: VALIDATOR_2, - relaychain_token_amount: 50 + token_amount: 50 }, ] )); diff --git a/modules/homa/src/lib.rs b/modules/homa/src/lib.rs index ed20d29ce..d4d547ce1 100644 --- a/modules/homa/src/lib.rs +++ b/modules/homa/src/lib.rs @@ -49,18 +49,18 @@ pub mod weights; pub mod module { use super::*; - pub type RelayChainAccountIdOf = <::XcmInterface as HomaSubAccountXcm< + pub type AssetHubAccountIdOf = <::XcmInterface as HomaSubAccountXcm< ::AccountId, Balance, - >>::RelayChainAccountId; + >>::AssetHubAccountId; /// The subaccount's staking ledger which kept by Homa protocol #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, Default)] pub struct StakingLedger { - /// Corresponding to the active of the subaccount's staking ledger on relaychain + /// Corresponding to the active of the subaccount's staking ledger on assethub #[codec(compact)] pub bonded: Balance, - /// Corresponding to the unlocking of the subaccount's staking ledger on relaychain + /// Corresponding to the unlocking of the subaccount's staking ledger on assethub pub unlocking: Vec, } @@ -153,7 +153,7 @@ pub mod module { /// Block number provider for the relaychain. type RelayChainBlockNumber: BlockNumberProvider>; - /// The XcmInterface to manage the staking of sub-account on relaychain. + /// The XcmInterface to manage the staking of sub-account on assethub. type XcmInterface: HomaSubAccountXcm; /// The limit for process redeem requests when bump era. @@ -163,7 +163,7 @@ pub mod module { /// Weight information for the extrinsics in this module. type WeightInfo: WeightInfo; - type NominationsProvider: NomineesProvider>; + type NominationsProvider: NomineesProvider>; } #[pallet::error] @@ -216,7 +216,7 @@ pub mod module { fee_in_liquid: Balance, redeemed_staking_amount: Balance, }, - /// Redeem request is redeemed by unbond on relaychain. + /// Redeem request is redeemed by unbond on assethub. RedeemedByUnbond { redeemer: T::AccountId, era_index_when_unbond: EraIndex, @@ -244,7 +244,7 @@ pub mod module { }, /// The soft bonded cap of per sub account has been updated. SoftBondedCapPerSubAccountUpdated { cap_amount: Balance }, - /// The estimated reward rate per era of relaychain staking has been updated. + /// The estimated reward rate per era of assethub staking has been updated. EstimatedRewardRatePerEraUpdated { reward_rate: Rate }, /// The commission rate has been updated. CommissionRateUpdated { commission_rate: Rate }, @@ -256,16 +256,16 @@ pub mod module { BumpEraFrequencyUpdated { frequency: BlockNumberFor }, /// The interval eras to nominate. NominateIntervalEraUpdated { eras: EraIndex }, - /// Withdraw unbonded from RelayChain + /// Withdraw unbonded from assethub HomaWithdrawUnbonded { sub_account_index: u16, amount: Balance }, - /// Unbond staking currency of sub account on RelayChain + /// Unbond staking currency of sub account on assethub HomaUnbond { sub_account_index: u16, amount: Balance }, - /// Transfer staking currency to sub account and bond on RelayChain + /// Transfer staking currency to sub account and bond on assethub HomaBondExtra { sub_account_index: u16, amount: Balance }, - /// Nominate validators on RelayChain + /// Nominate validators on assethub HomaNominate { sub_account_index: u16, - nominations: Vec>, + nominations: Vec>, }, } @@ -290,7 +290,7 @@ pub mod module { #[pallet::getter(fn get_total_bonded)] pub type TotalStakingBonded = StorageValue<_, Balance, ValueQuery>; - /// The total staking currency to bond on relaychain when new era, + /// The total staking currency to bond on assethub when new era, /// and that is available to be match fast redeem request. /// ToBondPool value: StakingCurrencyAmount #[pallet::storage] @@ -298,7 +298,7 @@ pub mod module { pub type ToBondPool = StorageValue<_, Balance, ValueQuery>; /// The total amount of void liquid currency. It's will not be issued, - /// used to avoid newly issued LDOT to obtain the incoming staking income from relaychain. + /// used to avoid newly issued LDOT to obtain the incoming staking income from assethub. /// And it is guaranteed that the current exchange rate between liquid currency and staking /// currency will not change. It will be reset to 0 at the beginning of the `rebalance` when new /// era starts. @@ -336,7 +336,7 @@ pub mod module { #[pallet::storage] pub type EstimatedRewardRatePerEra = StorageValue<_, FractionalRate, ValueQuery>; - /// The maximum amount of bonded staking currency for a single sub on relaychain to obtain the + /// The maximum amount of bonded staking currency for a single sub on assethub to obtain the /// best staking rewards. /// /// SoftBondedCapPerSubAccount: value: Balance @@ -418,8 +418,8 @@ pub mod module { /// The redeem request will be executed in two ways: /// 1. Redeem by fast match: Homa use staking currency in ToBondPool to match redeem request /// in the current era, setting a higher fee_rate can increase the possibility of being fast - /// matched. 2. Redeem by unbond on relaychain: if redeem request has not been fast matched - /// in current era, Homa will unbond staking currency on relaychain when the next era + /// matched. 2. Redeem by unbond on assethub: if redeem request has not been fast matched + /// in current era, Homa will unbond staking currency on assethub when the next era /// bumped. So redeemer at least wait for the unbonding period + extra 1 era to get the /// redemption. /// @@ -502,9 +502,9 @@ pub mod module { /// /// Parameters: /// - `soft_bonded_cap_per_sub_account`: soft cap of staking amount for a single nominator - /// on relaychain to obtain the best staking rewards. + /// on assethub to obtain the best staking rewards. /// - `estimated_reward_rate_per_era`: the estimated staking yield of each era on the - /// current relay chain. + /// current relaychain. /// - `commission_rate`: the rate to draw from estimated staking rewards as commission to /// HomaTreasury /// - `fast_match_fee_rate`: the fixed fee rate when redeem request is been fast matched. @@ -575,7 +575,7 @@ pub mod module { if let Some(change) = last_era_bumped_block { // config last_era_bumped_block should not cause bump era to occur immediately, because // the last_era_bumped_block after the bump era will not be same with the actual relaychain - // era bumped block again, especially if it leads to multiple bump era. + // era bumped block again, especially if it leads to multiple bump era. // and it should be config after config no-zero bump_era_frequency. let bump_era_frequency = Self::bump_era_frequency(); let current_relay_chain_block = T::RelayChainBlockNumber::current_block_number(); @@ -599,7 +599,7 @@ pub mod module { } /// Reset the bonded and unbonding to local subaccounts ledger according to the ledger on - /// relaychain. Requires `GovernanceOrigin` + /// assethub. Requires `GovernanceOrigin` /// /// Parameters: /// - `updates`: update list of subaccount. @@ -994,7 +994,7 @@ pub mod module { Ok(()) } - /// Get back unbonded of all subaccounts on relaychain by XCM. + /// Get back unbonded of all subaccounts on assethub by XCM. /// The staking currency withdrew becomes available to be redeemed. #[transactional] pub fn process_scheduled_unbond(new_era: EraIndex) -> DispatchResult { @@ -1029,12 +1029,12 @@ pub mod module { } /// Distribute PoolToBond to ActiveSubAccountsIndexList, then cross-transfer the - /// distribution amount to the subaccounts on relaychain and bond it by XCM. + /// distribution amount to the subaccounts on assethub and bond it by XCM. #[transactional] pub fn process_to_bond_pool() -> DispatchResult { let to_bond_pool = Self::to_bond_pool(); - // if to_bond is gte than MintThreshold, try to bond_extra on relaychain + // if to_bond is gte than MintThreshold, try to bond_extra on assethub if to_bond_pool >= T::MintThreshold::get() { let xcm_transfer_fee = T::XcmInterface::get_xcm_transfer_fee(); let bonded_list: Vec<(u16, Balance)> = T::ActiveSubAccountsIndexList::get() @@ -1080,7 +1080,7 @@ pub mod module { Ok(()) } - /// Process redeem requests and subaccounts do unbond on relaychain by XCM message. + /// Process redeem requests and subaccounts do unbond on assethub by XCM message. #[transactional] pub fn process_redeem_requests(new_era: EraIndex) -> Result { let era_index_to_expire = new_era + T::BondingDuration::get(); @@ -1149,7 +1149,7 @@ pub mod module { Ok(handled_requests) } - /// Process nominate validators for subaccounts on relaychain. + /// Process nominate validators for subaccounts on assethub. pub fn process_nominate(new_era: EraIndex) -> DispatchResult { // check whether need to nominate let nominate_interval_era = NominateIntervalEra::::get(); @@ -1180,7 +1180,7 @@ pub mod module { } /// Bump current era. - /// The rebalance will send XCM messages to relaychain. Once the XCM message is sent, + /// The rebalance will send XCM messages to assethub. Once the XCM message is sent, /// the execution result cannot be obtained and cannot be rolled back. So the process /// of rebalance is not atomic. pub fn bump_current_era(amount: EraIndex) -> Result { diff --git a/modules/homa/src/mock.rs b/modules/homa/src/mock.rs index 4f0fb54fb..ec89fdc0b 100644 --- a/modules/homa/src/mock.rs +++ b/modules/homa/src/mock.rs @@ -56,7 +56,7 @@ pub const VALIDATOR_D: AccountId = AccountId32::new([203u8; 32]); /// mock XCM transfer. pub struct MockHomaSubAccountXcm; impl HomaSubAccountXcm for MockHomaSubAccountXcm { - type RelayChainAccountId = AccountId; + type AssetHubAccountId = AccountId; fn transfer_staking_to_sub_account(sender: &AccountId, _: u16, amount: Balance) -> DispatchResult { Currencies::withdraw( @@ -79,7 +79,7 @@ impl HomaSubAccountXcm for MockHomaSubAccountXcm { Ok(()) } - fn nominate_on_sub_account(_: u16, _: Vec) -> DispatchResult { + fn nominate_on_sub_account(_: u16, _: Vec) -> DispatchResult { Ok(()) } diff --git a/modules/support/src/relaychain.rs b/modules/support/src/assethub.rs similarity index 73% rename from modules/support/src/relaychain.rs rename to modules/support/src/assethub.rs index d86ab1853..36a239b50 100644 --- a/modules/support/src/relaychain.rs +++ b/modules/support/src/assethub.rs @@ -16,7 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -// * Since XCM V3, relaychain configs 'SafeCallFilter' to filter the call in Transact: +// * Since XCM V3, xcm executor configs 'SafeCallFilter' to filter the call in Transact: // * https://github.com/paritytech/polkadot/blob/master/runtime/polkadot/src/xcm_config.rs use parity_scale_codec::{Decode, Encode, FullCodec}; @@ -31,13 +31,13 @@ use xcm::{prelude::*, v3::Weight as XcmWeight}; #[derive(Encode, Decode, RuntimeDebug)] pub enum BalancesCall { #[codec(index = 3)] - TransferKeepAlive(::Source, #[codec(compact)] Balance), + TransferKeepAlive(::Source, #[codec(compact)] Balance), } #[derive(Encode, Decode, RuntimeDebug)] -pub enum UtilityCall { +pub enum UtilityCall { #[codec(index = 1)] - AsDerivative(u16, RCC), + AsDerivative(u16, AHC), } #[derive(Encode, Decode, RuntimeDebug)] @@ -49,7 +49,7 @@ pub enum StakingCall { #[codec(index = 3)] WithdrawUnbonded(u32), #[codec(index = 5)] - Nominate(Vec<::Source>), + Nominate(Vec<::Source>), } /// `pallet-xcm` calls. @@ -62,18 +62,18 @@ pub enum XcmCall { } // Same to `Polkadot` and `Kusama` runtime `Lookup` config. -pub type RelayChainLookup = AccountIdLookup; +pub type AssetHubLookup = AccountIdLookup; /// `pallet-proxy` calls. #[derive(Encode, Decode, RuntimeDebug)] -pub enum ProxyCall { +pub enum ProxyCall { /// `proxy(real, force_proxy_type, call)` call. Force proxy type is not supported and /// is always set to `None`. #[codec(index = 0)] - Proxy(::Source, Option<()>, RCC), + Proxy(::Source, Option<()>, AHC), } -pub trait RelayChainCall: Sized { +pub trait AssetHubCall: Sized { fn balances(call: BalancesCall) -> Self; fn staking(call: StakingCall) -> Self; fn utility(call: UtilityCall) -> Self; @@ -82,41 +82,41 @@ pub trait RelayChainCall: Sized { } pub trait CallBuilder { - type RelayChainAccountId: FullCodec; + type AssetHubAccountId: FullCodec; type Balance: FullCodec; - type RelayChainCall: FullCodec + RelayChainCall; + type AssetHubCall: FullCodec + AssetHubCall; /// Execute a call, replacing the `Origin` with a sub-account. /// params: /// - call: The call to be executed. /// - index: The index of sub-account to be used as the new origin. - fn utility_as_derivative_call(call: Self::RelayChainCall, index: u16) -> Self::RelayChainCall; + fn utility_as_derivative_call(call: Self::AssetHubCall, index: u16) -> Self::AssetHubCall; - /// Bond extra on relay-chain. + /// Bond extra on assethub. /// params: /// - amount: The amount of staking currency to bond. - fn staking_bond_extra(amount: Self::Balance) -> Self::RelayChainCall; + fn staking_bond_extra(amount: Self::Balance) -> Self::AssetHubCall; - /// Unbond on relay-chain. + /// Unbond on assethub. /// params: /// - amount: The amount of staking currency to unbond. - fn staking_unbond(amount: Self::Balance) -> Self::RelayChainCall; + fn staking_unbond(amount: Self::Balance) -> Self::AssetHubCall; - /// Withdraw unbonded staking on the relay-chain. + /// Withdraw unbonded staking on the assethub. /// params: /// - num_slashing_spans: The number of slashing spans to withdraw from. - fn staking_withdraw_unbonded(num_slashing_spans: u32) -> Self::RelayChainCall; + fn staking_withdraw_unbonded(num_slashing_spans: u32) -> Self::AssetHubCall; - /// Nominate the relay-chain. + /// Nominate the assethub. /// params: /// - targets: The target validator list. - fn staking_nominate(targets: Vec) -> Self::RelayChainCall; + fn staking_nominate(targets: Vec) -> Self::AssetHubCall; /// Transfer Staking currency to another account, disallowing "death". /// params: /// - to: The destination for the transfer /// - amount: The amount of staking currency to be transferred. - fn balances_transfer_keep_alive(to: Self::RelayChainAccountId, amount: Self::Balance) -> Self::RelayChainCall; + fn balances_transfer_keep_alive(to: Self::AssetHubAccountId, amount: Self::Balance) -> Self::AssetHubCall; /// Reserve transfer assets. /// params: @@ -129,31 +129,28 @@ pub trait CallBuilder { beneficiary: Location, assets: Assets, fee_assets_item: u32, - ) -> Self::RelayChainCall; + ) -> Self::AssetHubCall; /// Proxy a call with a `real` account without a forced proxy type. /// params: /// - real: The real account. /// - call: The call to be executed. - fn proxy_call(real: Self::RelayChainAccountId, call: Self::RelayChainCall) -> Self::RelayChainCall; + fn proxy_call(real: Self::AssetHubAccountId, call: Self::AssetHubCall) -> Self::AssetHubCall; /// Wrap the final call into the Xcm format. /// params: /// - call: The call to be executed /// - extra_fee: Extra fee (in staking currency) used for buy the `weight`. /// - weight: the weight limit used for XCM. - fn finalize_call_into_xcm_message( - call: Self::RelayChainCall, - extra_fee: Self::Balance, - weight: XcmWeight, - ) -> Xcm<()>; + fn finalize_call_into_xcm_message(call: Self::AssetHubCall, extra_fee: Self::Balance, weight: XcmWeight) + -> Xcm<()>; /// Wrap the final multiple calls into the Xcm format. /// params: /// - calls: the multiple calls and its weight limit to be executed /// - extra_fee: Extra fee (in staking currency) used for buy the `weight`. fn finalize_multiple_calls_into_xcm_message( - calls: Vec<(Self::RelayChainCall, XcmWeight)>, + calls: Vec<(Self::AssetHubCall, XcmWeight)>, extra_fee: Self::Balance, ) -> Xcm<()>; } diff --git a/modules/support/src/homa.rs b/modules/support/src/homa.rs index 172434fdb..9a007b1ea 100644 --- a/modules/support/src/homa.rs +++ b/modules/support/src/homa.rs @@ -22,18 +22,18 @@ use sp_std::{fmt::Debug, vec::Vec}; use xcm::v4::prelude::*; pub trait HomaSubAccountXcm { - type RelayChainAccountId: Debug + Clone + Ord; - /// Cross-chain transfer staking currency to sub account on relaychain. + type AssetHubAccountId: Debug + Clone + Ord; + /// Cross-chain transfer staking currency to sub account on assethub. fn transfer_staking_to_sub_account(sender: &AccountId, sub_account_index: u16, amount: Balance) -> DispatchResult; - /// Send XCM message to the relaychain for sub account to withdraw_unbonded staking currency and + /// Send XCM message to the assethub for sub account to withdraw_unbonded staking currency and /// send it back. fn withdraw_unbonded_from_sub_account(sub_account_index: u16, amount: Balance) -> DispatchResult; - /// Send XCM message to the relaychain for sub account to bond extra. + /// Send XCM message to the assethub for sub account to bond extra. fn bond_extra_on_sub_account(sub_account_index: u16, amount: Balance) -> DispatchResult; - /// Send XCM message to the relaychain for sub account to unbond. + /// Send XCM message to the assethub for sub account to unbond. fn unbond_on_sub_account(sub_account_index: u16, amount: Balance) -> DispatchResult; - /// Send XCM message to the relaychain for sub account to nominate. - fn nominate_on_sub_account(sub_account_index: u16, targets: Vec) -> DispatchResult; + /// Send XCM message to the assethub for sub account to nominate. + fn nominate_on_sub_account(sub_account_index: u16, targets: Vec) -> DispatchResult; /// The fee of cross-chain transfer is deducted from the recipient. fn get_xcm_transfer_fee() -> Balance; /// The fee of parachain diff --git a/modules/support/src/lib.rs b/modules/support/src/lib.rs index 4abaf1deb..bcf87571f 100644 --- a/modules/support/src/lib.rs +++ b/modules/support/src/lib.rs @@ -29,6 +29,7 @@ use sp_runtime::{ use sp_std::{prelude::*, result::Result, vec}; use xcm::prelude::*; +pub mod assethub; pub mod bounded; pub mod dex; pub mod earning; @@ -37,7 +38,6 @@ pub mod homa; pub mod honzon; pub mod incentives; pub mod mocks; -pub mod relaychain; pub mod stable_asset; pub use crate::bounded::*; diff --git a/modules/xcm-interface/Cargo.toml b/modules/xcm-interface/Cargo.toml index 1cfac111b..d606d4844 100644 --- a/modules/xcm-interface/Cargo.toml +++ b/modules/xcm-interface/Cargo.toml @@ -29,7 +29,7 @@ xcm-builder = { workspace = true, features = ["std"] } xcm-executor = { workspace = true, features = ["std"] } orml-tokens = { workspace = true, features = ["std"] } module-currencies = { workspace = true, features = ["std"] } -module-relaychain = { workspace = true, features = ["std"] } +module-assethub = { workspace = true, features = ["std"] } [features] default = ["std"] diff --git a/modules/xcm-interface/src/lib.rs b/modules/xcm-interface/src/lib.rs index ae6cbb3f0..7307788a8 100644 --- a/modules/xcm-interface/src/lib.rs +++ b/modules/xcm-interface/src/lib.rs @@ -18,7 +18,7 @@ //! Xcm Interface module. //! -//! This module interfaces Acala native modules with the Relaychain / parachains via the use of XCM. +//! This module interfaces Acala native modules with the AssetHub / parachains via the use of XCM. //! Functions in this module will create XCM messages that performs the requested functions and //! send the messages out to the intended destination. //! @@ -29,7 +29,7 @@ use frame_support::{pallet_prelude::*, traits::Get}; use frame_system::pallet_prelude::*; -use module_support::{relaychain::CallBuilder, HomaSubAccountXcm}; +use module_support::{assethub::CallBuilder, HomaSubAccountXcm}; use orml_traits::XcmTransfer; use primitives::{Balance, CurrencyId, EraIndex}; use scale_info::TypeInfo; @@ -71,20 +71,20 @@ pub mod module { #[pallet::constant] type StakingCurrencyId: Get; - /// The account of parachain on the relaychain. + /// The account of parachain on the assethub. #[pallet::constant] type ParachainAccount: Get; - /// Unbonding slashing spans for unbonding on the relaychain. + /// Unbonding slashing spans for unbonding on the assethub. #[pallet::constant] - type RelayChainUnbondingSlashingSpans: Get; + type AssetHubUnbondingSlashingSpans: Get; /// The convert for convert sovereign subacocunt index to the Location where the /// staking currencies are sent to. type SovereignSubAccountLocationConvert: Convert; - /// The Call builder for communicating with RelayChain via XCM messaging. - type RelayChainCallBuilder: CallBuilder; + /// The Call builder for communicating with AssetHub via XCM messaging. + type AssetHubCallBuilder: CallBuilder; /// The interface to Cross-chain transfer. type XcmTransfer: XcmTransfer; @@ -119,7 +119,7 @@ pub mod module { } /// The dest weight limit and fee for execution XCM msg sended by XcmInterface. Must be - /// sufficient, otherwise the execution of XCM msg on relaychain will fail. + /// sufficient, otherwise the execution of XCM msg on assethub will fail. /// /// XcmDestWeightAndFee: map: XcmInterfaceOperation => (Weight, Balance) #[pallet::storage] @@ -172,9 +172,9 @@ pub mod module { } impl HomaSubAccountXcm for Pallet { - type RelayChainAccountId = T::AccountId; + type AssetHubAccountId = T::AccountId; - /// Cross-chain transfer staking currency to sub account on relaychain. + /// Cross-chain transfer staking currency to sub account on assethub. fn transfer_staking_to_sub_account( sender: &T::AccountId, sub_account_index: u16, @@ -190,27 +190,25 @@ pub mod module { .map(|_| ()) } - /// Send XCM message to the relaychain for sub account to withdraw_unbonded staking currency + /// Send XCM message to the assethub for sub account to withdraw_unbonded staking currency /// and send it back. fn withdraw_unbonded_from_sub_account(sub_account_index: u16, amount: Balance) -> DispatchResult { let (xcm_dest_weight, xcm_fee) = Self::xcm_dest_weight_and_fee(XcmInterfaceOperation::HomaWithdrawUnbonded); // TODO: config xcm_dest_weight and fee for withdraw_unbonded and transfer separately. // Temporarily use double fee. - let xcm_message = T::RelayChainCallBuilder::finalize_multiple_calls_into_xcm_message( + let xcm_message = T::AssetHubCallBuilder::finalize_multiple_calls_into_xcm_message( vec![ ( - T::RelayChainCallBuilder::utility_as_derivative_call( - T::RelayChainCallBuilder::staking_withdraw_unbonded( - T::RelayChainUnbondingSlashingSpans::get(), - ), + T::AssetHubCallBuilder::utility_as_derivative_call( + T::AssetHubCallBuilder::staking_withdraw_unbonded(T::AssetHubUnbondingSlashingSpans::get()), sub_account_index, ), xcm_dest_weight, ), ( - T::RelayChainCallBuilder::utility_as_derivative_call( - T::RelayChainCallBuilder::balances_transfer_keep_alive(T::ParachainAccount::get(), amount), + T::AssetHubCallBuilder::utility_as_derivative_call( + T::AssetHubCallBuilder::balances_transfer_keep_alive(T::ParachainAccount::get(), amount), sub_account_index, ), xcm_dest_weight, @@ -230,12 +228,12 @@ pub mod module { Ok(()) } - /// Send XCM message to the relaychain for sub account to bond extra. + /// Send XCM message to the assethub for sub account to bond extra. fn bond_extra_on_sub_account(sub_account_index: u16, amount: Balance) -> DispatchResult { let (xcm_dest_weight, xcm_fee) = Self::xcm_dest_weight_and_fee(XcmInterfaceOperation::HomaBondExtra); - let xcm_message = T::RelayChainCallBuilder::finalize_call_into_xcm_message( - T::RelayChainCallBuilder::utility_as_derivative_call( - T::RelayChainCallBuilder::staking_bond_extra(amount), + let xcm_message = T::AssetHubCallBuilder::finalize_call_into_xcm_message( + T::AssetHubCallBuilder::utility_as_derivative_call( + T::AssetHubCallBuilder::staking_bond_extra(amount), sub_account_index, ), xcm_fee, @@ -252,12 +250,12 @@ pub mod module { Ok(()) } - /// Send XCM message to the relaychain for sub account to unbond. + /// Send XCM message to the assethub for sub account to unbond. fn unbond_on_sub_account(sub_account_index: u16, amount: Balance) -> DispatchResult { let (xcm_dest_weight, xcm_fee) = Self::xcm_dest_weight_and_fee(XcmInterfaceOperation::HomaUnbond); - let xcm_message = T::RelayChainCallBuilder::finalize_call_into_xcm_message( - T::RelayChainCallBuilder::utility_as_derivative_call( - T::RelayChainCallBuilder::staking_unbond(amount), + let xcm_message = T::AssetHubCallBuilder::finalize_call_into_xcm_message( + T::AssetHubCallBuilder::utility_as_derivative_call( + T::AssetHubCallBuilder::staking_unbond(amount), sub_account_index, ), xcm_fee, @@ -274,12 +272,12 @@ pub mod module { Ok(()) } - /// Send XCM message to the relaychain for sub account to nominate. - fn nominate_on_sub_account(sub_account_index: u16, targets: Vec) -> DispatchResult { + /// Send XCM message to the assethub for sub account to nominate. + fn nominate_on_sub_account(sub_account_index: u16, targets: Vec) -> DispatchResult { let (xcm_dest_weight, xcm_fee) = Self::xcm_dest_weight_and_fee(XcmInterfaceOperation::HomaNominate); - let xcm_message = T::RelayChainCallBuilder::finalize_call_into_xcm_message( - T::RelayChainCallBuilder::utility_as_derivative_call( - T::RelayChainCallBuilder::staking_nominate(targets.clone()), + let xcm_message = T::AssetHubCallBuilder::finalize_call_into_xcm_message( + T::AssetHubCallBuilder::utility_as_derivative_call( + T::AssetHubCallBuilder::staking_nominate(targets.clone()), sub_account_index, ), xcm_fee, diff --git a/modules/xcm-interface/src/mocks/kusama.rs b/modules/xcm-interface/src/mocks/kusama.rs index 58bd936bf..6f41d3354 100644 --- a/modules/xcm-interface/src/mocks/kusama.rs +++ b/modules/xcm-interface/src/mocks/kusama.rs @@ -18,4 +18,4 @@ use super::*; -impl_mock!(module_relaychain::KusamaRelayChainCall); +impl_mock!(module_assethub::KusamaAssetHubCall); diff --git a/modules/xcm-interface/src/mocks/mod.rs b/modules/xcm-interface/src/mocks/mod.rs index 806fa25cf..1575ea287 100644 --- a/modules/xcm-interface/src/mocks/mod.rs +++ b/modules/xcm-interface/src/mocks/mod.rs @@ -60,7 +60,7 @@ ord_parameter_types! { parameter_types! { pub const GetStakingCurrencyId: CurrencyId = DOT; pub const ParachainAccount: AccountId = AccountId32::new([0u8; 32]); - pub const ParachainId: module_relaychain::ParaId = module_relaychain::ParaId::new(2000); + pub const ParachainId: module_assethub::ParaId = module_assethub::ParaId::new(2000); pub SelfLocation: Location = Location::new(1, Parachain(ParachainId::get().into())); } @@ -212,7 +212,7 @@ impl XcmAssetTransfers for MockExec { #[macro_export] macro_rules! impl_mock { - ($relaychain:ty) => { + ($assethub:ty) => { pub type LocalOriginToLocation = SignedToAccountId32; pub type Block = frame_system::mocking::MockBlock; @@ -271,9 +271,9 @@ macro_rules! impl_mock { type UpdateOrigin = EnsureSignedBy; type StakingCurrencyId = GetStakingCurrencyId; type ParachainAccount = ParachainAccount; - type RelayChainUnbondingSlashingSpans = ConstU32<28>; + type AssetHubUnbondingSlashingSpans = ConstU32<28>; type SovereignSubAccountLocationConvert = SubAccountIndexLocationConvertor; - type RelayChainCallBuilder = module_relaychain::RelayChainCallBuilder; + type AssetHubCallBuilder = module_assethub::AssetHubCallBuilder; type XcmTransfer = MockXcmTransfer; type SelfLocation = SelfLocation; type AccountIdToLocation = AccountIdToLocation; diff --git a/modules/xcm-interface/src/mocks/polkadot.rs b/modules/xcm-interface/src/mocks/polkadot.rs index a18b1db21..b1743a053 100644 --- a/modules/xcm-interface/src/mocks/polkadot.rs +++ b/modules/xcm-interface/src/mocks/polkadot.rs @@ -18,4 +18,4 @@ use super::*; -impl_mock!(module_relaychain::PolkadotRelayChainCall); +impl_mock!(module_assethub::PolkadotAssetHubCall); diff --git a/runtime/acala/Cargo.toml b/runtime/acala/Cargo.toml index 45fdb08a9..8a9e2b66a 100644 --- a/runtime/acala/Cargo.toml +++ b/runtime/acala/Cargo.toml @@ -120,7 +120,7 @@ module-liquid-crowdloan = { workspace = true } module-loans = { workspace = true } module-nft = { workspace = true } module-prices = { workspace = true } -module-relaychain = { workspace = true } +module-assethub = { workspace = true } module-session-manager = { workspace = true } module-support = { workspace = true } module-transaction-pause = { workspace = true } @@ -259,7 +259,7 @@ std = [ "module-loans/std", "module-nft/std", "module-prices/std", - "module-relaychain/std", + "module-assethub/std", "module-session-manager/std", "module-support/std", "module-transaction-pause/std", diff --git a/runtime/acala/src/lib.rs b/runtime/acala/src/lib.rs index 530977134..3e2cbc779 100644 --- a/runtime/acala/src/lib.rs +++ b/runtime/acala/src/lib.rs @@ -52,11 +52,11 @@ use sp_version::RuntimeVersion; use frame_system::{EnsureRoot, EnsureSigned, RawOrigin}; use module_asset_registry::{AssetIdMaps, EvmErc20InfoMapping}; +use module_assethub::AssetHubCallBuilder; use module_cdp_engine::CollateralCurrencyIds; use module_currencies::BasicCurrencyAdapter; use module_evm::{runner::RunnerExtended, CallInfo, CreateInfo, EvmChainId, EvmTask}; use module_evm_accounts::EvmAddressMapping; -use module_relaychain::RelayChainCallBuilder; use module_support::{AddressMapping, AssetIdMapping, DispatchableTask, PoolId}; use module_transaction_payment::TargetedFeeAdjustment; @@ -1606,7 +1606,7 @@ parameter_types! { impl module_homa_validator_list::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type RelayChainAccountId = AccountId; + type ValidatorId = AccountId; type LiquidTokenCurrency = module_currencies::Currency; type MinBondAmount = MinBondAmount; type BondingDuration = BondingDuration; @@ -1672,9 +1672,9 @@ impl module_xcm_interface::Config for Runtime { type UpdateOrigin = EnsureRootOrHalfGeneralCouncil; type StakingCurrencyId = GetStakingCurrencyId; type ParachainAccount = ParachainAccount; - type RelayChainUnbondingSlashingSpans = ConstU32<5>; + type AssetHubUnbondingSlashingSpans = ConstU32<5>; type SovereignSubAccountLocationConvert = SubAccountIndexLocationConvertor; - type RelayChainCallBuilder = RelayChainCallBuilder; + type AssetHubCallBuilder = AssetHubCallBuilder; type XcmTransfer = XTokens; type SelfLocation = xcm_config::SelfLocation; type AccountIdToLocation = runtime_common::xcm_config::AccountIdToLocation; diff --git a/runtime/common/src/precompile/mock.rs b/runtime/common/src/precompile/mock.rs index 4b4ab0a4f..def8fd7b1 100644 --- a/runtime/common/src/precompile/mock.rs +++ b/runtime/common/src/precompile/mock.rs @@ -681,7 +681,7 @@ impl module_prices::Config for Test { /// mock XCM transfer. pub struct MockHomaSubAccountXcm; impl HomaSubAccountXcm for MockHomaSubAccountXcm { - type RelayChainAccountId = AccountId; + type AssetHubAccountId = AccountId; fn transfer_staking_to_sub_account(sender: &AccountId, _: u16, amount: Balance) -> DispatchResult { Currencies::withdraw( StakingCurrencyId::get(), @@ -703,7 +703,7 @@ impl HomaSubAccountXcm for MockHomaSubAccountXcm { Ok(()) } - fn nominate_on_sub_account(_: u16, _: Vec) -> DispatchResult { + fn nominate_on_sub_account(_: u16, _: Vec) -> DispatchResult { Ok(()) } diff --git a/runtime/integration-tests/Cargo.toml b/runtime/integration-tests/Cargo.toml index 72ced16cb..5c2421f7d 100644 --- a/runtime/integration-tests/Cargo.toml +++ b/runtime/integration-tests/Cargo.toml @@ -107,7 +107,7 @@ module-support = { workspace = true, features = ["std"] } module-xcm-interface = { workspace = true, features = ["std"] } module-homa = { workspace = true, features = ["std"] } module-session-manager = { workspace = true, features = ["std"] } -module-relaychain = { workspace = true, features = ["std"] } +module-assethub = { workspace = true, features = ["std"] } primitives = { workspace = true, features = ["std"] } runtime-common = { workspace = true, features = ["std"] } diff --git a/runtime/karura/Cargo.toml b/runtime/karura/Cargo.toml index da7130aef..ab9865017 100644 --- a/runtime/karura/Cargo.toml +++ b/runtime/karura/Cargo.toml @@ -120,7 +120,7 @@ module-incentives = { workspace = true } module-loans = { workspace = true } module-nft = { workspace = true } module-prices = { workspace = true } -module-relaychain = { workspace = true } +module-assethub = { workspace = true } module-session-manager = { workspace = true } module-support = { workspace = true } module-transaction-pause = { workspace = true } @@ -261,7 +261,7 @@ std = [ "module-loans/std", "module-nft/std", "module-prices/std", - "module-relaychain/std", + "module-assethub/std", "module-session-manager/std", "module-support/std", "module-transaction-pause/std", diff --git a/runtime/karura/src/lib.rs b/runtime/karura/src/lib.rs index 65cf55b72..a982682ff 100644 --- a/runtime/karura/src/lib.rs +++ b/runtime/karura/src/lib.rs @@ -53,11 +53,11 @@ use sp_version::RuntimeVersion; use frame_system::{EnsureRoot, EnsureSigned, RawOrigin}; use module_asset_registry::{AssetIdMaps, EvmErc20InfoMapping}; +use module_assethub::AssetHubCallBuilder; use module_cdp_engine::CollateralCurrencyIds; use module_currencies::BasicCurrencyAdapter; use module_evm::{runner::RunnerExtended, CallInfo, CreateInfo, EvmChainId, EvmTask}; use module_evm_accounts::EvmAddressMapping; -use module_relaychain::RelayChainCallBuilder; use module_support::{AddressMapping, AssetIdMapping, DispatchableTask, ExchangeRateProvider, FractionalRate, PoolId}; use module_transaction_payment::TargetedFeeAdjustment; @@ -1631,7 +1631,7 @@ parameter_types! { impl module_homa_validator_list::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type RelayChainAccountId = AccountId; + type ValidatorId = AccountId; type LiquidTokenCurrency = module_currencies::Currency; type MinBondAmount = MinBondAmount; type BondingDuration = BondingDuration; @@ -1697,9 +1697,9 @@ impl module_xcm_interface::Config for Runtime { type UpdateOrigin = EnsureRootOrHalfGeneralCouncil; type StakingCurrencyId = GetStakingCurrencyId; type ParachainAccount = ParachainAccount; - type RelayChainUnbondingSlashingSpans = ConstU32<5>; + type AssetHubUnbondingSlashingSpans = ConstU32<5>; type SovereignSubAccountLocationConvert = SubAccountIndexLocationConvertor; - type RelayChainCallBuilder = RelayChainCallBuilder; + type AssetHubCallBuilder = AssetHubCallBuilder; type XcmTransfer = XTokens; type SelfLocation = xcm_config::SelfLocation; type AccountIdToLocation = runtime_common::xcm_config::AccountIdToLocation; diff --git a/runtime/mandala/Cargo.toml b/runtime/mandala/Cargo.toml index 0a494d367..d490249da 100644 --- a/runtime/mandala/Cargo.toml +++ b/runtime/mandala/Cargo.toml @@ -128,7 +128,7 @@ module-homa-validator-list = { workspace = true } module-xcm-interface = { workspace = true } module-nominees-election = { workspace = true } module-session-manager = { workspace = true } -module-relaychain = { workspace = true } +module-assethub = { workspace = true } module-idle-scheduler = { workspace = true } module-aggregated-dex = { workspace = true } module-liquid-crowdloan = { workspace = true } @@ -274,7 +274,7 @@ std = [ "module-nft/std", "module-nominees-election/std", "module-prices/std", - "module-relaychain/std", + "module-assethub/std", "module-session-manager/std", "module-support/std", "module-transaction-pause/std", diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index 7a942702b..d8dc8a1de 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -48,11 +48,11 @@ use frame_support::{ }; use frame_system::{EnsureRoot, EnsureSigned, RawOrigin}; use module_asset_registry::{AssetIdMaps, EvmErc20InfoMapping}; +use module_assethub::AssetHubCallBuilder; use module_cdp_engine::CollateralCurrencyIds; use module_currencies::BasicCurrencyAdapter; use module_evm::{runner::RunnerExtended, CallInfo, CreateInfo, EvmChainId, EvmTask}; use module_evm_accounts::EvmAddressMapping; -use module_relaychain::RelayChainCallBuilder; use module_support::{AddressMapping, AssetIdMapping, DispatchableTask, ExchangeRateProvider, FractionalRate, PoolId}; use module_transaction_payment::TargetedFeeAdjustment; use parity_scale_codec::{Decode, DecodeLimit, Encode}; @@ -1466,7 +1466,7 @@ parameter_types! { impl module_homa_validator_list::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type RelayChainAccountId = AccountId; + type ValidatorId = AccountId; type LiquidTokenCurrency = module_currencies::Currency; type MinBondAmount = MinBondAmount; type BondingDuration = BondingDuration; @@ -1515,9 +1515,9 @@ impl module_xcm_interface::Config for Runtime { type UpdateOrigin = EnsureRootOrHalfGeneralCouncil; type StakingCurrencyId = GetStakingCurrencyId; type ParachainAccount = ParachainAccount; - type RelayChainUnbondingSlashingSpans = ConstU32<5>; + type AssetHubUnbondingSlashingSpans = ConstU32<5>; type SovereignSubAccountLocationConvert = SubAccountIndexLocationConvertor; - type RelayChainCallBuilder = RelayChainCallBuilder; + type AssetHubCallBuilder = AssetHubCallBuilder; type XcmTransfer = XTokens; type SelfLocation = xcm_config::SelfLocation; type AccountIdToLocation = xcm_config::AccountIdToLocation; From 6ad2c52dc03339dc02d72726c8cac7b82e89342b Mon Sep 17 00:00:00 2001 From: zjb0807 Date: Sun, 22 Jun 2025 15:39:58 +0800 Subject: [PATCH 03/12] improve --- modules/homa/src/lib.rs | 10 ++++------ modules/homa/src/mock.rs | 4 ++-- modules/support/src/homa.rs | 4 ++-- modules/xcm-interface/src/lib.rs | 4 ++-- runtime/common/src/precompile/mock.rs | 4 ++-- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/modules/homa/src/lib.rs b/modules/homa/src/lib.rs index d4d547ce1..1e8c85a20 100644 --- a/modules/homa/src/lib.rs +++ b/modules/homa/src/lib.rs @@ -49,10 +49,8 @@ pub mod weights; pub mod module { use super::*; - pub type AssetHubAccountIdOf = <::XcmInterface as HomaSubAccountXcm< - ::AccountId, - Balance, - >>::AssetHubAccountId; + pub type NomineeIdOf = + <::XcmInterface as HomaSubAccountXcm<::AccountId, Balance>>::NomineeId; /// The subaccount's staking ledger which kept by Homa protocol #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, Default)] @@ -163,7 +161,7 @@ pub mod module { /// Weight information for the extrinsics in this module. type WeightInfo: WeightInfo; - type NominationsProvider: NomineesProvider>; + type NominationsProvider: NomineesProvider>; } #[pallet::error] @@ -265,7 +263,7 @@ pub mod module { /// Nominate validators on assethub HomaNominate { sub_account_index: u16, - nominations: Vec>, + nominations: Vec>, }, } diff --git a/modules/homa/src/mock.rs b/modules/homa/src/mock.rs index ec89fdc0b..2a52ddfbd 100644 --- a/modules/homa/src/mock.rs +++ b/modules/homa/src/mock.rs @@ -56,7 +56,7 @@ pub const VALIDATOR_D: AccountId = AccountId32::new([203u8; 32]); /// mock XCM transfer. pub struct MockHomaSubAccountXcm; impl HomaSubAccountXcm for MockHomaSubAccountXcm { - type AssetHubAccountId = AccountId; + type NomineeId = AccountId; fn transfer_staking_to_sub_account(sender: &AccountId, _: u16, amount: Balance) -> DispatchResult { Currencies::withdraw( @@ -79,7 +79,7 @@ impl HomaSubAccountXcm for MockHomaSubAccountXcm { Ok(()) } - fn nominate_on_sub_account(_: u16, _: Vec) -> DispatchResult { + fn nominate_on_sub_account(_: u16, _: Vec) -> DispatchResult { Ok(()) } diff --git a/modules/support/src/homa.rs b/modules/support/src/homa.rs index 9a007b1ea..5a7f06d13 100644 --- a/modules/support/src/homa.rs +++ b/modules/support/src/homa.rs @@ -22,7 +22,7 @@ use sp_std::{fmt::Debug, vec::Vec}; use xcm::v4::prelude::*; pub trait HomaSubAccountXcm { - type AssetHubAccountId: Debug + Clone + Ord; + type NomineeId: Debug + Clone + Ord; /// Cross-chain transfer staking currency to sub account on assethub. fn transfer_staking_to_sub_account(sender: &AccountId, sub_account_index: u16, amount: Balance) -> DispatchResult; /// Send XCM message to the assethub for sub account to withdraw_unbonded staking currency and @@ -33,7 +33,7 @@ pub trait HomaSubAccountXcm { /// Send XCM message to the assethub for sub account to unbond. fn unbond_on_sub_account(sub_account_index: u16, amount: Balance) -> DispatchResult; /// Send XCM message to the assethub for sub account to nominate. - fn nominate_on_sub_account(sub_account_index: u16, targets: Vec) -> DispatchResult; + fn nominate_on_sub_account(sub_account_index: u16, targets: Vec) -> DispatchResult; /// The fee of cross-chain transfer is deducted from the recipient. fn get_xcm_transfer_fee() -> Balance; /// The fee of parachain diff --git a/modules/xcm-interface/src/lib.rs b/modules/xcm-interface/src/lib.rs index 7307788a8..0f79b2a38 100644 --- a/modules/xcm-interface/src/lib.rs +++ b/modules/xcm-interface/src/lib.rs @@ -172,7 +172,7 @@ pub mod module { } impl HomaSubAccountXcm for Pallet { - type AssetHubAccountId = T::AccountId; + type NomineeId = T::AccountId; /// Cross-chain transfer staking currency to sub account on assethub. fn transfer_staking_to_sub_account( @@ -273,7 +273,7 @@ pub mod module { } /// Send XCM message to the assethub for sub account to nominate. - fn nominate_on_sub_account(sub_account_index: u16, targets: Vec) -> DispatchResult { + fn nominate_on_sub_account(sub_account_index: u16, targets: Vec) -> DispatchResult { let (xcm_dest_weight, xcm_fee) = Self::xcm_dest_weight_and_fee(XcmInterfaceOperation::HomaNominate); let xcm_message = T::AssetHubCallBuilder::finalize_call_into_xcm_message( T::AssetHubCallBuilder::utility_as_derivative_call( diff --git a/runtime/common/src/precompile/mock.rs b/runtime/common/src/precompile/mock.rs index def8fd7b1..208101e12 100644 --- a/runtime/common/src/precompile/mock.rs +++ b/runtime/common/src/precompile/mock.rs @@ -681,7 +681,7 @@ impl module_prices::Config for Test { /// mock XCM transfer. pub struct MockHomaSubAccountXcm; impl HomaSubAccountXcm for MockHomaSubAccountXcm { - type AssetHubAccountId = AccountId; + type NomineeId = AccountId; fn transfer_staking_to_sub_account(sender: &AccountId, _: u16, amount: Balance) -> DispatchResult { Currencies::withdraw( StakingCurrencyId::get(), @@ -703,7 +703,7 @@ impl HomaSubAccountXcm for MockHomaSubAccountXcm { Ok(()) } - fn nominate_on_sub_account(_: u16, _: Vec) -> DispatchResult { + fn nominate_on_sub_account(_: u16, _: Vec) -> DispatchResult { Ok(()) } From bb471bfa55877170bacd10278c78e577f7e173e1 Mon Sep 17 00:00:00 2001 From: zjb0807 Date: Sun, 22 Jun 2025 16:02:14 +0800 Subject: [PATCH 04/12] fix --- runtime/mandala/src/benchmarking/homa_validator_list.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/mandala/src/benchmarking/homa_validator_list.rs b/runtime/mandala/src/benchmarking/homa_validator_list.rs index a50527b07..e9215078f 100644 --- a/runtime/mandala/src/benchmarking/homa_validator_list.rs +++ b/runtime/mandala/src/benchmarking/homa_validator_list.rs @@ -136,7 +136,7 @@ runtime_benchmarks! { )?; slashes.push(SlashInfo{ validator, - relaychain_token_amount: ValidatorInsuranceThreshold::get() * 9 + token_amount: ValidatorInsuranceThreshold::get() * 9 }); } }: _(RawOrigin::Root, slashes) From 461dc8751f19a3b61b72babff9df04b36ea27436 Mon Sep 17 00:00:00 2001 From: zjb0807 Date: Sun, 22 Jun 2025 17:34:11 +0800 Subject: [PATCH 05/12] add const --- runtime/mandala/src/constants.rs | 6 ++++++ runtime/mandala/src/lib.rs | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/runtime/mandala/src/constants.rs b/runtime/mandala/src/constants.rs index e3c2d0357..51a9fd45a 100644 --- a/runtime/mandala/src/constants.rs +++ b/runtime/mandala/src/constants.rs @@ -91,6 +91,12 @@ pub mod fee { } } +pub mod parachains { + pub mod asset_hub_polkadot { + pub const ID: u32 = 1000; + } +} + #[cfg(test)] mod tests { use crate::{constants::fee::base_tx_in_aca, Balance}; diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index d8dc8a1de..4445cc913 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -94,7 +94,7 @@ pub use sp_runtime::BuildStorage; pub use sp_runtime::{Perbill, Percent, Permill, Perquintill}; pub use authority::AuthorityConfigImpl; -pub use constants::{fee::*, time::*}; +pub use constants::{fee::*, parachains, time::*}; pub use primitives::{ currency::AssetIds, evm::{BlockLimits, EstimateResourcesRequest}, @@ -1416,7 +1416,7 @@ pub fn create_x2_parachain_location(index: u16) -> Location { Location::new( 1, [ - Parachain(1000), + Parachain(parachains::asset_hub_polkadot::ID), AccountId32 { network: None, id: Utility::derivative_account_id( From 0717f552bf3b70f74702dbe4155e71870e696659 Mon Sep 17 00:00:00 2001 From: zjb0807 Date: Fri, 4 Jul 2025 10:18:51 +0800 Subject: [PATCH 06/12] update --- runtime/acala/src/xcm_config.rs | 10 +++++----- runtime/mandala/src/xcm_config.rs | 9 +++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/runtime/acala/src/xcm_config.rs b/runtime/acala/src/xcm_config.rs index c6118f7ff..0d046562e 100644 --- a/runtime/acala/src/xcm_config.rs +++ b/runtime/acala/src/xcm_config.rs @@ -97,11 +97,11 @@ parameter_types! { pub BaseRate: u128 = aca_per_second(); /// Location of Asset Hub - pub AssetHubLocation: Location = Location::new(1, [Parachain(parachains::asset_hub_polkadot::ID)]); - pub RelayChainNativeAssetFromAssetHub: (AssetFilter, Location) = ( - RelayLocationFilter::get(), - AssetHubLocation::get() - ); + pub AssetHubLocation: Location = Location::new(1, [Parachain(parachains::asset_hub_polkadot::ID)]); + pub RelayChainNativeAssetFromAssetHub: (AssetFilter, Location) = ( + RelayLocationFilter::get(), + AssetHubLocation::get() + ); } type Reserves = ( diff --git a/runtime/mandala/src/xcm_config.rs b/runtime/mandala/src/xcm_config.rs index 9f595aaff..45f37d86c 100644 --- a/runtime/mandala/src/xcm_config.rs +++ b/runtime/mandala/src/xcm_config.rs @@ -17,10 +17,11 @@ // along with this program. If not, see . use super::{ - constants::fee::*, AccountId, AllPalletsWithSystem, AssetIdMapping, AssetIdMaps, Balance, Balances, Convert, - Currencies, CurrencyId, EvmAddressMapping, ExistentialDeposits, GetNativeCurrencyId, MessageQueue, - NativeTokenExistentialDeposit, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, - RuntimeOrigin, TreasuryAccount, UnknownTokens, XcmpQueue, ACA, + constants::{fee::*, parachains}, + AccountId, AllPalletsWithSystem, AssetIdMapping, AssetIdMaps, Balance, Balances, Convert, Currencies, CurrencyId, + EvmAddressMapping, ExistentialDeposits, GetNativeCurrencyId, MessageQueue, NativeTokenExistentialDeposit, + ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, TreasuryAccount, + UnknownTokens, XcmpQueue, ACA, }; pub use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; pub use frame_support::{ From aac0a43b7bfd0e24c4e678ba2edf6f3effaeb7ab Mon Sep 17 00:00:00 2001 From: zjb0807 Date: Fri, 4 Jul 2025 10:23:20 +0800 Subject: [PATCH 07/12] fix clippy --- runtime/mandala/src/xcm_config.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/runtime/mandala/src/xcm_config.rs b/runtime/mandala/src/xcm_config.rs index 45f37d86c..9f595aaff 100644 --- a/runtime/mandala/src/xcm_config.rs +++ b/runtime/mandala/src/xcm_config.rs @@ -17,11 +17,10 @@ // along with this program. If not, see . use super::{ - constants::{fee::*, parachains}, - AccountId, AllPalletsWithSystem, AssetIdMapping, AssetIdMaps, Balance, Balances, Convert, Currencies, CurrencyId, - EvmAddressMapping, ExistentialDeposits, GetNativeCurrencyId, MessageQueue, NativeTokenExistentialDeposit, - ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, TreasuryAccount, - UnknownTokens, XcmpQueue, ACA, + constants::fee::*, AccountId, AllPalletsWithSystem, AssetIdMapping, AssetIdMaps, Balance, Balances, Convert, + Currencies, CurrencyId, EvmAddressMapping, ExistentialDeposits, GetNativeCurrencyId, MessageQueue, + NativeTokenExistentialDeposit, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, + RuntimeOrigin, TreasuryAccount, UnknownTokens, XcmpQueue, ACA, }; pub use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; pub use frame_support::{ From 3aefeea38dcbdb5ad5cface6538d5f236ce382b2 Mon Sep 17 00:00:00 2001 From: zjb0807 Date: Tue, 15 Jul 2025 23:56:34 +0800 Subject: [PATCH 08/12] fix --- modules/assethub/src/lib.rs | 28 +++++++++++++------------- modules/homa/src/lib.rs | 8 ++++---- modules/xcm-interface/src/lib.rs | 26 +++++++++++++++--------- modules/xcm-interface/src/mocks/mod.rs | 5 +++-- runtime/acala/src/lib.rs | 2 +- runtime/karura/src/lib.rs | 2 +- runtime/mandala/src/lib.rs | 4 ++-- runtime/mandala/src/xcm_config.rs | 10 +++++---- 8 files changed, 48 insertions(+), 37 deletions(-) diff --git a/modules/assethub/src/lib.rs b/modules/assethub/src/lib.rs index e3438e459..50295c9eb 100644 --- a/modules/assethub/src/lib.rs +++ b/modules/assethub/src/lib.rs @@ -36,18 +36,18 @@ pub use cumulus_primitives_core::ParaId; use xcm::v4::{prelude::*, Weight as XcmWeight}; /// The encoded index corresponds to AssetHub's Runtime module configuration. -/// https://github.com/paritytech/polkadot/blob/444e96ae34bcec8362f0f947a07bd912b32ca48f/runtime/kusama/src/lib.rs#L1379 +/// https://github.com/polkadot-fellows/runtimes/blob/2fb47566718a974c261b68fffaae500be5581820/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs#L1065 #[derive(Encode, Decode, RuntimeDebug)] pub enum KusamaAssetHubCall { - #[codec(index = 4)] + #[codec(index = 10)] Balances(BalancesCall), - #[codec(index = 6)] + #[codec(index = 89)] // TODO: update Staking(StakingCall), - #[codec(index = 24)] + #[codec(index = 40)] Utility(Box>), - #[codec(index = 30)] + #[codec(index = 42)] Proxy(Box>), - #[codec(index = 99)] + #[codec(index = 31)] XcmPallet(XcmCall), } @@ -74,18 +74,18 @@ impl AssetHubCall for KusamaAssetHubCall { } /// The encoded index corresponds to AssetHub's Runtime module configuration. -/// https://github.com/paritytech/polkadot/blob/84a3962e76151ac5ed3afa4ef1e0af829531ab42/runtime/polkadot/src/lib.rs#L1040 +/// https://github.com/polkadot-fellows/runtimes/blob/2fb47566718a974c261b68fffaae500be5581820/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs#L983 #[derive(Encode, Decode, RuntimeDebug)] pub enum PolkadotAssetHubCall { - #[codec(index = 5)] + #[codec(index = 10)] Balances(BalancesCall), - #[codec(index = 7)] + #[codec(index = 89)] // TODO: check https://github.com/polkadot-fellows/runtimes/pull/812 Staking(StakingCall), - #[codec(index = 26)] + #[codec(index = 40)] Utility(Box>), - #[codec(index = 29)] + #[codec(index = 42)] Proxy(Box>), - #[codec(index = 99)] + #[codec(index = 31)] XcmPallet(XcmCall), } @@ -169,7 +169,7 @@ where fn finalize_call_into_xcm_message(call: AHC, extra_fee: Self::Balance, weight: XcmWeight) -> Xcm<()> { let asset = Asset { - id: AssetId(Location::here()), + id: AssetId(Location::parent()), fun: Fungibility::Fungible(extra_fee), }; Xcm(vec![ @@ -196,7 +196,7 @@ where fn finalize_multiple_calls_into_xcm_message(calls: Vec<(AHC, XcmWeight)>, extra_fee: Self::Balance) -> Xcm<()> { let asset = Asset { - id: AssetId(Location::here()), + id: AssetId(Location::parent()), fun: Fungibility::Fungible(extra_fee), }; diff --git a/modules/homa/src/lib.rs b/modules/homa/src/lib.rs index 1e8c85a20..3e70ecde9 100644 --- a/modules/homa/src/lib.rs +++ b/modules/homa/src/lib.rs @@ -663,10 +663,10 @@ pub mod module { #[pallet::call_index(8)] #[pallet::weight(< T as Config >::WeightInfo::on_initialize_with_bump_era(T::ProcessRedeemRequestsLimit::get()))] - pub fn force_bump_current_era(origin: OriginFor, bump_amount: EraIndex) -> DispatchResultWithPostInfo { + pub fn force_bump_current_era(origin: OriginFor, bump_era: EraIndex) -> DispatchResultWithPostInfo { T::GovernanceOrigin::ensure_origin(origin)?; - let res = Self::bump_current_era(bump_amount); + let res = Self::bump_current_era(bump_era); Ok(Some(T::WeightInfo::on_initialize_with_bump_era(res.unwrap_or_default())).into()) } @@ -1181,9 +1181,9 @@ pub mod module { /// The rebalance will send XCM messages to assethub. Once the XCM message is sent, /// the execution result cannot be obtained and cannot be rolled back. So the process /// of rebalance is not atomic. - pub fn bump_current_era(amount: EraIndex) -> Result { + pub fn bump_current_era(bump_era: EraIndex) -> Result { let previous_era = Self::relay_chain_current_era(); - let new_era = previous_era.saturating_add(amount); + let new_era = previous_era.saturating_add(bump_era); RelayChainCurrentEra::::put(new_era); LastEraBumpedBlock::::put(T::RelayChainBlockNumber::current_block_number()); Self::deposit_event(Event::::CurrentEraBumped { new_era_index: new_era }); diff --git a/modules/xcm-interface/src/lib.rs b/modules/xcm-interface/src/lib.rs index 0f79b2a38..a945215b3 100644 --- a/modules/xcm-interface/src/lib.rs +++ b/modules/xcm-interface/src/lib.rs @@ -89,9 +89,9 @@ pub mod module { /// The interface to Cross-chain transfer. type XcmTransfer: XcmTransfer; - /// Self parachain location. + /// AssetHub location. #[pallet::constant] - type SelfLocation: Get; + type AssetHubLocation: Get; /// Convert AccountId to Location to build XCM message. type AccountIdToLocation: Convert; @@ -180,14 +180,22 @@ pub mod module { sub_account_index: u16, amount: Balance, ) -> DispatchResult { - T::XcmTransfer::transfer( + let result = T::XcmTransfer::transfer( sender.clone(), T::StakingCurrencyId::get(), amount, T::SovereignSubAccountLocationConvert::convert(sub_account_index), WeightLimit::Limited(Self::xcm_dest_weight_and_fee(XcmInterfaceOperation::XtokensTransfer).0), - ) - .map(|_| ()) + ); + + log::debug!( + target: "xcm-interface", + "sender {:?} send XCM to transfer staking currency {:?} to sub account {:?}, result: {:?}", + sender, amount, sub_account_index, result + ); + + ensure!(result.is_ok(), Error::::XcmFailed); + Ok(()) } /// Send XCM message to the assethub for sub account to withdraw_unbonded staking currency @@ -217,7 +225,7 @@ pub mod module { xcm_fee.saturating_mul(2), ); - let result = pallet_xcm::Pallet::::send_xcm(Here, Parent, xcm_message); + let result = pallet_xcm::Pallet::::send_xcm(Here, T::AssetHubLocation::get(), xcm_message); log::debug!( target: "xcm-interface", "subaccount {:?} send XCM to withdraw unbonded {:?}, result: {:?}", @@ -239,7 +247,7 @@ pub mod module { xcm_fee, xcm_dest_weight, ); - let result = pallet_xcm::Pallet::::send_xcm(Here, Parent, xcm_message); + let result = pallet_xcm::Pallet::::send_xcm(Here, T::AssetHubLocation::get(), xcm_message); log::debug!( target: "xcm-interface", "subaccount {:?} send XCM to bond {:?}, result: {:?}", @@ -261,7 +269,7 @@ pub mod module { xcm_fee, xcm_dest_weight, ); - let result = pallet_xcm::Pallet::::send_xcm(Here, Parent, xcm_message); + let result = pallet_xcm::Pallet::::send_xcm(Here, T::AssetHubLocation::get(), xcm_message); log::debug!( target: "xcm-interface", "subaccount {:?} send XCM to unbond {:?}, result: {:?}", @@ -283,7 +291,7 @@ pub mod module { xcm_fee, xcm_dest_weight, ); - let result = pallet_xcm::Pallet::::send_xcm(Here, Parent, xcm_message); + let result = pallet_xcm::Pallet::::send_xcm(Here, T::AssetHubLocation::get(), xcm_message); log::debug!( target: "xcm-interface", "subaccount {:?} send XCM to nominate {:?}, result: {:?}", diff --git a/modules/xcm-interface/src/mocks/mod.rs b/modules/xcm-interface/src/mocks/mod.rs index 1575ea287..ccbb20144 100644 --- a/modules/xcm-interface/src/mocks/mod.rs +++ b/modules/xcm-interface/src/mocks/mod.rs @@ -61,7 +61,8 @@ parameter_types! { pub const GetStakingCurrencyId: CurrencyId = DOT; pub const ParachainAccount: AccountId = AccountId32::new([0u8; 32]); pub const ParachainId: module_assethub::ParaId = module_assethub::ParaId::new(2000); - pub SelfLocation: Location = Location::new(1, Parachain(ParachainId::get().into())); + pub const AssetHubId: module_assethub::ParaId = module_assethub::ParaId::new(1000); + pub AssetHubLocation: Location = Location::new(1, Parachain(AssetHubId::get().into())); } pub struct SubAccountIndexLocationConvertor; @@ -275,7 +276,7 @@ macro_rules! impl_mock { type SovereignSubAccountLocationConvert = SubAccountIndexLocationConvertor; type AssetHubCallBuilder = module_assethub::AssetHubCallBuilder; type XcmTransfer = MockXcmTransfer; - type SelfLocation = SelfLocation; + type AssetHubLocation = AssetHubLocation; type AccountIdToLocation = AccountIdToLocation; } diff --git a/runtime/acala/src/lib.rs b/runtime/acala/src/lib.rs index 3e2cbc779..4d38b0299 100644 --- a/runtime/acala/src/lib.rs +++ b/runtime/acala/src/lib.rs @@ -1676,7 +1676,7 @@ impl module_xcm_interface::Config for Runtime { type SovereignSubAccountLocationConvert = SubAccountIndexLocationConvertor; type AssetHubCallBuilder = AssetHubCallBuilder; type XcmTransfer = XTokens; - type SelfLocation = xcm_config::SelfLocation; + type AssetHubLocation = xcm_config::AssetHubLocation; type AccountIdToLocation = runtime_common::xcm_config::AccountIdToLocation; } diff --git a/runtime/karura/src/lib.rs b/runtime/karura/src/lib.rs index a982682ff..52e6486f2 100644 --- a/runtime/karura/src/lib.rs +++ b/runtime/karura/src/lib.rs @@ -1701,7 +1701,7 @@ impl module_xcm_interface::Config for Runtime { type SovereignSubAccountLocationConvert = SubAccountIndexLocationConvertor; type AssetHubCallBuilder = AssetHubCallBuilder; type XcmTransfer = XTokens; - type SelfLocation = xcm_config::SelfLocation; + type AssetHubLocation = xcm_config::AssetHubLocation; type AccountIdToLocation = runtime_common::xcm_config::AccountIdToLocation; } diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index 4445cc913..a4184071e 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -1432,7 +1432,7 @@ pub fn create_x2_parachain_location(index: u16) -> Location { parameter_types! { pub HomaTreasuryAccount: AccountId = HomaTreasuryPalletId::get().into_account_truncating(); pub ActiveSubAccountsIndexList: Vec = vec![ - 0, // 15sr8Dvq3AT3Z2Z1y8FnQ4VipekAHhmQnrkgzegUr1tNgbcn + 0, // 12pw22Qyy3o28BLshjce9yrSMs3fhSiLsAjqLPAzGktbXYV7 ]; pub MintThreshold: Balance = dollar(DOT); pub RedeemThreshold: Balance = 10 * dollar(LDOT); @@ -1519,7 +1519,7 @@ impl module_xcm_interface::Config for Runtime { type SovereignSubAccountLocationConvert = SubAccountIndexLocationConvertor; type AssetHubCallBuilder = AssetHubCallBuilder; type XcmTransfer = XTokens; - type SelfLocation = xcm_config::SelfLocation; + type AssetHubLocation = xcm_config::AssetHubLocation; type AccountIdToLocation = xcm_config::AccountIdToLocation; } diff --git a/runtime/mandala/src/xcm_config.rs b/runtime/mandala/src/xcm_config.rs index 9f595aaff..580009a8e 100644 --- a/runtime/mandala/src/xcm_config.rs +++ b/runtime/mandala/src/xcm_config.rs @@ -17,10 +17,11 @@ // along with this program. If not, see . use super::{ - constants::fee::*, AccountId, AllPalletsWithSystem, AssetIdMapping, AssetIdMaps, Balance, Balances, Convert, - Currencies, CurrencyId, EvmAddressMapping, ExistentialDeposits, GetNativeCurrencyId, MessageQueue, - NativeTokenExistentialDeposit, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, - RuntimeOrigin, TreasuryAccount, UnknownTokens, XcmpQueue, ACA, + AccountId, AllPalletsWithSystem, AssetIdMapping, AssetIdMaps, Balance, Balances, Convert, Currencies, CurrencyId, + EvmAddressMapping, ExistentialDeposits, GetNativeCurrencyId, MessageQueue, NativeTokenExistentialDeposit, + ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, TreasuryAccount, + UnknownTokens, XcmpQueue, ACA, + {constants::fee::*, parachains}, }; pub use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; pub use frame_support::{ @@ -330,6 +331,7 @@ impl Convert for AccountIdToLocation { parameter_types! { pub SelfLocation: Location = Location::new(1, Parachain(ParachainInfo::get().into())); + pub AssetHubLocation: Location = Location::new(1, [Parachain(parachains::asset_hub_polkadot::ID)]); pub const BaseXcmWeight: XcmWeight = XcmWeight::from_parts(100_000_000, 0); pub const MaxAssetsForTransfer: usize = 2; } From 6cce1e2d4b1dd0123c85a2065f4766be99167c4b Mon Sep 17 00:00:00 2001 From: zjb0807 Date: Wed, 16 Jul 2025 10:50:57 +0800 Subject: [PATCH 09/12] Apply suggestions Co-authored-by: Xiliang Chen --- modules/assethub/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/assethub/src/lib.rs b/modules/assethub/src/lib.rs index 50295c9eb..b17722855 100644 --- a/modules/assethub/src/lib.rs +++ b/modules/assethub/src/lib.rs @@ -185,7 +185,7 @@ where }, RefundSurplus, DepositAsset { - assets: AllCounted(1).into(), // there is only 1 asset on assethub + assets: AllCounted(1).into(), beneficiary: Location { parents: 0, interior: Parachain(ParachainId::get().into()).into(), From f00bb91fb1fcc5f46bcb3576835a904078b08426 Mon Sep 17 00:00:00 2001 From: zjb0807 Date: Fri, 18 Jul 2025 15:05:08 +0800 Subject: [PATCH 10/12] use pallet xcm XcmExecutor instead of xtokens --- modules/assethub/src/lib.rs | 39 ++++++++++++- modules/support/src/assethub.rs | 12 ++++ modules/xcm-interface/Cargo.toml | 2 + modules/xcm-interface/src/lib.rs | 72 ++++++++++++++---------- modules/xcm-interface/src/mocks/mod.rs | 78 ++------------------------ runtime/acala/src/lib.rs | 33 +++-------- runtime/karura/src/lib.rs | 33 +++-------- runtime/mandala/src/lib.rs | 33 +++-------- 8 files changed, 124 insertions(+), 178 deletions(-) diff --git a/modules/assethub/src/lib.rs b/modules/assethub/src/lib.rs index b17722855..c9ce2c304 100644 --- a/modules/assethub/src/lib.rs +++ b/modules/assethub/src/lib.rs @@ -167,6 +167,43 @@ where AHC::proxy(ProxyCall::Proxy(AssetHubLookup::unlookup(real), None, call)) } + fn finalize_transfer_asset_xcm_message( + to: Self::AssetHubAccountId, + amount: Self::Balance, + reserve: Location, + weight: XcmWeight, + ) -> Xcm<()> { + let asset = Asset { + id: AssetId(Location::parent()), + fun: Fungibility::Fungible(amount), + }; + Xcm(vec![ + WithdrawAsset(asset.clone().into()), + SetFeesMode { jit_withdraw: true }, + InitiateReserveWithdraw { + assets: All.into(), + reserve: reserve, + xcm: Xcm(vec![ + BuyExecution { + fees: asset, + weight_limit: Limited(weight), + }, + DepositAsset { + assets: AllCounted(1).into(), + beneficiary: Location { + parents: 0, + interior: AccountId32 { + network: None, + id: to.into(), + } + .into(), + }, + }, + ]), + }, + ]) + } + fn finalize_call_into_xcm_message(call: AHC, extra_fee: Self::Balance, weight: XcmWeight) -> Xcm<()> { let asset = Asset { id: AssetId(Location::parent()), @@ -221,7 +258,7 @@ where vec![ RefundSurplus, DepositAsset { - assets: AllCounted(1).into(), // there is only 1 asset on assethub + assets: AllCounted(1).into(), beneficiary: Location { parents: 0, interior: Parachain(ParachainId::get().into()).into(), diff --git a/modules/support/src/assethub.rs b/modules/support/src/assethub.rs index 36a239b50..b76a2b294 100644 --- a/modules/support/src/assethub.rs +++ b/modules/support/src/assethub.rs @@ -137,6 +137,18 @@ pub trait CallBuilder { /// - call: The call to be executed. fn proxy_call(real: Self::AssetHubAccountId, call: Self::AssetHubCall) -> Self::AssetHubCall; + /// Wrap the final transfer asset into the Xcm format. + /// params: + /// - to: The destination account. + /// - amount: The amount of staking currency to be transferred. + /// - weight: the weight limit used for XCM. + fn finalize_transfer_asset_xcm_message( + to: Self::AssetHubAccountId, + amount: Self::Balance, + reserve: Location, + weight: XcmWeight, + ) -> Xcm<()>; + /// Wrap the final call into the Xcm format. /// params: /// - call: The call to be executed diff --git a/modules/xcm-interface/Cargo.toml b/modules/xcm-interface/Cargo.toml index d606d4844..4cbdaa1fe 100644 --- a/modules/xcm-interface/Cargo.toml +++ b/modules/xcm-interface/Cargo.toml @@ -16,6 +16,7 @@ sp-core = { workspace = true } sp-std = { workspace = true } pallet-xcm = { workspace = true } xcm = { workspace = true } +xcm-executor = { workspace = true } primitives = { workspace = true } orml-traits = { workspace = true } module-support = { workspace = true } @@ -47,6 +48,7 @@ std = [ "sp-runtime/std", "sp-std/std", "xcm/std", + "xcm-executor/std" ] runtime-benchmarks = [ "frame-benchmarking", diff --git a/modules/xcm-interface/src/lib.rs b/modules/xcm-interface/src/lib.rs index a945215b3..39761c5c7 100644 --- a/modules/xcm-interface/src/lib.rs +++ b/modules/xcm-interface/src/lib.rs @@ -30,25 +30,28 @@ use frame_support::{pallet_prelude::*, traits::Get}; use frame_system::pallet_prelude::*; use module_support::{assethub::CallBuilder, HomaSubAccountXcm}; -use orml_traits::XcmTransfer; -use primitives::{Balance, CurrencyId, EraIndex}; +use primitives::{Balance, EraIndex}; use scale_info::TypeInfo; +use sp_core::hashing; use sp_runtime::traits::Convert; use sp_std::{convert::From, prelude::*, vec, vec::Vec}; use xcm::{prelude::*, v3::Weight as XcmWeight}; +use xcm_executor::traits::WeightBounds; mod mocks; pub use module::*; +const LOG_TARGET: &str = "xcm-interface"; + #[frame_support::pallet] pub mod module { use super::*; #[derive(Encode, Decode, Eq, PartialEq, Clone, RuntimeDebug, TypeInfo)] pub enum XcmInterfaceOperation { - // XTokens - XtokensTransfer, + // PalletXcm transfer + XcmTransfer, // Homa HomaWithdrawUnbonded, HomaBondExtra, @@ -67,10 +70,6 @@ pub mod module { /// Origin represented Governance type UpdateOrigin: EnsureOrigin<::RuntimeOrigin>; - /// The currency id of the Staking asset - #[pallet::constant] - type StakingCurrencyId: Get; - /// The account of parachain on the assethub. #[pallet::constant] type ParachainAccount: Get; @@ -79,16 +78,13 @@ pub mod module { #[pallet::constant] type AssetHubUnbondingSlashingSpans: Get; - /// The convert for convert sovereign subacocunt index to the Location where the + /// The convert for convert sovereign subacocunt index to the account where the /// staking currencies are sent to. - type SovereignSubAccountLocationConvert: Convert; + type SovereignSubAccountIdConvert: Convert; /// The Call builder for communicating with AssetHub via XCM messaging. type AssetHubCallBuilder: CallBuilder; - /// The interface to Cross-chain transfer. - type XcmTransfer: XcmTransfer; - /// AssetHub location. #[pallet::constant] type AssetHubLocation: Get; @@ -180,21 +176,39 @@ pub mod module { sub_account_index: u16, amount: Balance, ) -> DispatchResult { - let result = T::XcmTransfer::transfer( - sender.clone(), - T::StakingCurrencyId::get(), - amount, - T::SovereignSubAccountLocationConvert::convert(sub_account_index), - WeightLimit::Limited(Self::xcm_dest_weight_and_fee(XcmInterfaceOperation::XtokensTransfer).0), - ); + let (xcm_dest_weight, _xcm_fee) = Self::xcm_dest_weight_and_fee(XcmInterfaceOperation::XcmTransfer); + let to = T::SovereignSubAccountIdConvert::convert(sub_account_index); + let reserve = T::AssetHubLocation::get(); + + let mut xcm_message = + T::AssetHubCallBuilder::finalize_transfer_asset_xcm_message(to, amount, reserve, xcm_dest_weight) + .into(); + + let origin_location = T::AccountIdToLocation::convert(sender.clone()); + let mut hash = xcm_message.using_encoded(hashing::blake2_256); + let weight = T::Weigher::weight(&mut xcm_message).map_err(|e| { + log::error!( + target: LOG_TARGET, + "failed to weigh XCM message: {:?}", e + ); + Error::::XcmFailed + })?; log::debug!( - target: "xcm-interface", - "sender {:?} send XCM to transfer staking currency {:?} to sub account {:?}, result: {:?}", - sender, amount, sub_account_index, result + target: LOG_TARGET, + "origin_location {:?} send XCM to transfer staking currency {:?} to subaccount {:?}, message: {:?}", + origin_location, amount, sub_account_index, xcm_message ); + T::XcmExecutor::prepare_and_execute(origin_location, xcm_message, &mut hash, weight, weight) + .ensure_complete() + .map_err(|e| { + log::error!( + target: LOG_TARGET, + "XcmExecutor failed to execute XCM message: {:?}", e + ); + Error::::XcmFailed + })?; - ensure!(result.is_ok(), Error::::XcmFailed); Ok(()) } @@ -227,7 +241,7 @@ pub mod module { let result = pallet_xcm::Pallet::::send_xcm(Here, T::AssetHubLocation::get(), xcm_message); log::debug!( - target: "xcm-interface", + target: LOG_TARGET, "subaccount {:?} send XCM to withdraw unbonded {:?}, result: {:?}", sub_account_index, amount, result ); @@ -249,7 +263,7 @@ pub mod module { ); let result = pallet_xcm::Pallet::::send_xcm(Here, T::AssetHubLocation::get(), xcm_message); log::debug!( - target: "xcm-interface", + target: LOG_TARGET, "subaccount {:?} send XCM to bond {:?}, result: {:?}", sub_account_index, amount, result, ); @@ -271,7 +285,7 @@ pub mod module { ); let result = pallet_xcm::Pallet::::send_xcm(Here, T::AssetHubLocation::get(), xcm_message); log::debug!( - target: "xcm-interface", + target: LOG_TARGET, "subaccount {:?} send XCM to unbond {:?}, result: {:?}", sub_account_index, amount, result ); @@ -293,7 +307,7 @@ pub mod module { ); let result = pallet_xcm::Pallet::::send_xcm(Here, T::AssetHubLocation::get(), xcm_message); log::debug!( - target: "xcm-interface", + target: LOG_TARGET, "subaccount {:?} send XCM to nominate {:?}, result: {:?}", sub_account_index, targets, result ); @@ -304,7 +318,7 @@ pub mod module { /// The fee of cross-chain transfer is deducted from the recipient. fn get_xcm_transfer_fee() -> Balance { - Self::xcm_dest_weight_and_fee(XcmInterfaceOperation::XtokensTransfer).1 + Self::xcm_dest_weight_and_fee(XcmInterfaceOperation::XcmTransfer).1 } /// The fee of parachain transfer. diff --git a/modules/xcm-interface/src/mocks/mod.rs b/modules/xcm-interface/src/mocks/mod.rs index ccbb20144..fc06813a7 100644 --- a/modules/xcm-interface/src/mocks/mod.rs +++ b/modules/xcm-interface/src/mocks/mod.rs @@ -58,82 +58,16 @@ ord_parameter_types! { } parameter_types! { - pub const GetStakingCurrencyId: CurrencyId = DOT; pub const ParachainAccount: AccountId = AccountId32::new([0u8; 32]); pub const ParachainId: module_assethub::ParaId = module_assethub::ParaId::new(2000); pub const AssetHubId: module_assethub::ParaId = module_assethub::ParaId::new(1000); pub AssetHubLocation: Location = Location::new(1, Parachain(AssetHubId::get().into())); } -pub struct SubAccountIndexLocationConvertor; -impl Convert for SubAccountIndexLocationConvertor { - fn convert(_sub_account_index: u16) -> Location { - (Parent, Parachain(2000)).into() - } -} - -pub struct MockXcmTransfer; -impl XcmTransfer for MockXcmTransfer { - fn transfer( - _who: AccountId, - _currency_id: CurrencyId, - _amount: Balance, - _dest: Location, - _dest_weight_limit: WeightLimit, - ) -> Result, DispatchError> { - unimplemented!() - } - - /// Transfer `Asset` - fn transfer_multiasset( - _who: AccountId, - _asset: Asset, - _dest: Location, - _dest_weight_limit: WeightLimit, - ) -> Result, DispatchError> { - unimplemented!() - } - - fn transfer_with_fee( - _who: AccountId, - _currency_id: CurrencyId, - _amount: Balance, - _fee: Balance, - _dest: Location, - _dest_weight_limit: WeightLimit, - ) -> Result, DispatchError> { - unimplemented!() - } - - /// Transfer `AssetWithFee` - fn transfer_multiasset_with_fee( - _who: AccountId, - _asset: Asset, - _fee: Asset, - _dest: Location, - _dest_weight_limit: WeightLimit, - ) -> Result, DispatchError> { - unimplemented!() - } - - fn transfer_multicurrencies( - _who: AccountId, - _currencies: Vec<(CurrencyId, Balance)>, - _fee_item: u32, - _dest: Location, - _dest_weight_limit: WeightLimit, - ) -> Result, DispatchError> { - unimplemented!() - } - - fn transfer_multiassets( - _who: AccountId, - _assets: Assets, - _fee: Asset, - _dest: Location, - _dest_weight_limit: WeightLimit, - ) -> Result, DispatchError> { - unimplemented!() +pub struct SubAccountIndexAccountIdConvertor; +impl Convert for SubAccountIndexAccountIdConvertor { + fn convert(_sub_account_index: u16) -> AccountId { + AccountId32::new([1u8; 32]) } } @@ -270,12 +204,10 @@ macro_rules! impl_mock { impl Config for Runtime { type RuntimeEvent = RuntimeEvent; type UpdateOrigin = EnsureSignedBy; - type StakingCurrencyId = GetStakingCurrencyId; type ParachainAccount = ParachainAccount; type AssetHubUnbondingSlashingSpans = ConstU32<28>; - type SovereignSubAccountLocationConvert = SubAccountIndexLocationConvertor; + type SovereignSubAccountIdConvert = SubAccountIndexAccountIdConvertor; type AssetHubCallBuilder = module_assethub::AssetHubCallBuilder; - type XcmTransfer = MockXcmTransfer; type AssetHubLocation = AssetHubLocation; type AccountIdToLocation = AccountIdToLocation; } diff --git a/runtime/acala/src/lib.rs b/runtime/acala/src/lib.rs index 4d38b0299..967731b8d 100644 --- a/runtime/acala/src/lib.rs +++ b/runtime/acala/src/lib.rs @@ -114,7 +114,6 @@ use runtime_common::{ Rate, Ratio, RuntimeBlockLength, RuntimeBlockWeights, TechnicalCommitteeInstance, TechnicalCommitteeMembershipInstance, TimeStampedPrice, TipPerWeightStep, ACA, AUSD, DOT, LCDOT, LDOT, TAP, }; -use xcm::v4::prelude::*; mod authority; mod benchmarking; @@ -1639,27 +1638,13 @@ impl module_nominees_election::Config for Runtime { type WeightInfo = weights::module_nominees_election::WeightInfo; } -pub fn create_x2_parachain_location(index: u16) -> Location { - Location::new( - 1, - [ - Parachain(parachains::asset_hub_polkadot::ID), - AccountId32 { - network: None, - id: Utility::derivative_account_id( - Sibling::from(ParachainInfo::get()).into_account_truncating(), - index, - ) - .into(), - }, - ], - ) -} - -pub struct SubAccountIndexLocationConvertor; -impl Convert for SubAccountIndexLocationConvertor { - fn convert(sub_account_index: u16) -> Location { - create_x2_parachain_location(sub_account_index) +pub struct SubAccountIndexAccountIdConvertor; +impl Convert for SubAccountIndexAccountIdConvertor { + fn convert(sub_account_index: u16) -> AccountId { + Utility::derivative_account_id( + Sibling::from(ParachainInfo::get()).into_account_truncating(), + sub_account_index, + ) } } @@ -1670,12 +1655,10 @@ parameter_types! { impl module_xcm_interface::Config for Runtime { type RuntimeEvent = RuntimeEvent; type UpdateOrigin = EnsureRootOrHalfGeneralCouncil; - type StakingCurrencyId = GetStakingCurrencyId; type ParachainAccount = ParachainAccount; type AssetHubUnbondingSlashingSpans = ConstU32<5>; - type SovereignSubAccountLocationConvert = SubAccountIndexLocationConvertor; + type SovereignSubAccountIdConvert = SubAccountIndexAccountIdConvertor; type AssetHubCallBuilder = AssetHubCallBuilder; - type XcmTransfer = XTokens; type AssetHubLocation = xcm_config::AssetHubLocation; type AccountIdToLocation = runtime_common::xcm_config::AccountIdToLocation; } diff --git a/runtime/karura/src/lib.rs b/runtime/karura/src/lib.rs index 52e6486f2..63f6e238a 100644 --- a/runtime/karura/src/lib.rs +++ b/runtime/karura/src/lib.rs @@ -115,7 +115,6 @@ use runtime_common::{ Rate, Ratio, RuntimeBlockLength, RuntimeBlockWeights, TechnicalCommitteeInstance, TechnicalCommitteeMembershipInstance, TimeStampedPrice, TipPerWeightStep, KAR, KSM, KUSD, LKSM, TAI, }; -use xcm::v4::prelude::*; /// Import the stable_asset pallet. pub use nutsfinance_stable_asset; @@ -1664,27 +1663,13 @@ impl module_nominees_election::Config for Runtime { type WeightInfo = weights::module_nominees_election::WeightInfo; } -pub fn create_x2_parachain_location(index: u16) -> Location { - Location::new( - 1, - [ - Parachain(parachains::asset_hub_kusama::ID), - AccountId32 { - network: None, - id: Utility::derivative_account_id( - Sibling::from(ParachainInfo::get()).into_account_truncating(), - index, - ) - .into(), - }, - ], - ) -} - -pub struct SubAccountIndexLocationConvertor; -impl Convert for SubAccountIndexLocationConvertor { - fn convert(sub_account_index: u16) -> Location { - create_x2_parachain_location(sub_account_index) +pub struct SubAccountIndexAccountIdConvertor; +impl Convert for SubAccountIndexAccountIdConvertor { + fn convert(sub_account_index: u16) -> AccountId { + Utility::derivative_account_id( + Sibling::from(ParachainInfo::get()).into_account_truncating(), + sub_account_index, + ) } } @@ -1695,12 +1680,10 @@ parameter_types! { impl module_xcm_interface::Config for Runtime { type RuntimeEvent = RuntimeEvent; type UpdateOrigin = EnsureRootOrHalfGeneralCouncil; - type StakingCurrencyId = GetStakingCurrencyId; type ParachainAccount = ParachainAccount; type AssetHubUnbondingSlashingSpans = ConstU32<5>; - type SovereignSubAccountLocationConvert = SubAccountIndexLocationConvertor; + type SovereignSubAccountIdConvert = SubAccountIndexAccountIdConvertor; type AssetHubCallBuilder = AssetHubCallBuilder; - type XcmTransfer = XTokens; type AssetHubLocation = xcm_config::AssetHubLocation; type AccountIdToLocation = runtime_common::xcm_config::AccountIdToLocation; } diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index a4184071e..3afc5db0e 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -115,7 +115,6 @@ use runtime_common::{ Rate, Ratio, RuntimeBlockLength, RuntimeBlockWeights, TechnicalCommitteeInstance, TechnicalCommitteeMembershipInstance, TimeStampedPrice, TipPerWeightStep, ACA, AUSD, DOT, KSM, LCDOT, LDOT, }; -use xcm::prelude::*; /// Import the stable_asset pallet. pub use nutsfinance_stable_asset; @@ -1412,23 +1411,6 @@ parameter_types! { pub DefaultExchangeRate: ExchangeRate = ExchangeRate::saturating_from_rational(10, 100); // 1 : 10 } -pub fn create_x2_parachain_location(index: u16) -> Location { - Location::new( - 1, - [ - Parachain(parachains::asset_hub_polkadot::ID), - AccountId32 { - network: None, - id: Utility::derivative_account_id( - Sibling::from(ParachainInfo::get()).into_account_truncating(), - index, - ) - .into(), - }, - ], - ) -} - parameter_types! { pub HomaTreasuryAccount: AccountId = HomaTreasuryPalletId::get().into_account_truncating(); pub ActiveSubAccountsIndexList: Vec = vec![ @@ -1503,22 +1485,23 @@ parameter_types! { pub ParachainAccount: AccountId = Sibling::from(ParachainInfo::get()).into_account_truncating(); } -pub struct SubAccountIndexLocationConvertor; -impl Convert for SubAccountIndexLocationConvertor { - fn convert(sub_account_index: u16) -> Location { - create_x2_parachain_location(sub_account_index) +pub struct SubAccountIndexAccountIdConvertor; +impl Convert for SubAccountIndexAccountIdConvertor { + fn convert(sub_account_index: u16) -> AccountId { + Utility::derivative_account_id( + Sibling::from(ParachainInfo::get()).into_account_truncating(), + sub_account_index, + ) } } impl module_xcm_interface::Config for Runtime { type RuntimeEvent = RuntimeEvent; type UpdateOrigin = EnsureRootOrHalfGeneralCouncil; - type StakingCurrencyId = GetStakingCurrencyId; type ParachainAccount = ParachainAccount; type AssetHubUnbondingSlashingSpans = ConstU32<5>; - type SovereignSubAccountLocationConvert = SubAccountIndexLocationConvertor; + type SovereignSubAccountIdConvert = SubAccountIndexAccountIdConvertor; type AssetHubCallBuilder = AssetHubCallBuilder; - type XcmTransfer = XTokens; type AssetHubLocation = xcm_config::AssetHubLocation; type AccountIdToLocation = xcm_config::AccountIdToLocation; } From d829cb03e34b33c73dfe972a1fe5730b9e0ace2d Mon Sep 17 00:00:00 2001 From: zjb0807 Date: Fri, 18 Jul 2025 15:08:24 +0800 Subject: [PATCH 11/12] fix --- modules/assethub/src/lib.rs | 2 +- modules/support/src/assethub.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/assethub/src/lib.rs b/modules/assethub/src/lib.rs index c9ce2c304..b2f5d470d 100644 --- a/modules/assethub/src/lib.rs +++ b/modules/assethub/src/lib.rs @@ -182,7 +182,7 @@ where SetFeesMode { jit_withdraw: true }, InitiateReserveWithdraw { assets: All.into(), - reserve: reserve, + reserve, xcm: Xcm(vec![ BuyExecution { fees: asset, diff --git a/modules/support/src/assethub.rs b/modules/support/src/assethub.rs index b76a2b294..17952d989 100644 --- a/modules/support/src/assethub.rs +++ b/modules/support/src/assethub.rs @@ -141,6 +141,7 @@ pub trait CallBuilder { /// params: /// - to: The destination account. /// - amount: The amount of staking currency to be transferred. + /// - reserve: The reserve location. /// - weight: the weight limit used for XCM. fn finalize_transfer_asset_xcm_message( to: Self::AssetHubAccountId, From c70f7ff99cd00efa168da5113242fa186b214f7a Mon Sep 17 00:00:00 2001 From: zjb0807 Date: Fri, 18 Jul 2025 15:27:38 +0800 Subject: [PATCH 12/12] fix --- Cargo.lock | 2 - modules/xcm-interface/Cargo.toml | 3 -- modules/xcm-interface/src/mocks/mod.rs | 8 +--- runtime/integration-tests/src/runtime.rs | 28 ++---------- runtime/integration-tests/src/setup.rs | 58 ++++++++++++------------ 5 files changed, 35 insertions(+), 64 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7ae7c8f04..a36315b3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4190,8 +4190,6 @@ dependencies = [ "module-assethub", "module-currencies", "module-support", - "orml-tokens", - "orml-traits", "pallet-balances", "pallet-xcm", "parity-scale-codec", diff --git a/modules/xcm-interface/Cargo.toml b/modules/xcm-interface/Cargo.toml index 4cbdaa1fe..9944a5d84 100644 --- a/modules/xcm-interface/Cargo.toml +++ b/modules/xcm-interface/Cargo.toml @@ -18,7 +18,6 @@ pallet-xcm = { workspace = true } xcm = { workspace = true } xcm-executor = { workspace = true } primitives = { workspace = true } -orml-traits = { workspace = true } module-support = { workspace = true } [dev-dependencies] @@ -28,7 +27,6 @@ pallet-balances = { workspace = true, features = ["std"] } sp-io = { workspace = true, features = ["std"] } xcm-builder = { workspace = true, features = ["std"] } xcm-executor = { workspace = true, features = ["std"] } -orml-tokens = { workspace = true, features = ["std"] } module-currencies = { workspace = true, features = ["std"] } module-assethub = { workspace = true, features = ["std"] } @@ -40,7 +38,6 @@ std = [ "frame-support/std", "frame-system/std", "module-support/std", - "orml-traits/std", "pallet-xcm/std", "primitives/std", "scale-info/std", diff --git a/modules/xcm-interface/src/mocks/mod.rs b/modules/xcm-interface/src/mocks/mod.rs index fc06813a7..448e59ace 100644 --- a/modules/xcm-interface/src/mocks/mod.rs +++ b/modules/xcm-interface/src/mocks/mod.rs @@ -25,8 +25,6 @@ use frame_support::{ traits::{ConstU128, ConstU32, Everything, Nothing}, }; use frame_system::{EnsureRoot, EnsureSignedBy}; -use orml_traits::xcm_transfer::Transferred; -use primitives::{CurrencyId, TokenSymbol}; use sp_runtime::{traits::IdentityLookup, AccountId32, BuildStorage}; use xcm_builder::{EnsureXcmOrigin, FixedWeightBounds, SignedToAccountId32}; use xcm_executor::traits::XcmAssetTransfers; @@ -37,8 +35,6 @@ pub mod polkadot; pub type AccountId = AccountId32; pub const ALICE: AccountId = AccountId32::new([1u8; 32]); -pub const BOB: AccountId = AccountId32::new([2u8; 32]); -pub const DOT: CurrencyId = CurrencyId::Token(TokenSymbol::DOT); parameter_types! { pub const UnitWeightCost: XcmWeight = XcmWeight::from_parts(10, 10); @@ -65,9 +61,9 @@ parameter_types! { } pub struct SubAccountIndexAccountIdConvertor; -impl Convert for SubAccountIndexAccountIdConvertor { +impl Convert for SubAccountIndexAccountIdConvertor { fn convert(_sub_account_index: u16) -> AccountId { - AccountId32::new([1u8; 32]) + AccountId::new([1u8; 32]) } } diff --git a/runtime/integration-tests/src/runtime.rs b/runtime/integration-tests/src/runtime.rs index a823f415c..5cb74d80b 100644 --- a/runtime/integration-tests/src/runtime.rs +++ b/runtime/integration-tests/src/runtime.rs @@ -304,32 +304,12 @@ fn parachain_subaccounts_are_unique() { ); assert_eq!( - create_x2_parachain_location(0), - Location::new( - 1, - [ - Parachain(1000), - Junction::AccountId32 { - network: None, - id: hex_literal::hex!["50ca9b6bf6c83ca2a918b9861788d6facd26e5fd78a07f9848070697683745b3"] - .into(), - } - ] - ), + SubAccountIndexAccountIdConvertor::convert(0), + hex_literal::hex!["50ca9b6bf6c83ca2a918b9861788d6facd26e5fd78a07f9848070697683745b3"].into() ); assert_eq!( - create_x2_parachain_location(1), - Location::new( - 1, - [ - Parachain(1000), - Junction::AccountId32 { - network: None, - id: hex_literal::hex!["025f1ca0b76b0d646f33b799a040df9fc14e06b7486770656766e8e8381f6c6f"] - .into(), - } - ] - ), + SubAccountIndexAccountIdConvertor::convert(1), + hex_literal::hex!["025f1ca0b76b0d646f33b799a040df9fc14e06b7486770656766e8e8381f6c6f"].into() ); }); } diff --git a/runtime/integration-tests/src/setup.rs b/runtime/integration-tests/src/setup.rs index d5dc72b71..3ec410d11 100644 --- a/runtime/integration-tests/src/setup.rs +++ b/runtime/integration-tests/src/setup.rs @@ -60,17 +60,17 @@ mod mandala_imports { pub use mandala_runtime::xcm_config::*; use mandala_runtime::AlternativeFeeSurplus; pub use mandala_runtime::{ - create_x2_parachain_location, get_all_module_accounts, AcalaOracle, AcalaSwap, AccountId, AggregatedDex, - AssetRegistry, AuctionManager, Aura, AuraExt, Authority, AuthoritysOriginId, Authorship, Balance, Balances, - BlockNumber, CDPEnginePalletId, CDPTreasuryPalletId, CdpEngine, CdpTreasury, CollatorSelection, - CreateClassDeposit, CreateTokenDeposit, Currencies, CurrencyId, DataDepositPerByte, DealWithFees, - DefaultDebitExchangeRate, DefaultExchangeRate, Dex, EmergencyShutdown, EvmAccounts, ExistentialDeposits, - FinancialCouncil, GetNativeCurrencyId, Homa, Honzon, IdleScheduler, Loans, MinRewardDistributeAmount, - MinimumDebitValue, NativeTokenExistentialDeposit, NftPalletId, OneDay, OriginCaller, ParachainInfo, - ParachainSystem, Proxy, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, Scheduler, Session, SessionKeys, - SessionManager, SevenDays, StableAsset, StableAssetPalletId, System, Timestamp, TokenSymbol, Tokens, - TransactionPayment, TransactionPaymentPalletId, TreasuryAccount, TreasuryPalletId, UncheckedExtrinsic, Utility, - Vesting, XcmInterface, EVM, NFT, + get_all_module_accounts, AcalaOracle, AcalaSwap, AccountId, AggregatedDex, AssetRegistry, AuctionManager, Aura, + AuraExt, Authority, AuthoritysOriginId, Authorship, Balance, Balances, BlockNumber, CDPEnginePalletId, + CDPTreasuryPalletId, CdpEngine, CdpTreasury, CollatorSelection, CreateClassDeposit, CreateTokenDeposit, + Currencies, CurrencyId, DataDepositPerByte, DealWithFees, DefaultDebitExchangeRate, DefaultExchangeRate, Dex, + EmergencyShutdown, EvmAccounts, ExistentialDeposits, FinancialCouncil, GetNativeCurrencyId, Homa, Honzon, + IdleScheduler, Loans, MinRewardDistributeAmount, MinimumDebitValue, NativeTokenExistentialDeposit, NftPalletId, + OneDay, OriginCaller, ParachainInfo, ParachainSystem, Proxy, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, + Scheduler, Session, SessionKeys, SessionManager, SevenDays, StableAsset, StableAssetPalletId, + SubAccountIndexAccountIdConvertor, System, Timestamp, TokenSymbol, Tokens, TransactionPayment, + TransactionPaymentPalletId, TreasuryAccount, TreasuryPalletId, UncheckedExtrinsic, Utility, Vesting, + XcmInterface, EVM, NFT, }; use primitives::TradingPair; use runtime_common::{ACA, AUSD, DOT, LDOT}; @@ -106,16 +106,17 @@ mod karura_imports { pub use karura_runtime::xcm_config::*; use karura_runtime::AlternativeFeeSurplus; pub use karura_runtime::{ - constants::parachains, create_x2_parachain_location, get_all_module_accounts, AcalaOracle, AcalaSwap, - AccountId, AggregatedDex, AssetRegistry, AuctionManager, Aura, AuraExt, Authority, AuthoritysOriginId, Balance, - Balances, BlockNumber, CDPEnginePalletId, CDPTreasuryPalletId, CdpEngine, CdpTreasury, CreateClassDeposit, - CreateTokenDeposit, Currencies, CurrencyId, DataDepositPerByte, DefaultDebitExchangeRate, DefaultExchangeRate, - Dex, EmergencyShutdown, EvmAccounts, ExistentialDeposits, FinancialCouncil, GetNativeCurrencyId, Homa, Honzon, + constants::parachains, get_all_module_accounts, AcalaOracle, AcalaSwap, AccountId, AggregatedDex, + AssetRegistry, AuctionManager, Aura, AuraExt, Authority, AuthoritysOriginId, Balance, Balances, BlockNumber, + CDPEnginePalletId, CDPTreasuryPalletId, CdpEngine, CdpTreasury, CreateClassDeposit, CreateTokenDeposit, + Currencies, CurrencyId, DataDepositPerByte, DefaultDebitExchangeRate, DefaultExchangeRate, Dex, + EmergencyShutdown, EvmAccounts, ExistentialDeposits, FinancialCouncil, GetNativeCurrencyId, Homa, Honzon, IdleScheduler, KaruraFoundationAccounts, Loans, MinimumDebitValue, NativeTokenExistentialDeposit, NftPalletId, OneDay, OriginCaller, ParachainAccount, ParachainInfo, ParachainSystem, PolkadotXcm, Proxy, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, Scheduler, Session, SessionManager, SevenDays, StableAsset, - StableAssetPalletId, System, Timestamp, TokenSymbol, Tokens, TransactionPayment, TransactionPaymentPalletId, - TreasuryPalletId, Utility, Vesting, XTokens, XcmInterface, EVM, NFT, + StableAssetPalletId, SubAccountIndexAccountIdConvertor, System, Timestamp, TokenSymbol, Tokens, + TransactionPayment, TransactionPaymentPalletId, TreasuryPalletId, Utility, Vesting, XTokens, XcmInterface, EVM, + NFT, }; use primitives::TradingPair; use runtime_common::{KAR, KSM, KUSD, LKSM}; @@ -150,17 +151,16 @@ mod acala_imports { pub use acala_runtime::xcm_config::*; use acala_runtime::AlternativeFeeSurplus; pub use acala_runtime::{ - constants::parachains, create_x2_parachain_location, get_all_module_accounts, AcalaFoundationAccounts, - AcalaOracle, AcalaSwap, AccountId, AggregatedDex, AssetRegistry, AuctionManager, Aura, AuraExt, Authority, - AuthoritysOriginId, Balance, Balances, BlockNumber, CDPEnginePalletId, CDPTreasuryPalletId, CdpEngine, - CdpTreasury, CreateClassDeposit, CreateTokenDeposit, Currencies, CurrencyId, DataDepositPerByte, - DefaultDebitExchangeRate, DefaultExchangeRate, Dex, EmergencyShutdown, EvmAccounts, ExistentialDeposits, - FinancialCouncil, GetNativeCurrencyId, Homa, Honzon, IdleScheduler, Loans, MinimumDebitValue, - NativeTokenExistentialDeposit, NftPalletId, OneDay, OriginCaller, ParachainAccount, ParachainInfo, - ParachainSystem, PolkadotXcm, Proxy, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, Scheduler, Session, - SessionManager, SevenDays, StableAsset, StableAssetPalletId, System, Timestamp, TokenSymbol, Tokens, - TransactionPayment, TransactionPaymentPalletId, TreasuryPalletId, Utility, Vesting, XTokens, XcmInterface, EVM, - NFT, + constants::parachains, get_all_module_accounts, AcalaFoundationAccounts, AcalaOracle, AcalaSwap, AccountId, + AggregatedDex, AssetRegistry, AuctionManager, Aura, AuraExt, Authority, AuthoritysOriginId, Balance, Balances, + BlockNumber, CDPEnginePalletId, CDPTreasuryPalletId, CdpEngine, CdpTreasury, CreateClassDeposit, + CreateTokenDeposit, Currencies, CurrencyId, DataDepositPerByte, DefaultDebitExchangeRate, DefaultExchangeRate, + Dex, EmergencyShutdown, EvmAccounts, ExistentialDeposits, FinancialCouncil, GetNativeCurrencyId, Homa, Honzon, + IdleScheduler, Loans, MinimumDebitValue, NativeTokenExistentialDeposit, NftPalletId, OneDay, OriginCaller, + ParachainAccount, ParachainInfo, ParachainSystem, PolkadotXcm, Proxy, Runtime, RuntimeCall, RuntimeEvent, + RuntimeOrigin, Scheduler, Session, SessionManager, SevenDays, StableAsset, StableAssetPalletId, + SubAccountIndexAccountIdConvertor, System, Timestamp, TokenSymbol, Tokens, TransactionPayment, + TransactionPaymentPalletId, TreasuryPalletId, Utility, Vesting, XTokens, XcmInterface, EVM, NFT, }; use frame_support::parameter_types; use primitives::TradingPair;