> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sendai.fun/llms.txt
> Use this file to discover all available pages before exploring further.

# Adrena Protocol Integration

> Learn how to use perpetual trading functionality with Adrena Protocol

Solana Agent Kit provides comprehensive integration with Adrena Protocol for perpetual trading. The integration supports both long and short positions with configurable leverage and slippage parameters.

## Key Features

* Long/Short position trading
* Configurable leverage up to 100x
* Slippage protection
* Automated token account setup
* Price feed integration
* Support for multiple collateral types

## Opening Positions

### Long Position

```typescript theme={"system"}
const signature = await agent.methods.openPerpTradeLong({
  price: 300, // USD price
  collateralAmount: 10, // Amount of collateral
  collateralMint: new PublicKey("J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn"), // jitoSOL
  leverage: 50000, // 5x leverage (10000 = 1x)
  tradeMint: new PublicKey("J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn"), // Trading asset
  slippage: 0.3, // 0.3% slippage tolerance
});
```

### Short Position

```typescript theme={"system"}
const signature = await agent.methods.openPerpTradeShort({
  price: 300,
  collateralAmount: 10,
  collateralMint: TOKENS.USDC, // Default collateral for shorts
  leverage: 50000,
  tradeMint: TOKENS.jitoSOL,
  slippage: 0.3,
});
```

## Closing Positions

### Close Long Position

```typescript theme={"system"}
const signature = await agent.methods.closePerpTradeLong({
  price: 200, // Minimum exit price
  tradeMint: new PublicKey("J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn"),
});
```

### Close Short Position

```typescript theme={"system"}
const signature = await agent.methods.closePerpTradeShort({
  price: 200,
  tradeMint: new PublicKey("J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn"),
});
```

## LangChain Integration

Solana Agent Kit provides LangChain tools for automated trading:

### Open Trade Tool

```typescript theme={"system"}
import { SolanaPerpOpenTradeTool } from 'solana-agent-kit';

const openTradeTool = new SolanaPerpOpenTradeTool(agent);

// Tool input format:
const input = {
  collateralAmount: 1,
  collateralMint: "J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn",
  tradeMint: "J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn",
  leverage: 50000,
  price: 100,
  slippage: 0.3,
  side: "long" // or "short"
};
```

### Close Trade Tool

```typescript theme={"system"}
import { SolanaPerpCloseTradeTool } from 'solana-agent-kit';

const closeTradeTool = new SolanaPerpCloseTradeTool(agent);

// Tool input format:
const input = {
  tradeMint: "J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn",
  price: 100,
  side: "long" // or "short"
};
```

## Example Prompts

For LangChain AI tools, here are example prompts:

### Opening Trades

```text theme={"system"}
"Open a long position in SOL with 5x leverage using 10 jitoSOL as collateral"

"Short ETH with 3x leverage using 100 USDC as collateral with 0.5% slippage"

"Go long on JitoSOL with maximum leverage of 10x using 5 SOL"
```

### Closing Trades

```text theme={"system"}
"Close my long SOL position at $100 minimum price"

"Exit short ETH position when price reaches $2000"

"Close all my open perpetual trades"
```

## Important Notes

1. **Leverage Configuration**
   * Leverage is specified in basis points (10000 = 1x)
   * Maximum leverage varies by market
   * Example: 50000 = 5x leverage

2. **Collateral Types**
   * Long positions: Use same token as tradeMint to avoid swaps
   * Short positions: USDC recommended as collateral

3. **Price and Slippage**
   * Price in USD
   * Slippage as percentage (0.3 = 0.3%)
   * Always monitor price impact before trading

## Error Handling

```typescript theme={"system"}
try {
  await agent.methods.openPerpTradeLong({...});
} catch (error) {
  if (error.message.includes("insufficient funds")) {
    // Handle insufficient collateral
  } else if (error.message.includes("slippage tolerance exceeded")) {
    // Handle price movement
  }
}
```

## Technical Details

### Program ID

```typescript theme={"system"}
const ADRENA_PROGRAM_ID = new PublicKey(
  "13gDzEXCdocbj8iAiqrScGo47NiSuYENGsRqi3SEAwet"
);
```

### Price Decimals

```typescript theme={"system"}
const PRICE_DECIMALS = 10;
```

### Default Values

```typescript theme={"system"}
const DEFAULT_OPTIONS = {
  LEVERAGE_BPS: 50000, // 5x leverage
};
```

### Token Support

* jitoSOL
* USDC
* Additional assets based on protocol liquidity
