Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,786 changes: 1,027 additions & 759 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v
try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" }
frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39" }

# Substrate pallets
# Substrate pallets
# (wasm)
pallet-assets = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.39", default-features = false }
Expand Down Expand Up @@ -202,6 +202,12 @@ xcm-simulator = { git = "https://github.com/paritytech/polkadot", branch = "rele
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.39" }
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.39" }

# ORML
# (wasm)
orml-xtokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.39", default-features = false }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.39", default-features = false }
orml-xcm-support = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.39", default-features = false }

# Astar pallets & modules
# (wasm)
pallet-block-reward = { git = "https://github.com/AstarNetwork/astar-frame", branch = "polkadot-v0.9.39", default-features = false }
Expand Down
10 changes: 10 additions & 0 deletions runtime/shibuya/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ xcm = { workspace = true }
xcm-builder = { workspace = true }
xcm-executor = { workspace = true }

# orml dependencies
orml-xtokens = { workspace = true }
orml-traits = { workspace = true }
orml-xcm-support = { workspace = true }

# Astar pallets
pallet-block-reward = { workspace = true }
pallet-chain-extension-dapps-staking = { workspace = true }
Expand Down Expand Up @@ -223,6 +228,9 @@ std = [
"xcm-primitives/std",
"substrate-wasm-builder",
"pallet-chain-extension-assets/std",
"orml-xtokens/std",
"orml-traits/std",
"orml-xcm-support/std",
]
runtime-benchmarks = [
"frame-benchmarking",
Expand All @@ -242,6 +250,7 @@ runtime-benchmarks = [
"pallet-preimage/runtime-benchmarks",
"pallet-collator-selection/runtime-benchmarks",
"polkadot-runtime/runtime-benchmarks",
"orml-xtokens/runtime-benchmarks",
]
try-runtime = [
"fp-self-contained/try-runtime",
Expand Down Expand Up @@ -287,6 +296,7 @@ try-runtime = [
"pallet-preimage/try-runtime",
"pallet-base-fee/try-runtime",
"pallet-evm/try-runtime",
"orml-xtokens/try-runtime",
]
evm-tracing = [
"moonbeam-evm-tracer",
Expand Down
3 changes: 2 additions & 1 deletion runtime/shibuya/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("shibuya"),
impl_name: create_runtime_str!("shibuya"),
authoring_version: 1,
spec_version: 99,
spec_version: 100,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
Expand Down Expand Up @@ -1228,6 +1228,7 @@ construct_runtime!(
CumulusXcm: cumulus_pallet_xcm = 52,
DmpQueue: cumulus_pallet_dmp_queue = 53,
XcAssetConfig: pallet_xc_asset_config = 54,
Xtokens: orml_xtokens = 55,

EVM: pallet_evm = 60,
Ethereum: pallet_ethereum = 61,
Expand Down
86 changes: 83 additions & 3 deletions runtime/shibuya/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ use frame_support::{
weights::Weight,
};
use frame_system::EnsureRoot;
use sp_runtime::traits::{Convert, Get};
use sp_std::marker::PhantomData;

// Polkadot imports
use xcm::latest::prelude::*;
Expand All @@ -39,7 +41,14 @@ use xcm_builder::{
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, WithComputedOrigin,
};
use xcm_executor::{traits::JustTry, XcmExecutor};
use xcm_executor::{
traits::{Convert as XcmConvert, JustTry},
XcmExecutor,
};

// ORML imports
use orml_traits::location::{RelativeReserveProvider, Reserve};
use orml_xcm_support::DisabledParachainFee;

// Astar imports
use xcm_primitives::{FixedRateOfForeignAsset, ReserveAssetFilter, XcmFungibleFeeHandler};
Expand Down Expand Up @@ -160,6 +169,8 @@ pub type ShibuyaXcmFungibleFeeHandler = XcmFungibleFeeHandler<
TreasuryAccountId,
>;

pub type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
Expand All @@ -170,7 +181,7 @@ impl xcm_executor::Config for XcmConfig {
type IsTeleporter = ();
type UniversalLocation = UniversalLocation;
type Barrier = XcmBarrier;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type Weigher = Weigher;
type Trader = (
UsingComponents<WeightToFee, ShibuyaLocation, AccountId, Balances, DealWithFees>,
FixedRateOfForeignAsset<XcAssetConfig, ShibuyaXcmFungibleFeeHandler>,
Expand Down Expand Up @@ -223,7 +234,7 @@ impl pallet_xcm::Config for Runtime {
type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = Nothing;
type XcmReserveTransferFilter = Everything;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type Weigher = Weigher;
type UniversalLocation = UniversalLocation;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
Expand Down Expand Up @@ -260,3 +271,72 @@ impl cumulus_pallet_dmp_queue::Config for Runtime {
type XcmExecutor = XcmExecutor<XcmConfig>;
type ExecuteOverweightOrigin = EnsureRoot<AccountId>;
}

/// Convert `AccountId` to `MultiLocation`.
pub struct AccountIdToMultiLocation;
impl Convert<AccountId, MultiLocation> for AccountIdToMultiLocation {
fn convert(account: AccountId) -> MultiLocation {
X1(AccountId32 {
network: None,
Comment thread
shaunxw marked this conversation as resolved.
id: account.into(),
})
.into()
}
}

parameter_types! {
/// The absolute location in perspective of the whole network.
pub ShibuyaLocationAbsolute: MultiLocation = MultiLocation {
parents: 1,
interior: X1(
Parachain(ParachainInfo::parachain_id().into())
)
};
/// Max asset types for one cross-chain transfer. `2` covers all current use cases.
/// Can be updated with extra test cases in the future if needed.
pub const MaxAssetsForTransfer: usize = 2;
Comment thread
shaunxw marked this conversation as resolved.
}

/// Convert `AssetId` to optional `MultiLocation`. The impl is a wrapper
/// on `ShibuyaAssetLocationIdConverter`.
pub struct AssetIdConvert;
impl Convert<AssetId, Option<MultiLocation>> for AssetIdConvert {
fn convert(asset_id: AssetId) -> Option<MultiLocation> {
ShibuyaAssetLocationIdConverter::reverse_ref(&asset_id).ok()
}
}

/// `MultiAsset` reserve location provider. It's based on `RelativeReserveProvider` and in
/// addition will convert self absolute location to relative location.
pub struct AbsoluteAndRelativeReserveProvider<AbsoluteLocation>(PhantomData<AbsoluteLocation>);
impl<AbsoluteLocation: Get<MultiLocation>> Reserve
for AbsoluteAndRelativeReserveProvider<AbsoluteLocation>
{
fn reserve(asset: &MultiAsset) -> Option<MultiLocation> {
RelativeReserveProvider::reserve(asset).map(|reserve_location| {
if reserve_location == AbsoluteLocation::get() {
MultiLocation::here()
} else {
reserve_location
}
})
}
}

impl orml_xtokens::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type CurrencyId = AssetId;
type CurrencyIdConvert = AssetIdConvert;
type AccountIdToMultiLocation = AccountIdToMultiLocation;
type SelfLocation = ShibuyaLocation;
type XcmExecutor = XcmExecutor<XcmConfig>;
type Weigher = Weigher;
type BaseXcmWeight = UnitWeightCost;
type UniversalLocation = UniversalLocation;
type MaxAssetsForTransfer = MaxAssetsForTransfer;
// Default impl. Refer to `orml-xtokens` docs for more details.
type MinXcmFee = DisabledParachainFee;
type MultiLocationsFilter = Everything;
type ReserveProvider = AbsoluteAndRelativeReserveProvider<ShibuyaLocationAbsolute>;
}
8 changes: 8 additions & 0 deletions tests/xcm-simulator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ xcm-builder = { workspace = true }
xcm-executor = { workspace = true }
xcm-simulator = { workspace = true }

# ORML
orml-xtokens = { workspace = true }
orml-traits = { workspace = true }
orml-xcm-support = { workspace = true }

[features]
default = ["std"]
std = [
Expand All @@ -73,6 +78,9 @@ std = [
"pallet-dapps-staking/std",
"pallet-proxy/std",
"pallet-utility/std",
"orml-xtokens/std",
"orml-traits/std",
"orml-xcm-support/std",
]
runtime-benchmarks = [
"frame-system/runtime-benchmarks",
Expand Down
1 change: 1 addition & 0 deletions tests/xcm-simulator/src/mocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub type ParachainPalletXcm = pallet_xcm::Pallet<parachain::Runtime>;
pub type ParachainAssets = pallet_assets::Pallet<parachain::Runtime>;
pub type ParachainBalances = pallet_balances::Pallet<parachain::Runtime>;
pub type ParachainContracts = pallet_contracts::Pallet<parachain::Runtime>;
pub type ParachainXtokens = orml_xtokens::Pallet<parachain::Runtime>;

pub fn parent_account_id() -> parachain::AccountId {
let location = (Parent,);
Expand Down
88 changes: 84 additions & 4 deletions tests/xcm-simulator/src/mocks/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use sp_core::{ConstBool, H256};
use sp_runtime::{
testing::Header,
traits::{AccountIdConversion, Convert, IdentityLookup},
traits::{AccountIdConversion, Convert, Get, IdentityLookup},
AccountId32, Perbill, RuntimeDebug,
};
use sp_std::marker::PhantomData;
use sp_std::prelude::*;

use super::msg_queue::*;
Expand All @@ -55,7 +56,14 @@ use xcm_builder::{
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, WithComputedOrigin,
};
use xcm_executor::{traits::JustTry, XcmExecutor};

use orml_traits::location::{RelativeReserveProvider, Reserve};
use orml_xcm_support::DisabledParachainFee;

use xcm_executor::{
traits::{Convert as XcmConvert, JustTry},
XcmExecutor,
};

use xcm_primitives::{
AssetLocationIdConverter, FixedRateOfForeignAsset, ReserveAssetFilter, XcmFungibleFeeHandler,
Expand Down Expand Up @@ -499,6 +507,8 @@ pub type ShidenXcmFungibleFeeHandler = XcmFungibleFeeHandler<
TreasuryAccountId,
>;

pub type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
Expand All @@ -509,7 +519,7 @@ impl xcm_executor::Config for XcmConfig {
type IsTeleporter = ();
type UniversalLocation = UniversalLocation;
type Barrier = XcmBarrier;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type Weigher = Weigher;
type Trader = (
FixedRateOfFungible<NativePerSecond, ()>,
FixedRateOfForeignAsset<XcAssetConfig, ShidenXcmFungibleFeeHandler>,
Expand Down Expand Up @@ -551,7 +561,7 @@ impl pallet_xcm::Config for Runtime {
type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = Nothing;
type XcmReserveTransferFilter = Everything;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type Weigher = Weigher;
type UniversalLocation = UniversalLocation;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
Expand All @@ -568,6 +578,75 @@ impl pallet_xcm::Config for Runtime {
type ReachableDest = ReachableDest;
}

/// Convert `AccountId` to `MultiLocation`.
pub struct AccountIdToMultiLocation;
impl Convert<AccountId, MultiLocation> for AccountIdToMultiLocation {
fn convert(account: AccountId) -> MultiLocation {
X1(Junction::AccountId32 {
network: None,
id: account.into(),
})
.into()
}
}

parameter_types! {
/// The absolute location in perspective of the whole network.
pub ShidenLocationAbsolute: MultiLocation = MultiLocation {
parents: 1,
interior: X1(
Parachain(MsgQueue::parachain_id().into())
)
};
/// Max asset types for one cross-chain transfer. `2` covers all current use cases.
/// Can be updated with extra test cases in the future if needed.
pub const MaxAssetsForTransfer: usize = 2;
}

/// Convert `AssetId` to optional `MultiLocation`. The impl is a wrapper
/// on `ShidenAssetLocationIdConverter`.
pub struct AssetIdConvert;
impl Convert<AssetId, Option<MultiLocation>> for AssetIdConvert {
fn convert(asset_id: AssetId) -> Option<MultiLocation> {
ShidenAssetLocationIdConverter::reverse_ref(&asset_id).ok()
}
}

/// `MultiAsset` reserve location provider. It's based on `RelativeReserveProvider` and in
/// addition will convert self absolute location to relative location.
pub struct AbsoluteAndRelativeReserveProvider<AbsoluteLocation>(PhantomData<AbsoluteLocation>);
impl<AbsoluteLocation: Get<MultiLocation>> Reserve
for AbsoluteAndRelativeReserveProvider<AbsoluteLocation>
{
fn reserve(asset: &MultiAsset) -> Option<MultiLocation> {
RelativeReserveProvider::reserve(asset).map(|reserve_location| {
if reserve_location == AbsoluteLocation::get() {
MultiLocation::here()
} else {
reserve_location
}
})
}
}

impl orml_xtokens::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type CurrencyId = AssetId;
type CurrencyIdConvert = AssetIdConvert;
type AccountIdToMultiLocation = AccountIdToMultiLocation;
type SelfLocation = ShidenLocation;
type XcmExecutor = XcmExecutor<XcmConfig>;
type Weigher = Weigher;
type BaseXcmWeight = UnitWeightCost;
type UniversalLocation = UniversalLocation;
type MaxAssetsForTransfer = MaxAssetsForTransfer;
// Default impl. Refer to `orml-xtokens` docs for more details.
type MinXcmFee = DisabledParachainFee;
type MultiLocationsFilter = Everything;
type ReserveProvider = AbsoluteAndRelativeReserveProvider<ShidenLocationAbsolute>;
}

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
type Block = frame_system::mocking::MockBlock<Runtime>;

Expand All @@ -590,5 +669,6 @@ construct_runtime!(
Randomness: pallet_insecure_randomness_collective_flip::{Pallet, Storage},
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
Contracts: pallet_contracts::{Pallet, Call, Storage, Event<T>},
Xtokens: orml_xtokens::{Pallet, Storage, Call, Event<T>},
}
);
Loading