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

Jamie/merge conflicts #6

Merged
merged 8 commits into from
Aug 8, 2024
Prev Previous commit
Next Next commit
feat: after receive and custom bridge messageIDs emmited
CarsonCase committed Aug 1, 2024
commit 5f061d0be156c71f61553dcebfe3f8c8fc489d47
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ contract CrossChainOPTellerWithMultiAssetSupport is CrossChainTellerBase {

uint32 public maxMessageGas;
uint32 public minMessageGas;
uint128 public nonce;

error CrossChainOPTellerWithMultiAssetSupport_OnlyMessenger();
error CrossChainOPTellerWithMultiAssetSupport_OnlyPeerAsSender();
@@ -60,7 +61,7 @@ contract CrossChainOPTellerWithMultiAssetSupport is CrossChainTellerBase {
* @param receiver to receive the shares
* @param shareMintAmount amount of shares to mint
*/
function receiveBridgeMessage(address receiver, uint256 shareMintAmount) external {
function receiveBridgeMessage(address receiver, uint256 shareMintAmount, bytes32 messageId) external {
_beforeReceive();

if (msg.sender != address(messenger)) {
@@ -72,20 +73,25 @@ contract CrossChainOPTellerWithMultiAssetSupport is CrossChainTellerBase {
}

vault.enter(address(0), ERC20(address(0)), 0, receiver, shareMintAmount);

_afterReceive(shareMintAmount, receiver, messageId);
}

/**
* @notice the virtual bridge function to execute Optimism messenger sendMessage()
* @param data bridge data
* @return messageId
*/
function _bridge(uint256 shareAmount, BridgeData calldata data) internal override returns (bytes32) {
function _bridge(uint256 shareAmount, BridgeData calldata data) internal override returns (bytes32 messageId) {
unchecked {
messageId = keccak256(abi.encodePacked(++nonce, address(this), block.chainid));
}

messenger.sendMessage(
peer,
abi.encodeCall(this.receiveBridgeMessage, (data.destinationChainReceiver, shareAmount)),
abi.encodeCall(this.receiveBridgeMessage, (data.destinationChainReceiver, shareAmount, messageId)),
uint32(data.messageGas)
);
return bytes32(0);
}

/**
22 changes: 16 additions & 6 deletions src/base/Roles/CrossChain/CrossChainTellerBase.sol
Original file line number Diff line number Diff line change
@@ -90,12 +90,6 @@ abstract contract CrossChainTellerBase is TellerWithMultiAssetSupport {
_afterBridge(shareAmount, data, messageId);
}

/**
* @notice the before bridge hook to perform additional checks
* @param data bridge data
*/
function _beforeBridge(BridgeData calldata data) internal virtual;

/**
* @notice the virtual bridge function to be overridden
* @param data bridge data
@@ -110,6 +104,12 @@ abstract contract CrossChainTellerBase is TellerWithMultiAssetSupport {
*/
function _quote(uint256 shareAmount, BridgeData calldata data) internal view virtual returns (uint256);

/**
* @notice the before bridge hook to perform additional checks
* @param data bridge data
*/
function _beforeBridge(BridgeData calldata data) internal virtual;

/**
* @notice after bridge code, just an emit but can be overriden
* @param shareAmount share amount burned
@@ -126,4 +126,14 @@ abstract contract CrossChainTellerBase is TellerWithMultiAssetSupport {
function _beforeReceive() internal virtual {
if (isPaused) revert TellerWithMultiAssetSupport__Paused();
}

/**
* @notice a hook to execute after receiving
* @param shareAmount the shareAmount that was minted
* @param destinationChainReceiver the receiver of the shares
* @param messageId the message ID
*/
function _afterReceive(uint256 shareAmount, address destinationChainReceiver, bytes32 messageId) internal virtual {
emit MessageReceived(messageId, shareAmount, destinationChainReceiver);
}
}
Original file line number Diff line number Diff line change
@@ -72,6 +72,8 @@ contract MultiChainLayerZeroTellerWithMultiAssetSupport is MultiChainTellerBase,
// Decode the payload to get the message
(uint256 shareAmount, address receiver) = abi.decode(payload, (uint256, address));
vault.enter(address(0), ERC20(address(0)), 0, receiver, shareAmount);

_afterReceive(shareAmount, receiver, _guid);
}

/**