Skip to content

Exchange endpoints: createVault, setReferrer - #156

Merged
TuxedoFish merged 2 commits into
mainfrom
endpoint/create-vault-set-referrer
Sep 8, 2026
Merged

Exchange endpoints: createVault, setReferrer#156
TuxedoFish merged 2 commits into
mainfrom
endpoint/create-vault-set-referrer

Conversation

@TuxedoFish

Copy link
Copy Markdown
Owner

Summary

  • Implements createVault (closes Implement createVault #122) and setReferrer (closes Implement setReferrer #125), the two remaining /exchange actions from the "outstanding endpoints" triage.
  • createVault completes the vault feature set that already has vaultDetails/vaultTransfer but no way to actually create one. It's an L1 action whose response returns the newly-created vault's address (response.data).
  • setReferrer pairs with the existing referral read endpoint. Plain L1 action, {status, response:{type:"default"}} on success - reuses SimpleResponse/parseSimpleResponse exactly like vaultTransfer/borrowLend.

Request/response shape verification

Neither createVault nor setReferrer is 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/hyperliquid TypeScript 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} where initialUsd is float * 1e6 (min 100 USD) and the action's own nonce field is required to equal the envelope nonce (same pattern this codebase already has for agentSendAsset). 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"}}.
  • Both are plain L1 actions, not EIP-712 user-signed actions (confirmed by the TS SDK's Signing: L1 Action. doc comment on each).
  • vaultAddress rule: neither request schema in the TS SDK includes an envelope-level vaultAddress field (unlike e.g. order.ts, which explicitly has vaultAddress: v.optional(Address)), so neither gets a vaultAddress parameter on RestApi/WebsocketApi, per CONTRIBUTING.md's rule and consistent with how this codebase already treats vaultTransfer/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.json is 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 (especially createVault's data field 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/SetReferrerRequest structs.
  • include/hyperliquid/types/ResponseTypes.h: CreateVaultResponse (setReferrer reuses SimpleResponse).
  • src/messages/ExchangeRequestBuilder.h/.cpp: createVault/setReferrer builders.
  • include/hyperliquid/rest/RestApiMessageParser.h/.cpp: parseCreateVault, dispatch wiring (SetReferrer folded into the existing onSimpleResponse case group).
  • include/hyperliquid/rest/RestEndpointListener.h: onCreateVault callback.
  • include/hyperliquid/rest/RestApi.h/.cpp: createVault/setReferrer (sync) + createVaultAsync/setReferrerAsync.
  • include/hyperliquid/websocket/WebsocketApi.h/.cpp: createVault/setReferrer wrapping signAndSend generically, per CONTRIBUTING.md's explicit reminder not to skip this step.
  • src/signing/Signing.cpp: added RestEndpointType::CreateVault to the existing embedded-nonce special case alongside AgentSendAsset.
  • Tests in tests/rest_vaults_test.cpp (request-builder + response-parser, including field-order and USD-scaling checks) and tests/websocket_api_exchange_test.cpp (wallet-required smoke tests).
  • examples/rest_create_vault.cpp, examples/rest_set_referrer.cpp.
  • README's exchange actions coverage table: both flipped , 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 configure
  • cmake --build build -j"$(nproc)" - zero warnings/errors on a full clean rebuild
  • ctest --test-dir build - 100% pass (28/28 test binaries, including the new builder/parser/smoke tests)
  • Live testnet verification (not done here - see note above)

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com

https://claude.ai/code/session_018Le73N2EZjGLsCqmCScAse

@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.63248% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.28%. Comparing base (9869c9e) to head (84beec6).

Files with missing lines Patch % Lines
src/rest/RestApi.cpp 0.00% 14 Missing ⚠️
src/rest/RestApiMessageParser.cpp 80.00% 5 Missing ⚠️
src/websocket/WebsocketApi.cpp 75.00% 2 Missing ⚠️
tests/rest_vaults_test.cpp 95.12% 0 Missing and 2 partials ⚠️
include/hyperliquid/rest/RestEndpointListener.h 0.00% 1 Missing ⚠️
src/signing/Signing.cpp 50.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions Bot added the ready for review CI passed; ready to be reviewed label Sep 8, 2026
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
TuxedoFish force-pushed the endpoint/create-vault-set-referrer branch from fe178b0 to 3f70ab9 Compare September 8, 2026 15:23
Comment thread include/hyperliquid/rest/RestApi.h Outdated
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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Leave this out

{
std::string status;
std::string type;
// The newly created vault's address (response.data on success).

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

remove

Comment thread src/messages/ExchangeRequestBuilder.cpp Outdated
// 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).

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Please remove - add to docs in future

@TuxedoFish
TuxedoFish merged commit cc645fd into main Sep 8, 2026
12 checks passed
@TuxedoFish
TuxedoFish deleted the endpoint/create-vault-set-referrer branch September 8, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review CI passed; ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement setReferrer Implement createVault

1 participant