The home for Hyperlane core contracts, sdk packages, and other infrastructure
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.
 
 
 
 
 
 
hyperlane-monorepo/solidity/optics-xapps/contracts/XAppConnectionClient.sol

77 lines
2.4 KiB

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
// ============ External Imports ============
import {Home} from "@celo-org/optics-sol/contracts/Home.sol";
import {XAppConnectionManager} from "@celo-org/optics-sol/contracts/XAppConnectionManager.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
abstract contract XAppConnectionClient is OwnableUpgradeable {
// ============ Mutable Storage ============
XAppConnectionManager public xAppConnectionManager;
uint256[49] private __GAP; // gap for upgrade safety
// ============ Modifiers ============
/**
* @notice Only accept messages from an Optics Replica contract
*/
modifier onlyReplica() {
require(_isReplica(msg.sender), "!replica");
_;
}
// ======== Initializer =========
function __XAppConnectionClient_initialize(address _xAppConnectionManager)
internal
initializer
{
xAppConnectionManager = XAppConnectionManager(_xAppConnectionManager);
__Ownable_init();
}
// ============ External functions ============
/**
* @notice Modify the contract the xApp uses to validate Replica contracts
* @param _xAppConnectionManager The address of the xAppConnectionManager contract
*/
function setXAppConnectionManager(address _xAppConnectionManager)
external
onlyOwner
{
xAppConnectionManager = XAppConnectionManager(_xAppConnectionManager);
}
// ============ Internal functions ============
/**
* @notice Get the local Home contract from the xAppConnectionManager
* @return The local Home contract
*/
function _home() internal view returns (Home) {
return xAppConnectionManager.home();
}
/**
* @notice Determine whether _potentialReplcia is an enrolled Replica from the xAppConnectionManager
* @return True if _potentialReplica is an enrolled Replica
*/
function _isReplica(address _potentialReplica)
internal
view
returns (bool)
{
return xAppConnectionManager.isReplica(_potentialReplica);
}
/**
* @notice Get the local domain from the xAppConnectionManager
* @return The local domain
*/
function _localDomain() internal view virtual returns (uint32) {
return xAppConnectionManager.localDomain();
}
}