# Elyra agent quickstart

A runnable starting point for an agent that uses Elyra on Elysium (chain id 99901) with its own
wallet. It does what an agent should do before it signs anything, in order:

1. Reads what Elyra publishes on its site: `/llms.txt`, the deployment manifest
   (`/deployments/elysium.json`), the chain constants (`/deployments/elysium-external.json`) and
   the ABIs `/llms.txt` links. It stops if the two sources disagree about an address.
2. Quotes a swap of native HYPE for USDC through the Elyra Router (`Router.quoteExactIn`).
3. Plans a deposit of the swap's minimum output into a USDC vault from the manifest: the swap with
   a minimum out and a deadline, an exact approval to the vault, and the deposit. Every `to` is
   checked against the deployment files.
4. Simulates the whole plan in one `eth_simulateV1` request, each call after the one before.
5. Sends it, one transaction at a time, only with `--send`. Without it nothing is signed.

Elyra never asks for a key, a seed phrase or a signature. The key stays in this process.

## Files

| File | What it is |
|---|---|
| `quickstart.ts` | the script: read, quote, plan, simulate, send |
| `elyra.ts` | the pure helpers it uses: the hop encoding, the plan, the published-address table |
| `elyra.test.ts` | their tests (`npm test`, no network) |
| `package.json`, `tsconfig.json` | viem is the only dependency |

## Setup

Node 22.18 or newer runs the TypeScript files directly.

```bash
npm install
export ELYRA_SITE="<the address of Elyra's site, without a trailing slash>"
```

### On a local fork (the default)

Start a fork of Elysium with [Foundry](https://getfoundry.sh)'s anvil. The public RPC keeps full
history, so it can serve the fork; it rate-limits parallel calls, so a paid RPC URL is faster:

```bash
anvil --fork-url https://rpc.elysium.kinetiq.xyz --chain-id 99901 --port 8549
```

Then, in another terminal:

```bash
export RPC_URL=http://127.0.0.1:8549
npm start              # read, quote, plan and simulate; nothing is sent
npm run send           # the same, then send the plan on the fork
npm start -- --amount 0.2
```

On a fork with no `PRIVATE_KEY` set, the script makes a throwaway key and funds it with 1 HYPE
(`anvil_setBalance`), so it runs with nothing else to set up.

### On Elysium

Use a wallet of the agent's own, funded only with what it should manage, never your main wallet.

```bash
RPC_URL=https://rpc.elysium.kinetiq.xyz AGENT_ADDRESS=0xYourAgentWallet npm start
```

simulates the plan for that address without a key. To send it for real, the key comes from the
agent's own environment, and `--mainnet` must be given as well as `--send`:

```bash
RPC_URL=https://rpc.elysium.kinetiq.xyz PRIVATE_KEY=0x… npm start -- --send --mainnet
```

The script refuses an address that has code on chain (an EIP-7702 delegation, for instance): such
code can forward what the address receives.

| Variable | Default | |
|---|---|---|
| `ELYRA_SITE` | none, required | where `/llms.txt` and the deployment files are read from; the script stops when it is unset |
| `RPC_URL` | a local fork | the chain to read, simulate and send on |
| `PRIVATE_KEY` | none | the agent wallet's key; on a local fork a throwaway one is made when unset |
| `AGENT_ADDRESS` | none | simulate for this address without a key |

## What to change first

- The amount (`--amount`, in HYPE) and the slippage (`SLIPPAGE_BPS`, 50 = 0.5 %).
- The route: the script quotes one hop through each public HYPE/USDC pool. The Router also takes
  Elyra's own pools, DLMM pairs and up to three hops: see Routes through the Router in the
  Agents and integrations chapter (`/docs/agents#routes-through-the-router`).
- The vault: any vault in the manifest takes the same `deposit(assets, receiver)`. LP, hedged and
  structured vault shares carry 3 more decimals than their asset, so read the vault's own
  `decimals()`, as the script does. USDC has 6 decimals.

## The rules it keeps

The same as `/llms.txt` lists, and the Agents and integrations chapter (`/docs/agents`) explains:
its own wallet, every `to` checked against the deployment files, exact approvals only, a minimum
and a short deadline on the swap, a fresh `previewDeposit` before the deposit (an ERC-4626 deposit
takes no minimum), and one simulation of the whole sequence before anything is signed. A gas
estimate is the least that succeeded on the latest block, so the script sends with 25 % more, as
wallets do.

## Limits

The script reads static files from Elyra's site and talks to the RPC you give it. The public RPC
rate-limits parallel calls: keep reads batched (Multicall3) and slow down on a 429. See Rate limits
in the Agents and integrations chapter (`/docs/agents#rate-limits`).
