Thin TypeScript helpers for Harbor market integration. Quotes and prices are on-chain views (dry-runs / minter / aggregator). There is no Harbor REST API.
npm install github:baofinance/harbor-sdk viem
# after npm publish (requires @harbor org + NPM_TOKEN):
# npm install @harbor/sdk viemimport { createPublicClient, http } from "viem";
import { mainnet } from "viem/chains";
import { createHarborClient } from "@harbor/sdk";
const publicClient = createPublicClient({
chain: mainnet,
transport: http(),
});
const harbor = createHarborClient({ publicClient, chainId: 1 });
const quote = await harbor.quoteMint("eth-fxusd", {
side: "pegged",
wrappedCollateralIn: 10n ** 18n,
});
const mint = harbor.encodeTx.mintPeggedToken({
marketId: "eth-fxusd",
wrappedCollateralIn: 10n ** 18n,
receiver: "0x…",
minPeggedOut: quote.minOut,
});
// Optional convenience zaps (market must list genesisZap / peggedTokenZap)
const zap = harbor.encodeZap.minterCollateralToToken({
marketId: "eth-fxusd",
side: "pegged",
receiver: "0x…",
collateralAmount: 10n ** 6n,
minWrappedCollateralOut: 0n,
minTokenOut: quote.minOut,
});
// Harbor Swap (Yield/keeper) — pass swapper once deployed
const withSwap = createHarborClient({
publicClient,
chainId: 1,
swapper: "0x…", // Swapper_v1 CREATE3
});
const route = await withSwap.swap!.getRoute("0xFrom", "0xTo");| Method | On-chain |
|---|---|
getAddresses / getMarket |
Address JSON (mainnet-v1) |
getPrice |
peggedTokenPrice / leveragedTokenPrice + aggregator latestAnswer |
getMarketState |
collateralRatio, leverageRatio, config |
quoteMint / quoteRedeem |
*DryRun |
encodeTx |
mint* / redeem* + ERC-20 approve |
encodeZap |
Genesis / minter zap helpers |
swap.getRoute / encodeSwap |
Swapper_v1 + executor (optional swapper option) |
Docs: harbor-docs → Integrators → SDK.
- Add repo secret
NPM_TOKENwith publish rights to the@harbornpm org. - Bump
versioninpackage.json. - Create a GitHub Release or run the Publish npm workflow manually.
MIT