HertzFlow SDK
TypeScript SDK for integrating with the HertzFlow protocol.
The HertzFlow SDK is a TypeScript SDK for reading HertzFlow markets, positions, and orders and submitting transactions from viem-based applications.
Requirements
Node.js 18 or later
A BNB Smart Chain RPC endpoint
A HertzFlow oracle URL
A
viemwallet client for write transactions
Installation
Install the SDK and viem in your application:
npm install @hertzflow/sdk-v2 viemyarn add @hertzflow/sdk-v2 viempnpm add @hertzflow/sdk-v2 viemQuick Start
import { HertzFlowSDK } from "@hertzflow/sdk-v2";
const sdk = new HertzFlowSDK({
chainId: 56,
rpcUrl: "https://bsc-rpc.publicnode.com",
oracleUrl: "https://oracle-aggregator.mainnet.htzfl.link/api",
});
const markets = await sdk.markets.getMarkets();
const { tokensData } = await sdk.tokens.getTokensData();
const { pricesData } = await sdk.tokens.getTokenRecentPrices();
const marketsData = Object.fromEntries(
markets.map((market) => [market.marketTokenAddress, market])
);
sdk.setAccount("0xYourAccount");
const { positionsData } = await sdk.positions.getPositions({
prices: pricesData ?? {},
marketsData,
tokensData: tokensData ?? {},
});Read methods use the SDK's public client. To submit a transaction, also provide a wallet client in the constructor or call sdk.setWalletClient().
Configuration
BNB Smart Chain Testnet
97
HertzFlow protocol modules
BNB Smart Chain
56
HertzFlow protocol modules
debugMode defaults to enabled. Set it to false to disable internal SDK console logging.
Custom viem clients
Keep account in the SDK configuration in sync with the wallet client. Supplying a wallet client does not set the SDK account automatically.
API Reference
Markets
sdk.markets.getMarkets(offset?, limit?)
Read the market list from the contracts
sdk.markets.getMarketsConfigs(markets)
Read market configuration values
sdk.markets.getMarketsValues(params)
Read current pool, open interest, funding, and borrowing values
sdk.markets.mergeMarketsInfo(params)
Combine markets, tokens, configs, and values into enriched market data
Tokens and prices
sdk.tokens.getTokensData()
Load built-in token metadata and merge configured static overrides or async metadata for newly listed tokens
sdk.tokens.getTokenRecentPrices()
Fetch the latest oracle prices
sdk.tokens.getTokensBalances(account?, tokensList?)
Read native and ERC-20 balances
sdk.tokens.getTokenMetadata(tokenAddresses)
Read ERC-20 name, symbol, and decimals on-chain
sdk.tokens.getNativeToken()
Return the configured native token
sdk.oracle.getLatestPrices()
Fetch raw latest-price records
Positions and orders
sdk.positions.getPositions(params)
Read an account's open positions
sdk.positions.getPositionsConstants()
Read position and collateral limits
sdk.orders.getOrders(params)
Read and filter an account's orders
sdk.orders.createIncreaseOrder(params)
Create a market or limit increase order, optionally with SL/TP changes
sdk.orders.createDecreaseOrder(params[])
Create one or more decrease orders
sdk.orders.updateOrder(params)
Update an existing order
sdk.orders.cancelOrders(orderKeys)
Cancel one or more orders
sdk.orders.depositPositionCollateral(params)
Add collateral to a position
sdk.orders.withdrawPositionCollateral(params)
Remove collateral from a position
Amounts are integer bigint values in their documented token or USD precision. Slippage arguments differ by method: createIncreaseOrder() and createDecreaseOrder() receive basis points, while the collateral deposit and withdrawal helpers receive a decimal ratio and convert it internally.
Swap + increase orders
For an internal USD collateral order such as HFUSD, the SDK can swap the user's payment token through Peach and use the output to mint the internal USD token before creating the increase order. This integration is available on BNB Smart Chain mainnet (56) only. Complete a small-value mainnet validation in the application before enabling it in production.
The full flow runs in one ExchangeRouter.multicall:
internalUsd must identify the HFBank, wrapped token (for example HFUSD), and its underlying token (for example USDT). Get an order-specific quote and pass it to createIncreaseOrder():
getOrderQuote() returns an ERC-20-compatible quote for the order handler. If the user pays with native BNB, it re-quotes the input as WBNB so the order can send WBNB to ExternalHandler; do not pass a standalone native swapETH quote to an order. The swap, mint, and order are atomic: if any step reverts, the entire multicall reverts.
For limit increase orders, the Peach swap and internal USD mint happen when the order is submitted; they are not deferred until the limit price is triggered.
Before submission, request a fresh quote and ensure its input token and amount match the order, its output token matches internalUsd.underlyingTokenAddress, its router is trusted, its transaction value is 0, and its deadline has not expired. The user approves the HertzFlow Synthetics Router; the Peach approval is executed inside the order's external call.
Liquidity
sdk.liquidity.getOrders(params?)
Read pending HzLP and HzV deposit and withdrawal orders
sdk.liquidity.cancelOrder(order)
Cancel one pending liquidity order
sdk.liquidity.cancelOrders(orders)
Cancel multiple pending liquidity orders in one router call; all orders must use the same scope
sdk.liquidity.createDeposit(params)
Deposit long and short tokens into an HzLP market
sdk.liquidity.createWithdrawal(params)
Redeem HzLP market tokens
sdk.liquidity.createHlvDeposit(params)
Deposit into an HzV vault, with optional per-market allocations
sdk.liquidity.createHlvWithdrawal(params)
Withdraw from an HzV vault, with optional per-market allocations
sdk.allowance.approveTokenForLiquidityRouter(token, amount?)
Compatibility alias that approves the Synthetics Router
The liquidity order reader can filter by account, market address, scope (market or hlv), and limit. The liquidity transaction helpers return a transaction hash. The SDK can retry a deposit or withdrawal with the execution fee required by the contract simulation when the supplied fee is too low.
Allowances
sdk.allowance.getTokenAllowance(token, spender)
Read an ERC-20 allowance
sdk.allowance.approveToken(token, spender, amount?)
Approve an ERC-20 spender; the default amount is maxUint256
sdk.allowance.getTokenAllowanceForSyntheticsRouter(token)
Read allowance for the Synthetics Router
sdk.allowance.approveTokenForSyntheticsRouter(token, amount?)
Approve the Synthetics Router
sdk.allowance.getTokenAllowanceForLiquidityRouter(token)
Compatibility alias that reads the Synthetics Router allowance
Gas and execution fees
sdk.utils.getGasLimits()
Read protocol gas-limit configuration
sdk.utils.getGasPrice()
Read and buffer the current gas price
sdk.utils.getEstimatedGasFee(type, params, gasLimits?)
Estimate gas for a protocol action
sdk.utils.getExecutionFee(type, tokensData, nativePrice, params, gasLimits?, gasPrice?)
Calculate the execution fee
sdk.utils.getUiFeeFactor()
Read the configured UI fee factor
Runtime Management
Use setAccount() when the active wallet changes. Use setWalletClient() or setPublicClient() to replace the clients at runtime.
Last updated

