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

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/example-native-token-transfers.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/evm/src/NttManager/NttManager.sol b/evm/src/NttManager/NttManager.sol
index 7ac021b..60e4aee 100644
--- a/evm/src/NttManager/NttManager.sol
+++ b/evm/src/NttManager/NttManager.sol
@@ -383,7 +383,7 @@ contract NttManager is INttManager, RateLimiter, ManagerBase {
bytes32 refundAddress,
bool shouldQueue,
bytes memory transceiverInstructions
- ) internal returns (uint64) {
+ ) internal virtual returns (uint64) {
if (amount == 0) {
revert ZeroAmount();
}
5 changes: 5 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ jobs:
with:
submodules: recursive

- name: Apply patch
run: |
cd lib/example-native-token-transfers
git apply ../../.github/example-native-token-transfers.diff

- name: Setup Node
uses: actions/setup-node@v4

Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/test-fork.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ jobs:
with:
submodules: recursive

- name: Apply patch
run: |
cd lib/example-native-token-transfers
git apply ../../.github/example-native-token-transfers.diff

- name: Setup Node
uses: actions/setup-node@v4

Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/test-gas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ jobs:
with:
submodules: recursive

- name: Apply patch
run: |
cd lib/example-native-token-transfers
git apply ../../.github/example-native-token-transfers.diff

- name: Setup Node
uses: actions/setup-node@v4

Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/test-sizes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ jobs:
with:
submodules: recursive

- name: Apply patch
run: |
cd lib/example-native-token-transfers
git apply ../../.github/example-native-token-transfers.diff

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

Expand Down
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ via_ir = false
[profile.production]
build_info = true
optimizer = true
optimizer_runs = 800
optimizer_runs = 1500
sizes = true
via_ir = true

Expand Down
38 changes: 10 additions & 28 deletions src/HubPortal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ import { TypeConverter } from "./libs/TypeConverter.sol";
contract HubPortal is IHubPortal, Portal {
using TypeConverter for address;

/// @dev Use only standard WormholeTransceiver with relaying enabled
bytes public constant DEFAULT_TRANSCEIVER_INSTRUCTIONS = new bytes(1);

/* ============ Variables ============ */

/// @inheritdoc IHubPortal
Expand Down Expand Up @@ -54,7 +51,7 @@ contract HubPortal is IHubPortal, Portal {
) external payable returns (bytes32 messageId_) {
uint128 index_ = _currentIndex();
bytes memory payload_ = PayloadEncoder.encodeIndex(index_, destinationChainId_);
messageId_ = _sendMessage(destinationChainId_, refundAddress_, payload_);
messageId_ = _sendCustomMessage(destinationChainId_, refundAddress_, payload_);

emit MTokenIndexSent(destinationChainId_, messageId_, index_);
}
Expand All @@ -67,7 +64,7 @@ contract HubPortal is IHubPortal, Portal {
) external payable returns (bytes32 messageId_) {
bytes32 value_ = IRegistrarLike(registrar).get(key_);
bytes memory payload_ = PayloadEncoder.encodeKey(key_, value_, destinationChainId_);
messageId_ = _sendMessage(destinationChainId_, refundAddress_, payload_);
messageId_ = _sendCustomMessage(destinationChainId_, refundAddress_, payload_);

emit RegistrarKeySent(destinationChainId_, messageId_, key_, value_);
}
Expand All @@ -81,7 +78,7 @@ contract HubPortal is IHubPortal, Portal {
) external payable returns (bytes32 messageId_) {
bool status_ = IRegistrarLike(registrar).listContains(listName_, account_);
bytes memory payload_ = PayloadEncoder.encodeListUpdate(listName_, account_, status_, destinationChainId_);
messageId_ = _sendMessage(destinationChainId_, refundAddress_, payload_);
messageId_ = _sendCustomMessage(destinationChainId_, refundAddress_, payload_);

emit RegistrarListStatusSent(destinationChainId_, messageId_, listName_, account_, status_);
}
Expand Down Expand Up @@ -118,43 +115,28 @@ contract HubPortal is IHubPortal, Portal {
* @param amount_ The amount of M Token to unlock to the recipient.
*/
function _mintOrUnlock(address recipient_, uint256 amount_, uint128) internal override {
IERC20(mToken()).transfer(recipient_, amount_);
if (recipient_ != address(this)) {
IERC20(mToken()).transfer(recipient_, amount_);
}
}

/// @notice Sends a generic message to the destination chain.
/// @dev The implementation is adapted from `NttManager` `_transfer` function.
function _sendMessage(
/// @dev Sends a custom (not a transfer) message to the destination chain.
function _sendCustomMessage(
uint16 destinationChainId_,
bytes32 refundAddress_,
bytes memory payload_
) private returns (bytes32 messageId_) {
if (refundAddress_ == bytes32(0)) revert InvalidRefundAddress();

(
address[] memory enabledTransceivers_,
TransceiverStructs.TransceiverInstruction[] memory instructions_,
uint256[] memory priceQuotes_,

) = _prepareForTransfer(destinationChainId_, DEFAULT_TRANSCEIVER_INSTRUCTIONS);

TransceiverStructs.NttManagerMessage memory message_ = TransceiverStructs.NttManagerMessage(
bytes32(uint256(_useMessageSequence())),
msg.sender.toBytes32(),
payload_
);

// send the message
_sendMessageToTransceivers(
destinationChainId_,
refundAddress_,
_getPeersStorage()[destinationChainId_].peerAddress,
priceQuotes_,
instructions_,
enabledTransceivers_,
TransceiverStructs.encodeNttManagerMessage(message_)
);
_sendMessage(destinationChainId_, refundAddress_, message_);

return TransceiverStructs.nttManagerMessageDigest(chainId, message_);
messageId_ = TransceiverStructs.nttManagerMessageDigest(chainId, message_);
}

/* ============ Internal View/Pure Functions ============ */
Expand Down
Loading
Loading