Skip to main content

TypeScript SDK (@opshuns/sdk)

The Opshuns TypeScript SDK lives in the sibling sdk repo (../sdk from this web monorepo). Package: @opshuns/sdk (packages/typescript).

Use it for:

  • HTTP + Phoenix Channels against the Opshuns API
  • EIP-712 signing for options RFQ, FixedPackage, Dutch, and Margin
  • Contract helpers / ABIs for mothership, CLOB, native router, and MarginRFQCore

Admin /api/admin/* routes are not wrapped.

Install​

From a published package (when available) or link the local workspace:

# sibling checkout
cd ../sdk
npm install
npm run build

# in your app
npm install ../sdk/packages/typescript
# or: npm install @opshuns/sdk

Runnable walkthroughs:

cd ../sdk
OPSHUNS_CLOB=0x… npm run example:taker -w @opshuns/sdk
OPSHUNS_CLOB=0x… OPSHUNS_MAKER_API_KEY=… npm run example:maker -w @opshuns/sdk

Quick start​

import {
OpshunsClient,
signRfqPackageOffer,
opshunsMothership,
takerAddressHash,
ABIS,
} from "@opshuns/sdk"

const client = new OpshunsClient({ baseUrl: "http://127.0.0.1:4000" })

await client.loginWithSiwe(wallet.address, (msg) => wallet.signMessage(msg))

const networks = await client.listNetworks()
const mothership = /* from networks[].contracts.mothership / factory */

Three common patterns​

1. Taker: options / Dutch / margin RFQ​

const session = await client.createQuoteSession(
{
chain_id: 31337,
taker_address: wallet.address,
intents: [/* OpshunIntentShared */],
polarity: "a_is_buy",
expires_in: 60,
},
{
onEvent: (event, payload) => {
if (event === "rfq_offer") console.log("offer", payload)
},
},
)

After you pick an offer, settle on-chain with executeFixedPackageIntent (see Settle matched intents with your own RFQ). Wallet product flow: Add to your crypto wallet.

Dutch auctions: build a DutchFillRequest and sign with signDutchFillRequest, then create the quote with dutch_request / offer_formats: "dutch_only".

2. Maker: fill quote streams​

const maker = await client.startMakerSession(31337, {
apiKey: makerKeySecret,
onEvent: async (event, payload) => {
if (event !== "rfq_request") return
const offer = await signRfqPackageOffer(wallet, mothership, 31337, request)
await client.placeBid((payload as { id: string }).id, offer)
},
})

Signing domains and helpers: EIP-712 signing. Auction lifecycle: Fill options RFQ quotes.

3. Contracts: CLOB posts and native wrap​

import {
opshunsMothership,
encodeMothershipCall,
opshunsNativeRouter,
ABIS,
ZERO_ADDRESS,
} from "@opshuns/sdk"

const ms = opshunsMothership(mothershipAddress, signer)

// Resting book
await ms.orderBuy(clob, pairKey, amount, wallet.address, ZERO_ADDRESS)
await ms.orderSell(clob, pairKey, amount, wallet.address, ZERO_ADDRESS)

// Native gas → wrap → mothership → refund
const router = opshunsNativeRouter(nativeRouterAddress, signer)
const data = encodeMothershipCall(ABIS.OpshunsMothership, "orderBuy", [
clob,
pairKey,
amount,
wallet.address, // beneficiary = user (router is msg.sender)
ZERO_ADDRESS,
])
await router.execute(data, { value: amountInWei })

Book posts: Call the CLOB directly. Bilateral settle: Settle matched intents with your own RFQ.

Signing helpers​

HelperDomainRole
signRfqPackageOfferOpshunsFixedPackageMaker package premium (API auction)
signRfqLegByLegOfferOpshunsRFQMaker inventory FillMatched (zero premium; not the API auction)
signDutchFillRequestOpshunsDutchFillTaker Dutch auction
signRfq*OfferDigest / signDutchFillRequestDigestsameLocal key / digest path
signMarginLoanOfferMarginRFQCoreLender. digest only (do not raw signTypedData)
signMarginLoanRequestMarginRFQCoreBorrower after select

Also: takerAddressHash, directionsHash, digestOpshunIntentRequestLegByLeg, legByLegRequestToApi, …

API surface (high level)​

AreaExamples
AuthloginWithSiwe, me, health
DiscoverylistNetworks, payment / premium tokens, portfolio
Options RFQcreateQuote, createQuoteSession, placeBid, fillQuote, getQuote
Margin RFQcreateMarginQuoteSession, placeMarginOffer, selectMarginOffer
Maker / taker keyscreateMakerKeyWithSigner, createTakerDelegateWithSigner, …
PubsubstartMakerSession, OpshunsPubsub, topic helpers in topics.ts
GoalDoc
Embed hosted UIAdd to your Dapp
Wallet + API taker orgAdd to your crypto wallet
Own RFQ → bookCall the CLOB directly
Own RFQ → settleSettle matched intents with your own RFQ
Maker auctionFill options RFQ quotes
All fill modesOn-chain fill modes
REST mapAPI overview

Source of truth: ../sdk/README.md and packages/typescript/src/{client,contracts,types}.ts.