Skip to content
elyrail

Swaps on Uniswap v4

swap_uniswap_v4 swaps an exact input amount in one Uniswap v4 pool through the official Universal Router on Elysium mainnet. Uniswap has no deployment on Elysium testnet, so on testnet the tool returns CONFIG_UNKNOWN.

Policy#

json
{
  "tokens": [{ "address": "0xb47c4C8F73F009CC0C0d3f92B388d13E293F0B65", "symbol": "USDC", "decimals": 6 }],
  "limits": { "perTransaction": [{ "token": "native", "max": "0.5" }, { "token": "0xb47c4C8F73F009CC0C0d3f92B388d13E293F0B65", "max": "100" }] },
  "swaps": [{
    "venue": "uniswap-v4",
    "router": "0x1B341FDD55d56F8E08409A2C25DDFad93Eb03C1a",
    "selectors": ["0x3593564c"],
    "tokensIn": ["native"],
    "tokensOut": ["0xb47c4C8F73F009CC0C0d3f92B388d13E293F0B65"],
    "maxSlippageBps": 50
  }]
}

How a swap is checked#

  1. The tool quotes with the official V4Quoter and sets minAmountOut from slippageBps.
  2. It encodes execute(0x10, [SWAP_EXACT_IN_SINGLE, SETTLE_ALL, TAKE_ALL]) for Universal Router 2.2.0, following the v4-periphery source at the commit that router uses.
  3. It sets a deadline.
  4. The wallet simulates the transaction and requires:
    • no more of the input token leaves than declared;
    • at least minAmountOut arrives;
    • minAmountOut is within maxSlippageBps of the simulated output, not of the tool's own quote;
    • no approval is created.

ERC-20 inputs need two approvals first, both through approve_token: an ERC-20 approval to Permit2, then a Permit2 approval (with an expiry) to the Universal Router. The policy must allow both.

Only pools without hooks are allowed, unless the policy lists the hook contract in hooks.

Verified#

The calldata was checked against the real mainnet contracts by simulating a 0.01 HYPE to USDC swap with eth_simulateV1. Nothing was sent.