Skip to main content
HedgeVault lets an app or script deposit into a vault and withdraw from it for its own wallet. It reads vaults from chain through your RPC connection and builds each transaction locally from the program’s interface. It needs no API key and never calls a Hedgin server. Like Meteora’s DLMM SDK, every action returns an unsigned Transaction. You sign and send it yourself, with a keypair or a wallet adapter. The SDK never holds a key.
HedgeVault is available from @hedginxyz/sdk 0.5.0.

Install

@coral-xyz/anchor provides BN, the integer type for amounts.

Deposit and withdraw

In a browser, send the same transaction with your wallet adapter:

How a request settles

A deposit or withdrawal is a request, not an instant swap. It waits for the next valuation, which happens every 4 hours, and then settles at that NAV (net asset value per share). See Vaults and NAV.
1

Request

deposit moves your tokens into the vault’s holding account. withdraw moves your shares there. Nothing is invested or paid out yet.
2

Wait for the valuation

getPositionByUser shows the request as pending. You can cancel it with cancelDeposit or cancelWithdrawal while it is pending.
3

Settlement

After the valuation, Hedgin’s keeper settles every resolvable request on its own. A deposit becomes shares in your wallet. A withdrawal pays out the deposit token, or native SOL for a SOL vault. You do not send anything for this step.
A private vault also needs the manager to approve each request before it settles. Until then, awaitingApproval is true and the request stays cancellable.

Reads

getPositionByUser returns: Each open request has a state: Each request also has cancellable, awaitingApproval, epoch, and createdTs (Unix seconds).

Actions

Each action takes one object with user, the wallet that signs and pays, and returns a Promise<Transaction>. Amounts are BN in base units, the token’s smallest unit. For 5 USDC, which has 6 decimals, pass new BN(5_000_000). Shares use the same number of decimals as the deposit token.

Options

getAll and create take the same options:

Errors

Every transaction is simulated before it is returned, so a request the program would refuse throws instead of failing on chain. The ApiError carries the program’s error name in code. Program error names for other cases, such as a paused vault or a full deposit cap, come through the same way.

What the SDK checks before it returns a transaction

A deposit moves your own funds, so the SDK refuses to return a transaction unless it does exactly what you asked. A refusal throws UnsafeTransactionError. The transaction must meet every rule:
  • user is the only signer and pays the fee.
  • It contains exactly one Hedgin vault instruction, of the kind you called, for this vault, your wallet, and your exact amount.
  • The priority fee is at or under maxPriorityFeeLamports.
  • It uses no address lookup tables, so every account it touches is visible to the check.
  • The only other instructions allowed are for a SOL deposit: create your own wrapped SOL account, move at most amount lamports into it, and sync it.
The compute unit limit is set from the simulation, plus 20% headroom. The transaction carries recentBlockhash and lastValidBlockHeight, so send it promptly. For the manager client, see Getting started.