rain-sdk-v2 1.0.3 → 1.0.4

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 (2) hide show
  1. package/README.md +76 -21
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -23,14 +23,21 @@ import { arbitrum } from 'viem/chains';
23
23
 
24
24
  // Initialize SDK
25
25
  const rain = new Rain({
26
- environment: 'development', // 'development' | 'stage' | 'production'
26
+ environment: 'development', // 'development' | 'stage'
27
27
  rpcUrl: 'https://arb1.arbitrum.io/rpc', // optional, uses random public RPC if omitted
28
28
  });
29
29
 
30
30
  // Get environment config
31
31
  const config = rain.getEnvironmentConfig();
32
- console.log(config.usdt_token); // USDT contract address
33
32
  console.log(config.market_factory_address); // Factory contract
33
+ console.log(config.tokens.usdt.address); // USDT token address
34
+ console.log(config.tokens.rain.address); // RAIN token address
35
+ console.log(config.tokens.usdt.decimals); // 6
36
+ console.log(config.tokens.rain.decimals); // 18
37
+
38
+ // Get token config by address
39
+ const tokenInfo = rain.getTokenConfig('0x...');
40
+ console.log(tokenInfo?.decimals, tokenInfo?.symbol);
34
41
  ```
35
42
 
36
43
  ---
@@ -49,7 +56,7 @@ const rain = new Rain(config?: RainCoreConfig);
49
56
 
50
57
  | Parameter | Type | Default | Description |
51
58
  |-----------|------|---------|-------------|
52
- | `environment` | `'development' \| 'stage' \| 'production'` | `'development'` | Target environment |
59
+ | `environment` | `'development' \| 'stage'` | `'development'` | Target environment |
53
60
  | `rpcUrl` | `string` | Random public RPC | Custom Arbitrum RPC URL |
54
61
  | `apiUrl` | `string` | From environment | Custom API URL |
55
62
 
@@ -130,9 +137,12 @@ interface RawTransaction {
130
137
  Creates a new prediction market. Returns approval TX (if needed) + createPool TX.
131
138
 
132
139
  ```typescript
140
+ const config = rain.getEnvironmentConfig();
141
+
142
+ // Create market with USDT (6 decimals)
133
143
  const txs = await rain.buildCreateMarketTx({
134
144
  marketQuestion: 'Will ETH reach $5000 by end of 2025?',
135
- marketOptions: ['Yes', 'No', 'Maybe'],
145
+ marketOptions: ['Yes', 'No'],
136
146
  marketTags: ['crypto'],
137
147
  marketDescription: 'Prediction on ETH price target',
138
148
  isPublic: true,
@@ -140,21 +150,29 @@ const txs = await rain.buildCreateMarketTx({
140
150
  creator: '0x...', // smart account or EOA address
141
151
  startTime: BigInt(Math.floor(Date.now() / 1000) + 120), // 2 min from now
142
152
  endTime: BigInt(Math.floor(Date.now() / 1000) + 86400), // 24h from now
143
- no_of_options: 3n,
153
+ no_of_options: 2n,
144
154
  disputeTimer: 60, // seconds (set by SDK from environment)
145
- inputAmountWei: parseUnits('10', 6), // 10 USDT initial liquidity
146
- barValues: [33.33, 33.33, 33.34], // probability distribution (0-100, sums to 100)
147
- baseToken: config.usdt_token, // USDT address
155
+ inputAmountWei: parseUnits('10', 6), // 10 USDT
156
+ barValues: [50, 50], // probability distribution (0-100, sums to 100)
157
+ baseToken: config.tokens.usdt.address, // USDT
148
158
  tradingModel: TradingModel.AMM, // AMM = 0, OrderBook = 1
149
159
  });
150
160
 
161
+ // Create market with RAIN token (18 decimals)
162
+ const txsRain = await rain.buildCreateMarketTx({
163
+ ...params,
164
+ inputAmountWei: parseUnits('10', 18), // 10 RAIN
165
+ baseToken: config.tokens.rain.address, // RAIN token
166
+ });
167
+
151
168
  // Approval amount = liquidity + (oracleFixedFeePerOption * numberOfOptions)
169
+ // Oracle fee is automatically calculated based on the token's decimals
152
170
  ```
153
171
 
154
172
  | Parameter | Type | Description |
155
173
  |-----------|------|-------------|
156
174
  | `marketQuestion` | `string` | The market question |
157
- | `marketOptions` | `string[]` | Option labels (3-26 options) |
175
+ | `marketOptions` | `string[]` | Option labels (2-26 options) |
158
176
  | `marketTags` | `string[]` | Tags (1-3) |
159
177
  | `marketDescription` | `string` | Description |
160
178
  | `isPublic` | `boolean` | Public market |
@@ -408,7 +426,7 @@ Build an ERC20 approve transaction.
408
426
 
409
427
  ```typescript
410
428
  const tx = rain.buildApprovalTx({
411
- tokenAddress: config.usdt_token,
429
+ tokenAddress: config.tokens.usdt.address,
412
430
  spender: '0x...', // market contract address
413
431
  amount: parseUnits('100', 6), // 100 USDT
414
432
  });
@@ -424,7 +442,7 @@ Check current ERC20 allowance.
424
442
 
425
443
  ```typescript
426
444
  const allowance = await rain.getTokenAllowance({
427
- tokenAddress: config.usdt_token,
445
+ tokenAddress: config.tokens.usdt.address,
428
446
  owner: '0x...', // your address
429
447
  spender: '0x...', // market contract
430
448
  });
@@ -534,9 +552,22 @@ const result = await rain.checkOrderExists({
534
552
 
535
553
  Wallet-based login to the Rain backend.
536
554
 
555
+ #### `signLoginMessage(walletClient, walletAddress)`
556
+
557
+ Signs the lowercased wallet address using `personal_sign`. This signature is required for login.
558
+
559
+ ```typescript
560
+ import { signLoginMessage } from 'rain-sdk-v2';
561
+
562
+ const walletClient = createWalletClient({ chain: arbitrum, transport: custom(window.ethereum) });
563
+ const signature = await signLoginMessage(walletClient, '0x...' as `0x${string}`);
564
+ ```
565
+
566
+ #### `login(params)`
567
+
537
568
  ```typescript
538
569
  const result = await rain.login({
539
- signature: '0x...', // personal_sign of lowercased wallet address
570
+ signature, // from signLoginMessage
540
571
  walletAddress: '0x...', // EOA address
541
572
  smartWalletAddress: '0x...', // Smart account address
542
573
  referredBy: 'CODE', // optional referral code
@@ -564,10 +595,17 @@ Returns:
564
595
  | `apiUrl` | Backend API URL |
565
596
  | `market_factory_address` | Factory contract address |
566
597
  | `dispute_initial_timer` | Dispute timer in seconds |
567
- | `oracle_fixed_fee_per_option` | Oracle fee per option in base token wei |
568
- | `usdt_symbol` | USDT token symbol |
569
- | `usdt_token` | USDT token address |
570
- | `rain_token` | RAIN token address |
598
+ | `tokens.usdt` | USDT token config (`address`, `symbol`, `decimals`, `oracle_fixed_fee_per_option`) |
599
+ | `tokens.rain` | RAIN token config (`address`, `symbol`, `decimals`, `oracle_fixed_fee_per_option`) |
600
+
601
+ ### `getTokenConfig(tokenAddress)`
602
+
603
+ Looks up token configuration by contract address. Returns `TokenConfig` or `null`.
604
+
605
+ ```typescript
606
+ const tokenInfo = rain.getTokenConfig('0x...');
607
+ // { address, symbol, decimals, oracle_fixed_fee_per_option }
608
+ ```
571
609
 
572
610
  ---
573
611
 
@@ -595,11 +633,28 @@ enum OptionSide {
595
633
 
596
634
  ## Environments
597
635
 
598
- | Environment | API | Factory |
599
- |-------------|-----|---------|
600
- | `development` | `https://dev-api.rain.one` | `0xBD99...0adE` |
601
- | `stage` | `https://stg-api.rain.one` | `0xD490...96BE` |
602
- | `production` | `https://prod-api.rain.one` | `0xA864...F264` |
636
+ | Environment | API | Factory | USDT | RAIN |
637
+ |-------------|-----|---------|------|------|
638
+ | `development` | `https://dev2-api.rain.one` | `0xBD99...0adE` | 6 decimals | 18 decimals |
639
+ | `stage` | `https://stg2-api.rain.one` | `0x4b93...2884` | 6 decimals | 18 decimals |
640
+
641
+ ### Supported Tokens
642
+
643
+ Each environment includes token configs for both **USDT** (6 decimals) and **RAIN** (18 decimals). The SDK automatically handles decimal conversions for oracle fees and minimum liquidity validation based on the token used.
644
+
645
+ ```typescript
646
+ const config = rain.getEnvironmentConfig();
647
+
648
+ // USDT
649
+ config.tokens.usdt.address // Token contract address
650
+ config.tokens.usdt.decimals // 6
651
+ config.tokens.usdt.symbol // "USDTm" (dev) or "USD₮0" (stage)
652
+
653
+ // RAIN
654
+ config.tokens.rain.address // Token contract address
655
+ config.tokens.rain.decimals // 18
656
+ config.tokens.rain.symbol // "RAIN"
657
+ ```
603
658
 
604
659
  ---
605
660
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rain-sdk-v2",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
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",