Skip to content

Commit

Permalink
support native eth in outbound queue
Browse files Browse the repository at this point in the history
  • Loading branch information
alistair-singh committed Dec 12, 2024
1 parent b985619 commit 7a76da6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bridges/snowbridge/primitives/router/src/outbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ impl<UniversalLocation, EthereumNetwork, OutboundQueue, AgentHashedDescription,
OutboundQueue,
AgentHashedDescription,
ConvertAssetId,
> where
>
where
UniversalLocation: Get<InteriorLocation>,
EthereumNetwork: Get<NetworkId>,
OutboundQueue: SendMessage<Balance = u128>,
Expand Down Expand Up @@ -281,6 +282,7 @@ where
match inner_location.unpack() {
(0, [AccountKey20 { network, key }]) if self.network_matches(network) =>
Some((H160(*key), *amount)),
(0, []) => Some((H160([0; 20]), *amount)),
_ => None,
},
_ => None,
Expand Down
35 changes: 35 additions & 0 deletions bridges/snowbridge/primitives/router/src/outbound/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,41 @@ fn xcm_converter_convert_with_wildcard_all_asset_filter_succeeds() {
assert_eq!(result, Ok((expected_payload, [0; 32])));
}

#[test]
fn xcm_converter_convert_with_native_eth_succeeds() {
let network = BridgedNetwork::get();

let token_address: [u8; 20] = [0; 20];
let beneficiary_address: [u8; 20] = hex!("2000000000000000000000000000000000000000");

let assets: Assets = vec![Asset { id: AssetId([].into()), fun: Fungible(1000) }].into();
let filter: AssetFilter = Wild(All);

let message: Xcm<()> = vec![
WithdrawAsset(assets.clone()),
ClearOrigin,
BuyExecution { fees: assets.get(0).unwrap().clone(), weight_limit: Unlimited },
DepositAsset {
assets: filter,
beneficiary: AccountKey20 { network: None, key: beneficiary_address }.into(),
},
SetTopic([0; 32]),
]
.into();
let mut converter =
XcmConverter::<MockTokenIdConvert, ()>::new(&message, network, Default::default());
let expected_payload = Command::AgentExecute {
agent_id: Default::default(),
command: AgentExecuteCommand::TransferToken {
token: token_address.into(),
recipient: beneficiary_address.into(),
amount: 1000,
},
};
let result = converter.convert();
assert_eq!(result, Ok((expected_payload, [0; 32])));
}

#[test]
fn xcm_converter_convert_with_fees_less_than_reserve_yields_success() {
let network = BridgedNetwork::get();
Expand Down

0 comments on commit 7a76da6

Please sign in to comment.