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

Commit

Permalink
Focus on the xcm construction & Remove reward
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Jul 23, 2024
1 parent f0abb7e commit d489756
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 317 deletions.
27 changes: 10 additions & 17 deletions bridges/snowbridge/primitives/router/src/outbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ where
})?;

// convert fee to Asset
let fee = Asset::from((Location::parent(), fee.total())).into();
let fee = Asset::from((Location::parent(), fee.local)).into();

Ok(((ticket.encode(), message_id), fee))
}
Expand Down Expand Up @@ -148,12 +148,12 @@ enum XcmConverterError {
DepositAssetExpected,
NoReserveAssets,
FilterDoesNotConsumeAllAssets,
TooManyAssets,
ZeroAssetTransfer,
BeneficiaryResolutionFailed,
AssetResolutionFailed,
InvalidFeeAsset,
SetTopicExpected,
FeeAssetExpected,
FeeAssetInvalid,
}

macro_rules! match_expression {
Expand Down Expand Up @@ -202,10 +202,13 @@ impl<'a, Call> XcmConverter<'a, Call> {
}

// Get the fee asset item from BuyExecution or continue parsing.
let fee_asset = match_expression!(self.peek(), Ok(BuyExecution { fees, .. }), fees);
if fee_asset.is_some() {
let _ = self.next();
}
let fee_asset = match_expression!(self.next()?, BuyExecution { fees, .. }, fees)
.ok_or(FeeAssetExpected)?;
ensure!(fee_asset.clone().id == AssetId::from(Location::parent()), FeeAssetInvalid);
let _fee_amount = match fee_asset.clone().fun {
Fungible(fee_amount) => Ok(fee_amount),
_ => Err(FeeAssetInvalid),
}?;

let (deposit_assets, beneficiary) = match_expression!(
self.next()?,
Expand Down Expand Up @@ -233,18 +236,8 @@ impl<'a, Call> XcmConverter<'a, Call> {
return Err(FilterDoesNotConsumeAllAssets)
}

// We only support a single asset at a time.
ensure!(reserve_assets.len() == 1, TooManyAssets);
let reserve_asset = reserve_assets.get(0).ok_or(AssetResolutionFailed)?;

// If there was a fee specified verify it.
if let Some(fee_asset) = fee_asset {
// The fee asset must be the same as the reserve asset.
if fee_asset.id != reserve_asset.id || fee_asset.fun > reserve_asset.fun {
return Err(InvalidFeeAsset)
}
}

let (token, amount) = match reserve_asset {
Asset { id: AssetId(inner_location), fun: Fungible(amount) } =>
match inner_location.unpack() {
Expand Down
Loading

0 comments on commit d489756

Please sign in to comment.