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

# Withdraw

> Low-level instruction to withdraw SY from a Senior or Junior tranche

# createWithdrawInstruction

Builds a raw instruction that burns Senior or Junior LP shares and withdraws SY.

## Usage

```typescript theme={null}
import {
  TrancheSide,
  createWithdrawInstruction,
} from "@exponent-labs/exponent-sdk/client/tranching";

const ix = createWithdrawInstruction(
  {
    user: wallet.publicKey,
    market: marketAddress,
    returnModelStorage,
    addressLookupTable,
    syProgram,
    syMint,
    tokenLpSrc: userLpTokenAccount,
    tokenSyEscrow,
    tokenDst: userSyTokenAccount,
    mintLp: mintLpSenior,
    tokenProgram,
    eventAuthority,
    program: tranchingProgram,
  },
  {
    trancheSide: TrancheSide.Senior,
    lpAmountIn: 500_000_000n, // raw Senior LP units to burn
    minAmountOut: 0n,         // raw SY units
  }
);
```

## Accounts

| Name                 | Type        | Signer | Writable | Description                  |
| -------------------- | ----------- | ------ | -------- | ---------------------------- |
| `user`               | `PublicKey` | Yes    | Yes      | Withdrawer                   |
| `market`             | `PublicKey` | No     | Yes      | Tranching market account     |
| `returnModelStorage` | `PublicKey` | No     | Yes      | Return model storage account |
| `addressLookupTable` | `PublicKey` | No     | No       | Market address lookup table  |
| `syProgram`          | `PublicKey` | No     | No       | Linked SY program            |
| `syMint`             | `PublicKey` | No     | Yes      | SY mint                      |
| `tokenLpSrc`         | `PublicKey` | No     | Yes      | User LP source account       |
| `tokenSyEscrow`      | `PublicKey` | No     | Yes      | Market SY escrow             |
| `tokenDst`           | `PublicKey` | No     | Yes      | User SY destination account  |
| `mintLp`             | `PublicKey` | No     | Yes      | Senior or Junior LP mint     |
| `tokenProgram`       | `PublicKey` | No     | No       | SPL Token program            |
| `eventAuthority`     | `PublicKey` | No     | No       | Event authority PDA          |
| `program`            | `PublicKey` | No     | No       | Exponent Tranching program   |

## Args

| Name           | Type          | Description                                         |
| -------------- | ------------- | --------------------------------------------------- |
| `trancheSide`  | `TrancheSide` | `Senior` or `Junior`                                |
| `lpAmountIn`   | `u64`         | Selected-tranche LP shares to burn, in raw LP units |
| `minAmountOut` | `u64`         | Minimum SY amount to receive, in raw SY token units |

## Remaining accounts

Append the market's `getSyState` and `withdrawSy` CPI remaining accounts after the generated keys.

## Returns

`TransactionInstruction` - a transaction instruction ready to be added to a transaction.
