From 804c898fb3d4437efd277207435141ec770a9de3 Mon Sep 17 00:00:00 2001 From: Guantong Date: Tue, 21 Mar 2023 12:44:35 +0800 Subject: [PATCH] Remove xcmTransactor from Pangoro --- Cargo.lock | 26 --- Cargo.toml | 2 - runtime/pangoro/Cargo.toml | 2 - runtime/pangoro/src/lib.rs | 1 - runtime/pangoro/src/pallets/polkadot_xcm.rs | 181 +------------------- 5 files changed, 1 insertion(+), 211 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2e2274521..0d3d27673 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6846,7 +6846,6 @@ dependencies = [ "orml-utilities", "parity-scale-codec", "scale-info", - "serde", "sp-core", "sp-io", "sp-runtime", @@ -6862,7 +6861,6 @@ dependencies = [ "frame-support", "parity-scale-codec", "scale-info", - "serde", "sp-io", "sp-runtime", "sp-std", @@ -8114,29 +8112,6 @@ dependencies = [ "xcm-executor", ] -[[package]] -name = "pallet-xcm-transactor" -version = "0.2.0" -source = "git+https://github.com/jiguantong/moonbeam?branch=evm-xcm-debug#bd427bc96e062d65d646e322392c0b74c9833204" -dependencies = [ - "cumulus-primitives-core", - "frame-benchmarking", - "frame-support", - "frame-system", - "log", - "orml-traits", - "parity-scale-codec", - "scale-info", - "serde", - "sp-io", - "sp-runtime", - "sp-std", - "xcm", - "xcm-builder", - "xcm-executor", - "xcm-primitives", -] - [[package]] name = "pangolin-runtime" version = "6.0.0" @@ -8320,7 +8295,6 @@ dependencies = [ "pallet-utility", "pallet-vesting", "pallet-xcm", - "pallet-xcm-transactor", "parachain-info", "parity-scale-codec", "polkadot-parachain", diff --git a/Cargo.toml b/Cargo.toml index d070cec1c..979c6553d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -105,7 +105,6 @@ pallet-evm-precompile-simple = { default-features = false, git = "https://gith account = { default-features = false, git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.38" } moonbeam-relay-encoder = { default-features = false, git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.38" } pallet-ethereum-xcm = { default-features = false, git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.38" } -pallet-xcm-transactor = { default-features = false, git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.38" } precompile-utils = { default-features = false, git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.38" } xcm-primitives = { default-features = false, git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.38" } @@ -198,7 +197,6 @@ try-runtime-cli = { git = "https://github.com/parityt account = { git = "https://github.com/jiguantong/moonbeam", branch = "evm-xcm-debug" } moonbeam-relay-encoder = { git = "https://github.com/jiguantong/moonbeam", branch = "evm-xcm-debug" } pallet-ethereum-xcm = { git = "https://github.com/jiguantong/moonbeam", branch = "evm-xcm-debug" } -pallet-xcm-transactor = { git = "https://github.com/jiguantong/moonbeam", branch = "evm-xcm-debug" } precompile-utils = { git = "https://github.com/jiguantong/moonbeam", branch = "evm-xcm-debug" } xcm-primitives = { git = "https://github.com/jiguantong/moonbeam", branch = "evm-xcm-debug" } diff --git a/runtime/pangoro/Cargo.toml b/runtime/pangoro/Cargo.toml index d7466ebfe..6d852bcc0 100644 --- a/runtime/pangoro/Cargo.toml +++ b/runtime/pangoro/Cargo.toml @@ -72,7 +72,6 @@ pallet-evm-precompile-simple = { workspace = true } # moonbeam moonbeam-relay-encoder = { workspace = true } pallet-ethereum-xcm = { workspace = true } -pallet-xcm-transactor = { workspace = true } precompile-utils = { workspace = true } xcm-primitives = { workspace = true } @@ -194,7 +193,6 @@ std = [ # moonbeam "pallet-ethereum-xcm/std", - "pallet-xcm-transactor/std", "precompile-utils/std", "xcm-primitives/std", diff --git a/runtime/pangoro/src/lib.rs b/runtime/pangoro/src/lib.rs index 2e2a0e773..eb1d45302 100644 --- a/runtime/pangoro/src/lib.rs +++ b/runtime/pangoro/src/lib.rs @@ -167,7 +167,6 @@ frame_support::construct_runtime! { // Ethereum XCM EthereumXcm: pallet_ethereum_xcm = 44, - XcmTransactor: pallet_xcm_transactor = 45 } } diff --git a/runtime/pangoro/src/pallets/polkadot_xcm.rs b/runtime/pangoro/src/pallets/polkadot_xcm.rs index eb0200e9a..adbad99c0 100644 --- a/runtime/pangoro/src/pallets/polkadot_xcm.rs +++ b/runtime/pangoro/src/pallets/polkadot_xcm.rs @@ -16,15 +16,13 @@ // You should have received a copy of the GNU General Public License // along with Darwinia. If not, see . -// crates.io -use codec::{Decode, Encode}; // darwinia use crate::*; // polkadot use xcm::latest::prelude::*; // substrate use frame_support::traits::Currency; -use sp_runtime::traits::{Hash, Zero}; +use sp_runtime::traits::Zero; /// Means for transacting assets on this chain. pub type LocalAssetTransactor = xcm_builder::CurrencyAdapter< @@ -224,8 +222,6 @@ impl cumulus_pallet_xcm::Config for Runtime { type XcmExecutor = xcm_executor::XcmExecutor; } -// === XCM <> EVM === - pub struct EthereumXcmEnsureProxy; impl xcm_primitives::EnsureProxy for EthereumXcmEnsureProxy { fn ensure_ok(delegator: AccountId, delegatee: AccountId) -> Result<(), &'static str> { @@ -253,181 +249,6 @@ impl pallet_ethereum_xcm::Config for Runtime { type XcmEthereumOrigin = pallet_ethereum_xcm::EnsureXcmEthereumTransaction; } -// For now we only allow to transact in the relay, although this might change in the future -// Transactors just defines the chains in which we allow transactions to be issued through -// xcm -#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, scale_info::TypeInfo)] -pub enum Transactors { - Relay, -} - -// Default for benchmarking -#[cfg(feature = "runtime-benchmarks")] -impl Default for Transactors { - fn default() -> Self { - Transactors::Relay - } -} - -impl TryFrom for Transactors { - type Error = (); - - fn try_from(value: u8) -> Result { - match value { - 0u8 => Ok(Transactors::Relay), - _ => Err(()), - } - } -} - -impl xcm_primitives::UtilityEncodeCall for Transactors { - fn encode_call(self, call: xcm_primitives::UtilityAvailableCalls) -> Vec { - match self { - // The encoder should be polkadot - Transactors::Relay => - moonbeam_relay_encoder::polkadot::PolkadotEncoder.encode_call(call), - } - } -} - -impl xcm_primitives::XcmTransact for Transactors { - fn destination(self) -> MultiLocation { - match self { - Transactors::Relay => MultiLocation::parent(), - } - } -} - -// Our AssetType. For now we only handle Xcm Assets -#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, scale_info::TypeInfo)] -pub enum AssetType { - Xcm(MultiLocation), -} -impl Default for AssetType { - fn default() -> Self { - Self::Xcm(MultiLocation::here()) - } -} - -impl From for AssetType { - fn from(location: MultiLocation) -> Self { - Self::Xcm(location) - } -} - -impl Into> for AssetType { - fn into(self) -> Option { - match self { - Self::Xcm(location) => Some(location), - } - } -} - -// Implementation on how to retrieve the AssetId from an AssetType -// We take it -impl From for crate::AssetId { - fn from(asset: AssetType) -> crate::AssetId { - match asset { - AssetType::Xcm(id) => { - let mut result: [u8; 8] = [0u8; 8]; - let hash: sp_core::H256 = - id.using_encoded(::Hashing::hash); - result.copy_from_slice(&hash.as_fixed_bytes()[0..8]); - u64::from_le_bytes(result) - }, - } - } -} - -// Our currencyId. We distinguish for now between SelfReserve, and Others, defined by their Id. -#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, scale_info::TypeInfo)] -pub enum CurrencyId { - SelfReserve, - // ForeignAsset(crate::AssetId), - // // Our local assets - // LocalAssetReserve(crate::AssetId), -} - -impl xcm_primitives::AccountIdToCurrencyId for Runtime { - fn account_to_currency_id(account: AccountId) -> Option { - match account { - // TODO this should be our BalancesPrecompile address - // the self-reserve currency is identified by the pallet-balances address - a if a == sp_core::H160::from_low_u64_be(2050).into() => Some(CurrencyId::SelfReserve), - // the rest of the currencies, by their corresponding erc20 address - _ => { - unimplemented!("todo"); - } - // _ => Runtime::account_to_asset_id(account).map(|(prefix, asset_id)| { - // CurrencyId::LocalAssetReserve(asset_id) - // // We don't have ForeignAsset - // if prefix == FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX.to_vec() { - // CurrencyId::ForeignAsset(asset_id) - // } else { - // CurrencyId::LocalAssetReserve(asset_id) - // } - // }), - } - } -} - -// How to convert from CurrencyId to MultiLocation -pub struct CurrencyIdtoMultiLocation; -impl sp_runtime::traits::Convert> - for CurrencyIdtoMultiLocation -{ - fn convert(currency: CurrencyId) -> Option { - match currency { - CurrencyId::SelfReserve => { - let multi: MultiLocation = AnchoringSelfReserve::get(); - Some(multi) - }, /* CurrencyId::ForeignAsset(asset) => AssetXConverter::reverse_ref(asset).ok(), - * // No transactor matches this yet, so even if we have this enum variant the - * transfer will fail CurrencyId::LocalAssetReserve(asset) => { - * let mut location = LocalAssetsPalletLocation::get(); - * location.push_interior(xcm::opaque::latest::Junction::GeneralIndex(asset. - * into())).ok(); Some(location) - * } */ - } - } -} - -// We use all transactors -// These correspond to -// SelfReserve asset, both pre and post 0.9.16 -// Foreign assets -// Local assets, both pre and post 0.9.16 -// We can remove the Old reanchor once -// we import https://github.com/open-web3-stack/open-runtime-module-library/pull/708 -pub type AssetTransactors = (LocalAssetTransactor,); - -// 1 ROC/WND should be enough -frame_support::parameter_types! { - pub MaxHrmpRelayFee: MultiAsset = (MultiLocation::parent(), 1_000_000_000_000u128).into(); -} - -impl pallet_xcm_transactor::Config for Runtime { - type AccountIdToMultiLocation = xcm_primitives::AccountIdToMultiLocation; - type AssetTransactor = AssetTransactors; - type Balance = Balance; - type BaseXcmWeight = UnitWeightCost; - type CurrencyId = CurrencyId; - type CurrencyIdToMultiLocation = CurrencyIdtoMultiLocation; - type DerivativeAddressRegistrationOrigin = frame_system::EnsureRoot; - type HrmpEncoder = moonbeam_relay_encoder::westend::WestendEncoder; - type HrmpManipulatorOrigin = frame_system::EnsureRoot; - type MaxHrmpFee = xcm_builder::Case; - type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve; - type RuntimeEvent = RuntimeEvent; - type SelfLocation = SelfLocation; - type SovereignAccountDispatcherOrigin = frame_system::EnsureRoot; - type Transactor = Transactors; - type UniversalLocation = UniversalLocation; - type Weigher = XcmWeigher; - type WeightInfo = pallet_xcm_transactor::weights::SubstrateWeight; - type XcmSender = XcmRouter; -} - pub struct DarwiniaCall; impl xcm_executor::traits::CallDispatcher for DarwiniaCall { fn dispatch(