Skip to content

Commit

Permalink
Remove xcmTransactor from Pangolin
Browse files Browse the repository at this point in the history
  • Loading branch information
Guantong committed Mar 21, 2023
1 parent 2434791 commit 4184195
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 184 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions runtime/pangolin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down Expand Up @@ -194,7 +193,6 @@ std = [

# moonbeam
"pallet-ethereum-xcm/std",
"pallet-xcm-transactor/std",
"precompile-utils/std",
"xcm-primitives/std",

Expand Down
1 change: 0 additions & 1 deletion runtime/pangolin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ frame_support::construct_runtime! {

// Ethereum XCM
EthereumXcm: pallet_ethereum_xcm = 44,
XcmTransactor: pallet_xcm_transactor = 45
}
}

Expand Down
181 changes: 1 addition & 180 deletions runtime/pangolin/src/pallets/polkadot_xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

// 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<
Expand Down Expand Up @@ -224,8 +222,6 @@ impl cumulus_pallet_xcm::Config for Runtime {
type XcmExecutor = xcm_executor::XcmExecutor<XcmExecutorConfig>;
}

// === XCM <> EVM ===

pub struct EthereumXcmEnsureProxy;
impl xcm_primitives::EnsureProxy<AccountId> for EthereumXcmEnsureProxy {
fn ensure_ok(delegator: AccountId, delegatee: AccountId) -> Result<(), &'static str> {
Expand Down Expand Up @@ -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<u8> for Transactors {
type Error = ();

fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0u8 => Ok(Transactors::Relay),
_ => Err(()),
}
}
}

impl xcm_primitives::UtilityEncodeCall for Transactors {
fn encode_call(self, call: xcm_primitives::UtilityAvailableCalls) -> Vec<u8> {
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<MultiLocation> for AssetType {
fn from(location: MultiLocation) -> Self {
Self::Xcm(location)
}
}

impl Into<Option<MultiLocation>> for AssetType {
fn into(self) -> Option<MultiLocation> {
match self {
Self::Xcm(location) => Some(location),
}
}
}

// Implementation on how to retrieve the AssetId from an AssetType
// We take it
impl From<AssetType> 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(<Runtime as frame_system::Config>::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<AccountId, CurrencyId> for Runtime {
fn account_to_currency_id(account: AccountId) -> Option<CurrencyId> {
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<CurrencyId, Option<xcm::opaque::latest::MultiLocation>>
for CurrencyIdtoMultiLocation
{
fn convert(currency: CurrencyId) -> Option<MultiLocation> {
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<AccountId>;
type AssetTransactor = AssetTransactors;
type Balance = Balance;
type BaseXcmWeight = UnitWeightCost;
type CurrencyId = CurrencyId;
type CurrencyIdToMultiLocation = CurrencyIdtoMultiLocation;
type DerivativeAddressRegistrationOrigin = frame_system::EnsureRoot<AccountId>;
type HrmpEncoder = moonbeam_relay_encoder::westend::WestendEncoder;
type HrmpManipulatorOrigin = frame_system::EnsureRoot<AccountId>;
type MaxHrmpFee = xcm_builder::Case<MaxHrmpRelayFee>;
type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve<UniversalLocation>;
type RuntimeEvent = RuntimeEvent;
type SelfLocation = SelfLocation;
type SovereignAccountDispatcherOrigin = frame_system::EnsureRoot<AccountId>;
type Transactor = Transactors;
type UniversalLocation = UniversalLocation;
type Weigher = XcmWeigher;
type WeightInfo = pallet_xcm_transactor::weights::SubstrateWeight<Runtime>;
type XcmSender = XcmRouter;
}

pub struct DarwiniaCall;
impl xcm_executor::traits::CallDispatcher<RuntimeCall> for DarwiniaCall {
fn dispatch(
Expand Down

0 comments on commit 4184195

Please sign in to comment.