# Elyra skill

Elyra: programmable orders for Elysium (chain 99901, gas in HYPE). You sign an order once (EIP-712): tokens, amounts,
the worst price you accept, expiry, partial fills, TWAP parts and an optional condition on a Uniswap v4 pool's TWAP or on
a HyperCore value (mid or hourly funding of HYPE, BTC, ETH, SOL). Bonded solvers fill open orders in batch auctions every
4 seconds from Elysium's v4 pools, their inventory and each other's orders. The settlement contract pays the receiver at
least the limit after the fee (0.10 %, cap 0.30 %) or the order does not fill. Signing moves nothing.

## Read (no key)
- `GET https://www.elyraprotocol.xyz/api/status`: chain head, contract addresses (null before deployment), auction service status, constants.
- `GET https://www.elyraprotocol.xyz/api/quote?sell=USDC&buy=HYPE&amount=100`: the reference solver's live v4 route and output, the HyperCore mid next to it, receiverGets after the fee. `raw=1` takes base units.
- `GET https://www.elyraprotocol.xyz/api/conditions?coins=HYPE&key=HYPE.funding&op=lte&threshold=0`: HyperCore values as feed keys (1e18), and whether a condition holds now.
- `GET https://www.elyraprotocol.xyz/api/pools`: the v4 pools used for routing, live.

## Place an order
1. `GET /api/status`: take `contracts.settlement` (EIP-712 verifyingContract) and `contracts.relayer`.
2. Approve the relayer once per sell token (ERC-20 approve, sellSource 0) or give it a Permit2 allowance (sellSource 1). Sell HYPE as WHYPE (deposit first).
3. Build the order (amounts in base units, per part):
```
Order(address owner,address sellToken,address buyToken,address receiver,uint256 sellAmount,uint256 buyAmount,
      uint32 validFrom,uint32 validTo,uint16 parts,uint32 partInterval,bool partiallyFillable,uint8 sellSource,
      bytes32 appData,uint256 salt,Condition condition)
Condition(uint8 kind,address source,bytes32 key,int256 threshold,uint32 window,uint32 maxAge)
domain { name: "Elyra", version: "1", chainId: 99901, verifyingContract: <settlement> }
```
   buyAmount is the minimum the receiver gets for sellAmount after the fee. Condition kind 0 none, 1 value >= threshold,
   2 value <= threshold; source ElyraFeed with key = ASCII "HYPE.funding" left aligned in bytes32 and threshold scaled 1e18,
   or ElyraPoolOracle with key = poolId and threshold = a tick over `window` seconds. maxAge at most 600.
4. Sign the typed data with the owner's wallet, then `POST https://www.elyraprotocol.xyz/api/orders` with `{"order": {...}, "signature": "0x...", "scheme": 0}`. The answer holds the uid.
5. Track: `GET https://www.elyraprotocol.xyz/api/orders?owner=0x...`. Cancel off chain: sign `Cancel(bytes32 orderHash)` and `DELETE /api/orders/<uid>` with `{"signature"}`; on chain: `invalidate([uid])` on the settlement.

## SDK and MCP
- `import * as Elyra from "https://www.elyraprotocol.xyz/sdk/elyra.js"`: quote, conditions, buildOrder, feedCondition, typedData, submit, orders, cancel.
- MCP (streamable HTTP, keyless, never signs): `https://www.elyraprotocol.xyz/mcp`. Tools: elyra_status, elyra_quote, elyra_conditions, elyra_pools, elyra_build_order, elyra_list_orders, elyra_get_order, elyra_auction, elyra_auctions, elyra_solvers, elyra_cancel_typed_data, elyra_invalidate_calldata, elyra_approve_calldata, elyra_wrap_calldata.

## Run a solver
Register a HYPE bond on ElyraSolverRegistry (`register()`, minimum 0.1 HYPE at launch). Every 4 s read `GET /api/auction`,
build a Solution (tokens, uniform prices, trades, interactions through the Universal Router or the settlement's unlock
callback), simulate `settle` from your address, sign `Commit(uint64 auctionId,bytes32 solutionHash,uint64 deadline)` and
`POST /api/solutions`. If you win, the Award is in `GET /api/auctions`: call `settle(solution, award)` before the deadline.
You keep 80 % of the fee on each fill. Three won auctions left unsettled within 24 h slash 10 % of the bond and eject you.

Docs: https://www.elyraprotocol.xyz/docs
