diff --git a/Cargo.lock b/Cargo.lock index 1e3aef955b..bc97c5bfb1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -237,8 +237,10 @@ dependencies = [ "parachain-info", "parity-scale-codec", "polkadot-parachain", + "polkadot-primitives", "polkadot-runtime-parachains", "serde", + "smallvec 1.6.1", "sp-api", "sp-arithmetic", "sp-block-builder", @@ -879,6 +881,7 @@ dependencies = [ "pallet-xcm", "parity-scale-codec", "polkadot-parachain", + "smallvec 1.6.1", "sp-arithmetic", "sp-core", "sp-io", @@ -2213,8 +2216,10 @@ dependencies = [ "parachain-info", "parity-scale-codec", "polkadot-parachain", + "polkadot-primitives", "polkadot-runtime-parachains", "serde", + "smallvec 1.6.1", "sp-api", "sp-arithmetic", "sp-block-builder", diff --git a/pallets/salp/Cargo.toml b/pallets/salp/Cargo.toml index 02b9cfd8f9..3c3c09e1e8 100644 --- a/pallets/salp/Cargo.toml +++ b/pallets/salp/Cargo.toml @@ -25,8 +25,10 @@ polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-f xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.8" } pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.8" } pallet-multisig = { version = "3.0.0"} +smallvec = "1.6.1" sp-io = "3.0.0" sp-core = "3.0.0" +sp-runtime = "3.0.0" orml-tokens = "0.4.1-dev" orml-currencies = "0.4.1-dev" pallet-balances = "3.0.0" diff --git a/pallets/salp/src/lib.rs b/pallets/salp/src/lib.rs index 0b58b64acc..db320b98c3 100644 --- a/pallets/salp/src/lib.rs +++ b/pallets/salp/src/lib.rs @@ -33,7 +33,7 @@ mod mock; mod tests; // Re-export pallet items so that they can be accessed from the crate namespace. -use frame_support::{pallet_prelude::*, sp_runtime::MultiSignature}; +use frame_support::{pallet_prelude::*, sp_runtime::MultiSignature, transactional}; use node_primitives::{ParaId, TokenInfo, TokenSymbol}; use orml_traits::MultiCurrency; pub use pallet::*; @@ -44,22 +44,12 @@ type TrieIndex = u32; pub trait WeightInfo { fn create() -> Weight; fn contribute() -> Weight; - fn on_finalize(n: u32) -> Weight; -} - -pub struct TestWeightInfo; -impl WeightInfo for TestWeightInfo { - fn create() -> Weight { - 0 - } - - fn contribute() -> Weight { - 0 - } - - fn on_finalize(_n: u32) -> Weight { - 0 - } + fn unlock() -> Weight; + fn withdraw() -> Weight; + fn refund() -> Weight; + fn redeem() -> Weight; + fn dissolve(n: u32) -> Weight; + fn on_initialize(n: u32) -> Weight; } #[allow(type_alias_bounds)] @@ -224,6 +214,7 @@ pub mod pallet { pallet_prelude::{storage::child, *}, sp_runtime::traits::{AccountIdConversion, CheckedAdd, Hash, Saturating, Zero}, storage::ChildTriePrefixIterator, + weights::WeightToFeePolynomial, PalletId, }; use frame_system::pallet_prelude::*; @@ -317,6 +308,8 @@ pub mod pallet { #[pallet::constant] type WithdrawWeight: Get; + + type WeightToFee: WeightToFeePolynomial>; } #[pallet::pallet] @@ -510,7 +503,7 @@ pub mod pallet { Pays::No ))] pub fn fund_end(origin: OriginFor, #[pallet::compact] index: ParaId) -> DispatchResult { - let _owner = T::EnsureConfirmAsMultiSig::ensure_origin(origin)?; + T::EnsureConfirmAsMultiSig::ensure_origin(origin)?; let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; ensure!( @@ -526,11 +519,7 @@ pub mod pallet { } /// Unlock the reserved vsToken/vsBond after fund success - #[pallet::weight(( - 0, - DispatchClass::Normal, - Pays::No - ))] + #[pallet::weight(T::WeightInfo::unlock())] pub fn unlock( _origin: OriginFor, who: AccountIdOf, @@ -569,11 +558,7 @@ pub mod pallet { } /// Create a new crowdloaning campaign for a parachain slot deposit for the current auction. - #[pallet::weight(( - 0, - DispatchClass::Normal, - Pays::No - ))] + #[pallet::weight(T::WeightInfo::create())] pub fn create( origin: OriginFor, #[pallet::compact] index: ParaId, @@ -619,11 +604,8 @@ 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(( - 0, - DispatchClass::Normal, - Pays::No - ))] + #[pallet::weight(T::WeightInfo::contribute())] + #[transactional] pub fn contribute( origin: OriginFor, #[pallet::compact] index: ParaId, @@ -668,7 +650,7 @@ pub mod pallet { #[pallet::compact] index: ParaId, is_success: bool, ) -> DispatchResult { - let _owner = T::EnsureConfirmAsMultiSig::ensure_origin(origin)?; + T::EnsureConfirmAsMultiSig::ensure_origin(origin)?; let fund = Self::funds(index).ok_or(Error::::InvalidParaId)?; let can_confirm = fund.status == FundStatus::Ongoing || @@ -727,11 +709,8 @@ 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, - DispatchClass::Normal, - Pays::No - ))] + #[pallet::weight(T::WeightInfo::withdraw())] + #[transactional] pub fn withdraw(origin: OriginFor, #[pallet::compact] index: ParaId) -> DispatchResult { let owner = ensure_signed(origin.clone())?; @@ -788,11 +767,8 @@ pub mod pallet { Ok(()) } - #[pallet::weight(( - 0, - DispatchClass::Normal, - Pays::No - ))] + #[pallet::weight(T::WeightInfo::refund())] + #[transactional] pub fn refund(origin: OriginFor, #[pallet::compact] index: ParaId) -> DispatchResult { let who = ensure_signed(origin.clone())?; @@ -885,11 +861,8 @@ pub mod pallet { Ok(()) } - #[pallet::weight(( - 0, - DispatchClass::Normal, - Pays::No - ))] + #[pallet::weight(T::WeightInfo::redeem())] + #[transactional] pub fn redeem( origin: OriginFor, #[pallet::compact] index: ParaId, @@ -989,11 +962,7 @@ pub mod pallet { } /// Remove a fund after the retirement period has ended and all funds have been returned. - #[pallet::weight(( - 0, - DispatchClass::Normal, - Pays::No - ))] + #[pallet::weight(T::WeightInfo::dissolve(T::RemoveKeysLimit::get()))] pub fn dissolve(origin: OriginFor, #[pallet::compact] index: ParaId) -> DispatchResult { let depositor = ensure_signed(origin)?; @@ -1030,7 +999,7 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { - fn on_finalize(n: BlockNumberFor) { + fn on_initialize(n: BlockNumberFor) -> Weight { // Release x% KSM/DOT from redeem-pool to bancor-pool per cycle if n != 0 && (n % T::ReleaseCycle::get()) == 0 { if let Ok(rp_balance) = TryInto::::try_into(Self::redeem_pool()) { @@ -1052,14 +1021,10 @@ pub mod pallet { } } } + ::WeightInfo::on_initialize(n) // TODO: Auto unlock vsToken/vsBond? } - - fn on_initialize(_n: BlockNumberFor) -> frame_support::weights::Weight { - // TODO estimate weight - Zero::zero() - } } impl Pallet { @@ -1160,8 +1125,13 @@ pub mod pallet { fn xcm_ump_contribute( _origin: OriginFor, index: ParaId, - value: BalanceOf, + mut value: BalanceOf, ) -> XcmResult { + let fee: BalanceOf = T::WeightToFee::calc(&T::BifrostXcmExecutor::transact_weight( + T::ContributionWeight::get(), + )); + value = value.saturating_sub(fee); + let contribution = Contribution { index, value, signature: None }; let call = CrowdloanContributeCall::CrowdloanContribute(ContributeCall::Contribute( diff --git a/pallets/salp/src/mock.rs b/pallets/salp/src/mock.rs index 06e440c4d9..f90b121c0f 100644 --- a/pallets/salp/src/mock.rs +++ b/pallets/salp/src/mock.rs @@ -21,6 +21,7 @@ use frame_support::{ construct_runtime, parameter_types, traits::{EnsureOrigin, GenesisBuild}, + weights::{WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial}, PalletId, }; use frame_system::RawOrigin; @@ -36,9 +37,10 @@ use xcm::{ DoubleEncoded, }; use xcm_builder::{EnsureXcmOrigin, SignedToAccountId32}; -use xcm_support::BifrostXcmExecutor; +use xcm_support::{BifrostXcmExecutor, Weight}; use crate as salp; +use crate::WeightInfo; pub(crate) type AccountId = <::Signer as sp_runtime::traits::IdentifyAccount>::AccountId; pub(crate) type Block = frame_system::mocking::MockBlock; @@ -233,6 +235,21 @@ impl EnsureOrigin for EnsureConfirmAsMultiSig { } } +use smallvec::smallvec; +pub use sp_runtime::Perbill; +pub struct WeightToFee; +impl WeightToFeePolynomial for WeightToFee { + type Balance = Balance; + fn polynomial() -> WeightToFeeCoefficients { + smallvec![WeightToFeeCoefficient { + degree: 1, + negative: false, + coeff_frac: Perbill::from_rational(90u32, 100u32), + coeff_integer: 1, + }] + } +} + impl salp::Config for Test { type BancorPool = Bancor; type BifrostXcmExecutor = MockXcmExecutor; @@ -251,12 +268,48 @@ impl salp::Config for Test { type SubmissionDeposit = SubmissionDeposit; type VSBondValidPeriod = VSBondValidPeriod; type XcmTransferOrigin = XcmTransferOrigin; - type WeightInfo = salp::TestWeightInfo; + type WeightInfo = SalpWeightInfo; type SelfParaId = SelfParaId; type BaseXcmWeight = BaseXcmWeight; type ContributionWeight = ContributionWeight; type WithdrawWeight = WithdrawWeight; type EnsureConfirmAsMultiSig = EnsureConfirmAsMultiSig; + type WeightToFee = WeightToFee; +} + +pub struct SalpWeightInfo; +impl WeightInfo for SalpWeightInfo { + fn create() -> Weight { + 0 + } + + fn contribute() -> Weight { + 0 + } + + fn unlock() -> Weight { + 0 + } + + fn withdraw() -> Weight { + 0 + } + + fn redeem() -> Weight { + 0 + } + + fn refund() -> Weight { + 0 + } + + fn dissolve(_n: u32) -> Weight { + 0 + } + + fn on_initialize(_n: u32) -> Weight { + 0 + } } // To control the result returned by `MockXcmExecutor` @@ -266,7 +319,7 @@ pub(crate) static mut MOCK_XCM_RESULT: (bool, bool) = (true, true); pub struct MockXcmExecutor; impl BifrostXcmExecutor for MockXcmExecutor { - fn transact_weight() -> u64 { + fn transact_weight(_: u64) -> u64 { return 0; } diff --git a/runtime/asgard/Cargo.toml b/runtime/asgard/Cargo.toml index 57f00635cc..1da44516c8 100644 --- a/runtime/asgard/Cargo.toml +++ b/runtime/asgard/Cargo.toml @@ -12,6 +12,7 @@ log = { version = "0.4.14", default-features = false } serde = { version = "1.0.124", optional = true } static_assertions = "1.1.0" hex-literal = { version = "0.3.1"} +smallvec = "1.6.1" # primitives node-primitives = { default-features = false, path = "../../node/primitives" } @@ -71,6 +72,7 @@ parachain-info = { git = "https://github.com/paritytech/cumulus", default-featur pallet-collator-selection = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.8" } # Polkadot dependencies +polkadot-primitives = { git = "https://github.com/paritytech/polkadot", default-features = false,branch = "release-v0.9.8" } polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.8" } xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.8" } xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.8" } @@ -164,6 +166,7 @@ std = [ "xcm/std", "xcm-builder/std", "xcm-executor/std", + "polkadot-primitives/std", "polkadot-runtime-parachains/std", "bifrost-bancor/std", "bifrost-bancor-runtime-api/std", diff --git a/runtime/asgard/src/constants.rs b/runtime/asgard/src/constants.rs index a5578d062e..b99e463429 100644 --- a/runtime/asgard/src/constants.rs +++ b/runtime/asgard/src/constants.rs @@ -25,6 +25,7 @@ pub mod currency { pub const BNCS: Balance = 1_000_000_000_000; pub const DOLLARS: Balance = BNCS; pub const CENTS: Balance = DOLLARS / 100; // assume this is worth about a cent. + pub const RELAY_CENTS: Balance = DOLLARS / 30_000; pub const MILLICENTS: Balance = CENTS / 1_000; pub const MILLIBNC: Balance = 1_000_000_000; pub const MICROBNC: Balance = 1_000_000; @@ -82,3 +83,29 @@ pub mod time { pub const ROCOCO_LEASE_PERIOD: BlockNumber = 1 * DAYS; pub const WESTEND_LEASE_PERIOD: BlockNumber = 28 * DAYS; } + +/// Relaychain Fee related. +pub mod relay_fee { + use frame_support::weights::{ + constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients, + WeightToFeePolynomial, + }; + use polkadot_primitives::v0::Balance; + use smallvec::smallvec; + pub use sp_runtime::Perbill; + + pub struct WeightToFee; + impl WeightToFeePolynomial for WeightToFee { + type Balance = Balance; + fn polynomial() -> WeightToFeeCoefficients { + let p = super::currency::RELAY_CENTS; + let q = 10 * Balance::from(ExtrinsicBaseWeight::get()); + smallvec![WeightToFeeCoefficient { + degree: 1, + negative: false, + coeff_frac: Perbill::from_rational(p % q, q), + coeff_integer: p / q, + }] + } + } +} diff --git a/runtime/asgard/src/lib.rs b/runtime/asgard/src/lib.rs index 5fda117f13..de695e26ff 100644 --- a/runtime/asgard/src/lib.rs +++ b/runtime/asgard/src/lib.rs @@ -106,6 +106,8 @@ use zenlink_protocol::{ ZenlinkMultiAssets, }; +use crate::constants::relay_fee::WeightToFee; + mod weights; pub type SessionHandlers = (); @@ -1018,6 +1020,7 @@ impl bifrost_salp::Config for Runtime { type BaseXcmWeight = XcmWeight; type EnsureConfirmAsMultiSig = EnsureOneOf; + type WeightToFee = WeightToFee; } parameter_types! { diff --git a/runtime/asgard/src/weights/bifrost_salp.rs b/runtime/asgard/src/weights/bifrost_salp.rs index 8749be06d7..799212a1be 100644 --- a/runtime/asgard/src/weights/bifrost_salp.rs +++ b/runtime/asgard/src/weights/bifrost_salp.rs @@ -42,7 +42,8 @@ use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; -/// Weight functions for bifrost_salp. +/// Weight functions for bifrost_salp +/// @todo benchmark again later pub struct WeightInfo(PhantomData); impl bifrost_salp::WeightInfo for WeightInfo { fn create() -> Weight { @@ -55,9 +56,37 @@ impl bifrost_salp::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } - fn on_finalize(_n: u32) -> Weight { - (8_405_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) + fn unlock() -> Weight { + (0 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + fn withdraw() -> Weight { + (64_140_000 as Weight) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + fn redeem() -> Weight { + (110_824_000 as Weight) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + fn refund() -> Weight { + (110_824_000 as Weight) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + fn dissolve(k: u32) -> Weight { + (0 as Weight) + .saturating_add((45_890_000 as Weight).saturating_mul(k as Weight)) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(k as Weight))) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + .saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(k as Weight))) + } + fn on_initialize(_n: u32) -> Weight { + (9_002_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } } diff --git a/runtime/dev/Cargo.toml b/runtime/dev/Cargo.toml index b63c71c156..3a3cdc66c7 100644 --- a/runtime/dev/Cargo.toml +++ b/runtime/dev/Cargo.toml @@ -12,6 +12,7 @@ log = { version = "0.4.14", default-features = false } serde = { version = "1.0.124", optional = true } static_assertions = "1.1.0" hex-literal = { version = "0.3.1"} +smallvec = "1.6.1" # primitives node-primitives = { default-features = false, path = "../../node/primitives" } @@ -72,6 +73,7 @@ parachain-info = { git = "https://github.com/paritytech/cumulus", default-featur pallet-collator-selection = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.8" } # Polkadot dependencies +polkadot-primitives = { git = "https://github.com/paritytech/polkadot", default-features = false,branch = "release-v0.9.8" } polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.8" } xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.8" } xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.8" } diff --git a/runtime/dev/src/constants.rs b/runtime/dev/src/constants.rs index 55c3881a59..26acb5eb92 100644 --- a/runtime/dev/src/constants.rs +++ b/runtime/dev/src/constants.rs @@ -25,6 +25,7 @@ pub mod currency { pub const BNCS: Balance = 1_000_000_000_000; pub const DOLLARS: Balance = BNCS; pub const CENTS: Balance = DOLLARS / 100; // assume this is worth about a cent. + pub const RELAY_CENTS: Balance = DOLLARS / 30_000; pub const MILLICENTS: Balance = CENTS / 1_000; pub const MILLIBNC: Balance = 1_000_000_000; pub const MICROBNC: Balance = 1_000_000; @@ -82,3 +83,29 @@ pub mod time { pub const ROCOCO_LEASE_PERIOD: BlockNumber = 1 * DAYS; pub const WESTEND_LEASE_PERIOD: BlockNumber = 28 * DAYS; } + +/// Relaychain Fee related. +pub mod relay_fee { + use frame_support::weights::{ + constants::ExtrinsicBaseWeight, WeightToFeeCoefficient, WeightToFeeCoefficients, + WeightToFeePolynomial, + }; + use polkadot_primitives::v0::Balance; + use smallvec::smallvec; + pub use sp_runtime::Perbill; + + pub struct WeightToFee; + impl WeightToFeePolynomial for WeightToFee { + type Balance = Balance; + fn polynomial() -> WeightToFeeCoefficients { + let p = super::currency::RELAY_CENTS; + let q = 10 * Balance::from(ExtrinsicBaseWeight::get()); + smallvec![WeightToFeeCoefficient { + degree: 1, + negative: false, + coeff_frac: Perbill::from_rational(p % q, q), + coeff_integer: p / q, + }] + } + } +} diff --git a/runtime/dev/src/lib.rs b/runtime/dev/src/lib.rs index 936e1e68fb..7e6b46d148 100644 --- a/runtime/dev/src/lib.rs +++ b/runtime/dev/src/lib.rs @@ -921,6 +921,8 @@ impl bifrost_minter_reward::Config for Runtime { type WeightInfo = weights::bifrost_minter_reward::WeightInfo; } +use crate::constants::relay_fee::WeightToFee; + parameter_types! { pub const SubmissionDeposit: Balance = 100 * DOLLARS; pub const MinContribution: Balance = 1 * DOLLARS; @@ -987,6 +989,7 @@ impl bifrost_salp::Config for Runtime { type WithdrawWeight = WithdrawWeight; type BaseXcmWeight = XcmWeight; type EnsureConfirmAsMultiSig = EnsureConfirmAsMultiSig; + type WeightToFee = WeightToFee; } parameter_types! { diff --git a/runtime/dev/src/weights/bifrost_salp.rs b/runtime/dev/src/weights/bifrost_salp.rs index 1fabc47330..1ef5490cc6 100644 --- a/runtime/dev/src/weights/bifrost_salp.rs +++ b/runtime/dev/src/weights/bifrost_salp.rs @@ -42,7 +42,8 @@ use frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; -/// Weight functions for bifrost_salp. +/// Weight functions for bifrost_salp +/// @todo benchmark again later pub struct WeightInfo(PhantomData); impl bifrost_salp::WeightInfo for WeightInfo { fn create() -> Weight { @@ -55,11 +56,37 @@ impl bifrost_salp::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } - fn on_finalize(n: u32) -> Weight { + fn unlock() -> Weight { + (0 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + fn withdraw() -> Weight { + (64_140_000 as Weight) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + fn redeem() -> Weight { + (110_824_000 as Weight) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + fn refund() -> Weight { + (110_824_000 as Weight) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + fn dissolve(k: u32) -> Weight { + (0 as Weight) + .saturating_add((45_890_000 as Weight).saturating_mul(k as Weight)) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(k as Weight))) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + .saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(k as Weight))) + } + fn on_initialize(_n: u32) -> Weight { (9_002_000 as Weight) - // Standard Error: 0 - .saturating_add((235_000 as Weight).saturating_mul(n as Weight)) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } } diff --git a/xcm-support/src/lib.rs b/xcm-support/src/lib.rs index f9cbc48600..3de31d1de8 100644 --- a/xcm-support/src/lib.rs +++ b/xcm-support/src/lib.rs @@ -156,8 +156,8 @@ pub struct BifrostXcmAdaptor(PhantomData<(XcmSender, B impl> BifrostXcmExecutor for BifrostXcmAdaptor { - fn transact_weight() -> u64 { - return 4 * BaseXcmWeight::get(); + fn transact_weight(weight: u64) -> u64 { + return weight + 4 * BaseXcmWeight::get(); } fn ump_transact( @@ -169,7 +169,7 @@ impl> BifrostXcmExecutor let mut message = Xcm::WithdrawAsset { assets: vec![MultiAsset::ConcreteFungible { id: MultiLocation::Null, - amount: (weight + Self::transact_weight()) as u128, + amount: Self::transact_weight(weight) as u128, }], effects: vec![Order::BuyExecution { fees: MultiAsset::All, diff --git a/xcm-support/src/traits.rs b/xcm-support/src/traits.rs index 130a8bb316..0c91f4c1f1 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 transact_weight() -> u64; + fn transact_weight(weight: u64) -> u64; fn ump_transact( origin: MultiLocation,