// SPDX-License-Identifier: MIT pragma solidity ^0.8.24; /// @title Elysio SDK: types and interfaces /// @notice A contract on Elysium sends an intent; a relayer places it on HyperCore and answers with exactly one /// final receipt. Sizes and prices use 8 decimals, the precision HyperCore uses on the wire. library ElysioTypes { enum Tif { Ioc, Gtc, Alo } /// Open and Acked are not final; every other status is. enum Status { None, Open, Acked, Filled, Partial, Dropped, Unanswered } struct Intent { uint32 asset; // HyperCore asset id, e.g. 10107 = HYPE/USDC spot bool isBuy; bool reduceOnly; Tif tif; uint64 sz; // 8 decimals: 0.18 HYPE = 18_000_000 uint64 limitPx; // 8 decimals uint64 deadline; // unix seconds; no final receipt by deadline + 5 minutes => Unanswered uint32 callbackGas; // gas for onReceipt, at most 2,000,000 } struct Receipt { Status status; uint64 filledSz; // 8 decimals uint64 avgPx; // 8 decimals, 0 when nothing filled int64 fee; // 8 decimals in quote, negative is a rebate uint64 oid; // HyperCore order id, 0 if never placed uint64 coreTime; // HyperCore time of the final event, ms uint8 reason; // Dropped reason, 0 otherwise bytes32 fillHash; // hash of the HyperCore fill hashes } // Dropped reasons uint8 internal constant IOC_NO_MATCH = 1; uint8 internal constant ALO_WOULD_CROSS = 2; uint8 internal constant CANCELLED_AT_DEADLINE = 3; uint8 internal constant INSUFFICIENT_BALANCE = 4; uint8 internal constant BELOW_MIN_VALUE = 5; uint8 internal constant REJECTED_OTHER = 6; uint256 internal constant EXPIRY_GRACE = 5 minutes; uint32 internal constant MAX_CALLBACK_GAS = 2_000_000; function isFinal(Status s) internal pure returns (bool) { return s >= Status.Filled; } /// The 128-bit client order id every HyperCore order carries, so each order traces back to one intent. function cloid(address router, uint256 intentId) internal view returns (bytes16) { return bytes16(keccak256(abi.encode(block.chainid, router, intentId))); } } /// Implemented by consumers. Only the router calls it, once per final receipt (and again on retryCallback). interface IElysioReceiver { function onReceipt(uint256 intentId, ElysioTypes.Receipt calldata receipt) external; } interface IElysioRouter { event IntentRequested( uint256 indexed intentId, address indexed consumer, address indexed relayer, address coreAccount, bytes16 cloid, ElysioTypes.Intent intent ); event ReceiptPosted(uint256 indexed intentId, address indexed relayer, ElysioTypes.Receipt receipt); event CallbackResult(uint256 indexed intentId, bool ok, uint256 gasUsed); event Expired(uint256 indexed intentId, address indexed relayer, address caller); /// Records the intent for msg.sender (a bound consumer) and returns its id. function request(ElysioTypes.Intent calldata intent) external returns (uint256 intentId); /// The stored receipt; status None or Open until an answer lands. function receiptOf(uint256 intentId) external view returns (ElysioTypes.Receipt memory); /// Replays a stored final receipt to its consumer. Anyone can call it. function retryCallback(uint256 intentId) external; /// After deadline + 5 minutes with no final receipt, ends the intent as Unanswered. Anyone can call it. function expire(uint256 intentId) external; }