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/aggregation/StaticAggregationHook.sol

69 lines
2.0 KiB

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.8.0;
/*@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@ HYPERLANE @@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@*/
import {StandardHookMetadata} from "../libs/StandardHookMetadata.sol";
import {AbstractPostDispatchHook} from "../libs/AbstractPostDispatchHook.sol";
import {IPostDispatchHook} from "../../interfaces/hooks/IPostDispatchHook.sol";
import {MetaProxy} from "../../libs/MetaProxy.sol";
contract StaticAggregationHook is AbstractPostDispatchHook {
using StandardHookMetadata for bytes;
// ============ External functions ============
/// @inheritdoc AbstractPostDispatchHook
function _postDispatch(bytes calldata metadata, bytes calldata message)
internal
override
{
address[] memory _hooks = hooks(message);
uint256 count = _hooks.length;
for (uint256 i = 0; i < count; i++) {
uint256 quote = IPostDispatchHook(_hooks[i]).quoteDispatch(
metadata,
message
);
IPostDispatchHook(_hooks[i]).postDispatch{value: quote}(
metadata,
message
);
}
}
/// @inheritdoc AbstractPostDispatchHook
function _quoteDispatch(bytes calldata metadata, bytes calldata message)
internal
view
override
returns (uint256)
{
address[] memory _hooks = hooks(message);
uint256 count = _hooks.length;
uint256 total = 0;
for (uint256 i = 0; i < count; i++) {
total += IPostDispatchHook(_hooks[i]).quoteDispatch(
metadata,
message
);
}
return total;
}
function hooks(bytes calldata) public pure returns (address[] memory) {
return abi.decode(MetaProxy.metadata(), (address[]));
}
}