Skip to main content

Overview

MeltHub is the central contract deployed on HyperEVM. It handles:
  • Receiving cross-chain bridge messages from MeltBridge via LayerZero
  • Minting wrapped MeltAsset tokens
  • Same-chain wrap/unwrap operations
  • Routing tokens to HyperCore via precompiles
  • Fee collection and management
Inherits: OApp (LayerZero), Pausable, ReentrancyGuard

Constructor

constructor(address _lzEndpoint, address _owner, address _feeCollector)
ParameterDescription
_lzEndpointLayerZero endpoint address on HyperEVM
_ownerContract owner (admin operations)
_feeCollectorAddress that receives collected fees

Token Registration

function registerToken(
    address originalToken_,
    address wrappedToken_,
    uint32 sourceEid_,
    uint256 feeBps_
) external onlyOwner
Registers a new token pair. Called by MeltFactory during deployment.
  • sourceEid_ = 0 for same-chain tokens
  • feeBps_ must be ≤ MAX_FEE_BPS (1000 = 10%)
  • Emits TokenRegistered

Same-Chain Operations

wrap

function wrap(bytes32 configKey, uint256 amount) external returns (uint256 amountOut)
Wraps original tokens into MeltAsset tokens. Only for same-chain tokens (sourceEid == 0).
  • Transfers original tokens from caller
  • Deducts fee, mints wrapped tokens
  • Returns amount after fee

unwrap

function unwrap(bytes32 configKey, uint256 amount) external returns (uint256 amountOut)
Unwraps MeltAsset tokens back to original tokens. Burns wrapped tokens and returns originals.

Cross-Chain Bridge

Inbound (_lzReceive)

Automatically called by LayerZero when a bridge message arrives from MeltBridge:
  1. Decodes payload: (originalToken, recipient, amount, toCore)
  2. Looks up token config
  3. Deducts fee, mints wrapped tokens
  4. If toCore == true: routes to HyperCore via _bridgeToCore()

bridgeOut

function bridgeOut(
    address wrappedToken,
    uint256 amount,
    bytes32 recipient
) external payable returns (MessagingReceipt memory)
Bridges tokens back to the source chain. Burns wrapped tokens and sends LayerZero message to MeltBridge to release locked originals. Requires msg.value for LayerZero gas fees. Use quoteBridgeOut to estimate.

quoteBridgeOut

function quoteBridgeOut(
    address wrappedToken,
    uint256 amount,
    bytes32 recipient
) external view returns (MessagingFee memory)
Returns estimated LayerZero fee for a bridge-out operation.

HyperCore Integration

setCoreConfig

function setCoreConfig(
    bytes32 configKey,
    uint64 coreIndexId_,
    int8 decimalDiff_
) external onlyOwner
Configures HyperCore integration for a token:
  • coreIndexId_ — HIP-1 token index on HyperCore
  • decimalDiff_ — EVM decimals minus Core decimals (for amount conversion)

Admin Functions

FunctionDescription
setFee(configKey, feeBps)Update fee for a token
pauseToken(configKey)Pause a specific token
unpauseToken(configKey)Unpause a specific token
pause() / unpause()Pause/unpause entire hub
setFeeCollector(address)Update fee collector address
collectFees(wrappedToken)Withdraw accumulated fees

Events

EventEmitted When
TokenRegisteredNew token pair registered
WrappedSame-chain wrap executed
UnwrappedSame-chain unwrap executed
BridgedInCross-chain bridge received
BridgedOutCross-chain bridge sent
BridgedToCoreToken routed to HyperCore
FeeUpdatedToken fee changed
FeesCollectedFees withdrawn

Errors

ErrorCause
TokenNotRegisteredOperating on unregistered token
TokenPausedToken operations are paused
InvalidFeeFee exceeds MAX_FEE_BPS (10%)
InvalidSourceChainWrong sourceEid for operation
CoreNotConfiguredHyperCore config missing
CoreUserNotActivatedRecipient doesn’t exist on HyperCore