Add HyperSwap AMM connector for HyperEVM#641
Conversation
fengtality
left a comment
There was a problem hiding this comment.
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 IHyperswapV2Router02ABI — swapExactTokensForTokens, 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-218 — addLiquidityETH 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:758 — quoteToken || '' 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-2383—formatTokenAmountcatches errors and returns0. 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-2487—AMM_POOL_ADDRESS_EXAMPLEis commented "WETH-USDC pool on Base";CLMM_POOL_ADDRESS_EXAMPLEreferences BSC.BASE_TOKEN/QUOTE_TOKENdefaults areUSDT/WBNB— tokens that don't exist in the HyperEVM token list. Swagger examples should reference real HyperEVM pools/tokens.schemas.ts— ~200 LoC ofHyperswapClmm*andHyperswapExecuteQuote*schemas are defined but never wired to a registered route. Drop them or scope the PR to include the routes.hyperswap.config.ts:2042—|| 4fallback onmaximumHopsshould be removed (the YAML template already provides the value; let a misconfiguration surface).- Multiple route files —
require('@fastify/sensible')is re-registered per-route via CommonJSrequire()even thoughhyperswap.routes.tsalready registers it at the wrapper level. Remove the duplicates.
🟢 Nits
hyperswap.utils.ts:findPoolAddressis exported but always returnsnulland never called — dead code.hyperswap.ts:getV2Poolsilently returnsnullon any error including RPC failures — should re-throw non-expected errors.positionInfo.ts:972hardcodesdefault: 'base'fornetwork— 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.
|
Thanks for the detailed review. I pushed an update addressing the requested changes:
Validation run locally: Results: typecheck passed, build passed, scoped ESLint had 0 errors, and the HyperSwap route test suite passed: 4/4 tests. |
Summary
/connectors/hyperswap/ammin Gateway and advertises it from/config/connectors.Testing
corepack pnpm exec jest --runInBand test/connectors/hyperswap/hyperswap.routes.test.tscorepack pnpm run buildcorepack pnpm exec eslint "src/connectors/hyperswap/**/*.ts" "test/connectors/hyperswap/**/*.ts" --format table(0 errors; existing default-import/no-unused warnings only)Closes #503