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/libs/AbstractPostDispatchHook.sol

91 lines
2.6 KiB

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.8.0;
/*@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@ HYPERLANE @@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@*/
// ============ Internal Imports ============
import {StandardHookMetadata} from "./StandardHookMetadata.sol";
import {IPostDispatchHook} from "../../interfaces/hooks/IPostDispatchHook.sol";
/**
* @title AbstractPostDispatch
* @notice Abstract post dispatch hook supporting the current global hook metadata variant.
*/
abstract contract AbstractPostDispatchHook is IPostDispatchHook {
using StandardHookMetadata for bytes;
// ============ External functions ============
/// @inheritdoc IPostDispatchHook
function supportsMetadata(bytes calldata metadata)
public
pure
virtual
override
returns (bool)
{
return
metadata.length == 0 ||
metadata.variant() == StandardHookMetadata.VARIANT;
}
/// @inheritdoc IPostDispatchHook
function postDispatch(bytes calldata metadata, bytes calldata message)
external
payable
override
{
require(
supportsMetadata(metadata),
"AbstractPostDispatchHook: invalid metadata variant"
);
_postDispatch(metadata, message);
}
/// @inheritdoc IPostDispatchHook
function quoteDispatch(bytes calldata metadata, bytes calldata message)
public
view
override
returns (uint256)
{
require(
supportsMetadata(metadata),
"AbstractPostDispatchHook: invalid metadata variant"
);
return _quoteDispatch(metadata, message);
}
// ============ Internal functions ============
/**
* @notice Post dispatch hook implementation.
* @param metadata The metadata of the message being dispatched.
* @param message The message being dispatched.
*/
function _postDispatch(bytes calldata metadata, bytes calldata message)
internal
virtual;
/**
* @notice Quote dispatch hook implementation.
* @param metadata The metadata of the message being dispatched.
* @param message The message being dispatched.
* @return The quote for the dispatch.
*/
function _quoteDispatch(bytes calldata metadata, bytes calldata message)
internal
view
virtual
returns (uint256);
}