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

Fix xcm reserve transfer from Rockmine <> Trappist. #221

Merged
merged 3 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions runtime/trappist/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,14 @@ pub mod fee {
}]
}
}

pub fn base_tx_fee() -> Balance {
CENTS / 10
}

pub fn default_fee_per_second() -> u128 {
let base_weight = Balance::from(ExtrinsicBaseWeight::get().ref_time());
let base_tx_per_second = (WEIGHT_REF_TIME_PER_SECOND as u128) / base_weight;
base_tx_per_second * base_tx_fee()
}
}
5 changes: 3 additions & 2 deletions runtime/trappist/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ impl<Call> XcmWeightInfo<Call> for TrappistXcmWeight<Call> {
fn withdraw_asset(assets: &MultiAssets) -> XCMWeight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::withdraw_asset())
}
// Currently there is no trusted reserve
// Hacked value to make the tests passing. This should be overwritten by the benchmarking
// pallet.
fn reserve_asset_deposited(_assets: &MultiAssets) -> XCMWeight {
u64::MAX
10_000u64.into()
}
fn receive_teleported_asset(assets: &MultiAssets) -> XCMWeight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::receive_teleported_asset())
Expand Down
33 changes: 25 additions & 8 deletions runtime/trappist/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::{impls::ToAuthor, weights::TrappistDropAssetsWeigher};
use crate::{
constants::fee::default_fee_per_second, impls::ToAuthor, weights::TrappistDropAssetsWeigher,
};

use super::{
AccountId, AssetRegistry, Assets, Balance, Balances, ParachainInfo, ParachainSystem,
Expand Down Expand Up @@ -43,11 +45,11 @@ use xcm::latest::{prelude::*, Fungibility::Fungible, MultiAsset, MultiLocation};
use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, AsPrefixedGeneralIndex,
ConvertedConcreteAssetId, CurrencyAdapter, EnsureXcmOrigin, FungiblesAdapter, IsConcrete,
LocationInverter, NativeAsset, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative,
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,
WeightInfoBounds,
ConvertedConcreteAssetId, CurrencyAdapter, EnsureXcmOrigin, FixedRateOfFungible,
FungiblesAdapter, IsConcrete, LocationInverter, NativeAsset, ParentAsSuperuser, ParentIsPreset,
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
UsingComponents, WeightInfoBounds,
};
use xcm_executor::XcmExecutor;

Expand Down Expand Up @@ -211,6 +213,14 @@ parameter_types! {
// Rockmine's Assets pallet index
pub RockmineAssetsPalletLocation: MultiLocation =
MultiLocation::new(1, X2(Parachain(1000), PalletInstance(50)));

pub RUsdPerSecond: (xcm::v1::AssetId, u128) = (
MultiLocation::new(1, X3(Parachain(1000), PalletInstance(50), GeneralIndex(1984))).into(),
default_fee_per_second() * 10
);
/// Roc = 7 RUSD
pub RocPerSecond: (xcm::v1::AssetId, u128) = (MultiLocation::parent().into(), default_fee_per_second() * 70);

}

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

//--
pub type Traders = (
// RUSD
FixedRateOfFungible<RUsdPerSecond, ()>,
// Roc
FixedRateOfFungible<RocPerSecond, ()>,
// Everything else
UsingComponents<WeightToFee, SelfReserve, AccountId, Balances, ToAuthor<Runtime>>,
);

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

Expand All @@ -256,7 +273,7 @@ impl xcm_executor::Config for XcmConfig {
RuntimeCall,
MaxInstructions,
>;
type Trader = UsingComponents<WeightToFee, SelfReserve, AccountId, Balances, ToAuthor<Runtime>>;
type Trader = Traders;
type ResponseHandler = PolkadotXcm;
type AssetTrap = TrappistDropAssets<
AssetId,
Expand Down