Exchange endpoints: createVault, setReferrer - #156
Merged
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #156 +/- ##
==========================================
+ Coverage 70.17% 70.28% +0.10%
==========================================
Files 54 54
Lines 8782 8898 +116
Branches 534 539 +5
==========================================
+ Hits 6163 6254 +91
- Misses 2616 2639 +23
- Partials 3 5 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Adds two missing /exchange actions following the CONTRIBUTING.md pattern:
- createVault: creates a new vault. L1 action whose action carries its own
"nonce" field equal to the envelope nonce (like agentSendAsset), and
returns the new vault's address on success. Does not take a vaultAddress
parameter (it creates a vault rather than acting through an existing one).
- setReferrer: sets a referral code for the calling wallet. Plain L1 action,
no vaultAddress support, reuses SimpleResponse/parseSimpleResponse like
vaultTransfer/borrowLend.
Request/response shapes are cross-checked against the official TS SDK
(@nktkas/hyperliquid, src/api/exchange/_methods/{createVault,setReferrer}.ts)
since neither action is documented on the public gitbook docs page. Not
verified live against testnet in this environment (no funded testnet
wallet available) - please double-check before relying on this.
Wires up RestApi (sync + async) and WebsocketApi for both, adds
request-builder and response-parser tests to tests/rest_vaults_test.cpp
(the file already covering the related vaultDetails/vaultTransfer/referral
endpoints), adds wallet-required smoke tests to
tests/websocket_api_exchange_test.cpp, adds examples/rest_create_vault.cpp
and examples/rest_set_referrer.cpp, and updates README's exchange actions
coverage table (36 -> 38 of 68 implemented).
Closes #122
Closes #125
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Le73N2EZjGLsCqmCScAse
TuxedoFish
force-pushed
the
endpoint/create-vault-set-referrer
branch
from
September 8, 2026 15:23
fe178b0 to
3f70ab9
Compare
TuxedoFish
commented
Sep 8, 2026
| SimpleResponse approveBuilderFee(const ApproveBuilderFeeRequest& request); | ||
| SimpleResponse userSetAbstraction(const UserSetAbstractionRequest& request); | ||
| // setReferrer sets a referral code for the calling wallet itself, so like the transfer-style | ||
| // actions above it does not take a vaultAddress parameter. |
TuxedoFish
commented
Sep 8, 2026
| { | ||
| std::string status; | ||
| std::string type; | ||
| // The newly created vault's address (response.data on success). |
TuxedoFish
commented
Sep 8, 2026
| // createVault is the one L1 action (besides agentSendAsset) whose action carries its own | ||
| // "nonce" field, required to equal the envelope nonce - injected downstream by | ||
| // Signing::prepareBody, not here (see the RestEndpointType::CreateVault special-case | ||
| // next to AgentSendAsset's). |
Owner
Author
There was a problem hiding this comment.
Please remove - add to docs in future
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.
Summary
createVault(closes Implement createVault #122) andsetReferrer(closes Implement setReferrer #125), the two remaining/exchangeactions from the "outstanding endpoints" triage.createVaultcompletes the vault feature set that already hasvaultDetails/vaultTransferbut no way to actually create one. It's an L1 action whose response returns the newly-created vault's address (response.data).setReferrerpairs with the existingreferralread endpoint. Plain L1 action,{status, response:{type:"default"}}on success - reusesSimpleResponse/parseSimpleResponseexactly likevaultTransfer/borrowLend.Request/response shape verification
Neither
createVaultnorsetReferreris documented on the public Hyperliquid gitbook docs page (checked directly - only the more common actions are covered there). I cross-checked the exact field names/types against the official@nktkas/hyperliquidTypeScript SDK's source, which is more authoritative than the docs page for these two:src/api/exchange/_methods/createVault.ts: action ={type: "createVault", name, description, initialUsd, nonce}whereinitialUsdisfloat * 1e6(min 100 USD) and the action's ownnoncefield is required to equal the envelope nonce (same pattern this codebase already has foragentSendAsset). Response:{status:"ok", response:{type:"createVault", data: "0x..."}}(vault address) on success.src/api/exchange/_methods/setReferrer.ts: action ={type: "setReferrer", code}. Response:{status:"ok", response:{type:"default"}}.Signing: L1 Action.doc comment on each).vaultAddressrule: neither request schema in the TS SDK includes an envelope-levelvaultAddressfield (unlike e.g.order.ts, which explicitly hasvaultAddress: v.optional(Address)), so neither gets avaultAddressparameter onRestApi/WebsocketApi, per CONTRIBUTING.md's rule and consistent with how this codebase already treatsvaultTransfer/hip3LiquidatorTransfer(own request fields already name the target).I was not able to verify these live against testnet in this environment - there's no funded testnet wallet configured (
examples/test.jsonis gitignored and wasn't present in this sandbox). The two new examples (examples/rest_create_vault.cpp,examples/rest_set_referrer.cpp) are written and compile, but haven't been run against the real endpoint. Please double-check the response shape (especiallycreateVault'sdatafield being a bare string vs. some other nesting) against a real payload before relying on this, per CONTRIBUTING.md's guidance on unverified field shapes.What's implemented
include/hyperliquid/types/RequestTypes.h:RestEndpointType::CreateVault/SetReferrer(+toString/isAuthenticated),CreateVaultRequest/SetReferrerRequeststructs.include/hyperliquid/types/ResponseTypes.h:CreateVaultResponse(setReferrer reusesSimpleResponse).src/messages/ExchangeRequestBuilder.h/.cpp:createVault/setReferrerbuilders.include/hyperliquid/rest/RestApiMessageParser.h/.cpp:parseCreateVault, dispatch wiring (SetReferrerfolded into the existingonSimpleResponsecase group).include/hyperliquid/rest/RestEndpointListener.h:onCreateVaultcallback.include/hyperliquid/rest/RestApi.h/.cpp:createVault/setReferrer(sync) +createVaultAsync/setReferrerAsync.include/hyperliquid/websocket/WebsocketApi.h/.cpp:createVault/setReferrerwrappingsignAndSendgenerically, per CONTRIBUTING.md's explicit reminder not to skip this step.src/signing/Signing.cpp: addedRestEndpointType::CreateVaultto the existing embedded-noncespecial case alongsideAgentSendAsset.tests/rest_vaults_test.cpp(request-builder + response-parser, including field-order and USD-scaling checks) andtests/websocket_api_exchange_test.cpp(wallet-required smoke tests).examples/rest_create_vault.cpp,examples/rest_set_referrer.cpp.⬜→✅, count updated 36 → 38 of 68.Test plan
cmake -S . -B build -DHYPERLIQUID_WARNINGS_AS_ERRORS=ON -DHYPERLIQUID_BUILD_TESTS=ON -DHYPERLIQUID_BUILD_EXAMPLES=ON -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake"- clean configurecmake --build build -j"$(nproc)"- zero warnings/errors on a full clean rebuildctest --test-dir build- 100% pass (28/28 test binaries, including the new builder/parser/smoke tests)Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com
https://claude.ai/code/session_018Le73N2EZjGLsCqmCScAse