diff --git a/contracts/relayer/ILayerZeroClientRelayer.sol b/contracts/relayer/ILayerZeroClientRelayer.sol new file mode 100644 index 0000000..8344ea5 --- /dev/null +++ b/contracts/relayer/ILayerZeroClientRelayer.sol @@ -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 +{ + +} diff --git a/contracts/relayer/ILayerZeroClientRelayerInternal.sol b/contracts/relayer/ILayerZeroClientRelayerInternal.sol new file mode 100644 index 0000000..cb7936a --- /dev/null +++ b/contracts/relayer/ILayerZeroClientRelayerInternal.sol @@ -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 { + +} diff --git a/contracts/relayer/LayerZeroClientRelayer.sol b/contracts/relayer/LayerZeroClientRelayer.sol new file mode 100644 index 0000000..636bfcd --- /dev/null +++ b/contracts/relayer/LayerZeroClientRelayer.sol @@ -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 +{ + +} diff --git a/contracts/relayer/LayerZeroClientRelayerInternal.sol b/contracts/relayer/LayerZeroClientRelayerInternal.sol new file mode 100644 index 0000000..c542b7f --- /dev/null +++ b/contracts/relayer/LayerZeroClientRelayerInternal.sol @@ -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'); + } + } +} diff --git a/contracts/relayer/LayerZeroClientRelayerMock.sol b/contracts/relayer/LayerZeroClientRelayerMock.sol new file mode 100644 index 0000000..b654c9d --- /dev/null +++ b/contracts/relayer/LayerZeroClientRelayerMock.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import { LayerZeroClientRelayer } from './LayerZeroClientRelayer.sol'; + +contract LayerZeroClientRelayerMock is LayerZeroClientRelayer {}