> ## Documentation Index
> Fetch the complete documentation index at: https://docs.exponent.finance/llms.txt
> Use this file to discover all available pages before exploring further.

# SDK Preflight

> Read market state before routing users or accepting LP tokens

***

The following pattern shows the state reads that are useful before routing a user into a tranche or accepting tranching LP tokens in another protocol.

```typescript theme={null}
import {
  TranchingMarket,
  tranchingFromNumber,
} from "@exponent-labs/exponent-sdk";
import {
  TrancheSide,
  TranchingMarketState,
} from "@exponent-labs/exponent-sdk/client/tranching";
import { PublicKey } from "@solana/web3.js";

const market = await TranchingMarket.load(connection, new PublicKey("..."), env);
await market.reload();

const side = TrancheSide.Senior;
const lpMint = market.lpMint(side);
const userLpAta = market.lpAta(side, user);

const isPaused = (market.state.statusFlags & 1) !== 0;
const isRecovery =
  market.state.marketState === TranchingMarketState.FixedTermRecovery;

const lpPrice =
  side === TrancheSide.Senior
    ? market.getSrLpPriceNetAsset()
    : market.getJrLpPriceNetAsset();

const remainingNavCapacity =
  side === TrancheSide.Senior
    ? market.getSyncedSrRemainingCapacityNetAssetValue()
    : market.getSyncedJrRemainingCapacityNetAssetValue();

console.log({
  lpMint: lpMint.toBase58(),
  userLpAta: userLpAta.toBase58(),
  isPaused,
  isRecovery,
  lpPriceRaw: lpPrice, // raw fixed-point NAV per raw LP unit
  lpPriceFixedPoint: tranchingFromNumber(lpPrice),
  remainingNavCapacityRaw: remainingNavCapacity, // raw fixed-point NAV units
  remainingNavCapacityFixedPoint: tranchingFromNumber(remainingNavCapacity),
  utilization: tranchingFromNumber(market.state.financials.utilization),
  fixedTermEndTsSec: market.state.financials.fixedTermEndTs,
});
```

<Note>
  `tranchingFromNumber` only converts Exponent Tranching `Number` fixed-point values. It does not divide token amounts by mint decimals. Balance, NAV, and transaction amount displays usually also need the SY, base, and LP mint decimals.
</Note>

## Transaction Builders

A transaction can then be built with the instruction that matches the user's input and desired output:

| User starts with | User wants | SDK method                                                                              |
| ---------------- | ---------- | --------------------------------------------------------------------------------------- |
| Base asset       | LP tokens  | [`ixWrapperDeposit`](/developer-tranching/typescript/instructions/ix-wrapper-deposit)   |
| SY               | LP tokens  | [`ixDeposit`](/developer-tranching/typescript/instructions/ix-deposit)                  |
| LP tokens        | SY         | [`ixWithdraw`](/developer-tranching/typescript/instructions/ix-withdraw)                |
| LP tokens        | Base asset | [`ixWrapperWithdraw`](/developer-tranching/typescript/instructions/ix-wrapper-withdraw) |

Output protection is normally represented by these guard fields:

| Method              | Output guard   |
| ------------------- | -------------- |
| `ixWrapperDeposit`  | `minLpOut`     |
| `ixDeposit`         | `minLpOut`     |
| `ixWithdraw`        | `minAmountOut` |
| `ixWrapperWithdraw` | `minBaseOut`   |

## Integration Sequence

Most integrations follow this sequence:

1. `TranchingMarket.load(...)` creates the market context.
2. `market.reload()` refreshes state before pricing or transaction construction.
3. `market.lpMint(trancheSide)` identifies the selected LP mint.
4. `getSrLpPriceNetAsset()` or `getJrLpPriceNetAsset()` provides the effective-NAV price input.
5. `state.marketState`, `state.statusFlags`, utilization, and recovery timestamps describe the current lifecycle and risk state.
6. [Capacity Helpers](/developer-tranching/typescript/read-functions/get-capacity-and-lp-prices#capacity-helpers) provide remaining Senior or Junior room.
7. [APY and Protection](/developer-tranching/typescript/read-functions/calculate-apy-and-protection) helpers can show expected Senior/Junior return and Senior drawdown protection.
8. SDK instruction builders construct the deposit or withdrawal transaction, with `minLpOut`, `minAmountOut`, or `minBaseOut` as output guards.
9. Lending integrations usually treat `FixedTermRecovery` as a Senior redemption lock and apply conservative collateral factors to Junior LP because Junior absorbs first losses.

## Related SDK Pages

<CardGroup cols={2}>
  <Card title="Read Functions" icon="file-spreadsheet" href="/developer-tranching/typescript/read-functions/overview">
    SDK getters for market state, LP prices, capacity, APY, and token accounts.
  </Card>

  <Card title="TypeScript Instructions" icon="file-spreadsheet" href="/developer-tranching/typescript/instructions/overview">
    SDK builders for deposits, withdrawals, and wrappers.
  </Card>
</CardGroup>
