Skip to main content
This page lists the public API of @hedginxyz/sdk, based on the SDK’s source. For worked recipes, see Examples. For request and response fields of each API route, see the API reference.

Dependencies

Node 18 or later. The package is CommonJS.

Program IDs

Constants

Core types

Outcome

What execute and onboardPhoenix return. Every kind carries signatures, the signatures of every transaction sent so far.

Progress and ExecuteOptions

sleep and now exist for tests with a fixed clock. Leave them unset in production.

TransactionSigner

Anything that can sign as the manager wallet: a local keypair, a hardware wallet, or a KMS. It must add its signature and keep the signatures the builder already added.

Creating a client

createHedgeClient

Returns a HedgeClient bound to one API key. The client sends the key as a bearer token on every request. Reads time out after 10 seconds. Builders time out after 30 seconds, because they simulate on chain and can call Jupiter.

Vault reads

Every read needs the read scope. Each method parses the response against the SDK’s schemas and returns its data. A response that does not match throws ApiError with the code contract_mismatch. The SDK never returns a half-parsed object. vault is a vault address string in every signature.

listVaults

The vaults this key manages, from GET /vaults. Each VaultSummary has address, name, status, depositMint, depositSymbol, depositDecimals, and totalAssets, so you can format amounts without another request. Newer servers also send approvalRequired, parent (the parent vault of a child vault, else null), and childCount. Child vaults are not in this list.

getVault

The on-chain vault state, from GET /vaults/{vault}: fees, limits, pending requests, pause flags, and the NAV epoch. navPerShare is scaled by 1e9. protocol.maxSlippageBps is the protocol-wide slippage cap. shareSymbol is the share token’s symbol, null until its metadata exists.

getHoldings

Token balances and their value, from GET /vaults/{vault}/holdings. depositToken describes the deposit mint. When some token has no price, partial is true and unpriced lists the mints.

getStrategies

Open strategies, from GET /vaults/{vault}/strategies. Strategy is a union keyed by type: On a dlmm strategy, lowerBinId and upperBinId are inclusive. They and bins are optional because older servers omit them. The SDK lists a strategy type it does not know as unreadable.

getNavHistory

Posted NAVs, oldest first, from GET /vaults/{vault}/nav. The API returns the latest 200 by default. A point with overridden: true was set by an admin, not by the keeper. Throws ApiError with the code HistoryUnavailable when the deployment has no history database.

getRequests

Queued deposits and withdrawals, from GET /vaults/{vault}/requests. A request is pending until a later NAV epoch is posted, then resolvable. It is frozen when a newer epoch starts before that NAV lands: neither claimable nor cancellable until the NAV is posted. On a vault with approvalRequired, awaitingApproval is true until the manager approves the request’s current amount. It cannot settle until then and stays cancellable. Deposit amount is in deposit-mint base units. Withdrawal shares is in share base units.

getStrategyHistory

Closed strategies with their per-mint cash flows, newest first, from GET /vaults/{vault}/strategy-history. realizedPnl is a signed base-unit string equal to returned + feesRetained - contributed. A strategy with exact: false predates exact accounting. Throws HistoryUnavailable like getNavHistory.

getPhoenix

Phoenix setup and trading state, from GET /vaults/{vault}/phoenix. status is none (no strategy), registered (strategy exists, trader not onboarded), or ready. usdcVault is false when the deposit mint is not USDC. openOrders, withdrawable, and account are null when Phoenix’s API is down, and account is also null before onboarding.

Market reads

These reads take vault too, because the API scopes every request to a vault the key manages.

getQuote

A Jupiter quote, from GET /jupiter/quote. Returns inAmount, outAmount, priceImpactPct, routeLabels, and slippageBps. One side of the swap must be the vault’s deposit mint.

getToken

Any mint’s symbol, decimals, name, priceUsd, and Jupiter verified flag, from GET /tokens/{mint}. verified is null when unknown. Warn before a swap that involves an unverified token.

searchPools

Meteora DLMM pools that match query, such as a symbol, from GET /dlmm/pools. page defaults to 1. Returns total, page, pages, and pools, each with address, name, tokenX, tokenY, binStep, and display-only tvl, volume24h, fees24h, and baseFeePct.

getPool

One pool, from GET /dlmm/pools/{lbPair}: tokenX, tokenY, binStep, activeBinId, and activePrice (token Y per token X, as a string). Use it to choose a DLMM range.

Execution

execute

Runs one action to a terminal Outcome. It builds on the server, inspects every transaction against the signing policy, signs locally, sends, and polls until every transaction confirms, one fails, or 120 seconds pass. It follows batches and next continuations, and stops with TooManySteps after 12 builds. It never rebuilds after an ambiguous send. It throws only for a network error while building, before anything is signed, and for an error from your signer. See What execute throws.

onboardPhoenix

Registers the vault’s Phoenix trader after phoenix/initialize. Phoenix co-signs on submit, so this path checks the transaction against a separate, narrower onboarding policy, signs it as fee payer, and submits it to Phoenix. It never resubmits. Needs the send and phoenix/onboard scopes.

build, send, and status

The low-level calls execute is made of. build does not inspect or sign. Prefer execute. If you call build yourself, run inspectTransaction on every step before you sign.

Actions

ActionRequest is a union keyed by action. The other fields are that builder’s body, and TypeScript checks them per action. payer is never part of a body, because the API sets it from the key.

Jupiter

Meteora DLMM

shape is "spot", "curve", or "bidAsk". maxActiveBinSlippage is how many bins the active price may move between build and landing before the transaction fails. amountX and amountY are base units of the pool’s token X and token Y.

Phoenix perpetuals

phoenix/order fields:

Vault administration

name is at most 32 UTF-8 bytes. Fees are basis points from 0 to 10000. depositCap and minDeposit are deposit-mint base units. minWithdrawalShares is share base units. status is a VaultStatus. With approvalRequired, deposits and withdrawals wait for the manager to approve each one.

Request approval

On a vault with approvalRequired, the vault authority approves or rejects each queued request. Read the queue with getRequests first. All four need the vault authority’s key.

Child vaults

A child vault belongs to a vault that takes deposits. It has the same authority and deposit mint and no depositors of its own. Use it to hold part of the capital apart, for example for one strategy. mint defaults to the deposit mint. Another mint must be tracked by the sending vault. The receiving vault’s Jupiter strategy is created first when it is missing.

Continuations

Some builds return a step with next. execute follows it after the current batch confirms. You never request these yourself, but your key needs their scopes.

Key scopes

Each API key lists the actions it may run. The API rejects a request when the key lacks a needed scope. The SDK cannot check scopes before it builds, so a missing scope shows up as a failed outcome with the API’s error code. So dlmm/zap-out needs dlmm/zap-out, dlmm/zap-out/swap, and jupiter/sweep, and a wide dlmm/open also needs dlmm/extend.

Signing

keypairSigner

Wraps a Keypair as a TransactionSigner.

keypairFromFile

Reads a Solana CLI keypair file, a JSON array of 64 bytes. Its errors never include the file contents.

inspectTransaction

Checks one unsigned base64 transaction against the signing policy and returns it decoded. Throws UnsafeTransactionError when it is not v0, is not paid by manager, lacks a required co-signature, calls a program outside the allowed set at the top level, or sets a priority fee above the cap. A priced transaction with no compute unit limit is read at the 1.4M CU maximum, so a missing limit cannot hide a fee.

inspectPhoenixOnboardTransaction

The narrower check onboardPhoenix uses. The transaction must be v0, paid by manager, non-empty, and call only PHOENIX_PROGRAM_ID at the top level. ComputeBudget is refused, so no priority fee can be set.

DLMM helpers

Pure functions. They never touch the network. A pool argument needs activeBinId, activePrice, and binStep, so a PoolInfo from getPool fits. Prices are token Y per token X.

binRangeForPrices

The smallest bin range that covers a price range. sides says which tokens the range can take: X at and above the active bin, Y at and below it. Throws when a price is not positive, minPrice is not below maxPrice, or the range needs more than 1,400 bins.

binPrice

The price of one bin.

flipSide

The non-deposit token a dlmm/flip sells: X, unless X is the deposit mint.

flipRange

The part of an inclusive selection that holds only one side’s token: bins strictly above the active bin for X, strictly below it for Y. Returns null when no bin qualifies.

Unit helpers

parseUnits

Converts a display amount such as "1.5" or "1,000" to a base-unit string. Throws when the text is not a number or has more fractional digits than the token, instead of rounding.

formatUnits

Converts a base-unit string to a display amount with trailing zeros removed. Neither helper goes through number.

Errors

Reads throw ApiError. Inside execute, an ApiError becomes a failed outcome and an UnsafeTransactionError becomes a refused outcome. The SDK adds two codes of its own: Other codes come from the API. See Errors and limits.

Other exports

These exist for tests and custom transports. Most integrations do not need them.