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

Support Native ETH in v1 #1354

Merged
merged 35 commits into from
Jan 27, 2025
Merged

Support Native ETH in v1 #1354

merged 35 commits into from
Jan 27, 2025

Conversation

alistair-singh
Copy link
Contributor

@alistair-singh alistair-singh commented Dec 12, 2024

Changes

  1. Use the 0x0000000000000000000000000000000000000000 token address as Native ETH.
  2. When sendToken is called with the 0x00.. an amount of msg.value is locked in asset hub agent.
  3. To avoid clashing with fees/rewards and locked funds, fees/rewards are collected and dispensed from the Gateway Proxy account.
  4. The existing funds in the agents will be migrated on upgrade.
  5. Scripts which mentions FundAgent are now called FundGateway

Related polkadot-sdk: paritytech/polkadot-sdk#6855

TODO

  • Fix tests
  • Add tests for the Eth asserting msg.value.
  • Migrate agent funds to gateway proxy on upgrade

Resolves: https://linear.app/snowfork/issue/SNO-1222

Copy link

codecov bot commented Dec 17, 2024

Codecov Report

Attention: Patch coverage is 87.80488% with 5 lines in your changes missing coverage. Please review.

Project coverage is 76.58%. Comparing base (24b9d31) to head (bb130a4).
Report is 158 commits behind head on main.

Files with missing lines Patch % Lines
contracts/src/Assets.sol 84.21% 3 Missing ⚠️
contracts/src/upgrades/Gateway202410.sol 77.77% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1354      +/-   ##
==========================================
- Coverage   77.83%   76.58%   -1.25%     
==========================================
  Files          14       17       +3     
  Lines         415      739     +324     
  Branches       76      110      +34     
==========================================
+ Hits          323      566     +243     
- Misses         75      162      +87     
+ Partials       17       11       -6     
Flag Coverage Δ
solidity 76.58% <87.80%> (-1.25%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alistair-singh alistair-singh marked this pull request as ready for review December 17, 2024 23:52
contracts/src/Gateway.sol Outdated Show resolved Hide resolved
contracts/src/Types.sol Outdated Show resolved Hide resolved
contracts/src/GatewayProxy.sol Outdated Show resolved Hide resolved
@alistair-singh
Copy link
Contributor Author

@vgeddes we have a Command called TransferNativeFromAgent which is a management-style command, issuable from bridgehub only, that can empty an agent account of ETH. We would need to add a similar command TransferNativeFromGateway to do the same thing for the Gateway. We should also maybe disable TransferNativeFromAgent so that there is no way to remove ETH from an agent other than an Unlock command.

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-merge-queue bot pushed a commit to paritytech/polkadot-sdk that referenced this pull request Jan 7, 2025
Changes:
1. Use the 0x0000000000000000000000000000000000000000 token address as
Native ETH.
2. Convert it to/from `{ parents: 2, interior:
X1(GlobalConsensus(Ethereum{chain_id: 1})) }` when encountered.

Onchain changes:
This will require a governance request to register native ETH (with the
above location) in the foreign assets pallet and make it sufficient.

Related solidity changes:
Snowfork/snowbridge#1354

TODO:
- [x] Emulated Tests

---------

Co-authored-by: Vincent Geddes <[email protected]>
Co-authored-by: Bastian Köcher <[email protected]>
Co-authored-by: Bastian Köcher <[email protected]>
github-actions bot pushed a commit to paritytech/polkadot-sdk that referenced this pull request Jan 8, 2025
Changes:
1. Use the 0x0000000000000000000000000000000000000000 token address as
Native ETH.
2. Convert it to/from `{ parents: 2, interior:
X1(GlobalConsensus(Ethereum{chain_id: 1})) }` when encountered.

Onchain changes:
This will require a governance request to register native ETH (with the
above location) in the foreign assets pallet and make it sufficient.

Related solidity changes:
Snowfork/snowbridge#1354

TODO:
- [x] Emulated Tests

---------

Co-authored-by: Vincent Geddes <[email protected]>
Co-authored-by: Bastian Köcher <[email protected]>
Co-authored-by: Bastian Köcher <[email protected]>
(cherry picked from commit 4059282)
contracts/src/AgentExecutor.sol Outdated Show resolved Hide resolved
@@ -60,7 +62,7 @@ library Assets {
) external view returns (Costs memory costs) {
AssetsStorage.Layout storage $ = AssetsStorage.layout();
TokenInfo storage info = $.tokenRegistry[token];
if (!info.isRegistered) {
if (!info.isRegistered && token != address(0)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not just register ether as a token, so we can avoid the complexity of this check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in a3e5aa4

contracts/src/Assets.sol Show resolved Hide resolved
payable($.assetHubAgent).safeNativeTransfer(amount);
ticket.value = amount;

ticket.dest = $.assetHubParaID;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems that both _sendEther and _sendNativeToken share this ticket/payload creation code. Can we not factor that out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed in 0921ff9

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.

Awesome feature! 🥳

contracts/src/Assets.sol Outdated Show resolved Hide resolved
contracts/src/Assets.sol Show resolved Hide resolved
contracts/src/Gateway.sol Outdated Show resolved Hide resolved
web/packages/api/src/environment.ts Show resolved Hide resolved
@vgeddes vgeddes self-assigned this Jan 22, 2025
contracts/src/Assets.sol Outdated Show resolved Hide resolved
contracts/src/Assets.sol Show resolved Hide resolved
@vgeddes
Copy link
Collaborator

vgeddes commented Jan 27, 2025

@alistair-singh ready for another round of review - I improved the validation of the passed ether in Gateway.submitOutbound

@vgeddes vgeddes merged commit cb05e1f into main Jan 27, 2025
3 checks passed
@vgeddes vgeddes deleted the alistair/support-eth branch January 27, 2025 14:50
@vgeddes vgeddes restored the alistair/support-eth branch January 27, 2025 15:30
Copy link
Contributor Author

@alistair-singh alistair-singh left a comment

Choose a reason for hiding this comment

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

Looks good!

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

Successfully merging this pull request may close these issues.

4 participants