Skip to content

HyperCore Execution

This section covers the HyperEVM execution contracts: the Allocator and the Router.

HyperCoreAllocator

Source: src/strategies/hyperevm/HyperCoreAllocator.sol

The Allocator resides on the HyperEVM. It receives bridged assets via CCTP, mints internal shares to track the source chain's ownership, and distributes capital to routers.

Public And External Functions

Function Access Description
initialize(...) initializer Initializes allocator proxy, stores asset, receiver domain, receiver, manager, CCTP contracts, decimals offset.
asset() public view Returns HyperEVM asset.
receiver() public view Returns source-chain CCTP receiver domain and address.
manager() public view Returns harvest/exit recipient.
totalAssets() public view Returns allocator idle asset plus all router assets.
idleAssets() public view Returns asset balance held by allocator.
totalSupply() public view Returns allocator internal share supply.
pendingRedeemShares() public view Returns shares queued for cross-chain redemption.
pendingRedeemAssets() public view Converts pending redeem shares to assets.
routers() public view Returns registered router list.
addRouter(address router) Developer Registers router. Emits RouterAdded.
setCctpMaxFee(uint256 maxFee) Keeper Sets max CCTP fee.
allocate(uint256 routerIdx, uint256 amount) Keeper Transfers idle asset to router.
collect(uint256 routerIdx, uint256 amount) Keeper Pulls asset back from router after router approval.
executeRedeem(uint256 sharesToRedeem) Keeper Burns queued internal shares and bridges assets back to source chain with state hook.
sendState() Keeper Sends current allocator state to source chain.
handleInvestMessage(bytes message, bytes attestation) Keeper Receives CCTP invest mint, mints internal shares, sends state response.
handleDivestMessage(bytes message, bytes attestation) Keeper Relays CCTP divest message to mint local asset.
handleReceiveFinalizedMessage(...) CCTP MessageTransmitter only Queues RedeemMessage.shares into pending redeem shares.
handleReceiveUnfinalizedMessage(...) external pure Accepts unfinalized message path and returns true.
exit() Keeper Transfers allocator idle asset to manager.
harvest(IERC20 asset_) Keeper Sweeps non-primary token to manager. Emits Harvested.

Internal Functions

Function Description
_getHyperCoreAllocatorStorage() Returns HyperCoreAllocator's ERC-7201 namespaced storage pointer.
_authorizeUpgrade(address) UUPS authorization, Admin only.
_sendState(uint256 processedAssets) Sends UpdatedStateMessage to source chain.
_encodeStateMessage(...) Encodes nonce, timestamp, totals, processed assets/shares.
_validateSource(...) Validates CCTP source domain and sender.
_convertToShares(uint256 assets, Math.Rounding rounding) ERC-4626-style conversion for allocator internal shares.
_convertToAssets(uint256 shares, Math.Rounding rounding) ERC-4626-style conversion for allocator internal shares.
_addressToBytes32(address) Converts address to bytes32.
_bytes32ToAddress(bytes32) Converts bytes32 to address.

HyperCoreRouter

Source: src/strategies/hyperevm/HyperCoreRouter.sol

The Router calls the HyperCore Layer 1 precompiles to generate yield through HLP and margin accounts.

Public And External Functions

Function Access Description
receiver() public view Returns parent allocator.
asset() public view Returns HyperEVM asset.
totalAssets() public view Returns router ERC-20 balance, spot balance, perp withdrawable balance, and HLP equity minus reserved fee.
balance() public view Returns ERC-20 asset held by router.
balanceSpot() public view Reads HyperCore spot balance precompile and converts wei to USD units.
balancePerp() public view Reads HyperCore withdrawable precompile.
vaultEquity() public view Reads HLP vault equity precompile and returns unlock status.
depositToSpot(uint256 amount) Keeper Deposits ERC-20 asset to CoreDepositWallet.
spotToPerp(uint64 amount) Keeper Moves USD from spot to perp margin.
perpToVault(uint64 amount) Keeper Deposits perp margin into HLP vault.
vaultToPerp(uint64 amount) Keeper Withdraws HLP vault equity to perp margin.
perpToSpot(uint64 amount) Keeper Moves perp margin back to spot.
withdrawFromSpot(uint64 amount) Keeper Withdraws spot to system, producing ERC-20 asset on router.
harvest(IERC20 asset_) Keeper Sweeps non-primary token to allocator.
approveOnlyForAllocator() Allocator only Approves allocator to pull router's ERC-20 asset balance.

Internal Functions

Function Description
_transferUsdClass(uint64 ntl, bool toPerp) Sends HyperCore USD class transfer raw action.
_spotSend(address to, uint64 token, uint64 amountWei) Sends HyperCore spot send raw action.
_vaultTransfer(address vault, bool isDeposit, uint64 amountUsd) Sends HyperCore vault transfer raw action.
_weiToUsd(uint64 amountWei) Converts HyperCore wei-style amount to 6-decimal USD unit.
_usdToWei(uint64 amountUsd) Converts 6-decimal USD unit to HyperCore wei-style amount.