diff --git a/Cargo.lock b/Cargo.lock index c74ee26837..600e72915e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4858,10 +4858,8 @@ dependencies = [ [[package]] name = "node-inspect" version = "0.8.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.8#1b758b2a8d151d97d2242260c465b6df9cb8a7a4" dependencies = [ "derive_more", - "log", "parity-scale-codec", "sc-cli", "sc-client-api", @@ -4875,8 +4873,10 @@ dependencies = [ [[package]] name = "node-inspect" version = "0.8.0" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.8#1b758b2a8d151d97d2242260c465b6df9cb8a7a4" dependencies = [ "derive_more", + "log", "parity-scale-codec", "sc-cli", "sc-client-api", diff --git a/node/primitives/src/lib.rs b/node/primitives/src/lib.rs index f2ffbd6caf..9dc57429ed 100644 --- a/node/primitives/src/lib.rs +++ b/node/primitives/src/lib.rs @@ -30,11 +30,13 @@ mod bridge; mod currency; mod tests; pub mod traits; +mod xcm; pub use crate::{ bridge::*, currency::{CurrencyId, TokenSymbol}, traits::*, + xcm::*, }; /// An index to a block. diff --git a/node/primitives/src/xcm.rs b/node/primitives/src/xcm.rs new file mode 100644 index 0000000000..ff0a0dba0f --- /dev/null +++ b/node/primitives/src/xcm.rs @@ -0,0 +1,42 @@ +// This file is part of Bifrost. + +// Copyright (C) 2019-2021 Liebi Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use codec::{Decode, Encode}; +use sp_std::prelude::*; + +/// The type used to represent the xcmp transfer direction +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode)] +pub enum TransferOriginType { + FromSelf = 0, + FromRelayChain = 1, + FromSiblingParaChain = 2, +} + +pub struct XcmBaseWeight(u64); + +impl From for XcmBaseWeight { + fn from(u: u64) -> Self { + XcmBaseWeight(u) + } +} + +impl From for u64 { + fn from(x: XcmBaseWeight) -> Self { + x.0.into() + } +} diff --git a/pallets/salp/src/lib.rs b/pallets/salp/src/lib.rs index 08f7d746b1..337ad0f6b8 100644 --- a/pallets/salp/src/lib.rs +++ b/pallets/salp/src/lib.rs @@ -220,7 +220,7 @@ pub mod pallet { PalletId, }; use frame_system::pallet_prelude::*; - use node_primitives::{BancorHandler, CurrencyId, LeasePeriod, ParaId}; + use node_primitives::{BancorHandler, CurrencyId, LeasePeriod, ParaId, TransferOriginType}; use orml_traits::{currency::TransferAll, MultiCurrency, MultiReservableCurrency}; use polkadot_parachain::primitives::Id as PolkadotParaId; use sp_arithmetic::Percent; @@ -292,6 +292,9 @@ pub mod pallet { type BifrostXcmExecutor: BifrostXcmExecutor; + #[pallet::constant] + type XcmTransferOrigin: Get; + /// Weight information for the extrinsics in this module. type WeightInfo: WeightInfo; } @@ -423,17 +426,21 @@ pub mod pallet { #[pallet::call] impl Pallet { - #[pallet::weight(0)] + #[pallet::weight(( + 0, + DispatchClass::Normal, + Pays::No + ))] pub fn fund_success( origin: OriginFor, #[pallet::compact] index: ParaId, ) -> DispatchResult { - let depositor = ensure_signed(origin)?; + let owner = ensure_signed(origin)?; let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; ensure!(fund.status == FundStatus::Ongoing, Error::::InvalidFundStatus); - ensure!(depositor == fund.depositor, Error::::UnauthorizedAccount); + ensure!(owner == fund.depositor, Error::::UnauthorizedAccount); let fund_new = FundInfo { status: FundStatus::Success, ..fund }; Funds::::insert(index, Some(fund_new)); @@ -441,15 +448,19 @@ pub mod pallet { Ok(()) } - #[pallet::weight(0)] + #[pallet::weight(( + 0, + DispatchClass::Normal, + Pays::No + ))] pub fn fund_fail(origin: OriginFor, #[pallet::compact] index: ParaId) -> DispatchResult { - let depositor = ensure_signed(origin)?; + let owner = ensure_signed(origin)?; // crownload is failed, so enable the withdrawal function of vsToken/vsBond let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; ensure!(fund.status == FundStatus::Ongoing, Error::::InvalidFundStatus); - ensure!(depositor == fund.depositor, Error::::UnauthorizedAccount); + ensure!(owner == fund.depositor, Error::::UnauthorizedAccount); let fund_new = FundInfo { status: FundStatus::Failed, ..fund }; Funds::::insert(index, Some(fund_new)); @@ -457,17 +468,21 @@ pub mod pallet { Ok(()) } - #[pallet::weight(0)] + #[pallet::weight(( + 0, + DispatchClass::Normal, + Pays::No + ))] pub fn fund_retire( origin: OriginFor, #[pallet::compact] index: ParaId, ) -> DispatchResult { - let depositor = ensure_signed(origin)?; + let owner = ensure_signed(origin)?; let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; ensure!(fund.status == FundStatus::Success, Error::::InvalidFundStatus); - ensure!(depositor == fund.depositor, Error::::UnauthorizedAccount); + ensure!(owner == fund.depositor, Error::::UnauthorizedAccount); let fund_new = FundInfo { status: FundStatus::Retired, ..fund }; Funds::::insert(index, Some(fund_new)); @@ -475,9 +490,13 @@ pub mod pallet { Ok(()) } - #[pallet::weight(0)] + #[pallet::weight(( + 0, + DispatchClass::Normal, + Pays::No + ))] pub fn fund_end(origin: OriginFor, #[pallet::compact] index: ParaId) -> DispatchResult { - let depositor = ensure_signed(origin)?; + let owner = ensure_signed(origin)?; let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; ensure!( @@ -486,7 +505,7 @@ pub mod pallet { Error::::InvalidFundStatus ); - ensure!(depositor == fund.depositor, Error::::UnauthorizedAccount); + ensure!(owner == fund.depositor, Error::::UnauthorizedAccount); let fund_new = FundInfo { status: FundStatus::End, ..fund }; Funds::::insert(index, Some(fund_new)); @@ -495,7 +514,11 @@ pub mod pallet { } /// Unlock the reserved vsToken/vsBond after fund success - #[pallet::weight(0)] + #[pallet::weight(( + 0, + DispatchClass::Normal, + Pays::No + ))] pub fn unlock( _origin: OriginFor, who: AccountIdOf, @@ -535,7 +558,11 @@ pub mod pallet { /// TODO: Refactor the docs. /// Create a new crowdloaning campaign for a parachain slot deposit for the current auction. - #[pallet::weight(T::WeightInfo::create())] + #[pallet::weight(( + 0, + DispatchClass::Normal, + Pays::No + ))] pub fn create( origin: OriginFor, #[pallet::compact] index: ParaId, @@ -543,7 +570,7 @@ pub mod pallet { #[pallet::compact] first_slot: LeasePeriod, #[pallet::compact] last_slot: LeasePeriod, ) -> DispatchResult { - let depositor = ensure_signed(origin)?; + let owner = ensure_signed(origin)?; ensure!(!Funds::::contains_key(index), Error::::FundAlreadyCreated); @@ -556,12 +583,12 @@ pub mod pallet { let deposit = T::SubmissionDeposit::get(); - T::MultiCurrency::reserve(T::DepositToken::get(), &depositor, deposit)?; + T::MultiCurrency::reserve(T::DepositToken::get(), &owner, deposit)?; Funds::::insert( index, Some(FundInfo { - depositor, + depositor: owner, deposit, raised: Zero::zero(), cap, @@ -581,7 +608,11 @@ pub mod pallet { /// Contribute to a crowd sale. This will transfer some balance over to fund a parachain /// slot. It will be withdrawable in two instances: the parachain becomes retired; or the /// slot is unable to be purchased and the timeout expires. - #[pallet::weight(T::WeightInfo::contribute())] + #[pallet::weight(( + 0, + DispatchClass::Normal, + Pays::No + ))] pub fn contribute( origin: OriginFor, #[pallet::compact] index: ParaId, @@ -615,14 +646,18 @@ pub mod pallet { } /// Confirm contribute - #[pallet::weight(0)] + #[pallet::weight(( + 0, + DispatchClass::Normal, + Pays::No + ))] pub fn confirm_contribute( origin: OriginFor, who: AccountIdOf, #[pallet::compact] index: ParaId, is_success: bool, ) -> DispatchResult { - let depositor = ensure_signed(origin)?; + let owner = ensure_signed(origin)?; let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; let can_confirm = fund.status == FundStatus::Ongoing || @@ -630,7 +665,7 @@ pub mod pallet { fund.status == FundStatus::Success; ensure!(can_confirm, Error::::InvalidFundStatus); - ensure!(depositor == fund.depositor, Error::::UnauthorizedAccount); + ensure!(owner == fund.depositor, Error::::UnauthorizedAccount); let (contributed, status) = Self::contribution(fund.trie_index, &who); ensure!(status.is_contributing(), Error::::InvalidContributionStatus); @@ -651,6 +686,10 @@ pub mod pallet { FundInfo { raised: fund.raised.saturating_add(contributing), ..fund }; Funds::::insert(index, Some(fund_new)); + if T::XcmTransferOrigin::get() == TransferOriginType::FromRelayChain { + T::MultiCurrency::withdraw(T::RelayChainToken::get(), &who, contributing)?; + } + // Update the contribution of who let contributed_new = contributed.saturating_add(contributing); Self::put_contribution( @@ -679,37 +718,45 @@ pub mod pallet { /// Withdraw full balance of the parachain. this function may need to be called multiple /// times /// - `index`: The parachain to whose crowdloan the contribution was made. - #[pallet::weight(0)] + #[pallet::weight(( + 0, + DispatchClass::Normal, + Pays::No + ))] pub fn withdraw(origin: OriginFor, #[pallet::compact] index: ParaId) -> DispatchResult { - let depositor = ensure_signed(origin.clone())?; + let owner = ensure_signed(origin.clone())?; let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; let can = fund.status == FundStatus::Failed || fund.status == FundStatus::Retired; ensure!(can, Error::::InvalidFundStatus); - ensure!(depositor == fund.depositor, Error::::UnauthorizedAccount); + ensure!(owner == fund.depositor, Error::::UnauthorizedAccount); - Self::xcm_ump_withdraw(origin, index).map_err(|_| Error::::XcmFailed)?; + Self::xcm_ump_withdraw(index).map_err(|_| Error::::XcmFailed)?; - Self::deposit_event(Event::Withdrawing(depositor, index, fund.raised)); + Self::deposit_event(Event::Withdrawing(owner, index, fund.raised)); Ok(()) } /// Confirm withdraw by fund owner temporarily - #[pallet::weight(0)] + #[pallet::weight(( + 0, + DispatchClass::Normal, + Pays::No + ))] pub fn confirm_withdraw( origin: OriginFor, #[pallet::compact] index: ParaId, is_success: bool, ) -> DispatchResult { - let depositor = ensure_signed(origin)?; + let owner = ensure_signed(origin)?; let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; let can = fund.status == FundStatus::Failed || fund.status == FundStatus::Retired; ensure!(can, Error::::InvalidFundStatus); - ensure!(depositor == fund.depositor, Error::::UnauthorizedAccount); + ensure!(owner == fund.depositor, Error::::UnauthorizedAccount); let amount_withdrew = fund.raised; @@ -726,15 +773,19 @@ pub mod pallet { Funds::::insert(index, Some(fund_new)); } - Self::deposit_event(Event::Withdrew(depositor, index, amount_withdrew)); + Self::deposit_event(Event::Withdrew(owner, index, amount_withdrew)); } else { - Self::deposit_event(Event::WithdrawFailed(depositor, index, amount_withdrew)); + Self::deposit_event(Event::WithdrawFailed(owner, index, amount_withdrew)); } Ok(()) } - #[pallet::weight(0)] + #[pallet::weight(( + 0, + DispatchClass::Normal, + Pays::No + ))] pub fn refund(origin: OriginFor, #[pallet::compact] index: ParaId) -> DispatchResult { let who = ensure_signed(origin.clone())?; @@ -758,8 +809,7 @@ pub mod pallet { Error::::NotEnoughReservedAssetsToRefund ); - Self::xcm_ump_transfer(origin, index, contributed) - .map_err(|_| Error::::XcmFailed)?; + Self::xcm_ump_redeem(origin, index, contributed).map_err(|_| Error::::XcmFailed)?; RefundPool::::set(Self::refund_pool().saturating_sub(contributed)); @@ -775,19 +825,23 @@ pub mod pallet { Ok(()) } - #[pallet::weight(0)] + #[pallet::weight(( + 0, + DispatchClass::Normal, + Pays::No + ))] pub fn confirm_refund( origin: OriginFor, who: AccountIdOf, #[pallet::compact] index: ParaId, is_success: bool, ) -> DispatchResult { - let depositor = ensure_signed(origin)?; + let owner = ensure_signed(origin)?; let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; ensure!(fund.status == FundStatus::RefundWithdrew, Error::::InvalidFundStatus); - ensure!(depositor == fund.depositor, Error::::UnauthorizedAccount); + ensure!(owner == fund.depositor, Error::::UnauthorizedAccount); let (contributed, status) = Self::contribution(fund.trie_index, &who); ensure!(status == ContributionStatus::Refunding, Error::::InvalidContributionStatus); @@ -826,7 +880,11 @@ pub mod pallet { Ok(()) } - #[pallet::weight(0)] + #[pallet::weight(( + 0, + DispatchClass::Normal, + Pays::No + ))] pub fn redeem( origin: OriginFor, #[pallet::compact] index: ParaId, @@ -840,8 +898,9 @@ pub mod pallet { let cur_block = >::block_number(); ensure!(!Self::is_expired(cur_block, last_slot), Error::::VSBondExpired); - ensure!(Self::can_redeem(cur_block, last_slot), Error::::UnRedeemableNow); - + if T::XcmTransferOrigin::get() != TransferOriginType::FromRelayChain { + ensure!(Self::can_redeem(cur_block, last_slot), Error::::UnRedeemableNow); + } #[allow(non_snake_case)] let (vsToken, vsBond) = Self::vsAssets(index, first_slot, last_slot); @@ -853,7 +912,7 @@ pub mod pallet { let status = Self::redeem_status(who.clone(), (index, first_slot, last_slot)); ensure!(status == RedeemStatus::Idle, Error::::InvalidRedeemStatus); - Self::xcm_ump_transfer(origin.clone(), index, value) + Self::xcm_ump_redeem(origin.clone(), index, value) .map_err(|_| Error::::XcmFailed)?; RedeemPool::::set(Self::redeem_pool().saturating_sub(value)); @@ -869,7 +928,11 @@ pub mod pallet { Ok(()) } - #[pallet::weight(0)] + #[pallet::weight(( + 0, + DispatchClass::Normal, + Pays::No + ))] pub fn confirm_redeem( origin: OriginFor, who: AccountIdOf, @@ -921,7 +984,11 @@ pub mod pallet { } /// Remove a fund after the retirement period has ended and all funds have been returned. - #[pallet::weight(0)] + #[pallet::weight(( + 0, + DispatchClass::Normal, + Pays::No + ))] pub fn dissolve(origin: OriginFor, #[pallet::compact] index: ParaId) -> DispatchResult { let depositor = ensure_signed(origin)?; @@ -1084,14 +1151,11 @@ pub mod pallet { } fn xcm_ump_contribute( - origin: OriginFor, + _origin: OriginFor, index: ParaId, value: BalanceOf, ) -> XcmResult { - let origin_location: MultiLocation = - T::ExecuteXcmOrigin::ensure_origin(origin).map_err(|_e| XcmError::BadOrigin)?; - - let contribution = Contribution { index, value: value.clone(), signature: None }; + let contribution = Contribution { index, value, signature: None }; let call = CrowdloanContributeCall::CrowdloanContribute(ContributeCall::Contribute( contribution, @@ -1099,32 +1163,29 @@ pub mod pallet { .encode() .into(); - let amount = TryInto::::try_into(value).map_err(|_| XcmError::Unimplemented)?; - - let _result = T::BifrostXcmExecutor::ump_transfer_asset( - origin_location.clone(), + T::BifrostXcmExecutor::ump_transact( MultiLocation::X1(Junction::Parachain(index)), - amount, - true, - )?; - - T::BifrostXcmExecutor::ump_transact(origin_location, call) + call, + false, + ) } - fn xcm_ump_withdraw(origin: OriginFor, index: ParaId) -> XcmResult { - let origin_location: MultiLocation = - T::ExecuteXcmOrigin::ensure_origin(origin).map_err(|_e| XcmError::BadOrigin)?; - + fn xcm_ump_withdraw(index: ParaId) -> XcmResult { let who: AccountIdOf = PolkadotParaId::from(index).into_account(); let withdraw = Withdraw { who, index }; let call = CrowdloanWithdrawCall::CrowdloanWithdraw(WithdrawCall::Withdraw(withdraw)) .encode() .into(); - T::BifrostXcmExecutor::ump_transact(origin_location, call) + + T::BifrostXcmExecutor::ump_transact( + MultiLocation::X1(Junction::Parachain(index)), + call, + false, + ) } - fn xcm_ump_transfer(origin: OriginFor, index: ParaId, value: BalanceOf) -> XcmResult { + fn xcm_ump_redeem(origin: OriginFor, index: ParaId, value: BalanceOf) -> XcmResult { let origin_location: MultiLocation = T::ExecuteXcmOrigin::ensure_origin(origin).map_err(|_e| XcmError::BadOrigin)?; diff --git a/pallets/salp/src/mock.rs b/pallets/salp/src/mock.rs index 07105fc7c1..79c1967445 100644 --- a/pallets/salp/src/mock.rs +++ b/pallets/salp/src/mock.rs @@ -19,7 +19,7 @@ // Ensure we're `no_std` when compiling for Wasm. use frame_support::{construct_runtime, parameter_types, traits::GenesisBuild, PalletId}; -use node_primitives::{Amount, Balance, CurrencyId, TokenSymbol}; +use node_primitives::{Amount, Balance, CurrencyId, TokenSymbol, TransferOriginType}; use sp_arithmetic::Percent; use sp_core::H256; use sp_runtime::{ @@ -168,6 +168,7 @@ parameter_types! { pub const ReleaseCycle: BlockNumber = 1 * DAYS; pub const ReleaseRatio: Percent = Percent::from_percent(50); pub const DepositTokenType: CurrencyId = CurrencyId::Token(TokenSymbol::ASG); + pub const XcmTransferOrigin: TransferOriginType = TransferOriginType::FromSelf; } parameter_types! { @@ -193,6 +194,7 @@ impl salp::Config for Test { type SlotLength = SlotLength; type SubmissionDeposit = SubmissionDeposit; type VSBondValidPeriod = VSBondValidPeriod; + type XcmTransferOrigin = XcmTransferOrigin; type WeightInfo = salp::TestWeightInfo; } @@ -203,7 +205,7 @@ pub(crate) static mut MOCK_XCM_RESULT: (bool, bool) = (true, true); pub struct MockXcmExecutor; impl BifrostXcmExecutor for MockXcmExecutor { - fn ump_transact(_origin: MultiLocation, _call: DoubleEncoded<()>) -> XcmResult { + fn ump_transact(_origin: MultiLocation, _call: DoubleEncoded<()>, _relayer: bool) -> XcmResult { let result = unsafe { MOCK_XCM_RESULT.0 }; match result { @@ -229,12 +231,16 @@ impl BifrostXcmExecutor for MockXcmExecutor { pub(crate) fn new_test_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + let initial_balance = 100000 as u128; orml_tokens::GenesisConfig:: { balances: vec![ - (ALICE, NativeCurrencyId::get(), 100), - (BRUCE, NativeCurrencyId::get(), 100), - (CATHI, NativeCurrencyId::get(), 100), + (ALICE, NativeCurrencyId::get(), initial_balance), + (ALICE, RelayCurrencyId::get(), initial_balance), + (BRUCE, NativeCurrencyId::get(), initial_balance), + (BRUCE, RelayCurrencyId::get(), initial_balance), + (CATHI, NativeCurrencyId::get(), initial_balance), + (CATHI, RelayCurrencyId::get(), initial_balance), ], } .assimilate_storage(&mut t) diff --git a/runtime/asgard/src/constants.rs b/runtime/asgard/src/constants.rs index 07b5bd5233..a5578d062e 100644 --- a/runtime/asgard/src/constants.rs +++ b/runtime/asgard/src/constants.rs @@ -28,6 +28,7 @@ pub mod currency { pub const MILLICENTS: Balance = CENTS / 1_000; pub const MILLIBNC: Balance = 1_000_000_000; pub const MICROBNC: Balance = 1_000_000; + pub const XCM_WEIGHT: u64 = 1_000_000_000; pub const fn deposit(items: u32, bytes: u32) -> Balance { items as Balance * 15 * CENTS + (bytes as Balance) * 6 * CENTS diff --git a/runtime/asgard/src/lib.rs b/runtime/asgard/src/lib.rs index 21d1179f19..81fa9179b7 100644 --- a/runtime/asgard/src/lib.rs +++ b/runtime/asgard/src/lib.rs @@ -75,7 +75,9 @@ use bifrost_runtime_common::xcm_impl::{ use codec::{Decode, Encode}; use constants::{currency::*, time::*}; use cumulus_primitives_core::ParaId as CumulusParaId; -use node_primitives::{Amount, CurrencyId, Moment, Nonce, TokenSymbol}; +use node_primitives::{ + Amount, CurrencyId, Moment, Nonce, TokenSymbol, TransferOriginType, XcmBaseWeight, +}; // orml imports use orml_currencies::BasicCurrencyAdapter; use orml_traits::MultiCurrency; @@ -751,8 +753,7 @@ pub type BifrostAssetTransactor = BifrostCurrencyAdapter< pub struct XcmConfig; impl Config for XcmConfig { - // How to withdraw and deposit an asset.(upgrade to BifrostAssetTransactor later) - type AssetTransactor = LocalAssetTransactor; + type AssetTransactor = BifrostAssetTransactor; type Barrier = Barrier; type Call = Call; type IsReserve = BifrostFilteredAssets; @@ -940,11 +941,13 @@ parameter_types! { pub const LeasePeriod: BlockNumber = KUSAMA_LEASE_PERIOD; pub const ReleaseRatio: Percent = Percent::from_percent(50); pub const SlotLength: BlockNumber = 8u32 as BlockNumber; + pub const XcmTransferOrigin: TransferOriginType = TransferOriginType::FromRelayChain; + pub XcmWeight: XcmBaseWeight = XCM_WEIGHT.into(); } impl bifrost_salp::Config for Runtime { type BancorPool = Bancor; - type BifrostXcmExecutor = BifrostXcmAdaptor; + type BifrostXcmExecutor = BifrostXcmAdaptor; type DepositToken = NativeCurrencyId; type Event = Event; type ExecuteXcmOrigin = EnsureXcmOrigin; @@ -959,6 +962,7 @@ impl bifrost_salp::Config for Runtime { type SlotLength = SlotLength; type SubmissionDeposit = SubmissionDeposit; type VSBondValidPeriod = VSBondValidPeriod; + type XcmTransferOrigin = XcmTransferOrigin; type WeightInfo = weights::pallet_salp::WeightInfo; // bifrost_salp::TestWeightInfo; } diff --git a/xcm-support/src/lib.rs b/xcm-support/src/lib.rs index 9c44b02ea9..114329703e 100644 --- a/xcm-support/src/lib.rs +++ b/xcm-support/src/lib.rs @@ -48,6 +48,7 @@ use xcm::{ use xcm_executor::traits::{Convert as xcmConvert, MatchesFungible, TransactAsset}; pub use xcm_executor::XcmExecutor; mod traits; +pub use node_primitives::XcmBaseWeight; pub use traits::{BifrostXcmExecutor, HandleDmpMessage, HandleUmpMessage, HandleXcmpMessage}; #[cfg(test)] @@ -149,16 +150,22 @@ impl< } } -pub struct BifrostXcmAdaptor(PhantomData); +pub struct BifrostXcmAdaptor(PhantomData<(XcmSender, BaseXcmWeight)>); -impl BifrostXcmExecutor for BifrostXcmAdaptor { - fn ump_transact(_origin: MultiLocation, call: DoubleEncoded<()>) -> XcmResult { - let message = Xcm::Transact { +impl> BifrostXcmExecutor + for BifrostXcmAdaptor +{ + fn ump_transact(origin: MultiLocation, call: DoubleEncoded<()>, relay: bool) -> XcmResult { + let mut message = Xcm::Transact { origin_type: OriginKind::SovereignAccount, require_weight_at_most: u64::MAX, call, }; + if relay { + message = Xcm::<()>::RelayedFrom { who: origin, message: Box::new(message) }; + } + XcmSender::send_xcm(MultiLocation::X1(Junction::Parent), message) } @@ -168,9 +175,18 @@ impl BifrostXcmExecutor for BifrostXcmAdaptor { amount: u128, relay: bool, ) -> XcmResult { - let mut message = Xcm::TransferAsset { + let mut message = Xcm::WithdrawAsset { assets: vec![MultiAsset::ConcreteFungible { id: MultiLocation::Null, amount }], - dest, + effects: vec![ + Order::BuyExecution { + fees: MultiAsset::All, + weight: 0, + debt: 3 * BaseXcmWeight::get(), + halt_on_error: false, + xcm: vec![], + }, + DepositAsset { assets: vec![All], dest }, + ], }; if relay { diff --git a/xcm-support/src/traits.rs b/xcm-support/src/traits.rs index 8fe40cc02b..798c8b3079 100644 --- a/xcm-support/src/traits.rs +++ b/xcm-support/src/traits.rs @@ -43,7 +43,7 @@ pub trait HandleXcmpMessage { /// Bifrost Xcm Executor pub trait BifrostXcmExecutor { - fn ump_transact(origin: MultiLocation, call: DoubleEncoded<()>) -> XcmResult; + fn ump_transact(origin: MultiLocation, call: DoubleEncoded<()>, relay: bool) -> XcmResult; fn ump_transfer_asset( origin: MultiLocation,