Проверенный контрактЧастичноеLicenseRef-Dromos-Restricted-Use-1.0
HyperlaneAdapter
Адрес0x4aaff8cfb43e2cefbbbf4c133c934db6ba7e4c14
- Баланс
0 ETH
- Транзакций
1
- Компилятор
solc 0.8.36
- Тот же код
Только этот контракт
Подробности
- Компилятор
- solc 0.8.36+commit.8a079791
- Язык
- solidity
- Оптимизация
- Да, 10 000 прогонов
- Версия EVM
- prague
- Лицензия
- LicenseRef-Dromos-Restricted-Use-1.0
- Совпадение
- Частичноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 26 206 269
- Транзакция создания
- 0x9743cbc193…2ed933ba7f
- Библиотеки
- V3/src/src/libraries/RewardsLogicLibrary.sol:RewardsLogicLibrary0x2b73…8d6720V3/src/src/libraries/LeafAllocationLibrary.sol:LeafAllocationLibrary0xc7e2…3e0398V3/src/src/libraries/VotingRewardsFactoryLibrary.sol:VotingRewardsFactoryLibrary0x1c38…49634e
10 файлов
- V3/src/bridge/hyperlane/HyperlaneAdapter.solглавный5,29 КБ
- V3/src/interfaces/bridge/IMessageAdapter.sol4,07 КБ
- V3/src/interfaces/bridge/IMessageOrchestrator.sol4,59 КБ
- V3/src/interfaces/bridge/hyperlane/IHyperlaneAdapter.sol4 КБ
- V3/src/libraries/Roles.sol2,55 КБ
- node_modules/@hyperlane-xyz/core/contracts/hooks/libs/StandardHookMetadata.sol6,95 КБ
- node_modules/@hyperlane-xyz/core/contracts/interfaces/IInterchainSecurityModule.sol1,41 КБ
- node_modules/@hyperlane-xyz/core/contracts/interfaces/IMailbox.sol3,5 КБ
- node_modules/@hyperlane-xyz/core/contracts/interfaces/hooks/IPostDispatchHook.sol1,93 КБ
- node_modules/@openzeppelin/contracts/access/IAccessControl.sol3,34 КБ
V3/src/bridge/hyperlane/HyperlaneAdapter.sol
/// SPDX-License-Identifier: LicenseRef-Dromos-Restricted-Use-1.0
pragma solidity 0.8.36;
import {StandardHookMetadata} from '@hyperlane/contracts/hooks/libs/StandardHookMetadata.sol';
import {IMailbox} from '@hyperlane/contracts/interfaces/IMailbox.sol';
import {IAccessControl} from '@openzeppelin/contracts/access/IAccessControl.sol';
import {IMessageOrchestrator} from 'V3/interfaces/bridge/IMessageOrchestrator.sol';
import {IHyperlaneAdapter, IMessageAdapter} from 'V3/interfaces/bridge/hyperlane/IHyperlaneAdapter.sol';
import {Roles} from 'V3/libraries/Roles.sol';
/**
* @title HyperlaneAdapter
* @notice Transport adapter backed by the Hyperlane mailbox, deployed on root and every leaf chain.
* @dev Bound to a single remote pair at deployment via the `REMOTE_DOMAIN_ID` and `REMOTE_CHAIN_ID` immutables; only
* the counterpart address (`remoteAdapter`) can be updated by holders of `ADAPTER_CONFIG_ROLE` on `VOTER`.
*/
contract HyperlaneAdapter is IHyperlaneAdapter {
/// @inheritdoc IMessageAdapter
uint256 public immutable REMOTE_CHAIN_ID;
/// @inheritdoc IHyperlaneAdapter
uint32 public immutable REMOTE_DOMAIN_ID;
/// @inheritdoc IHyperlaneAdapter
IMessageOrchestrator public immutable ORCHESTRATOR;
/// @inheritdoc IHyperlaneAdapter
IMailbox public immutable MAILBOX;
/// @inheritdoc IHyperlaneAdapter
IAccessControl public immutable VOTER;
/// @inheritdoc IHyperlaneAdapter
bytes32 public remoteAdapter;
/**
* @notice Binds the adapter to its counterpart chain at deployment.
* @param _remoteChainId Chain id of the counterpart chain.
* @param _remoteDomainId Hyperlane domain id of the counterpart chain.
* @param _orchestrator Local `MessageOrchestrator` bound to this adapter.
* @param _mailbox Hyperlane mailbox on this chain.
* @param _voter Local voter (`Voter` on root, `LeafVoter` on leaves) whose `ADAPTER_CONFIG_ROLE` gates
* `setRemoteAdapter`.
* @param _remoteAdapter Initial counterpart address, or zero when configured later.
*/
constructor(
uint256 _remoteChainId,
uint32 _remoteDomainId,
address _orchestrator,
address _mailbox,
address _voter,
bytes32 _remoteAdapter
) {
if (_remoteChainId == 0) revert InvalidChainId();
if (_remoteChainId == block.chainid) revert InvalidChainId();
if (_remoteDomainId == 0) revert InvalidDomain();
if (_orchestrator == address(0)) revert ZeroAddress();
if (_mailbox == address(0)) revert ZeroAddress();
if (_voter == address(0)) revert ZeroAddress();
// Hyperlane routes by domain id, so a remote domain equal to the local one is a transport self-loop.
if (_remoteDomainId == IMailbox(_mailbox).localDomain()) revert InvalidDomain();
REMOTE_CHAIN_ID = _remoteChainId;
REMOTE_DOMAIN_ID = _remoteDomainId;
ORCHESTRATOR = IMessageOrchestrator(_orchestrator);
MAILBOX = IMailbox(_mailbox);
VOTER = IAccessControl(_voter);
if (_remoteAdapter != bytes32(0)) {
remoteAdapter = _remoteAdapter;
emit RemoteAdapterUpdated(_remoteAdapter);
}
}
/// @inheritdoc IMessageAdapter
function sendMessage(bytes calldata _message, uint256 _gasLimit, address _refundRecipient) external payable {
if (msg.sender != address(ORCHESTRATOR)) revert CallerNotOrchestrator();
if (_gasLimit == 0) revert InvalidGasLimit();
bytes32 _remoteAdapter = remoteAdapter;
if (_remoteAdapter == bytes32(0)) revert RemoteAdapterNotSet();
bytes32 _messageId = MAILBOX.dispatch{value: msg.value}(
REMOTE_DOMAIN_ID, _remoteAdapter, _message, StandardHookMetadata.format(0, _gasLimit, _refundRecipient)
);
emit MessageSent(_messageId, _remoteAdapter);
}
/// @inheritdoc IMessageAdapter
function handle(uint32 _origin, bytes32 _sender, bytes calldata _message) external payable {
if (msg.sender != address(MAILBOX)) revert CallerNotMailbox();
if (_origin != REMOTE_DOMAIN_ID) revert UnauthorizedOrigin();
bytes32 _remoteAdapter = remoteAdapter;
if (_remoteAdapter == bytes32(0)) revert RemoteAdapterNotSet();
if (_sender != _remoteAdapter) revert UnauthorizedSender();
ORCHESTRATOR.route{value: msg.value}(REMOTE_CHAIN_ID, _message);
}
/// @inheritdoc IMessageAdapter
function setRemoteAdapter(bytes32 _remoteAdapter) external {
if (!VOTER.hasRole(Roles.ADAPTER_CONFIG_ROLE, msg.sender)) revert CallerNotAdapterAuthority();
if (_remoteAdapter == bytes32(0)) revert InvalidRemoteAdapter();
remoteAdapter = _remoteAdapter;
emit RemoteAdapterUpdated(_remoteAdapter);
}
/// @inheritdoc IMessageAdapter
function quoteMessage(
bytes calldata _message,
uint256 _gasLimit,
address _refundRecipient
) external view returns (uint256 _fee) {
if (_gasLimit == 0) revert InvalidGasLimit();
bytes32 _remoteAdapter = remoteAdapter;
if (_remoteAdapter == bytes32(0)) revert RemoteAdapterNotSet();
// Quote against the exact arguments `sendMessage` dispatches with: the interchain gas payment is priced off
// the gas limit encoded in the hook metadata, so quoting without it would return the default-gas fee.
_fee = MAILBOX.quoteDispatch(
REMOTE_DOMAIN_ID, _remoteAdapter, _message, StandardHookMetadata.format(0, _gasLimit, _refundRecipient)
);
}
}
V3/src/interfaces/bridge/IMessageAdapter.sol
/// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/**
* @title IMessageAdapter
* @notice Interface for transport adapters that carry payloads between `MessageOrchestrator` instances without
* inspecting their content.
*/
interface IMessageAdapter {
/// @notice Thrown when `sendMessage` is invoked by a caller that is not a registered orchestrator.
error CallerNotOrchestrator();
/// @notice Thrown when the adapter is constructed with a zero chain id.
error InvalidChainId();
/// @notice Thrown when a required address argument is the zero address.
error ZeroAddress();
/**
* @notice Sends the payload through the transport.
* @dev Callable only by the registered orchestrator. Forwards `msg.value` to the underlying transport as the fee.
* Any excess over the actual fee is expected to be refunded by the transport directly to `_refundRecipient`.
* @param _message The wrapped message body forwarded to the underlying transport.
* @param _gasLimit Execution gas reserved for the destination handler.
* @param _refundRecipient Address that receives native ETH refunds from the transport.
*/
function sendMessage(bytes calldata _message, uint256 _gasLimit, address _refundRecipient) external payable;
/**
* @notice Transport entrypoint invoked by the underlying transport to deliver an inbound payload to the local
* orchestrator.
* @dev Implementations that carry an underlying transport validate the transport caller, the origin, and the
* sender against their configured remote counterpart, then call the orchestrator with `REMOTE_CHAIN_ID` as the
* source chain id. Implementations without a transport (e.g., `RootLocalAdapter`) may revert.
* @dev Payable: the transport forwards the relayer's delivery value (Hyperlane's `Mailbox.process` attaches
* `msg.value` to `handle`), and the adapter passes it through to `route`, where it lands in the orchestrator's
* pre-funding pool.
* @param _origin Transport-level identifier of the source chain.
* @param _sender Trusted counterpart address as reported by the transport.
* @param _message The wrapped message body delivered to the orchestrator's `route`.
*/
function handle(uint32 _origin, bytes32 _sender, bytes calldata _message) external payable;
/**
* @notice Quotes the transport fee `sendMessage` would charge for the same inputs.
* @dev Takes the identical arguments to `sendMessage` on purpose: the underlying transport prices the wrapped
* message and the destination gas budget together, so a quote taken with different arguments is not the fee
* the send will cost. Callers that quote-then-send in the same transaction get an exact figure; the
* fee-less local adapter quotes zero.
* @param _message The wrapped message body that would be forwarded to the underlying transport.
* @param _gasLimit Execution gas that would be reserved for the destination handler.
* @param _refundRecipient Address that would receive native ETH refunds from the transport.
* @return _fee Native amount `sendMessage` requires for these inputs.
*/
function quoteMessage(
bytes calldata _message,
uint256 _gasLimit,
address _refundRecipient
) external view returns (uint256 _fee);
/**
* @notice Updates the stored remote adapter address.
* @dev Implementations that carry a remote counterpart gate this entrypoint behind the adapter authority and reject
* the zero value. Implementations without a remote counterpart (e.g., `RootLocalAdapter`) may revert.
* @param _remoteAdapter The new counterpart adapter on the remote chain.
*/
function setRemoteAdapter(bytes32 _remoteAdapter) external;
/**
* @notice Chain id this adapter is bound to. Read by the orchestrator at registration time to verify the
* adapter is wired to the chain it is being registered for.
* @return _chainId Chain id of the counterpart chain (or the local chain id for the local adapter on root).
*/
function REMOTE_CHAIN_ID() external view returns (uint256 _chainId);
}
V3/src/interfaces/bridge/IMessageOrchestrator.sol
/// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/**
* @title IMessageOrchestrator
* @notice Shared inbound entrypoint of every orchestrator. Registered adapters call `route`, which checks the caller
* and the nonce, then hands the body to a typed handler.
*/
interface IMessageOrchestrator {
/**
* @notice Routing identifier stamped into the message header and read to pick the typed handler.
* @param None Zero-default guard, rejected at decode so an empty payload cannot pass as the first real type.
* @param AllocateChain Root to leaf — sets a tokenId's chain-level VP budget and the chain emissions scalar.
* @param AllocateGauge Root to leaf — distributes a chain budget across gauges; cooldown-gated on the leaf.
* @param ClaimRewards Root to leaf — claims fee and incentive rewards.
* @param Redeem Leaf to root — Redeem.
* @param SetOperator Root to leaf — propagates the per-tokenId operator assignment.
* @param Deallocate Leaf to root — confirms a tokenId's deallocation so root credits `CHAIN0`.
* @param ReduceCooldown Root to leaf — accrues a tokenId's pending cooldown reduction.
* @param EmergencyDeallocate Root to leaf — clears a tokenId's gauges and cuts its chain budget by the drained
* amount, so a Suspended chain re-syncs when it is next reachable.
*/
enum MessageType {
None,
AllocateChain,
AllocateGauge,
ClaimRewards,
Redeem,
SetOperator,
Deallocate,
ReduceCooldown,
EmergencyDeallocate
}
/// @notice Emitted when an outbound message is handed to a transport adapter and its nonce is stamped.
/// @param _chainId Destination chain id.
/// @param _chainNonce Outbound nonce stamped on this message.
/// @param _msgType Routing identifier carried by the message.
event MessageDispatched(uint256 indexed _chainId, uint256 _chainNonce, MessageType _msgType);
/// @notice Emitted when an inbound message is accepted and its nonce is consumed.
/// @param _chainId Source chain id.
/// @param _chainNonce Nonce stamped by the source orchestrator.
/// @param _msgType Routing identifier carried by the message.
event MessageReceived(uint256 indexed _chainId, uint256 _chainNonce, MessageType _msgType);
/// @notice Reverts when the inbound payload is too short to contain the wrapped header.
error InvalidPayload();
/// @notice Reverts when the inbound message type byte is above the `MessageType` enum range.
error InvalidMessageType();
/// @notice Reverts when the inbound message type byte is the `None` zero value, never a routable type.
error NoneMessageType();
/// @notice Reverts when a supplied address parameter is the zero address.
error ZeroAddress();
/// @notice Reverts when `dispatch` is called and no adapter is registered for the destination.
error AdapterNotRegistered();
/// @notice Reverts when `dispatch` is called by anyone other than the local voter contract.
error CallerNotAuthorized();
/// @notice Reverts when a `MessageType` is not routable in the current direction.
error UnsupportedMessageType();
/// @notice Reverts when `route` is called by anyone other than the registered adapter.
error CallerNotAdapter();
/// @notice Reverts when the inbound `chainNonce` has already been consumed.
error NonceAlreadyUsed();
/// @notice Reverts while the local clock trails the message's `dispatchedAt`; the transport redelivers once it
/// catches up, so a chain resuming from an outage cannot start accrual before the sender booked it.
error ClockBehindDispatch();
/// @notice Reverts when an adapter setter is called without `ADAPTER_CONFIG_ROLE` on the local voter.
error CallerNotAdapterAuthority();
/// @notice Reverts when `setAdapter` is invoked with the zero address.
error InvalidAdapter();
/**
* @notice Routes a message delivered by a registered adapter to the orchestrator's typed handler.
* @dev Registered adapter only. Nonces are single-use. Root rejects a `Redeem` from a suspended origin but still
* takes a `Deallocate`; the leaf routes while suspended so held root messages keep applying.
* @dev `payable` so a relayer can send a deallocation return fee: on the leaf it lands in the pre-funding pool
* that pays the return. Root has no use for inbound value.
* @param _originChainId Source chain id, supplied by the adapter from its `REMOTE_CHAIN_ID`.
* @param _payload The wrapped message to decode and route.
*/
function route(uint256 _originChainId, bytes calldata _payload) external payable;
}
V3/src/interfaces/bridge/hyperlane/IHyperlaneAdapter.sol
/// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import {IMailbox} from '@hyperlane/contracts/interfaces/IMailbox.sol';
import {IAccessControl} from '@openzeppelin/contracts/access/IAccessControl.sol';
import {IMessageAdapter} from 'V3/interfaces/bridge/IMessageAdapter.sol';
import {IMessageOrchestrator} from 'V3/interfaces/bridge/IMessageOrchestrator.sol';
/**
* @title IHyperlaneAdapter
* @notice Interface for the Hyperlane-backed transport adapter deployed on root and every leaf chain, bound to a
* single remote pair at deployment.
*/
interface IHyperlaneAdapter is IMessageAdapter {
/**
* @notice Emitted on every outbound dispatch so off-chain monitoring can correlate the message with its delivery.
* @param _messageId Hyperlane message id returned by `mailbox.dispatch`.
* @param _remoteAdapter The counterpart adapter that will receive the message.
*/
event MessageSent(bytes32 indexed _messageId, bytes32 _remoteAdapter);
/**
* @notice Emitted when an `ADAPTER_CONFIG_ROLE` holder updates the counterpart adapter address.
* @param _current The new `remoteAdapter` value after the update.
*/
event RemoteAdapterUpdated(bytes32 _current);
/// @notice Thrown when `setRemoteAdapter` is invoked by a caller without `ADAPTER_CONFIG_ROLE` on `VOTER`.
error CallerNotAdapterAuthority();
/// @notice Thrown when `handle` is invoked by a caller that is not the Hyperlane mailbox.
error CallerNotMailbox();
/// @notice Thrown when the adapter is constructed with an invalid Hyperlane remote domain id: either zero, or equal
/// to the mailbox's local domain (which would make outbound messages a same-chain transport self-loop).
error InvalidDomain();
/// @notice Thrown when `sendMessage` is invoked with `_gasLimit == 0`, which would cause delivery to fail downstream.
error InvalidGasLimit();
/// @notice Thrown when `setRemoteAdapter` is invoked with `bytes32(0)`, preventing half-configured state.
error InvalidRemoteAdapter();
/// @notice Thrown when `sendMessage` or `handle` is invoked while `remoteAdapter` is unset (`bytes32(0)`).
error RemoteAdapterNotSet();
/// @notice Thrown when `handle` is invoked with an `_origin` that does not match `REMOTE_DOMAIN_ID`.
error UnauthorizedOrigin();
/// @notice Thrown when `handle` is invoked with a `_sender` that does not match `remoteAdapter`.
error UnauthorizedSender();
/**
* @notice Hyperlane domain id of the counterpart chain. Used for inbound origin validation and as the outbound
* dispatch destination.
* @return _remoteDomainId Hyperlane domain id of the counterpart chain.
*/
function REMOTE_DOMAIN_ID() external view returns (uint32 _remoteDomainId);
/**
* @notice Address of the local `MessageOrchestrator` bound to this adapter at deployment.
* @return _orchestrator The local orchestrator that calls `sendMessage` outbound and receives `route` inbound.
*/
function ORCHESTRATOR() external view returns (IMessageOrchestrator _orchestrator);
/**
* @notice Address of the Hyperlane mailbox on this chain bound to this adapter at deployment.
* @return _mailbox The Hyperlane mailbox that dispatches outbound messages and delivers inbound ones.
*/
function MAILBOX() external view returns (IMailbox _mailbox);
/**
* @notice Local voter whose `ADAPTER_CONFIG_ROLE` gates `setRemoteAdapter`: the `Voter` on root, the `LeafVoter`
* on each leaf. Typed by the role registry the adapter consumes. Set at deployment, immutable.
* @return _voter The local voter's role registry.
*/
function VOTER() external view returns (IAccessControl _voter);
/**
* @notice Address of the counterpart adapter on the remote chain. Mutable by `ADAPTER_CONFIG_ROLE` holders through
* `setRemoteAdapter`.
* @return _remoteAdapter The bytes32 encoded counterpart adapter address, or `bytes32(0)` if not yet configured.
*/
function remoteAdapter() external view returns (bytes32 _remoteAdapter);
}
V3/src/libraries/Roles.sol
// SPDX-License-Identifier: LicenseRef-Dromos-Restricted-Use-1.0
pragma solidity 0.8.36;
/**
* @title Roles
* @notice Central registry of AccessControl role identifiers used by Voter and LeafVoter.
*/
library Roles {
/// @notice Root governance authority.
bytes32 public constant GOVERNANCE_ROLE = keccak256('GOVERNANCE_ROLE');
/// @notice Admin of the operational config roles.
bytes32 public constant CONFIG_ADMIN_ROLE = keccak256('CONFIG_ADMIN_ROLE');
/// @notice Configures Voter-wide parameters.
bytes32 public constant VOTER_CONFIG_ROLE = keccak256('VOTER_CONFIG_ROLE');
/// @notice Registers and configures per-chain parameters.
bytes32 public constant CHAIN_CONFIG_ROLE = keccak256('CHAIN_CONFIG_ROLE');
/// @notice Flips per-chain status.
bytes32 public constant CHAIN_STATUS_ROLE = keccak256('CHAIN_STATUS_ROLE');
/// @notice Authorizes remote-adapter configuration on bridge adapters.
bytes32 public constant ADAPTER_CONFIG_ROLE = keccak256('ADAPTER_CONFIG_ROLE');
/// @notice Replaces the Splitter's recipient list, directing future team-share emissions.
bytes32 public constant SPLITTER_CONFIG_ROLE = keccak256('SPLITTER_CONFIG_ROLE');
/// @notice Whitelists tokenIds on the LeafVoter.
bytes32 public constant TOKEN_WHITELIST_ROLE = keccak256('TOKEN_WHITELIST_ROLE');
/// @notice Emergency actor authorized to zero a gauge's emission cap on the leaf.
bytes32 public constant EMERGENCY_COUNCIL_ROLE = keccak256('EMERGENCY_COUNCIL_ROLE');
/// @notice Registers and unregisters factories on the FactoryRegistry.
bytes32 public constant FACTORY_REGISTRY_ADMIN_ROLE = keccak256('FACTORY_REGISTRY_ADMIN_ROLE');
/// @notice Administers the GaugeManager's creation module set.
bytes32 public constant MODULE_ADMIN_ROLE = keccak256('MODULE_ADMIN_ROLE');
/// @notice Creates Relays on the RelayFactory.
bytes32 public constant RELAY_DEPLOYER_ROLE = keccak256('RELAY_DEPLOYER_ROLE');
/// @notice Configures operational gas limits, including messaging, gauge fee flushing and token symbol reads.
bytes32 public constant GAS_CONFIGURER_ROLE = keccak256('GAS_CONFIGURER_ROLE');
/// @notice Withdraws native currency from a contract (e.g. collected deallocation return fees on the
/// root Voter, or a leaf orchestrator's pre-funded return-message balance).
bytes32 public constant NATIVE_WITHDRAWER_ROLE = keccak256('NATIVE_WITHDRAWER_ROLE');
/// @notice Seizes token metadata NFTs on the TokenNFT.
bytes32 public constant SEIZER_ROLE = keccak256('SEIZER_ROLE');
}
node_modules/@hyperlane-xyz/core/contracts/hooks/libs/StandardHookMetadata.sol
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.8.0;
/*@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@ HYPERLANE @@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@*/
/**
* Format of metadata:
*
* [0:2] variant
* [2:34] msg.value
* [34:66] Gas limit for message (IGP)
* [66:86] Refund address for message (IGP)
* [86:] Custom metadata
*/
library StandardHookMetadata {
struct Metadata {
uint16 variant;
uint256 msgValue;
uint256 gasLimit;
address refundAddress;
}
uint8 private constant VARIANT_OFFSET = 0;
uint8 private constant MSG_VALUE_OFFSET = 2;
uint8 private constant GAS_LIMIT_OFFSET = 34;
uint8 private constant REFUND_ADDRESS_OFFSET = 66;
uint256 private constant MIN_METADATA_LENGTH = 86;
uint16 public constant VARIANT = 1;
/**
* @notice Returns the variant of the metadata.
* @param _metadata ABI encoded standard hook metadata.
* @return variant of the metadata as uint8.
*/
function variant(bytes calldata _metadata) internal pure returns (uint16) {
if (_metadata.length < VARIANT_OFFSET + 2) return 0;
return uint16(bytes2(_metadata[VARIANT_OFFSET:VARIANT_OFFSET + 2]));
}
/**
* @notice Returns the specified value for the message.
* @param _metadata ABI encoded standard hook metadata.
* @param _default Default fallback value.
* @return Value for the message as uint256.
*/
function msgValue(
bytes calldata _metadata,
uint256 _default
) internal pure returns (uint256) {
if (_metadata.length < MSG_VALUE_OFFSET + 32) return _default;
return
uint256(bytes32(_metadata[MSG_VALUE_OFFSET:MSG_VALUE_OFFSET + 32]));
}
/**
* @notice Returns the specified gas limit for the message.
* @param _metadata ABI encoded standard hook metadata.
* @param _default Default fallback gas limit.
* @return Gas limit for the message as uint256.
*/
function gasLimit(
bytes calldata _metadata,
uint256 _default
) internal pure returns (uint256) {
if (_metadata.length < GAS_LIMIT_OFFSET + 32) return _default;
return
uint256(bytes32(_metadata[GAS_LIMIT_OFFSET:GAS_LIMIT_OFFSET + 32]));
}
function gasLimit(
bytes memory _metadata
) internal pure returns (uint256 _gasLimit) {
if (_metadata.length < GAS_LIMIT_OFFSET + 32) return 50_000;
assembly {
_gasLimit := mload(add(_metadata, add(0x20, GAS_LIMIT_OFFSET)))
}
}
/**
* @notice Returns the specified refund address for the message.
* @param _metadata ABI encoded standard hook metadata.
* @param _default Default fallback refund address.
* @return Refund address for the message as address.
*/
function refundAddress(
bytes calldata _metadata,
address _default
) internal pure returns (address) {
if (_metadata.length < REFUND_ADDRESS_OFFSET + 20) return _default;
return
address(
bytes20(
_metadata[REFUND_ADDRESS_OFFSET:REFUND_ADDRESS_OFFSET + 20]
)
);
}
/**
* @notice Returns any custom metadata.
* @param _metadata ABI encoded standard hook metadata.
* @return Custom metadata.
*/
function getCustomMetadata(
bytes calldata _metadata
) internal pure returns (bytes calldata) {
if (_metadata.length < MIN_METADATA_LENGTH) return _metadata[0:0];
return _metadata[MIN_METADATA_LENGTH:];
}
/**
* @notice Formats the specified gas limit and refund address into standard hook metadata.
* @param _msgValue msg.value for the message.
* @param _gasLimit Gas limit for the message.
* @param _refundAddress Refund address for the message.
* @return ABI encoded standard hook metadata.
*/
function format(
uint256 _msgValue,
uint256 _gasLimit,
address _refundAddress
) internal pure returns (bytes memory) {
return abi.encodePacked(VARIANT, _msgValue, _gasLimit, _refundAddress);
}
/**
/**
* @notice Formats the specified gas limit and refund address into standard hook metadata.
* @param _msgValue msg.value for the message.
* @param _gasLimit Gas limit for the message.
* @param _refundAddress Refund address for the message.
* @param _customMetadata Additional metadata to include in the standard hook metadata.
* @return ABI encoded standard hook metadata.
*/
function formatMetadata(
uint256 _msgValue,
uint256 _gasLimit,
address _refundAddress,
bytes memory _customMetadata
) internal pure returns (bytes memory) {
return
abi.encodePacked(
VARIANT,
_msgValue,
_gasLimit,
_refundAddress,
_customMetadata
);
}
/**
* @notice Formats the specified gas limit and refund address into standard hook metadata.
* @param _msgValue msg.value for the message.
* @return ABI encoded standard hook metadata.
*/
function overrideMsgValue(
uint256 _msgValue
) internal view returns (bytes memory) {
return formatMetadata(_msgValue, uint256(0), msg.sender, "");
}
/**
* @notice Formats the specified gas limit and refund address into standard hook metadata.
* @param _gasLimit Gas limit for the message.
* @return ABI encoded standard hook metadata.
*/
function overrideGasLimit(
uint256 _gasLimit
) internal view returns (bytes memory) {
return formatMetadata(uint256(0), _gasLimit, msg.sender, "");
}
/**
* @notice Formats the specified refund address into standard hook metadata.
* @param _refundAddress Refund address for the message.
* @return ABI encoded standard hook metadata.
*/
function overrideRefundAddress(
address _refundAddress
) internal pure returns (bytes memory) {
return formatMetadata(uint256(0), uint256(0), _refundAddress, "");
}
function getRefundAddress(
bytes memory _metadata,
address _default
) internal pure returns (address) {
if (_metadata.length < REFUND_ADDRESS_OFFSET + 20) return _default;
address result;
assembly {
let data_start_ptr := add(_metadata, 32) // Skip length prefix of _metadata
let mload_ptr := add(data_start_ptr, sub(REFUND_ADDRESS_OFFSET, 12))
result := mload(mload_ptr) // Loads 32 bytes; address takes lower 20 bytes.
}
return result;
}
}
node_modules/@hyperlane-xyz/core/contracts/interfaces/IInterchainSecurityModule.sol
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
interface IInterchainSecurityModule {
enum Types {
UNUSED,
ROUTING,
AGGREGATION,
LEGACY_MULTISIG,
MERKLE_ROOT_MULTISIG,
MESSAGE_ID_MULTISIG,
NULL, // used with relayer carrying no metadata
CCIP_READ,
ARB_L2_TO_L1,
WEIGHTED_MERKLE_ROOT_MULTISIG,
WEIGHTED_MESSAGE_ID_MULTISIG,
OP_L2_TO_L1,
POLYMER
}
/**
* @notice Returns an enum that represents the type of security model
* encoded by this ISM.
* @dev Relayers infer how to fetch and format metadata.
*/
function moduleType() external view returns (uint8);
/**
* @notice Defines a security model responsible for verifying interchain
* messages based on the provided metadata.
* @param _metadata Off-chain metadata provided by a relayer, specific to
* the security model encoded by the module (e.g. validator signatures)
* @param _message Hyperlane encoded interchain message
* @return True if the message was verified
*/
function verify(
bytes calldata _metadata,
bytes calldata _message
) external returns (bool);
}
interface ISpecifiesInterchainSecurityModule {
function interchainSecurityModule()
external
view
returns (IInterchainSecurityModule);
}
node_modules/@hyperlane-xyz/core/contracts/interfaces/IMailbox.sol
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.8.0;
import {IInterchainSecurityModule} from "./IInterchainSecurityModule.sol";
import {IPostDispatchHook} from "./hooks/IPostDispatchHook.sol";
interface IMailbox {
// ============ Events ============
/**
* @notice Emitted when a new message is dispatched via Hyperlane
* @param sender The address that dispatched the message
* @param destination The destination domain of the message
* @param recipient The message recipient address on `destination`
* @param message Raw bytes of message
*/
event Dispatch(
address indexed sender,
uint32 indexed destination,
bytes32 indexed recipient,
bytes message
);
/**
* @notice Emitted when a new message is dispatched via Hyperlane
* @param messageId The unique message identifier
*/
event DispatchId(bytes32 indexed messageId);
/**
* @notice Emitted when a Hyperlane message is processed
* @param messageId The unique message identifier
*/
event ProcessId(bytes32 indexed messageId);
/**
* @notice Emitted when a Hyperlane message is delivered
* @param origin The origin domain of the message
* @param sender The message sender address on `origin`
* @param recipient The address that handled the message
*/
event Process(
uint32 indexed origin,
bytes32 indexed sender,
address indexed recipient
);
function localDomain() external view returns (uint32);
function delivered(bytes32 messageId) external view returns (bool);
function defaultIsm() external view returns (IInterchainSecurityModule);
function defaultHook() external view returns (IPostDispatchHook);
function requiredHook() external view returns (IPostDispatchHook);
function latestDispatchedId() external view returns (bytes32);
function nonce() external view returns (uint32);
function dispatch(
uint32 destinationDomain,
bytes32 recipientAddress,
bytes calldata messageBody
) external payable returns (bytes32 messageId);
function quoteDispatch(
uint32 destinationDomain,
bytes32 recipientAddress,
bytes calldata messageBody
) external view returns (uint256 fee);
function dispatch(
uint32 destinationDomain,
bytes32 recipientAddress,
bytes calldata body,
bytes calldata defaultHookMetadata
) external payable returns (bytes32 messageId);
function quoteDispatch(
uint32 destinationDomain,
bytes32 recipientAddress,
bytes calldata messageBody,
bytes calldata defaultHookMetadata
) external view returns (uint256 fee);
function dispatch(
uint32 destinationDomain,
bytes32 recipientAddress,
bytes calldata body,
bytes calldata customHookMetadata,
IPostDispatchHook customHook
) external payable returns (bytes32 messageId);
function quoteDispatch(
uint32 destinationDomain,
bytes32 recipientAddress,
bytes calldata messageBody,
bytes calldata customHookMetadata,
IPostDispatchHook customHook
) external view returns (uint256 fee);
function process(
bytes calldata metadata,
bytes calldata message
) external payable;
function recipientIsm(
address recipient
) external view returns (IInterchainSecurityModule module);
}
node_modules/@hyperlane-xyz/core/contracts/interfaces/hooks/IPostDispatchHook.sol
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.8.0;
/*@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@ HYPERLANE @@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@*/
interface IPostDispatchHook {
enum HookTypes {
UNUSED,
ROUTING,
AGGREGATION,
MERKLE_TREE,
INTERCHAIN_GAS_PAYMASTER,
FALLBACK_ROUTING,
ID_AUTH_ISM,
PAUSABLE,
PROTOCOL_FEE,
DEPRECATED,
RATE_LIMITED,
ARB_L2_TO_L1,
OP_L2_TO_L1,
MAILBOX_DEFAULT_HOOK,
AMOUNT_ROUTING,
CCTP
}
/**
* @notice Returns an enum that represents the type of hook
*/
function hookType() external view returns (uint8);
/**
* @notice Returns whether the hook supports metadata
* @param metadata metadata
* @return Whether the hook supports metadata
*/
function supportsMetadata(
bytes calldata metadata
) external view returns (bool);
/**
* @notice Post action after a message is dispatched via the Mailbox
* @param metadata The metadata required for the hook
* @param message The message passed from the Mailbox.dispatch() call
*/
function postDispatch(
bytes calldata metadata,
bytes calldata message
) external payable;
/**
* @notice Compute the payment required by the postDispatch call
* @param metadata The metadata required for the hook
* @param message The message passed from the Mailbox.dispatch() call
* @return Quoted payment for the postDispatch call
*/
function quoteDispatch(
bytes calldata metadata,
bytes calldata message
) external view returns (uint256);
}
node_modules/@openzeppelin/contracts/access/IAccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (access/IAccessControl.sol)
pragma solidity >=0.8.4;
/**
* @dev External interface of AccessControl declared to support ERC-165 detection.
*/
interface IAccessControl {
/**
* @dev The `account` is missing a role.
*/
error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
/**
* @dev The caller of a function is not the expected one.
*
* NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
*/
error AccessControlBadConfirmation();
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted to signal this.
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call. This account bears the admin role (for the granted role).
* Expected in cases where the role was granted using the internal {AccessControl-_grantRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*/
function renounceRole(bytes32 role, address callerConfirmation) external;
}
Настройки компилятораПоказать
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {
"V3/src/src/libraries/RewardsLogicLibrary.sol": {
"RewardsLogicLibrary": "0x2b73DF2e7e957C77F1D8C01e0a71aD1fF38D6720"
},
"V3/src/src/libraries/LeafAllocationLibrary.sol": {
"LeafAllocationLibrary": "0xC7E262e848fCa78C3C66Ee3c9835e4E65E3E0398"
},
"V3/src/src/libraries/VotingRewardsFactoryLibrary.sol": {
"VotingRewardsFactoryLibrary": "0x1C3821772BFAAE08eE2D4ED8E2c29844CA49634e"
}
},
"optimizer": {
"runs": 10000,
"enabled": true
},
"viaSSACFG": false,
"evmVersion": "prague",
"remappings": [
"forge-std/=node_modules/forge-std/src/",
"@hyperlane/contracts/=node_modules/@hyperlane-xyz/core/contracts/",
"node_modules/@hyperlane-xyz/:@openzeppelin/contracts/=node_modules/@openzeppelin/contracts-v4/",
"node_modules/@hyperlane-xyz/:@openzeppelin/contracts/=node_modules/@openzeppelin/contracts-v4/",
"node_modules/@hyperlane-xyz/:@openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable-v4/",
"node_modules/@hyperlane-xyz/:@openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable-v4/",
"@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/",
"@openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable/",
"@openzeppelin4/contracts/=node_modules/@openzeppelin/contracts-v4/",
"@solady/=node_modules/solady/src/",
"@nomad-xyz/src/=node_modules/@nomad-xyz/excessively-safe-call/src/",
"V3/=V3/src/",
"V3-script/=V3/script/",
"V3-test/=V3/test/"
],
"experimental": false
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.