@@ -12,10 +12,13 @@ use sp_runtime::{
12
12
ArithmeticError , FixedU128 ,
13
13
} ;
14
14
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
+ } ;
17
20
use xcm_builder:: TakeRevenue ;
18
- use xcm_executor:: { traits:: WeightTrader , Assets } ;
21
+ use xcm_executor:: { traits:: WeightTrader , AssetsInHolding } ;
19
22
20
23
/// Alias for AssetMetadata to improve readability (and to placate clippy)
21
24
pub type DefaultAssetMetadata < T > =
54
57
/// conversion rate.
55
58
pub struct FixedRateAssetRegistryTrader < P : FixedConversionRateProvider > ( PhantomData < P > ) ;
56
59
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 > {
58
61
let fee_per_second = P :: get_fee_per_second ( location) ?;
59
62
let weight_ratio = FixedU128 :: saturating_from_rational ( weight. ref_time ( ) , WEIGHT_REF_TIME_PER_SECOND ) ;
60
63
let amount = weight_ratio. saturating_mul_int ( fee_per_second) ;
@@ -66,7 +69,7 @@ impl<P: FixedConversionRateProvider> WeightToFeeConverter for FixedRateAssetRegi
66
69
/// bought weight.
67
70
pub struct BoughtWeight {
68
71
weight : Weight ,
69
- asset_location : MultiLocation ,
72
+ asset_location : Location ,
70
73
amount : u128 ,
71
74
}
72
75
@@ -90,49 +93,53 @@ impl<W: WeightToFeeConverter, R: TakeRevenue> WeightTrader for AssetRegistryTrad
90
93
}
91
94
}
92
95
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 > {
94
102
log:: trace!(
95
103
target: "xcm::weight" ,
96
104
"AssetRegistryTrader::buy_weight weight: {:?}, payment: {:?}" ,
97
105
weight, payment,
98
106
) ;
99
107
100
108
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) ;
106
122
}
107
123
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) ;
129
136
}
130
137
}
131
138
}
132
139
Err ( XcmError :: TooExpensive )
133
140
}
134
141
135
- fn refund_weight ( & mut self , weight : XcmWeight , _context : & XcmContext ) -> Option < MultiAsset > {
142
+ fn refund_weight ( & mut self , weight : XcmWeight , _context : & XcmContext ) -> Option < Asset > {
136
143
log:: trace!( target: "xcm::weight" , "AssetRegistryTrader::refund_weight weight: {:?}" , weight) ;
137
144
138
145
match self . bought_weight {
@@ -144,7 +151,7 @@ impl<W: WeightToFeeConverter, R: TakeRevenue> WeightTrader for AssetRegistryTrad
144
151
bought. weight = new_weight;
145
152
bought. amount = new_amount;
146
153
147
- Some ( ( AssetId :: Concrete ( bought. asset_location ) , refunded_amount) . into ( ) )
154
+ Some ( ( AssetId ( bought. asset_location . clone ( ) ) , refunded_amount) . into ( ) )
148
155
}
149
156
None => None , // nothing to refund
150
157
}
@@ -154,7 +161,7 @@ impl<W: WeightToFeeConverter, R: TakeRevenue> WeightTrader for AssetRegistryTrad
154
161
impl < W : WeightToFeeConverter , R : TakeRevenue > Drop for AssetRegistryTrader < W , R > {
155
162
fn drop ( & mut self ) {
156
163
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 ( ) ) ;
158
165
}
159
166
}
160
167
}
@@ -180,22 +187,22 @@ impl<T: Config> Inspect for Pallet<T> {
180
187
type CustomMetadata = T :: CustomMetadata ;
181
188
type StringLimit = T :: StringLimit ;
182
189
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 ( ) ? )
185
192
}
186
193
187
194
fn metadata ( id : & Self :: AssetId ) -> Option < AssetMetadata < Self :: Balance , Self :: CustomMetadata , Self :: StringLimit > > {
188
195
Pallet :: < T > :: metadata ( id)
189
196
}
190
197
191
198
fn metadata_by_location (
192
- location : & MultiLocation ,
199
+ location : & Location ,
193
200
) -> 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 ( ) ? )
195
202
}
196
203
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 ( ) ) )
199
206
}
200
207
}
201
208
@@ -213,7 +220,7 @@ impl<T: Config> Mutate for Pallet<T> {
213
220
name : Option < BoundedVec < u8 , Self :: StringLimit > > ,
214
221
symbol : Option < BoundedVec < u8 , Self :: StringLimit > > ,
215
222
existential_deposit : Option < Self :: Balance > ,
216
- location : Option < Option < VersionedMultiLocation > > ,
223
+ location : Option < Option < VersionedLocation > > ,
217
224
additional : Option < Self :: CustomMetadata > ,
218
225
) -> DispatchResult {
219
226
Pallet :: < T > :: do_update_asset (
0 commit comments