@@ -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);
@@ -129,6 +132,10 @@ contract OVaultComposer is IOVaultComposer, ReentrancyGuard {
129132
130133 /// @dev Dirty swapping amountLD and minAmountLD to 1e18 and 0 to avoid Slippage issue on the target OFT quoteSend()
131134 function validateTargetOFTConfig (address _oft , SendParam memory _sendParam ) external view {
135+ if (COMPOSER_EID == _sendParam.dstEid) {
136+ return ;
137+ }
138+
132139 _sendParam.amountLD = 1e18 ;
133140 _sendParam.minAmountLD = 0 ;
134141
@@ -138,6 +145,18 @@ contract OVaultComposer is IOVaultComposer, ReentrancyGuard {
138145 /// @dev External call for try...catch logic in lzCompose()
139146 function send (address _oft , SendParam calldata _sendParam ) external payable nonReentrant {
140147 if (msg .sender != address (this )) revert OnlySelf (msg .sender );
148+ if (_sendParam.dstEid == COMPOSER_EID) {
149+ address _receiver = _sendParam.to.bytes32ToAddress ();
150+ uint256 _amountLD = _sendParam.amountLD;
151+ IERC20 token = IERC20 (IOFT (_oft).token ());
152+ token.transfer (_receiver, _amountLD);
153+ if (msg .value > 0 ) {
154+ (bool sent , ) = _receiver.call { value: msg .value }("" );
155+ require (sent, "Failed to send Ether " );
156+ }
157+ emit SentOnHub (_receiver, _oft, _amountLD);
158+ return ;
159+ }
141160 _send (_oft, _sendParam);
142161 }
143162
0 commit comments