feat(sdk): swap() end-to-end for usdc to usdh#10
Merged
Conversation
Wire createUsdhKit to InfoClient + signing + ExchangeClient. Reads the L2 orderbook, computes a slippage-tolerant aggressive limit price (mid * (1 + slippageBps/10000)), builds a Market IOC order action, signs via the configured signer, submits to /exchange, parses the fill, and returns a SwapResult with realised slippage in bps. The slippage check is pre-fill (HL rejects bad prices itself) and the realised value is reported on the result without throwing after settlement. NetworkError wraps transport and per-order errors. NotImplementedError for USDT until the double-hop lands. SwapResult.txHash removed (HL L1 actions have no Ethereum tx hash); orderId is the canonical identifier. ResolvedPair exposes assetIndex, baseSzDecimals, and quoteWeiDecimals so price and size strings respect actual pair precision. Nonces are emitted monotonically across concurrent calls. Tests: 7 swap + others, 121 total in the package.
sumfxn
pushed a commit
that referenced
this pull request
Apr 28, 2026
6 tasks
sumfxn
added a commit
that referenced
this pull request
Apr 28, 2026
) The post-fill slippage check was removed in PR #10 because Hyperliquid's matcher enforces the limit price pre-fill, but the SlippageExceededError class kept being exported and the README example told users to instanceof it. Removing both means the public API stops promising a code path that cannot run; consumers read result.slippageBps instead. useUsdhKit was rebuilding the kit on every render, throwing away the monotonic-nonce closure, the pair-resolver cache, and any in-flight spotMeta request. Wrapping in useMemo keyed on the wagmi inputs gives consumers a stable kit identity across renders and stops needless network chatter on quote-heavy screens. assertBookHasSides was unreachable: midPrice18 already throws NetworkError with the same message format on the same book reference. Added a defensive non-zero pair-index test in pair-resolver.test.ts to lock the contract that pair.index is the SpotPair API field, not the array position (mainnet has USDH/USDC at index 230).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
swap()end-to-end forUSDC -> USDH. The SDK is now feature-complete for V1.Files
packages/sdk/src/kit.ts— full swap impl (~150 LOC)packages/sdk/src/pricing.ts—formatDecimalaccepts optionalmaxFracDigitspackages/sdk/src/pair-resolver.ts—ResolvedPairaddsbaseSzDecimals+quoteWeiDecimalspackages/sdk/src/types/swap.ts—SwapResult.txHashremoved (HL has no tx hash for L1 actions)Behaviour
mid * (1 + slippageBps/10000)orderaction at the limit, with size in USDH base unitssignL1Action, posts via/exchangeSwapResultwithorderId,received,spent,price, realisedslippageBpsNotImplementedErroruntil the double-hop landsswap()callsTests (121 total)
pnpm lintcleanpnpm typecheckcleanpnpm buildESM 24KB + CJS + dtsFollow-ups (post-V1)
signing.test.ts(see PR feat(sdk): hl signing layer (phantom agent + eip-712) #8 audit note)