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/hooks/DomainRoutingHook.sol

66 lines
1.7 KiB

// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
// ============ Internal Imports ============
import {Message} from "../libs/Message.sol";
import {IPostDispatchHook} from "../interfaces/hooks/IPostDispatchHook.sol";
// ============ External Imports ============
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
contract DomainRoutingHook is IPostDispatchHook, Ownable {
using Message for bytes;
struct HookConfig {
uint32 destination;
address hook;
}
mapping(uint32 => IPostDispatchHook) public hooks;
constructor(address _owner) {
_transferOwnership(_owner);
}
function setHook(uint32 destination, address hook) public onlyOwner {
hooks[destination] = IPostDispatchHook(hook);
}
function setHooks(HookConfig[] calldata configs) external onlyOwner {
for (uint256 i = 0; i < configs.length; i++) {
setHook(configs[i].destination, configs[i].hook);
}
}
function postDispatch(bytes calldata metadata, bytes calldata message)
public
payable
virtual
override
{
_getConfiguredHook(message).postDispatch{value: msg.value}(
metadata,
message
);
}
function quoteDispatch(bytes calldata metadata, bytes calldata message)
public
view
virtual
override
returns (uint256)
{
return _getConfiguredHook(message).quoteDispatch(metadata, message);
}
// ============ Internal Functions ============
function _getConfiguredHook(bytes calldata message)
internal
view
returns (IPostDispatchHook)
{
return hooks[message.destination()];
}
}