SDK Modules

This directory contains the feature modules that provide all SDK functionality.

Module Overview

Module
File
Purpose
Requires Signer

ERC20

erc20.ts

Token operations

Write ops only

OptionBook

optionBook.ts

Order execution

Write ops only

API

api.ts

Data fetching

No

OptionFactory

optionFactory.ts

RFQ lifecycle

Write ops only

Option

option.ts

Position management

Write ops only

Events

events.ts

Blockchain events

No

WebSocket

websocket.ts

Real-time data

No

Utils

utils.ts

Calculations

No

MMPricing

mmPricing.ts

Market Maker pricing

No

RFQKeyManager

rfqKeyManager.ts

ECDH keys & encryption for RFQ

No

Table of Contents


ERC20Module

Token approval, balance, and transfer operations.

Methods (read-only and requires signer)

Example: Approve Before Trading


OptionBookModule

Execute trades by filling orders from the orderbook.

Methods (read-only)

Methods (requires signer)

Example: Fill an Order


APIModule

Fetch data from the Thetanuts APIs. All methods are read-only except triggerIndexerUpdate().

All data comes from the unified indexer at indexer.thetanuts.finance. All list endpoints return complete arrays.

Health

Factory (RFQ) Endpoints

Book (OptionBook) Endpoints

Orders & Market Data (Odette API)


OptionFactoryModule

Request for Quotation (RFQ) system for custom options.

RFQ Lifecycle Methods (requires signer)

View Methods — Quotation State (read-only)

View Methods — Constants (read-only)

View Methods — State (read-only)

View Methods — Referral (read-only)

Write Methods — Referral & Swap (requires signer)

RFQ Lifecycle


OptionModule

Manage option positions after trading (BaseOption contract).

Write Methods (requires signer)

Read Methods (read-only)


EventsModule

Query blockchain events from contracts.

OptionBook / OptionFactory Events (read-only)

BaseOption Events (read-only)

Query events from individual option contracts (requires option address):

Example: Get Recent Fills


WebSocketModule

Real-time data subscriptions.

Methods (read-only)

Subscription Types

Type
Data

orders

Order updates (new, filled, cancelled)

positions

Position changes

prices

Real-time price updates

trades

Trade executions

quotations

RFQ updates

Example: Subscribe to Orders


UtilsModule

Utility calculations for options.

Methods (read-only)

Supported Structures

Structure
Strikes
Description

call

1

Long/short call

put

1

Long/short put

call_spread

2

Bull/bear call spread

put_spread

2

Bull/bear put spread

butterfly

3

Butterfly spread

iron_condor

4

Iron condor

straddle

1

Long/short straddle

strangle

2

Long/short strangle

Example: Calculate Spread Payoff


RFQKeyManagerModule

ECDH keypair generation, secure storage, and encryption/decryption for the sealed-bid auction RFQ workflow.

Key Generation Methods

Key Storage Methods

Encryption Methods

Utility Methods

Storage Providers

The module auto-detects the environment:

  • Browser: Uses localStorage

  • Node.js: Uses in-memory storage (keys lost on exit)

Custom storage can be configured:

Example: Complete RFQ Offer Flow

Example: Decrypt Incoming Offers (Requester)

Encryption Details

The module uses industry-standard cryptography:

  • Key Exchange: ECDH (secp256k1) for shared secret derivation

  • Key Derivation: SHA-256 hash of shared secret

  • Encryption: AES-256-GCM with 12-byte random IV

  • Payload: JSON encoded { offerAmount, nonce }

  • Output: IV (12 bytes) || ciphertext as hex string


MMPricingModule

Market Maker pricing with fee adjustments and collateral costs.

Methods (read-only)

MM Pricing Adjustments

MM pricing includes:

  1. Fee adjustment: min(0.0004, price * 0.125)

  2. Collateral cost: Based on APR rates (USD: 8%, BTC: 2%, ETH: 3%)

  3. Buffered prices: Additional safety margin for execution


Excluded Admin Functions

The following on-chain admin functions are intentionally excluded from the SDK. They require contract owner authorization and are not relevant to application developers or market makers.

Contract
Function Signature
On-Chain Modifier
Reason

OptionFactory

setMaxRfqValue(uint256)

onlyOwner

Protocol governance — sets max RFQ size

OptionFactory

setBaseSplitFee(uint256)

onlyOwner

Protocol governance — sets option split fee

OptionFactory

deprecateFactory()

onlyOwner

Protocol governance — permanently disables factory

OptionBook

setMinimumThresholds(uint256, uint256)

factory.owner()

Protocol governance — sets min premium/contracts

BaseOption has zero admin-only functions. All methods are gated by buyer/seller roles or option state.

Owner-Gated Methods That ARE Included

These methods are included because they serve referral partners or have broader utility, but they require owner authorization:

Module
Method
Note

optionFactory

withdrawFees()

Requires owner auth — see @remarks in JSDoc

optionBook

setReferrerFeeSplit()

Requires owner auth — see @remarks in JSDoc

optionBook

sweepProtocolFees()

Sends fees to owner — see @remarks in JSDoc

Last updated