rain-sdk-v2 2.0.2 → 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 +8 -0
- package/dist/Rain.d.ts +1 -0
- package/dist/Rain.js +17 -3
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +1 -0
- package/dist/api/whitelistedTokens.d.ts +2 -0
- package/dist/api/whitelistedTokens.js +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -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 =
|
|
93
|
-
const
|
|
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
|
}
|
package/dist/api/index.d.ts
CHANGED
package/dist/api/index.js
CHANGED
|
@@ -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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rain-sdk-v2",
|
|
3
|
-
"version": "2.0.
|
|
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",
|