rain-sdk-v2 1.0.12 → 1.2.1

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
@@ -15,6 +15,10 @@ 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<{
19
+ oracleFeePerOption: bigint;
20
+ liquidityFeeBps: bigint;
21
+ }>;
18
22
  buildCreateMarketTx(params: CreateMarketTxParams): Promise<RawTransaction[]>;
19
23
  buildEnterOptionTx(params: EnterOptionTxParams & {
20
24
  walletAddress: `0x${string}`;
@@ -34,6 +38,12 @@ export declare class Rain {
34
38
  optionSide: number;
35
39
  userAddress: `0x${string}`;
36
40
  }): Promise<bigint>;
41
+ getUserSharesInEscrow(params: {
42
+ marketContractAddress: `0x${string}`;
43
+ option: bigint;
44
+ optionSide: number;
45
+ userAddress: `0x${string}`;
46
+ }): Promise<bigint>;
37
47
  getDynamicPayout(params: {
38
48
  marketContractAddress: `0x${string}`;
39
49
  userAddress: `0x${string}`;
package/dist/Rain.js CHANGED
@@ -17,6 +17,7 @@ import { loginUser } from './auth/login.js';
17
17
  import { getUserOptionLPShares } from './markets/getUserOptionLPShares.js';
18
18
  import { getUserOptionShares } from './markets/getUserOptionShares.js';
19
19
  import { getDynamicPayout } from './markets/getDynamicPayout.js';
20
+ import { getUserSharesInEscrow } from './markets/getUserSharesInEscrow.js';
20
21
  import { createPublicClient, http, parseAbi } from 'viem';
21
22
  import { arbitrum } from 'viem/chains';
22
23
  import * as usersApi from './api/users.js';
@@ -32,6 +33,12 @@ import * as rainBurnApi from './api/rainBurn.js';
32
33
  import * as disputeApi from './api/dispute.js';
33
34
  import * as followApi from './api/follow.js';
34
35
  const erc20AllowanceAbi = parseAbi(['function allowance(address owner, address spender) view returns (uint256)']);
36
+ const factoryViewAbi = parseAbi([
37
+ 'function oracleFixedFee() view returns (uint256)',
38
+ 'function liquidityFee() view returns (uint256)',
39
+ 'function baseToken() view returns (address)',
40
+ ]);
41
+ const erc20DecimalsAbi = parseAbi(['function decimals() view returns (uint8)']);
35
42
  export class Rain {
36
43
  environment;
37
44
  marketFactory;
@@ -69,11 +76,29 @@ export class Rain {
69
76
  buildApprovalTx(params) {
70
77
  return buildApproveRawTx(params);
71
78
  }
72
- buildCreateMarketTx(params) {
79
+ async getCreateMarketFees(tokenAddress) {
80
+ const pc = createPublicClient({ chain: arbitrum, transport: http(this.rpcUrl) });
81
+ const [oracleFeeRaw, liquidityFeeBps, factoryBaseToken] = await Promise.all([
82
+ pc.readContract({ address: this.marketFactory, abi: factoryViewAbi, functionName: 'oracleFixedFee' }),
83
+ pc.readContract({ address: this.marketFactory, abi: factoryViewAbi, functionName: 'liquidityFee' }),
84
+ pc.readContract({ address: this.marketFactory, abi: factoryViewAbi, functionName: 'baseToken' }),
85
+ ]);
86
+ if (tokenAddress.toLowerCase() === factoryBaseToken.toLowerCase()) {
87
+ return { oracleFeePerOption: oracleFeeRaw, liquidityFeeBps: liquidityFeeBps };
88
+ }
89
+ const baseTokenDecimals = await pc.readContract({ address: factoryBaseToken, abi: erc20DecimalsAbi, functionName: 'decimals' });
90
+ const tokenConfig = this.getTokenConfig(tokenAddress);
91
+ const tokenDecimals = BigInt(tokenConfig?.decimals ?? 18);
92
+ const oracleFeePerOption = oracleFeeRaw * (10n ** (tokenDecimals - BigInt(baseTokenDecimals)));
93
+ return { oracleFeePerOption, liquidityFeeBps: liquidityFeeBps };
94
+ }
95
+ async buildCreateMarketTx(params) {
73
96
  const tokenConfig = this.getTokenConfig(params.baseToken);
74
- const oracleFixedFeePerOption = tokenConfig?.oracle_fixed_fee_per_option ?? 1000000n;
75
97
  const tokenDecimals = params.tokenDecimals ?? tokenConfig?.decimals ?? 6;
76
- return buildCreateMarketRawTx({ ...params, tokenDecimals, factoryContractAddress: this.marketFactory, apiUrl: this.apiUrl, rpcUrl: this.rpcUrl, disputeTimer: this.distute_initial_timer, oracleFixedFeePerOption });
98
+ const { oracleFeePerOption, liquidityFeeBps } = await this.getCreateMarketFees(params.baseToken);
99
+ const liquidityFeeAmount = params.inputAmountWei * liquidityFeeBps / 10000n;
100
+ const totalOracleFee = oracleFeePerOption * BigInt(params.no_of_options) + liquidityFeeAmount;
101
+ 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 });
77
102
  }
78
103
  async buildEnterOptionTx(params) {
79
104
  return buildEnterOptionRawTx({ ...params, rpcUrl: this.rpcUrl });
@@ -90,6 +115,9 @@ export class Rain {
90
115
  async getUserOptionShares(params) {
91
116
  return getUserOptionShares({ ...params, rpcUrl: this.rpcUrl });
92
117
  }
118
+ async getUserSharesInEscrow(params) {
119
+ return getUserSharesInEscrow({ ...params, rpcUrl: this.rpcUrl });
120
+ }
93
121
  async getDynamicPayout(params) {
94
122
  return getDynamicPayout({ ...params, rpcUrl: this.rpcUrl });
95
123
  }
@@ -0,0 +1,8 @@
1
+ export interface GetUserSharesInEscrowParams {
2
+ marketContractAddress: `0x${string}`;
3
+ option: bigint;
4
+ optionSide: number;
5
+ userAddress: `0x${string}`;
6
+ rpcUrl: string;
7
+ }
8
+ export declare function getUserSharesInEscrow(params: GetUserSharesInEscrowParams): Promise<bigint>;
@@ -0,0 +1,17 @@
1
+ import { createPublicClient, http } from 'viem';
2
+ import { arbitrum } from 'viem/chains';
3
+ import { MarketsAbi } from '../abi/MarketsAbi.js';
4
+ export async function getUserSharesInEscrow(params) {
5
+ const { marketContractAddress, option, optionSide, userAddress, rpcUrl } = params;
6
+ const client = createPublicClient({
7
+ chain: arbitrum,
8
+ transport: http(rpcUrl),
9
+ });
10
+ const shares = await client.readContract({
11
+ address: marketContractAddress,
12
+ abi: MarketsAbi,
13
+ functionName: 'userSharesPerSideInEscrow',
14
+ args: [option, optionSide, userAddress],
15
+ });
16
+ return shares;
17
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rain-sdk-v2",
3
- "version": "1.0.12",
3
+ "version": "1.2.1",
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",