> ## 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.

# Yield Stripping SDK

> Get started with the Exponent Core SDK

Set up the Exponent Core SDK and walk through its complete lifecycle, from stripping yield assets into PT and YT, to collecting yield, and merging back.

## Installation

<CodeGroup>
  ```bash yarn theme={null}
  yarn add @exponent-labs/exponent-sdk
  ```

  ```bash npm theme={null}
  npm install @exponent-labs/exponent-sdk
  ```

  ```bash pnpm theme={null}
  pnpm add @exponent-labs/exponent-sdk
  ```
</CodeGroup>

## Setup

```typescript theme={null}
import { Vault, YtPosition, LOCAL_ENV } from "@exponent-labs/exponent-sdk";
import {
  Connection,
  PublicKey,
  Transaction,
  sendAndConfirmTransaction,
  Keypair,
} from "@solana/web3.js";

const connection = new Connection("https://api.mainnet-beta.solana.com");
const wallet = Keypair.fromSecretKey(/* your keypair */);
const vaultAddress = new PublicKey("...");

const vault = await Vault.load(LOCAL_ENV, connection, vaultAddress);
```

<Steps>
  <Step title="Initialize a Yield Position">
    Before stripping, create a `YieldTokenPosition` account for your wallet. This is a one-time setup per vault.

    <Note>
      YT is just an SPL token — the protocol can't track yield for tokens sitting in your wallet. The `YieldTokenPosition` account escrows your YT and records the SY exchange rate at entry, which is needed to compute earned yield. `ixStripFromBase` automatically deposits YT into this position, so it must exist before stripping.
    </Note>

    ```typescript theme={null}
    const initIx = vault.ixInitializeYieldPosition({
      owner: wallet.publicKey,
    });

    const tx = new Transaction().add(initIx);
    await sendAndConfirmTransaction(connection, tx, [wallet]);
    ```
  </Step>

  <Step title="Strip Base Tokens into PT and YT">
    Use `ixStripFromBase` to convert a base asset directly into PT and YT. This wraps the base into SY, strips it into PT and YT, and deposits the YT into your yield position in a single atomic instruction.

    ```typescript theme={null}
    const ix = await vault.ixStripFromBase({
      owner: wallet.publicKey,
      amountBase: 1_000_000n, // e.g. 1 USDC (6 decimals)
    });

    const tx = new Transaction().add(ix);
    await sendAndConfirmTransaction(connection, tx, [wallet]);

    const ytPosition = await YtPosition.loadByOwner(
      LOCAL_ENV,
      connection,
      wallet.publicKey,
      vault,
    );
    ```

    <Tip>
      If you already hold SY tokens, use `vault.ixStrip()` instead. It skips the base-to-SY wrapping step, but does not auto-deposit YT. In that case, call `ytPosition.ixDepositYt()` separately.
    </Tip>
  </Step>

  <Step title="Stage Yield">
    Before collecting, stage yield. This computes earned interest and emissions based on the current SY exchange rate.

    ```typescript theme={null}
    const stageIx = ytPosition.ixStageYield({
      payer: wallet.publicKey,
    });

    const tx = new Transaction().add(stageIx);
    await sendAndConfirmTransaction(connection, tx, [wallet]);
    ```
  </Step>

  <Step title="Collect Interest">
    After staging, collect earned interest, which is paid in SY tokens.

    ```typescript theme={null}
    const collectIx = ytPosition.ixCollectInterest({
      signer: wallet.publicKey,
    });

    const tx = new Transaction().add(collectIx);
    await sendAndConfirmTransaction(connection, tx, [wallet]);
    ```
  </Step>

  <Step title="Withdraw YT">
    Before merging, withdraw YT from the yield position back to your wallet. The merge instruction burns YT directly from your token account.

    ```typescript theme={null}
    const withdrawIx = ytPosition.ixWithdrawYt({
      amount: 1_000_000n, // amount of YT to withdraw
    });

    const tx = new Transaction().add(withdrawIx);
    await sendAndConfirmTransaction(connection, tx, [wallet]);
    ```
  </Step>

  <Step title="Merge PT and YT Back to Base">
    When you're ready to exit, merge PT and YT back into the base asset.

    ```typescript theme={null}
    const { ixs, setupIxs } = await vault.ixMergeToBase({
      owner: wallet.publicKey,
      amountPy: 1_000_000n, // amount of PT & YT to merge
    });

    const tx = new Transaction().add(...setupIxs, ...ixs);
    await sendAndConfirmTransaction(connection, tx, [wallet]);
    ```
  </Step>
</Steps>

## Reading State

Query vault and position state without sending transactions:

```typescript theme={null}
// Current SY exchange rate
const rate = vault.currentSyExchangeRate;

// Vault expiration
const expiresAt = vault.expirationDate;

// Claimable interest (in base token units)
const claimable = ytPosition.getClaimableInterest(rate);

// Claimable emissions
const emissions = ytPosition.getClaimableEmissions();
```

## Next Steps

<CardGroup cols={2}>
  <Card href="/developer-core/typescript/instructions/overview" title="Vault Instructions">
    TypeScript SDK instruction functions for Exponent Core
  </Card>

  <Card href="/developer-core/typescript/yt-instructions/overview" title="YtPosition Instructions">
    TypeScript SDK instructions for managing yield positions
  </Card>

  <Card href="/developer-core/typescript/read-functions/overview" title="Read Functions">
    Read functions available for querying Core market state without submitting transactions.
  </Card>
</CardGroup>
