Skip to content
This repository was archived by the owner on May 21, 2024. It is now read-only.

Commit 5b60204

Browse files
authored
Fix xcm reserve transfer from Rockmine <> Trappist. (#221)
* Fixing XCM values * Fixing comment * Adding needed helpers
1 parent f75f1c7 commit 5b60204

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

runtime/trappist/src/constants.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,14 @@ pub mod fee {
7272
}]
7373
}
7474
}
75+
76+
pub fn base_tx_fee() -> Balance {
77+
CENTS / 10
78+
}
79+
80+
pub fn default_fee_per_second() -> u128 {
81+
let base_weight = Balance::from(ExtrinsicBaseWeight::get().ref_time());
82+
let base_tx_per_second = (WEIGHT_REF_TIME_PER_SECOND as u128) / base_weight;
83+
base_tx_per_second * base_tx_fee()
84+
}
7585
}

runtime/trappist/src/weights/xcm/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ impl<Call> XcmWeightInfo<Call> for TrappistXcmWeight<Call> {
5555
fn withdraw_asset(assets: &MultiAssets) -> XCMWeight {
5656
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::withdraw_asset())
5757
}
58-
// Currently there is no trusted reserve
58+
// Hacked value to make the tests passing. This should be overwritten by the benchmarking
59+
// pallet.
5960
fn reserve_asset_deposited(_assets: &MultiAssets) -> XCMWeight {
60-
u64::MAX
61+
10_000u64.into()
6162
}
6263
fn receive_teleported_asset(assets: &MultiAssets) -> XCMWeight {
6364
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::receive_teleported_asset())

runtime/trappist/src/xcm_config.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
// See the License for the specific language governing permissions and
1616
// limitations under the License.
1717

18-
use crate::{impls::ToAuthor, weights::TrappistDropAssetsWeigher};
18+
use crate::{
19+
constants::fee::default_fee_per_second, impls::ToAuthor, weights::TrappistDropAssetsWeigher,
20+
};
1921

2022
use super::{
2123
AccountId, AssetRegistry, Assets, Balance, Balances, ParachainInfo, ParachainSystem,
@@ -43,11 +45,11 @@ use xcm::latest::{prelude::*, Fungibility::Fungible, MultiAsset, MultiLocation};
4345
use xcm_builder::{
4446
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
4547
AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, AsPrefixedGeneralIndex,
46-
ConvertedConcreteAssetId, CurrencyAdapter, EnsureXcmOrigin, FungiblesAdapter, IsConcrete,
47-
LocationInverter, NativeAsset, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative,
48-
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
49-
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,
50-
WeightInfoBounds,
48+
ConvertedConcreteAssetId, CurrencyAdapter, EnsureXcmOrigin, FixedRateOfFungible,
49+
FungiblesAdapter, IsConcrete, LocationInverter, NativeAsset, ParentAsSuperuser, ParentIsPreset,
50+
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
51+
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
52+
UsingComponents, WeightInfoBounds,
5153
};
5254
use xcm_executor::XcmExecutor;
5355

@@ -211,6 +213,14 @@ parameter_types! {
211213
// Rockmine's Assets pallet index
212214
pub RockmineAssetsPalletLocation: MultiLocation =
213215
MultiLocation::new(1, X2(Parachain(1000), PalletInstance(50)));
216+
217+
pub RUsdPerSecond: (xcm::v1::AssetId, u128) = (
218+
MultiLocation::new(1, X3(Parachain(1000), PalletInstance(50), GeneralIndex(1984))).into(),
219+
default_fee_per_second() * 10
220+
);
221+
/// Roc = 7 RUSD
222+
pub RocPerSecond: (xcm::v1::AssetId, u128) = (MultiLocation::parent().into(), default_fee_per_second() * 70);
223+
214224
}
215225

216226
//- From PR https://github.com/paritytech/cumulus/pull/936
@@ -237,7 +247,14 @@ impl<T: Get<MultiLocation>> FilterAssetLocation for ReserveAssetsFrom<T> {
237247
}
238248
}
239249

240-
//--
250+
pub type Traders = (
251+
// RUSD
252+
FixedRateOfFungible<RUsdPerSecond, ()>,
253+
// Roc
254+
FixedRateOfFungible<RocPerSecond, ()>,
255+
// Everything else
256+
UsingComponents<WeightToFee, SelfReserve, AccountId, Balances, ToAuthor<Runtime>>,
257+
);
241258

242259
pub type Reserves = (NativeAsset, ReserveAssetsFrom<RockmineLocation>);
243260

@@ -256,7 +273,7 @@ impl xcm_executor::Config for XcmConfig {
256273
RuntimeCall,
257274
MaxInstructions,
258275
>;
259-
type Trader = UsingComponents<WeightToFee, SelfReserve, AccountId, Balances, ToAuthor<Runtime>>;
276+
type Trader = Traders;
260277
type ResponseHandler = PolkadotXcm;
261278
type AssetTrap = TrappistDropAssets<
262279
AssetId,

0 commit comments

Comments
 (0)