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

46 lines
1.2 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
{
hooks[message.destination()].postDispatch{value: msg.value}(
metadata,
message
);
}
}