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/contracts/isms/routing/DefaultFallbackRoutingIsm.sol

40 lines
1.2 KiB

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.8.0;
import {DomainRoutingIsm} from "./DomainRoutingIsm.sol";
import {IMailbox} from "../../Mailbox.sol";
import {IInterchainSecurityModule} from "../../interfaces/IInterchainSecurityModule.sol";
import {EnumerableMapExtended} from "../../libs/EnumerableMapExtended.sol";
import {TypeCasts} from "../../libs/TypeCasts.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
contract DefaultFallbackRoutingIsm is DomainRoutingIsm {
using EnumerableMapExtended for EnumerableMapExtended.UintToBytes32Map;
using Address for address;
using TypeCasts for bytes32;
IMailbox public immutable mailbox;
constructor(address _mailbox) {
require(
_mailbox.isContract(),
"DefaultFallbackRoutingIsm: INVALID_MAILBOX"
);
mailbox = IMailbox(_mailbox);
}
function modules(uint32 origin)
public
view
override
returns (IInterchainSecurityModule)
{
(bool contained, bytes32 _module) = _modules.tryGet(origin);
if (contained) {
return IInterchainSecurityModule(_module.bytes32ToAddress());
} else {
return mailbox.defaultIsm();
}
}
}