|
|
|
@ -1,12 +1,16 @@ |
|
|
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0 |
|
|
|
|
pragma solidity >=0.6.11; |
|
|
|
|
pragma abicoder v2; |
|
|
|
|
|
|
|
|
|
// ============ Internal Imports ============ |
|
|
|
|
import {IOutbox} from "../interfaces/IOutbox.sol"; |
|
|
|
|
import {IInterchainGasPaymaster} from "../interfaces/IInterchainGasPaymaster.sol"; |
|
|
|
|
import {IAbacusConnectionManager} from "../interfaces/IAbacusConnectionManager.sol"; |
|
|
|
|
|
|
|
|
|
// ============ External Imports ============ |
|
|
|
|
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; |
|
|
|
|
import {SafeMath} from "@openzeppelin/contracts/math/SafeMath.sol"; |
|
|
|
|
import {EnumerableSet} from "@openzeppelin/contracts/utils/EnumerableSet.sol"; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @title AbacusConnectionManager |
|
|
|
@ -15,6 +19,9 @@ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; |
|
|
|
|
* domains. |
|
|
|
|
*/ |
|
|
|
|
contract AbacusConnectionManager is IAbacusConnectionManager, Ownable { |
|
|
|
|
using SafeMath for uint256; |
|
|
|
|
using EnumerableSet for EnumerableSet.AddressSet; |
|
|
|
|
|
|
|
|
|
// ============ Public Storage ============ |
|
|
|
|
|
|
|
|
|
// Outbox contract |
|
|
|
@ -26,8 +33,8 @@ contract AbacusConnectionManager is IAbacusConnectionManager, Ownable { |
|
|
|
|
IInterchainGasPaymaster public override interchainGasPaymaster; |
|
|
|
|
// local Inbox address => remote Outbox domain |
|
|
|
|
mapping(address => uint32) public inboxToDomain; |
|
|
|
|
// remote Outbox domain => local Inbox address |
|
|
|
|
mapping(uint32 => address) public domainToInbox; |
|
|
|
|
// remote Outbox domain => local Inbox addresses |
|
|
|
|
mapping(uint32 => EnumerableSet.AddressSet) domainToInboxes; |
|
|
|
|
|
|
|
|
|
// ============ Events ============ |
|
|
|
|
|
|
|
|
@ -85,11 +92,10 @@ contract AbacusConnectionManager is IAbacusConnectionManager, Ownable { |
|
|
|
|
* @param _inbox the address of the Inbox |
|
|
|
|
*/ |
|
|
|
|
function enrollInbox(uint32 _domain, address _inbox) external onlyOwner { |
|
|
|
|
// un-enroll any existing inbox |
|
|
|
|
_unenrollInbox(_inbox); |
|
|
|
|
require(!isInbox(_inbox), "already inbox"); |
|
|
|
|
// add inbox and domain to two-way mapping |
|
|
|
|
inboxToDomain[_inbox] = _domain; |
|
|
|
|
domainToInbox[_domain] = _inbox; |
|
|
|
|
domainToInboxes[_domain].add(_inbox); |
|
|
|
|
emit InboxEnrolled(_domain, _inbox); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -109,6 +115,26 @@ contract AbacusConnectionManager is IAbacusConnectionManager, Ownable { |
|
|
|
|
return outbox.localDomain(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @notice Returns the Inbox addresses for a given remote domain |
|
|
|
|
* @return inboxes An array of addresses of the Inboxes |
|
|
|
|
*/ |
|
|
|
|
function getInboxes(uint32 remoteDomain) |
|
|
|
|
external |
|
|
|
|
view |
|
|
|
|
returns (address[] memory) |
|
|
|
|
{ |
|
|
|
|
EnumerableSet.AddressSet storage _inboxes = domainToInboxes[ |
|
|
|
|
remoteDomain |
|
|
|
|
]; |
|
|
|
|
uint256 length = _inboxes.length(); |
|
|
|
|
address[] memory ret = new address[](length); |
|
|
|
|
for (uint256 i = 0; i < length; i = i.add(1)) { |
|
|
|
|
ret[i] = _inboxes.at(i); |
|
|
|
|
} |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ============ Public Functions ============ |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -155,7 +181,7 @@ contract AbacusConnectionManager is IAbacusConnectionManager, Ownable { |
|
|
|
|
*/ |
|
|
|
|
function _unenrollInbox(address _inbox) internal { |
|
|
|
|
uint32 _currentDomain = inboxToDomain[_inbox]; |
|
|
|
|
domainToInbox[_currentDomain] = address(0); |
|
|
|
|
domainToInboxes[_currentDomain].remove(_inbox); |
|
|
|
|
inboxToDomain[_inbox] = 0; |
|
|
|
|
emit InboxUnenrolled(_currentDomain, _inbox); |
|
|
|
|
} |
|
|
|
|