For the complete documentation index, see llms.txt. This page is also available as Markdown.

Utilities

Pure utility functions for decimal conversions, payout calculations, and payoff diagram generation — no network calls required.

Access via client.utils.

Method Reference

Method
Description
Signer

toBigInt(value, decimals)

Convert human-readable string/number to bigint

No

fromBigInt(value, decimals)

Convert bigint to human-readable string

No

strikeToChain(strike)

Convert strike price to on-chain format (8 decimals)

No

strikeFromChain(value)

Convert on-chain strike to human-readable number

No

toUsdcDecimals(value)

Convert to USDC (6 decimals)

No

fromUsdcDecimals(value)

Convert from USDC bigint to string

No

calculatePayout(params)

Option payoff calculation

No

calculateCollateral(params)

Required collateral for a position

No

generatePayoffDiagram(params)

Payoff chart data points

No

Decimal Conversions

toBigInt()

Convert a human-readable value to a bigint with the specified decimal precision. Uses string-based parsing to avoid floating-point errors.

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

const client = new ThetanutsClient({ chainId: 8453, provider });

const usdc = client.utils.toBigInt('100.5', 6);   // 100500000n
const weth = client.utils.toBigInt('1.5', 18);    // 1500000000000000000n
const btc  = client.utils.toBigInt('0.001', 8);   // 100000n

fromBigInt()

Convert a bigint back to a human-readable string.

Strike / Price Conversions

Strikes and prices are stored on-chain with 8 decimal places. Use these helpers instead of manual multiplication to avoid floating-point errors.

strikeToChain()

strikeFromChain()

Convenience Methods

Payout Calculation

calculatePayout()

Calculate option payoff at a given settlement price. Pure math — no chain calls.

Supported types and strike orderings. Strike order must match what the on-chain factory expects — pass strikes exactly as listed:

type

Strikes

Order

Invariant

'call'

1

[strike]

'put'

1

[strike]

'call_spread'

2

[lower, upper] ASCENDING

'put_spread'

2

[lower, upper] ASCENDING

'call_fly'

3

[K1, K2, K3] ASCENDING

K2 - K1 === K3 - K2 (equidistant)

'put_fly'

3

[K3, K2, K1] DESCENDING

K3 - K2 === K2 - K1 (equidistant)

'call_condor'

4

[K1, K2, K3, K4] ASCENDING

K2 - K1 === K4 - K3 (equal wings)

'put_condor'

4

[K1, K2, K3, K4] ASCENDING (condors are always ascending)

K2 - K1 === K4 - K3

'iron_condor'

4

[putLower, putUpper, callLower, callUpper]

putUpper <= callLower

'ranger'

4

[callLower, callUpper, putLower, putUpper]

spread widths equal AND callUpper < putLower

Multi-leg example (iron condor — buyer's payoff):

Ranger example (zone-bound):

Ranger seller posts 2k collateral (use calculateCollateral) even though the buyer's max payoff is k — either ramp can max out independently.

calculateCollateral()

Calculate the required collateral for a position.

generatePayoffDiagram()

Generate an array of { price, payout } data points for rendering a payoff chart.

Decimal Constants

Import the DECIMALS constant to avoid hardcoding decimal values:

Full Conversion Example


See Also

Last updated