-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feat: Wrapped M bridging #34
base: main
Are you sure you want to change the base?
Conversation
LCOV of commit
|
src/Portal.sol
Outdated
IERC20(sourceWrappedToken_).transferFrom(msg.sender, address(this), amount_); | ||
|
||
// unwrap Wrapped M token to M Token | ||
amount_ = IWrappedMTokenLike(sourceWrappedToken_).unwrap(address(this), 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.
Since we will be whitelisting the supported wrapped tokens, it seems safe to rely on the amount
returned by unwrap
.
Ideally we should retrieve the balance in the contract before, then after and compute the exact amount that was unwrapped.
src/Portal.sol
Outdated
|
||
uint256 totalPriceQuote_ = _sendMessage(destinationChainId_, refundAddress_, message_); | ||
|
||
emit MTokenSent(destinationChainId_, messageId_, msg.sender, recipient_, amount_, index_); |
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.
We should emit the WrappedMTokenSent
event for Wrapped tokens.
// unwrap Wrapped M token to M Token | ||
amount_ = IWrappedMTokenLike(sourceWrappedToken_).unwrap(address(this), amount_); | ||
|
||
// NOTE: the following code has been adapted from NTT manager `transfer` or `_transferEntryPoint` functions. |
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.
Since we are not using _transferEntryPoint
, shouldn't this function burn M on Spoke chains and lock it on the Hub chain?
src/interfaces/IPortal.sol
Outdated
* @param sender The address that bridged the M tokens via the Portal. | ||
* @param recipient The account receiving tokens on destination chain. | ||
* @param amount The amount of tokens. | ||
* @param index The the M token index. |
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.
* @param index The the M token index. | |
* @param index The M token index. |
src/Portal.sol
Outdated
_mintOrUnlock(address(this), amount_, index_); | ||
|
||
// wraps M token and transfers it to the recipient | ||
_wrap(destinationWrappedToken_, recipient_, 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.
We should emit the WrappedMTokenReceived
event for wrapped tokens.
src/interfaces/IPortal.sol
Outdated
* @param sourceWrappedToken The address of Wrapped M token on the source chain. | ||
* @param destinationChainId The Wormhole destination chain ID. | ||
* @param destinationWrappedToken The address of Wrapped M token on the destination chain. |
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.
The indentation can be fixed.
src/interfaces/IPortal.sol
Outdated
* @notice Sets the address of Wrapped M Token on the remote chain. | ||
* @param sourceWrappedToken The address of Wrapped M token on the source chain. | ||
* @param destinationChainId The Wormhole destination chain ID. | ||
* @param destinationWrappedToken The address of Wrapped M token on the destination chain. |
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.
Indentation can be fixed.
src/interfaces/IPortal.sol
Outdated
/** | ||
* @notice Transfers Wrapped M Token to the destination chain. | ||
* @param amount The amount of tokens to transfer. | ||
* @param sourceWrappedToken The address of the Wrapped M Token of the source chain. |
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.
* @param sourceWrappedToken The address of the Wrapped M Token of the source chain. | |
* @param sourceWrappedToken The address of the Wrapped M Token on the source chain. |
Motivation
Provide the ability to bridge both official M^0 Wrapped M token and generic M token extensions using M Portal by unwrapping tokens on the source, bridging M and wrapping them back on the destination. The proposed solution allows flexible bridging and wrapping. E.g., from M to Wrapped M, from M Extension to M, etc.
Proposed changes
mapping
to store the relationship between Wrapped M tokens on local and remote chains. The mapping can be updated only by the owner.transferWrappedMToken
function to transfer a generic Wrapped M token by specifying source token address. Under the hood, the Wrapped M token is unwrapped to M token on the source, M token is bridged and wrapped back on the destination._receiveMToken
to handle M Token wrapping on the destination. If wrapping fails, M token is transferred to the recipient.Challenges
Due to the current Wormhole NTT design it's not possible to utilize NTTManager functions for transferring Wrapped tokens and as a result some of the functionality from NTTManager contract is duplicated in Portal. In particular, we cannot call NTTManager's
transfer
or_transferEntryPoint
functions insidetransferWrappedMToken
as they attempt to transfer M token from themsg.sender
. We also cannot use NTTManager's_transfer
function since we cannot pass additional parameter (destination wrapped token address) to_prepareNativeTokenTransfer
function.Next Steps/Questions: