Skip to content

Commit

Permalink
XCM native fee reduction (#1092)
Browse files Browse the repository at this point in the history
* Solution suggestion

* Apply to to other runtimes
  • Loading branch information
Dinonard authored Nov 30, 2023
1 parent cef3ab1 commit 5a51359
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 11 deletions.
12 changes: 12 additions & 0 deletions runtime/astar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,18 @@ impl WeightToFeePolynomial for WeightToFee {
}
}

/// Handles coverting weight consumed by XCM into native currency fee.
///
/// Similar to standard `WeightToFee` handler, but force uses the minimum multiplier.
pub struct XcmWeightToFee;
impl frame_support::weights::WeightToFee for XcmWeightToFee {
type Balance = Balance;

fn weight_to_fee(n: &Weight) -> Self::Balance {
MinimumMultiplier::get().saturating_mul_int(WeightToFee::weight_to_fee(&n))
}
}

pub struct DealWithFees;
impl OnUnbalanced<NegativeImbalance> for DealWithFees {
fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {
Expand Down
4 changes: 2 additions & 2 deletions runtime/astar/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use super::{
AccountId, AllPalletsWithSystem, AssetId, Assets, AstarAssetLocationIdConverter, Balance,
Balances, DealWithFees, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall,
RuntimeEvent, RuntimeOrigin, TreasuryAccountId, WeightToFee, XcAssetConfig, XcmpQueue,
RuntimeEvent, RuntimeOrigin, TreasuryAccountId, XcAssetConfig, XcmWeightToFee, XcmpQueue,
};
use crate::weights;
use frame_support::{
Expand Down Expand Up @@ -251,7 +251,7 @@ impl xcm_executor::Config for XcmConfig {
type Barrier = XcmBarrier;
type Weigher = Weigher;
type Trader = (
UsingComponents<WeightToFee, AstarLocation, AccountId, Balances, DealWithFees>,
UsingComponents<XcmWeightToFee, AstarLocation, AccountId, Balances, DealWithFees>,
FixedRateOfForeignAsset<XcAssetConfig, AstarXcmFungibleFeeHandler>,
);
type ResponseHandler = PolkadotXcm;
Expand Down
12 changes: 12 additions & 0 deletions runtime/shibuya/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,18 @@ impl WeightToFeePolynomial for WeightToFee {
}
}

/// Handles coverting weight consumed by XCM into native currency fee.
///
/// Similar to standard `WeightToFee` handler, but force uses the minimum multiplier.
pub struct XcmWeightToFee;
impl frame_support::weights::WeightToFee for XcmWeightToFee {
type Balance = Balance;

fn weight_to_fee(n: &Weight) -> Self::Balance {
MinimumMultiplier::get().saturating_mul_int(WeightToFee::weight_to_fee(&n))
}
}

pub struct DealWithFees;
impl OnUnbalanced<NegativeImbalance> for DealWithFees {
fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {
Expand Down
4 changes: 2 additions & 2 deletions runtime/shibuya/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use super::{
AccountId, AllPalletsWithSystem, AssetId, Assets, Balance, Balances, DealWithFees,
ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin,
ShibuyaAssetLocationIdConverter, TreasuryAccountId, WeightToFee, XcAssetConfig, XcmpQueue,
ShibuyaAssetLocationIdConverter, TreasuryAccountId, XcAssetConfig, XcmWeightToFee, XcmpQueue,
};
use crate::weights;
use frame_support::{
Expand Down Expand Up @@ -185,7 +185,7 @@ impl xcm_executor::Config for XcmConfig {
type Barrier = XcmBarrier;
type Weigher = Weigher;
type Trader = (
UsingComponents<WeightToFee, ShibuyaLocation, AccountId, Balances, DealWithFees>,
UsingComponents<XcmWeightToFee, ShibuyaLocation, AccountId, Balances, DealWithFees>,
FixedRateOfForeignAsset<XcAssetConfig, ShibuyaXcmFungibleFeeHandler>,
);
type ResponseHandler = PolkadotXcm;
Expand Down
18 changes: 15 additions & 3 deletions runtime/shiden/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,20 @@ impl WeightToFeePolynomial for WeightToFee {
}
}

pub struct BurnFees;
impl OnUnbalanced<NegativeImbalance> for BurnFees {
/// Handles coverting weight consumed by XCM into native currency fee.
///
/// Similar to standard `WeightToFee` handler, but force uses the minimum multiplier.
pub struct XcmWeightToFee;
impl frame_support::weights::WeightToFee for XcmWeightToFee {
type Balance = Balance;

fn weight_to_fee(n: &Weight) -> Self::Balance {
MinimumMultiplier::get().saturating_mul_int(WeightToFee::weight_to_fee(&n))
}
}

pub struct DealWithFees;
impl OnUnbalanced<NegativeImbalance> for DealWithFees {
/// Payout tips but burn all the fees
fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {
if let Some(fees) = fees_then_tips.next() {
Expand All @@ -682,7 +694,7 @@ impl OnUnbalanced<NegativeImbalance> for BurnFees {

impl pallet_transaction_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, BurnFees>;
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees>;
type WeightToFee = WeightToFee;
type OperationalFeeMultiplier = OperationalFeeMultiplier;
type FeeMultiplierUpdate = TargetedFeeAdjustment<
Expand Down
8 changes: 4 additions & 4 deletions runtime/shiden/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
// along with Astar. If not, see <http://www.gnu.org/licenses/>.

use super::{
AccountId, AllPalletsWithSystem, AssetId, Assets, Balance, Balances, BurnFees, ParachainInfo,
ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin,
ShidenAssetLocationIdConverter, TreasuryAccountId, WeightToFee, XcAssetConfig, XcmpQueue,
AccountId, AllPalletsWithSystem, AssetId, Assets, Balance, Balances, DealWithFees,
ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin,
ShidenAssetLocationIdConverter, TreasuryAccountId, XcAssetConfig, XcmWeightToFee, XcmpQueue,
};
use crate::weights;
use frame_support::{
Expand Down Expand Up @@ -255,7 +255,7 @@ impl xcm_executor::Config for XcmConfig {
type Barrier = XcmBarrier;
type Weigher = Weigher;
type Trader = (
UsingComponents<WeightToFee, ShidenLocation, AccountId, Balances, BurnFees>,
UsingComponents<XcmWeightToFee, ShidenLocation, AccountId, Balances, DealWithFees>,
FixedRateOfForeignAsset<XcAssetConfig, ShidenXcmFungibleFeeHandler>,
);
type ResponseHandler = PolkadotXcm;
Expand Down

0 comments on commit 5a51359

Please sign in to comment.