rain-sdk-v2 2.0.0 → 2.0.2

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
@@ -23,7 +23,7 @@ import { arbitrum } from 'viem/chains';
23
23
 
24
24
  // Initialize SDK
25
25
  const rain = new Rain({
26
- environment: 'development', // 'development' | 'stage'
26
+ environment: 'development', // 'development' | 'stage' | 'production'
27
27
  rpcUrl: 'https://arb1.arbitrum.io/rpc', // optional, uses random public RPC if omitted
28
28
  });
29
29
 
@@ -56,7 +56,7 @@ const rain = new Rain(config?: RainCoreConfig);
56
56
 
57
57
  | Parameter | Type | Default | Description |
58
58
  |-----------|------|---------|-------------|
59
- | `environment` | `'development' \| 'stage'` | `'development'` | Target environment |
59
+ | `environment` | `'development' \| 'stage' \| 'production'` | `'development'` | Target environment |
60
60
  | `rpcUrl` | `string` | Random public RPC | Custom Arbitrum RPC URL |
61
61
  | `apiUrl` | `string` | From environment | Custom API URL |
62
62
 
@@ -151,9 +151,10 @@ const txs = await rain.buildCreateMarketTx({
151
151
  startTime: BigInt(Math.floor(Date.now() / 1000) + 120), // 2 min from now
152
152
  endTime: BigInt(Math.floor(Date.now() / 1000) + 86400), // 24h from now
153
153
  no_of_options: 2n,
154
- disputeTimer: 60, // seconds (set by SDK from environment)
154
+ disputeTimer: 259200, // oracle end time duration in seconds (e.g. 259200 = 3 days)
155
155
  inputAmountWei: parseUnits('10', 6), // 10 USDT
156
156
  barValues: [50, 50], // probability distribution (0-100, sums to 100)
157
+ initialYesPrices: [500000000000000000n, 500000000000000000n], // optional, 1e18 scale (50% = 5e17)
157
158
  baseToken: config.tokens.usdt.address, // USDT
158
159
  tradingModel: TradingModel.AMM, // AMM = 0, OrderBook = 1
159
160
  marketImage: 'https://cdn.example.com/market-image.png',
@@ -183,7 +184,9 @@ const txsRain = await rain.buildCreateMarketTx({
183
184
  | `endTime` | `bigint` | Unix timestamp (seconds) |
184
185
  | `no_of_options` | `bigint` | Number of options |
185
186
  | `inputAmountWei` | `bigint` | Initial liquidity in base token wei |
187
+ | `disputeTimer` | `number` | Oracle end time duration in seconds (e.g. 259200 = 3 days). Auto-set from environment config |
186
188
  | `barValues` | `number[]` | Probability distribution (0-100 scale) |
189
+ | `initialYesPrices` | `bigint[]` | *(Optional)* Initial Yes prices per option in 1e18 scale (e.g. `500000000000000000n` = 50%). Defaults to 50% for AMM. Forced to `0n` for OrderBook |
187
190
  | `baseToken` | `0x${string}` | Base token address (USDT or RAIN) |
188
191
  | `tradingModel` | `TradingModel` | `AMM (0)` or `OrderBook (1)` |
189
192
  | `marketImage` | `string` | Market image URL (required) |
@@ -194,7 +197,7 @@ const txsRain = await rain.buildCreateMarketTx({
194
197
 
195
198
  #### `buildEnterOptionTx(params): Promise<RawTransaction[]>`
196
199
 
197
- Buy shares of an option (AMM trade). Automatically reads the market's base token, checks allowance, and includes approval TX if needed.
200
+ Buy shares of an option (AMM trade). Automatically reads the market's base token, checks allowance, includes approval TX if needed, and calculates slippage protection via on-chain `getEntryShares`.
198
201
 
199
202
  ```typescript
200
203
  const txs = await rain.buildEnterOptionTx({
@@ -203,6 +206,8 @@ const txs = await rain.buildEnterOptionTx({
203
206
  optionSide: OptionSide.Yes, // Yes = 1, No = 2
204
207
  buyAmountInWei: parseUnits('5', 6), // 5 USDT (or parseUnits('5', 18) for RAIN)
205
208
  walletAddress: '0x...', // user's wallet address
209
+ slippageTolerance: 5n, // optional, default 5% — percentage tolerance for minSharesOut
210
+ deadline: 600n, // optional, default 600 (10 min) — duration in seconds
206
211
  });
207
212
  // Returns [approveTx?, enterOptionTx]
208
213
  ```
@@ -214,8 +219,11 @@ const txs = await rain.buildEnterOptionTx({
214
219
  | `optionSide` | `OptionSide` | `Yes (1)` or `No (2)` |
215
220
  | `buyAmountInWei` | `bigint` | Amount in base token wei |
216
221
  | `walletAddress` | `0x${string}` | User's wallet address (for allowance check) |
222
+ | `minSharesOut` | `bigint` | *(Optional)* Minimum shares to receive. Auto-calculated from `getEntryShares` with slippage if not set |
223
+ | `slippageTolerance` | `bigint` | *(Optional)* Slippage percentage (e.g. `5n` = 5%). Default: 5% |
224
+ | `deadline` | `bigint` | *(Optional)* Duration in seconds (e.g. `600n` = 10 min). Default: 600 |
217
225
 
218
- > **Note:** Approval is handled automatically. The SDK reads `baseToken` from the market contract and checks allowance before building transactions.
226
+ > **Note:** Approval is handled automatically. The SDK reads `baseToken` from the market contract and checks allowance before building transactions. Slippage protection is auto-calculated: the SDK calls `getEntryShares` on-chain to get expected shares, then applies the slippage tolerance.
219
227
 
220
228
  ---
221
229
 
@@ -257,7 +265,7 @@ const tx = rain.buildMergeTx({
257
265
 
258
266
  #### `buildAddLiquidityTx(params): Promise<RawTransaction[]>`
259
267
 
260
- Add liquidity to a specific option. Automatically checks allowance and includes approval TX if needed.
268
+ Add liquidity to a specific option. Automatically checks allowance, includes approval TX if needed, and calculates slippage protection from on-chain AMM reserves.
261
269
 
262
270
  ```typescript
263
271
  const txs = await rain.buildAddLiquidityTx({
@@ -265,15 +273,28 @@ const txs = await rain.buildAddLiquidityTx({
265
273
  option: 1n,
266
274
  totalAmountInWei: parseUnits('10', 6), // 10 USDT
267
275
  walletAddress: '0x...', // user's wallet address
276
+ slippageTolerance: 5n, // optional, default 5%
277
+ deadline: 600n, // optional, default 600 (10 min) — duration in seconds
268
278
  });
269
279
  // Returns [approveTx?, addLiquidityTx]
270
280
  ```
271
281
 
272
- > **Note:** Approval is handled automatically.
282
+ | Parameter | Type | Description |
283
+ |-----------|------|-------------|
284
+ | `marketContractAddress` | `0x${string}` | Market contract address |
285
+ | `option` | `bigint` | Option index (1-based) |
286
+ | `totalAmountInWei` | `bigint` | Amount in base token wei |
287
+ | `walletAddress` | `0x${string}` | User's wallet address (for allowance check) |
288
+ | `minYesToDeposit` | `bigint` | *(Optional)* Min yes tokens to deposit. Auto-calculated from reserves if not set |
289
+ | `minNoToDeposit` | `bigint` | *(Optional)* Min no tokens to deposit. Auto-calculated from reserves if not set |
290
+ | `slippageTolerance` | `bigint` | *(Optional)* Slippage percentage (e.g. `5n` = 5%). Default: 5% |
291
+ | `deadline` | `bigint` | *(Optional)* Duration in seconds (e.g. `600n` = 10 min). Default: 600 |
273
292
 
274
- #### `buildRemoveLiquidityTx(params: RemoveLiquidityTxParams): RawTransaction`
293
+ > **Note:** Approval is handled automatically. Slippage protection is auto-calculated from `ammYesReserve`/`ammNoReserve` proportionally.
275
294
 
276
- Remove liquidity by burning LP shares.
295
+ #### `buildRemoveLiquidityTx(params: RemoveLiquidityTxParams): Promise<RawTransaction>`
296
+
297
+ Remove liquidity by burning LP shares. Automatically calculates slippage protection via on-chain `getRemovedLiquidity`.
277
298
 
278
299
  ```typescript
279
300
  const lpShares = await rain.getUserOptionLPShares({
@@ -282,13 +303,25 @@ const lpShares = await rain.getUserOptionLPShares({
282
303
  userAddress: '0x...',
283
304
  });
284
305
 
285
- const tx = rain.buildRemoveLiquidityTx({
306
+ const tx = await rain.buildRemoveLiquidityTx({
286
307
  marketContractAddress: '0x...',
287
308
  option: 1n,
288
309
  lpShares, // raw LP shares amount
310
+ slippageTolerance: 5n, // optional, default 5%
311
+ deadline: 600n, // optional, default 600 (10 min) — duration in seconds
289
312
  });
290
313
  ```
291
314
 
315
+ | Parameter | Type | Description |
316
+ |-----------|------|-------------|
317
+ | `marketContractAddress` | `0x${string}` | Market contract address |
318
+ | `option` | `bigint` | Option index (1-based) |
319
+ | `lpShares` | `bigint` | LP shares to remove |
320
+ | `minYesOut` | `bigint` | *(Optional)* Min yes tokens to receive. Auto-calculated from `getRemovedLiquidity` if not set |
321
+ | `minNoOut` | `bigint` | *(Optional)* Min no tokens to receive. Auto-calculated if not set |
322
+ | `slippageTolerance` | `bigint` | *(Optional)* Slippage percentage (e.g. `5n` = 5%). Default: 5% |
323
+ | `deadline` | `bigint` | *(Optional)* Duration in seconds (e.g. `600n` = 10 min). Default: 600 |
324
+
292
325
  ---
293
326
 
294
327
  ### Order Book
@@ -484,6 +517,19 @@ const yesShares = await rain.getUserOptionShares({
484
517
  });
485
518
  ```
486
519
 
520
+ ### `getOptionClaimed(params): Promise<boolean>`
521
+
522
+ Check if a user has already claimed winnings for a specific option.
523
+
524
+ ```typescript
525
+ const claimed = await rain.getOptionClaimed({
526
+ marketContractAddress: '0x...',
527
+ option: 1n,
528
+ userAddress: '0x...',
529
+ });
530
+ // true if already claimed, false otherwise
531
+ ```
532
+
487
533
  ### `getDynamicPayout(params): Promise<bigint[]>`
488
534
 
489
535
  Get the dynamic payout amounts for a user on a specific option. Returns an array of payout values per side.
@@ -659,8 +705,9 @@ enum OptionSide {
659
705
 
660
706
  | Environment | API | Factory | USDT | RAIN |
661
707
  |-------------|-----|---------|------|------|
662
- | `development` | `https://dev2-api.rain.one` | `0xBD99...0adE` | 6 decimals | 18 decimals |
663
- | `stage` | `https://stg2-api.rain.one` | `0x4b93...2884` | 6 decimals | 18 decimals |
708
+ | `development` | `https://dev2-api.rain.one` | `0xbbDd...f02f` | 6 decimals | 18 decimals |
709
+ | `stage` | `https://stg2-api.rain.one` | `0x16cc...628d` | 6 decimals | 18 decimals |
710
+ | `production` | `https://prod2-api.rain.one` | `0x38B3...C677` | 6 decimals | 18 decimals |
664
711
 
665
712
  ### Supported Tokens
666
713
 
@@ -672,7 +719,7 @@ const config = rain.getEnvironmentConfig();
672
719
  // USDT
673
720
  config.tokens.usdt.address // Token contract address
674
721
  config.tokens.usdt.decimals // 6
675
- config.tokens.usdt.symbol // "USDTm" (dev) or "USD₮0" (stage)
722
+ config.tokens.usdt.symbol // "USDTm" (dev) or "USD₮0" (stage/production)
676
723
 
677
724
  // RAIN
678
725
  config.tokens.rain.address // Token contract address
@@ -692,7 +739,8 @@ config.tokens.rain.symbol // "RAIN"
692
739
  5. Wait for endTime to pass
693
740
  6. Close Pool (buildClosePoolAITx / buildClosePoolManualTx)
694
741
  7. Calculate Winner (buildCalculateWinnerTx)
695
- 8. Claim (buildClaimTx)
742
+ 8. Check if claimed (getOptionClaimed) — optional
743
+ 9. Claim (buildClaimTx)
696
744
  ```
697
745
 
698
746
  If disputed:
package/dist/Rain.d.ts CHANGED
@@ -132,6 +132,14 @@ export declare class Rain {
132
132
  readonly usdt: import("./config/environments.js").TokenConfig;
133
133
  readonly rain: import("./config/environments.js").TokenConfig;
134
134
  };
135
+ } | {
136
+ readonly apiUrl: "https://prod2-api.rain.one";
137
+ readonly market_factory_address: `0x${string}`;
138
+ readonly dispute_initial_timer: number;
139
+ readonly tokens: {
140
+ readonly usdt: import("./config/environments.js").TokenConfig;
141
+ readonly rain: import("./config/environments.js").TokenConfig;
142
+ };
135
143
  };
136
144
  private cfg;
137
145
  findUserByWalletAddress(params: {
@@ -1,4 +1,4 @@
1
- export declare const ALLOWED_ENVIRONMENTS: readonly ["development", "stage"];
1
+ export declare const ALLOWED_ENVIRONMENTS: readonly ["development", "stage", "production"];
2
2
  export declare const DEFAULT_RPCS: string[];
3
3
  export declare function getRandomRpc(): string;
4
4
  export declare const USDT_SYMBOL_DEV = "USDTm";
@@ -1,4 +1,4 @@
1
- export const ALLOWED_ENVIRONMENTS = ["development", "stage"];
1
+ export const ALLOWED_ENVIRONMENTS = ["development", "stage", "production"];
2
2
  export const DEFAULT_RPCS = [
3
3
  "https://arb1.arbitrum.io/rpc",
4
4
  "https://arbitrum-one.publicnode.com",
@@ -37,7 +37,9 @@ export async function buildCreateMarketRawTx(params) {
37
37
  ipfsUri: ipfsUrl,
38
38
  initialLiquidity: inputAmountWei,
39
39
  liquidityPercentages,
40
- initialYesPrices: params.initialYesPrices ?? liquidityPercentages.map(() => 500000000000000000n),
40
+ initialYesPrices: (tradingModel ?? 0) === 1
41
+ ? liquidityPercentages.map(() => 0n)
42
+ : (params.initialYesPrices ?? liquidityPercentages.map(() => 500000000000000000n)),
41
43
  baseToken,
42
44
  tradingModel: tradingModel ?? 0,
43
45
  };
package/dist/types.d.ts CHANGED
@@ -7,7 +7,7 @@ export interface RainConfig {
7
7
  chain: Chain;
8
8
  rpcUrl?: string;
9
9
  }
10
- export type RainEnvironment = "development" | "stage";
10
+ export type RainEnvironment = "development" | "stage" | "production";
11
11
  export interface RainCoreConfig {
12
12
  environment?: RainEnvironment;
13
13
  rpcUrl?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rain-sdk-v2",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "type": "module",
5
5
  "description": "Rain SDK V2 — TypeScript SDK for Rain prediction markets on Arbitrum. Market creation, trading, liquidity, order book, split/merge, dispute, and smart account support.",
6
6
  "main": "dist/index.js",