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

Commit

Permalink
added fee handler trait
Browse files Browse the repository at this point in the history
  • Loading branch information
alistair-singh committed Nov 8, 2023
1 parent 39ac579 commit c3ff111
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ impl xcm_executor::Config for XcmConfig {
BridgeHubRococoChainId,
BridgeHubRococoMessagesLane,
>,
XcmExportFeeToSnowbridge<
EthereumNetwork,
TreasuryAccount,
Self::AssetTransactor,
>,
XcmFeeToAccount<Self::AssetTransactor, AccountId, TreasuryAccount>,
),
>;
Expand Down Expand Up @@ -571,3 +576,42 @@ impl<
fee
}
}

/// 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)>,
);

impl<
EthereumNetwork: Get<NetworkId>,
ReceiverAccount: Get<AccountId>,
AssetTransactor: TransactAsset,
> HandleFee for XcmExportFeeToSnowbridge<EthereumNetwork, ReceiverAccount, AssetTransactor>
{
fn handle_fee(
fees: MultiAssets,
context: Option<&XcmContext>,
reason: FeeReason,
) -> MultiAssets {
if matches!(reason, FeeReason::Export { network: bridged_network, destination }
if bridged_network == EthereumNetwork::get() && destination == Here)
{
log::info!(
target: "xcm::fees",
"XcmExportFeeToSnowbridge fees: {fees:?}, context: {context:?}, reason: {reason:?}",
);

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

return MultiAssets::new()
}

fees
}
}

0 comments on commit c3ff111

Please sign in to comment.