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

# Titan DEX Instructions

> Execute token swaps through the Titan DEX aggregator via policy-gated vault execution

The Titan instructions module enables vault managers and allocators to swap tokens through [Titan](https://titan.exchange), a Solana DEX aggregator. The integration works in two steps: fetch a swap quote from Titan's gateway, then wrap the resulting instruction in a Squads sync transaction.

<Note>
  Titan swap quotes are fetched from Titan's REST gateway, which requires a base URL (`baseUrl`) and an auth token (`authToken`) issued by Titan.
</Note>

## Transaction Structure

Every Titan interaction goes through `createVaultSyncTransaction`, which returns three parts:

```typescript theme={null}
const { preInstructions, instruction, postInstructions } =
  await createVaultSyncTransaction({
    instructions,   // Array of VaultInstruction descriptors
    owner,          // Vault PDA (the Squads smart account)
    connection,
    policyPda,      // Policy authorizing this execution
    vaultPda,       // Squads vault PDA
    signer,         // The allocator or manager wallet
    vaultAddress,   // ExponentStrategyVault PDA (auto-resolves hook accounts)
  });

// Send all three parts in order
const tx = new Transaction().add(...preInstructions, instruction, ...postInstructions);
await sendAndConfirmTransaction(connection, tx, [wallet]);
```

| Part               | What it contains                                               | Why it's separate                                 |
| ------------------ | -------------------------------------------------------------- | ------------------------------------------------- |
| `preInstructions`  | Any permissionless setup instructions                          | Must be top-level instructions                    |
| `instruction`      | Squads sync transaction wrapping all vault-signed instructions | Executes with the vault's smart account as signer |
| `postInstructions` | Any post-operation instructions                                | Must be top-level instructions                    |

***

## Fetching a Quote

`TitanGatewayClient.quoteVaultSwapInstruction` requests a swap route from Titan's gateway and returns a `TransactionInstruction` along with any Address Lookup Table addresses needed for transaction compilation.

```typescript theme={null}
import { TitanGatewayClient } from "@exponent-labs/exponent-sdk";
import { PublicKey } from "@solana/web3.js";

const titan = new TitanGatewayClient({
  baseUrl: "https://...",   // Titan gateway URL
  authToken: "...",         // Titan auth token
});

const quoteResult = await titan.quoteVaultSwapInstruction({
  inputMint: new PublicKey("..."),    // Token to sell
  outputMint: new PublicKey("..."),   // Token to buy
  amount: 1_000_000_000n,             // Amount of input token in native units
  slippageBps: 50,                    // Slippage tolerance in basis points
  ownerPda: vaultPda,                 // The vault's smart account (trader)
});
```

### Parameters

| Parameter     | Type        | Description                                                 |
| ------------- | ----------- | ----------------------------------------------------------- |
| `baseUrl`     | `string`    | Titan gateway base URL                                      |
| `authToken`   | `string`    | Titan auth token. Sent as an `Authorization: Bearer` header |
| `inputMint`   | `PublicKey` | Mint address of the token to sell                           |
| `outputMint`  | `PublicKey` | Mint address of the token to buy                            |
| `amount`      | `bigint`    | Amount of input token in native units                       |
| `slippageBps` | `number`    | Optional. Slippage tolerance in basis points                |
| `ownerPda`    | `PublicKey` | The trader's smart account — use the vault's Squads PDA     |

### Return Value

| Field                         | Type                     | Description                                         |
| ----------------------------- | ------------------------ | --------------------------------------------------- |
| `instruction`                 | `TransactionInstruction` | The Titan `SwapRouteV2` instruction to execute      |
| `addressLookupTableAddresses` | `PublicKey[]`            | Address Lookup Table addresses from the Titan route |

<Warning>
  Titan swap quotes have a short expiry. Fetch the quote and submit the transaction promptly to avoid stale routes.
</Warning>

***

## Executing a Swap

`titanAction.swap` wraps the instruction from `quoteVaultSwapInstruction` into a vault instruction descriptor for `createVaultSyncTransaction`.

```typescript theme={null}
import {
  titanAction,
  createVaultSyncTransaction,
} from "@exponent-labs/exponent-sdk";

const { preInstructions, instruction, postInstructions } =
  await createVaultSyncTransaction({
    instructions: [
      titanAction.swap({
        instruction: quoteResult.instruction,
        addressLookupTableAddresses: quoteResult.addressLookupTableAddresses,
      }),
    ],
    owner: vaultPda,
    connection,
    policyPda,
    vaultPda,
    signer: wallet.publicKey,
    vaultAddress,
  });

const tx = new Transaction().add(...preInstructions, instruction, ...postInstructions);
await sendAndConfirmTransaction(connection, tx, [wallet]);
```

### Parameters

| Parameter                     | Type                     | Description                                                                    |
| ----------------------------- | ------------------------ | ------------------------------------------------------------------------------ |
| `instruction`                 | `TransactionInstruction` | The Titan `SwapRouteV2` instruction returned by `quoteVaultSwapInstruction`    |
| `addressLookupTableAddresses` | `PublicKey[]`            | Optional. ALT addresses from the quote. Defaults to `[]`. Strongly recommended |

<Tip>
  Passing `addressLookupTableAddresses` from the quote is strongly recommended — the sync transaction builder uses them to compress the final V0 message.
</Tip>

A matching policy must exist before executing. See [Policy Builders](/vault-sdk/typescript/manager-operations/policy-builders#titan-swap-policy).

***

## Full Flow Example

This example demonstrates fetching a Titan swap quote and executing it through the vault.

### Step 1: Fetch Swap Quote

```typescript theme={null}
import {
  TitanGatewayClient,
  titanAction,
  createVaultSyncTransaction,
} 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 INPUT_MINT = new PublicKey("...");   // e.g., USDC
const OUTPUT_MINT = new PublicKey("...");  // e.g., SOL

const titan = new TitanGatewayClient({
  baseUrl: "https://...",
  authToken: "...",
});

const quoteResult = await titan.quoteVaultSwapInstruction({
  inputMint: INPUT_MINT,
  outputMint: OUTPUT_MINT,
  amount: 1_000_000_000n,
  slippageBps: 50,
  ownerPda: vaultPda,
});
```

### Step 2: Execute Swap Through Vault

```typescript theme={null}
const { preInstructions, instruction, postInstructions } =
  await createVaultSyncTransaction({
    instructions: [
      titanAction.swap({
        instruction: quoteResult.instruction,
        addressLookupTableAddresses: quoteResult.addressLookupTableAddresses,
      }),
    ],
    owner: vaultPda,
    connection,
    policyPda,
    vaultPda,
    signer: wallet.publicKey,
    vaultAddress,
  });

const tx = new Transaction().add(...preInstructions, instruction, ...postInstructions);
await sendAndConfirmTransaction(connection, tx, [wallet]);
```
