Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snowbridge: Add support for Ether #548

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

alistair-singh
Copy link

@alistair-singh alistair-singh commented Jan 16, 2025

Adds support for the bridging Ether.

TODO

  • Update snowbridge-router-primitives crate 2409-1 0.16.1
  • Add a test to test round trip of Ether.

@alistair-singh alistair-singh mentioned this pull request Jan 16, 2025
6 tasks
@acatangiu
Copy link
Contributor

Doesn't look good, new crates bring new minor or major versions of deps, doesn't build.

I see the snowfork crates have semver-minor bump, I expected patch bumps to have everything working ok.

@alistair-singh alistair-singh force-pushed the alistair/support-native-ether branch from 042c49e to 2ea7fd3 Compare January 23, 2025 09:58
@alistair-singh alistair-singh force-pushed the alistair/support-native-ether branch from 61541b1 to d46f577 Compare January 23, 2025 23:40
@alistair-singh alistair-singh marked this pull request as ready for review January 23, 2025 23:41
Comment on lines 474 to 477
AssetHubPolkadot::fund_accounts(vec![
(AssetHubPolkadotReceiver::get(), INITIAL_FUND),
(ethereum_sovereign_account(), INITIAL_FUND),
]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not be necessary.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test failed without (AssetHubPolkadotReceiver::get(), INITIAL_FUND), so I pulled it in from the WETH test. The fee assertions of the test are what failed.

let message = VersionedMessage::V1(MessageV1 {
chain_id: CHAIN_ID,
command: Command::SendToken {
token: [0; 20].into(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a comment like [0;20] representing Ether is better.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in a0a5211

<AssetHubPolkadot as AssetHubPolkadotPallet>::Balances::free_balance(
AssetHubPolkadotReceiver::get(),
);
// Send the Weth back to Ethereum
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be ether here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 7d39a0a

Copy link
Contributor

@yrong yrong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@github-actions github-actions bot requested a review from yrong January 24, 2025 07:33
Copy link

Review required! Latest push from author must always be reviewed

Copy link
Contributor

@claravanstaden claravanstaden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alistair-singh adding ether does not require any runtime config, except the new snowbridge-router-primitives crate version, right?

@alistair-singh
Copy link
Author

@alistair-singh adding ether does not require any runtime config, except the new snowbridge-router-primitives crate version, right?

No, we just need the new code in the crate which interprets 0x00... as Ether's multi-location. And the feature is blocked from the solidity side as it wont let you register and submit that address. Deploying the new version of the contract code will enable it by registering Ether at upgrade time.

Copy link
Contributor

@yrong yrong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

<<BridgeHubPolkadot as BridgeHubPolkadotPallet>::Balances as frame_support::traits::fungible::Inspect<_>>::balance(&RelayTreasuryPalletAccount::get())
});

// Send Ether from Asset Hub.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Send Ether from Asset Hub.
// Send Ether from Asset Hub back to Ethereum.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in e946e28

assert!(free_balance_diff > AH_BASE_FEE);
});

// Recieve Ether on Bridge Hub and dispatch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Recieve Ether on Bridge Hub and dispatch
// Check that message with Ether was queued on the BridgeHub

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in e946e28

Comment on lines 607 to 608
// Check that the transfer token back to Ethereum message was queue in the Ethereum
// Outbound Queue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Check that the transfer token back to Ethereum message was queue in the Ethereum
// Outbound Queue
// check the outbound queue

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in e946e28

);
});

// Receive ether on Asset Hub.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Receive ether on Asset Hub.
// Receive Ether on Asset Hub.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in e946e28

assert_expected_events!(
AssetHubPolkadot,
vec![
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { .. }) => {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could/should be exact here:

Suggested change
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { .. }) => {},
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, .. }) => {
asset_id: *asset_id == ether_location,
},

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 798229c

);
});

// Send Ether from Bridge Hub
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Send Ether from Bridge Hub
// Send Ether from Bridge Hub (simulates received Command from Ethereum)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in e946e28


let ether_location: Location = (Parent, Parent, EthereumNetwork::get()).into();

AssetHubPolkadot::execute_with(|| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
AssetHubPolkadot::execute_with(|| {
// Register Ether as foreign asset on AH.
AssetHubPolkadot::execute_with(|| {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in e946e28

@@ -459,6 +461,184 @@ fn send_token_from_ethereum_to_asset_hub() {
});
}

/// Tests sending ether from Ethereum to Asset Hub and back to Ethereum
#[test]
fn send_eth_asset_from_asset_hub_to_ethereum() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can imagine to create some generic helper function:

fn send_token_from_ethereum_to_asset_hub_and_back_works(token: Location) {
   // copy the code below
}

and then reuse for test-cases, something like:

#[test]
fn send_weth_from_ethereum_to_asset_hub() {
    send_token_from_ethereum_to_asset_hub_and_back_works(WETH)
}

#[test]
fn send_eth_from_ethereum_to_asset_hub() {
    let ether_location: Location = (Parent, Parent, EthereumNetwork::get()).into();
    send_token_from_ethereum_to_asset_hub_and_back_works(ether_location)
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 798229c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants