-
Notifications
You must be signed in to change notification settings - Fork 107
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
base: main
Are you sure you want to change the base?
Support Native ETH in v1 #1354
Conversation
c2835dd
to
b75401c
Compare
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@vgeddes we have a Command called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
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]>
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)
c778b96
to
757bcc0
Compare
contracts/src/AgentExecutor.sol
Outdated
function transferNative(address payable recipient, uint256 amount) external { | ||
recipient.safeNativeTransfer(amount); | ||
} | ||
|
||
/// @dev Transfer ether to Gateway. Used once off for migration purposes. Can be removed after version 1. | ||
function transferNativeToGateway(address payable gateway, uint256 amount) external { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this context, msg.sender
will always be the gateway address, as verified by Agent.invoke
. So having a gateway
parameter is redundant.
Also, prefer this naming in this context:
function transferNativeToGateway(address payable gateway, uint256 amount) external { | |
function transferEtherToGateway(address payable gateway, uint256 amount) external { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in aca3846
contracts/src/Assets.sol
Outdated
@@ -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)) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in a3e5aa4
@@ -144,7 +148,18 @@ library Assets { | |||
AssetsStorage.Layout storage $ = AssetsStorage.layout(); | |||
|
|||
// Lock the funds into AssetHub's agent contract | |||
_transferToAgent($.assetHubAgent, token, sender, amount); | |||
if (token != address(0)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the way you've introduced native ether support adds complexity by adding a lot of decision branches at the lowest level.
We already have branches at a higher level to choose between foreign, native tokens. We can add a branch for eth support there.
Concretely, I would suggest adding a new _sendEther
function instead of adding branches in _sendNativeToken
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in d8a9a58
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you reverted the _sendEther
and _sendNativeToken
split and merged it again. Just out of interest why?
contracts/src/Assets.sol
Outdated
payable($.assetHubAgent).safeNativeTransfer(amount); | ||
ticket.value = amount; | ||
|
||
ticket.dest = $.assetHubParaID; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in 0921ff9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome feature! 🥳
@@ -65,7 +65,7 @@ export const SNOWBRIDGE_ENV: { [id: string]: SnowbridgeEnvironment } = { | |||
erc20tokensReceivable: [ | |||
{ | |||
id: "WETH", | |||
address: "0x87d1f7fdfEe7f651FaBc8bFCB6E086C278b77A7d", | |||
address: "0x774667629726ec1FaBEbCEc0D9139bD1C8f72a23", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know why the WETH address changed?
// Ensure that arbitrary users cannot initialize storage in this logic contract. | ||
if (ERC1967.load() == address(0)) { | ||
revert Unauthorized(); | ||
} | ||
|
||
// We expect version 0, deploying version 1. | ||
CoreStorage.Layout storage $ = CoreStorage.layout(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this for?
For the next upgrade after this, we'll deploy a new contract like Gateway202506.sol
with different initializer code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It stops us from deploying this instance of Gateway202410 twice and hence running the same migration twice. I know this is controlled by governance, but an explicit way to do this in code is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we can consider adding a version check, but I don't think this PR is the right place for it.
I will remove the version check for the time being.
* do not dispatch transfer from native command * test to make sure the behavior is off * fmt * naming
0921ff9
to
ddad89f
Compare
ticket.dest = $.assetHubParaID; | ||
ticket.costs = _sendTokenCosts(destinationChain, destinationChainFee, maxDestinationChainFee); | ||
|
||
// Construct a message payload | ||
if (destinationChain == $.assetHubParaID) { | ||
// The funds will be minted into the receiver's account on AssetHub | ||
if (destinationAddress.isAddress32()) { | ||
// The receiver has a 32-byte account ID | ||
ticket.payload = SubstrateTypes.SendTokenToAssetHubAddress32( | ||
token, destinationAddress.asAddress32(), $.assetHubReserveTransferFee, amount | ||
); | ||
} else { | ||
// AssetHub does not support 20-byte account IDs | ||
revert Unsupported(); | ||
} | ||
} else { | ||
if (destinationChainFee == 0) { | ||
revert InvalidDestinationFee(); | ||
} | ||
// The funds will be minted into sovereign account of the destination parachain on AssetHub, | ||
// and then reserve-transferred to the receiver's account on the destination parachain. | ||
if (destinationAddress.isAddress32()) { | ||
// The receiver has a 32-byte account ID | ||
ticket.payload = SubstrateTypes.SendTokenToAddress32( | ||
token, | ||
destinationChain, | ||
destinationAddress.asAddress32(), | ||
$.assetHubReserveTransferFee, | ||
destinationChainFee, | ||
amount | ||
); | ||
} else if (destinationAddress.isAddress20()) { | ||
// The receiver has a 20-byte account ID | ||
ticket.payload = SubstrateTypes.SendTokenToAddress20( | ||
token, | ||
destinationChain, | ||
destinationAddress.asAddress20(), | ||
$.assetHubReserveTransferFee, | ||
destinationChainFee, | ||
amount | ||
); | ||
} else { | ||
revert Unsupported(); | ||
} | ||
} | ||
|
||
emit IGateway.TokenSent(token, sender, destinationChain, destinationAddress, amount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block can be replaced by calling _emitSendNativeTokenTicket
.
@@ -144,7 +148,18 @@ library Assets { | |||
AssetsStorage.Layout storage $ = AssetsStorage.layout(); | |||
|
|||
// Lock the funds into AssetHub's agent contract | |||
_transferToAgent($.assetHubAgent, token, sender, amount); | |||
if (token != address(0)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you reverted the _sendEther
and _sendNativeToken
split and merged it again. Just out of interest why?
Changes
0x0000000000000000000000000000000000000000
token address as Native ETH.0x00..
an amount ofmsg.value
is locked in asset hub agent.Related polkadot-sdk: paritytech/polkadot-sdk#6855
TODO
Resolves: https://linear.app/snowfork/issue/SNO-1222