@rainprotocolsdk/sdk 1.2.0 → 2.0.0

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.
Files changed (48) hide show
  1. package/README.md +644 -99
  2. package/dist/Rain.d.ts +16 -3
  3. package/dist/Rain.js +46 -4
  4. package/dist/abi/TradeMarketsAbi.d.ts +66 -0
  5. package/dist/abi/TradeMarketsAbi.js +85 -0
  6. package/dist/auth/login.d.ts +4 -0
  7. package/dist/auth/login.js +24 -0
  8. package/dist/auth/types.d.ts +16 -0
  9. package/dist/auth/types.js +1 -0
  10. package/dist/config/environments.d.ts +7 -0
  11. package/dist/config/environments.js +17 -3
  12. package/dist/constants/contractmethods.d.ts +9 -0
  13. package/dist/constants/contractmethods.js +9 -0
  14. package/dist/index.d.ts +1 -0
  15. package/dist/markets/getMarketById.d.ts +2 -0
  16. package/dist/markets/getMarketById.js +12 -0
  17. package/dist/markets/getUserInvestments.d.ts +2 -0
  18. package/dist/markets/getUserInvestments.js +23 -0
  19. package/dist/markets/types.d.ts +21 -0
  20. package/dist/tx/ClaimFunds/buildClaimFundsRawTx.d.ts +2 -0
  21. package/dist/tx/ClaimFunds/buildClaimFundsRawTx.js +34 -0
  22. package/dist/tx/ClaimFunds/helpers.d.ts +8 -0
  23. package/dist/tx/ClaimFunds/helpers.js +37 -0
  24. package/dist/tx/CloseMarket/buildCloseMarketRawTx.d.ts +2 -0
  25. package/dist/tx/CloseMarket/buildCloseMarketRawTx.js +97 -0
  26. package/dist/tx/CloseMarket/helpers.d.ts +2 -0
  27. package/dist/tx/CloseMarket/helpers.js +16 -0
  28. package/dist/tx/CreateMarket/buildCreateMarketRawTx.d.ts +1 -1
  29. package/dist/tx/CreateMarket/buildCreateMarketRawTx.js +17 -6
  30. package/dist/tx/CreateMarket/createMarketValidation.js +18 -4
  31. package/dist/tx/CreateMarket/helpers.d.ts +2 -0
  32. package/dist/tx/CreateMarket/helpers.js +33 -0
  33. package/dist/tx/Dispute/buildDisputeRawTx.d.ts +3 -0
  34. package/dist/tx/Dispute/buildDisputeRawTx.js +59 -0
  35. package/dist/tx/Dispute/helpers.d.ts +1 -0
  36. package/dist/tx/Dispute/helpers.js +9 -0
  37. package/dist/tx/buildApprovalRawTx.d.ts +1 -1
  38. package/dist/tx/buildCancelAllOpenOrdersRawTx.d.ts +2 -0
  39. package/dist/tx/buildCancelAllOpenOrdersRawTx.js +35 -0
  40. package/dist/tx/buildCancelOrdersRawTx.d.ts +2 -0
  41. package/dist/tx/buildCancelOrdersRawTx.js +42 -0
  42. package/dist/tx/buildRawTransactions.d.ts +2 -1
  43. package/dist/tx/buildRawTransactions.js +35 -1
  44. package/dist/tx/types.d.ts +75 -2
  45. package/dist/types.d.ts +1 -0
  46. package/dist/utils/helpers.d.ts +2 -0
  47. package/dist/utils/helpers.js +14 -1
  48. package/package.json +2 -2
package/dist/Rain.d.ts CHANGED
@@ -1,15 +1,28 @@
1
- import { GetMarketsParams, Market } from './markets/types.js';
2
- import { ApproveTxParams, CreateMarketTxParams, EnterLimitOptionTxParams, EnterOptionTxParams, RawTransaction } from './tx/types.js';
1
+ import { GetMarketByIdParams, GetMarketsParams, GetUserInvestmentsParams, Market, UserInvestment } from './markets/types.js';
2
+ import { ApproveTxParams, CancelAllOpenOrdersTxParams, CancelOrdersTxParams, ClaimTxParams, CloseMarketTxParams, CreateDisputeTxParams, CreateAppealTxParams, CreateMarketTxParams, EnterLimitOptionTxParams, EnterOptionTxParams, LimitSellOptionTxParams, RawTransaction } from './tx/types.js';
3
3
  import { RainCoreConfig, RainEnvironment } from './types.js';
4
+ import { LoginParams, LoginResult } from './auth/types.js';
4
5
  export declare class Rain {
5
6
  readonly environment: RainEnvironment;
6
7
  private readonly marketFactory;
7
8
  private readonly apiUrl;
8
9
  private readonly distute_initial_timer;
10
+ private readonly rpcUrl?;
11
+ private readonly usdtSymbol;
9
12
  constructor(config?: RainCoreConfig);
10
13
  getPublicMarkets(params: GetMarketsParams): Promise<Market[]>;
14
+ getMarketById(params: GetMarketByIdParams): Promise<Market>;
15
+ getUserInvestments(params: GetUserInvestmentsParams): Promise<UserInvestment[]>;
11
16
  buildApprovalTx(params: ApproveTxParams): RawTransaction | Error;
12
17
  buildBuyOptionRawTx(params: EnterOptionTxParams): RawTransaction;
13
18
  buildLimitBuyOptionTx(params: EnterLimitOptionTxParams): RawTransaction;
14
- buildCreateMarketTx(params: CreateMarketTxParams): RawTransaction;
19
+ buildLimitSellOptionTx(params: LimitSellOptionTxParams): RawTransaction;
20
+ buildCancelOrdersTx(params: CancelOrdersTxParams): RawTransaction[];
21
+ buildCancelAllOpenOrdersTx(params: CancelAllOpenOrdersTxParams): Promise<RawTransaction[]>;
22
+ buildCreateMarketTx(params: CreateMarketTxParams): Promise<RawTransaction[]>;
23
+ buildClaimTx(params: ClaimTxParams): Promise<RawTransaction>;
24
+ buildCloseMarketTx(params: CloseMarketTxParams): Promise<RawTransaction[]>;
25
+ buildCreateDisputeTx(params: CreateDisputeTxParams): Promise<RawTransaction[]>;
26
+ buildCreateAppealTx(params: CreateAppealTxParams): Promise<RawTransaction[]>;
27
+ login(params: LoginParams): Promise<LoginResult>;
15
28
  }
package/dist/Rain.js CHANGED
@@ -1,15 +1,25 @@
1
1
  import { getMarkets } from './markets/getMarkets.js';
2
- import { buildEnterOptionRawTx, buildLimitBuyOrderRawTx } from './tx/buildRawTransactions.js';
2
+ import { getMarketById } from './markets/getMarketById.js';
3
+ import { getUserInvestments } from './markets/getUserInvestments.js';
4
+ import { buildEnterOptionRawTx, buildLimitBuyOrderRawTx, buildLimitSellOrderRawTx } from './tx/buildRawTransactions.js';
5
+ import { buildCancelOrdersRawTx } from './tx/buildCancelOrdersRawTx.js';
6
+ import { buildCancelAllOpenOrdersRawTx } from './tx/buildCancelAllOpenOrdersRawTx.js';
7
+ import { buildCloseMarketRawTx } from './tx/CloseMarket/buildCloseMarketRawTx.js';
8
+ import { buildCreateDisputeRawTx, buildCreateAppealRawTx } from './tx/Dispute/buildDisputeRawTx.js';
3
9
  import { buildApproveRawTx } from './tx/buildApprovalRawTx.js';
4
10
  import { buildCreateMarketRawTx } from './tx/CreateMarket/buildCreateMarketRawTx.js';
5
- import { ALLOWED_ENVIRONMENTS, ENV_CONFIG } from './config/environments.js';
11
+ import { ALLOWED_ENVIRONMENTS, ENV_CONFIG, getRandomRpc } from './config/environments.js';
12
+ import { buildClaimRawTx } from './tx/ClaimFunds/buildClaimFundsRawTx.js';
13
+ import { loginUser } from './auth/login.js';
6
14
  export class Rain {
7
15
  environment;
8
16
  marketFactory;
9
17
  apiUrl;
10
18
  distute_initial_timer;
19
+ rpcUrl;
20
+ usdtSymbol;
11
21
  constructor(config = {}) {
12
- const { environment = "development" } = config;
22
+ const { environment = "development", rpcUrl } = config;
13
23
  function isValidEnvironment(env) {
14
24
  return ALLOWED_ENVIRONMENTS.includes(env);
15
25
  }
@@ -17,14 +27,22 @@ export class Rain {
17
27
  throw new Error(`Invalid environment "${environment}". Allowed values: ${ALLOWED_ENVIRONMENTS.join(", ")}`);
18
28
  }
19
29
  this.environment = environment;
30
+ this.rpcUrl = rpcUrl ?? getRandomRpc();
20
31
  const envConfig = ENV_CONFIG[this.environment];
21
32
  this.marketFactory = envConfig.market_factory_address;
22
33
  this.apiUrl = envConfig.apiUrl;
23
34
  this.distute_initial_timer = envConfig.dispute_initial_timer;
35
+ this.usdtSymbol = envConfig.usdt_symbol;
24
36
  }
25
37
  async getPublicMarkets(params) {
26
38
  return getMarkets({ ...params, apiUrl: this.apiUrl });
27
39
  }
40
+ async getMarketById(params) {
41
+ return getMarketById({ ...params, apiUrl: this.apiUrl });
42
+ }
43
+ async getUserInvestments(params) {
44
+ return getUserInvestments({ ...params, apiUrl: this.apiUrl });
45
+ }
28
46
  buildApprovalTx(params) {
29
47
  return buildApproveRawTx(params);
30
48
  }
@@ -34,7 +52,31 @@ export class Rain {
34
52
  buildLimitBuyOptionTx(params) {
35
53
  return buildLimitBuyOrderRawTx(params);
36
54
  }
55
+ buildLimitSellOptionTx(params) {
56
+ return buildLimitSellOrderRawTx(params);
57
+ }
58
+ buildCancelOrdersTx(params) {
59
+ return buildCancelOrdersRawTx(params);
60
+ }
61
+ async buildCancelAllOpenOrdersTx(params) {
62
+ return buildCancelAllOpenOrdersRawTx({ ...params, apiUrl: this.apiUrl });
63
+ }
37
64
  buildCreateMarketTx(params) {
38
- return buildCreateMarketRawTx({ ...params, factoryContractAddress: this.marketFactory, disputeTimer: this.distute_initial_timer });
65
+ return buildCreateMarketRawTx({ ...params, factoryContractAddress: this.marketFactory, apiUrl: this.apiUrl, rpcUrl: this.rpcUrl, disputeTimer: this.distute_initial_timer });
66
+ }
67
+ async buildClaimTx(params) {
68
+ return buildClaimRawTx({ ...params, apiUrl: this.apiUrl, rpcUrl: this.rpcUrl });
69
+ }
70
+ async buildCloseMarketTx(params) {
71
+ return buildCloseMarketRawTx({ ...params, apiUrl: this.apiUrl, rpcUrl: this.rpcUrl, usdtSymbol: this.usdtSymbol });
72
+ }
73
+ async buildCreateDisputeTx(params) {
74
+ return buildCreateDisputeRawTx({ ...params, apiUrl: this.apiUrl, rpcUrl: this.rpcUrl, usdtSymbol: this.usdtSymbol });
75
+ }
76
+ async buildCreateAppealTx(params) {
77
+ return buildCreateAppealRawTx({ ...params, apiUrl: this.apiUrl, rpcUrl: this.rpcUrl, usdtSymbol: this.usdtSymbol });
78
+ }
79
+ async login(params) {
80
+ return loginUser({ ...params, apiUrl: this.apiUrl });
39
81
  }
40
82
  }
@@ -267,12 +267,78 @@ export declare const TradePoolAbi: readonly [{
267
267
  readonly internalType: "bool";
268
268
  }];
269
269
  readonly stateMutability: "view";
270
+ }, {
271
+ readonly type: "function";
272
+ readonly name: "openDispute";
273
+ readonly inputs: readonly [];
274
+ readonly outputs: readonly [];
275
+ readonly stateMutability: "nonpayable";
276
+ }, {
277
+ readonly type: "function";
278
+ readonly name: "getDisputeAppealFee";
279
+ readonly inputs: readonly [];
280
+ readonly outputs: readonly [{
281
+ readonly name: "disputeFee";
282
+ readonly type: "uint256";
283
+ readonly internalType: "uint256";
284
+ }];
285
+ readonly stateMutability: "view";
286
+ }, {
287
+ readonly type: "function";
288
+ readonly name: "DISPUTE_FEE_MIN";
289
+ readonly inputs: readonly [];
290
+ readonly outputs: readonly [{
291
+ readonly name: "";
292
+ readonly type: "uint256";
293
+ readonly internalType: "uint256";
294
+ }];
295
+ readonly stateMutability: "view";
296
+ }, {
297
+ readonly type: "function";
298
+ readonly name: "DISPUTE_FEE_MAX";
299
+ readonly inputs: readonly [];
300
+ readonly outputs: readonly [{
301
+ readonly name: "";
302
+ readonly type: "uint256";
303
+ readonly internalType: "uint256";
304
+ }];
305
+ readonly stateMutability: "view";
306
+ }, {
307
+ readonly type: "function";
308
+ readonly name: "APPEAL_FEE_MIN";
309
+ readonly inputs: readonly [];
310
+ readonly outputs: readonly [{
311
+ readonly name: "";
312
+ readonly type: "uint256";
313
+ readonly internalType: "uint256";
314
+ }];
315
+ readonly stateMutability: "view";
270
316
  }, {
271
317
  readonly type: "function";
272
318
  readonly name: "closePool";
273
319
  readonly inputs: readonly [];
274
320
  readonly outputs: readonly [];
275
321
  readonly stateMutability: "nonpayable";
322
+ }, {
323
+ readonly type: "function";
324
+ readonly name: "closePool";
325
+ readonly inputs: readonly [{
326
+ readonly name: "proposedWinner";
327
+ readonly type: "uint256";
328
+ readonly internalType: "uint256";
329
+ }];
330
+ readonly outputs: readonly [];
331
+ readonly stateMutability: "nonpayable";
332
+ }, {
333
+ readonly type: "function";
334
+ readonly name: "getResolverBondAmount";
335
+ readonly inputs: readonly [];
336
+ readonly outputs: readonly [{
337
+ readonly name: "resolverBondAmount";
338
+ readonly type: "uint256";
339
+ readonly internalType: "uint256";
340
+ }];
341
+ readonly stateMutability: "view";
276
342
  }, {
277
343
  readonly type: "function";
278
344
  readonly name: "creatorFee";
@@ -347,6 +347,65 @@ export const TradePoolAbi = [
347
347
  ],
348
348
  "stateMutability": "view"
349
349
  },
350
+ {
351
+ "type": "function",
352
+ "name": "openDispute",
353
+ "inputs": [],
354
+ "outputs": [],
355
+ "stateMutability": "nonpayable"
356
+ },
357
+ {
358
+ "type": "function",
359
+ "name": "getDisputeAppealFee",
360
+ "inputs": [],
361
+ "outputs": [
362
+ {
363
+ "name": "disputeFee",
364
+ "type": "uint256",
365
+ "internalType": "uint256"
366
+ }
367
+ ],
368
+ "stateMutability": "view"
369
+ },
370
+ {
371
+ "type": "function",
372
+ "name": "DISPUTE_FEE_MIN",
373
+ "inputs": [],
374
+ "outputs": [
375
+ {
376
+ "name": "",
377
+ "type": "uint256",
378
+ "internalType": "uint256"
379
+ }
380
+ ],
381
+ "stateMutability": "view"
382
+ },
383
+ {
384
+ "type": "function",
385
+ "name": "DISPUTE_FEE_MAX",
386
+ "inputs": [],
387
+ "outputs": [
388
+ {
389
+ "name": "",
390
+ "type": "uint256",
391
+ "internalType": "uint256"
392
+ }
393
+ ],
394
+ "stateMutability": "view"
395
+ },
396
+ {
397
+ "type": "function",
398
+ "name": "APPEAL_FEE_MIN",
399
+ "inputs": [],
400
+ "outputs": [
401
+ {
402
+ "name": "",
403
+ "type": "uint256",
404
+ "internalType": "uint256"
405
+ }
406
+ ],
407
+ "stateMutability": "view"
408
+ },
350
409
  {
351
410
  "type": "function",
352
411
  "name": "closePool",
@@ -354,6 +413,32 @@ export const TradePoolAbi = [
354
413
  "outputs": [],
355
414
  "stateMutability": "nonpayable"
356
415
  },
416
+ {
417
+ "type": "function",
418
+ "name": "closePool",
419
+ "inputs": [
420
+ {
421
+ "name": "proposedWinner",
422
+ "type": "uint256",
423
+ "internalType": "uint256"
424
+ }
425
+ ],
426
+ "outputs": [],
427
+ "stateMutability": "nonpayable"
428
+ },
429
+ {
430
+ "type": "function",
431
+ "name": "getResolverBondAmount",
432
+ "inputs": [],
433
+ "outputs": [
434
+ {
435
+ "name": "resolverBondAmount",
436
+ "type": "uint256",
437
+ "internalType": "uint256"
438
+ }
439
+ ],
440
+ "stateMutability": "view"
441
+ },
357
442
  {
358
443
  "type": "function",
359
444
  "name": "creatorFee",
@@ -0,0 +1,4 @@
1
+ import { LoginParams, LoginResult } from './types.js';
2
+ export declare function loginUser(params: LoginParams & {
3
+ apiUrl: string;
4
+ }): Promise<LoginResult>;
@@ -0,0 +1,24 @@
1
+ export async function loginUser(params) {
2
+ const { signature, walletAddress, smartWalletAddress, referredBy, apiUrl } = params;
3
+ const res = await fetch(`${apiUrl}/auth/login-or-register-with-walletAddress`, {
4
+ method: 'POST',
5
+ headers: { 'Content-Type': 'application/json' },
6
+ body: JSON.stringify({
7
+ sign: signature,
8
+ walletAddress,
9
+ userSmartAddress: smartWalletAddress,
10
+ ...(referredBy ? { referredBy } : {}),
11
+ }),
12
+ });
13
+ if (!res.ok) {
14
+ const text = await res.text().catch(() => res.statusText);
15
+ throw new Error(`Login failed (${res.status}): ${text}`);
16
+ }
17
+ const data = await res.json();
18
+ const accessToken = data?.token;
19
+ const userId = data?.user?._id;
20
+ if (!accessToken || !userId) {
21
+ throw new Error('Login response missing token or user id');
22
+ }
23
+ return { accessToken, userId };
24
+ }
@@ -0,0 +1,16 @@
1
+ export interface LoginParams {
2
+ /** Signed message (personal_sign of the lowercased wallet address) */
3
+ signature: string;
4
+ /** EOA wallet address */
5
+ walletAddress: string;
6
+ /** Smart account / AA wallet address */
7
+ smartWalletAddress: string;
8
+ /** Optional referral code */
9
+ referredBy?: string;
10
+ }
11
+ export interface LoginResult {
12
+ /** JWT access token */
13
+ accessToken: string;
14
+ /** Backend user ID */
15
+ userId: string;
16
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,18 +1,25 @@
1
1
  export declare const ALLOWED_ENVIRONMENTS: readonly ["development", "stage", "production"];
2
+ export declare const DEFAULT_RPCS: string[];
3
+ export declare function getRandomRpc(): string;
4
+ export declare const USDT_SYMBOL_DEV = "USDTm";
5
+ export declare const USDT_SYMBOL_PROD = "USD\u20AE0";
2
6
  export declare const ENV_CONFIG: {
3
7
  readonly development: {
4
8
  readonly apiUrl: "https://dev-api.rain.one";
5
9
  readonly market_factory_address: "0x148DA7F2039B2B00633AC2ab566f59C8a4C86313";
6
10
  readonly dispute_initial_timer: number;
11
+ readonly usdt_symbol: "USDTm";
7
12
  };
8
13
  readonly stage: {
9
14
  readonly apiUrl: "https://stg-api.rain.one";
10
15
  readonly market_factory_address: "0x6109c9f28FE3Ad84c51368f7Ef2d487ca020c561";
11
16
  readonly dispute_initial_timer: number;
17
+ readonly usdt_symbol: "USD₮0";
12
18
  };
13
19
  readonly production: {
14
20
  readonly apiUrl: "https://prod-api.rain.one";
15
21
  readonly market_factory_address: "0xccCB3C03D9355B01883779EF15C1Be09cf3623F1";
16
22
  readonly dispute_initial_timer: number;
23
+ readonly usdt_symbol: "USD₮0";
17
24
  };
18
25
  };
@@ -1,18 +1,32 @@
1
1
  export const ALLOWED_ENVIRONMENTS = ["development", "stage", "production"];
2
+ export const DEFAULT_RPCS = [
3
+ "https://arbitrum.meowrpc.com",
4
+ "https://rpc.sentio.xyz/arbitrum-one",
5
+ "https://rpc.owlracle.info/arb/70d38ce1826c4a60bb2a8e05a6c8b20f"
6
+ ];
7
+ export function getRandomRpc() {
8
+ const index = Math.floor(Math.random() * DEFAULT_RPCS.length);
9
+ return DEFAULT_RPCS[index];
10
+ }
11
+ export const USDT_SYMBOL_DEV = "USDTm";
12
+ export const USDT_SYMBOL_PROD = "USD₮0";
2
13
  export const ENV_CONFIG = {
3
14
  development: {
4
15
  apiUrl: "https://dev-api.rain.one",
5
16
  market_factory_address: "0x148DA7F2039B2B00633AC2ab566f59C8a4C86313",
6
- dispute_initial_timer: 1 * 60
17
+ dispute_initial_timer: 1 * 60,
18
+ usdt_symbol: USDT_SYMBOL_DEV,
7
19
  },
8
20
  stage: {
9
21
  apiUrl: "https://stg-api.rain.one",
10
22
  market_factory_address: "0x6109c9f28FE3Ad84c51368f7Ef2d487ca020c561",
11
- dispute_initial_timer: 1 * 60
23
+ dispute_initial_timer: 1 * 60,
24
+ usdt_symbol: USDT_SYMBOL_PROD,
12
25
  },
13
26
  production: {
14
27
  apiUrl: "https://prod-api.rain.one",
15
28
  market_factory_address: "0xccCB3C03D9355B01883779EF15C1Be09cf3623F1",
16
- dispute_initial_timer: 120 * 60
29
+ dispute_initial_timer: 120 * 60,
30
+ usdt_symbol: USDT_SYMBOL_PROD,
17
31
  },
18
32
  };
@@ -1,4 +1,13 @@
1
1
  export declare const ENTER_OPTION = "enterOption";
2
2
  export declare const PLACE_BUY_ORDER = "placeBuyOrder";
3
+ export declare const PLACE_SELL_ORDER = "placeSellOrder";
3
4
  export declare const APPROVE_TOKEN = "approve";
4
5
  export declare const CREATE_MARKET = "createPool";
6
+ export declare const CLAIM = "claim";
7
+ export declare const CLOSE_POOL = "closePool";
8
+ export declare const CHOOSE_WINNER = "chooseWinner";
9
+ export declare const GET_RESOLVER_BOND_AMOUNT = "getResolverBondAmount";
10
+ export declare const OPEN_DISPUTE = "openDispute";
11
+ export declare const GET_DISPUTE_APPEAL_FEE = "getDisputeAppealFee";
12
+ export declare const CANCEL_BUY_ORDERS = "cancelBuyOrders";
13
+ export declare const CANCEL_SELL_ORDERS = "cancelSellOrders";
@@ -1,4 +1,13 @@
1
1
  export const ENTER_OPTION = 'enterOption';
2
2
  export const PLACE_BUY_ORDER = 'placeBuyOrder';
3
+ export const PLACE_SELL_ORDER = 'placeSellOrder';
3
4
  export const APPROVE_TOKEN = 'approve';
4
5
  export const CREATE_MARKET = 'createPool';
6
+ export const CLAIM = "claim";
7
+ export const CLOSE_POOL = 'closePool';
8
+ export const CHOOSE_WINNER = 'chooseWinner';
9
+ export const GET_RESOLVER_BOND_AMOUNT = 'getResolverBondAmount';
10
+ export const OPEN_DISPUTE = 'openDispute';
11
+ export const GET_DISPUTE_APPEAL_FEE = 'getDisputeAppealFee';
12
+ export const CANCEL_BUY_ORDERS = 'cancelBuyOrders';
13
+ export const CANCEL_SELL_ORDERS = 'cancelSellOrders';
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { Rain } from './Rain.js';
2
2
  export { RainAA } from './RainAA.js';
3
3
  export * from './types.js';
4
+ export type { LoginParams, LoginResult } from './auth/types.js';
@@ -0,0 +1,2 @@
1
+ import { GetMarketByIdParams, Market } from './types.js';
2
+ export declare function getMarketById(params: GetMarketByIdParams): Promise<Market>;
@@ -0,0 +1,12 @@
1
+ export async function getMarketById(params) {
2
+ if (!params?.apiUrl)
3
+ throw new Error("Environment is not set properly, api url is missing");
4
+ if (!params?.marketId)
5
+ throw new Error("marketId is required");
6
+ const res = await fetch(`${params.apiUrl}/pools/pool/${params.marketId}`);
7
+ if (!res.ok) {
8
+ throw new Error(`Failed to fetch market: ${res.status}`);
9
+ }
10
+ const data = await res.json();
11
+ return data;
12
+ }
@@ -0,0 +1,2 @@
1
+ import { GetUserInvestmentsParams, UserInvestment } from './types.js';
2
+ export declare function getUserInvestments(params: GetUserInvestmentsParams): Promise<UserInvestment[]>;
@@ -0,0 +1,23 @@
1
+ import { MARKET_STATUS } from './constants.js';
2
+ export async function getUserInvestments(params) {
3
+ if (!params?.apiUrl)
4
+ throw new Error("Environment is not set properly, api url is missing");
5
+ if (!params?.walletAddress)
6
+ throw new Error("walletAddress is required");
7
+ if (!params?.accessToken)
8
+ throw new Error("accessToken is required");
9
+ const query = new URLSearchParams();
10
+ query.append('walletAddress', params.walletAddress);
11
+ if (params?.limit)
12
+ query.append('limit', params.limit.toString());
13
+ if (params?.offset)
14
+ query.append('offset', params.offset.toString());
15
+ if (params?.status)
16
+ query.append('status', MARKET_STATUS[params.status]);
17
+ const res = await fetch(`${params.apiUrl}/investments/user-invested-pools?${query.toString()}`, { headers: { Authorization: `Bearer ${params.accessToken}` } });
18
+ if (!res.ok) {
19
+ throw new Error(`Failed to fetch user investments: ${res.status}`);
20
+ }
21
+ const data = await res.json();
22
+ return data?.data ?? data;
23
+ }
@@ -13,3 +13,24 @@ export interface Market {
13
13
  totalVolume: string;
14
14
  status: MarketStatus;
15
15
  }
16
+ export interface GetMarketByIdParams {
17
+ marketId: string;
18
+ apiUrl?: string;
19
+ }
20
+ export interface GetUserInvestmentsParams {
21
+ walletAddress: string;
22
+ accessToken: string;
23
+ limit?: number;
24
+ offset?: number;
25
+ status?: MarketStatus;
26
+ apiUrl?: string;
27
+ }
28
+ export interface UserInvestment {
29
+ _id: string;
30
+ poolId: string;
31
+ walletAddress: string;
32
+ investment: any[];
33
+ totalInvestment: string;
34
+ pool: Record<string, any>;
35
+ [key: string]: any;
36
+ }
@@ -0,0 +1,2 @@
1
+ import { ClaimTxParams, RawTransaction } from "../types.js";
2
+ export declare function buildClaimRawTx(params: ClaimTxParams): Promise<RawTransaction>;
@@ -0,0 +1,34 @@
1
+ import { encodeFunctionData } from "viem";
2
+ import { TradePoolAbi } from "../../abi/TradeMarketsAbi.js";
3
+ import { getMarket, getUserOptionShares, isRpcValid } from "./helpers.js";
4
+ import { MARKET_STATUS } from "../../markets/constants.js";
5
+ import { CLAIM } from "../../constants/contractmethods.js";
6
+ export async function buildClaimRawTx(params) {
7
+ const { marketId, walletAddress, apiUrl, rpcUrl } = params;
8
+ if (!apiUrl) {
9
+ throw new Error("Environemnt is not set properly, api url is missing");
10
+ }
11
+ const isRpcWorking = await isRpcValid(rpcUrl);
12
+ if (!rpcUrl || !isRpcWorking) {
13
+ throw new Error("Provided RPC URL is not valid or not working");
14
+ }
15
+ if (!marketId)
16
+ throw new Error("marketContractAddress is required");
17
+ if (!walletAddress)
18
+ throw new Error("walletAddress is required");
19
+ const { data } = await getMarket({ marketId, apiUrl });
20
+ if (data?.status !== MARKET_STATUS.Closed)
21
+ throw new Error("Market is not closed yet. Please wait until the market is closed to claim your funds.");
22
+ const marketContractAddress = data?.contractAddress;
23
+ const options = data?.options || 0;
24
+ const userShares = await getUserOptionShares({ marketContractAddress: marketContractAddress, walletAddress: walletAddress, options: options, rpcUrl: rpcUrl });
25
+ if (userShares?.length <= 0)
26
+ throw new Error("No shares to claim for this market");
27
+ return {
28
+ to: marketContractAddress,
29
+ data: encodeFunctionData({
30
+ abi: TradePoolAbi,
31
+ functionName: CLAIM,
32
+ }),
33
+ };
34
+ }
@@ -0,0 +1,8 @@
1
+ import { Market } from "../../markets/types.js";
2
+ import { GetUserOptionSharesParams } from "../types.js";
3
+ export declare function getMarket(params: {
4
+ marketId: string;
5
+ apiUrl: string;
6
+ }): Promise<Market>;
7
+ export declare function isRpcValid(rpcUrl: string | undefined): Promise<boolean>;
8
+ export declare function getUserOptionShares(params: GetUserOptionSharesParams): Promise<number[]>;
@@ -0,0 +1,37 @@
1
+ import { Contract, JsonRpcProvider } from "ethers";
2
+ import { TradePoolAbi } from "../../abi/TradeMarketsAbi.js";
3
+ export async function getMarket(params) {
4
+ if (!params?.apiUrl) {
5
+ throw new Error("Environemnt is not set properly, api url is missing");
6
+ }
7
+ const res = await fetch(`${params.apiUrl}/pools/pool/${params.marketId}`);
8
+ if (!res.ok) {
9
+ throw new Error(`Failed to fetch markets: ${res.status}`);
10
+ }
11
+ const data = await res.json();
12
+ return data;
13
+ }
14
+ export async function isRpcValid(rpcUrl) {
15
+ if (!rpcUrl)
16
+ return false;
17
+ const provider = new JsonRpcProvider(rpcUrl);
18
+ try {
19
+ await provider.getNetwork();
20
+ return true;
21
+ }
22
+ catch (error) {
23
+ return false;
24
+ }
25
+ }
26
+ export async function getUserOptionShares(params) {
27
+ const { marketContractAddress, options, walletAddress, rpcUrl } = params;
28
+ const provider = new JsonRpcProvider(rpcUrl);
29
+ const userShares = [];
30
+ for (let i = 0; i < options.length; i++) {
31
+ const choiceIndex = options[i].choiceIndex;
32
+ const contract = new Contract(marketContractAddress, TradePoolAbi, provider);
33
+ const userVotes = await contract.userVotes(choiceIndex, walletAddress);
34
+ Number(userVotes) > 0 && userShares.push(Number(userVotes));
35
+ }
36
+ return userShares;
37
+ }
@@ -0,0 +1,2 @@
1
+ import { CloseMarketTxParams, RawTransaction } from "../types.js";
2
+ export declare function buildCloseMarketRawTx(params: CloseMarketTxParams): Promise<RawTransaction[]>;