rain-sdk-v2 2.0.3 → 2.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
@@ -167,8 +167,9 @@ const txsRain = await rain.buildCreateMarketTx({
167
167
  baseToken: config.tokens.rain.address, // RAIN token
168
168
  });
169
169
 
170
- // Approval amount = liquidity + (oracleFixedFeePerOption * numberOfOptions)
171
- // Oracle fee is automatically calculated based on the token's decimals
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 |
@@ -530,6 +531,17 @@ const claimed = await rain.getOptionClaimed({
530
531
  // true if already claimed, false otherwise
531
532
  ```
532
533
 
534
+ ### `getDisputeWindow(params): Promise<bigint>`
535
+
536
+ Get the dispute window duration (in seconds) for a market contract.
537
+
538
+ ```typescript
539
+ const window = await rain.getDisputeWindow({
540
+ marketContractAddress: '0x...',
541
+ });
542
+ // window = dispute window in seconds (e.g. 7200n = 2 hours)
543
+ ```
544
+
533
545
  ### `getDynamicPayout(params): Promise<bigint[]>`
534
546
 
535
547
  Get the dynamic payout amounts for a user on a specific option. Returns an array of payout values per side.
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}`): Promise<{
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 & {
@@ -49,6 +51,9 @@ export declare class Rain {
49
51
  option: bigint;
50
52
  userAddress: `0x${string}`;
51
53
  }): Promise<boolean>;
54
+ getDisputeWindow(params: {
55
+ marketContractAddress: `0x${string}`;
56
+ }): Promise<bigint>;
52
57
  getDynamicPayout(params: {
53
58
  marketContractAddress: `0x${string}`;
54
59
  userAddress: `0x${string}`;
package/dist/Rain.js CHANGED
@@ -19,6 +19,7 @@ import { getUserOptionShares } from './markets/getUserOptionShares.js';
19
19
  import { getDynamicPayout } from './markets/getDynamicPayout.js';
20
20
  import { getUserSharesInEscrow } from './markets/getUserSharesInEscrow.js';
21
21
  import { getOptionClaimed } from './markets/getOptionClaimed.js';
22
+ import { getDisputeWindow } from './markets/getDisputeWindow.js';
22
23
  import { createPublicClient, http, parseAbi } from 'viem';
23
24
  import { arbitrum } from 'viem/chains';
24
25
  import * as usersApi from './api/users.js';
@@ -40,7 +41,6 @@ const factoryViewAbi = parseAbi([
40
41
  'function liquidityFee() view returns (uint256)',
41
42
  'function baseToken() view returns (address)',
42
43
  ]);
43
- const erc20DecimalsAbi = parseAbi(['function decimals() view returns (uint8)']);
44
44
  export class Rain {
45
45
  environment;
46
46
  marketFactory;
@@ -78,7 +78,7 @@ export class Rain {
78
78
  buildApprovalTx(params) {
79
79
  return buildApproveRawTx(params);
80
80
  }
81
- async getCreateMarketFees(tokenAddress) {
81
+ async getCreateMarketFees(tokenAddress, inputAmountWei) {
82
82
  const pc = createPublicClient({ chain: arbitrum, transport: http(this.rpcUrl) });
83
83
  const [oracleFeeRaw, liquidityFeeBps, factoryBaseToken] = await Promise.all([
84
84
  pc.readContract({ address: this.marketFactory, abi: factoryViewAbi, functionName: 'oracleFixedFee' }),
@@ -86,27 +86,19 @@ export class Rain {
86
86
  pc.readContract({ address: this.marketFactory, abi: factoryViewAbi, functionName: 'baseToken' }),
87
87
  ]);
88
88
  if (tokenAddress.toLowerCase() === factoryBaseToken.toLowerCase()) {
89
- return { oracleFeePerOption: oracleFeeRaw, liquidityFeeBps: liquidityFeeBps };
89
+ return { oracleFeePerOption: oracleFeeRaw, liquidityFeeBps: liquidityFeeBps, useBufferApproval: false, perOptionBuffer: 0n };
90
90
  }
91
- const tokenConfig = this.getTokenConfig(tokenAddress);
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)));
104
- return { oracleFeePerOption, liquidityFeeBps: liquidityFeeBps };
91
+ // For non-base tokens (e.g. RAIN): approval = initialLiquidity + (numberOfOptions * 20% of initialLiquidity)
92
+ const perOptionBuffer = inputAmountWei * 20n / 100n;
93
+ return { oracleFeePerOption: 0n, liquidityFeeBps: liquidityFeeBps, useBufferApproval: true, perOptionBuffer };
105
94
  }
106
95
  async buildCreateMarketTx(params) {
107
96
  const tokenConfig = this.getTokenConfig(params.baseToken);
108
97
  const tokenDecimals = params.tokenDecimals ?? tokenConfig?.decimals ?? 6;
109
- const { oracleFeePerOption, liquidityFeeBps } = await this.getCreateMarketFees(params.baseToken);
98
+ const { oracleFeePerOption, liquidityFeeBps, useBufferApproval, perOptionBuffer } = await this.getCreateMarketFees(params.baseToken, params.inputAmountWei);
99
+ if (useBufferApproval) {
100
+ return buildCreateMarketRawTx({ ...params, tokenDecimals, factoryContractAddress: this.marketFactory, apiUrl: this.apiUrl, rpcUrl: this.rpcUrl, disputeTimer: this.distute_initial_timer, oracleFixedFeePerOption: perOptionBuffer });
101
+ }
110
102
  const liquidityFeeAmount = params.inputAmountWei * liquidityFeeBps / 10000n;
111
103
  const totalOracleFee = oracleFeePerOption * BigInt(params.no_of_options) + liquidityFeeAmount;
112
104
  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 });
@@ -132,6 +124,9 @@ export class Rain {
132
124
  async getOptionClaimed(params) {
133
125
  return getOptionClaimed({ ...params, rpcUrl: this.rpcUrl });
134
126
  }
127
+ async getDisputeWindow(params) {
128
+ return getDisputeWindow({ ...params, rpcUrl: this.rpcUrl });
129
+ }
135
130
  async getDynamicPayout(params) {
136
131
  return getDynamicPayout({ ...params, rpcUrl: this.rpcUrl });
137
132
  }
@@ -0,0 +1,5 @@
1
+ export interface GetDisputeWindowParams {
2
+ marketContractAddress: `0x${string}`;
3
+ rpcUrl: string;
4
+ }
5
+ export declare function getDisputeWindow(params: GetDisputeWindowParams): Promise<bigint>;
@@ -0,0 +1,16 @@
1
+ import { createPublicClient, http } from 'viem';
2
+ import { arbitrum } from 'viem/chains';
3
+ import { MarketsAbi } from '../abi/MarketsAbi.js';
4
+ export async function getDisputeWindow(params) {
5
+ const { marketContractAddress, rpcUrl } = params;
6
+ const client = createPublicClient({
7
+ chain: arbitrum,
8
+ transport: http(rpcUrl),
9
+ });
10
+ const disputeWindow = await client.readContract({
11
+ address: marketContractAddress,
12
+ abi: MarketsAbi,
13
+ functionName: 'DISPUTE_WINDOW',
14
+ });
15
+ return disputeWindow;
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rain-sdk-v2",
3
- "version": "2.0.3",
3
+ "version": "2.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",