@rainprotocolsdk/sdk 1.2.0 → 2.0.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.
Files changed (48) hide show
  1. package/README.md +644 -99
  2. package/dist/Rain.d.ts +16 -3
  3. package/dist/Rain.js +46 -4
  4. package/dist/abi/TradeMarketsAbi.d.ts +66 -0
  5. package/dist/abi/TradeMarketsAbi.js +85 -0
  6. package/dist/auth/login.d.ts +4 -0
  7. package/dist/auth/login.js +24 -0
  8. package/dist/auth/types.d.ts +16 -0
  9. package/dist/auth/types.js +1 -0
  10. package/dist/config/environments.d.ts +7 -0
  11. package/dist/config/environments.js +17 -3
  12. package/dist/constants/contractmethods.d.ts +9 -0
  13. package/dist/constants/contractmethods.js +9 -0
  14. package/dist/index.d.ts +1 -0
  15. package/dist/markets/getMarketById.d.ts +2 -0
  16. package/dist/markets/getMarketById.js +12 -0
  17. package/dist/markets/getUserInvestments.d.ts +2 -0
  18. package/dist/markets/getUserInvestments.js +23 -0
  19. package/dist/markets/types.d.ts +21 -0
  20. package/dist/tx/ClaimFunds/buildClaimFundsRawTx.d.ts +2 -0
  21. package/dist/tx/ClaimFunds/buildClaimFundsRawTx.js +34 -0
  22. package/dist/tx/ClaimFunds/helpers.d.ts +8 -0
  23. package/dist/tx/ClaimFunds/helpers.js +37 -0
  24. package/dist/tx/CloseMarket/buildCloseMarketRawTx.d.ts +2 -0
  25. package/dist/tx/CloseMarket/buildCloseMarketRawTx.js +97 -0
  26. package/dist/tx/CloseMarket/helpers.d.ts +2 -0
  27. package/dist/tx/CloseMarket/helpers.js +16 -0
  28. package/dist/tx/CreateMarket/buildCreateMarketRawTx.d.ts +1 -1
  29. package/dist/tx/CreateMarket/buildCreateMarketRawTx.js +17 -6
  30. package/dist/tx/CreateMarket/createMarketValidation.js +18 -4
  31. package/dist/tx/CreateMarket/helpers.d.ts +2 -0
  32. package/dist/tx/CreateMarket/helpers.js +33 -0
  33. package/dist/tx/Dispute/buildDisputeRawTx.d.ts +3 -0
  34. package/dist/tx/Dispute/buildDisputeRawTx.js +59 -0
  35. package/dist/tx/Dispute/helpers.d.ts +1 -0
  36. package/dist/tx/Dispute/helpers.js +9 -0
  37. package/dist/tx/buildApprovalRawTx.d.ts +1 -1
  38. package/dist/tx/buildCancelAllOpenOrdersRawTx.d.ts +2 -0
  39. package/dist/tx/buildCancelAllOpenOrdersRawTx.js +35 -0
  40. package/dist/tx/buildCancelOrdersRawTx.d.ts +2 -0
  41. package/dist/tx/buildCancelOrdersRawTx.js +42 -0
  42. package/dist/tx/buildRawTransactions.d.ts +2 -1
  43. package/dist/tx/buildRawTransactions.js +35 -1
  44. package/dist/tx/types.d.ts +75 -2
  45. package/dist/types.d.ts +1 -0
  46. package/dist/utils/helpers.d.ts +2 -0
  47. package/dist/utils/helpers.js +14 -1
  48. package/package.json +2 -2
package/README.md CHANGED
@@ -30,10 +30,68 @@ yarn add @rainprotocolsdk/sdk
30
30
  ```ts
31
31
  import { Rain } from "@rainprotocolsdk/sdk";
32
32
 
33
- const rain = new Rain();
33
+ const rain = new Rain({ environment: "production" });
34
34
  ```
35
35
 
36
- > The constructor is intentionally empty to allow future configuration without breaking changes.
36
+ ### Constructor Parameters
37
+
38
+ ```ts
39
+ interface RainCoreConfig {
40
+ environment?: "development" | "stage" | "production"; // default: "development"
41
+ rpcUrl?: string; // optional custom RPC URL
42
+ }
43
+ ```
44
+
45
+ ---
46
+
47
+ ## login
48
+
49
+ Authenticates a user against the Rain backend using a wallet signature and returns a JWT access token.
50
+
51
+ The caller is responsible for signing the message — pass the resulting signature along with the wallet addresses.
52
+
53
+ ### Method Signature
54
+
55
+ ```ts
56
+ login(params: LoginParams): Promise<LoginResult>
57
+ ```
58
+
59
+ ### Parameters
60
+
61
+ ```ts
62
+ interface LoginParams {
63
+ signature: string; // personal_sign of the lowercased wallet address
64
+ walletAddress: string; // EOA wallet address
65
+ smartWalletAddress: string; // Smart account / AA wallet address
66
+ referredBy?: string; // Optional referral code
67
+ }
68
+ ```
69
+
70
+ ### Return Type
71
+
72
+ ```ts
73
+ interface LoginResult {
74
+ accessToken: string; // JWT token for authenticated API calls
75
+ userId: string; // Backend user ID
76
+ }
77
+ ```
78
+
79
+ ### Example
80
+
81
+ ```ts
82
+ // 1. Sign the message with your wallet provider
83
+ const signature = await walletClient.signMessage({
84
+ message: walletAddress.toLowerCase(),
85
+ });
86
+
87
+ // 2. Login
88
+ const { accessToken, userId } = await rain.login({
89
+ signature,
90
+ walletAddress: "0x996ea23940f4a01610181D04bdB6F862719b63f0",
91
+ smartWalletAddress: "0xSmartAccountAddress...",
92
+ referredBy: "REFCODE123", // optional
93
+ });
94
+ ```
37
95
 
38
96
  ---
39
97
 
@@ -51,8 +109,8 @@ getPublicMarkets(params: GetMarketsParams): Promise<Market[]>;
51
109
 
52
110
  ```ts
53
111
  interface GetMarketsParams {
54
- limit: number;
55
- offset: number;
112
+ limit?: number;
113
+ offset?: number;
56
114
  sortBy?: "Liquidity" | "Volumn" | "latest";
57
115
  status?: 'Live' | 'New' | 'WaitingForResult' | 'UnderDispute' | 'UnderAppeal' | 'ClosingSoon' | 'InReview' | 'InEvaluation' | 'Closed' | 'Trading';
58
116
  }
@@ -62,95 +120,102 @@ interface GetMarketsParams {
62
120
 
63
121
  ```ts
64
122
  const markets = await rain.getPublicMarkets({
65
- limit?: 12,
66
- offset?: 1,
67
- sortBy?: "Liquidity",
68
- status?: "Live",
123
+ limit: 12,
124
+ offset: 1,
125
+ sortBy: "Liquidity",
126
+ status: "Live",
69
127
  });
70
128
  ```
71
129
 
72
130
  ---
73
131
 
74
- ## buildApprovalTx
132
+ ## getMarketById
75
133
 
76
- ```
77
- Builds a raw ERC20 approval transaction if needed.
134
+ Fetches a single market by its ID from the Rain backend.
78
135
 
79
- This function prepares an unsigned approve(spender, amount) transaction and does not execute it.
136
+ ### Method Signature
80
137
 
81
- If amount is not provided, a default large allowance is approved.
138
+ ```ts
139
+ getMarketById(params: GetMarketByIdParams): Promise<Market>
82
140
  ```
83
141
 
84
- ### Return Type
142
+ ### Parameters
85
143
 
86
144
  ```ts
87
- interface RawTransaction {
88
- to: `0x${string}`;
89
- data: `0x${string}`;
145
+ interface GetMarketByIdParams {
146
+ marketId: string; // MongoDB _id of the market
90
147
  }
91
148
  ```
92
149
 
150
+ ### Validations
151
+
152
+ | Parameter | Type | Required | Description |
153
+ | ---------- | -------- | -------- | ---------------------- |
154
+ | `marketId` | `string` | ✅ | Unique market `_id` |
155
+
93
156
  ### Example
94
157
 
95
158
  ```ts
96
- const approvalTx = rain.buildApprovalTx({
97
- tokenAddress: `0x${string}`, // Approval token address
98
- spender: `0x${string}`, // Market contract address
99
- amount?: 1000000000000000000n // optional parameter
100
- });
159
+ const market = await rain.getMarketById({
160
+ marketId: "698c8f116e985bbfacc7fc01",
161
+ });
101
162
  ```
102
163
 
103
164
  ---
104
165
 
105
- ## buildCreateMarketTx
106
-
107
- Builds a **raw EVM transaction** for creating a market in rain protocol.
166
+ ## getUserInvestments
108
167
 
109
- This function **does not send the transaction** it only prepares calldata.
168
+ Fetches a user's invested markets from the Rain backend. Requires a valid access token.
110
169
 
111
170
  ### Method Signature
112
171
 
113
172
  ```ts
114
- buildCreateMarketTx(params: CreateMarketTxParams): RawTransaction;
173
+ getUserInvestments(params: GetUserInvestmentsParams): Promise<UserInvestment[]>
115
174
  ```
116
175
 
117
176
  ### Parameters
118
177
 
119
178
  ```ts
120
- interface CreateMarketTxParams {
121
- isPublic: boolean;
122
- isPublicPoolResolverAi: boolean;
123
- creator: `0x${string}`;
124
- startTime: number | bigint; // Unix timestamp (seconds)
125
- endTime: number | bigint; // Must be > startTime
126
- options: number; // Number of options (> 0)
127
- ipfsUrl: string; // IPFS CID
128
- inputAmountWei: bigint; // Initial liquidity (token wei)
129
- barValues: (number)[]; // Token Distribution values in options in %
130
- baseToken: `0x${string}`; // ERC20 token address
131
- tokenDecimals?: number; // Optional (default: 6)
179
+ interface GetUserInvestmentsParams {
180
+ walletAddress: string; // User's wallet address
181
+ accessToken: string; // JWT from Rain auth (login)
182
+ limit?: number;
183
+ offset?: number;
184
+ status?: 'Live' | 'New' | 'WaitingForResult' | 'UnderDispute' | 'UnderAppeal' | 'ClosingSoon' | 'InReview' | 'InEvaluation' | 'Closed' | 'Trading';
132
185
  }
133
186
  ```
134
187
 
135
188
  ### Validations
136
189
 
137
- | Field | Type | Required | Description |
138
- | ------------------------ | ------------------ | -------- | -------------------------------- |
139
- | `isPublic` | `boolean` | ✅ | Whether market is public |
140
- | `isPublicPoolResolverAi` | `boolean` | ✅ | AI resolver flag |
141
- | `creator` | `0x${string}` | | Market creator address |
142
- | `startTime` | `number \| bigint` | | Market start timestamp |
143
- | `endTime` | `number \| bigint` | ✅ | Must be greater than `startTime` |
144
- | `options` | `number` | ✅ | Number of market options (> 2) |
145
- | `ipfsUrl` | `string` | ✅ | IPFS CID containing metadata |
146
- | `inputAmountWei` | `bigint` | ✅ | Initial liquidity amount |
147
- | `barValues` | `array` | ✅ | Cannot be empty |
148
- | `baseToken` | `0x${string}` | ✅ | ERC20 base token address |
149
- | `tokenDecimals` | `number` | ❌ | Defaults to `6` |
190
+ | Parameter | Type | Required | Description |
191
+ | --------------- | ------------- | -------- | ------------------------------------ |
192
+ | `walletAddress` | `string` | ✅ | The user's wallet address |
193
+ | `accessToken` | `string` | ✅ | JWT returned from `login()` |
194
+ | `limit` | `number` | | Number of results per page |
195
+ | `offset` | `number` | | Pagination offset |
196
+ | `status` | `MarketStatus`| | Filter by market status |
150
197
 
151
- ### Minimum Liquidity Rule
198
+ ### Example
199
+
200
+ ```ts
201
+ const investments = await rain.getUserInvestments({
202
+ walletAddress: "0x996ea23940f4a01610181D04bdB6F862719b63f0",
203
+ accessToken: "eyJhbGciOi...",
204
+ limit: 10,
205
+ offset: 1,
206
+ status: "Live",
207
+ });
208
+ ```
209
+
210
+ ---
211
+
212
+ ## buildApprovalTx
213
+
214
+ Builds a raw ERC20 approval transaction if needed.
215
+
216
+ This function prepares an unsigned `approve(spender, amount)` transaction and does not execute it.
152
217
 
153
- # inputAmountWei >= 10 tokens
218
+ If `amount` is not provided, a default large allowance is approved.
154
219
 
155
220
  ### Return Type
156
221
 
@@ -164,28 +229,11 @@ interface RawTransaction {
164
229
  ### Example
165
230
 
166
231
  ```ts
167
- rain.buildCreateMarketTx({
168
- isPublic: true,
169
- isPublicPoolResolverAi: false,
170
- creator: "0x996ea23940f4a01610181D04bdB6F862719b63f0",
171
- startTime: 1770836400,
172
- endTime: 1770922800,
173
- options: 3,
174
- ipfsUrl: "QmUdu2eLEQ2qFtNeVVLfVQDBCoc4DT5752enxDitLGmVec",
175
- inputAmountWei: 100000000n,
176
- barValues: [48, 40, 1],
177
- baseToken: "0xCa4f77A38d8552Dd1D5E44e890173921B67725F4"
178
- })
179
- ```
180
-
181
- ### Recommended Execution Pattern
182
-
183
- ```ts
184
- // 1. Build raw transaction
185
- const rawTx = rain.buildCreateMarketTx({...});
186
-
187
- // 2. Execute using your provider
188
- await yourProvider.sendTransaction(rawTx);
232
+ const approvalTx = rain.buildApprovalTx({
233
+ tokenAddress: "0xTokenAddress...", // ERC20 token address
234
+ spender: "0xMarketContractAddress...", // Market contract address
235
+ amount: 1000000000000000000n // optional
236
+ });
189
237
  ```
190
238
 
191
239
  ---
@@ -206,9 +254,9 @@ buildBuyOptionRawTx(params: EnterOptionTxParams): RawTransaction;
206
254
 
207
255
  ```ts
208
256
  interface EnterOptionTxParams {
209
- address: `0x${string}`; // Trademarket contract address
210
- selectedOption: number; // Option index
211
- buyInWei: bigint; // Amount in wei
257
+ marketContractAddress: `0x${string}`; // TradeMarket contract address
258
+ selectedOption: bigint; // Option index
259
+ buyAmountInWei: bigint; // Amount in wei
212
260
  }
213
261
  ```
214
262
 
@@ -225,11 +273,12 @@ interface RawTransaction {
225
273
 
226
274
  ```ts
227
275
  const rawTx = rain.buildBuyOptionRawTx({
228
- address: `0x${string}`,
229
- selectedOption: 1,
230
- buyInWei: 1000000000000000000n,
276
+ marketContractAddress: "0xMarketContractAddress...",
277
+ selectedOption: 1n,
278
+ buyAmountInWei: 1000000n,
231
279
  });
232
280
  ```
281
+
233
282
  ---
234
283
 
235
284
  ## buildLimitBuyOptionTx
@@ -248,22 +297,23 @@ buildLimitBuyOptionTx(params: EnterLimitOptionTxParams): RawTransaction
248
297
 
249
298
  ```ts
250
299
  interface EnterLimitOptionTxParams {
251
- marketContractAddress: `0x${string}`; // market contract address
252
- selectedOption: number; // Option index
253
- pricePerShare: bigint; // price per share
254
- buyAmountInWei: bigint; // total buy amount (already converted to token wei)
255
- tokenDecimals?: number; // token decimals optional (default: `6`)
300
+ marketContractAddress: `0x${string}`; // Market contract address
301
+ selectedOption: number; // Option index
302
+ pricePerShare: number; // Limit price per share (between 0 and 1)
303
+ buyAmountInWei: bigint; // Total buy amount in token wei
304
+ tokenDecimals?: number; // Token decimals (default: 6)
256
305
  }
257
306
  ```
307
+
258
308
  ### Validations
259
309
 
260
310
  | Field | Type | Required | Description |
261
311
  | ----------------------- | ------------- | -------- | ------------------------------------------------------ |
262
- | `marketContractAddress` | `0x${string}` | ✅ | Address of the market contract |
312
+ | `marketContractAddress` | `0x${string}` | ✅ | Address of the market contract |
263
313
  | `selectedOption` | `number` | ✅ | Option index to place the buy order for |
264
314
  | `pricePerShare` | `number` | ✅ | Limit price per share (between `0` and `1`) |
265
315
  | `buyAmountInWei` | `bigint` | ✅ | Total amount to spend (already converted to token wei) |
266
- | `tokenDecimals` | `number` | ❌ | Token decimals optional (default: `6`) |
316
+ | `tokenDecimals` | `number` | ❌ | Token decimals (default: `6`) |
267
317
 
268
318
  ### Return Type
269
319
 
@@ -278,11 +328,499 @@ interface RawTransaction {
278
328
 
279
329
  ```ts
280
330
  rain.buildLimitBuyOptionTx({
281
- marketContractAddress: `0x${string}`,
282
- buyAmountInWei: 1000000,
283
- pricePerShare: 0.1,
284
- selectedOption: 1,
285
- })
331
+ marketContractAddress: "0xMarketContractAddress...",
332
+ selectedOption: 1,
333
+ pricePerShare: 0.6,
334
+ buyAmountInWei: 1000000n,
335
+ });
336
+ ```
337
+
338
+ ---
339
+
340
+ ## buildLimitSellOptionTx
341
+
342
+ Builds a **raw EVM transaction** for placing a limit sell order on a Rain market.
343
+
344
+ This function **does not send the transaction** — it only prepares calldata.
345
+
346
+ ### Method Signature
347
+
348
+ ```ts
349
+ buildLimitSellOptionTx(params: LimitSellOptionTxParams): RawTransaction
350
+ ```
351
+
352
+ ### Parameters
353
+
354
+ ```ts
355
+ interface LimitSellOptionTxParams {
356
+ marketContractAddress: `0x${string}`; // Market contract address
357
+ selectedOption: number; // Option index
358
+ pricePerShare: number; // Limit price per share (between 0 and 1)
359
+ sharesAmountWei: bigint; // Number of shares to sell (in wei)
360
+ tokenDecimals?: number; // Token decimals (default: 6)
361
+ }
362
+ ```
363
+
364
+ ### Validations
365
+
366
+ | Field | Type | Required | Description |
367
+ | ----------------------- | ------------- | -------- | ------------------------------------------- |
368
+ | `marketContractAddress` | `0x${string}` | ✅ | Address of the market contract |
369
+ | `selectedOption` | `number` | ✅ | Option index to place the sell order for |
370
+ | `pricePerShare` | `number` | ✅ | Limit price per share (between `0` and `1`) |
371
+ | `sharesAmountWei` | `bigint` | ✅ | Number of shares to sell (must be `> 0`) |
372
+ | `tokenDecimals` | `number` | ❌ | Token decimals (default: `6`) |
373
+
374
+ ### Return Type
375
+
376
+ ```ts
377
+ interface RawTransaction {
378
+ to: `0x${string}`;
379
+ data: `0x${string}`;
380
+ }
381
+ ```
382
+
383
+ ### Example
384
+
385
+ ```ts
386
+ rain.buildLimitSellOptionTx({
387
+ marketContractAddress: "0xMarketContractAddress...",
388
+ selectedOption: 0,
389
+ pricePerShare: 0.4,
390
+ sharesAmountWei: 500000n,
391
+ });
392
+ ```
393
+
394
+ ---
395
+
396
+ ## buildCancelOrdersTx
397
+
398
+ Builds **raw EVM transactions** to cancel specific open orders on a Rain market.
399
+
400
+ Groups orders by type and returns up to two transactions — one for sell orders (`cancelSellOrders`) and one for buy orders (`cancelBuyOrders`).
401
+
402
+ This function **does not send the transaction** — it only prepares calldata.
403
+
404
+ ### Method Signature
405
+
406
+ ```ts
407
+ buildCancelOrdersTx(params: CancelOrdersTxParams): RawTransaction[]
408
+ ```
409
+
410
+ ### Parameters
411
+
412
+ ```ts
413
+ interface OrderToCancel {
414
+ orderType: 'buy' | 'sell';
415
+ option: bigint; // Option index (e.g. 0n for Yes, 1n for No)
416
+ pricePerShare: bigint; // Price in 18-decimal wei
417
+ orderId: bigint; // externalID from the open order
418
+ }
419
+
420
+ interface CancelOrdersTxParams {
421
+ marketContractAddress: `0x${string}`;
422
+ orders: OrderToCancel[];
423
+ }
424
+ ```
425
+
426
+ ### Validations
427
+
428
+ | Field | Type | Required | Description |
429
+ | ----------------------- | ---------------- | -------- | ------------------------------------- |
430
+ | `marketContractAddress` | `0x${string}` | ✅ | Address of the market contract |
431
+ | `orders` | `OrderToCancel[]`| ✅ | Non-empty array of orders to cancel |
432
+
433
+ ### Return Type
434
+
435
+ ```ts
436
+ RawTransaction[] // 1 tx if only buy or only sell; 2 txs if both
437
+ ```
438
+
439
+ ### Example
440
+
441
+ ```ts
442
+ const txs = rain.buildCancelOrdersTx({
443
+ marketContractAddress: "0xMarketContractAddress...",
444
+ orders: [
445
+ {
446
+ orderType: "buy",
447
+ option: 0n,
448
+ pricePerShare: 600000000000000000n, // 0.6 in 18 decimals
449
+ orderId: 42n,
450
+ },
451
+ {
452
+ orderType: "sell",
453
+ option: 1n,
454
+ pricePerShare: 400000000000000000n,
455
+ orderId: 43n,
456
+ },
457
+ ],
458
+ });
459
+ ```
460
+
461
+ ---
462
+
463
+ ## buildCancelAllOpenOrdersTx
464
+
465
+ Fetches all open orders for a wallet on a given market from the Rain backend and builds the cancel transactions automatically.
466
+
467
+ Returns an empty array if no open orders exist.
468
+
469
+ ### Method Signature
470
+
471
+ ```ts
472
+ buildCancelAllOpenOrdersTx(params: CancelAllOpenOrdersTxParams): Promise<RawTransaction[]>
473
+ ```
474
+
475
+ ### Parameters
476
+
477
+ ```ts
478
+ interface CancelAllOpenOrdersTxParams {
479
+ marketId: string; // MongoDB _id of the market
480
+ marketContractAddress: `0x${string}`; // Market contract address
481
+ walletAddress: `0x${string}`; // User's wallet address
482
+ accessToken: string; // JWT from Rain auth (login)
483
+ }
484
+ ```
485
+
486
+ ### Validations
487
+
488
+ | Field | Type | Required | Description |
489
+ | ----------------------- | ------------- | -------- | ------------------------------------ |
490
+ | `marketId` | `string` | ✅ | MongoDB `_id` from market data |
491
+ | `marketContractAddress` | `0x${string}` | ✅ | Market contract address |
492
+ | `walletAddress` | `0x${string}` | ✅ | Wallet address of the user |
493
+ | `accessToken` | `string` | ✅ | JWT returned from `login()` |
494
+
495
+ ### Return Type
496
+
497
+ ```ts
498
+ RawTransaction[] // empty array if no open orders found
499
+ ```
500
+
501
+ ### Example
502
+
503
+ ```ts
504
+ const txs = await rain.buildCancelAllOpenOrdersTx({
505
+ marketId: "698c8f116e985bbfacc7fc01",
506
+ marketContractAddress: "0xMarketContractAddress...",
507
+ walletAddress: "0x996ea23940f4a01610181D04bdB6F862719b63f0",
508
+ accessToken: "eyJhbGciOi...",
509
+ });
510
+ ```
511
+
512
+ ---
513
+
514
+ ## buildCreateMarketTx
515
+
516
+ Builds a **raw EVM transaction** for creating a market in Rain Protocol.
517
+
518
+ This function **does not send the transaction** — it only prepares calldata.
519
+
520
+ ### Method Signature
521
+
522
+ ```ts
523
+ buildCreateMarketTx(params: CreateMarketTxParams): Promise<RawTransaction[]>
524
+ ```
525
+
526
+ ### Parameters
527
+
528
+ ```ts
529
+ interface CreateMarketTxParams {
530
+ marketQuestion: string;
531
+ marketOptions: string[];
532
+ marketTags: string[];
533
+ marketDescription: string;
534
+ isPublic: boolean;
535
+ isPublicPoolResolverAi: boolean;
536
+ creator: `0x${string}`;
537
+ startTime: bigint; // Unix timestamp (seconds)
538
+ endTime: bigint; // Must be > startTime
539
+ no_of_options: bigint; // Number of options (>= 2)
540
+ inputAmountWei: bigint; // Initial liquidity (token wei)
541
+ barValues: number[]; // Token distribution per option in %
542
+ baseToken: `0x${string}`; // ERC20 token address
543
+ tokenDecimals?: number; // Optional (default: 6)
544
+ }
545
+ ```
546
+
547
+ ### Validations
548
+
549
+ | Field | Type | Required | Description |
550
+ | ------------------------ | ------------------ | -------- | ------------------------------------------ |
551
+ | `marketQuestion` | `string` | ✅ | Market question (cannot be empty) |
552
+ | `marketOptions` | `string[]` | ✅ | List of options (2 to 26) |
553
+ | `marketTags` | `string[]` | ✅ | Tags related to the market (1 to 3) |
554
+ | `marketDescription` | `string` | ✅ | Detailed market description |
555
+ | `isPublic` | `boolean` | ✅ | Whether market is public |
556
+ | `isPublicPoolResolverAi` | `boolean` | ✅ | AI resolver flag |
557
+ | `creator` | `0x${string}` | ✅ | Market creator address |
558
+ | `startTime` | `bigint` | ✅ | Market start timestamp |
559
+ | `endTime` | `bigint` | ✅ | Must be greater than `startTime` |
560
+ | `no_of_options` | `bigint` | ✅ | Number of market options (>= 2) |
561
+ | `inputAmountWei` | `bigint` | ✅ | Initial liquidity (minimum 10 tokens) |
562
+ | `barValues` | `number[]` | ✅ | Cannot be empty |
563
+ | `baseToken` | `0x${string}` | ✅ | ERC20 base token address |
564
+ | `tokenDecimals` | `number` | ❌ | Defaults to `6` |
565
+
566
+ ### Minimum Liquidity Rule
567
+
568
+ #### inputAmountWei >= 10 tokens
569
+
570
+ ### Return Type
571
+
572
+ ```ts
573
+ RawTransaction[] // [approve, createMarket] or [createMarket] depending on allowance
574
+ ```
575
+
576
+ ### Note
577
+
578
+ If the user has not approved the **Rain Factory contract**, the function will return two transactions **(approve + create market)**, but if approval already exists, it will return only one transaction **(create market)**.
579
+
580
+ ### Example
581
+
582
+ ```ts
583
+ const txs = await rain.buildCreateMarketTx({
584
+ marketQuestion: "Will BTC hit 100k?",
585
+ marketOptions: ["Yes", "No"],
586
+ marketTags: ["crypto", "bitcoin"],
587
+ marketDescription: "Prediction market for BTC price",
588
+ isPublic: true,
589
+ isPublicPoolResolverAi: false,
590
+ creator: "0x996ea23940f4a01610181D04bdB6F862719b63f0",
591
+ startTime: 1770836400n,
592
+ endTime: 1770922800n,
593
+ no_of_options: 2n,
594
+ inputAmountWei: 100000000n,
595
+ barValues: [50, 50],
596
+ baseToken: "0xCa4f77A38d8552Dd1D5E44e890173921B67725F4",
597
+ });
598
+ ```
599
+
600
+ ---
601
+
602
+ ## buildClaimTx
603
+
604
+ Builds a **raw EVM transaction** to claim funds from a resolved Rain market.
605
+
606
+ This function **does not send the transaction** — it only prepares calldata.
607
+
608
+ ### Method Signature
609
+
610
+ ```ts
611
+ buildClaimTx(params: ClaimTxParams): Promise<RawTransaction>
612
+ ```
613
+
614
+ ### Parameters
615
+
616
+ ```ts
617
+ interface ClaimTxParams {
618
+ marketId: string;
619
+ walletAddress: `0x${string}`;
620
+ }
621
+ ```
622
+
623
+ ### Validations
624
+
625
+ | Parameter | Type | Required | Description |
626
+ | --------------- | ------------- | -------- | ---------------------------------- |
627
+ | `marketId` | `string` | ✅ | Unique identifier of the market |
628
+ | `walletAddress` | `0x${string}` | ✅ | Address of the user claiming funds |
629
+
630
+ ### Return Type
631
+
632
+ ```ts
633
+ interface RawTransaction {
634
+ to: `0x${string}`;
635
+ data: `0x${string}`;
636
+ }
637
+ ```
638
+
639
+ ### Example
640
+
641
+ ```ts
642
+ const tx = await rain.buildClaimTx({
643
+ marketId: "698c8f116e985bbfacc7fc01",
644
+ walletAddress: "0x996ea23940f4a01610181D04bdB6F862719b63f0",
645
+ });
646
+ ```
647
+
648
+ ---
649
+
650
+ ## buildCloseMarketTx
651
+
652
+ Builds **raw EVM transactions** to close a Rain market and submit the resolution outcome.
653
+
654
+ Handles both V2 and V3 market contracts automatically. For V3 markets, checks token allowances and prepends an approval transaction if needed.
655
+
656
+ This function **does not send the transactions** — it only prepares calldata.
657
+
658
+ ### Method Signature
659
+
660
+ ```ts
661
+ buildCloseMarketTx(params: CloseMarketTxParams): Promise<RawTransaction[]>
662
+ ```
663
+
664
+ ### Parameters
665
+
666
+ ```ts
667
+ interface CloseMarketTxParams {
668
+ marketId: string; // MongoDB _id of the market
669
+ walletAddress: `0x${string}`; // Smart account address
670
+ proposedOutcome?: number; // Winner option index (required for V2 and V3 manual resolver)
671
+ usdtTokenAddress?: `0x${string}`; // Required for V3 USDT markets
672
+ rainTokenAddress?: `0x${string}`; // Required for V3 RAIN markets
673
+ usdtSymbol?: string; // USDT symbol for the environment (e.g. "USDTm")
674
+ tokenDecimals?: number; // Defaults to 6
675
+ }
676
+ ```
677
+
678
+ ### Validations
679
+
680
+ | Field | Type | Required | Description |
681
+ | -------------------- | ------------- | -------- | -------------------------------------------------------- |
682
+ | `marketId` | `string` | ✅ | MongoDB `_id` of the market |
683
+ | `walletAddress` | `0x${string}` | ✅ | Smart account used for allowance checks |
684
+ | `proposedOutcome` | `number` | ⚠️ | Required for V2 markets and V3 manual resolver markets |
685
+ | `usdtTokenAddress` | `0x${string}` | ⚠️ | Required for V3 USDT markets |
686
+ | `rainTokenAddress` | `0x${string}` | ⚠️ | Required for V3 RAIN markets |
687
+ | `usdtSymbol` | `string` | ❌ | Used to detect if market uses USDT as base token |
688
+ | `tokenDecimals` | `number` | ❌ | Defaults to `6` |
689
+
690
+ ### Return Type
691
+
692
+ ```ts
693
+ RawTransaction[] // [approve?, closePool] for V3 or [closePool, chooseWinner] for V2
694
+ ```
695
+
696
+ ### Example
697
+
698
+ ```ts
699
+ // V2 market
700
+ const txs = await rain.buildCloseMarketTx({
701
+ marketId: "698c8f116e985bbfacc7fc01",
702
+ walletAddress: "0x996ea23940f4a01610181D04bdB6F862719b63f0",
703
+ proposedOutcome: 0,
704
+ });
705
+
706
+ // V3 manual resolver with RAIN token
707
+ const txs = await rain.buildCloseMarketTx({
708
+ marketId: "698c8f116e985bbfacc7fc01",
709
+ walletAddress: "0x996ea23940f4a01610181D04bdB6F862719b63f0",
710
+ proposedOutcome: 1,
711
+ rainTokenAddress: "0xRainTokenAddress...",
712
+ usdtSymbol: "USDTm",
713
+ });
714
+ ```
715
+
716
+ ---
717
+
718
+ ## buildCreateDisputeTx
719
+
720
+ Builds **raw EVM transactions** to open a dispute on a Rain market.
721
+
722
+ Checks the user's token allowance against the dispute fee and prepends an approval transaction if needed.
723
+
724
+ This function **does not send the transactions** — it only prepares calldata.
725
+
726
+ ### Method Signature
727
+
728
+ ```ts
729
+ buildCreateDisputeTx(params: CreateDisputeTxParams): Promise<RawTransaction[]>
730
+ ```
731
+
732
+ ### Parameters
733
+
734
+ ```ts
735
+ interface CreateDisputeTxParams {
736
+ marketId: string; // MongoDB _id of the market
737
+ walletAddress: `0x${string}`; // User's wallet address
738
+ usdtTokenAddress?: `0x${string}`; // Required for USDT markets
739
+ rainTokenAddress?: `0x${string}`; // Required for RAIN markets
740
+ usdtSymbol?: string; // Used to detect market token type
741
+ }
742
+ ```
743
+
744
+ ### Validations
745
+
746
+ | Field | Type | Required | Description |
747
+ | ------------------- | ------------- | -------- | -------------------------------------------- |
748
+ | `marketId` | `string` | ✅ | MongoDB `_id` of the market |
749
+ | `walletAddress` | `0x${string}` | ✅ | Address of the user opening the dispute |
750
+ | `usdtTokenAddress` | `0x${string}` | ⚠️ | Required if market uses USDT as base token |
751
+ | `rainTokenAddress` | `0x${string}` | ⚠️ | Required if market uses RAIN as base token |
752
+ | `usdtSymbol` | `string` | ❌ | Used to detect if market uses USDT |
753
+
754
+ ### Return Type
755
+
756
+ ```ts
757
+ RawTransaction[] // [approve?, openDispute]
758
+ ```
759
+
760
+ ### Example
761
+
762
+ ```ts
763
+ const txs = await rain.buildCreateDisputeTx({
764
+ marketId: "698c8f116e985bbfacc7fc01",
765
+ walletAddress: "0x996ea23940f4a01610181D04bdB6F862719b63f0",
766
+ rainTokenAddress: "0xRainTokenAddress...",
767
+ usdtSymbol: "USDTm",
768
+ });
769
+ ```
770
+
771
+ ---
772
+
773
+ ## buildCreateAppealTx
774
+
775
+ Builds **raw EVM transactions** to appeal a dispute resolution on a Rain market.
776
+
777
+ Identical flow to `buildCreateDisputeTx` — checks token allowance against the appeal fee and prepends an approval if needed.
778
+
779
+ This function **does not send the transactions** — it only prepares calldata.
780
+
781
+ ### Method Signature
782
+
783
+ ```ts
784
+ buildCreateAppealTx(params: CreateAppealTxParams): Promise<RawTransaction[]>
785
+ ```
786
+
787
+ ### Parameters
788
+
789
+ ```ts
790
+ interface CreateAppealTxParams {
791
+ marketId: string; // MongoDB _id of the market
792
+ walletAddress: `0x${string}`; // User's wallet address
793
+ usdtTokenAddress?: `0x${string}`; // Required for USDT markets
794
+ rainTokenAddress?: `0x${string}`; // Required for RAIN markets
795
+ usdtSymbol?: string; // Used to detect market token type
796
+ }
797
+ ```
798
+
799
+ ### Validations
800
+
801
+ | Field | Type | Required | Description |
802
+ | ------------------- | ------------- | -------- | -------------------------------------------- |
803
+ | `marketId` | `string` | ✅ | MongoDB `_id` of the market |
804
+ | `walletAddress` | `0x${string}` | ✅ | Address of the user filing the appeal |
805
+ | `usdtTokenAddress` | `0x${string}` | ⚠️ | Required if market uses USDT as base token |
806
+ | `rainTokenAddress` | `0x${string}` | ⚠️ | Required if market uses RAIN as base token |
807
+ | `usdtSymbol` | `string` | ❌ | Used to detect if market uses USDT |
808
+
809
+ ### Return Type
810
+
811
+ ```ts
812
+ RawTransaction[] // [approve?, openDispute]
813
+ ```
814
+
815
+ ### Example
816
+
817
+ ```ts
818
+ const txs = await rain.buildCreateAppealTx({
819
+ marketId: "698c8f116e985bbfacc7fc01",
820
+ walletAddress: "0x996ea23940f4a01610181D04bdB6F862719b63f0",
821
+ rainTokenAddress: "0xRainTokenAddress...",
822
+ usdtSymbol: "USDTm",
823
+ });
286
824
  ```
287
825
 
288
826
  ---
@@ -308,6 +846,8 @@ Raw Transaction
308
846
  RainAA (HOW to execute)
309
847
  ```
310
848
 
849
+ ---
850
+
311
851
  ## Versioning Policy
312
852
 
313
853
  Rain SDK follows **Semantic Versioning**:
@@ -321,12 +861,17 @@ Rain SDK follows **Semantic Versioning**:
321
861
  ## Recommended Usage Pattern
322
862
 
323
863
  ```ts
324
- // 1. Read data / build tx
325
- const rain = new Rain();
326
- const rawTx = rain.buildBuyOptionRawTx(...);
864
+ // 1. Init SDK
865
+ const rain = new Rain({ environment: "production" });
866
+
867
+ // 2. Login
868
+ const { accessToken } = await rain.login({ signature, walletAddress, smartWalletAddress });
327
869
 
328
- // 2. Execute via your provider
329
- await yourprovider.sendTransaction(rawTx);
870
+ // 3. Read data / build tx
871
+ const rawTx = await rain.buildBuyOptionRawTx({ ... });
872
+
873
+ // 4. Execute via your provider
874
+ await yourProvider.sendTransaction(rawTx);
330
875
  ```
331
876
 
332
877
  ---