@moxie-markets/sdk
v0.1.0
Published
TypeScript SDK for Moxie Markets Prediction Perp DEX
Downloads
12
Readme
Prediction Perp DEX SDK
The TypeScript SDK for interacting with the Moxie Markets Prediction Perp DEX on Solana. This SDK provides a comprehensive interface for traders, keepers, and protocol administrators.
Features
- Protocol Management: Initialize protocol, add markets, update global state
- User Operations: Deposit/withdraw collateral, place orders (limit/market), manage positions
- Polymarket Integration: Fetch real-world prediction markets and prices
- Keeper Services: Automated price updates, liquidations, funding rate updates, and order matching
Installation
npm install @moxie-markets/sdkPrerequisites
Before running any tests or scripts, ensure you have a local Solana validator running and the program deployed.
Start Local Validator:
solana-test-validatorDeploy Program: In the root of the project (parent directory):
anchor build anchor deploy
Testing Guide
We provide several scripts to test different parts of the system.
🚀 End-to-End Test (Recommended)
The best way to see the system in action. This script fetches live data from Polymarket, creates a corresponding market on Solana, and performs a full lifecycle test (deposit, trade, settle).
npm run test:e2e
# or
npx ts-node test-e2e-polymarket.ts🤖 Keeper Service Test
Tests the automated keeper functionality including price updates, liquidations, and order filling.
npm run test:keeper
# or
npx ts-node test-keeper.ts🔮 Polymarket Data Test
Fetches popular markets from Polymarket to verify API connectivity and data format.
npm run test:polymarket
# or
npx ts-node test-polymarket.ts🛠️ Basic SDK Integration
Simple test for basic protocol initialization and user operations (deposit/withdraw) without external dependencies.
npm run test:integration
# or
npx ts-node test-sdk.tsUsage Example
import { Connection, Keypair } from "@solana/web3.js";
import { PredictionClient, IWallet } from "@pred-perp-dex/sdk";
// 1. Setup connection
const connection = new Connection("http://127.0.0.1:8899", "confirmed");
// 2. Initialize Client
const client = new PredictionClient({
connection,
wallet: myWallet, // IWallet interface
});
// 3. User Operations
await client.initializeUser();
await client.deposit(solToLamports(1));
// 4. Place Order
await client.placeOrder({
marketIndex: 0,
direction: PositionDirection.Long,
orderType: OrderType.Limit,
baseAssetAmount: new BN(10_000_000), // 0.1 units
price: new BN(500_000), // $0.50
reduceOnly: false,
postOnly: false,
});Protocol Initialization
To initialize the protocol on a new network (localnet or devnet):
# For localnet
npm run init:localnet
# For devnet
npm run init:devnetExtensive Docs/Guide
Coming soon...
