@contextwtf/sdk 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,143 @@
1
+ # Context SDK
2
+
3
+ TypeScript SDK for trading on [Context Markets](https://context.markets) — an AI-powered prediction market platform on Base.
4
+
5
+ For the full quickstart guide, API reference, and developer docs, visit [docs.context.markets/developers](https://docs.context.markets/developers).
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @contextwtf/sdk
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ### Read Market Data (no auth)
16
+
17
+ ```ts
18
+ import { ContextClient } from "@contextwtf/sdk";
19
+
20
+ const ctx = new ContextClient();
21
+
22
+ const { markets } = await ctx.markets.list({ query: "elections", status: "active" });
23
+ const book = await ctx.markets.orderbook(markets[0].id);
24
+ const oracle = await ctx.markets.oracle(markets[0].id);
25
+ ```
26
+
27
+ ### Place an Order
28
+
29
+ ```ts
30
+ import { ContextClient } from "@contextwtf/sdk";
31
+
32
+ const ctx = new ContextClient({
33
+ apiKey: process.env.CONTEXT_API_KEY!,
34
+ signer: { privateKey: process.env.CONTEXT_PRIVATE_KEY! as `0x${string}` },
35
+ });
36
+
37
+ await ctx.orders.create({
38
+ marketId: "0x...",
39
+ outcome: "yes",
40
+ side: "buy",
41
+ priceCents: 45, // 45¢
42
+ size: 10, // 10 contracts
43
+ });
44
+ ```
45
+
46
+ Need an API key? Visit [context.markets](https://context.markets) or reach out on Discord.
47
+
48
+ ## API Reference
49
+
50
+ ### `ctx.markets`
51
+
52
+ | Method | Description |
53
+ |--------|-------------|
54
+ | `list(params?)` | Search/filter markets |
55
+ | `get(id)` | Get market details |
56
+ | `quotes(marketId)` | Get bid/ask/last per outcome |
57
+ | `orderbook(marketId)` | Get bid/ask ladder |
58
+ | `simulate(marketId, params)` | Simulate trade for slippage |
59
+ | `priceHistory(marketId, params?)` | OHLCV candle data |
60
+ | `oracle(marketId)` | Get oracle resolution status |
61
+ | `activity(marketId)` | Market event feed |
62
+ | `globalActivity()` | Platform-wide activity |
63
+
64
+ ### `ctx.orders` (requires signer)
65
+
66
+ | Method | Description |
67
+ |--------|-------------|
68
+ | `list(params?)` | Query orders with filters |
69
+ | `listAll(params?)` | Paginate through all orders |
70
+ | `mine(marketId?)` | Your open orders |
71
+ | `allMine(marketId?)` | Paginate all your orders |
72
+ | `create(req)` | Place a signed limit order |
73
+ | `cancel(nonce)` | Cancel by nonce |
74
+ | `cancelReplace(cancelNonce, newOrder)` | Atomic cancel + replace |
75
+ | `bulkCreate(orders)` | Place multiple orders |
76
+ | `bulkCancel(nonces)` | Cancel multiple orders |
77
+
78
+ ### `ctx.portfolio`
79
+
80
+ | Method | Description |
81
+ |--------|-------------|
82
+ | `get(address?)` | Positions across markets (defaults to signer) |
83
+ | `balance(address?)` | USDC balance (defaults to signer) |
84
+
85
+ ### `ctx.account` (requires signer)
86
+
87
+ | Method | Description |
88
+ |--------|-------------|
89
+ | `status()` | Check wallet approval status |
90
+ | `setup()` | Approve contracts for trading |
91
+ | `mintTestUsdc(amount?)` | Mint testnet USDC |
92
+ | `deposit(amount)` | Deposit USDC into Holdings |
93
+ | `withdraw(amount)` | Withdraw USDC from Holdings |
94
+ | `mintCompleteSets(marketId, amount)` | Mint YES+NO token pairs |
95
+ | `burnCompleteSets(marketId, amount)` | Burn pairs to recover USDC |
96
+
97
+ ## Pricing
98
+
99
+ Prices are in **cents** (1-99). Sizes are in **contracts**. The SDK handles on-chain encoding internally.
100
+
101
+ ```
102
+ 45¢ = 45% probability = 0.45 USDC per contract
103
+ ```
104
+
105
+ The SDK also handles outcome index mapping — pass `outcome: "yes"` or `outcome: "no"` and it converts to the correct on-chain `outcomeIndex` for you.
106
+
107
+ ## Examples
108
+
109
+ ```bash
110
+ npx tsx examples/basic-read.ts
111
+ CONTEXT_API_KEY=... CONTEXT_PRIVATE_KEY=0x... npx tsx examples/place-order.ts
112
+ ```
113
+
114
+ | Example | Description |
115
+ |---------|-------------|
116
+ | `basic-read.ts` | Search markets, read quotes/orderbook/oracle (no auth) |
117
+ | `place-order.ts` | Place, query, and cancel orders |
118
+ | `setup-trader-wallet.ts` | Check + auto-approve wallet for trading |
119
+ | `deposit-usdc.ts` | Deposit USDC into Holdings contract |
120
+ | `audit-book.ts` | Audit all active orderbooks and open orders |
121
+ | `watch-markets.ts` | Poll and watch price changes on active markets |
122
+ | `batch-markets.ts` | Fetch quotes, orderbooks, and oracle data in parallel |
123
+
124
+ ## Network
125
+
126
+ Currently targeting **Base Sepolia** (chain ID 84532) testnet.
127
+
128
+ | Contract | Address |
129
+ |----------|---------|
130
+ | USDC | `0xBbee2756d3169CF7065e5E9C4A5EA9b1D1Fd415e` |
131
+ | Holdings | `0x2C65541078F04B56975F31153D8465edD40eC4cF` |
132
+ | Settlement | `0x67b8f94DcaF32800Fa0cD476FBD8c1D1EB2d5209` |
133
+
134
+ ## Development
135
+
136
+ ```bash
137
+ bun install # Install dependencies
138
+ bun run build # Build ESM + CJS + types
139
+ bun run typecheck # Type check
140
+ bun run test # Run tests
141
+ ```
142
+
143
+ Requires Node 18+.