@@ -8,6 +8,7 @@ import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.s
88
99import { IOFT, SendParam, MessagingFee } from "@layerzerolabs/oft-evm/contracts/interfaces/IOFT.sol " ;
1010import { IOAppCore } from "@layerzerolabs/oapp-evm/contracts/oapp/interfaces/IOAppCore.sol " ;
11+ import { ILayerZeroEndpointV2 } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol " ;
1112import { OFTComposeMsgCodec } from "@layerzerolabs/oft-evm/contracts/libs/OFTComposeMsgCodec.sol " ;
1213
1314import { IOVaultComposer, FailedMessage, FailedState } from "./interfaces/IOVaultComposer.sol " ;
@@ -22,6 +23,7 @@ contract OVaultComposer is IOVaultComposer, ReentrancyGuard {
2223 address public immutable SHARE_OFT;
2324 address public immutable OVAULT;
2425 address public immutable ENDPOINT;
26+ uint32 public immutable COMPOSER_EID;
2527
2628 mapping (bytes32 guid = > FailedMessage) public failedMessages;
2729
@@ -36,6 +38,7 @@ contract OVaultComposer is IOVaultComposer, ReentrancyGuard {
3638 SHARE_OFT = IOVault (_ovault).SHARE_OFT ();
3739 ASSET_OFT = IOVault (_ovault).ASSET_OFT ();
3840 ENDPOINT = address (IOAppCore (ASSET_OFT).endpoint ());
41+ COMPOSER_EID = ILayerZeroEndpointV2 (ENDPOINT).eid ();
3942
4043 // Approve the adapter to spend the share tokens held by this contract
4144 IERC20 (share).approve (OVAULT, type (uint256 ).max);
@@ -138,6 +141,18 @@ contract OVaultComposer is IOVaultComposer, ReentrancyGuard {
138141 /// @dev External call for try...catch logic in lzCompose()
139142 function send (address _oft , SendParam calldata _sendParam ) external payable nonReentrant {
140143 if (msg .sender != address (this )) revert OnlySelf (msg .sender );
144+ if (_sendParam.dstEid != COMPOSER_EID) {
145+ address _receiver = _sendParam.to.bytes32ToAddress ();
146+ uint256 _amountLD = _sendParam.amountLD;
147+ IERC20 token = IERC20 (IOFT (_oft).token ());
148+ token.transfer (_receiver, _amountLD);
149+ if (msg .value > 0 ) {
150+ (bool sent , ) = _receiver.call { value: msg .value }("" );
151+ require (sent, "Failed to send Ether " );
152+ }
153+ emit SentOnHub (_receiver, _oft, _amountLD);
154+ return ;
155+ }
141156 _send (_oft, _sendParam);
142157 }
143158
0 commit comments