rain-sdk-v2 1.0.3 → 1.0.5
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,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'
|
|
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'
|
|
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'
|
|
145
|
+
marketOptions: ['Yes', 'No'],
|
|
136
146
|
marketTags: ['crypto'],
|
|
137
147
|
marketDescription: 'Prediction on ETH price target',
|
|
138
148
|
isPublic: true,
|
|
@@ -140,21 +150,30 @@ 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:
|
|
153
|
+
no_of_options: 2n,
|
|
144
154
|
disputeTimer: 60, // seconds (set by SDK from environment)
|
|
145
|
-
inputAmountWei: parseUnits('10', 6), // 10 USDT
|
|
146
|
-
barValues: [
|
|
147
|
-
baseToken: config.
|
|
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
|
|
159
|
+
marketImage: 'https://cdn.example.com/market-image.png',
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// Create market with RAIN token (18 decimals)
|
|
163
|
+
const txsRain = await rain.buildCreateMarketTx({
|
|
164
|
+
...params,
|
|
165
|
+
inputAmountWei: parseUnits('10', 18), // 10 RAIN
|
|
166
|
+
baseToken: config.tokens.rain.address, // RAIN token
|
|
149
167
|
});
|
|
150
168
|
|
|
151
169
|
// Approval amount = liquidity + (oracleFixedFeePerOption * numberOfOptions)
|
|
170
|
+
// Oracle fee is automatically calculated based on the token's decimals
|
|
152
171
|
```
|
|
153
172
|
|
|
154
173
|
| Parameter | Type | Description |
|
|
155
174
|
|-----------|------|-------------|
|
|
156
175
|
| `marketQuestion` | `string` | The market question |
|
|
157
|
-
| `marketOptions` | `string[]` | Option labels (
|
|
176
|
+
| `marketOptions` | `string[]` | Option labels (2-26 options) |
|
|
158
177
|
| `marketTags` | `string[]` | Tags (1-3) |
|
|
159
178
|
| `marketDescription` | `string` | Description |
|
|
160
179
|
| `isPublic` | `boolean` | Public market |
|
|
@@ -165,8 +184,9 @@ const txs = await rain.buildCreateMarketTx({
|
|
|
165
184
|
| `no_of_options` | `bigint` | Number of options |
|
|
166
185
|
| `inputAmountWei` | `bigint` | Initial liquidity in base token wei |
|
|
167
186
|
| `barValues` | `number[]` | Probability distribution (0-100 scale) |
|
|
168
|
-
| `baseToken` | `0x${string}` | Base token address (USDT) |
|
|
187
|
+
| `baseToken` | `0x${string}` | Base token address (USDT or RAIN) |
|
|
169
188
|
| `tradingModel` | `TradingModel` | `AMM (0)` or `OrderBook (1)` |
|
|
189
|
+
| `marketImage` | `string` | Market image URL (required) |
|
|
170
190
|
|
|
171
191
|
---
|
|
172
192
|
|
|
@@ -408,7 +428,7 @@ Build an ERC20 approve transaction.
|
|
|
408
428
|
|
|
409
429
|
```typescript
|
|
410
430
|
const tx = rain.buildApprovalTx({
|
|
411
|
-
tokenAddress: config.
|
|
431
|
+
tokenAddress: config.tokens.usdt.address,
|
|
412
432
|
spender: '0x...', // market contract address
|
|
413
433
|
amount: parseUnits('100', 6), // 100 USDT
|
|
414
434
|
});
|
|
@@ -424,7 +444,7 @@ Check current ERC20 allowance.
|
|
|
424
444
|
|
|
425
445
|
```typescript
|
|
426
446
|
const allowance = await rain.getTokenAllowance({
|
|
427
|
-
tokenAddress: config.
|
|
447
|
+
tokenAddress: config.tokens.usdt.address,
|
|
428
448
|
owner: '0x...', // your address
|
|
429
449
|
spender: '0x...', // market contract
|
|
430
450
|
});
|
|
@@ -534,9 +554,22 @@ const result = await rain.checkOrderExists({
|
|
|
534
554
|
|
|
535
555
|
Wallet-based login to the Rain backend.
|
|
536
556
|
|
|
557
|
+
#### `signLoginMessage(walletClient, walletAddress)`
|
|
558
|
+
|
|
559
|
+
Signs the lowercased wallet address using `personal_sign`. This signature is required for login.
|
|
560
|
+
|
|
561
|
+
```typescript
|
|
562
|
+
import { signLoginMessage } from 'rain-sdk-v2';
|
|
563
|
+
|
|
564
|
+
const walletClient = createWalletClient({ chain: arbitrum, transport: custom(window.ethereum) });
|
|
565
|
+
const signature = await signLoginMessage(walletClient, '0x...' as `0x${string}`);
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
#### `login(params)`
|
|
569
|
+
|
|
537
570
|
```typescript
|
|
538
571
|
const result = await rain.login({
|
|
539
|
-
signature
|
|
572
|
+
signature, // from signLoginMessage
|
|
540
573
|
walletAddress: '0x...', // EOA address
|
|
541
574
|
smartWalletAddress: '0x...', // Smart account address
|
|
542
575
|
referredBy: 'CODE', // optional referral code
|
|
@@ -564,10 +597,17 @@ Returns:
|
|
|
564
597
|
| `apiUrl` | Backend API URL |
|
|
565
598
|
| `market_factory_address` | Factory contract address |
|
|
566
599
|
| `dispute_initial_timer` | Dispute timer in seconds |
|
|
567
|
-
| `
|
|
568
|
-
| `
|
|
569
|
-
|
|
570
|
-
|
|
600
|
+
| `tokens.usdt` | USDT token config (`address`, `symbol`, `decimals`, `oracle_fixed_fee_per_option`) |
|
|
601
|
+
| `tokens.rain` | RAIN token config (`address`, `symbol`, `decimals`, `oracle_fixed_fee_per_option`) |
|
|
602
|
+
|
|
603
|
+
### `getTokenConfig(tokenAddress)`
|
|
604
|
+
|
|
605
|
+
Looks up token configuration by contract address. Returns `TokenConfig` or `null`.
|
|
606
|
+
|
|
607
|
+
```typescript
|
|
608
|
+
const tokenInfo = rain.getTokenConfig('0x...');
|
|
609
|
+
// { address, symbol, decimals, oracle_fixed_fee_per_option }
|
|
610
|
+
```
|
|
571
611
|
|
|
572
612
|
---
|
|
573
613
|
|
|
@@ -595,11 +635,28 @@ enum OptionSide {
|
|
|
595
635
|
|
|
596
636
|
## Environments
|
|
597
637
|
|
|
598
|
-
| Environment | API | Factory |
|
|
599
|
-
|
|
600
|
-
| `development` | `https://
|
|
601
|
-
| `stage` | `https://
|
|
602
|
-
|
|
638
|
+
| Environment | API | Factory | USDT | RAIN |
|
|
639
|
+
|-------------|-----|---------|------|------|
|
|
640
|
+
| `development` | `https://dev2-api.rain.one` | `0xBD99...0adE` | 6 decimals | 18 decimals |
|
|
641
|
+
| `stage` | `https://stg2-api.rain.one` | `0x4b93...2884` | 6 decimals | 18 decimals |
|
|
642
|
+
|
|
643
|
+
### Supported Tokens
|
|
644
|
+
|
|
645
|
+
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.
|
|
646
|
+
|
|
647
|
+
```typescript
|
|
648
|
+
const config = rain.getEnvironmentConfig();
|
|
649
|
+
|
|
650
|
+
// USDT
|
|
651
|
+
config.tokens.usdt.address // Token contract address
|
|
652
|
+
config.tokens.usdt.decimals // 6
|
|
653
|
+
config.tokens.usdt.symbol // "USDTm" (dev) or "USD₮0" (stage)
|
|
654
|
+
|
|
655
|
+
// RAIN
|
|
656
|
+
config.tokens.rain.address // Token contract address
|
|
657
|
+
config.tokens.rain.decimals // 18
|
|
658
|
+
config.tokens.rain.symbol // "RAIN"
|
|
659
|
+
```
|
|
603
660
|
|
|
604
661
|
---
|
|
605
662
|
|
|
@@ -35,6 +35,8 @@ export function validateCreateMarketParams(params) {
|
|
|
35
35
|
throw new Error("barValues array is required and cannot be empty");
|
|
36
36
|
if (!baseToken)
|
|
37
37
|
throw new Error("baseToken address is required");
|
|
38
|
+
if (!params.marketImage)
|
|
39
|
+
throw new Error("marketImage is required");
|
|
38
40
|
if (!factoryContractAddress)
|
|
39
41
|
throw new Error("factoryContractAddress is required");
|
|
40
42
|
const decimals = tokenDecimals ?? 6;
|
|
@@ -20,7 +20,7 @@ export async function uploadMetaData(params) {
|
|
|
20
20
|
startDate: formattedStartDate,
|
|
21
21
|
endDate: formattedEndDate,
|
|
22
22
|
tradingModel: tradingModel ?? 0,
|
|
23
|
-
questionImage: params.
|
|
23
|
+
questionImage: params.marketImage,
|
|
24
24
|
tags: marketTags,
|
|
25
25
|
poolDescription: marketDescription,
|
|
26
26
|
isAiResolver: isPublicPoolResolverAi,
|
package/dist/tx/types.d.ts
CHANGED
|
@@ -108,7 +108,7 @@ export interface CreateMarketTxParams {
|
|
|
108
108
|
barValues: number[];
|
|
109
109
|
baseToken: `0x${string}`;
|
|
110
110
|
tradingModel?: TradingModel;
|
|
111
|
-
|
|
111
|
+
marketImage: string;
|
|
112
112
|
tokenDecimals?: number;
|
|
113
113
|
factoryContractAddress?: `0x${string}`;
|
|
114
114
|
oracleFixedFeePerOption?: bigint;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rain-sdk-v2",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
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",
|