-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
534 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
helix-contract/contracts/ln/messager/Eth2ScrollReceiveService.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.17; | ||
|
||
import "./interface/IScrollMessenger.sol"; | ||
import "../base/LnAccessController.sol"; | ||
import "../interface/ILowLevelMessager.sol"; | ||
|
||
// from ethereum to arbitrum messager | ||
contract Eth2ScrollReceiveService is ILowLevelMessageReceiver, LnAccessController { | ||
uint256 immutable public REMOTE_CHAINID; | ||
address immutable public scrollMessager; | ||
address public remoteMessager; | ||
|
||
mapping(address=>address) public appPairs; | ||
|
||
modifier onlyRemoteBridge() { | ||
require(msg.sender == scrollMessager, "invalid caller"); | ||
require(remoteMessager == IScrollMessenger(scrollMessager).xDomainMessageSender(), "invalid remote caller"); | ||
_; | ||
} | ||
|
||
constructor(address _dao, address _scrollMessager, uint256 _remoteChainId) { | ||
_initialize(_dao); | ||
REMOTE_CHAINID = _remoteChainId; | ||
scrollMessager = _scrollMessager; | ||
} | ||
|
||
function setRemoteMessager(address _remoteMessager) onlyDao external { | ||
remoteMessager = _remoteMessager; | ||
} | ||
|
||
function registerRemoteSender(uint256 _remoteChainId, address _remoteBridge) onlyWhiteListCaller external { | ||
require(_remoteChainId == REMOTE_CHAINID, "invalid remote chainId"); | ||
appPairs[msg.sender] = _remoteBridge; | ||
} | ||
|
||
function recvMessage(address _remoteApp, address _localApp, bytes memory _message) onlyRemoteBridge external { | ||
address remoteAppAddress = appPairs[_localApp]; | ||
require(remoteAppAddress == _remoteApp, "invalid remote app"); | ||
(bool result,) = _localApp.call(_message); | ||
require(result == true, "local call failed"); | ||
} | ||
} | ||
|
62 changes: 62 additions & 0 deletions
62
helix-contract/contracts/ln/messager/Eth2ScrollSendService.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.17; | ||
|
||
import "./interface/IScrollMessenger.sol"; | ||
import "../base/LnAccessController.sol"; | ||
import "../interface/ILowLevelMessager.sol"; | ||
|
||
contract Eth2ScrollSendService is ILowLevelMessageSender, LnAccessController { | ||
uint256 immutable public REMOTE_CHAINID; | ||
IScrollMessenger immutable public scrollMessager; | ||
address public remoteMessager; | ||
mapping(address=>address) public appPairs; | ||
|
||
constructor(address _dao, address _scrollMessager, uint256 _remoteChainId) { | ||
_initialize(_dao); | ||
scrollMessager = IScrollMessenger(_scrollMessager); | ||
REMOTE_CHAINID = _remoteChainId; | ||
} | ||
|
||
function setRemoteMessager(address _remoteMessager) onlyDao external { | ||
remoteMessager = _remoteMessager; | ||
} | ||
|
||
function registerRemoteReceiver(uint256 _remoteChainId, address _remoteBridge) onlyWhiteListCaller external { | ||
require(_remoteChainId == REMOTE_CHAINID, "invalid remote chainId"); | ||
appPairs[msg.sender] = _remoteBridge; | ||
} | ||
|
||
function sendMessage(uint256 _remoteChainId, bytes memory _message, bytes memory _params) onlyWhiteListCaller external payable { | ||
require(_remoteChainId == REMOTE_CHAINID, "invalid remote chainId"); | ||
address remoteAppAddress = appPairs[msg.sender]; | ||
require(remoteAppAddress != address(0), "app not registered"); | ||
|
||
(uint256 l2GasLimit, address refunder) = abi.decode(_params, (uint256, address)); | ||
|
||
bytes memory remoteReceiveCall = abi.encodeWithSelector( | ||
ILowLevelMessageReceiver.recvMessage.selector, | ||
msg.sender, | ||
remoteAppAddress, | ||
_message | ||
); | ||
scrollMessager.sendMessage{value: msg.value}( | ||
remoteMessager, | ||
0, | ||
remoteReceiveCall, | ||
l2GasLimit, | ||
refunder | ||
); | ||
} | ||
|
||
function fee(uint256 _l2GasLimit) external view returns(uint256) { | ||
address messageQueue = scrollMessager.messageQueue(); | ||
return IL1MessageQueue(messageQueue).estimateCrossDomainMessageFee(_l2GasLimit); | ||
} | ||
|
||
function encodeParams( | ||
uint256 _l2GasLimit, | ||
address _refunder | ||
) external pure returns(bytes memory) { | ||
return abi.encode(_l2GasLimit, _refunder); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
helix-contract/contracts/ln/messager/interface/IScrollMessenger.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.17; | ||
|
||
interface IScrollMessenger { | ||
function sendMessage(address target, uint256 value, bytes calldata message, uint256 gasLimit, address refundAddress) external payable; | ||
function messageQueue() external view returns (address); | ||
function xDomainMessageSender() external view returns (address); | ||
} | ||
|
||
interface IL1MessageQueue { | ||
function estimateCrossDomainMessageFee(uint256 gasLimit) external view returns(uint256); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.