@somnia-chain/markets-sdk


@somnia-chain/markets-sdk / index / PerpStateOnchain

Interface: PerpStateOnchain

Defined in: packages/sdk/src/perp/state.ts:22

A perp pool's live pricing/funding state, read straight from chain in one pipelined fan-out. Fresher than the indexed Market row (funding fields there only update when FundingUpdated fires, i.e. per settlement window).

Properties

markPrice

markPrice: bigint

Defined in: packages/sdk/src/perp/state.ts:24

EMA-smoothed oracle mark price (raw quote units per whole base).


markPriceOk

markPriceOk: boolean

Defined in: packages/sdk/src/perp/state.ts:29

Whether the mark feed is live. When false, markPrice is not meaningful — the FundingUpdated event signals the same condition with a 0 sentinel.


indexPrice

indexPrice: bigint

Defined in: packages/sdk/src/perp/state.ts:31

Unsmoothed oracle index price (raw quote units per whole base).


indexUpdatedAt

indexUpdatedAt: bigint

Defined in: packages/sdk/src/perp/state.ts:33

Index price oracle timestamp (seconds).


fundingRate

fundingRate: bigint

Defined in: packages/sdk/src/perp/state.ts:35

Current funding rate per settlement window (1e18-scaled fraction, signed).


cumulativeFundingPerUnit

cumulativeFundingPerUnit: bigint

Defined in: packages/sdk/src/perp/state.ts:37

Settled cumulative funding per base unit (1e18-scaled, signed).


projectedCumulativeFundingPerUnit

projectedCumulativeFundingPerUnit: bigint

Defined in: packages/sdk/src/perp/state.ts:39

Cumulative funding projected to now (unsettled accrual included).


openInterest

openInterest: bigint

Defined in: packages/sdk/src/perp/state.ts:47

TOTAL open interest in base units.

Replaces longOpenInterest / shortOpenInterest: the contract keeps ONE counter because the short side is provably equal in a matched CLOB, and the two-field form did not match the deployed ABI at all — it made every getPerpState call throw.


fundingWindowSec

fundingWindowSec: number

Defined in: packages/sdk/src/perp/state.ts:53

The rate's DENOMINATOR in seconds (fundingCalculationWindowSec), 28800 on every live pool. fundingRate is per THIS window — not per settlement interval and not annualized. Normalize with it; never with a hardcoded constant.


fundingIntervalSec

fundingIntervalSec: number

Defined in: packages/sdk/src/perp/state.ts:59

Settlement cadence in seconds. 300 on testnet, expected 3600 on mainnet, so fundingWindowSec / fundingIntervalSec is 96 vs 8 — the same emitted rate means a 12x different per-interval accrual between them.


lastFundingUpdateAt

lastFundingUpdateAt: bigint

Defined in: packages/sdk/src/perp/state.ts:61

Last settlement, unix seconds (the chain stores nanoseconds).


nextFundingAt

nextFundingAt: bigint

Defined in: packages/sdk/src/perp/state.ts:63

When the next settlement becomes due. Settlement is LAZY, so it may pass unmet.


emaPremium

emaPremium: bigint

Defined in: packages/sdk/src/perp/state.ts:70

EMA'd premium driving the rate: book-MIDPOINT vs index, NOT mark vs index, and 0 for a one-sided or empty book. Not recoverable from events, so this is the only source. Expect it to disagree with (mark - index) / index — they are different quantities by design.