You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
3.0 KiB
95 lines
3.0 KiB
4 years ago
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||
|
pragma solidity >=0.6.11;
|
||
|
|
||
3 years ago
|
// ============ Internal Imports ============
|
||
|
import {Outbox} from "../Outbox.sol";
|
||
|
import {XAppConnectionManager} from "../XAppConnectionManager.sol";
|
||
4 years ago
|
// ============ External Imports ============
|
||
3 years ago
|
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
||
4 years ago
|
|
||
3 years ago
|
abstract contract XAppConnectionClient is OwnableUpgradeable {
|
||
4 years ago
|
// ============ Mutable Storage ============
|
||
|
|
||
|
XAppConnectionManager public xAppConnectionManager;
|
||
3 years ago
|
uint256[49] private __GAP; // gap for upgrade safety
|
||
4 years ago
|
|
||
3 years ago
|
// ============ Events ============
|
||
|
|
||
|
/**
|
||
|
* @notice Emitted when a new xAppConnectionManager is set.
|
||
|
* @param xAppConnectionManager The address of the xAppConnectionManager contract
|
||
|
*/
|
||
|
event SetXAppConnectionManager(address indexed xAppConnectionManager);
|
||
|
|
||
4 years ago
|
// ============ Modifiers ============
|
||
|
|
||
|
/**
|
||
3 years ago
|
* @notice Only accept messages from an Abacus Inbox contract
|
||
4 years ago
|
*/
|
||
3 years ago
|
modifier onlyInbox() {
|
||
|
require(_isInbox(msg.sender), "!inbox");
|
||
4 years ago
|
_;
|
||
|
}
|
||
|
|
||
3 years ago
|
// ======== Initializer =========
|
||
4 years ago
|
|
||
3 years ago
|
function __XAppConnectionClient_initialize(address _xAppConnectionManager)
|
||
|
internal
|
||
|
initializer
|
||
|
{
|
||
4 years ago
|
xAppConnectionManager = XAppConnectionManager(_xAppConnectionManager);
|
||
3 years ago
|
__Ownable_init();
|
||
4 years ago
|
}
|
||
|
|
||
|
// ============ External functions ============
|
||
|
|
||
|
/**
|
||
3 years ago
|
* @notice Modify the contract the xApp uses to validate Inbox contracts
|
||
4 years ago
|
* @param _xAppConnectionManager The address of the xAppConnectionManager contract
|
||
|
*/
|
||
|
function setXAppConnectionManager(address _xAppConnectionManager)
|
||
|
external
|
||
3 years ago
|
virtual
|
||
4 years ago
|
onlyOwner
|
||
|
{
|
||
3 years ago
|
_setXAppConnectionManager(_xAppConnectionManager);
|
||
4 years ago
|
}
|
||
|
|
||
|
// ============ Internal functions ============
|
||
|
|
||
3 years ago
|
/**
|
||
|
* @notice Modify the contract the xApp uses to validate Inbox contracts
|
||
|
* @param _xAppConnectionManager The address of the xAppConnectionManager contract
|
||
|
*/
|
||
|
function _setXAppConnectionManager(address _xAppConnectionManager)
|
||
|
internal
|
||
|
{
|
||
|
xAppConnectionManager = XAppConnectionManager(_xAppConnectionManager);
|
||
|
emit SetXAppConnectionManager(_xAppConnectionManager);
|
||
|
}
|
||
|
|
||
4 years ago
|
/**
|
||
3 years ago
|
* @notice Get the local Outbox contract from the xAppConnectionManager
|
||
|
* @return The local Outbox contract
|
||
4 years ago
|
*/
|
||
3 years ago
|
function _outbox() internal view returns (Outbox) {
|
||
|
return xAppConnectionManager.outbox();
|
||
4 years ago
|
}
|
||
|
|
||
|
/**
|
||
3 years ago
|
* @notice Determine whether _potentialInbox is an enrolled Inbox from the xAppConnectionManager
|
||
|
* @return True if _potentialInbox is an enrolled Inbox
|
||
4 years ago
|
*/
|
||
3 years ago
|
function _isInbox(address _potentialInbox) internal view returns (bool) {
|
||
|
return xAppConnectionManager.isInbox(_potentialInbox);
|
||
4 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* @notice Get the local domain from the xAppConnectionManager
|
||
|
* @return The local domain
|
||
|
*/
|
||
3 years ago
|
function _localDomain() internal view virtual returns (uint32) {
|
||
4 years ago
|
return xAppConnectionManager.localDomain();
|
||
|
}
|
||
|
}
|