rain-sdk-v2 1.0.2 → 1.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/dist/Rain.d.ts CHANGED
@@ -8,9 +8,12 @@ export declare class Rain {
8
8
  private readonly marketFactory;
9
9
  private readonly apiUrl;
10
10
  private readonly distute_initial_timer;
11
- private readonly oracleFixedFeePerOption;
12
11
  private readonly rpcUrl?;
13
12
  constructor(config?: RainCoreConfig);
13
+ /**
14
+ * Get token config by address. Returns decimals, symbol, and oracle fee.
15
+ */
16
+ getTokenConfig(tokenAddress: `0x${string}`): import("./config/environments.js").TokenConfig | null;
14
17
  buildApprovalTx(params: ApproveTxParams): RawTransaction;
15
18
  buildCreateMarketTx(params: CreateMarketTxParams): Promise<RawTransaction[]>;
16
19
  buildEnterOptionTx(params: EnterOptionTxParams): RawTransaction;
@@ -89,10 +92,18 @@ export declare class Rain {
89
92
  readonly apiUrl: "https://dev2-api.rain.one";
90
93
  readonly market_factory_address: `0x${string}`;
91
94
  readonly dispute_initial_timer: number;
92
- readonly oracle_fixed_fee_per_option: 1000000n;
93
- readonly usdt_symbol: "USDTm";
94
- readonly usdt_token: `0x${string}`;
95
- readonly rain_token: `0x${string}`;
95
+ readonly tokens: {
96
+ readonly usdt: import("./config/environments.js").TokenConfig;
97
+ readonly rain: import("./config/environments.js").TokenConfig;
98
+ };
99
+ } | {
100
+ readonly apiUrl: "https://stg2-api.rain.one";
101
+ readonly market_factory_address: `0x${string}`;
102
+ readonly dispute_initial_timer: number;
103
+ readonly tokens: {
104
+ readonly usdt: import("./config/environments.js").TokenConfig;
105
+ readonly rain: import("./config/environments.js").TokenConfig;
106
+ };
96
107
  };
97
108
  private cfg;
98
109
  findUserByWalletAddress(params: {
package/dist/Rain.js CHANGED
@@ -36,7 +36,6 @@ export class Rain {
36
36
  marketFactory;
37
37
  apiUrl;
38
38
  distute_initial_timer;
39
- oracleFixedFeePerOption;
40
39
  rpcUrl;
41
40
  constructor(config = {}) {
42
41
  const { environment = "development", rpcUrl, apiUrl } = config;
@@ -52,13 +51,28 @@ export class Rain {
52
51
  this.marketFactory = envConfig.market_factory_address;
53
52
  this.apiUrl = apiUrl ?? envConfig.apiUrl;
54
53
  this.distute_initial_timer = envConfig.dispute_initial_timer;
55
- this.oracleFixedFeePerOption = envConfig.oracle_fixed_fee_per_option;
54
+ }
55
+ /**
56
+ * Get token config by address. Returns decimals, symbol, and oracle fee.
57
+ */
58
+ getTokenConfig(tokenAddress) {
59
+ const envConfig = ENV_CONFIG[this.environment];
60
+ const tokens = envConfig.tokens;
61
+ for (const key of Object.keys(tokens)) {
62
+ if (tokens[key].address.toLowerCase() === tokenAddress.toLowerCase()) {
63
+ return tokens[key];
64
+ }
65
+ }
66
+ return null;
56
67
  }
57
68
  buildApprovalTx(params) {
58
69
  return buildApproveRawTx(params);
59
70
  }
60
71
  buildCreateMarketTx(params) {
61
- return buildCreateMarketRawTx({ ...params, factoryContractAddress: this.marketFactory, apiUrl: this.apiUrl, rpcUrl: this.rpcUrl, disputeTimer: this.distute_initial_timer, oracleFixedFeePerOption: this.oracleFixedFeePerOption });
72
+ const tokenConfig = this.getTokenConfig(params.baseToken);
73
+ const oracleFixedFeePerOption = tokenConfig?.oracle_fixed_fee_per_option ?? 1000000n;
74
+ const tokenDecimals = params.tokenDecimals ?? tokenConfig?.decimals ?? 6;
75
+ return buildCreateMarketRawTx({ ...params, tokenDecimals, factoryContractAddress: this.marketFactory, apiUrl: this.apiUrl, rpcUrl: this.rpcUrl, disputeTimer: this.distute_initial_timer, oracleFixedFeePerOption });
62
76
  }
63
77
  buildEnterOptionTx(params) {
64
78
  return buildEnterOptionRawTx(params);
@@ -0,0 +1,6 @@
1
+ import { WalletClient } from 'viem';
2
+ /**
3
+ * Signs the lowercased wallet address using personal_sign.
4
+ * This signature is required for the Rain login API.
5
+ */
6
+ export declare function signLoginMessage(walletClient: WalletClient, walletAddress: `0x${string}`): Promise<string>;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Signs the lowercased wallet address using personal_sign.
3
+ * This signature is required for the Rain login API.
4
+ */
5
+ export async function signLoginMessage(walletClient, walletAddress) {
6
+ const message = walletAddress.toLowerCase();
7
+ const signature = await walletClient.signMessage({
8
+ account: walletAddress,
9
+ message,
10
+ });
11
+ return signature;
12
+ }
@@ -1,15 +1,30 @@
1
- export declare const ALLOWED_ENVIRONMENTS: readonly ["development"];
1
+ export declare const ALLOWED_ENVIRONMENTS: readonly ["development", "stage"];
2
2
  export declare const DEFAULT_RPCS: string[];
3
3
  export declare function getRandomRpc(): string;
4
4
  export declare const USDT_SYMBOL_DEV = "USDTm";
5
+ export interface TokenConfig {
6
+ address: `0x${string}`;
7
+ symbol: string;
8
+ decimals: number;
9
+ oracle_fixed_fee_per_option: bigint;
10
+ }
5
11
  export declare const ENV_CONFIG: {
6
12
  readonly development: {
7
13
  readonly apiUrl: "https://dev2-api.rain.one";
8
14
  readonly market_factory_address: `0x${string}`;
9
15
  readonly dispute_initial_timer: number;
10
- readonly oracle_fixed_fee_per_option: 1000000n;
11
- readonly usdt_symbol: "USDTm";
12
- readonly usdt_token: `0x${string}`;
13
- readonly rain_token: `0x${string}`;
16
+ readonly tokens: {
17
+ readonly usdt: TokenConfig;
18
+ readonly rain: TokenConfig;
19
+ };
20
+ };
21
+ readonly stage: {
22
+ readonly apiUrl: "https://stg2-api.rain.one";
23
+ readonly market_factory_address: `0x${string}`;
24
+ readonly dispute_initial_timer: number;
25
+ readonly tokens: {
26
+ readonly usdt: TokenConfig;
27
+ readonly rain: TokenConfig;
28
+ };
14
29
  };
15
30
  };
@@ -1,4 +1,4 @@
1
- export const ALLOWED_ENVIRONMENTS = ["development"];
1
+ export const ALLOWED_ENVIRONMENTS = ["development", "stage"];
2
2
  export const DEFAULT_RPCS = [
3
3
  "https://arb1.arbitrum.io/rpc",
4
4
  "https://arbitrum-one.publicnode.com",
@@ -9,26 +9,45 @@ export function getRandomRpc() {
9
9
  return DEFAULT_RPCS[index];
10
10
  }
11
11
  export const USDT_SYMBOL_DEV = "USDTm";
12
- // export const USDT_SYMBOL_PROD = "USD₮0";
13
12
  export const ENV_CONFIG = {
14
13
  development: {
15
14
  apiUrl: "https://dev2-api.rain.one",
16
15
  market_factory_address: "0xBD99441C4116b85dFecA2d6521EC0e2Eb62F0adE",
17
16
  dispute_initial_timer: 1 * 60,
18
- oracle_fixed_fee_per_option: 1000000n, // $1 per option (6 decimals)
19
- usdt_symbol: USDT_SYMBOL_DEV,
20
- usdt_token: "0xCa4f77A38d8552Dd1D5E44e890173921B67725F4",
21
- rain_token: "0x25118290e6A5f4139381D072181157035864099d",
17
+ tokens: {
18
+ usdt: {
19
+ address: "0xCa4f77A38d8552Dd1D5E44e890173921B67725F4",
20
+ symbol: USDT_SYMBOL_DEV,
21
+ decimals: 6,
22
+ oracle_fixed_fee_per_option: 1000000n, // $1 in 6 decimals
23
+ },
24
+ rain: {
25
+ address: "0x25118290e6A5f4139381D072181157035864099d",
26
+ symbol: "RAIN",
27
+ decimals: 18,
28
+ oracle_fixed_fee_per_option: 1000000000000000000n, // $1 in 18 decimals
29
+ },
30
+ },
31
+ },
32
+ stage: {
33
+ apiUrl: "https://stg2-api.rain.one",
34
+ market_factory_address: "0x4b936AB5114F3DFa2A010117Afeb47F746842884",
35
+ dispute_initial_timer: 1 * 60,
36
+ tokens: {
37
+ usdt: {
38
+ address: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
39
+ symbol: "USD₮0",
40
+ decimals: 6,
41
+ oracle_fixed_fee_per_option: 1000000n,
42
+ },
43
+ rain: {
44
+ address: "0x43976a124e6834b541840Ce741243dAD3dd538DA",
45
+ symbol: "RAIN",
46
+ decimals: 18,
47
+ oracle_fixed_fee_per_option: 1000000000000000000n,
48
+ },
49
+ },
22
50
  },
23
- // stage: {
24
- // apiUrl: "https://stg-api.rain.one",
25
- // market_factory_address: "0xD4900CA167228365806FBA4cB21f7EAe8b6d96BE" as `0x${string}`,
26
- // dispute_initial_timer: 1 * 60,
27
- // oracle_fixed_fee_per_option: 1_000_000n, // $1 per option (6 decimals)
28
- // usdt_symbol: USDT_SYMBOL_PROD,
29
- // usdt_token: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9" as `0x${string}`,
30
- // rain_token: "0x43976a124e6834b541840Ce741243dAD3dd538DA" as `0x${string}`,
31
- // },
32
51
  // production: {
33
52
  // apiUrl: "https://prod-api.rain.one",
34
53
  // market_factory_address: "0xA8640B62D755e42C9ed6A86d0fc65CE09e31F264" as `0x${string}`,
package/dist/index.d.ts CHANGED
@@ -4,6 +4,8 @@ export * from './types.js';
4
4
  export { TradingModel, OptionSide } from './tx/types.js';
5
5
  export type { CreateMarketTxParams, EnterOptionTxParams, AddLiquidityTxParams, RemoveLiquidityTxParams, SplitTxParams, MergeTxParams, ClosePoolAITxParams, ClosePoolManualTxParams, ChooseWinnerTxParams, PlaceBuyOrderTxParams, PlaceSellOrderTxParams, OpenDisputeTxParams, ClaimTxParams, CancelBuyOrdersTxParams, CancelSellOrdersTxParams, RawTransaction, ApproveTxParams } from './tx/types.js';
6
6
  export type { LoginParams, LoginResult } from './auth/types.js';
7
+ export { signLoginMessage } from './auth/signMessage.js';
8
+ export type { TokenConfig } from './config/environments.js';
7
9
  export * from './api/index.js';
8
10
  export { RainSocket } from './socket/RainSocket.js';
9
11
  export type { RainSocketEvent, EnterOptionEventData, ExitOptionEventData, LiquidityEventData, SplitEventData, MergeEventData, RemoveLiquidityEventData, SyncPriceEventData, OrderCreatedEventData, OrderCancelledEventData, OrderFilledEventData, PoolClosedEventData, PoolEventData, WinnerEventData, DisputeOpenedEventData, OracleCreatedEventData, AppealOpenedEventData, DisputeWinnerEventData, AppealWinnerEventData, ClaimRewardEventData, DisputeRefundEventData } from './socket/RainSocket.js';
package/dist/index.js CHANGED
@@ -2,5 +2,6 @@ export { Rain } from './Rain.js';
2
2
  export { RainAA } from './RainAA.js';
3
3
  export * from './types.js';
4
4
  export { TradingModel, OptionSide } from './tx/types.js';
5
+ export { signLoginMessage } from './auth/signMessage.js';
5
6
  export * from './api/index.js';
6
7
  export { RainSocket } from './socket/RainSocket.js';
@@ -11,8 +11,8 @@ export function validateCreateMarketParams(params) {
11
11
  throw new Error("question is required");
12
12
  if (!marketDescription)
13
13
  throw new Error("description is required");
14
- if (!Array.isArray(marketOptions) || marketOptions.length < 3 || marketOptions.length > 26) {
15
- throw new Error("options must be between 3 and 26");
14
+ if (!Array.isArray(marketOptions) || marketOptions.length < 2 || marketOptions.length > 26) {
15
+ throw new Error("options must be between 2 and 26");
16
16
  }
17
17
  if (marketOptions.some(opt => !opt?.toString().trim())) {
18
18
  throw new Error("options cannot contain empty values");
@@ -39,8 +39,10 @@ export function validateCreateMarketParams(params) {
39
39
  throw new Error("factoryContractAddress is required");
40
40
  const decimals = tokenDecimals ?? 6;
41
41
  const oneTokenInWei = 10n ** BigInt(decimals);
42
- if (inputAmountWei < oneTokenInWei * 10n) {
43
- throw new Error("Market cannot be opened: inputAmountWei must be at least $10");
42
+ // $0.1 minimum for dev/stage, validation for production handled separately
43
+ const minAmount = oneTokenInWei / 10n; // 0.1 token
44
+ if (inputAmountWei < minAmount) {
45
+ throw new Error("Market cannot be opened: inputAmountWei must be at least $0.1");
44
46
  }
45
47
  if (startTime >= endTime)
46
48
  throw new Error("startTime must be earlier than endTime");
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";
10
+ export type RainEnvironment = "development" | "stage";
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": "1.0.2",
3
+ "version": "1.0.3",
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",