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
| Helper | Domain | Role |
|---|---|---|
signRfqPackageOffer | OpshunsFixedPackage | Maker package premium (API auction) |
signRfqLegByLegOffer | OpshunsRFQ | Maker inventory FillMatched (zero premium; not the API auction) |
signDutchFillRequest | OpshunsDutchFill | Taker Dutch auction |
signRfq*OfferDigest / signDutchFillRequestDigest | same | Local key / digest path |
signMarginLoanOffer | MarginRFQCore | Lender. digest only (do not raw signTypedData) |
signMarginLoanRequest | MarginRFQCore | Borrower after select |
Also: takerAddressHash, directionsHash, digestOpshunIntentRequestLegByLeg, legByLegRequestToApi, …
API surface (high level)
| Area | Examples |
|---|---|
| Auth | loginWithSiwe, me, health |
| Discovery | listNetworks, payment / premium tokens, portfolio |
| Options RFQ | createQuote, createQuoteSession, placeBid, fillQuote, getQuote |
| Margin RFQ | createMarginQuoteSession, placeMarginOffer, selectMarginOffer |
| Maker / taker keys | createMakerKeyWithSigner, createTakerDelegateWithSigner, … |
| Pubsub | startMakerSession, OpshunsPubsub, topic helpers in topics.ts |
Related guides
| Goal | Doc |
|---|---|
| Embed hosted UI | Add to your Dapp |
| Wallet + API taker org | Add to your crypto wallet |
| Own RFQ → book | Call the CLOB directly |
| Own RFQ → settle | Settle matched intents with your own RFQ |
| Maker auction | Fill options RFQ quotes |
| All fill modes | On-chain fill modes |
| REST map | API overview |
Source of truth: ../sdk/README.md and packages/typescript/src/{client,contracts,types}.ts.