SDK guide

One package covers reads, previews, transaction building and the indexer for both Dusk programs.

Updated Nov 9, 2026

@omnipair/dusk-sdk is the TypeScript client for Omnipair V2. It ships both program IDLs, typed account readers and previews, transaction builders for every instruction, operator and referral helpers, and an indexer client. It is strict ESM, targets Dusk market layout v14, and is MIT licensed.

Install and pin

npm install --save-exact @omnipair/dusk-sdk@2.21.0-next.20261109

The SDK is published to npm, and a version publishes only once every IDL it ships matches the program deployed on its cluster.

Devnet builds publish under the next tag, which always points at the newest deployed devnet build. Mainnet builds publish under latest, the tag a plain install reads. Until the first mainnet release, latest holds 2.0.2, a deprecated build for a program that no longer exists.

Pin an exact version in anything you ship; npm saves a caret range unless told otherwise. The IDL the package carries is the contract your transactions are encoded against: when the program is redeployed with a new IDL, a new SDK follows, and a mismatch shows up as account or discriminator errors.

The app pins the version, the npm tarball's hash and both IDL hashes in one frozen revision object, and builds no transaction until the deployment the API reports matches them. Do the same, and compare against Addresses.

Module map

ImportWhat it gives you
DuskThe client: new Dusk({ provider, indexerBaseUrl }) with write, get, fetch, operator, orders and the raw program
IDL, leverageDelegateIdl()The two Anchor IDLs, for error tables, event decoding and custom builders
PROGRAM_ID, DUSK_PROGRAM_IDThe Dusk program id
createDuskProgram, createLeverageDelegateProgramRaw Anchor Program instances
SEEDS, derive…AddressEvery PDA seed and a derivation helper for each account
deriveMarketParamsHash, defaultMarketLaunchConfig, lpMintLen, lpMintRentMarket creation
decodePreview…ReturnDataDecoders for every preview_* instruction's return data
feeParameterUpdate … trancheParameterUpdate, assertParameterUpdate, uploadProposalMetadata, tryFetchProposalDescriptionOperator parameter and metadata helpers
referralBindingInterestShareBps, quoteReferralInterestShareReferral math
ORDER_PROTOCOL_FEE_BPS, calculateOrderProtocolFee, orderProtocolFeeAccountsOrder fees
tokenProgramForMint, resolveTransferHookAccountMetas, buildLpTransferHook…Token-2022 plumbing
previewVirtualBook, decodeDuskVirtualBookBatchThe depth view
Subpaths ./idl, ./preview, ./indexerThe same pieces without the client

The client in three parts

import { Dusk } from "@omnipair/dusk-sdk"
 
const dusk = new Dusk({ provider, indexerBaseUrl })
 
dusk.write // typed builders per flow, plus any instruction by name
dusk.get // PDA helpers, account fetches, typed simulation previews
dusk.fetch // the indexer's REST routes
dusk.orders // typed builders for the leverage-delegate program
dusk.program // the raw Anchor Program<DuskIdl>

Most instructions have a typed builder, such as buildSwapTransaction, addLiquidityTransaction, buildBorrowTransaction or buildOpenLeverageTransaction: TypeScript checks every field, and the builder derives the accounts and adds the hLP account prefix wherever the program needs it. Composite helpers return an instruction with the setup it needs: yield accounts from depositSingleSided and withdrawSingleSided, the referral accrual from referredBorrow and referredOpenLeverage, and operator proposal PDAs from dusk.operator.

write.builder, write.instruction, write.transaction and write.rpc take any IDL instruction by name, with instruction arguments and account names checked against the IDL at compile time and before encoding. The writing transactions page walks through each; reading state and quotes covers get and fetch.

Accounts and seeds

Every account is a PDA. The seeds, from SEEDS:

AccountSeeds
Marketmarket_v2, base mint, quote mint, params hash
Reserve, collateral, interest vaultmarket_reserve / market_collateral / market_interest, market, mint
Leverage collateral vaultleverage_collateral, market, mint
Borrow positionborrow_position_v2, market, owner, position id
Leverage positionleverage_position_v2, market, position owner, namespace authority, position id
Leverage delegationleverage_delegation_v2, position
Yield accountyield, market, owner, LP mint, asset mint, kind
hLP srLP custodyhlp_ylp_vault, market, hLP mint
Futarchy authorityfutarchy_authority
Referral partner, accrualreferral_partner, authority; referral_accrual, partner, market, mint
Operator proposal, revenue archiveoperator_change, market, nonce (u64 LE); operator_revenue, market, revenue epoch (u64 LE)
Event authority__event_authority

The params hash for a market is sha256("dusk-<network>:<BASE-QUOTE label>:<base mint>:<quote mint>"), computed by deriveMarketParamsHash; the mints are never sorted.

Amounts and prices

All amounts are raw integer atoms as BN or bigint. Prices and price limits are quote per base in fixed nine-decimal NAD units.

Mints with the Token-2022 interest-bearing or scaled-UI-amount extensions display differently from atoms / 10^decimals; convert with the token program's AmountToUiAmount for display and keep raw integers everywhere else. A display multiplier never creates collateral or yield.

Testing

The SDK's scripts folder has operator, preview and virtual-book checks, all read-only. Preview a transaction with dusk.get before you send it.

Compatibility

  • Node 20 or later; strict ESM with .js specifiers.

  • Peer @coral-xyz/anchor 0.30 or later and @solana/web3.js 1.95 or later.

  • The legacy @omnipair/program-interface package targets the V1 program and shares nothing with this SDK.