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

Feat: Wrapped M bridging #34

Merged
merged 36 commits into from
Feb 3, 2025
Merged

Feat: Wrapped M bridging #34

merged 36 commits into from
Feb 3, 2025

Conversation

0xIryna
Copy link
Collaborator

@0xIryna 0xIryna commented Jan 16, 2025

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

  • add a mapping to store addresses of $M token on the remote chain. It will be used to determine the destination $M address when INttManager.transfer function is called. The mapping can be updated only by the owner.
  • add a mapping to store the supported bridging paths between local and remote chains. The mapping can be updated only by the owner.
  • add transferMLikeToken function to transfer a generic M like token by specifying source and destination token addresses. Under the hood, if the source token is Wrapped M token, it's unwrapped to M token, M token is bridged and wrapped back on the destination if needed.
  • extend Token Transfer additional payload to include the address of destination M token.
  • modify _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. We decided to fork Wormhole's native-transfer-tokens repo and make _transferEntryPoint functions virtual to reduce code duplication and prevent Yul stack too deep issues.

Next Steps:

  • consider leaving extra $M token in Portal contracts to prevent rounding issues when $M is transferred between non-earning users and earning Portal

Copy link

github-actions bot commented Jan 16, 2025

LCOV of commit f7fef0b during Forge Coverage #176

Summary coverage rate:
  lines......: 84.8% (284 of 335 lines)
  functions..: 78.0% (64 of 82 functions)
  branches...: 73.7% (28 of 38 branches)

Files changed coverage rate:
                                 |Lines       |Functions  |Branches    
  Filename                       |Rate     Num|Rate    Num|Rate     Num
  =====================================================================
  src/HubPortal.sol              |23.1%     39| 0.0%     9|    -      0
  src/Portal.sol                 |22.5%     89| 106%    18|    -      0
  src/SpokePortal.sol            |20.0%     35| 143%     7|    -      0
  src/SpokeVault.sol             |16.7%     24| 0.0%     4|    -      0
  src/governance/Configurator.sol|    -      0|    -     0|    -      0
  src/governance/Migrator.sol    |    -      0|    -     0|    -      0
  src/libs/PayloadEncoder.sol    |21.3%     47| 0.0%    10|    -      0
  src/libs/SafeCall.sol          |33.3%      3| 0.0%     1|    -      0

@0xIryna 0xIryna marked this pull request as draft January 16, 2025 18:09
src/Portal.sol Outdated Show resolved Hide resolved
src/Portal.sol Outdated Show resolved Hide resolved
src/Portal.sol Outdated Show resolved Hide resolved
src/interfaces/IPortal.sol Outdated Show resolved Hide resolved
src/Portal.sol Outdated Show resolved Hide resolved
src/interfaces/IPortal.sol Outdated Show resolved Hide resolved
src/interfaces/IPortal.sol Outdated Show resolved Hide resolved
src/interfaces/IPortal.sol Outdated Show resolved Hide resolved
@toninorair toninorair marked this pull request as ready for review January 27, 2025 17:08
src/Portal.sol Outdated Show resolved Hide resolved
src/Portal.sol Outdated Show resolved Hide resolved
script/deploy/DeployBase.sol Outdated Show resolved Hide resolved
script/deploy/DeployBase.sol Outdated Show resolved Hide resolved
script/helpers/Utils.sol Outdated Show resolved Hide resolved
src/interfaces/IPortal.sol Outdated Show resolved Hide resolved
src/Portal.sol Outdated Show resolved Hide resolved
src/Portal.sol Show resolved Hide resolved
src/SpokePortal.sol Outdated Show resolved Hide resolved
test/fork/Deploy.t.sol Outdated Show resolved Hide resolved
@0xIryna 0xIryna requested a review from PierrickGT January 30, 2025 05:05
@0xIryna 0xIryna merged commit 9c72c13 into main Feb 3, 2025
2 of 4 checks passed
@0xIryna 0xIryna deleted the feat/wrapped-m-bridging branch February 3, 2025 21:11
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.

3 participants