Skip to content

Repository files navigation

perpX

perpX Logo

The Secondary Market for Kalshi on Solana

Trade Kalshi prediction markets with up to 40x leverage on Solana. A decentralized secondary market bringing real-world prediction markets on-chain on Solana.

Why perpXKalshi IntegrationFeaturesGetting StartedHow It Works


Why perpX?

Kalshi is the first CFTC-regulated prediction market exchange in the US, offering markets on elections, economics, crypto, weather, and more. However, Kalshi has limitations:

Limitation perpX Solution
No leverage trading Up to 40x leverage on any market
US-only access Permissionless - anyone with a Solana wallet
Centralized custody Non-custodial - your keys, your funds
Limited trading hours 24/7 trading on Solana
No short selling (limited) Full long/short on any outcome

perpX creates a decentralized secondary market where anyone can trade Kalshi market outcomes with leverage, bringing the world's most liquid prediction markets to DeFi.


Kalshi Integration

How Markets Are Synced

perpX mirrors Kalshi markets on-chain with a 1:1 mapping:

Kalshi Market (KXBTC-25MAR28-B100000)
         ↓
    perpX Syncs
         ↓
On-Chain Market (Solana)
         ↓
  Trade with Leverage

Real-Time Price Feeds

  • Mark prices are derived from Kalshi's live market prices
  • Settlement prices are determined by Kalshi market outcomes
  • Markets expire and settle based on Kalshi's official resolution

Supported Market Categories

Category Kalshi Series Example Markets
Federal Reserve KXFED Will the Fed raise rates?
Inflation KXCPI CPI above 3%?
Employment KXJOBS Unemployment rate predictions
GDP KXGDP Q4 GDP growth above 2%?
Bitcoin KXBTC BTC above $100k by March?
Ethereum KXETH ETH price milestones
S&P 500 INX Index price targets
Nasdaq NASDAQ100 Tech index predictions

Market Registry

Every Kalshi market is mapped to an on-chain market via the Market Registry:

{
  "KXBTC-25MAR28-B100000": {
    "marketIndex": 52,
    "marketPda": "7xK2...",
    "title": "Bitcoin above $100,000?",
    "expiryTimestamp": 1743148800
  }
}

This ensures:

  • Consistent market identification across platforms
  • Automatic expiry matching with Kalshi
  • Proper settlement based on Kalshi outcomes

Features

Leveraged Trading

  • Trade with 1x to 40x leverage on any Kalshi market
  • Amplify your conviction on prediction market outcomes
  • Capital-efficient trading with isolated margin

Long & Short

  • Go Long (YES): Profit when the outcome probability increases
  • Go Short (NO): Profit when the outcome probability decreases
  • Full flexibility to trade either direction

DeFi Native

  • Non-custodial: Smart contract holds funds, not a centralized exchange
  • Permissionless: No KYC, no geographic restrictions
  • Transparent: All trades and positions visible on-chain
  • Composable: Built on Solana for future DeFi integrations

Risk Management

  • Isolated Margin: Each position has dedicated collateral
  • Liquidation Engine: Automated liquidations protect the protocol
  • Insurance Fund: Backstop for under-collateralized positions
  • No Funding Rates: Unlike perps, no ongoing funding payments

Forced Expiry

  • All positions settle at Kalshi market expiration
  • No indefinite holding - markets have defined end dates
  • Settlement based on real-world Kalshi outcomes

How It Works

1. Market Creation

Kalshi publishes market → perpX syncs to Solana → On-chain market created

2. Trading

User deposits USDC → Opens leveraged position → PnL tracks Kalshi price

3. Settlement

Kalshi market expires → Outcome determined → perpX settles all positions

Price Example

If you believe Bitcoin will be above $100,000 by March 28th:

Kalshi Price Your Position Leverage Collateral Potential PnL
45¢ (45% YES) Long 100 contracts 10x $4.50 USDC +$55 if YES wins

If the market moves to 60¢:

  • Without leverage: +$15 profit (33% return)
  • With 10x leverage: +$150 profit (333% return)

Architecture

perpX/
├── programs/               # Solana smart contracts (Anchor)
│   └── prediction-perps/
│       ├── instructions/   # open_position, close_position, liquidate, settle
│       ├── state/          # Market, Position, Config accounts
│       └── utils/          # Price calculations, margin checks
│
├── app/                    # Next.js frontend
│   ├── components/         # Trading UI, charts, position management
│   ├── lib/
│   │   ├── kalshi.ts       # Kalshi API integration
│   │   └── market-registry.json  # Kalshi → On-chain mapping
│   └── hooks/              # useTrading, usePositions, useKalshiMarkets
│
├── keeper/                 # Automated bot service
│   ├── liquidator.ts       # Monitors and liquidates risky positions
│   ├── settler.ts          # Settles expired markets
│   └── priceUpdater.ts     # Syncs Kalshi prices on-chain
│
└── scripts/
    ├── sync-kalshi-markets.ts   # Bulk sync Kalshi markets
    └── create-new-market.ts     # Create individual market

Getting Started

Prerequisites

  • Node.js 18+
  • Solana wallet (Phantom, Solflare, etc.)
  • Devnet USDC from Circle Faucet

Quick Start

  1. Clone and install

    git clone https://github.com/e-man07/kalshi.git
    cd kalshi/prediction-perps
    yarn install
    cd app && npm install
  2. Run the frontend

    npm run dev
  3. Get test USDC

  4. Start trading

    • Connect wallet at localhost:3000
    • Browse Kalshi markets
    • Open a leveraged position

Syncing New Kalshi Markets

To add new Kalshi markets to perpX:

# Sync all markets from supported categories
npx ts-node scripts/sync-kalshi-markets.ts

# Or add a specific market
npx ts-node scripts/create-new-market.ts KXBTC-25MAR28-B100000

Smart Contract

Program ID: C5aeAdDofqXDwf39wPz21DXajvgu993UeghATenu9xyN

Instructions

Instruction Description
create_market Create on-chain market linked to Kalshi ticker
open_position Open leveraged long/short position
close_position Close position at current mark price
add_margin Add collateral to reduce liquidation risk
liquidate Liquidate undercollateralized position
settle_market Settle market based on Kalshi outcome
claim_settlement Withdraw funds from settled position

Roadmap

  • Core trading engine (open/close positions)
  • Kalshi market sync
  • Liquidation system
  • Settlement system
  • Cross-margin mode
  • Stop-loss / take-profit orders
  • More Kalshi market categories
  • Mainnet deployment

Tech Stack

Component Technology
Smart Contracts Rust, Anchor Framework
Frontend Next.js 14, React, TypeScript
Styling Tailwind CSS
Charts TradingView Lightweight Charts
Blockchain Solana
Collateral USDC
Data Source Kalshi API

Links


Disclaimer

perpX is an experimental DeFi protocol on Solana devnet. It is not affiliated with Kalshi Inc. Trading leveraged positions carries significant risk. Use at your own risk.


Bringing Kalshi to DeFi
Built on Solana

About

The secondary market for Kalshi on Solana - trade predictions with up to 40x leverage.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages