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/app/contracts/XAppConnectionClient.sol

107 lines
3.5 KiB

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
// ============ Internal Imports ============
import {IInterchainGasPaymaster} from "@abacus-network/core/interfaces/IInterchainGasPaymaster.sol";
import {IOutbox} from "@abacus-network/core/interfaces/IOutbox.sol";
import {IXAppConnectionManager} from "@abacus-network/core/interfaces/IXAppConnectionManager.sol";
// ============ External Imports ============
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
abstract contract XAppConnectionClient is OwnableUpgradeable {
// ============ Mutable Storage ============
IXAppConnectionManager public xAppConnectionManager;
uint256[49] private __GAP; // gap for upgrade safety
// ============ Events ============
/**
* @notice Emitted when a new xAppConnectionManager is set.
* @param xAppConnectionManager The address of the xAppConnectionManager contract
*/
event SetXAppConnectionManager(address indexed xAppConnectionManager);
// ============ Modifiers ============
/**
* @notice Only accept messages from an Abacus Inbox contract
*/
modifier onlyInbox() {
require(_isInbox(msg.sender), "!inbox");
_;
}
// ======== Initializer =========
function __XAppConnectionClient_initialize(address _xAppConnectionManager)
internal
{
_setXAppConnectionManager(_xAppConnectionManager);
__Ownable_init();
}
// ============ External functions ============
/**
* @notice Modify the contract the xApp uses to validate Inbox contracts
* @param _xAppConnectionManager The address of the xAppConnectionManager contract
*/
function setXAppConnectionManager(address _xAppConnectionManager)
external
virtual
onlyOwner
{
_setXAppConnectionManager(_xAppConnectionManager);
}
// ============ Internal functions ============
/**
* @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 = IXAppConnectionManager(_xAppConnectionManager);
emit SetXAppConnectionManager(_xAppConnectionManager);
}
/**
* @notice Get the local Outbox contract from the xAppConnectionManager
* @return The local Outbox contract
*/
function _outbox() internal view returns (IOutbox) {
return xAppConnectionManager.outbox();
}
/**
* @notice Gets the local Interchain Gas Paymaster contract from the xAppConnectionManager.
* @return The local Interchain Gas Paymaster contract.
*/
function _interchainGasPaymaster()
internal
view
returns (IInterchainGasPaymaster)
{
return xAppConnectionManager.interchainGasPaymaster();
}
/**
* @notice Determine whether _potentialInbox is an enrolled Inbox from the xAppConnectionManager
* @return True if _potentialInbox is an enrolled Inbox
*/
function _isInbox(address _potentialInbox) internal view returns (bool) {
return xAppConnectionManager.isInbox(_potentialInbox);
}
/**
* @notice Get the local domain from the xAppConnectionManager
* @return The local domain
*/
function _localDomain() internal view virtual returns (uint32) {
return xAppConnectionManager.localDomain();
}
}