rain-sdk-v2 2.0.1 → 2.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/README.md CHANGED
@@ -186,7 +186,7 @@ const txsRain = await rain.buildCreateMarketTx({
186
186
  | `inputAmountWei` | `bigint` | Initial liquidity in base token wei |
187
187
  | `disputeTimer` | `number` | Oracle end time duration in seconds (e.g. 259200 = 3 days). Auto-set from environment config |
188
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% per option |
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 |
190
190
  | `baseToken` | `0x${string}` | Base token address (USDT or RAIN) |
191
191
  | `tradingModel` | `TradingModel` | `AMM (0)` or `OrderBook (1)` |
192
192
  | `marketImage` | `string` | Market image URL (required) |
@@ -1068,6 +1068,14 @@ await rain.createDisputeMessage({
1068
1068
  const convo = await rain.getPoolDisputeConvo({ poolId: '...', subPool: '...', limit: 50, offset: 0 }, accessToken);
1069
1069
  ```
1070
1070
 
1071
+ ### Whitelisted Tokens
1072
+
1073
+ ```typescript
1074
+ // Get token price in USD
1075
+ const priceData = await rain.getTokenPrice('0x...'); // token contract address
1076
+ // priceData.data = { price: 0.05 } — USD price per token
1077
+ ```
1078
+
1071
1079
  ---
1072
1080
 
1073
1081
  ## WebSocket Events (Socket.IO)
package/dist/Rain.d.ts CHANGED
@@ -256,4 +256,5 @@ export declare class Rain {
256
256
  getFollowers(params: FollowListParams, accessToken?: string): Promise<import("./api/types.js").ApiResponse<unknown>>;
257
257
  getFollowing(params: FollowListParams, accessToken?: string): Promise<import("./api/types.js").ApiResponse<unknown>>;
258
258
  getFollowStats(params: FollowStatsParams, accessToken?: string): Promise<import("./api/types.js").ApiResponse<unknown>>;
259
+ getTokenPrice(tokenAddress: string): Promise<import("./api/types.js").ApiResponse<unknown>>;
259
260
  }
package/dist/Rain.js CHANGED
@@ -33,6 +33,7 @@ import * as notificationsApi from './api/notifications.js';
33
33
  import * as rainBurnApi from './api/rainBurn.js';
34
34
  import * as disputeApi from './api/dispute.js';
35
35
  import * as followApi from './api/follow.js';
36
+ import * as whitelistedTokensApi from './api/whitelistedTokens.js';
36
37
  const erc20AllowanceAbi = parseAbi(['function allowance(address owner, address spender) view returns (uint256)']);
37
38
  const factoryViewAbi = parseAbi([
38
39
  'function oracleFixedFee() view returns (uint256)',
@@ -87,10 +88,19 @@ export class Rain {
87
88
  if (tokenAddress.toLowerCase() === factoryBaseToken.toLowerCase()) {
88
89
  return { oracleFeePerOption: oracleFeeRaw, liquidityFeeBps: liquidityFeeBps };
89
90
  }
90
- const baseTokenDecimals = await pc.readContract({ address: factoryBaseToken, abi: erc20DecimalsAbi, functionName: 'decimals' });
91
91
  const tokenConfig = this.getTokenConfig(tokenAddress);
92
- const tokenDecimals = BigInt(tokenConfig?.decimals ?? 18);
93
- const oracleFeePerOption = oracleFeeRaw * (10n ** (tokenDecimals - BigInt(baseTokenDecimals)));
92
+ const tokenDecimals = tokenConfig?.decimals ?? 18;
93
+ const baseTokenDecimals = Number(await pc.readContract({ address: factoryBaseToken, abi: erc20DecimalsAbi, functionName: 'decimals' }));
94
+ const priceResponse = await whitelistedTokensApi.getTokenPrice(tokenAddress, { apiUrl: this.apiUrl });
95
+ const tokenPriceUsd = priceResponse.data?.currentprice;
96
+ if (!tokenPriceUsd || tokenPriceUsd <= 0) {
97
+ throw new Error(`Could not fetch price for token ${tokenAddress}`);
98
+ }
99
+ // oracleFeeRaw is in factory base token (USDT) = $value in base token decimals
100
+ // Convert to USD value, then to token amount: feeUsd / tokenPrice * 10^tokenDecimals
101
+ const feeUsd = Number(oracleFeeRaw) / (10 ** baseTokenDecimals);
102
+ const feeInToken = feeUsd / tokenPriceUsd;
103
+ const oracleFeePerOption = BigInt(Math.ceil(feeInToken * (10 ** tokenDecimals)));
94
104
  return { oracleFeePerOption, liquidityFeeBps: liquidityFeeBps };
95
105
  }
96
106
  async buildCreateMarketTx(params) {
@@ -448,4 +458,8 @@ export class Rain {
448
458
  async getFollowStats(params, accessToken) {
449
459
  return followApi.getFollowStats(params, this.cfg(accessToken));
450
460
  }
461
+ // ─── Whitelisted Tokens ─────────────────────────────────────────────────────
462
+ async getTokenPrice(tokenAddress) {
463
+ return whitelistedTokensApi.getTokenPrice(tokenAddress, this.cfg());
464
+ }
451
465
  }
@@ -12,3 +12,4 @@ export * from './notifications.js';
12
12
  export * from './rainBurn.js';
13
13
  export * from './dispute.js';
14
14
  export * from './follow.js';
15
+ export * from './whitelistedTokens.js';
package/dist/api/index.js CHANGED
@@ -12,3 +12,4 @@ export * from './notifications.js';
12
12
  export * from './rainBurn.js';
13
13
  export * from './dispute.js';
14
14
  export * from './follow.js';
15
+ export * from './whitelistedTokens.js';
@@ -0,0 +1,2 @@
1
+ import { ApiConfig, ApiResponse } from './types.js';
2
+ export declare function getTokenPrice(tokenAddress: string, config: ApiConfig): Promise<ApiResponse>;
@@ -0,0 +1,8 @@
1
+ import { buildHeaders, handleResponse } from './helpers.js';
2
+ export async function getTokenPrice(tokenAddress, config) {
3
+ const res = await fetch(`${config.apiUrl}/whitelisted-tokens/get-token-price?tokenAddress=${encodeURIComponent(tokenAddress)}`, {
4
+ method: 'GET',
5
+ headers: buildHeaders(config),
6
+ });
7
+ return handleResponse(res);
8
+ }
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rain-sdk-v2",
3
- "version": "2.0.1",
3
+ "version": "2.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",