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.
163 lines
5.8 KiB
163 lines
5.8 KiB
4 years ago
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||
|
pragma solidity >=0.6.11;
|
||
|
|
||
3 years ago
|
// ============ Internal Imports ============
|
||
3 years ago
|
import {IOutbox} from "../interfaces/IOutbox.sol";
|
||
3 years ago
|
import {IInterchainGasPaymaster} from "../interfaces/IInterchainGasPaymaster.sol";
|
||
3 years ago
|
import {IAbacusConnectionManager} from "../interfaces/IAbacusConnectionManager.sol";
|
||
3 years ago
|
// ============ External Imports ============
|
||
|
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
|
||
4 years ago
|
|
||
3 years ago
|
/**
|
||
3 years ago
|
* @title AbacusConnectionManager
|
||
3 years ago
|
* @author Celo Labs Inc.
|
||
3 years ago
|
* @notice Manages a registry of local Inbox contracts for remote Outbox
|
||
3 years ago
|
* domains.
|
||
3 years ago
|
*/
|
||
3 years ago
|
contract AbacusConnectionManager is IAbacusConnectionManager, Ownable {
|
||
3 years ago
|
// ============ Public Storage ============
|
||
4 years ago
|
|
||
3 years ago
|
// Outbox contract
|
||
3 years ago
|
IOutbox public override outbox;
|
||
3 years ago
|
// Interchain Gas Paymaster contract. The off-chain processor associated with
|
||
|
// the paymaster contract must be willing to process messages dispatched from
|
||
|
// the current Outbox contract, otherwise payments made to the paymaster will
|
||
|
// not result in processed messages.
|
||
3 years ago
|
IInterchainGasPaymaster public override interchainGasPaymaster;
|
||
3 years ago
|
// local Inbox address => remote Outbox domain
|
||
|
mapping(address => uint32) public inboxToDomain;
|
||
|
// remote Outbox domain => local Inbox address
|
||
|
mapping(uint32 => address) public domainToInbox;
|
||
4 years ago
|
|
||
3 years ago
|
// ============ Events ============
|
||
|
|
||
3 years ago
|
/**
|
||
3 years ago
|
* @notice Emitted when a new Outbox is set.
|
||
|
* @param outbox the address of the Outbox
|
||
3 years ago
|
*/
|
||
3 years ago
|
event NewOutbox(address indexed outbox);
|
||
3 years ago
|
|
||
3 years ago
|
/**
|
||
|
* @notice Emitted when a new Interchain Gas Paymaster is set.
|
||
|
* @param interchainGasPaymaster The address of the Interchain Gas Paymaster.
|
||
|
*/
|
||
|
event NewInterchainGasPaymaster(address indexed interchainGasPaymaster);
|
||
|
|
||
3 years ago
|
/**
|
||
3 years ago
|
* @notice Emitted when a new Inbox is enrolled / added
|
||
|
* @param domain the remote domain of the Outbox contract for the Inbox
|
||
|
* @param inbox the address of the Inbox
|
||
3 years ago
|
*/
|
||
3 years ago
|
event InboxEnrolled(uint32 indexed domain, address inbox);
|
||
4 years ago
|
|
||
3 years ago
|
/**
|
||
3 years ago
|
* @notice Emitted when a new Inbox is un-enrolled / removed
|
||
|
* @param domain the remote domain of the Outbox contract for the Inbox
|
||
|
* @param inbox the address of the Inbox
|
||
3 years ago
|
*/
|
||
3 years ago
|
event InboxUnenrolled(uint32 indexed domain, address inbox);
|
||
4 years ago
|
|
||
3 years ago
|
// ============ Constructor ============
|
||
|
|
||
|
// solhint-disable-next-line no-empty-blocks
|
||
|
constructor() Ownable() {}
|
||
|
|
||
|
// ============ External Functions ============
|
||
|
|
||
|
/**
|
||
3 years ago
|
* @notice Sets the address of the local Outbox contract and the address of
|
||
|
* the local Interchain Gas Paymaster contract.
|
||
|
* @dev This should be used to atomically change the local Outbox and Interchain Gas Paymaster.
|
||
|
* @param _outbox The address of the new local Outbox contract.
|
||
|
* @param _interchainGasPaymaster The address of the new local Interchain Gas Paymaster contract.
|
||
3 years ago
|
*/
|
||
3 years ago
|
function setOutboxAndInterchainGasPaymaster(
|
||
|
address _outbox,
|
||
|
address _interchainGasPaymaster
|
||
|
) external onlyOwner {
|
||
|
setOutbox(_outbox);
|
||
|
setInterchainGasPaymaster(_interchainGasPaymaster);
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
/**
|
||
3 years ago
|
* @notice Allow Owner to enroll Inbox contract
|
||
|
* @param _domain the remote domain of the Outbox contract for the Inbox
|
||
3 years ago
|
* @param _inbox the address of the Inbox
|
||
3 years ago
|
*/
|
||
3 years ago
|
function enrollInbox(uint32 _domain, address _inbox) external onlyOwner {
|
||
3 years ago
|
// un-enroll any existing inbox
|
||
|
_unenrollInbox(_inbox);
|
||
|
// add inbox and domain to two-way mapping
|
||
|
inboxToDomain[_inbox] = _domain;
|
||
|
domainToInbox[_domain] = _inbox;
|
||
|
emit InboxEnrolled(_domain, _inbox);
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
/**
|
||
3 years ago
|
* @notice Allow Owner to un-enroll Inbox contract
|
||
|
* @param _inbox the address of the Inbox
|
||
3 years ago
|
*/
|
||
3 years ago
|
function unenrollInbox(address _inbox) external onlyOwner {
|
||
|
_unenrollInbox(_inbox);
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
/**
|
||
3 years ago
|
* @notice Query local domain from Outbox
|
||
3 years ago
|
* @return local domain
|
||
|
*/
|
||
3 years ago
|
function localDomain() external view override returns (uint32) {
|
||
3 years ago
|
return outbox.localDomain();
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
// ============ Public Functions ============
|
||
|
|
||
3 years ago
|
/**
|
||
|
* @notice Sets the address of the local Outbox contract.
|
||
|
* @dev Changing the Outbox and not the Interchain Gas Paymaster may result in
|
||
|
* using an Interchain Gas Paymaster that expects messages to be dispatched via
|
||
|
* a different outbox. Use `setOutboxAndInterchainGasPaymaster` to change both
|
||
|
* atomically.
|
||
|
* @param _outbox The address of the new local Outbox contract.
|
||
|
*/
|
||
|
function setOutbox(address _outbox) public onlyOwner {
|
||
3 years ago
|
outbox = IOutbox(_outbox);
|
||
3 years ago
|
emit NewOutbox(_outbox);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @notice Sets the address of the local Interchain Gas Paymaster contract.
|
||
|
* @param _interchainGasPaymaster The address of the new local Interchain Gas Paymaster contract.
|
||
|
*/
|
||
|
function setInterchainGasPaymaster(address _interchainGasPaymaster)
|
||
|
public
|
||
|
onlyOwner
|
||
|
{
|
||
|
interchainGasPaymaster = IInterchainGasPaymaster(
|
||
|
_interchainGasPaymaster
|
||
|
);
|
||
|
emit NewInterchainGasPaymaster(_interchainGasPaymaster);
|
||
|
}
|
||
|
|
||
3 years ago
|
/**
|
||
3 years ago
|
* @notice Check whether _inbox is enrolled
|
||
|
* @param _inbox the inbox to check for enrollment
|
||
|
* @return TRUE iff _inbox is enrolled
|
||
3 years ago
|
*/
|
||
3 years ago
|
function isInbox(address _inbox) public view override returns (bool) {
|
||
3 years ago
|
return inboxToDomain[_inbox] != 0;
|
||
3 years ago
|
}
|
||
|
|
||
|
// ============ Internal Functions ============
|
||
|
|
||
|
/**
|
||
3 years ago
|
* @notice Remove the inbox from the two-way mappings
|
||
|
* @param _inbox inbox to un-enroll
|
||
3 years ago
|
*/
|
||
3 years ago
|
function _unenrollInbox(address _inbox) internal {
|
||
|
uint32 _currentDomain = inboxToDomain[_inbox];
|
||
|
domainToInbox[_currentDomain] = address(0);
|
||
|
inboxToDomain[_inbox] = 0;
|
||
|
emit InboxUnenrolled(_currentDomain, _inbox);
|
||
4 years ago
|
}
|
||
4 years ago
|
}
|