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

> Buy PT tokens using base assets in a single transaction

The `ixWrapperBuyPt` method on the `MarketThree` class converts base assets into PT (Principal Tokens) by wrapping the base into SY and then swapping SY for PT in a single atomic operation.

## Usage

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

const connection = new Connection("https://api.mainnet-beta.solana.com");
const market = await MarketThree.load(LOCAL_ENV, connection, marketAddress);

const { ixs, setupIxs } = await market.ixWrapperBuyPt({
  owner: wallet.publicKey,
  minPtOut: 1_000_000_000n,
  baseIn: 1_100_000_000n,
});

const tx = new Transaction().add(...setupIxs, ...ixs);
const signature = await sendAndConfirmTransaction(connection, tx, [wallet]);
```

<Tip>
  This is an async method because it needs to construct the SY minting accounts from the market's flavor configuration.
</Tip>

## Required Parameters

| Parameter  | Type        | Description                            |
| ---------- | ----------- | -------------------------------------- |
| `owner`    | `PublicKey` | The owner's wallet public key          |
| `minPtOut` | `bigint`    | Minimum amount of PT tokens to receive |
| `baseIn`   | `bigint`    | Amount of base asset to spend          |

## Optional Parameters

| Parameter           | Type        | Description                                            |
| ------------------- | ----------- | ------------------------------------------------------ |
| `tokenSyTrader`     | `PublicKey` | Intermediate SY token account. Defaults to owner's ATA |
| `tokenPtTrader`     | `PublicKey` | Destination PT token account. Defaults to owner's ATA  |
| `tokenBaseTrader`   | `PublicKey` | Source base token account. Defaults to owner's ATA     |
| `lnImpliedApyLimit` | `number`    | Optional APY limit for the swap                        |

## Returns

Returns a `Promise<PreparedInstruction>` with the following structure:

```typescript theme={null}
{
  ixs: TransactionInstruction[],      // Main instructions to execute
  setupIxs: TransactionInstruction[]  // Setup instructions for creating ATAs
}
```

The `setupIxs` array contains instructions to create the necessary associated token accounts (ATAs) for SY, PT, and base tokens. The `ixs` array contains the flavor pre-instructions, the buy PT instruction, and the flavor post-instructions.
