Skip to content

Commit 03806e8

Browse files
committed
fix: if target network is the hub then token.transfer() the tokens to the user along with msg.value
Signed-off-by: shankar <shankar@layerzerolabs.org>
1 parent 5a16ea5 commit 03806e8

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

packages/ovault-composer/contracts/OVaultComposer.sol

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.s
88

99
import { IOFT, SendParam, MessagingFee } from "@layerzerolabs/oft-evm/contracts/interfaces/IOFT.sol";
1010
import { IOAppCore } from "@layerzerolabs/oapp-evm/contracts/oapp/interfaces/IOAppCore.sol";
11+
import { ILayerZeroEndpointV2 } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
1112
import { OFTComposeMsgCodec } from "@layerzerolabs/oft-evm/contracts/libs/OFTComposeMsgCodec.sol";
1213

1314
import { 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

packages/ovault-composer/contracts/interfaces/IOVaultComposer.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ interface IOVaultComposer is IOAppComposer {
2222
/// ========================== EVENTS =====================================
2323
event DecodeFailed(bytes32 indexed guid, address indexed oft, bytes message);
2424
event Sent(bytes32 indexed guid, address indexed oft);
25+
event SentOnHub(address indexed receiver, address indexed oft, uint256 amountLD);
2526
event SendFailed(bytes32 indexed guid, address indexed oft);
2627
event Refunded(bytes32 indexed guid, address indexed oft);
2728
event Retried(bytes32 indexed guid, address indexed oft);

0 commit comments

Comments
 (0)