@@ -17,23 +17,22 @@ use sp_runtime::{
17
17
use cumulus_primitives_core:: { ChannelStatus , GetChannelInfo , ParaId } ;
18
18
use pallet_xcm:: XcmPassthrough ;
19
19
use polkadot_parachain:: primitives:: Sibling ;
20
- pub use xcm:: v0:: {
20
+ use xcm:: v0:: {
21
+ Error as XcmError ,
21
22
Junction :: { self , Parachain , Parent } ,
22
23
MultiAsset ,
23
- MultiLocation :: { self , X1 , X2 , X3 } ,
24
+ MultiLocation :: { self , X1 , X2 } ,
24
25
NetworkId , Xcm ,
25
26
} ;
26
- pub use xcm_builder:: {
27
- AccountId32Aliases , AllowTopLevelPaidExecutionFrom , AllowUnpaidExecutionFrom ,
28
- CurrencyAdapter as XcmCurrencyAdapter , EnsureXcmOrigin , FixedRateOfConcreteFungible , FixedWeightBounds , IsConcrete ,
29
- LocationInverter , NativeAsset , ParentAsSuperuser , ParentIsDefault , RelayChainAsNative , SiblingParachainAsNative ,
30
- SiblingParachainConvertsVia , SignedAccountId32AsNative , SignedToAccountId32 , SovereignSignedViaLocation ,
31
- TakeWeightCredit ,
27
+ use xcm_builder:: {
28
+ AccountId32Aliases , AllowTopLevelPaidExecutionFrom , EnsureXcmOrigin , FixedWeightBounds , LocationInverter ,
29
+ ParentIsDefault , RelayChainAsNative , SiblingParachainAsNative , SiblingParachainConvertsVia ,
30
+ SignedAccountId32AsNative , SignedToAccountId32 , SovereignSignedViaLocation , TakeWeightCredit ,
32
31
} ;
33
- use xcm_executor:: { Config , XcmExecutor } ;
32
+ use xcm_executor:: { traits :: WeightTrader , Assets , Config , XcmExecutor } ;
34
33
35
34
use orml_traits:: parameter_type_with_key;
36
- use orml_xcm_support:: { IsNativeConcrete , MultiCurrencyAdapter } ;
35
+ use orml_xcm_support:: { IsNativeConcrete , MultiCurrencyAdapter , MultiNativeAsset } ;
37
36
38
37
pub type AccountId = AccountId32 ;
39
38
@@ -132,7 +131,6 @@ pub type XcmOriginToCallOrigin = (
132
131
133
132
parameter_types ! {
134
133
pub const UnitWeightCost : Weight = 10 ;
135
- pub KsmPerSecond : ( MultiLocation , u128 ) = ( X1 ( Parent ) , 1_000 ) ;
136
134
}
137
135
138
136
pub type LocalAssetTransactor = MultiCurrencyAdapter <
@@ -146,20 +144,55 @@ pub type LocalAssetTransactor = MultiCurrencyAdapter<
146
144
> ;
147
145
148
146
pub type XcmRouter = ParachainXcmRouter < ParachainInfo > ;
149
- pub type Barrier = AllowUnpaidExecutionFrom < All < MultiLocation > > ;
147
+ pub type Barrier = ( TakeWeightCredit , AllowTopLevelPaidExecutionFrom < All < MultiLocation > > ) ;
148
+
149
+ /// A trader who believes all tokens are created equal to "weight" of any chain,
150
+ /// which is not true, but good enough to mock the fee payment of XCM execution.
151
+ ///
152
+ /// This mock will always trade `n` amount of weight to `n` amount of tokens.
153
+ pub struct AllTokensAreCreatedEqualToWeight ( MultiLocation ) ;
154
+ impl WeightTrader for AllTokensAreCreatedEqualToWeight {
155
+ fn new ( ) -> Self {
156
+ Self ( MultiLocation :: Null )
157
+ }
158
+
159
+ fn buy_weight ( & mut self , weight : Weight , payment : Assets ) -> Result < Assets , XcmError > {
160
+ let asset_id = payment
161
+ . fungible
162
+ . iter ( )
163
+ . next ( )
164
+ . expect ( "Payment must be something; qed" )
165
+ . 0 ;
166
+ let required = asset_id. clone ( ) . into_fungible_multiasset ( weight as u128 ) ;
167
+
168
+ if let MultiAsset :: ConcreteFungible { ref id, amount : _ } = required {
169
+ self . 0 = id. clone ( ) ;
170
+ }
171
+
172
+ let ( unused, _) = payment. less ( required) . map_err ( |_| XcmError :: TooExpensive ) ?;
173
+ Ok ( unused)
174
+ }
175
+
176
+ fn refund_weight ( & mut self , weight : Weight ) -> MultiAsset {
177
+ MultiAsset :: ConcreteFungible {
178
+ id : self . 0 . clone ( ) ,
179
+ amount : weight as u128 ,
180
+ }
181
+ }
182
+ }
150
183
151
184
pub struct XcmConfig ;
152
185
impl Config for XcmConfig {
153
186
type Call = Call ;
154
187
type XcmSender = XcmRouter ;
155
188
type AssetTransactor = LocalAssetTransactor ;
156
189
type OriginConverter = XcmOriginToCallOrigin ;
157
- type IsReserve = NativeAsset ;
190
+ type IsReserve = MultiNativeAsset ;
158
191
type IsTeleporter = ( ) ;
159
192
type LocationInverter = LocationInverter < Ancestry > ;
160
193
type Barrier = Barrier ;
161
194
type Weigher = FixedWeightBounds < UnitWeightCost , Call > ;
162
- type Trader = FixedRateOfConcreteFungible < KsmPerSecond , ( ) > ;
195
+ type Trader = AllTokensAreCreatedEqualToWeight ;
163
196
type ResponseHandler = ( ) ;
164
197
}
165
198
0 commit comments