@limitless-exchange/sdk 0.0.1 → 0.0.3

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 CHANGED
@@ -54,6 +54,12 @@ import { HttpClient, MarketFetcher } from '@limitless-exchange/sdk';
54
54
  // Create HTTP client (no authentication needed)
55
55
  const httpClient = new HttpClient({
56
56
  baseURL: 'https://api.limitless.exchange',
57
+
58
+ // Optional: Add custom headers to all requests
59
+ additionalHeaders: {
60
+ 'X-Custom-Header': 'my-value',
61
+ 'X-API-Version': 'v1',
62
+ },
57
63
  });
58
64
 
59
65
  const marketFetcher = new MarketFetcher(httpClient);
@@ -111,15 +117,75 @@ const result = await authenticator.authenticate({
111
117
  });
112
118
  ```
113
119
 
120
+ ### Token Approvals
121
+
122
+ **Important**: Before placing orders, you must approve tokens for the exchange contracts. This is a **one-time setup** per wallet.
123
+
124
+ #### Required Approvals
125
+
126
+ **CLOB Markets:**
127
+ - **BUY orders**: Approve USDC → `market.venue.exchange`
128
+ - **SELL orders**: Approve Conditional Tokens → `market.venue.exchange`
129
+
130
+ **NegRisk Markets:**
131
+ - **BUY orders**: Approve USDC → `market.venue.exchange`
132
+ - **SELL orders**: Approve Conditional Tokens → **both** `market.venue.exchange` AND `market.venue.adapter`
133
+
134
+ #### Quick Setup
135
+
136
+ Run the approval setup script:
137
+
138
+ ```bash
139
+ # Copy .env.example and configure your wallet
140
+ cp docs/code-samples/.env.example docs/code-samples/.env
141
+
142
+ # Edit .env and set your PRIVATE_KEY and market slug
143
+ # Then run the approval script
144
+ npx tsx docs/code-samples/setup-approvals.ts
145
+ ```
146
+
147
+ #### Manual Approval Example
148
+
149
+ ```typescript
150
+ import { ethers } from 'ethers';
151
+ import { MarketFetcher, getContractAddress } from '@limitless-exchange/sdk';
152
+
153
+ // 1. Fetch market to get venue addresses
154
+ const market = await marketFetcher.getMarket('market-slug');
155
+
156
+ // 2. Create contract instances
157
+ const usdc = new ethers.Contract(
158
+ getContractAddress('USDC'),
159
+ ['function approve(address spender, uint256 amount) returns (bool)'],
160
+ wallet
161
+ );
162
+
163
+ const ctf = new ethers.Contract(
164
+ getContractAddress('CTF'),
165
+ ['function setApprovalForAll(address operator, bool approved)'],
166
+ wallet
167
+ );
168
+
169
+ // 3. Approve USDC for BUY orders
170
+ await usdc.approve(market.venue.exchange, ethers.MaxUint256);
171
+
172
+ // 4. Approve CT for SELL orders
173
+ await ctf.setApprovalForAll(market.venue.exchange, true);
174
+
175
+ // 5. For NegRisk SELL orders, also approve adapter
176
+ if (market.negRiskRequestId) {
177
+ await ctf.setApprovalForAll(market.venue.adapter, true);
178
+ }
179
+ ```
180
+
181
+ For complete examples, see [docs/code-samples/setup-approvals.ts](./docs/code-samples/setup-approvals.ts).
182
+
114
183
  ### Trading on NegRisk Markets
115
184
 
116
185
  NegRisk markets are group markets with multiple related outcomes. Here's a quick example:
117
186
 
118
187
  ```typescript
119
- import { OrderClient, MarketFetcher, MarketType, Side, OrderType } from '@limitless-exchange/sdk';
120
-
121
- // Set the NegRisk contract address
122
- process.env.NEGRISK_CONTRACT_ADDRESS = '0x5a38afc17F7E97ad8d6C547ddb837E40B4aEDfC6';
188
+ import { OrderClient, MarketFetcher, Side, OrderType } from '@limitless-exchange/sdk';
123
189
 
124
190
  // 1. Fetch NegRisk group market
125
191
  const marketFetcher = new MarketFetcher(httpClient);
@@ -129,7 +195,7 @@ const groupMarket = await marketFetcher.getMarket('largest-company-end-of-2025-1
129
195
  const appleMarket = groupMarket.markets[0];
130
196
  const marketDetails = await marketFetcher.getMarket(appleMarket.slug);
131
197
 
132
- // 3. Create order client for NegRisk
198
+ // 3. Create order client (contract address from venue)
133
199
  const orderClient = new OrderClient({
134
200
  httpClient,
135
201
  wallet,
@@ -137,7 +203,6 @@ const orderClient = new OrderClient({
137
203
  userId: (authResult.profile as any).id,
138
204
  feeRateBps: (authResult.profile as any).rank?.feeRateBps || 300,
139
205
  },
140
- marketType: MarketType.NEGRISK, // Important: Use NEGRISK
141
206
  });
142
207
 
143
208
  // 4. Place order on submarket (not group!)