// SPDX-License-Identifier: MIT pragma solidity 0.8.28; /// @title CoreActions /// @notice Encodes HyperCore actions exactly like HyperEVM's CoreWriter (`sendRawAction(bytes)`): /// byte 0 = encoding version (1), bytes 1..3 = action id (big-endian uint24), /// then `abi.encode(params)`. Prices and sizes are 10^8 * the human-readable value. /// A contract that encodes its orders with this library runs unchanged on HyperEVM's /// CoreWriter, on Precompilisium's WriteSim, and on KeeperLane. library CoreActions { uint8 internal constant VERSION = 1; uint24 internal constant LIMIT_ORDER = 1; uint24 internal constant CANCEL_BY_OID = 10; uint24 internal constant CANCEL_BY_CLOID = 11; uint8 internal constant TIF_ALO = 1; uint8 internal constant TIF_GTC = 2; uint8 internal constant TIF_IOC = 3; /// Encoded lengths: 4 header bytes + 32 bytes per parameter. uint256 internal constant LIMIT_ORDER_LEN = 4 + 7 * 32; uint256 internal constant CANCEL_LEN = 4 + 2 * 32; function limitOrder( uint32 asset, bool isBuy, uint64 limitPx, uint64 sz, bool reduceOnly, uint8 tif, uint128 cloid ) internal pure returns (bytes memory) { return abi.encodePacked(VERSION, LIMIT_ORDER, abi.encode(asset, isBuy, limitPx, sz, reduceOnly, tif, cloid)); } function cancelByOid(uint32 asset, uint64 oid) internal pure returns (bytes memory) { return abi.encodePacked(VERSION, CANCEL_BY_OID, abi.encode(asset, oid)); } function cancelByCloid(uint32 asset, uint128 cloid) internal pure returns (bytes memory) { return abi.encodePacked(VERSION, CANCEL_BY_CLOID, abi.encode(asset, cloid)); } }