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

Commit

Permalink
add fee trait
Browse files Browse the repository at this point in the history
  • Loading branch information
alistair-singh committed Nov 9, 2023
1 parent fd7d778 commit 1522b7d
Showing 1 changed file with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ use snowbridge_router_primitives::{
inbound::GlobalConsensusEthereumConvertsFor,
outbound::EthereumBlobExporter,
};
use snowbridge_core::outbound::OutboundQueueLocalFee;
use sp_core::{Get, H256};
use sp_runtime::traits::AccountIdConversion;
use sp_std::marker::PhantomData;
Expand Down Expand Up @@ -325,6 +326,7 @@ impl xcm_executor::Config for XcmConfig {
EthereumNetwork,
SnowbridgeTreasuryAccount,
Self::AssetTransactor,
crate::EthereumOutboundQueue,
>,
XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>,
),
Expand Down Expand Up @@ -584,15 +586,16 @@ impl<

/// A `HandleFee` implementation that takes fees from `ExportMessage` XCM instructions
/// to Snowbridge and holds it in a receiver account. Burns the fees in case of a failure.
pub struct XcmExportFeeToSnowbridge<EthereumNetwork, ReceiverAccount, AssetTransactor>(
PhantomData<(EthereumNetwork, ReceiverAccount, AssetTransactor)>,
pub struct XcmExportFeeToSnowbridge<EthereumNetwork, ReceiverAccount, AssetTransactor, OutboundQueue>(
PhantomData<(EthereumNetwork, ReceiverAccount, AssetTransactor, OutboundQueue)>,
);

impl<
EthereumNetwork: Get<NetworkId>,
ReceiverAccount: Get<AccountId>,
AssetTransactor: TransactAsset,
> HandleFee for XcmExportFeeToSnowbridge<EthereumNetwork, ReceiverAccount, AssetTransactor>
OutboundQueue: OutboundQueueLocalFee<Balance = bp_rococo::Balance>,
> HandleFee for XcmExportFeeToSnowbridge<EthereumNetwork, ReceiverAccount, AssetTransactor, OutboundQueue>
{
fn handle_fee(
fees: MultiAssets,
Expand All @@ -608,13 +611,21 @@ impl<
);

let receiver = ReceiverAccount::get();
deposit_or_burn_fee::<AssetTransactor, _>(
fees,
context,
receiver,
);

return MultiAssets::new()
if let Some(XcmContext{ origin: Some(origin), ..}) = context {
// There is an origin so split fee into parts.
let local_fee = OutboundQueue::calculate_local_fee();

} else {
// There is no context so send the full fee to the receiver
deposit_or_burn_fee::<AssetTransactor, _>(
fees,
context,
receiver,
);
}

return fees;
}

fees
Expand Down

0 comments on commit 1522b7d

Please sign in to comment.