rain-sdk-v2 2.0.2 → 2.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.
- package/README.md +11 -2
- package/dist/Rain.d.ts +4 -1
- package/dist/Rain.js +14 -9
- 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
|
@@ -167,8 +167,9 @@ const txsRain = await rain.buildCreateMarketTx({
|
|
|
167
167
|
baseToken: config.tokens.rain.address, // RAIN token
|
|
168
168
|
});
|
|
169
169
|
|
|
170
|
-
// Approval
|
|
171
|
-
//
|
|
170
|
+
// Approval for USDT: liquidity + (oracleFixedFeePerOption * numberOfOptions)
|
|
171
|
+
// Approval for RAIN: liquidity + (numberOfOptions * 20% of liquidity)
|
|
172
|
+
// e.g. 1000 RAIN with 5 options → 1000 + (5 * 200) = 2000 RAIN approval
|
|
172
173
|
```
|
|
173
174
|
|
|
174
175
|
| Parameter | Type | Description |
|
|
@@ -1068,6 +1069,14 @@ await rain.createDisputeMessage({
|
|
|
1068
1069
|
const convo = await rain.getPoolDisputeConvo({ poolId: '...', subPool: '...', limit: 50, offset: 0 }, accessToken);
|
|
1069
1070
|
```
|
|
1070
1071
|
|
|
1072
|
+
### Whitelisted Tokens
|
|
1073
|
+
|
|
1074
|
+
```typescript
|
|
1075
|
+
// Get token price in USD
|
|
1076
|
+
const priceData = await rain.getTokenPrice('0x...'); // token contract address
|
|
1077
|
+
// priceData.data = { price: 0.05 } — USD price per token
|
|
1078
|
+
```
|
|
1079
|
+
|
|
1071
1080
|
---
|
|
1072
1081
|
|
|
1073
1082
|
## WebSocket Events (Socket.IO)
|
package/dist/Rain.d.ts
CHANGED
|
@@ -15,9 +15,11 @@ export declare class Rain {
|
|
|
15
15
|
*/
|
|
16
16
|
getTokenConfig(tokenAddress: `0x${string}`): import("./config/environments.js").TokenConfig | null;
|
|
17
17
|
buildApprovalTx(params: ApproveTxParams): RawTransaction;
|
|
18
|
-
getCreateMarketFees(tokenAddress: `0x${string}
|
|
18
|
+
getCreateMarketFees(tokenAddress: `0x${string}`, inputAmountWei: bigint): Promise<{
|
|
19
19
|
oracleFeePerOption: bigint;
|
|
20
20
|
liquidityFeeBps: bigint;
|
|
21
|
+
useBufferApproval: boolean;
|
|
22
|
+
perOptionBuffer: bigint;
|
|
21
23
|
}>;
|
|
22
24
|
buildCreateMarketTx(params: CreateMarketTxParams): Promise<RawTransaction[]>;
|
|
23
25
|
buildEnterOptionTx(params: EnterOptionTxParams & {
|
|
@@ -256,4 +258,5 @@ export declare class Rain {
|
|
|
256
258
|
getFollowers(params: FollowListParams, accessToken?: string): Promise<import("./api/types.js").ApiResponse<unknown>>;
|
|
257
259
|
getFollowing(params: FollowListParams, accessToken?: string): Promise<import("./api/types.js").ApiResponse<unknown>>;
|
|
258
260
|
getFollowStats(params: FollowStatsParams, accessToken?: string): Promise<import("./api/types.js").ApiResponse<unknown>>;
|
|
261
|
+
getTokenPrice(tokenAddress: string): Promise<import("./api/types.js").ApiResponse<unknown>>;
|
|
259
262
|
}
|
package/dist/Rain.js
CHANGED
|
@@ -33,13 +33,13 @@ 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)',
|
|
39
40
|
'function liquidityFee() view returns (uint256)',
|
|
40
41
|
'function baseToken() view returns (address)',
|
|
41
42
|
]);
|
|
42
|
-
const erc20DecimalsAbi = parseAbi(['function decimals() view returns (uint8)']);
|
|
43
43
|
export class Rain {
|
|
44
44
|
environment;
|
|
45
45
|
marketFactory;
|
|
@@ -77,7 +77,7 @@ export class Rain {
|
|
|
77
77
|
buildApprovalTx(params) {
|
|
78
78
|
return buildApproveRawTx(params);
|
|
79
79
|
}
|
|
80
|
-
async getCreateMarketFees(tokenAddress) {
|
|
80
|
+
async getCreateMarketFees(tokenAddress, inputAmountWei) {
|
|
81
81
|
const pc = createPublicClient({ chain: arbitrum, transport: http(this.rpcUrl) });
|
|
82
82
|
const [oracleFeeRaw, liquidityFeeBps, factoryBaseToken] = await Promise.all([
|
|
83
83
|
pc.readContract({ address: this.marketFactory, abi: factoryViewAbi, functionName: 'oracleFixedFee' }),
|
|
@@ -85,18 +85,19 @@ export class Rain {
|
|
|
85
85
|
pc.readContract({ address: this.marketFactory, abi: factoryViewAbi, functionName: 'baseToken' }),
|
|
86
86
|
]);
|
|
87
87
|
if (tokenAddress.toLowerCase() === factoryBaseToken.toLowerCase()) {
|
|
88
|
-
return { oracleFeePerOption: oracleFeeRaw, liquidityFeeBps: liquidityFeeBps };
|
|
88
|
+
return { oracleFeePerOption: oracleFeeRaw, liquidityFeeBps: liquidityFeeBps, useBufferApproval: false, perOptionBuffer: 0n };
|
|
89
89
|
}
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
const oracleFeePerOption = oracleFeeRaw * (10n ** (tokenDecimals - BigInt(baseTokenDecimals)));
|
|
94
|
-
return { oracleFeePerOption, liquidityFeeBps: liquidityFeeBps };
|
|
90
|
+
// For non-base tokens (e.g. RAIN): approval = initialLiquidity + (numberOfOptions * 20% of initialLiquidity)
|
|
91
|
+
const perOptionBuffer = inputAmountWei * 20n / 100n;
|
|
92
|
+
return { oracleFeePerOption: 0n, liquidityFeeBps: liquidityFeeBps, useBufferApproval: true, perOptionBuffer };
|
|
95
93
|
}
|
|
96
94
|
async buildCreateMarketTx(params) {
|
|
97
95
|
const tokenConfig = this.getTokenConfig(params.baseToken);
|
|
98
96
|
const tokenDecimals = params.tokenDecimals ?? tokenConfig?.decimals ?? 6;
|
|
99
|
-
const { oracleFeePerOption, liquidityFeeBps } = await this.getCreateMarketFees(params.baseToken);
|
|
97
|
+
const { oracleFeePerOption, liquidityFeeBps, useBufferApproval, perOptionBuffer } = await this.getCreateMarketFees(params.baseToken, params.inputAmountWei);
|
|
98
|
+
if (useBufferApproval) {
|
|
99
|
+
return buildCreateMarketRawTx({ ...params, tokenDecimals, factoryContractAddress: this.marketFactory, apiUrl: this.apiUrl, rpcUrl: this.rpcUrl, disputeTimer: this.distute_initial_timer, oracleFixedFeePerOption: perOptionBuffer });
|
|
100
|
+
}
|
|
100
101
|
const liquidityFeeAmount = params.inputAmountWei * liquidityFeeBps / 10000n;
|
|
101
102
|
const totalOracleFee = oracleFeePerOption * BigInt(params.no_of_options) + liquidityFeeAmount;
|
|
102
103
|
return buildCreateMarketRawTx({ ...params, tokenDecimals, factoryContractAddress: this.marketFactory, apiUrl: this.apiUrl, rpcUrl: this.rpcUrl, disputeTimer: this.distute_initial_timer, oracleFixedFeePerOption: totalOracleFee / BigInt(params.no_of_options) + 1n });
|
|
@@ -448,4 +449,8 @@ export class Rain {
|
|
|
448
449
|
async getFollowStats(params, accessToken) {
|
|
449
450
|
return followApi.getFollowStats(params, this.cfg(accessToken));
|
|
450
451
|
}
|
|
452
|
+
// ─── Whitelisted Tokens ─────────────────────────────────────────────────────
|
|
453
|
+
async getTokenPrice(tokenAddress) {
|
|
454
|
+
return whitelistedTokensApi.getTokenPrice(tokenAddress, this.cfg());
|
|
455
|
+
}
|
|
451
456
|
}
|
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.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",
|