-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: separation of the app-agnostic gateway interfaces and the K…
…leros-specific gateways
- Loading branch information
Showing
19 changed files
with
284 additions
and
271 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
/** | ||
* @authors: [@jaybuidl, @shotaronowhere] | ||
* @reviewers: [] | ||
* @auditors: [] | ||
* @bounties: [] | ||
* @deployments: [] | ||
*/ | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "../../bridge/interfaces/IFastBridgeReceiver.sol"; | ||
|
||
interface IReceiverGateway { | ||
function fastBridgeReceiver() external view returns (IFastBridgeReceiver); | ||
|
||
function senderChainID() external view returns (uint256); | ||
|
||
function senderGateway() external view returns (address); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
/** | ||
* @authors: [@jaybuidl, @shotaronowhere] | ||
* @reviewers: [] | ||
* @auditors: [] | ||
* @bounties: [] | ||
* @deployments: [] | ||
*/ | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "../../bridge/interfaces/IFastBridgeSender.sol"; | ||
|
||
interface ISenderGateway { | ||
function fastBridgeSender() external view returns (IFastBridgeSender); | ||
|
||
function receiverChainID() external view returns (uint256); | ||
|
||
function receiverGateway() external view returns (address); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "../../interfaces/ISenderGateway.sol"; | ||
|
||
interface ISenderGatewayMock is ISenderGateway {} |
66 changes: 66 additions & 0 deletions
66
contracts/src/bridge/test/gateways/ReceiverGatewayMock.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,66 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
/** | ||
* @authors: [@shotaronowhere] | ||
* @reviewers: [] | ||
* @auditors: [] | ||
* @bounties: [] | ||
* @deployments: [] | ||
*/ | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "./IReceiverGatewayMock.sol"; | ||
|
||
/** | ||
* Receiver Gateway Mock | ||
* Counterpart of `SenderGatewayMock` | ||
*/ | ||
contract ReceiverGatewayMock is IReceiverGateway { | ||
IFastBridgeReceiver public immutable fastBridgeReceiver; | ||
address public immutable override senderGateway; | ||
uint256 public immutable override senderChainID; | ||
|
||
uint256 public messageCount; | ||
uint256 public data; | ||
|
||
constructor( | ||
IFastBridgeReceiver _fastBridgeReceiver, | ||
address _senderGateway, | ||
uint256 _senderChainID | ||
) { | ||
fastBridgeReceiver = _fastBridgeReceiver; | ||
senderGateway = _senderGateway; | ||
senderChainID = _senderChainID; | ||
} | ||
|
||
modifier onlyFromFastBridge() { | ||
require(address(fastBridgeReceiver) == msg.sender, "Fast Bridge only."); | ||
_; | ||
} | ||
|
||
/** | ||
* Receive the message from the sender gateway. | ||
*/ | ||
function receiveMessage(address _messageSender) external onlyFromFastBridge { | ||
require(_messageSender == senderGateway, "Only the sender gateway is allowed."); | ||
_receiveMessage(); | ||
} | ||
|
||
/** | ||
* Receive the message from the sender gateway. | ||
*/ | ||
function receiveMessage(address _messageSender, uint256 _data) external onlyFromFastBridge { | ||
require(_messageSender == senderGateway, "Only the sender gateway is allowed."); | ||
_receiveMessage(_data); | ||
} | ||
|
||
function _receiveMessage() internal { | ||
messageCount++; | ||
} | ||
|
||
function _receiveMessage(uint256 _data) internal { | ||
messageCount++; | ||
data = _data; | ||
} | ||
} |
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,47 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
/** | ||
* @authors: [@shotaronowhere] | ||
* @reviewers: [] | ||
* @auditors: [] | ||
* @bounties: [] | ||
* @deployments: [] | ||
*/ | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "./IReceiverGatewayMock.sol"; | ||
import "../../interfaces/ISenderGateway.sol"; | ||
|
||
/** | ||
* Sender Gateway | ||
* Counterpart of `ReceiverGatewayMock` | ||
*/ | ||
contract SenderGatewayMock is ISenderGateway { | ||
IFastBridgeSender public immutable fastBridgeSender; | ||
address public override receiverGateway; | ||
uint256 public immutable override receiverChainID; | ||
|
||
struct RelayedData { | ||
uint256 arbitrationCost; | ||
address relayer; | ||
} | ||
mapping(bytes32 => RelayedData) public disputeHashtoRelayedData; | ||
|
||
constructor( | ||
IFastBridgeSender _fastBridgeSender, | ||
address _receiverGateway, | ||
uint256 _receiverChainID | ||
) { | ||
fastBridgeSender = _fastBridgeSender; | ||
receiverGateway = _receiverGateway; | ||
receiverChainID = _receiverChainID; | ||
} | ||
|
||
function sendFastMessage(uint256 _data) external { | ||
bytes4 methodSelector = IReceiverGatewayMock.receiveMessage.selector; | ||
bytes memory data = abi.encodeWithSelector(methodSelector, _data); | ||
|
||
fastBridgeSender.sendFast(receiverGateway, data); | ||
} | ||
} |
Oops, something went wrong.