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

Add relayer module #7

Draft
wants to merge 1 commit into
base: master
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
16 changes: 16 additions & 0 deletions contracts/relayer/ILayerZeroClientRelayer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { ILayerZeroClientReceiver } from '../receiver/ILayerZeroClientReceiver.sol';
import { ILayerZeroClientRelayerInternal } from './ILayerZeroClientRelayerInternal.sol';

/**
* @title LayerZero Client Relayer interface
*/
interface ILayerZeroClientRelayer is
ILayerZeroClientReceiver,
ILayerZeroClientRelayerInternal
{

}
12 changes: 12 additions & 0 deletions contracts/relayer/ILayerZeroClientRelayerInternal.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { ILayerZeroClientReceiverInternal } from '../receiver/ILayerZeroClientReceiverInternal.sol';

/**
* @title Partial LayerZero Client Relayer interface needed by internal functions
*/
interface ILayerZeroClientRelayerInternal is ILayerZeroClientReceiverInternal {

}
18 changes: 18 additions & 0 deletions contracts/relayer/LayerZeroClientRelayer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { LayerZeroClientReceiver } from '../receiver/LayerZeroClientReceiver.sol';
import { ILayerZeroClientRelayer } from './ILayerZeroClientRelayer.sol';
import { LayerZeroClientRelayerInternal } from './LayerZeroClientRelayerInternal.sol';

/**
* @title LayerZero Client extension for support of cross-chain message receipt
*/
abstract contract LayerZeroClientRelayer is
ILayerZeroClientRelayer,
LayerZeroClientRelayerInternal,
LayerZeroClientReceiver
{

}
38 changes: 38 additions & 0 deletions contracts/relayer/LayerZeroClientRelayerInternal.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { LayerZeroClientReceiverInternal } from '../receiver/LayerZeroClientReceiverInternal.sol';
import { ILayerZeroClientRelayer } from './ILayerZeroClientRelayer.sol';
import { ILayerZeroClientRelayerInternal } from './ILayerZeroClientRelayerInternal.sol';

/**
* @title LayerZero Client Relayer internal functions
* @dev derived from https://github.com/LayerZero-Labs/solidity-examples/ (MIT License)
*/
abstract contract LayerZeroClientRelayerInternal is
ILayerZeroClientRelayerInternal,
LayerZeroClientReceiverInternal
{
/**
* @inheritdoc LayerZeroClientReceiverInternal
* @notice forward received LayerZero cross-chain message to encoded target address
* @dev TODO describe how to format relayable calls
*/
function _handleLayerZeroMessage(
uint16,
bytes calldata,
uint64,
bytes calldata data
) internal virtual override {
uint256 length = data.length;

unchecked {
address target = address(bytes20(data[length - 20:]));

(bool success, ) = target.call(data[:length - 20]);

if (!success) revert('TODO: return revert message');
}
}
}
7 changes: 7 additions & 0 deletions contracts/relayer/LayerZeroClientRelayerMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { LayerZeroClientRelayer } from './LayerZeroClientRelayer.sol';

contract LayerZeroClientRelayerMock is LayerZeroClientRelayer {}