Skip to main content
The Titan team highly advises everyone to use the Meta Aggregator first as it does simulations and comparisons with multiple routers all in 1.

Setup

Set up your payment handler in just 3 lines:
import { payer } from "@faremeter/rides";
import { decode as msgpackDecode } from "@msgpack/msgpack";

const { PAYER_KEYPAIR } = process.env;
if (!PAYER_KEYPAIR) throw new Error("PAYER_KEYPAIR must be set");

await payer.addLocalWallet(PAYER_KEYPAIR);
@faremeter/rides automatically detects your network, looks up USDC, and sets up payments using your existing wallet. All examples below use payer.fetch().

Example: Get Exchange Info

Query exchange information from Titan:
const url = "https://titan-exchange.api.corbits.dev/api/v1/info";

const response = await payer.fetch(url, {
  method: "GET",
  headers: {
    Accept: "application/msgpack"  // or "application/json"
  }
});

if (!response.ok) {
  const text = await response.text().catch(() => "");
  throw new Error(`HTTP ${response.status} ${response.statusText} ${text}`);
}

// Handle MessagePack response
const buffer = await response.arrayBuffer();
const data = msgpackDecode(new Uint8Array(buffer));

console.log("Titan Exchange Info:", JSON.stringify(data, null, 2));

Handling MessagePack Response

Titan Exchange API uses MessagePack format. You must decode the response using a MessagePack library:
const response = await payer.fetch(url, {
  method: "GET",
  headers: {
    Accept: "application/msgpack"
  }
});

const buffer = await response.arrayBuffer();
const data = msgpackDecode(new Uint8Array(buffer));
console.log(data);

Example Response

{
  "protocolVersion": {
    "major": 1,
    "minor": 0,
    "patch": 2
  },
  "settings": {
    "quoteUpdate": {
      "intervalMs": {
        "min": 400,
        "max": 3600000,
        "default": 800
      },
      "numQuotes": {
        "min": 1,
        "max": 10,
        "default": 1
      }
    },
    "swap": {
      "slippageBps": {
        "min": 0,
        "max": 10000,
        "default": 100
      },
      "onlyDirectRoutes": false,
      "addSizeConstraint": true,
      "sizeConstraint": 1168
    },
    "transaction": {
      "closeInputTokenAccount": false,
      "createOutputTokenAccount": true
    },
    "connection": {
      "concurrentStreams": 5
    }
  }
}

Payment Flow

  1. Initial Request: Client sends GET request without Bearer token
  2. 402 Response: Proxy returns payment requirements
{
  "accepts": [{
    "network": "solana-mainnet-beta",
    "maxAmountRequired": 10000,
    "asset": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "payTo": "corzHctjX9Wtcrkfxz3Se8zdXqJYCaamWcQA7vwKF7Q"
  }]
}
  1. Payment: payer.fetch() or fetchWithPayer transfers 0.01 USDC on Solana
  2. Request Forwarded: Proxy adds Authorization: Bearer <token> and forwards

Installing MessagePack

To decode MessagePack responses, install the library:
npm install @msgpack/msgpack
import { decode as msgpackDecode } from "@msgpack/msgpack";

External Resources