Skip to navigation

Agent Swap Guide

Let an AI agent — Claude Code, Cursor, or your own — swap tokens for you on HyperEVM or Elysium. You ask in plain words (“swap 1 HYPE to USDC on Elysium”); the agent gets the best route from HyperFlow, checks it, and hands you the transaction to sign.

The first part of this page is for you: what the agent does and never does. The rest is the set of rules the agent follows, in whatever language or tools it uses. The same rules apply if you are writing a bot or app on the DEX Aggregator API yourself.

What the agent does

1

Finds the tokens

Reads each token’s name and decimals on-chain and shows them to you, so you confirm it is the right token. It never guesses an address.

2

Gets a quote

Asks HyperFlow for the best route and shows what you pay, what you receive, the minimum you will receive, and any fee. The minimum you confirm is written into the transaction, so you never get less.

3

Checks the price

Warns you if the trade itself moves the price against you by more than 1% (price impact), and asks again above 5%.

4

Asks you to approve the token, if needed

For tokens other than HYPE, asks you to approve — a one-time permission letting HyperFlow’s router move exactly the amount being swapped, never an unlimited amount.

5

Simulates the swap

Dry-runs the transaction on the chain first. If the dry run fails, nothing is sent.

6

You sign, it confirms

You sign in your own wallet, on the chain the agent names; the agent then checks the result and gives you the explorer link.

What it never does

  • Ask for, read or store your private key, seed phrase or keystore password.
  • Send any transaction without your confirmation.
  • Send a swap to a contract other than HyperFlow’s routers listed on this page. An approval goes to the token itself, and only for one of those routers.

Example

You: Swap 1 HYPE to USDC on Elysium.

Agent: Which USDC? Please paste its address or explorer link on Elysium.

You: 0xb47c4c8f73f009cc0c0d3f92b388d13e293f0b65

Agent: That is USDC, 6 decimals. You pay 1 HYPE (about 59 USD) and receive about 59.08 USDC, at least 58.79 USDC with 0.5% slippage. Price impact is under 0.1% and the dry run succeeded. Here is the transaction — check your wallet is on Elysium (chain ID 99901) before signing.

Use it

Paste this to any agent that can read web pages — Claude, ChatGPT, Cursor:

Read https://docs.hyperflow.fun/developers/agent-swap-guide.md and follow it to swap 1 HYPE to USDC on Elysium.

To keep it as a Claude Code skill, so Claude uses it whenever you ask for a swap:

mkdir -p ~/.claude/skills/hyperflow-swap && cd ~/.claude/skills/hyperflow-swap
printf -- '---\nname: hyperflow-swap\ndescription: Swap tokens on HyperEVM or Elysium through HyperFlow\n---\n' > SKILL.md
curl -fsSL https://docs.hyperflow.fun/developers/agent-swap-guide.md >> SKILL.md

Run it again to pick up changes to this page.

Agent instructions

Everything below is written for the agent. Follow every rule; when a check fails, stop and tell the user rather than working around it.

Chains

ChainAPI base URLChain IDPublic RPCExplorer
HyperEVMhttps://ag-api.hyperflow.fun/v1/hyperevm999https://rpc.hyperliquid.xyz/evmhttps://hyperevmscan.io
Elysiumhttps://ag-api.hyperflow.fun/v1/elysium99901https://rpc.elysium.kinetiq.xyzhttps://elysium.kinetiq.xyz

Routers — the only contracts a swap may be sent to:

ChainStandard routerRouter for swaps with an integrator fee
HyperEVM0x980B9271A33c4B31214301fAE584B18dBB9731eC0x0FbE14a7Cd24aDB08575d67bd39d2290A12126b0
Elysium0x980B9271A33c4B31214301fAE584B18dBB9731eC0x995E574059e1dD9528C22627773A397Bbb073A22

The native gas token (HYPE on both chains) is 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE, with 18 decimals.

Before you quote

  1. Pick one chain and keep it. Use that chain’s API base URL, RPC and router list for every step. Check the RPC’s chain ID matches before any on-chain read.
  2. Never guess a token address. Use an address the user gave, or ask for a link to the token on the chain’s explorer. There is no token-search endpoint.
  3. Read each ERC-20 token’s symbol() and decimals() on-chain and show the symbol to the user. Skip this for the native token (18 decimals).
  4. If a read fails, stop. “No code at address” means it is not a token on this chain — ask the user. A rate-limit or timeout error means retry after a few seconds. Never continue with a missing or default decimals value: a wrong value scales the amount by powers of ten.
  5. Convert the amount to wei with the token’s decimals, then convert it back and show the user, since extra decimal places are cut off.
  6. Slippage is a fraction: 0.005 means 0.5%, 0.5 means 50%. Use at most 0.05 unless the user explicitly agrees to more. If the user gives a number without a % sign, ask what they mean. The API applies values above 0 and up to 0.5; anything else silently becomes 0.01 — after the quote, check minAmountOut is about amountOut × (1 − slippage) and tell the user if the default was used.

Quote

  1. Call GET /quote with tokenIn, tokenOut, amountIn (wei) and slippage. If you integrate for a wallet or app that charges its own fee, add feeBps (1–100) and feeReceiver — see Integrator fee.
  2. Treat any non-200 status, error or errors in the body as a failure — see API errors. Set a timeout on every request. Token symbols are not accepted; the API needs addresses.
  3. Show the user, in token units: what they pay, what they receive (amountOut), the minimum they will receive (minAmountOut), the USD value of both sides, and the integrator fee if any. Both amountOut and minAmountOut are already net of that fee.
  4. Check price impact. priceImpactPercent is in percent, excludes the integrator fee, and is negative when the route loses value. Below −1, warn the user. Below −5, say plainly the trade loses more than 5% and suggest a smaller amount; continue only if the user confirms again. Zero or positive values need no warning.
  5. Get the user’s confirmation and remember the minAmountOut they confirmed.

Build the transaction

  1. Call GET /swap with the same parameters plus:
    • receiver: the user’s address, which must be the address that will sign;
    • minAmountOut: the value the user confirmed, so the transaction can never pay less;
    • deadline: now + 120 seconds (Unix seconds), so a transaction signed late fails instead of filling at a stale price.
  2. Check the router. tx.router must be in this chain’s row of the router table, ignoring case: the standard router when you sent no feeBps, the integrator-fee router when you did. With a fee, quote.integratorFee.bps and .receiver must equal what you sent; without one, integratorFee must be absent. If anything differs, stop.
  3. If /swap returns 400 minAmountOut is above the quoted output less slippage, the price moved against the user: quote again, show the new amounts and get confirmation again.
  4. If the user has not signed before the deadline, call /swap again and repeat checks 13 and 14.

Approve (ERC-20 input only)

  1. Read the user’s allowance for tx.router. If the read fails, retry; never treat a failed read as enough allowance.
  2. If it is below amountIn, ask the user to approve exactly amountIn for that router — never an unlimited amount. Hand it over like the swap in rule 22: to = the token, data = approve(<router>, <amountIn>), value = 0. If the approval reverts on a token that already has a non-zero allowance, approve 0 first, then the amount.
  3. After the approval is confirmed on-chain, call /swap again and repeat checks 13 and 14. A plain simulation before the approval always reverts; if your RPC supports eth_call state overrides, you may override the allowance to dry-run before asking for the approval.

Simulate

  1. Simulate the swap with eth_call from the user’s address to tx.router, with tx.data, and value = amountIn for native-token input (otherwise 0).
  2. The call returns the output amount as one 32-byte word. Check it is at least minAmountOut.
  3. If it reverts, do not send.
RevertLikely cause
TransferHelper: TRANSFER_FROM_FAILEDMissing approval, or the wallet holds less than amountIn — check balanceOf and allowance
insufficient funds for gas * price + value (an RPC error, not a revert)The wallet holds less HYPE than the value plus gas — tell the user; do not retry
TransferHelper: TRANSFER_FAILEDThe output token refused the transfer to receiver — check the receiver; do not retry blindly
TransferHelper: ETH_TRANSFER_FAILEDreceiver cannot accept native HYPE (for example a contract) — do not retry; ask for another receiver or swap to WHYPE
Anything elseThe route moved — call /swap again and re-simulate once; if it still reverts, report the message to the user

Match on the message text: reverts can arrive wrapped, as callBytes failed: Error(…).

Sign and confirm

  1. Do not sign yourself. Ask how the user signs, then give the transaction in that form: a command for their own terminal (for example cast send with --ledger or --interactive), or to, data, value (in wei) and chain ID for a wallet that accepts a custom transaction. Name the chain and its ID and ask the user to check their wallet is on it: the standard router has the same address on both chains, so a wallet on the wrong chain would send the swap there. Never ask for a password or key to sign on their behalf.
  2. Check the receipt for the transaction hash the user gives you, with a time limit. Status 1 means the swap went through: give the explorer link (<explorer>/tx/<hash>). Status 0 means it reverted on-chain — nothing was swapped, only gas was spent. Quote again before retrying.

API errors

BodyStatusWhat to do
{"error": "Bad request. Reason: minAmountOut is above the quoted output less slippage"}400The price moved against the user — see rule 14
{"error": "Bad request. Reason: …"} or any other message400Read the reason, fix the parameter, retry
{"errors": [{"field": "...", "message": "..."}]}400A parameter is malformed (e.g. a non-numeric amountIn) — fix that field
{"error": "Key: '…' Error:Field validation for '…' failed on the 'required' tag"}400A required parameter is missing (e.g. receiver on /swap)
{"error": "token not found"}404The token is not on this chain — check the address and the chain
{"error": "no path found"}404No route for this pair and amount — suggest a smaller amount or a different pair
{"error": "rate limit exceeded"}429Wait and retry with an increasing delay (250 ms, 500 ms, 1 s, …); stop after a few tries
anything5xxA fault on our side — retry once after a few seconds, then report it

Public RPCs are rate-limited too: the HyperEVM one starts refusing after a few calls per second. Space reads about a second apart, or use the user’s own RPC.

Reference