SDK Reference

Complete TypeScript SDK for interacting with GPMIN.

Installation

npm install @galaxia-predictions-market/sdk

Initialization

import { GalaxiaPredictionsSDK, MarketType } from '@galaxia-predictions-market/sdk';
import { Connection, Wallet } from '@solana/web3.js';

const connection = new Connection('https://api.devnet.solana.com');
const wallet = new Wallet(keypair);
const sdk = new GalaxiaPredictionsSDK(connection, wallet);

Market Operations

Create Market

const tx = await sdk.createMarket({
  marketId: 'unique-market-id',
  question: 'Will X happen?',
  marketType: MarketType.BINARY,
  outcomes: ['Yes', 'No'],
  endTime: Math.floor(Date.now() / 1000) + 31536000,
  oracle: new PublicKey('oracle-address'),
});

Get Market

const market = await sdk.getMarket('market-id');
console.log(market.question, market.outcomes);

Get All Markets

const markets = await sdk.getMarkets();
markets.forEach(market => {
  console.log(market.question);
});

Trading Operations

Execute Trade

const tx = await sdk.trade({
  marketId: 'market-id',
  outcomeIndex: 0, // Index of the outcome
  amount: 1000000, // Amount in smallest unit (1 GXA = 1e9)
});

Get Trading History

// Get all trades
const allTrades = await sdk.getTradingHistory();

// Get trades for specific market
const marketTrades = await sdk.getTradingHistory('market-id');

Liquidity Operations

Add Liquidity

const tx = await sdk.addLiquidity({
  marketId: 'market-id',
  amount: 1000000,
});

Remove Liquidity

const tx = await sdk.removeLiquidity('market-id', 1000000);

Get Liquidity Pools

const pools = await sdk.getLiquidityPools();
pools.forEach(pool => {
  console.log(pool.marketId, pool.totalLiquidity);
});

Settlement Operations

Resolve Market

// Only oracle can resolve
const tx = await sdk.resolveMarket('market-id', 0); // 0 = first outcome

Redeem Outcome Tokens

// After market is resolved, redeem winning tokens
const tx = await sdk.redeemOutcomeTokens('market-id');

TypeScript Types

export enum MarketType {
  BINARY = 'binary',
  MULTIPLE_CHOICE = 'multipleChoice',
  SCALAR = 'scalar',
}

export interface MarketConfig {
  marketId: string;
  question: string;
  marketType: MarketType;
  outcomes: string[];
  endTime: number;
  oracle: PublicKey;
}

export interface TradeParams {
  marketId: string;
  outcomeIndex: number;
  amount: number;
}