Migration Guide

Upgrade guide for existing users moving to the latest SDK patterns and APIs.

Table of Contents


Migrating to v0.2.1 (Base_r12 deployment)

v0.2.1 is the first 0.2.x release published to npm. It bundles the Base_r12 deployment cutover with 22 fixes that three adversarial code-review passes found in the staged surface. v0.2.0 was prepared internally but never published — there is no v0.2.0 on npm.

Pin to the deployment you want

  • @thetanuts-finance/thetanuts-client@^0.1.x — prior Base deployment (immutable on npm; use only if you need to keep talking to the old contracts).

  • @thetanuts-finance/thetanuts-client@^0.2.1 — Base_r12 deployment (recommended).

Breaking changes from 0.1.x → 0.2.1

  • client.events.getCollateralReturnedEvents was renamed to getExcessCollateralReturnedEvents with a new field shape:

  • OptionSplitEvent gained two fields. If you were destructuring, add feePaid and counterparty:

  • TransferApprovalEvent field order is fixed to match r12: { target, from, isBuyer, isApproved }. The 0.1.x SDK had target and from swapped in the typed wrapper for RangerOption events specifically.

  • OptionSettlementFailedEvent no longer has fields at the contract level. The SDK still populates optionAddress from the filter context for caller convenience.

  • Butterfly reverse-lookup names reconciled. getOptionImplementationInfo(addr).name returns 'CALL_FLY' / 'PUT_FLY' instead of 'CALL_FLYS' / 'PUT_FLYS'. The ProductName union in client.utils follows.

  • RangerModule.reclaimCollateral parameter renamed from recipient to ownedOption. Positional callers unaffected; named callers using a TypeScript object-shape break.

  • LoanRequest.keepOrderOpen is now a no-op. The r12 contract dropped the limit-order conversion field. The SDK still accepts the field for source compatibility but the value is ignored. The internal LoanCoordinator.requestLoan parameter tuple no longer includes convertToLimitOrder either; the SDK no longer sends it.

  • LoanIndexerLoan.convertToLimitOrder is optional. The lender-opportunity filter at client.loan.getLendingOpportunities only skips when the field is explicitly false; missing means eligible. If the r12 indexer drops the field entirely, your lender opportunity list still populates.

What you should also know about 0.2.1

  • New client.ranger module — see the Modules Overview.

  • chainConfig.implementations.RANGER, LINEAR_CALL, INVERSE_CALL_SPREAD, CALL_LOAN are new.

  • chainConfig.twapConsumer (string | null) surfaces the HistoricalPriceConsumerV3_TWAP address.

  • Ethereum mainnet (chainId 1) is now supported as a vault-only chain (only client.wheelVault works there).

  • Every RFQ entry point now rejects the seven undeployed PHYSICAL_* placeholder addresses with a clear INVALID_PARAMS error.

  • RANGER_OPTION_ABI is exported from the package root.


Breaking Changes

collateralAmount Parameter

The most critical change: collateralAmount must now always be 0 when creating RFQs.

Before (Incorrect Pattern)

After (Correct Pattern)

Why This Changed

Collateral is NOT locked at RFQ creation time. It is pulled from both parties at settlement time. The collateralAmount parameter in RFQ was misleading and should always be 0.

For SELL positions: You still need to calculate collateral, but only for token approval:


New Helper Methods

buildRFQParams()

High-level RFQ builder that:

  • Enforces collateralAmount = 0 automatically

  • Resolves addresses from chain config (no hardcoding)

  • Handles decimal conversions

buildRFQRequest()

Complete RFQ request builder including tracking and reserve price:

strikeToChain() / strikeFromChain()

Precision-safe strike conversion using string-based parsing (avoids floating-point errors):

getFullOptionInfo()

Aggregated option info in a single call (replaces multiple Promise.all patterns):

MM Pricing Filter Utilities

New utilities for filtering and sorting pricing data:


Code Migration Examples

Example 1: RFQ Creation for BUY Position

Example 2: RFQ Creation for SELL Position

Example 3: Option Position Queries

Example 4: Strike Price Conversion


Deprecation Notices

Deprecated Patterns

Pattern
Status
Replacement

Hardcoded contract addresses

Deprecated

Use client.chainConfig

Manual collateralAmount calculation

Deprecated

Always use BigInt(0) or buildRFQParams()

Multiple Promise.all for option info

Deprecated

Use getFullOptionInfo()

Manual strike scaling

Deprecated

Use strikeToChain() / strikeFromChain()

API Method Renames

To clarify data sources, some API methods have been renamed:

Old Method
New Method
Data Source

getUserPositions()

getUserPositionsFromIndexer()

Indexer API

getUserHistory()

getUserHistoryFromIndexer()

Indexer API

getStats()

getStatsFromIndexer()

Indexer API

getUserRFQs()

getUserRFQsFromRfq()

State/RFQ API

getRFQ()

getRFQFromRfq()

State/RFQ API

The old method names are still available as aliases but may be removed in a future version.


Indexer Migration Notes

Tested 2026-04-07 against indexer.thetanuts.finance (new unified indexer). Compared with optionbook-indexer.thetanuts.finance (old indexer, to be decommissioned).

Open Issues

Issue 1: Referrer userDailyMetrics not implemented

  • Endpoint: GET /api/v1/book/referrer/:addr/state

  • Severity: Medium

  • Description: Old indexer returns per-user, per-day trading stats. New indexer returns {}.

  • SDK impact: ReferrerStats.userDailyMetrics in src/types/api.ts expects this data.

Issue 2: Referrer topProfitableTrades not implemented

  • Endpoint: GET /api/v1/book/referrer/:addr/state

  • Severity: Medium

  • Description: Old indexer returns top 100 trades ranked by % return. New indexer returns [].

  • SDK impact: ReferrerStats.topProfitableTrades in src/types/api.ts expects this data.

Issue 4: Pagination not working on /api/v1/factory/rfqs

  • Endpoint: GET /api/v1/factory/rfqs?limit=2&offset=0

  • Severity: Low

  • Description: Pagination params are ignored — all RFQs are returned regardless. No pagination metadata in response.

  • SDK impact: None currently, but will not scale past ~5k RFQs.

Issue 6: Old indexer DNS records still active

  • Severity: Low

  • optionbook-indexer.thetanuts.finance still resolves and serves stale data.

  • Cleanup pending once migration is fully verified.

Resolved Issues

Issue
Resolution

SDK ReferrerStats type missing summary field

Fixed — ReferrerStats now includes optional summary?: ReferrerSummary

Daily stats endpoints return empty data

Fixed — getBookDailyStats(), getFactoryDailyStats(), getDailyStats() added

Factory referrals missing / empty

Fixed — StateReferral type corrected to match actual API response shape

Active filter bug — cancelled RFQ appearing in active results

Fixed — SDK now applies client-side re-filtering as a safety net

New Endpoints (not yet in SDK)

The following endpoints are live on the new indexer but do not yet have dedicated SDK methods:

Endpoint
Description

GET /api/v1/book/stats/protocol

Book protocol stats with time windows and implementation-type breakdowns

GET /api/v1/factory/stats/protocol

Factory protocol stats including avgTimeToFill, avgOffersPerRfq

GET /api/v1/stats/protocol

Combined book + factory protocol stats (merged totals + individual breakdowns)

Endpoint Status Summary

Endpoint
Status

/api/v1/book/user/:addr/positions

Working

/api/v1/book/user/:addr/history

Working

/api/v1/book/stats

Working

/api/v1/book/referrer/:addr/state

Partial (positions + summary; userDailyMetrics and topProfitableTrades missing)

/api/v1/book/stats/protocol

Working (new)

/api/v1/book/stats/daily

Working — SDK: getBookDailyStats()

/api/v1/factory/rfqs

Working (no pagination)

/api/v1/factory/rfqs/:id

Working

/api/v1/factory/offers

Working

/api/v1/factory/options

Working

/api/v1/factory/stats

Working

/api/v1/factory/user/:addr/rfqs

Working

/api/v1/factory/user/:addr/offers

Working

/api/v1/factory/user/:addr/positions

Working

/api/v1/factory/option/:addr

Working

/api/v1/factory/stats/protocol

Working (new)

/api/v1/factory/stats/daily

Working — SDK: getFactoryDailyStats()

/api/v1/book/option/:addr

Working

/api/v1/book/state

Working

/api/v1/stats/protocol

Working (new)

/api/v1/stats/daily

Working — SDK: getDailyStats()

/api/state

Working

/health

Working


See Also

  • Changelog - Version history and release notes

  • Examples - Runnable code examples covering common patterns

  • Error Handling — error codes and recovery patterns

Last updated