Thetanuts SDK Quick Reference

Quick reference for all SDK modules. For detailed documentation, see API Reference.

Installation

npm install @thetanuts-finance/thetanuts-client

Initialization

import { ThetanutsClient } from '@thetanuts-finance/thetanuts-client';

// Read-only client
const client = new ThetanutsClient({ chainId: 8453 });

// With signer (for transactions)
const client = new ThetanutsClient({
  chainId: 8453,
  signer: ethersWallet
});

Key Concepts

Concept
Description
Details

Reserve Price

Max (BUY) or min (SELL) acceptable price per contract

Collateral

Funds locked by seller to secure the option; pulled at settlement

Collateral Cost

Opportunity cost: amount × APR × time (BTC 1%, ETH 4%, USD 7%)

Sealed-Bid Auction

Encrypted offers prevent front-running; only requester can decrypt


Methods Summary

ERC20Module (Token operations)

Method
Description
Signer

getBalance(token, owner?)

Get token balance

No

getAllowance(token, owner, spender)

Get spending allowance

No

getDecimals(token)

Get token decimals (cached)

No

getSymbol(token)

Get token symbol

No

approve(token, spender, amount)

Approve spending

Yes

ensureAllowance(token, spender, amount)

Approve if needed

Yes

transfer(token, to, amount)

Transfer tokens

Yes

OptionBookModule (Order execution)

Method
Description
Signer

previewFillOrder(order, amount?, referrer?)

Dry-run fill preview

No

calculateNumContracts(usdc, price)

Calculate contracts from USDC

No

encodeFillOrder(order, amount?, referrer?)

Encode for viem/wagmi

No

getFees(token, referrer)

Get accumulated fees

No

getAmountFilled(nonce)

Get filled amount for nonce

No

getReferrerFeeSplit(address)

Get referrer fee % (bps)

No

fillOrder(order, amount?, referrer?)

Execute fill

Yes

swapAndFillOrder(order, swapParams)

Fill with swap

Yes

cancelOrder(order)

Cancel order

Yes

claimFees(token)

Claim accumulated fees

Yes

APIModule (Data fetching)

Method
Description
Signer

fetchOrders()

Fetch all orders

No

filterOrders(criteria)

Filter orders

No

getMarketData()

Get prices (BTC, ETH, SOL, etc.)

No

getMarketPrices()

Get all market prices

No

getStatsFromIndexer()

Protocol stats

No

getUserPositionsFromIndexer(address)

User positions

No

getUserHistoryFromIndexer(address)

Trade history

No

getReferrerStatsFromIndexer(address)

Referrer stats

No

getRfq(id)

Get RFQ by ID

No

getUserRfqs(address)

Get user's RFQs

No

getUserOffersFromRfq(address)

Get user's offers

No

OptionFactoryModule (RFQ lifecycle)

Method
Description
Signer

buildRFQParams(params)

Build RFQ params (supports multi-leg)

No

buildRFQRequest(params)

Build complete RFQ request

No

buildSpreadRFQ(params)

Build 2-leg spread RFQ

No

buildButterflyRFQ(params)

Build 3-leg butterfly RFQ

No

buildCondorRFQ(params)

Build 4-leg condor RFQ

No

buildIronCondorRFQ(params)

Build 4-leg iron condor RFQ

No

buildPhysicalOptionRFQ(params)

Build physically settled option RFQ (vanilla only)

No

encodeRequestForQuotation(request)

Encode for viem/wagmi

No

getQuotation(id)

Get quotation by ID

No

getQuotationCount()

Total RFQ count

No

calculateFee(contracts, premium, price)

Calculate fee

No

requestForQuotation(request)

Create RFQ

Yes

makeOfferForQuotation(params)

Make encrypted offer

Yes

revealOffer(params)

Reveal offer

Yes

settleQuotation(id)

Settle after reveal

Yes

settleQuotationEarly(id, amount, nonce, offeror)

Early settle

Yes

cancelQuotation(id)

Cancel RFQ

Yes

cancelOfferForQuotation(id)

Cancel offer

Yes

OptionModule (Position management)

Method
Description
Signer

getOptionInfo(address)

Get option details

No

calculatePayout(address, price)

Calculate payout

No

calculateRequiredCollateral(address, strikes, contracts)

Get collateral needed

No

getStrikes(address)

Get strike prices

No

getExpiry(address)

Get expiry timestamp

No

isExpired(address)

Check if expired

No

isSettled(address)

Check if settled

No

getBuyer(address)

Get buyer address

No

getSeller(address)

Get seller address

No

getNumContracts(address)

Get contract count

No

getCollateralAmount(address)

Get collateral amount

No

close(address)

Close position

Yes

transfer(address, isBuyer, target)

Transfer role

Yes

split(address, amount)

Split position

Yes

payout(address)

Execute payout

Yes

MMPricingModule (Market Maker pricing)

Method
Description
Signer

getAllPricing(underlying)

All pricing for ETH/BTC

No

getTickerPricing(ticker)

Pricing for specific ticker

No

getPositionPricing(params)

Long/short with collateral cost

No

getSpreadPricing(params)

2-leg spread pricing

No

getButterflyPricing(params)

3-leg butterfly pricing

No

getCondorPricing(params)

4-leg condor pricing

No

filterExpired(pricing[])

Filter out expired options

No

sortByExpiryAndStrike(pricing[])

Sort by expiry, then strike

No

getUniqueExpiries(pricing[])

Get unique expiry dates

No

filterByType(pricing[], isCall)

Filter calls/puts

No

RFQKeyManagerModule (Encryption)

Method
Description
Signer

generateKeyPair()

Generate ECDH keypair

No

getOrCreateKeyPair()

Get/create stored key

No

loadKeyPair()

Load from storage

No

hasStoredKey()

Check if key exists

No

storeKeyPair(keypair)

Store keypair

No

removeStoredKey()

Remove stored keypair

No

exportPrivateKey()

Export private key for backup

No

importFromPrivateKey(key, store?)

Import keypair from private key

No

encryptOffer(amount, nonce, pubKey)

Encrypt offer

No

decryptOffer(data, pubKey)

Decrypt incoming offers

No

generateNonce()

Generate random nonce

No

getPublicKeyFromPrivate(key)

Derive public key

No

isValidPublicKey(key)

Validate public key format

No

getStorageKeyId()

Get storage key identifier

No

EventsModule (Blockchain events)

Method
Description
Signer

getOrderFillEvents(filters?)

Order fill events

No

getOrderCancelledEvents(filters?)

Cancellation events

No

getOptionCreatedEvents(filters?)

New option events

No

getQuotationRequestedEvents(filters?)

RFQ request events

No

getOfferMadeEvents(filters?)

RFQ offer events

No

getOfferRevealedEvents(filters?)

Offer reveal events

No

getQuotationSettledEvents(filters?)

Settlement events

No

getPositionClosedEvents(option, filters?)

Position close events

No

WebSocketModule (Real-time)

Method
Description
Signer

connect(config?)

Connect to WebSocket

No

subscribe(options, callback)

Subscribe to updates

No

unsubscribe(id)

Unsubscribe

No

getState()

Get connection state

No

disconnect()

Disconnect

No

UtilsModule (Calculations)

Method
Description
Signer

calculatePayout(params)

Option payoff calculation

No

calculateCollateral(params)

Required collateral

No

generatePayoffDiagram(params)

Payoff chart data

No

toBigInt(value, decimals)

Convert to bigint

No

fromBigInt(value, decimals)

Convert from bigint

No

strikeToChain(strike)

Strike to 8 decimals

No

strikeFromChain(value)

Strike from 8 decimals

No

toUsdcDecimals(value)

Convert to USDC (6 dec)

No

fromUsdcDecimals(value)

Convert from USDC

No


Chain Configuration

Access all addresses from chain config (no hardcoding needed):


RFQ Creation

Multi-Leg Options (Spreads, Butterflies, Condors)

Convenience Helper Methods

Complete RFQ Request

CRITICAL: collateralAmount = 0


Strike Conversion

Use precision-safe methods to avoid floating-point errors:


Decimal Conversions


Option Module

Get Full Option Info (Single Call)

Individual Methods


MM Pricing

Get All Pricing

Get Specific Ticker

Position Pricing (With Collateral Cost)

Spread Pricing

Multi-leg structures use spread-level collateral cost (width-based, not sum of per-leg CCs).

Filter & Sort Utilities


ERC20 Operations


API Module


Type Exports


Decimal Reference

Type
Decimals
Example

USDC

6

1000000 = 1 USDC

WETH

18

1000000000000000000 = 1 WETH

cbBTC

8

100000000 = 1 cbBTC

Strike/Price

8

185000000000 = $1850

numContracts

collateral decimals

Depends on token


Common Patterns

Approval for SELL Position

Error Handling


Physical Options

Physical options involve actual delivery of the underlying asset at expiry.

Calculation Functions

Physical Option Products

Product
Collateral (Seller)
Delivery (Buyer)

PHYSICAL_CALL

numContracts (WETH)

strike × numContracts (USDC)

PHYSICAL_PUT

strike × numContracts (USDC)

numContracts (WETH)

PHYSICAL_CALL_SPREAD

width × numContracts (WETH)

width × numContracts (USDC)

PHYSICAL_PUT_SPREAD

width × numContracts (USDC)

width × numContracts (WETH)


See Also

Last updated