Skip to content

Repository files navigation

@harbor/sdk

Thin TypeScript helpers for Harbor market integration. Quotes and prices are on-chain views (dry-runs / minter / aggregator). There is no Harbor REST API.

Install

npm install github:baofinance/harbor-sdk viem
# after npm publish (requires @harbor org + NPM_TOKEN):
# npm install @harbor/sdk viem

Quick start

import { 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");

Surface

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.

Publish

  1. Add repo secret NPM_TOKEN with publish rights to the @harbor npm org.
  2. Bump version in package.json.
  3. Create a GitHub Release or run the Publish npm workflow manually.

License

MIT

About

harbor-sdk

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages