Skip to content

Commit

Permalink
Merge pull request #12 from Snowfork/alistair/remove-gateway-contract…
Browse files Browse the repository at this point in the history
…-locations

Remove gateway contract locations from Assets
  • Loading branch information
alistair-singh authored Nov 3, 2023
2 parents 7414de6 + 0ee181e commit dab8646
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ use xcm::latest::prelude::*;
use xcm_executor::XcmExecutor;

use crate::xcm_config::{
bridging::to_rococo::EthereumGatewayLocation, ForeignCreatorsSovereignAccountOf,
bridging::to_wococo::EthereumLocation, ForeignCreatorsSovereignAccountOf,
LocalAndForeignAssetsMultiLocationMatcher, TrustBackedAssetsPalletLocation,
};
use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
Expand Down Expand Up @@ -390,9 +390,7 @@ impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
type CreateOrigin = ForeignCreators<
(
FromSiblingParachain<parachain_info::Pallet<Runtime>>,
snowbridge_router_primitives::inbound::FromEthereumGlobalConsensus<
EthereumGatewayLocation,
>,
snowbridge_router_primitives::inbound::FromEthereumGlobalConsensus<EthereumLocation>,
),
ForeignCreatorsSovereignAccountOf,
AccountId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use super::{
};
use assets_common::{
local_and_foreign_assets::MatchesLocalAndForeignAssetsMultiLocation,
matching::{FromSiblingParachain, IsForeignConcreteAsset},
matching::{FromNetwork, FromSiblingParachain, IsForeignConcreteAsset},
};
use frame_support::{
match_types, parameter_types,
Expand All @@ -42,7 +42,7 @@ use parachains_common::{
use polkadot_parachain_primitives::primitives::Sibling;
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
use rococo_runtime_constants::system_parachain::SystemParachains;
use snowbridge_router_primitives::inbound::GlobalConsensusEthereumAccountConvertsFor;
use snowbridge_router_primitives::inbound::GlobalConsensusEthereumConvertsFor;
use sp_runtime::traits::{AccountIdConversion, ConvertInto};
use xcm::latest::prelude::*;
use xcm_builder::{
Expand Down Expand Up @@ -114,7 +114,7 @@ pub type LocationToAccountId = (
GlobalConsensusParachainConvertsFor<UniversalLocation, AccountId>,
// Ethereum contract sovereign account.
// (Used to get convert ethereum contract locations to sovereign account)
GlobalConsensusEthereumAccountConvertsFor<AccountId>,
GlobalConsensusEthereumConvertsFor<AccountId>,
);

/// Means for transacting the native currency on this chain.
Expand Down Expand Up @@ -563,8 +563,8 @@ impl xcm_executor::Config for XcmConfig {
// Users must use teleport where allowed (e.g. ROC with the Relay Chain).
type IsReserve = (
bridging::to_wococo::IsTrustedBridgedReserveLocationForConcreteAsset,
bridging::to_wococo::IsTrustedBridgedReserveLocationForForeignAsset,
bridging::to_rococo::IsTrustedBridgedReserveLocationForConcreteAsset,
bridging::to_rococo::IsTrustedBridgedReserveLocationForForeignAsset,
);
type IsTeleporter = TrustedTeleporters;
type UniversalLocation = UniversalLocation;
Expand Down Expand Up @@ -700,7 +700,7 @@ pub type ForeignCreatorsSovereignAccountOf = (
SiblingParachainConvertsVia<Sibling, AccountId>,
AccountId32Aliases<RelayNetwork, AccountId>,
ParentIsPreset<AccountId>,
GlobalConsensusEthereumAccountConvertsFor<AccountId>,
GlobalConsensusEthereumConvertsFor<AccountId>,
);

/// Simple conversion of `u32` into an `AssetId` for use in benchmarking.
Expand Down Expand Up @@ -782,6 +782,8 @@ pub mod bridging {
pub const WococoNetwork: NetworkId = NetworkId::Wococo;
pub AssetHubWococo: MultiLocation = MultiLocation::new(2, X2(GlobalConsensus(WococoNetwork::get()), Parachain(bp_asset_hub_wococo::ASSET_HUB_WOCOCO_PARACHAIN_ID)));
pub WocLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(WococoNetwork::get())));
pub EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 15 };
pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get())));

pub WocFromAssetHubWococo: (MultiAssetFilter, MultiLocation) = (
Wild(AllOf { fun: WildFungible, id: Concrete(WocLocation::get()) }),
Expand All @@ -802,7 +804,18 @@ pub mod bridging {
XcmBridgeHubRouterFeeAssetId::get(),
bp_asset_hub_rococo::BridgeHubRococoBaseFeeInRocs::get(),
).into())
)
),
NetworkExportTableItem::new(
EthereumNetwork::get(),
Some(sp_std::vec![
EthereumLocation::get().interior.split_global().expect("invalid configuration for Ethereum").1,
]),
SiblingBridgeHub::get(),
Some((
XcmBridgeHubRouterFeeAssetId::get(),
BridgeHubEthereumBaseFeeInRocs::get(),
).into())
),
];

/// Allowed assets for reserve transfer to `AssetHubWococo`.
Expand All @@ -815,11 +828,15 @@ pub mod bridging {
/// Universal aliases
pub UniversalAliases: BTreeSet<(MultiLocation, Junction)> = BTreeSet::from_iter(
sp_std::vec![
(SiblingBridgeHubWithBridgeHubWococoInstance::get(), GlobalConsensus(WococoNetwork::get()))
(SiblingBridgeHubWithBridgeHubWococoInstance::get(), GlobalConsensus(WococoNetwork::get())),
(SiblingBridgeHub::get(), GlobalConsensus(EthereumNetwork::get())),
]
);
}

pub type IsTrustedBridgedReserveLocationForForeignAsset =
matching::IsForeignConcreteAsset<FromNetwork<EthereumNetwork>>;

impl Contains<(MultiLocation, Junction)> for UniversalAliases {
fn contains(alias: &(MultiLocation, Junction)) -> bool {
UniversalAliases::get().contains(alias)
Expand Down Expand Up @@ -858,7 +875,6 @@ pub mod bridging {

pub mod to_rococo {
use super::*;
use assets_common::matching::FromNetwork;

parameter_types! {
pub SiblingBridgeHubWithBridgeHubRococoInstance: MultiLocation = MultiLocation::new(
Expand All @@ -872,18 +888,6 @@ pub mod bridging {
pub const RococoNetwork: NetworkId = NetworkId::Rococo;
pub AssetHubRococo: MultiLocation = MultiLocation::new(2, X2(GlobalConsensus(RococoNetwork::get()), Parachain(bp_asset_hub_rococo::ASSET_HUB_ROCOCO_PARACHAIN_ID)));
pub RocLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(RococoNetwork::get())));
pub EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 15 };
pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get()))); // TODO: Maybe registry address belongs here

pub const EthereumGatewayAddress: [u8; 20] = hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39");
// The Registry contract for the bridge which is also the origin for reserves and the prefix of all assets.
pub EthereumGatewayLocation: MultiLocation = EthereumLocation::get()
.pushed_with_interior(
AccountKey20 {
network: None,
key: EthereumGatewayAddress::get(),
}
).unwrap();

pub RocFromAssetHubRococo: (MultiAssetFilter, MultiLocation) = (
Wild(AllOf { fun: WildFungible, id: Concrete(RocLocation::get()) }),
Expand All @@ -905,15 +909,6 @@ pub mod bridging {
bp_asset_hub_wococo::BridgeHubWococoBaseFeeInWocs::get(),
).into())
),
NetworkExportTableItem::new(
EthereumNetwork::get(),
None, // TODO add Ethereum network / gateway contract
SiblingBridgeHub::get(),
Some((
XcmBridgeHubRouterFeeAssetId::get(),
BridgeHubEthereumBaseFeeInRocs::get(),
).into())
),
];

/// Allowed assets for reserve transfer to `AssetHubWococo`.
Expand All @@ -923,15 +918,10 @@ pub mod bridging {
// and nothing else
];

pub AllowedReserveTransferAssetsToEthereum: sp_std::vec::Vec<MultiAssetFilter> = sp_std::vec![
Wild(AllOf { fun: WildFungible, id: Concrete(EthereumGatewayLocation::get()) }),
];

/// Universal aliases
pub UniversalAliases: BTreeSet<(MultiLocation, Junction)> = BTreeSet::from_iter(
sp_std::vec![
(SiblingBridgeHubWithBridgeHubRococoInstance::get(), GlobalConsensus(RococoNetwork::get())),
(SiblingBridgeHub::get(), GlobalConsensus(EthereumNetwork::get())),
]
);
}
Expand All @@ -954,9 +944,6 @@ pub mod bridging {
),
>;

pub type IsTrustedBridgedReserveLocationForForeignAsset =
matching::IsForeignConcreteAsset<FromNetwork<EthereumNetwork>>;

/// Allows to reserve transfer assets to `AssetHubRococo`.
pub type AllowedReserveTransferAssets = LocationWithAssetFilters<
Equals<AssetHubRococo>,
Expand Down
8 changes: 6 additions & 2 deletions cumulus/parachains/runtimes/assets/common/src/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ pub struct FromNetwork<SelfNetworkId>(sp_std::marker::PhantomData<SelfNetworkId>
impl<SelfNetworkId: Get<NetworkId>> ContainsPair<MultiLocation, MultiLocation>
for FromNetwork<SelfNetworkId>
{
fn contains(&a: &MultiLocation, _b: &MultiLocation) -> bool {
// TODO: check that a.starts_with(b)
fn contains(&a: &MultiLocation, b: &MultiLocation) -> bool {
// `a` needs to be from `b` at least
if !a.starts_with(b) {
return false
}

match a {
MultiLocation { parents: 2, interior } => {
matches!(interior.first(), Some(GlobalConsensus(network)) if *network == SelfNetworkId::get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ use pallet_xcm::EnsureXcm;
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
pub use sp_runtime::{MultiAddress, Perbill, Permill};
use xcm::VersionedMultiLocation;
use xcm_config::{EthereumGatewayAddress, XcmConfig, XcmOriginToTransactDispatchOrigin};
use xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin};

use bp_runtime::HeaderId;

Expand Down Expand Up @@ -500,7 +500,7 @@ impl pallet_message_queue::Config for Runtime {

parameter_types! {
pub const Reward: u128 = 10;
pub const GatewayAddress: H160 = H160(EthereumGatewayAddress::get());
pub const GatewayAddress: H160 = H160(hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39"));
pub const CreateAssetCall: [u8;2] = [53, 0];
pub const CreateAssetExecutionFee: u128 = 2_000_000_000;
pub const SendTokenExecutionFee: u128 = 1_000_000_000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ use xcm_builder::{
deposit_or_burn_fee, AccountId32Aliases, AllowExplicitUnpaidExecutionFrom,
AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
CurrencyAdapter, DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal,
DescribeFamily, EnsureXcmOrigin, HandleFee, HashedDescription, IsConcrete,
ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents,
XcmFeeToAccount,
DescribeFamily, EnsureXcmOrigin, HandleFee, HashedDescription, IsConcrete, ParentAsSuperuser,
ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
XcmFeeManagerFromComponents, XcmFeeToAccount,
};
use xcm_executor::{
traits::{ExportXcm, FeeReason, TransactAsset, WithOriginFilter},
Expand All @@ -85,16 +84,6 @@ parameter_types! {
// Network and location for the local Ethereum testnet.
pub const EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 15 };
pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get())));

pub const EthereumGatewayAddress: [u8; 20] = hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39");
// The Registry contract for the bridge which is also the origin for reserves and the prefix of all assets.
pub EthereumGatewayLocation: MultiLocation = EthereumLocation::get()
.pushed_with_interior(
AccountKey20 {
network: None,
key: EthereumGatewayAddress::get(),
}
).unwrap();
}

/// Adapter for resolving `NetworkId` based on `pub storage Flavor: RuntimeFlavor`.
Expand Down Expand Up @@ -428,7 +417,7 @@ pub type AgentIdOf = HashedDescription<H256, DescribeFamily<DescribeAllTerminal>

pub type SnowbridgeExporter = EthereumBlobExporter<
UniversalLocation,
EthereumGatewayLocation,
EthereumLocation,
snowbridge_outbound_queue::Pallet<Runtime>,
AgentIdOf,
>;
Expand Down Expand Up @@ -472,7 +461,7 @@ impl ExportXcm for BridgeHubRococoOrBridgeHubWococoSwitchExporter {
destination,
message,
)
.map(|result| ((Ethereum { chain_id: 15 }, result.0), result.1)) // TODO get network ID
.map(|result| ((location, result.0), result.1))
},
_ => unimplemented!("Unsupported network: {:?}", network),
}
Expand Down

0 comments on commit dab8646

Please sign in to comment.