Skip to content

Add HyperSwap AMM connector for HyperEVM#641

Open
RYB-404 wants to merge 2 commits into
hummingbot:mainfrom
RYB-404:ryb-hyperswap-503
Open

Add HyperSwap AMM connector for HyperEVM#641
RYB-404 wants to merge 2 commits into
hummingbot:mainfrom
RYB-404:ryb-hyperswap-503

Conversation

@RYB-404

@RYB-404 RYB-404 commented May 25, 2026

Copy link
Copy Markdown

Summary

  • Adds a HyperSwap connector scoped to HyperEVM AMM/V2 support.
  • Registers /connectors/hyperswap/amm in Gateway and advertises it from /config/connectors.
  • Adds HyperEVM chain, HyperSwap connector, and WHYPE token templates.
  • Uses the documented HyperSwap V2 factory/router addresses and intentionally leaves router/CLMM routes unregistered until those surfaces have confirmed contracts and implementation coverage.

Testing

  • corepack pnpm exec jest --runInBand test/connectors/hyperswap/hyperswap.routes.test.ts
  • corepack pnpm run build
  • corepack pnpm exec eslint "src/connectors/hyperswap/**/*.ts" "test/connectors/hyperswap/**/*.ts" --format table (0 errors; existing default-import/no-unused warnings only)

Closes #503

@fengtality fengtality left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the connector — a few blocking issues from my read:

🔴 Critical (must fix before merge)

1. Router ABI contains only multicall — every swap/liquidity call will throw at runtime.

src/connectors/hyperswap/hyperswap_v2_router_abi.json ships with only a multicall function. Every route that uses IHyperswapV2Router02ABIswapExactTokensForTokens, swapTokensForExactTokens, addLiquidity, addLiquidityETH, removeLiquidity, removeLiquidityETH — will resolve to undefined on the ethers Contract and throw TypeError: routerContract.swapExactTokensForTokens is not a function. The connector is non-functional as shipped. Please include the full Uniswap-V2 Router02 ABI.

2. addLiquidity.ts:207-218addLiquidityETH called with msg.value even when base token is WETH.

When baseTokenObj.symbol === 'WETH', the code still routes through addLiquidityETH with value: rawBaseTokenAmount. WETH is an ERC-20, not native ETH — this burns native gas without depositing WETH and will likely revert (router would try to wrap already-wrapped tokens). The native-ETH path only makes sense for unwrapped ETH; WETH should use addLiquidity (both ERC-20s).

3. removeLiquidity.ts:1909-1910 — hardcoded 0.5% slippage ignores user config.

const slippageTolerance = new Percent(5, 1000); // 0.5%

slippagePct from the request is accepted but never applied. Users who configure higher slippage will get unexpected reverts.

4. executeSwap.ts:758quoteToken || '' silent fallback.

quoteToken is Type.Optional(...) in the schema, so it can be undefined. The || '' fallback then calls getToken('') which returns null, surfacing as a confusing notFound error instead of 'quoteToken is required'. Validate at the route handler.

🟡 Important

  • hyperswap.utils.ts:2374-2383formatTokenAmount catches errors and returns 0. This violates the repo's no-fallback rule (CLAUDE.md). A silent zero will corrupt slippage / allowance / fee math downstream. Remove the try/catch.
  • schemas.ts:2486-2487AMM_POOL_ADDRESS_EXAMPLE is commented "WETH-USDC pool on Base"; CLMM_POOL_ADDRESS_EXAMPLE references BSC. BASE_TOKEN / QUOTE_TOKEN defaults are USDT/WBNB — tokens that don't exist in the HyperEVM token list. Swagger examples should reference real HyperEVM pools/tokens.
  • schemas.ts — ~200 LoC of HyperswapClmm* and HyperswapExecuteQuote* schemas are defined but never wired to a registered route. Drop them or scope the PR to include the routes.
  • hyperswap.config.ts:2042|| 4 fallback on maximumHops should be removed (the YAML template already provides the value; let a misconfiguration surface).
  • Multiple route filesrequire('@fastify/sensible') is re-registered per-route via CommonJS require() even though hyperswap.routes.ts already registers it at the wrapper level. Remove the duplicates.

🟢 Nits

  • hyperswap.utils.ts:findPoolAddress is exported but always returns null and never called — dead code.
  • hyperswap.ts:getV2Pool silently returns null on any error including RPC failures — should re-throw non-expected errors.
  • positionInfo.ts:972 hardcodes default: 'base' for network — should be 'hyperevm'.
  • 63 LoC of tests for ~2700 LoC is well below the project's 75% coverage target.

Verdict

Needs rework before merge. The router ABI + WETH addLiquidityETH path are blocking — neither swaps nor liquidity operations work as-is. The slippage hardcode and quoteToken silent fallback are also user-facing bugs. Happy to re-review once these are addressed.

@RYB-404

RYB-404 commented May 29, 2026

Copy link
Copy Markdown
Author

Thanks for the detailed review. I pushed an update addressing the requested changes:

  • Expanded hyperswap_v2_router_abi.json with the Router02 methods used by the AMM routes: swapExactTokensForTokens, swapTokensForExactTokens, addLiquidity, addLiquidityETH, removeLiquidity, and removeLiquidityETH.
  • Removed the native ETH liquidity paths from the HyperEVM AMM add/remove liquidity routes. WETH is now treated as an ERC20 token and the routes use addLiquidity / removeLiquidity with allowance checks for both tokens.
  • Wired remove-liquidity slippage to the request/config value instead of the previous hardcoded 0.5% tolerance.
  • Made quoteToken explicit for execute-swap: the schema now requires it and the handler returns a clear 400 if it is missing.
  • Removed the silent formatTokenAmount catch-and-return-0 behavior so formatting/parsing issues are not hidden.
  • Cleaned up the HyperSwap schemas so the examples are HyperEVM/WETH-USDC focused and removed unused CLMM/extra execute schemas that were not part of this AMM-only connector surface.
  • Removed duplicate per-route @fastify/sensible registrations and removed the local maximumHops || 4 fallback.

Validation run locally:

corepack pnpm run typecheck
corepack pnpm run build
corepack pnpm exec eslint src/connectors/hyperswap --format table
$env:GATEWAY_TEST_MODE='dev'; corepack pnpm exec jest --verbose --runInBand test/connectors/hyperswap/hyperswap.routes.test.ts

Results: typecheck passed, build passed, scoped ESLint had 0 errors, and the HyperSwap route test suite passed: 4/4 tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add HyperSwap (HypeEVM) connector

2 participants