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

# Buy YT

> Low-level instruction to buy YT tokens using SY

# createBuyYtInstruction

Builds a raw instruction to buy YT tokens using SY. This instruction strips SY into PT and YT, then sells the excess PT back to the pool for SY, effectively converting the input SY into YT at the current market rate. The process leverages the PT/SY AMM to determine the conversion ratio.

## Usage

```typescript theme={null}
import { createBuyYtInstruction } from "@exponent-labs/exponent-sdk/client/clmm";
import { PublicKey, SystemProgram } from "@solana/web3.js";

const ix = createBuyYtInstruction({
  trader: traderKeypair.publicKey,
  market: marketAddress,
  ticks: ticksAccount,
  tokenSyTrader: traderSyTokenAccount,
  tokenYtTrader: traderYtTokenAccount,
  tokenPtTrader: traderPtTokenAccount,
  tokenSyEscrow: marketSyEscrow,
  tokenPtEscrow: marketPtEscrow,
  tokenYtEscrow: marketYtEscrow,
  tokenFeeTreasurySy: feeTreasurySyAccount,
  tokenFeeTreasuryPt: feeTreasuryPtAccount,
  tokenProgram: tokenProgramId,
  addressLookupTable: lookupTableAddress,
  syProgram: syProgramId,
  exponentCoreProgram: exponentCoreProgramId,
  eventAuthority: eventAuthorityPda,
  program: clmmProgramId,
  syIn: 1_000_000_000n,
  minYtOut: 900_000_000n,
  priceSpotLimit: 1.05,
});
```

## Accounts

| Name                  | Type        | Signer | Writable | Description                                 |
| --------------------- | ----------- | ------ | -------- | ------------------------------------------- |
| `trader`              | `PublicKey` | Yes    | Yes      | Wallet executing the trade                  |
| `market`              | `PublicKey` | No     | Yes      | The CLMM market account                     |
| `ticks`               | `PublicKey` | No     | Yes      | The market tick array account               |
| `tokenSyTrader`       | `PublicKey` | No     | Yes      | Trader's SY token account                   |
| `tokenYtTrader`       | `PublicKey` | No     | Yes      | Trader's YT token account                   |
| `tokenPtTrader`       | `PublicKey` | No     | Yes      | Trader's PT token account                   |
| `tokenSyEscrow`       | `PublicKey` | No     | Yes      | Market SY escrow account                    |
| `tokenPtEscrow`       | `PublicKey` | No     | Yes      | Market PT escrow account                    |
| `tokenYtEscrow`       | `PublicKey` | No     | Yes      | Market YT escrow account                    |
| `tokenFeeTreasurySy`  | `PublicKey` | No     | Yes      | SY fee treasury account                     |
| `tokenFeeTreasuryPt`  | `PublicKey` | No     | Yes      | PT fee treasury account                     |
| `tokenProgram`        | `PublicKey` | No     | No       | SPL Token program                           |
| `addressLookupTable`  | `PublicKey` | No     | No       | Market address lookup table                 |
| `syProgram`           | `PublicKey` | No     | No       | SY program                                  |
| `exponentCoreProgram` | `PublicKey` | No     | No       | Exponent core program (for strip/merge CPI) |
| `eventAuthority`      | `PublicKey` | No     | No       | Event authority PDA                         |
| `program`             | `PublicKey` | No     | No       | CLMM program ID                             |

## Args

| Name             | Type             | Description                              |
| ---------------- | ---------------- | ---------------------------------------- |
| `syIn`           | `u64`            | Amount of SY tokens to spend             |
| `minYtOut`       | `u64`            | Minimum amount of YT tokens to receive   |
| `priceSpotLimit` | `f64` (optional) | Price limit for anti-sandwich protection |

## Returns

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