Skip to content

Commit d26b0b1

Browse files
RomarQxlc
andauthored
deps: update substrate-sdk to version 1.7.0 (#977)
* deps: update substrate-sdk to version 1.7.0 * deps: update dependencies in Cargo.dev.toml file * test: test compatibility between xcm v3 MultiLocation and xcm v4 Location * keep asset registry using xcm v3 * Revert "test: test compatibility between xcm v3 MultiLocation and xcm v4 Location" This reverts commit 38f45f2. * fix test * fix tests --------- Co-authored-by: Bryan Chen <[email protected]>
1 parent c7910d3 commit d26b0b1

30 files changed

+820
-884
lines changed

Cargo.dev.toml

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,34 @@ scale-info = { version = "2.10.0", default-features = false, features = ["derive
3636
serde = { version = "1.0.189" }
3737
parity-scale-codec = { version = "3.6.5", default-features = false, features = ["max-encoded-len"] }
3838

39-
cumulus-pallet-xcm = { version = "0.7.0", default-features = false }
40-
cumulus-primitives-core = { version = "0.7.0", default-features = false }
41-
frame-benchmarking = { version = "28.0.0", default-features = false }
42-
frame-support = { version = "28.0.0", default-features = false }
43-
frame-system = { version = "28.0.0", default-features = false }
44-
pallet-balances = { version = "28.0.0", default-features = false }
45-
pallet-elections-phragmen = { version = "29.0.0", default-features = false }
46-
pallet-message-queue = { version = "31.0.0", default-features = false }
47-
pallet-preimage = { version = "28.0.0", default-features = false }
48-
pallet-root-testing = { version = "4.0.0", default-features = false }
49-
pallet-scheduler = { version = "29.0.0", default-features = false }
50-
pallet-treasury = { version = "27.0.0", default-features = false }
51-
pallet-xcm = { version = "7.0.0", default-features = false }
52-
polkadot-parachain-primitives = { version = "6.0.0", default-features = false }
53-
polkadot-runtime-common = { version = "7.0.0", default-features = false }
54-
polkadot-runtime-parachains = { version = "7.0.0", default-features = false }
55-
sp-api = { version = "26.0.0", default-features = false }
56-
sp-application-crypto = { version = "30.0.0", default-features = false }
57-
sp-arithmetic = { version = "23.0.0", default-features = false }
58-
sp-core = { version = "28.0.0", default-features = false }
59-
sp-io = { version = "30.0.0", default-features = false }
60-
sp-runtime = { version = "31.0.1", default-features = false }
61-
sp-runtime-interface = { version = "24.0.0", default-features = false }
62-
sp-staking = { version = "26.0.0", default-features = false }
39+
cumulus-pallet-xcm = { version = "0.8.0", default-features = false }
40+
cumulus-primitives-core = { version = "0.8.0", default-features = false }
41+
frame-benchmarking = { version = "29.0.0", default-features = false }
42+
frame-support = { version = "29.0.0", default-features = false }
43+
frame-system = { version = "29.0.0", default-features = false }
44+
pallet-balances = { version = "29.0.0", default-features = false }
45+
pallet-elections-phragmen = { version = "30.0.0", default-features = false }
46+
pallet-message-queue = { version = "32.0.0", default-features = false }
47+
pallet-preimage = { version = "29.0.0", default-features = false }
48+
pallet-root-testing = { version = "5.0.0", default-features = false }
49+
pallet-scheduler = { version = "30.0.0", default-features = false }
50+
pallet-treasury = { version = "28.0.0", default-features = false }
51+
pallet-xcm = { version = "8.0.0", default-features = false }
52+
polkadot-parachain-primitives = { version = "7.0.0", default-features = false }
53+
polkadot-runtime-common = { version = "8.0.0", default-features = false }
54+
polkadot-runtime-parachains = { version = "8.0.0", default-features = false }
55+
sp-api = { version = "27.0.0", default-features = false }
56+
sp-application-crypto = { version = "31.0.0", default-features = false }
57+
sp-arithmetic = { version = "24.0.0", default-features = false }
58+
sp-core = { version = "29.0.0", default-features = false }
59+
sp-io = { version = "31.0.0", default-features = false }
60+
sp-runtime = { version = "32.0.0", default-features = false }
61+
sp-runtime-interface = { version = "25.0.0", default-features = false }
62+
sp-staking = { version = "27.0.0", default-features = false }
6363
sp-std = { version = "14.0.0", default-features = false }
64-
sp-storage = { version = "19.0.0", default-features = false }
65-
xcm = { package = "staging-xcm", version = "7.0.0", default-features = false }
66-
xcm-builder = { package = "staging-xcm-builder", version = "7.0.0", default-features = false }
67-
xcm-executor = { package = "staging-xcm-executor", version = "7.0.0", default-features = false }
64+
sp-storage = { version = "20.0.0", default-features = false }
65+
xcm = { package = "staging-xcm", version = "8.0.0", default-features = false }
66+
xcm-builder = { package = "staging-xcm-builder", version = "8.0.0", default-features = false }
67+
xcm-executor = { package = "staging-xcm-executor", version = "8.0.0", default-features = false }
6868

69-
xcm-simulator = { version = "7.0.0" }
69+
xcm-simulator = { version = "8.0.0" }

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The Open Runtime Module Library (ORML) is a community maintained collection of S
2424

2525
#### Tokens
2626
- [asset-registry](https://github.com/open-web3-stack/open-runtime-module-library/tree/master/asset-registry)
27-
- Register asset / token metadata including name, decimals, and XCM MultiLocation
27+
- Register asset / token metadata including name, decimals, and XCM Location
2828
- Partially based on the Acala’s asset-registry pallet, which includes some Acala specific code (e.g. EVM+) so not suitable for other teams.
2929
- [currencies](https://github.com/open-web3-stack/open-runtime-module-library/tree/master/currencies)
3030
- Provide an unified interface to combine pallet-balances and orml-tokens

asset-registry/src/impls.rs

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ use sp_runtime::{
1212
ArithmeticError, FixedU128,
1313
};
1414
use sp_std::prelude::*;
15-
use xcm::v3::{prelude::*, Weight as XcmWeight};
16-
use xcm::VersionedMultiLocation;
15+
use xcm::VersionedLocation;
16+
use xcm::{
17+
v3,
18+
v4::{prelude::*, Weight as XcmWeight},
19+
};
1720
use xcm_builder::TakeRevenue;
18-
use xcm_executor::{traits::WeightTrader, Assets};
21+
use xcm_executor::{traits::WeightTrader, AssetsInHolding};
1922

2023
/// Alias for AssetMetadata to improve readability (and to placate clippy)
2124
pub type DefaultAssetMetadata<T> =
@@ -54,7 +57,7 @@ where
5457
/// conversion rate.
5558
pub struct FixedRateAssetRegistryTrader<P: FixedConversionRateProvider>(PhantomData<P>);
5659
impl<P: FixedConversionRateProvider> WeightToFeeConverter for FixedRateAssetRegistryTrader<P> {
57-
fn convert_weight_to_fee(location: &MultiLocation, weight: Weight) -> Option<u128> {
60+
fn convert_weight_to_fee(location: &Location, weight: Weight) -> Option<u128> {
5861
let fee_per_second = P::get_fee_per_second(location)?;
5962
let weight_ratio = FixedU128::saturating_from_rational(weight.ref_time(), WEIGHT_REF_TIME_PER_SECOND);
6063
let amount = weight_ratio.saturating_mul_int(fee_per_second);
@@ -66,7 +69,7 @@ impl<P: FixedConversionRateProvider> WeightToFeeConverter for FixedRateAssetRegi
6669
/// bought weight.
6770
pub struct BoughtWeight {
6871
weight: Weight,
69-
asset_location: MultiLocation,
72+
asset_location: Location,
7073
amount: u128,
7174
}
7275

@@ -90,49 +93,53 @@ impl<W: WeightToFeeConverter, R: TakeRevenue> WeightTrader for AssetRegistryTrad
9093
}
9194
}
9295

93-
fn buy_weight(&mut self, weight: XcmWeight, payment: Assets, _context: &XcmContext) -> Result<Assets, XcmError> {
96+
fn buy_weight(
97+
&mut self,
98+
weight: XcmWeight,
99+
payment: AssetsInHolding,
100+
_context: &XcmContext,
101+
) -> Result<AssetsInHolding, XcmError> {
94102
log::trace!(
95103
target: "xcm::weight",
96104
"AssetRegistryTrader::buy_weight weight: {:?}, payment: {:?}",
97105
weight, payment,
98106
);
99107

100108
for (asset, _) in payment.fungible.iter() {
101-
if let AssetId::Concrete(ref location) = asset {
102-
if matches!(self.bought_weight, Some(ref bought) if &bought.asset_location != location) {
103-
// we already bought another asset - don't attempt to buy this one since
104-
// we won't be able to refund it
105-
continue;
109+
let AssetId(ref location) = asset;
110+
if matches!(self.bought_weight, Some(ref bought) if &bought.asset_location != location) {
111+
// we already bought another asset - don't attempt to buy this one since
112+
// we won't be able to refund it
113+
continue;
114+
}
115+
116+
if let Some(fee_increase) = W::convert_weight_to_fee(location, weight) {
117+
if fee_increase == 0 {
118+
// if the fee is set very low it could lead to zero fees, in which case
119+
// constructing the fee asset item to subtract from payment would fail.
120+
// Therefore, provide early exit
121+
return Ok(payment);
106122
}
107123

108-
if let Some(fee_increase) = W::convert_weight_to_fee(location, weight) {
109-
if fee_increase == 0 {
110-
// if the fee is set very low it could lead to zero fees, in which case
111-
// constructing the fee asset item to subtract from payment would fail.
112-
// Therefore, provide early exit
113-
return Ok(payment);
114-
}
115-
116-
if let Ok(unused) = payment.clone().checked_sub((*asset, fee_increase).into()) {
117-
let (existing_weight, existing_fee) = match self.bought_weight {
118-
Some(ref x) => (x.weight, x.amount),
119-
None => (Weight::zero(), 0),
120-
};
121-
122-
self.bought_weight = Some(BoughtWeight {
123-
amount: existing_fee.checked_add(fee_increase).ok_or(XcmError::Overflow)?,
124-
weight: existing_weight.checked_add(&weight).ok_or(XcmError::Overflow)?,
125-
asset_location: *location,
126-
});
127-
return Ok(unused);
128-
}
124+
if let Ok(unused) = payment.clone().checked_sub((asset.clone(), fee_increase).into()) {
125+
let (existing_weight, existing_fee) = match self.bought_weight {
126+
Some(ref x) => (x.weight, x.amount),
127+
None => (Weight::zero(), 0),
128+
};
129+
130+
self.bought_weight = Some(BoughtWeight {
131+
amount: existing_fee.checked_add(fee_increase).ok_or(XcmError::Overflow)?,
132+
weight: existing_weight.checked_add(&weight).ok_or(XcmError::Overflow)?,
133+
asset_location: location.clone(),
134+
});
135+
return Ok(unused);
129136
}
130137
}
131138
}
132139
Err(XcmError::TooExpensive)
133140
}
134141

135-
fn refund_weight(&mut self, weight: XcmWeight, _context: &XcmContext) -> Option<MultiAsset> {
142+
fn refund_weight(&mut self, weight: XcmWeight, _context: &XcmContext) -> Option<Asset> {
136143
log::trace!(target: "xcm::weight", "AssetRegistryTrader::refund_weight weight: {:?}", weight);
137144

138145
match self.bought_weight {
@@ -144,7 +151,7 @@ impl<W: WeightToFeeConverter, R: TakeRevenue> WeightTrader for AssetRegistryTrad
144151
bought.weight = new_weight;
145152
bought.amount = new_amount;
146153

147-
Some((AssetId::Concrete(bought.asset_location), refunded_amount).into())
154+
Some((AssetId(bought.asset_location.clone()), refunded_amount).into())
148155
}
149156
None => None, // nothing to refund
150157
}
@@ -154,7 +161,7 @@ impl<W: WeightToFeeConverter, R: TakeRevenue> WeightTrader for AssetRegistryTrad
154161
impl<W: WeightToFeeConverter, R: TakeRevenue> Drop for AssetRegistryTrader<W, R> {
155162
fn drop(&mut self) {
156163
if let Some(ref bought) = self.bought_weight {
157-
R::take_revenue((AssetId::Concrete(bought.asset_location), bought.amount).into());
164+
R::take_revenue((AssetId(bought.asset_location.clone()), bought.amount).into());
158165
}
159166
}
160167
}
@@ -180,22 +187,22 @@ impl<T: Config> Inspect for Pallet<T> {
180187
type CustomMetadata = T::CustomMetadata;
181188
type StringLimit = T::StringLimit;
182189

183-
fn asset_id(location: &MultiLocation) -> Option<Self::AssetId> {
184-
Pallet::<T>::location_to_asset_id(location)
190+
fn asset_id(location: &Location) -> Option<Self::AssetId> {
191+
Pallet::<T>::location_to_asset_id(v3::Location::try_from(location.clone()).ok()?)
185192
}
186193

187194
fn metadata(id: &Self::AssetId) -> Option<AssetMetadata<Self::Balance, Self::CustomMetadata, Self::StringLimit>> {
188195
Pallet::<T>::metadata(id)
189196
}
190197

191198
fn metadata_by_location(
192-
location: &MultiLocation,
199+
location: &Location,
193200
) -> Option<AssetMetadata<Self::Balance, Self::CustomMetadata, Self::StringLimit>> {
194-
Pallet::<T>::fetch_metadata_by_location(location)
201+
Pallet::<T>::fetch_metadata_by_location(&v3::Location::try_from(location.clone()).ok()?)
195202
}
196203

197-
fn location(asset_id: &Self::AssetId) -> Result<Option<MultiLocation>, DispatchError> {
198-
Pallet::<T>::multilocation(asset_id)
204+
fn location(asset_id: &Self::AssetId) -> Result<Option<Location>, DispatchError> {
205+
Pallet::<T>::location(asset_id).map(|l| l.and_then(|l| l.try_into().ok()))
199206
}
200207
}
201208

@@ -213,7 +220,7 @@ impl<T: Config> Mutate for Pallet<T> {
213220
name: Option<BoundedVec<u8, Self::StringLimit>>,
214221
symbol: Option<BoundedVec<u8, Self::StringLimit>>,
215222
existential_deposit: Option<Self::Balance>,
216-
location: Option<Option<VersionedMultiLocation>>,
223+
location: Option<Option<VersionedLocation>>,
217224
additional: Option<Self::CustomMetadata>,
218225
) -> DispatchResult {
219226
Pallet::<T>::do_update_asset(

asset-registry/src/lib.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ use sp_runtime::{
1414
DispatchResult,
1515
};
1616
use sp_std::prelude::*;
17-
use xcm::{v3::prelude::*, VersionedMultiLocation};
17+
use xcm::{v3::prelude::*, VersionedLocation};
1818

1919
pub use impls::*;
20-
pub use module::*;
20+
use module::*;
2121
pub use weights::WeightInfo;
2222

2323
mod impls;
@@ -67,7 +67,7 @@ pub mod module {
6767
pub enum Error<T> {
6868
/// Asset was not found.
6969
AssetNotFound,
70-
/// The version of the `VersionedMultiLocation` value used is not able
70+
/// The version of the `VersionedLocation` value used is not able
7171
/// to be interpreted.
7272
BadVersion,
7373
/// The asset id is invalid.
@@ -104,11 +104,11 @@ pub mod module {
104104
OptionQuery,
105105
>;
106106

107-
/// Maps a multilocation to an asset id - useful when processing xcm
107+
/// Maps a location to an asset id - useful when processing xcm
108108
/// messages.
109109
#[pallet::storage]
110110
#[pallet::getter(fn location_to_asset_id)]
111-
pub type LocationToAssetId<T: Config> = StorageMap<_, Twox64Concat, MultiLocation, T::AssetId, OptionQuery>;
111+
pub type LocationToAssetId<T: Config> = StorageMap<_, Twox64Concat, Location, T::AssetId, OptionQuery>;
112112

113113
/// The last processed asset id - used when assigning a sequential id.
114114
#[pallet::storage]
@@ -172,7 +172,7 @@ pub mod module {
172172
name: Option<BoundedVec<u8, T::StringLimit>>,
173173
symbol: Option<BoundedVec<u8, T::StringLimit>>,
174174
existential_deposit: Option<T::Balance>,
175-
location: Option<Option<VersionedMultiLocation>>,
175+
location: Option<Option<VersionedLocation>>,
176176
additional: Option<T::CustomMetadata>,
177177
) -> DispatchResult {
178178
T::AuthorityOrigin::ensure_origin(origin, &Some(asset_id.clone()))?;
@@ -239,7 +239,7 @@ impl<T: Config> Pallet<T> {
239239
name: Option<BoundedVec<u8, T::StringLimit>>,
240240
symbol: Option<BoundedVec<u8, T::StringLimit>>,
241241
existential_deposit: Option<T::Balance>,
242-
location: Option<Option<VersionedMultiLocation>>,
242+
location: Option<Option<VersionedLocation>>,
243243
additional: Option<T::CustomMetadata>,
244244
) -> DispatchResult {
245245
Metadata::<T>::try_mutate(&asset_id, |maybe_metadata| -> DispatchResult {
@@ -281,13 +281,13 @@ impl<T: Config> Pallet<T> {
281281
}
282282

283283
pub fn fetch_metadata_by_location(
284-
location: &MultiLocation,
284+
location: &Location,
285285
) -> Option<AssetMetadata<T::Balance, T::CustomMetadata, T::StringLimit>> {
286286
let asset_id = LocationToAssetId::<T>::get(location)?;
287287
Metadata::<T>::get(asset_id)
288288
}
289289

290-
pub fn multilocation(asset_id: &T::AssetId) -> Result<Option<MultiLocation>, DispatchError> {
290+
pub fn location(asset_id: &T::AssetId) -> Result<Option<Location>, DispatchError> {
291291
Metadata::<T>::get(asset_id)
292292
.and_then(|metadata| {
293293
metadata
@@ -300,14 +300,14 @@ impl<T: Config> Pallet<T> {
300300
/// update LocationToAssetId mapping if the location changed
301301
fn do_update_location(
302302
asset_id: T::AssetId,
303-
old_location: Option<VersionedMultiLocation>,
304-
new_location: Option<VersionedMultiLocation>,
303+
old_location: Option<VersionedLocation>,
304+
new_location: Option<VersionedLocation>,
305305
) -> DispatchResult {
306306
// Update `LocationToAssetId` only if location changed
307307
if new_location != old_location {
308308
// remove the old location lookup if it exists
309309
if let Some(ref old_location) = old_location {
310-
let location: MultiLocation = old_location.clone().try_into().map_err(|()| Error::<T>::BadVersion)?;
310+
let location: Location = old_location.clone().try_into().map_err(|()| Error::<T>::BadVersion)?;
311311
LocationToAssetId::<T>::remove(location);
312312
}
313313

@@ -321,9 +321,9 @@ impl<T: Config> Pallet<T> {
321321
}
322322

323323
/// insert location into the LocationToAssetId map
324-
fn do_insert_location(asset_id: T::AssetId, location: VersionedMultiLocation) -> DispatchResult {
324+
fn do_insert_location(asset_id: T::AssetId, location: VersionedLocation) -> DispatchResult {
325325
// if the metadata contains a location, set the LocationToAssetId
326-
let location: MultiLocation = location.try_into().map_err(|()| Error::<T>::BadVersion)?;
326+
let location: Location = location.try_into().map_err(|()| Error::<T>::BadVersion)?;
327327
LocationToAssetId::<T>::try_mutate(location, |maybe_asset_id| {
328328
ensure!(maybe_asset_id.is_none(), Error::<T>::ConflictingLocation);
329329
*maybe_asset_id = Some(asset_id);

0 commit comments

Comments
 (0)