_gamma API

Programmatic access to the gamma protocol for deposits, withdrawals, and portfolio tracking.

Overview

Base URL

https://app.gma.fi/api

Authentication

API keys use Bearer auth. Contact us to get a key. Keys have read or write scope.

Response Format

All responses are JSON with success and data or error fields.

Authentication

All endpoints require an API key. Include it in the Authorization header as a Bearer token.

Header Format
Authorization: Bearer gma_api_...

Scopes

ScopeAccess
readRead-only endpoints (positions, history, NAV, withdraw status)
writeAll endpoints including deposit and withdraw (write implies read)

Error Responses

StatusMeaning
401Missing or invalid API key
403Insufficient scope (e.g. using a read key on a write endpoint)
429Rate limit exceeded
Authenticated Request Example
const API_KEY = 'gma_api_...';

const res = await fetch('https://app.gma.fi/api/positions?wallet=YOUR_WALLET_PUBKEY', {
  headers: {
    'Authorization': `Bearer ${API_KEY}`,
  },
});
const { success, data, error } = await res.json();

if (!success) {
  console.error('API error:', error);
} else {
  console.log('Positions:', data.vaults);
}

Endpoints

GET/api/positions
Get wallet holdings across all vaults+
GET/api/history
Get deposit/withdrawal transaction history+
GET/api/vault/{vault_id}/nav
Get current NAV and pricing for a vault+
POST/api/vault/{vault_id}/deposit
Get an unsigned transaction for depositing USDC+
GET/api/vault/{vault_id}/withdraw
Get withdrawal status for a wallet+
POST/api/vault/{vault_id}/withdraw
Initiate withdrawal or claim pending withdrawal+

Transaction Signing Guide (TypeScript)

The deposit and withdraw endpoints return unsigned transactions that you must sign and submit.

Complete Example: Deposit Flow
import { Connection, VersionedTransaction } from '@solana/web3.js';

// 1. Fetch the unsigned transaction from our API
const response = await fetch('https://app.gma.fi/api/vault/GPZW7ihHMMfZg5eNDmn376mwVzBKHh867vdWmjvNvYPK/deposit', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    wallet: wallet.publicKey.toBase58(),
    amount: 100_000_000  // 100 USDC in lamports (6 decimals)
  })
});
const { data } = await response.json();

// 2. Decode the base64 transaction
const txBytes = Buffer.from(data.transaction, 'base64');
const transaction = VersionedTransaction.deserialize(txBytes);

// 3. Sign with your wallet
// Option A: Browser wallet (Phantom, Solflare, etc.)
const signedTx = await window.solana.signTransaction(transaction);

// Option B: Keypair (for programmatic/server use)
// import { Keypair } from '@solana/web3.js';
// const keypair = Keypair.fromSecretKey(...);
// transaction.sign([keypair]);

// 4. Send and confirm
const connection = new Connection('https://api.mainnet-beta.solana.com', 'confirmed');
const signature = await connection.sendRawTransaction(signedTx.serialize());

// 5. Wait for confirmation
const confirmation = await connection.confirmTransaction(signature, 'confirmed');
if (confirmation.value.err) {
  throw new Error('Transaction failed');
}

console.log('Transaction confirmed:', signature);
// View on Solscan: https://solscan.io/tx/${signature}
Withdrawal with Status Check
// First, check if there's a pending withdrawal to claim
const statusRes = await fetch(
  'https://app.gma.fi/api/vault/GPZW7ihHMMfZg5eNDmn376mwVzBKHh867vdWmjvNvYPK/withdraw?wallet=' + walletPubkey
);
const { data: status } = await statusRes.json();

if (status.hasPendingWithdrawal && status.canClaimNow) {
  console.log('Claiming pending withdrawal of', status.estimatedUsdcAmount, 'USDC');
}

// Request the withdrawal transaction (will be claim or initiate based on state)
const withdrawRes = await fetch('https://app.gma.fi/api/vault/GPZW7ihHMMfZg5eNDmn376mwVzBKHh867vdWmjvNvYPK/withdraw', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    wallet: walletPubkey,
    sharesAmount: 50_000_000  // Only needed for new withdrawals
  })
});
const { data } = await withdrawRes.json();

console.log('Action:', data.action); // 'initiate' or 'claim'
console.log('Message:', data.message);

// Sign and submit as shown above...

Try It