Skip to content

Commit

Permalink
fmt check
Browse files Browse the repository at this point in the history
  • Loading branch information
zachary0809 committed Dec 18, 2023
1 parent a890009 commit ba4a03d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
3 changes: 1 addition & 2 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ use sp_runtime::{
};

use scale_info::prelude::string::String;
use sp_std::collections::btree_map::BTreeMap;
use sp_std::{marker::PhantomData, prelude::*};
use sp_std::{collections::btree_map::BTreeMap, marker::PhantomData, prelude::*};
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
Expand Down
7 changes: 4 additions & 3 deletions runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ use super::{
AccountId, AllPalletsWithSystem, BTreeMap, Balances, ParachainInfo, ParachainSystem,
PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue,
};
use crate::xcms::matches_token_ex::IsConcreteEx;
use crate::MagnetToStakingPot;
use crate::{
xcms::{matches_token_ex::IsConcreteEx, xcm_weight::UsingComponentsEx},
MagnetToStakingPot,
};
use frame_support::{
match_types, parameter_types,
traits::{ConstU32, Everything, Nothing},
Expand All @@ -21,7 +23,6 @@ use xcm_builder::{
WithComputedOrigin, WithUniqueTopic,
};
use xcm_executor::XcmExecutor;
use crate::xcms::xcm_weight::UsingComponentsEx;

parameter_types! {
pub const RelayLocation: MultiLocation = MultiLocation::parent();
Expand Down
3 changes: 1 addition & 2 deletions runtime/src/xcms/matches_token_ex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
// with different precision.

use frame_support::traits::Get;
use sp_std::collections::btree_map::BTreeMap;
use sp_std::marker::PhantomData;
use sp_std::{collections::btree_map::BTreeMap, marker::PhantomData};
use xcm::latest::{
AssetId::{Abstract, Concrete},
AssetInstance,
Expand Down
29 changes: 14 additions & 15 deletions runtime/src/xcms/xcm_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

// Modified by Alex Wang 2023/12

use codec::Decode;
use frame_support::{
dispatch::GetDispatchInfo,
traits::{tokens::currency::Currency as CurrencyT, Get, OnUnbalanced as OnUnbalancedT},
Expand All @@ -24,7 +25,6 @@ use frame_support::{
WeightToFee as WeightToFeeT,
},
};
use codec::Decode;
use sp_runtime::traits::{SaturatedConversion, Saturating, Zero};
use sp_std::{marker::PhantomData, result::Result};
use xcm::latest::{prelude::*, Weight};
Expand Down Expand Up @@ -154,11 +154,11 @@ impl<T: Get<(AssetId, u128, u128)>, R: TakeRevenue> WeightTrader for FixedRateOf
weight, payment, context,
);
let (id, units_per_second, units_per_mb) = T::get();
let amount = (units_per_second * (weight.ref_time() as u128) /
(WEIGHT_REF_TIME_PER_SECOND as u128)) +
(units_per_mb * (weight.proof_size() as u128) / (WEIGHT_PROOF_SIZE_PER_MB as u128));
let amount = (units_per_second * (weight.ref_time() as u128)
/ (WEIGHT_REF_TIME_PER_SECOND as u128))
+ (units_per_mb * (weight.proof_size() as u128) / (WEIGHT_PROOF_SIZE_PER_MB as u128));
if amount == 0 {
return Ok(payment)
return Ok(payment);
}
let unused =
payment.checked_sub((id, amount).into()).map_err(|_| XcmError::TooExpensive)?;
Expand All @@ -171,9 +171,9 @@ impl<T: Get<(AssetId, u128, u128)>, R: TakeRevenue> WeightTrader for FixedRateOf
log::trace!(target: "xcm::weight", "FixedRateOfFungible::refund_weight weight: {:?}, context: {:?}", weight, context);
let (id, units_per_second, units_per_mb) = T::get();
let weight = weight.min(self.0);
let amount = (units_per_second * (weight.ref_time() as u128) /
(WEIGHT_REF_TIME_PER_SECOND as u128)) +
(units_per_mb * (weight.proof_size() as u128) / (WEIGHT_PROOF_SIZE_PER_MB as u128));
let amount = (units_per_second * (weight.ref_time() as u128)
/ (WEIGHT_REF_TIME_PER_SECOND as u128))
+ (units_per_mb * (weight.proof_size() as u128) / (WEIGHT_PROOF_SIZE_PER_MB as u128));
self.0 -= weight;
self.1 = self.1.saturating_sub(amount);
if amount > 0 {
Expand Down Expand Up @@ -264,7 +264,7 @@ impl<
// places any weight bought into the right account.
// use PrecisionMultiplier for different precision between relaychain and Magnet
use frame_support::traits::Imbalance;
const PRECISION_MULTIPLIER: u128 = 1_000_000;
const PRECISION_MULTIPLIER: u128 = 1_000_000;

pub struct UsingComponentsEx<
WeightToFee: WeightToFeeT<Balance = Currency::Balance>,
Expand Down Expand Up @@ -297,7 +297,7 @@ impl<
) -> Result<Assets, XcmError> {
log::trace!(target: "runtime::xcm_weight", "UsingComponentsEx::buy_weight weight: {:?}, payment: {:?}, context: {:?}", weight, payment, context);
let amount = WeightToFee::weight_to_fee(&weight);

let mut u128_amount: u128 = amount.saturated_into();
let is_radix: bool = u128_amount % PRECISION_MULTIPLIER > 0;
u128_amount = u128_amount / PRECISION_MULTIPLIER;
Expand All @@ -306,7 +306,7 @@ impl<
}
let required = (Concrete(AssetId::get()), u128_amount).into();
let unused = payment.checked_sub(required).map_err(|_| XcmError::TooExpensive)?;

let amount: Currency::Balance = u128_amount.saturated_into();
self.0 = self.0.saturating_add(weight);
self.1 = self.1.saturating_add(amount);
Expand All @@ -318,10 +318,10 @@ impl<
log::trace!(target: "runtime::xcm_weight", "UsingComponentsEx::refund_weight weight: {:?}, context: {:?}", weight, context);
let weight = weight.min(self.0);
let amount = WeightToFee::weight_to_fee(&weight);

let mut u128_amount: u128 = amount.saturated_into();
u128_amount = u128_amount / PRECISION_MULTIPLIER;

let amount: Currency::Balance = u128_amount.saturated_into();
self.0 -= weight;
self.1 = self.1.saturating_sub(amount);
Expand All @@ -342,8 +342,7 @@ impl<
> Drop for UsingComponentsEx<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>
{
fn drop(&mut self) {
let amount: Currency::Balance = self.1 * PRECISION_MULTIPLIER.saturated_into();
let amount: Currency::Balance = self.1 * PRECISION_MULTIPLIER.saturated_into();
OnUnbalanced::on_unbalanced(Currency::issue(amount));
}
}

0 comments on commit ba4a03d

Please sign in to comment.