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:

type

Strikes

Description

'call'

1

Vanilla call (INVERSE_CALL)

'put'

1

Vanilla put

'call_spread'

2

Call spread

'put_spread'

2

Put spread

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