// SPDX-License-Identifier: MIT pragma solidity ^0.8.24; /// Integrate Mkrv from any contract on Elysium. Create an Execution Account owned by your contract, /// then submit intents from it. Mkrv works every intent on HyperCore and posts each fill back as a receipt. interface IMkrvFactory { event AccountCreated(address indexed owner, address account); function createAccount(address owner) external returns (address account); function accountOf(address owner) external view returns (address account); function predict(address owner) external view returns (address account); function feePerSlice() external view returns (uint256); } interface IMkrvAccount { enum Kind { Limit, Twap, Iceberg, Stop, TakeProfit, Bracket } /// prices and sizes are scaled by 1e8; durations in seconds struct Params { Kind kind; uint32 asset; // Hyperliquid perp asset index bool isBuy; bool reduceOnly; uint64 sz; uint64 limitPx; // Limit, Iceberg uint64 triggerPx; // Stop, TakeProfit uint64 tpPx; // Bracket uint64 slPx; // Bracket uint64 visibleSz; // Iceberg uint32 duration; // Twap uint32 interval; // Twap uint16 maxSlippageBps; } event InstructionSubmitted(uint256 indexed id, uint8 kind, uint32 asset, bool isBuy, uint64 sz, uint64 limitPx, uint64 triggerPx); event Execution(uint256 indexed id, uint32 sliceIndex, uint64 hlOid, uint64 avgPx, uint64 sz, bytes16 cloid); event InstructionCompleted(uint256 indexed id, uint64 filledSz); event InstructionCancelled(uint256 indexed id); /// send feePerSlice * expected slices as value function submit(Params calldata p) external payable returns (uint256 id); function cancel(uint256 id) external; function modify(uint256 id, uint64 sz, uint64 limitPx, uint64 triggerPx) external; function cloidOf(uint256 id, uint32 sliceIndex) external pure returns (bytes16); function owner() external view returns (address); function feePerSlice() external view returns (uint256); } /// Example: a contract that owns an Execution Account and buys HYPE over ten minutes. contract MkrvTwapExample { IMkrvFactory public immutable factory; IMkrvAccount public account; constructor(IMkrvFactory f) { factory = f; account = IMkrvAccount(f.createAccount(address(this))); } function buyHype(uint64 sz1e8) external payable returns (uint256) { IMkrvAccount.Params memory p; p.kind = IMkrvAccount.Kind.Twap; p.asset = 159; // HYPE perp on Hyperliquid mainnet p.isBuy = true; p.sz = sz1e8; p.duration = 600; p.interval = 150; // 4 slices p.maxSlippageBps = 50; return account.submit{value: msg.value}(p); } }