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
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.
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.
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%.
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.
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:
To keep it as a Claude Code skill, so Claude uses it whenever you ask for a swap:
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
Routers — the only contracts a swap may be sent to:
The native gas token (HYPE on both chains) is 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE, with 18 decimals.
Before you quote
- 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.
- 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.
- Read each ERC-20 token’s
symbol()anddecimals()on-chain and show the symbol to the user. Skip this for the native token (18 decimals). - 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.
- 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.
- Slippage is a fraction:
0.005means 0.5%,0.5means 50%. Use at most0.05unless 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 to0.5; anything else silently becomes0.01— after the quote, checkminAmountOutis aboutamountOut × (1 − slippage)and tell the user if the default was used.
Quote
- Call
GET /quotewithtokenIn,tokenOut,amountIn(wei) andslippage. If you integrate for a wallet or app that charges its own fee, addfeeBps(1–100) andfeeReceiver— see Integrator fee. - Treat any non-200 status,
errororerrorsin the body as a failure — see API errors. Set a timeout on every request. Token symbols are not accepted; the API needs addresses. - 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. BothamountOutandminAmountOutare already net of that fee. - Check price impact.
priceImpactPercentis 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. - Get the user’s confirmation and remember the
minAmountOutthey confirmed.
Build the transaction
- Call
GET /swapwith 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.
- Check the router.
tx.routermust be in this chain’s row of the router table, ignoring case: the standard router when you sent nofeeBps, the integrator-fee router when you did. With a fee,quote.integratorFee.bpsand.receivermust equal what you sent; without one,integratorFeemust be absent. If anything differs, stop. - If
/swapreturns400minAmountOut is above the quoted output less slippage, the price moved against the user: quote again, show the new amounts and get confirmation again. - If the user has not signed before the deadline, call
/swapagain and repeat checks 13 and 14.
Approve (ERC-20 input only)
- Read the user’s
allowancefortx.router. If the read fails, retry; never treat a failed read as enough allowance. - If it is below
amountIn, ask the user to approve exactlyamountInfor 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, approve0first, then the amount. - After the approval is confirmed on-chain, call
/swapagain and repeat checks 13 and 14. A plain simulation before the approval always reverts; if your RPC supportseth_callstate overrides, you may override the allowance to dry-run before asking for the approval.
Simulate
- Simulate the swap with
eth_callfrom the user’s address totx.router, withtx.data, andvalue = amountInfor native-token input (otherwise0). - The call returns the output amount as one 32-byte word. Check it is at least
minAmountOut. - If it reverts, do not send.
Match on the message text: reverts can arrive wrapped, as callBytes failed: Error(…).
Sign and confirm
- 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 sendwith--ledgeror--interactive), orto,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. - Check the receipt for the transaction hash the user gives you, with a time limit. Status
1means the swap went through: give the explorer link (<explorer>/tx/<hash>). Status0means it reverted on-chain — nothing was swapped, only gas was spent. Quote again before retrying.
API errors
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
- Full parameters and responses: DEX Aggregator API
- Router addresses: Smart Contracts