> For the complete documentation index, see [llms.txt](https://docs.adrena.trade/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.adrena.trade/sdk/sdk.md).

# TypeScript SDK

The Adrena TypeScript SDK provides a high-level interface for interacting with the Adrena Protocol on Solana - opening and closing perpetual positions, managing liquidity, staking tokens, and querying off-chain analytics.

Built on [@solana/kit](https://github.com/anza-xyz/kit) (Web3.js v2). All transactions are submitted via [Jito bundles](https://www.jito.network/) for MEV protection.

***

## Installation

```bash
# npm
npm install adrena-sdk@beta

# yarn
yarn add adrena-sdk@beta
```

***

## Configuration

All SDK functions require a `wallet` (transaction signer) and an `rpc` client. Use `createKitClient` to create both.

### Option 1 - `.env` file (recommended)

Create a `.env` file in your project root:

```env
PRIVATE_KEY_STR=<your-base58-private-key>
RPC_URL=https://your-rpc-url.com
WS_URL=wss://your-ws-url.com
```

> Never commit private keys. Add `.env` to your `.gitignore`.

Then in code:

```typescript
import { createKitClient } from 'adrena-sdk/clients';

const { wallet, rpc } = await createKitClient();
```

### Option 2 - Pass credentials directly

```typescript
import { createKitClient } from 'adrena-sdk/clients';

const { wallet, rpc } = await createKitClient({
  privateKey: 'your-base58-private-key',
  rpcUrl: 'https://your-rpc-url.com',
});
```

***

## Supported Assets

Adrena runs two separate on-chain pools. The SDK exposes both.

### Main Pool - Crypto Assets

| Symbol  | Role                   | Decimals |
| ------- | ---------------------- | -------- |
| JITOSOL | Principal / Collateral | 9        |
| WBTC    | Principal / Collateral | 8        |
| BONK    | Principal / Collateral | 5        |
| USDC    | Collateral / Liquidity | 6        |

**`PrincipalToken`** - the asset being traded: `"JITOSOL" | "WBTC" | "BONK"`

**`CollateralToken`** - the asset deposited as margin: `"USDC" | "JITOSOL" | "WBTC" | "BONK"`

> For **longs**, the collateral token must match the principal token (e.g. a JITOSOL long requires JITOSOL collateral). For **shorts**, the collateral token must always be `"USDC"`.

### Commodities Pool - Synthetic Assets

| Symbol | Name      | Decimals |
| ------ | --------- | -------- |
| XAU    | Gold      | 6        |
| XAG    | Silver    | 6        |
| WTI    | Crude Oil | 6        |

**`CommodityToken`** - `"XAU" | "XAG" | "WTI"`

Commodity positions are collateralised in USDC for both longs and shorts. There is no token swap - you deposit USDC and trade a price-feed-backed synthetic custody settled in USDC on close.

***

## Module Overview

The SDK is split into focused sub-packages. Import only what you need.

| Import path               | Purpose                                                |
| ------------------------- | ------------------------------------------------------ |
| `adrena-sdk/clients`      | Create the RPC + wallet client (`createKitClient`)     |
| `adrena-sdk/core`         | High-level trading, liquidity, and staking functions   |
| `adrena-sdk/instructions` | Low-level instruction builders for custom transactions |
| `adrena-sdk/helpers`      | PDAs, math, token accounts, transaction utilities      |
| `adrena-sdk/adrena-api`   | REST API client for off-chain data and analytics       |

***

## Sections

* [Trading](/sdk/sdk/trading.md)
* [Commodities](/sdk/sdk/commodities.md)
* [Liquidity & Swap](/sdk/sdk/liquidity-and-swap.md)
* [Staking](/sdk/sdk/staking.md)
* [Data API](/sdk/sdk/data-api.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.adrena.trade/sdk/sdk.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
