Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
38 changes: 19 additions & 19 deletions asset-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,37 @@ serde = { version = "1.0.136", optional = true }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["max-encoded-len"] }

# substrate
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" }

# polkadot
pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.37" }
xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.37" }
xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.37" }
xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.37" }
pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.38" }
xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.38" }
xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.38" }
xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.38" }

# orml
orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false }

[dev-dependencies]
# substrate
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.37" }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.38" }

# cumulus
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38" }
cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38" }
cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38" }
cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38" }
parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.38" }

# polkadot
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
xcm-simulator = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38" }
polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38" }
xcm-simulator = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38" }

# orml
orml-tokens = { path = "../tokens" }
Expand Down
8 changes: 3 additions & 5 deletions asset-registry/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl<W: WeightToFeeConverter, R: TakeRevenue> WeightTrader for AssetRegistryTrad
continue;
}

if let Some(fee_increase) = W::convert_weight_to_fee(location, Weight::from_ref_time(weight)) {
if let Some(fee_increase) = W::convert_weight_to_fee(location, weight) {
if fee_increase == 0 {
// if the fee is set very low it could lead to zero fees, in which case
// constructing the fee asset item to subtract from payment would fail.
Expand All @@ -120,9 +120,7 @@ impl<W: WeightToFeeConverter, R: TakeRevenue> WeightTrader for AssetRegistryTrad

self.bought_weight = Some(BoughtWeight {
amount: existing_fee.checked_add(fee_increase).ok_or(XcmError::Overflow)?,
weight: existing_weight
.checked_add(&Weight::from_ref_time(weight))
.ok_or(XcmError::Overflow)?,
weight: existing_weight.checked_add(&weight).ok_or(XcmError::Overflow)?,
asset_location: location.clone(),
});
return Ok(unused);
Expand All @@ -138,7 +136,7 @@ impl<W: WeightToFeeConverter, R: TakeRevenue> WeightTrader for AssetRegistryTrad

match self.bought_weight {
Some(ref mut bought) => {
let new_weight = bought.weight.saturating_sub(Weight::from_ref_time(weight));
let new_weight = bought.weight.saturating_sub(weight);
let new_amount = W::convert_weight_to_fee(&bought.asset_location, new_weight)?;
let refunded_amount = bought.amount.saturating_sub(new_amount);

Expand Down
2 changes: 1 addition & 1 deletion asset-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use sp_runtime::{
DispatchResult,
};
use sp_std::prelude::*;
use xcm::{v2::prelude::*, VersionedMultiLocation};
use xcm::{latest::prelude::*, VersionedMultiLocation};
Comment thread
xlc marked this conversation as resolved.
Outdated

pub use impls::*;
pub use module::*;
Expand Down
79 changes: 61 additions & 18 deletions asset-registry/src/mock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use super::*;
use mock::para::AssetRegistry;
use scale_info::TypeInfo;
use serde::{Deserialize, Serialize};
use sp_core::bounded::BoundedVec;
use sp_io::TestExternalities;
use sp_runtime::{traits::Convert, AccountId32};
use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain};
Expand Down Expand Up @@ -42,12 +43,54 @@ impl Convert<CurrencyId, Option<MultiLocation>> for CurrencyIdConvert {
fn convert(id: CurrencyId) -> Option<MultiLocation> {
match id {
CurrencyId::R => Some(Parent.into()),
CurrencyId::A => Some((Parent, Parachain(1), GeneralKey(b"A".to_vec().try_into().unwrap())).into()),
CurrencyId::A1 => Some((Parent, Parachain(1), GeneralKey(b"A1".to_vec().try_into().unwrap())).into()),
CurrencyId::B => Some((Parent, Parachain(2), GeneralKey(b"B".to_vec().try_into().unwrap())).into()),
CurrencyId::B1 => Some((Parent, Parachain(2), GeneralKey(b"B1".to_vec().try_into().unwrap())).into()),
CurrencyId::B2 => Some((Parent, Parachain(2), GeneralKey(b"B2".to_vec().try_into().unwrap())).into()),
CurrencyId::D => Some((Parent, Parachain(4), GeneralKey(b"D".to_vec().try_into().unwrap())).into()),
CurrencyId::A => Some(
(
Parent,
Parachain(1),
Junction::from(BoundedVec::try_from(b"A".to_vec()).unwrap()),
)
.into(),
),
CurrencyId::A1 => Some(
(
Parent,
Parachain(1),
Junction::from(BoundedVec::try_from(b"A1".to_vec()).unwrap()),
)
.into(),
),
CurrencyId::B => Some(
(
Parent,
Parachain(2),
Junction::from(BoundedVec::try_from(b"B".to_vec()).unwrap()),
)
.into(),
),
CurrencyId::B1 => Some(
(
Parent,
Parachain(2),
Junction::from(BoundedVec::try_from(b"B1".to_vec()).unwrap()),
)
.into(),
),
CurrencyId::B2 => Some(
(
Parent,
Parachain(2),
Junction::from(BoundedVec::try_from(b"B2".to_vec()).unwrap()),
)
.into(),
),
CurrencyId::D => Some(
(
Parent,
Parachain(4),
Junction::from(BoundedVec::try_from(b"D".to_vec()).unwrap()),
)
.into(),
),
CurrencyId::RegisteredAsset(id) => AssetRegistry::multilocation(&id).unwrap_or_default(),
}
}
Expand All @@ -65,21 +108,21 @@ impl Convert<MultiLocation, Option<CurrencyId>> for CurrencyIdConvert {
}
let currency_id = match l.clone() {
MultiLocation { parents, interior } if parents == 1 => match interior {
X2(Parachain(1), GeneralKey(k)) if k == a => Some(CurrencyId::A),
X2(Parachain(1), GeneralKey(k)) if k == a1 => Some(CurrencyId::A1),
X2(Parachain(2), GeneralKey(k)) if k == b => Some(CurrencyId::B),
X2(Parachain(2), GeneralKey(k)) if k == b1 => Some(CurrencyId::B1),
X2(Parachain(2), GeneralKey(k)) if k == b2 => Some(CurrencyId::B2),
X2(Parachain(4), GeneralKey(k)) if k == d => Some(CurrencyId::D),
X2(Parachain(1), GeneralKey { data, .. }) if data.to_vec() == a => Some(CurrencyId::A),
X2(Parachain(1), GeneralKey { data, .. }) if data.to_vec() == a1 => Some(CurrencyId::A1),
X2(Parachain(2), GeneralKey { data, .. }) if data.to_vec() == b => Some(CurrencyId::B),
X2(Parachain(2), GeneralKey { data, .. }) if data.to_vec() == b1 => Some(CurrencyId::B1),
X2(Parachain(2), GeneralKey { data, .. }) if data.to_vec() == b2 => Some(CurrencyId::B2),
X2(Parachain(4), GeneralKey { data, .. }) if data.to_vec() == d => Some(CurrencyId::D),
_ => None,
},
MultiLocation { parents, interior } if parents == 0 => match interior {
X1(GeneralKey(k)) if k == a => Some(CurrencyId::A),
X1(GeneralKey(k)) if k == b => Some(CurrencyId::B),
X1(GeneralKey(k)) if k == a1 => Some(CurrencyId::A1),
X1(GeneralKey(k)) if k == b1 => Some(CurrencyId::B1),
X1(GeneralKey(k)) if k == b2 => Some(CurrencyId::B2),
X1(GeneralKey(k)) if k == d => Some(CurrencyId::D),
X1(GeneralKey { data, .. }) if data.to_vec() == a => Some(CurrencyId::A),
X1(GeneralKey { data, .. }) if data.to_vec() == b => Some(CurrencyId::B),
X1(GeneralKey { data, .. }) if data.to_vec() == a1 => Some(CurrencyId::A1),
X1(GeneralKey { data, .. }) if data.to_vec() == b1 => Some(CurrencyId::B1),
X1(GeneralKey { data, .. }) if data.to_vec() == b2 => Some(CurrencyId::B2),
X1(GeneralKey { data, .. }) if data.to_vec() == d => Some(CurrencyId::D),
_ => None,
},
_ => None,
Expand Down
62 changes: 43 additions & 19 deletions asset-registry/src/mock/para.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ use sp_runtime::{
};
use xcm::latest::{prelude::*, Weight};
use xcm_builder::{
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, EnsureXcmOrigin, FixedWeightBounds, LocationInverter,
ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeRevenue, TakeWeightCredit,
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, EnsureXcmOrigin, FixedWeightBounds, ParentIsPreset,
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeRevenue, TakeWeightCredit,
};
use xcm_executor::{Config, XcmExecutor};

Expand Down Expand Up @@ -143,8 +143,8 @@ impl orml_asset_registry::Config for Runtime {
}

parameter_types! {
pub const ReservedXcmpWeight: Weight = WEIGHT_REF_TIME_PER_SECOND / 4;
pub const ReservedDmpWeight: Weight = WEIGHT_REF_TIME_PER_SECOND / 4;
pub const ReservedXcmpWeight: Weight = Weight::from_ref_time(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4));
pub const ReservedDmpWeight: Weight = Weight::from_ref_time(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4));
}

impl parachain_info::Config for Runtime {}
Expand All @@ -153,7 +153,8 @@ parameter_types! {
pub const RelayLocation: MultiLocation = MultiLocation::parent();
pub const RelayNetwork: NetworkId = NetworkId::Kusama;
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
pub UniversalLocation: InteriorMultiLocation =
X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into()));
}

pub type LocationToAccountId = (
Expand Down Expand Up @@ -214,6 +215,13 @@ impl FixedConversionRateProvider for MyFixedConversionRateProvider {
}
}

parameter_types! {
pub const UnitWeightCost: Weight = Weight::from_parts(10, 10);
pub const BaseXcmWeight: Weight = Weight::from_parts(100_000_000, 100_000_000);
pub const MaxInstructions: u32 = 100;
pub const MaxAssetsIntoHolding: u32 = 64;
}

pub struct XcmConfig;
impl Config for XcmConfig {
type RuntimeCall = RuntimeCall;
Expand All @@ -222,14 +230,23 @@ impl Config for XcmConfig {
type OriginConverter = XcmOriginToCallOrigin;
type IsReserve = MultiNativeAsset<AbsoluteReserveProvider>;
type IsTeleporter = ();
type LocationInverter = LocationInverter<Ancestry>;
type UniversalLocation = UniversalLocation;
type Barrier = Barrier;
type Weigher = FixedWeightBounds<ConstU64<10>, RuntimeCall, ConstU32<100>>;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type Trader = AssetRegistryWeightTrader;
type ResponseHandler = ();
type AssetTrap = PolkadotXcm;
type AssetClaims = PolkadotXcm;
type SubscriptionService = PolkadotXcm;
type AssetLocker = PolkadotXcm;
type AssetExchanger = ();
type PalletInstancesInfo = ();
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type FeeManager = ();
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = RuntimeCall;
type SafeCallFilter = Everything;
}

pub struct ChannelInfo;
Expand All @@ -251,6 +268,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime {
type ControllerOrigin = EnsureRoot<AccountId>;
type ControllerOriginConverter = XcmOriginToCallOrigin;
type WeightInfo = ();
type PriceForSiblingDelivery = ();
}

impl cumulus_pallet_dmp_queue::Config for Runtime {
Expand All @@ -266,6 +284,11 @@ impl cumulus_pallet_xcm::Config for Runtime {

pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;

parameter_types! {
pub SelfLocation: MultiLocation = MultiLocation::here();
pub const MaxAssetsForTransfer: usize = 3;
}

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
Expand All @@ -275,30 +298,31 @@ impl pallet_xcm::Config for Runtime {
type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = Nothing;
type XcmReserveTransferFilter = Everything;
type Weigher = FixedWeightBounds<ConstU64<10>, RuntimeCall, ConstU32<100>>;
type LocationInverter = LocationInverter<Ancestry>;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type UniversalLocation = UniversalLocation;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
type Currency = Balances;
type CurrencyMatcher = ();
type TrustedLockers = ();
type SovereignAccountOf = ();
type MaxLockers = ConstU32<8>;
type WeightInfo = pallet_xcm::TestWeightInfo;
}

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

parameter_types! {
pub SelfLocation: MultiLocation = MultiLocation::here();
pub const MaxAssetsForTransfer: usize = 3;
}

match_types! {
pub type ParentOrParachains: impl Contains<MultiLocation> = {
MultiLocation { parents: 0, interior: X1(Junction::AccountId32 { .. }) } |
Expand Down Expand Up @@ -331,9 +355,9 @@ impl orml_xtokens::Config for Runtime {
type MultiLocationsFilter = ParentOrParachains;
type MinXcmFee = ParachainMinFee;
type XcmExecutor = XcmExecutor<XcmConfig>;
type Weigher = FixedWeightBounds<ConstU64<10>, RuntimeCall, ConstU32<100>>;
type BaseXcmWeight = ConstU64<100_000_000>;
type LocationInverter = LocationInverter<Ancestry>;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type BaseXcmWeight = BaseXcmWeight;
type UniversalLocation = UniversalLocation;
type MaxAssetsForTransfer = MaxAssetsForTransfer;
type ReserveProvider = RelativeReserveProvider;
}
Expand Down
Loading