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

# Wrapper Buy YT

> Low-level instruction to buy YT tokens from base assets in a single atomic operation

# createWrapperBuyYtInstruction

Builds a raw instruction to buy YT tokens from base assets in a single atomic operation. This instruction handles SY minting from the base asset, stripping SY into PT and YT, and selling excess PT back to the pool -- all within a single transaction instruction. This is the most convenient way to acquire YT from a base asset.

## Usage

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

const ix = createWrapperBuyYtInstruction({
  buyer: buyerKeypair.publicKey,
  market: marketAddress,
  tokenSyTrader: buyerSyTokenAccount,
  tokenYtTrader: buyerYtTokenAccount,
  tokenPtTrader: buyerPtTokenAccount,
  tokenSyEscrow: marketSyEscrow,
  tokenPtEscrow: marketPtEscrow,
  tokenYtEscrow: marketYtEscrow,
  marketAddressLookupTable: lookupTableAddress,
  tokenProgram: tokenProgramId,
  syProgram: syProgramId,
  systemProgram: SystemProgram.programId,
  tokenFeeTreasurySy: feeTreasurySyAccount,
  tokenFeeTreasuryPt: feeTreasuryPtAccount,
  ticks: ticksAccount,
  exponentCoreProgram: exponentCoreProgramId,
  eventAuthority: eventAuthorityPda,
  program: clmmProgramId,
  ytOut: 1_000_000_000n,
  maxBaseAmount: 1_100_000_000n,
  mintSyAccountsLength: 5,
  depositYtAccountsUntil: 3,
});
```

## Accounts

| Name                       | Type        | Signer | Writable | Description                                 |
| -------------------------- | ----------- | ------ | -------- | ------------------------------------------- |
| `buyer`                    | `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                    |
| `marketAddressLookupTable` | `PublicKey` | No     | No       | Market address lookup table                 |
| `tokenProgram`             | `PublicKey` | No     | No       | SPL Token program                           |
| `syProgram`                | `PublicKey` | No     | No       | SY program                                  |
| `systemProgram`            | `PublicKey` | No     | No       | System program                              |
| `tokenFeeTreasurySy`       | `PublicKey` | No     | Yes      | SY fee treasury account                     |
| `tokenFeeTreasuryPt`       | `PublicKey` | No     | Yes      | PT fee treasury account                     |
| `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                                |
| ------------------------ | ----- | ------------------------------------------ |
| `ytOut`                  | `u64` | Amount of YT tokens to receive             |
| `maxBaseAmount`          | `u64` | Maximum amount of base asset to spend      |
| `mintSyAccountsLength`   | `u8`  | Number of CPI accounts used for SY minting |
| `depositYtAccountsUntil` | `u8`  | Number of CPI accounts used for YT deposit |

## Returns

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