Skip to content

Commit

Permalink
use claimer for refund surplus, otherwise relayer
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden committed Dec 5, 2024
1 parent 9ffb3e1 commit 85d355e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions bridges/snowbridge/primitives/router/src/inbound/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ where
for asset in &message.assets {
match asset {
Asset::NativeTokenERC20 { token_id, value } => {

let token_location: Location = Location::new(
2,
[
Expand All @@ -179,29 +178,34 @@ where
instructions.push(WithdrawAsset(withdraw_assets.into()));
}

let mut refund_surplus_to = origin_account_location;

if let Some(claimer) = message.claimer {
let claimer = Junction::decode(&mut claimer.as_ref())
.map_err(|_| ConvertMessageError::InvalidClaimer)?;
let claimer_location: Location = Location::new(0, [claimer.into()]);
refund_surplus_to = claimer_location.clone();
instructions.push(SetAssetClaimer { location: claimer_location });
}

// If the message origin is not the gateway proxy contract, set the origin to
// the original sender on Ethereum. Important to be before the arbitrary XCM that is
// appended to the message on the next line.
if message.origin != GatewayProxyAddress::get() {
instructions.push(DescendOrigin(AccountKey20 { key: message.origin.into(), network: None}.into()));
instructions.push(DescendOrigin(
AccountKey20 { key: message.origin.into(), network: None }.into(),
));
}

// Add the XCM sent in the message to the end of the xcm instruction
instructions.extend(message_xcm.0);

let appendix = vec![
RefundSurplus,
// Refund excess fees to the relayer
// Refund excess fees to the claimer, if present, otherwise the relayer
DepositAsset {
assets: Wild(AllOf { id: AssetId(fee_asset.into()), fun: WildFungible }),
beneficiary: origin_account_location,
beneficiary: refund_surplus_to,
},
];

Expand Down

0 comments on commit 85d355e

Please sign in to comment.