Skip to content

Commit

Permalink
send all assets in a single instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden committed Dec 5, 2024
1 parent d70ac6c commit bc45bbd
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions bridges/snowbridge/primitives/router/src/inbound/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,27 +146,39 @@ where
ReserveAssetDeposited(fee.clone().into()),
PayFees { asset: fee },
];
let mut reserve_assets = vec![];
let mut withdraw_assets = vec![];

for asset in &message.assets {
match asset {
Asset::NativeTokenERC20 { token_id, value } => {

let token_location: Location = Location::new(
2,
[
GlobalConsensus(EthereumNetwork::get()),
AccountKey20 { network: None, key: (*token_id).into() },
],
);
instructions.push(ReserveAssetDeposited((token_location, *value).into()));
let asset: XcmAsset = (token_location, *value).into();
reserve_assets.push(asset);
},
Asset::ForeignTokenERC20 { token_id, value } => {
let asset_id = ConvertAssetId::convert(&token_id)
.ok_or(ConvertMessageError::InvalidAsset)?;
instructions.push(WithdrawAsset((asset_id, *value).into()));
let asset: XcmAsset = (asset_id, *value).into();
withdraw_assets.push(asset);
},
}
}

if reserve_assets.len() > 0 {
instructions.push(ReserveAssetDeposited(reserve_assets.into()));
}
if withdraw_assets.len() > 0 {
instructions.push(WithdrawAsset(withdraw_assets.into()));
}

if let Some(claimer) = message.claimer {
let claimer = Junction::decode(&mut claimer.as_ref())
.map_err(|_| ConvertMessageError::InvalidClaimer)?;
Expand Down

0 comments on commit bc45bbd

Please sign in to comment.