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.
107 lines
2.9 KiB
107 lines
2.9 KiB
1 year ago
|
// SPDX-License-Identifier: MIT
|
||
|
pragma solidity >=0.8.0;
|
||
|
|
||
1 year ago
|
/*@@@@@@@ @@@@@@@@@
|
||
|
@@@@@@@@@ @@@@@@@@@
|
||
|
@@@@@@@@@ @@@@@@@@@
|
||
|
@@@@@@@@@ @@@@@@@@@
|
||
|
@@@@@@@@@@@@@@@@@@@@@@@@@
|
||
|
@@@@@ HYPERLANE @@@@@@@
|
||
|
@@@@@@@@@@@@@@@@@@@@@@@@@
|
||
|
@@@@@@@@@ @@@@@@@@@
|
||
|
@@@@@@@@@ @@@@@@@@@
|
||
|
@@@@@@@@@ @@@@@@@@@
|
||
|
@@@@@@@@@ @@@@@@@@*/
|
||
|
|
||
1 year ago
|
// ============ Internal Imports ============
|
||
1 year ago
|
import {StandardHookMetadata} from "../libs/StandardHookMetadata.sol";
|
||
|
import {AbstractPostDispatchHook} from "../libs/AbstractPostDispatchHook.sol";
|
||
|
import {MailboxClient} from "../../client/MailboxClient.sol";
|
||
|
import {Message} from "../../libs/Message.sol";
|
||
|
import {IPostDispatchHook} from "../../interfaces/hooks/IPostDispatchHook.sol";
|
||
1 year ago
|
|
||
1 year ago
|
// ============ External Imports ============
|
||
1 year ago
|
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
|
||
1 year ago
|
|
||
1 year ago
|
/**
|
||
|
* @title DomainRoutingHook
|
||
|
* @notice Delegates to a hook based on the destination domain of the message.
|
||
|
*/
|
||
|
contract DomainRoutingHook is AbstractPostDispatchHook, MailboxClient {
|
||
|
using Strings for uint32;
|
||
1 year ago
|
using Message for bytes;
|
||
|
|
||
1 year ago
|
struct HookConfig {
|
||
|
uint32 destination;
|
||
|
address hook;
|
||
|
}
|
||
|
|
||
1 year ago
|
mapping(uint32 => IPostDispatchHook) public hooks;
|
||
|
|
||
1 year ago
|
constructor(address _mailbox, address _owner) MailboxClient(_mailbox) {
|
||
1 year ago
|
_transferOwnership(_owner);
|
||
|
}
|
||
|
|
||
1 year ago
|
function setHook(uint32 destination, address hook) public onlyOwner {
|
||
1 year ago
|
hooks[destination] = IPostDispatchHook(hook);
|
||
|
}
|
||
|
|
||
1 year ago
|
function setHooks(HookConfig[] calldata configs) external onlyOwner {
|
||
|
for (uint256 i = 0; i < configs.length; i++) {
|
||
|
setHook(configs[i].destination, configs[i].hook);
|
||
|
}
|
||
|
}
|
||
|
|
||
1 year ago
|
function supportsMetadata(bytes calldata)
|
||
|
public
|
||
|
pure
|
||
|
virtual
|
||
|
override
|
||
|
returns (bool)
|
||
|
{
|
||
|
// routing hook does not care about metadata shape
|
||
|
return true;
|
||
|
}
|
||
|
|
||
1 year ago
|
// ============ Internal Functions ============
|
||
|
|
||
|
/// @inheritdoc AbstractPostDispatchHook
|
||
|
function _postDispatch(bytes calldata metadata, bytes calldata message)
|
||
|
internal
|
||
1 year ago
|
virtual
|
||
|
override
|
||
|
{
|
||
1 year ago
|
_getConfiguredHook(message).postDispatch{value: msg.value}(
|
||
1 year ago
|
metadata,
|
||
|
message
|
||
|
);
|
||
1 year ago
|
}
|
||
1 year ago
|
|
||
1 year ago
|
/// @inheritdoc AbstractPostDispatchHook
|
||
|
function _quoteDispatch(bytes calldata metadata, bytes calldata message)
|
||
|
internal
|
||
1 year ago
|
view
|
||
|
virtual
|
||
|
override
|
||
|
returns (uint256)
|
||
|
{
|
||
|
return _getConfiguredHook(message).quoteDispatch(metadata, message);
|
||
|
}
|
||
|
|
||
|
function _getConfiguredHook(bytes calldata message)
|
||
|
internal
|
||
|
view
|
||
1 year ago
|
virtual
|
||
|
returns (IPostDispatchHook hook)
|
||
1 year ago
|
{
|
||
1 year ago
|
hook = hooks[message.destination()];
|
||
|
require(
|
||
|
address(hook) != address(0),
|
||
|
string.concat(
|
||
|
"No hook configured for destination: ",
|
||
|
message.destination().toString()
|
||
|
)
|
||
|
);
|
||
1 year ago
|
}
|
||
1 year ago
|
}
|