npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@thetanuts-test/optionbook

v0.1.0

Published

OptionBook limit order book interactions for Thetanuts SDK

Readme

@thetanuts-test/optionbook

OptionBook limit order book interactions for the Thetanuts SDK.

Status: 🚧 Under Development

The OptionBook contract is being deployed. The ABI in this package is a placeholder and will be updated upon contract deployment.

Installation

# pnpm
pnpm add @thetanuts-test/core @thetanuts-test/optionbook

# npm
npm install @thetanuts-test/core @thetanuts-test/optionbook

# yarn
yarn add @thetanuts-test/core @thetanuts-test/optionbook

Quick Start

import { createThetanutsClient } from '@thetanuts-test/core'
import { optionBook } from '@thetanuts-test/optionbook'
import { parseUnits } from 'viem'

// Create client with wallet
const client = createThetanutsClient({
  chainId: 8453,
  walletClient, // Required for transactions
})

// Fill an order
const result = await optionBook.fillOrder(client, {
  order: orderData,
  signature: '0x...',
  fillAmount: parseUnits('5', 18),
})

API Reference

Fill Orders

fillOrder(client, params)

Fill an order from the order book.

const result = await optionBook.fillOrder(client, {
  order: {
    maker: '0xMakerAddress...',
    taker: '0x0000000000000000000000000000000000000000', // Any taker
    optionToken: '0xOptionToken...',
    collateralToken: '0xCollateralToken...',
    optionAmount: parseUnits('10', 18),
    collateralAmount: parseUnits('1000', 6),
    price: parseUnits('100', 6),
    expiry: BigInt(Math.floor(Date.now() / 1000) + 86400),
    nonce: 1n,
    isBuy: true,
  },
  signature: '0x...', // Maker's signature
  fillAmount: parseUnits('5', 18),
  referrer: '0x...', // Optional: Referrer address
})

// Returns: { hash: '0x...', success: boolean, filledAmount: bigint }

swapAndFillOrder(client, params)

Swap tokens and fill order in one transaction.

const result = await optionBook.swapAndFillOrder(client, {
  order: orderData,
  signature: '0x...',
  fillAmount: parseUnits('5', 18),
  routerAddress: '0xDexRouter...',
  srcToken: '0xFromToken...',
  dstToken: '0xToToken...',
  swapData: '0x...', // Encoded swap data
  swapAmount: parseUnits('500', 6),
})

Manage Orders

cancelOrder(client, order)

Cancel an open order.

const result = await optionBook.cancelOrder(client, order)
// Returns: { hash: '0x...', success: boolean }

hashOrder(order)

Compute order hash locally (no RPC call).

const orderHash = optionBook.hashOrder(order)
// Returns: '0x...' (bytes32)

computeNonce(client, maker)

Get current nonce for a maker address.

const nonce = await optionBook.computeNonce(client, '0xMakerAddress...')
// Returns: bigint

Fees

getFees(client, token, referrer?)

Get fee rates for a token.

const fees = await optionBook.getFees(
  client,
  '0xTokenAddress...',
  '0xReferrerAddress...' // Optional
)

// Returns
{
  protocolFeeRate: 30n,  // 0.30% (basis points)
  referralFeeRate: 10n,  // 0.10%
  totalFeeRate: 40n      // 0.40%
}

claimFees(client, token)

Claim accumulated referral fees.

const result = await optionBook.claimFees(client, '0xTokenAddress...')
// Returns: { hash: '0x...', success: boolean }

getClaimableFees(client, referrer, token)

Check claimable fee amount.

const amount = await optionBook.getClaimableFees(
  client,
  '0xReferrerAddress...',
  '0xTokenAddress...'
)
// Returns: bigint

Order Structure

interface Order {
  maker: Address        // Order creator
  taker: Address        // Specific taker (0x0 for any)
  optionToken: Address  // Option token address
  collateralToken: Address // Collateral token address
  optionAmount: bigint  // Amount of options
  collateralAmount: bigint // Total collateral
  price: bigint         // Price per option
  expiry: bigint        // Order expiry timestamp
  nonce: bigint         // Unique nonce (use computeNonce)
  isBuy: boolean        // true = buy order, false = sell order
}

Usage Example

Creating and Filling an Order Flow

import { createThetanutsClient } from '@thetanuts-test/core'
import { erc20 } from '@thetanuts-test/erc20'
import { optionBook } from '@thetanuts-test/optionbook'

// 1. Setup client
const client = createThetanutsClient({
  chainId: 8453,
  walletClient,
})

// 2. Ensure allowance for collateral
await erc20.ensureAllowance(client, {
  token: collateralToken,
  spender: optionBookAddress,
  amount: totalCost,
  approveMax: true,
})

// 3. Fill the order
const result = await optionBook.fillOrder(client, {
  order,
  signature,
  fillAmount: parseUnits('5', 18),
})

console.log('Filled:', result.hash)

TypeScript

Import types as needed:

import type {
  Order,
  SignedOrder,
  FillOrderParams,
  SwapAndFillOrderParams,
  FeeInfo,
  OrderResult,
  OrderBookQuote,
} from '@thetanuts-test/optionbook'

License

MIT