# ElyPerps skill

ElyPerps lists a perpetual market for any coin on Elysium with a spot pool on Ascend or its own ElyPerps pool. Margin and settlement in HYPE. Use this file to trade, run a keeper or LP from an agent.

## Endpoints (this site)
- MCP: `POST /mcp` (JSON-RPC 2.0, keyless). Tools: `markets`, `market_state`, `quote_open`, `open_calldata`, `close_calldata`, `liquidatable`.
- API: `/api/markets`, `/api/positions?account=0x...`, `/api/funding`, `/api/liquidations`, `/api/insurance`, `/api/stats?w=24h`, `/api/chain`.
- SDK: `/sdk/elyperps.js` (ES module): `new ElyPerps(site).quote(...)`, `.openCalldata(...)`, `.closeCalldata(engine)`, `.liquidateCalldata(engine, account)`.

## Rules the engine enforces
- Mark, launch-pool markets (default): median of the last 12 samples of the coin's Ascend launch pool, read onchain by `PerpSampler.sample(coin)` (anyone, at most every 5 s, each step at most 1%). Half caps, 2x.
- Mark, own-pool markets: 60-second TWAP of the pool's start-of-block observations (each moves at most 0.1%).
- Opens and closes fill at the worse of mark and spot.
- Opens pause when spot and TWAP differ by more than 3%.
- Open interest per side: 10% of the pool's HYPE depth within +-20% of the price, at most 25,000 HYPE. One account: 2% of depth.
- Leverage: 3x under 2,000 HYPE depth, 5x from 2,000, 10x from 50,000. Sampled markets: half caps, 2x.
- Maintenance margin: 15% at 3x and under, 10% at 5x, 5% at 10x.
- Funding every block, set by skew, at most 0.1% per hour. 10% of what the paying side pays goes to the pool's LPs.
- Skew cap: 10% of the insurance vault's HYPE. Past it, opens wait in a queue for the other side (cancel for a full refund). With an empty vault, every long is matched by a short.
- Fee: 0.05% of notional on open and close. 40% $ELYP stakers, 30% buys and burns $ELYP, 20% the pool's LPs, 10% buys and burns KNTQ.
- Liquidation: 0.5% of notional to the keeper, 0.5% to the vault.

## Trading loop
1. `markets` to pick a market that is open and not drifted.
2. `quote_open` with side, leverage and margin. Check `reasons` is empty and read `fillsNow`.
3. `open_calldata`, sign and send with `value`.
4. Watch `/api/positions?account=` and close with `close_calldata`.

## Keeper loop
For each market and each account with a position: `liquidatable`; if true, send its calldata. Call `settleFunding()`, `matchQueues()`, `poke()` and `flushLPFunding()` on each engine every pass.

## Chain
Elysium: HYPE gas, 100 ms blocks. `/api/chain` reports the head and how old it is; when the chain is stalled nothing can execute, so wait.
