rain-sdk-v2 1.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.
- package/README.md +1074 -0
- package/dist/Rain.d.ts +212 -0
- package/dist/Rain.js +401 -0
- package/dist/RainAA.d.ts +62 -0
- package/dist/RainAA.js +304 -0
- package/dist/abi/CreateMarketAbi.d.ts +1125 -0
- package/dist/abi/CreateMarketAbi.js +1 -0
- package/dist/abi/ERC20Abi.d.ts +89 -0
- package/dist/abi/ERC20Abi.js +119 -0
- package/dist/abi/MarketsAbi.d.ts +2810 -0
- package/dist/abi/MarketsAbi.js +1 -0
- package/dist/abi/OracleAbi.d.ts +11 -0
- package/dist/abi/OracleAbi.js +15 -0
- package/dist/api/comments.d.ts +14 -0
- package/dist/api/comments.js +48 -0
- package/dist/api/dispute.d.ts +3 -0
- package/dist/api/dispute.js +30 -0
- package/dist/api/follow.d.ts +6 -0
- package/dist/api/follow.js +38 -0
- package/dist/api/helpers.d.ts +4 -0
- package/dist/api/helpers.js +26 -0
- package/dist/api/index.d.ts +14 -0
- package/dist/api/index.js +14 -0
- package/dist/api/investments.d.ts +21 -0
- package/dist/api/investments.js +135 -0
- package/dist/api/notifications.d.ts +4 -0
- package/dist/api/notifications.js +24 -0
- package/dist/api/orders.d.ts +8 -0
- package/dist/api/orders.js +40 -0
- package/dist/api/points.d.ts +5 -0
- package/dist/api/points.js +32 -0
- package/dist/api/poolReviews.d.ts +4 -0
- package/dist/api/poolReviews.js +23 -0
- package/dist/api/pools.d.ts +41 -0
- package/dist/api/pools.js +149 -0
- package/dist/api/priceData.d.ts +2 -0
- package/dist/api/priceData.js +9 -0
- package/dist/api/rainBurn.d.ts +3 -0
- package/dist/api/rainBurn.js +15 -0
- package/dist/api/types.d.ts +292 -0
- package/dist/api/types.js +2 -0
- package/dist/api/users.d.ts +15 -0
- package/dist/api/users.js +60 -0
- package/dist/auth/login.d.ts +4 -0
- package/dist/auth/login.js +27 -0
- package/dist/auth/types.d.ts +16 -0
- package/dist/auth/types.js +1 -0
- package/dist/config/environments.d.ts +15 -0
- package/dist/config/environments.js +41 -0
- package/dist/constants/contractmethods.d.ts +15 -0
- package/dist/constants/contractmethods.js +15 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +6 -0
- package/dist/markets/getDisputeFee.d.ts +5 -0
- package/dist/markets/getDisputeFee.js +19 -0
- package/dist/markets/getOrderInfo.d.ts +53 -0
- package/dist/markets/getOrderInfo.js +80 -0
- package/dist/markets/getResolverBondAmount.d.ts +9 -0
- package/dist/markets/getResolverBondAmount.js +35 -0
- package/dist/markets/getUserOptionLPShares.d.ts +7 -0
- package/dist/markets/getUserOptionLPShares.js +17 -0
- package/dist/markets/getUserOptionShares.d.ts +8 -0
- package/dist/markets/getUserOptionShares.js +17 -0
- package/dist/socket/RainSocket.d.ts +175 -0
- package/dist/socket/RainSocket.js +186 -0
- package/dist/tx/CreateMarket/buildCreateMarketRawTx.d.ts +2 -0
- package/dist/tx/CreateMarket/buildCreateMarketRawTx.js +55 -0
- package/dist/tx/CreateMarket/createMarketValidation.d.ts +2 -0
- package/dist/tx/CreateMarket/createMarketValidation.js +48 -0
- package/dist/tx/CreateMarket/helpers.d.ts +3 -0
- package/dist/tx/CreateMarket/helpers.js +42 -0
- package/dist/tx/buildAddLiquidityRawTx.d.ts +2 -0
- package/dist/tx/buildAddLiquidityRawTx.js +23 -0
- package/dist/tx/buildApprovalRawTx.d.ts +2 -0
- package/dist/tx/buildApprovalRawTx.js +24 -0
- package/dist/tx/buildCalculateWinnerRawTx.d.ts +13 -0
- package/dist/tx/buildCalculateWinnerRawTx.js +37 -0
- package/dist/tx/buildCancelOrdersRawTx.d.ts +3 -0
- package/dist/tx/buildCancelOrdersRawTx.js +43 -0
- package/dist/tx/buildClaimRawTx.d.ts +2 -0
- package/dist/tx/buildClaimRawTx.js +19 -0
- package/dist/tx/buildClosePoolRawTx.d.ts +20 -0
- package/dist/tx/buildClosePoolRawTx.js +95 -0
- package/dist/tx/buildEnterOptionRawTx.d.ts +2 -0
- package/dist/tx/buildEnterOptionRawTx.js +25 -0
- package/dist/tx/buildMergeRawTx.d.ts +2 -0
- package/dist/tx/buildMergeRawTx.js +21 -0
- package/dist/tx/buildOpenDisputeRawTx.d.ts +8 -0
- package/dist/tx/buildOpenDisputeRawTx.js +39 -0
- package/dist/tx/buildPlaceOrderRawTx.d.ts +3 -0
- package/dist/tx/buildPlaceOrderRawTx.js +47 -0
- package/dist/tx/buildRemoveLiquidityRawTx.d.ts +2 -0
- package/dist/tx/buildRemoveLiquidityRawTx.js +23 -0
- package/dist/tx/buildSplitRawTx.d.ts +2 -0
- package/dist/tx/buildSplitRawTx.js +21 -0
- package/dist/tx/types.d.ts +117 -0
- package/dist/tx/types.js +10 -0
- package/dist/types.d.ts +15 -0
- package/dist/types.js +1 -0
- package/dist/utils/helpers.d.ts +4 -0
- package/dist/utils/helpers.js +28 -0
- package/package.json +66 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { encodeFunctionData } from "viem";
|
|
2
|
+
import { MarketsAbi } from "../abi/MarketsAbi.js";
|
|
3
|
+
import { ENTER_OPTION } from "../constants/contractmethods.js";
|
|
4
|
+
export function buildEnterOptionRawTx(params) {
|
|
5
|
+
const { marketContractAddress, selectedOption, optionSide, buyAmountInWei } = params;
|
|
6
|
+
if (!marketContractAddress)
|
|
7
|
+
throw new Error("marketContractAddress is required");
|
|
8
|
+
if (selectedOption === undefined || selectedOption === null)
|
|
9
|
+
throw new Error("selectedOption is required");
|
|
10
|
+
if (optionSide === undefined || optionSide === null)
|
|
11
|
+
throw new Error("optionSide is required");
|
|
12
|
+
if (!buyAmountInWei)
|
|
13
|
+
throw new Error("buyAmountInWei is required");
|
|
14
|
+
if (buyAmountInWei <= 0n)
|
|
15
|
+
throw new Error("buyAmountInWei must be greater than 0");
|
|
16
|
+
return {
|
|
17
|
+
to: marketContractAddress,
|
|
18
|
+
data: encodeFunctionData({
|
|
19
|
+
abi: MarketsAbi,
|
|
20
|
+
functionName: ENTER_OPTION,
|
|
21
|
+
args: [selectedOption, optionSide, buyAmountInWei],
|
|
22
|
+
}),
|
|
23
|
+
value: 0n,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { encodeFunctionData } from "viem";
|
|
2
|
+
import { MarketsAbi } from "../abi/MarketsAbi.js";
|
|
3
|
+
import { MERGE } from "../constants/contractmethods.js";
|
|
4
|
+
export function buildMergeRawTx(params) {
|
|
5
|
+
const { marketContractAddress, option, amount } = params;
|
|
6
|
+
if (!marketContractAddress)
|
|
7
|
+
throw new Error("marketContractAddress is required");
|
|
8
|
+
if (option === undefined || option === null)
|
|
9
|
+
throw new Error("option is required");
|
|
10
|
+
if (!amount || amount <= 0n)
|
|
11
|
+
throw new Error("amount must be greater than 0");
|
|
12
|
+
return {
|
|
13
|
+
to: marketContractAddress,
|
|
14
|
+
data: encodeFunctionData({
|
|
15
|
+
abi: MarketsAbi,
|
|
16
|
+
functionName: MERGE,
|
|
17
|
+
args: [option, amount],
|
|
18
|
+
}),
|
|
19
|
+
value: 0n,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { OpenDisputeTxParams, RawTransaction } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Build open dispute transactions.
|
|
4
|
+
* Reads the dispute fee from the contract, builds approval + openDispute.
|
|
5
|
+
*/
|
|
6
|
+
export declare function buildOpenDisputeRawTx(params: OpenDisputeTxParams & {
|
|
7
|
+
rpcUrl: string;
|
|
8
|
+
}): Promise<RawTransaction[]>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { encodeFunctionData } from "viem";
|
|
2
|
+
import { MarketsAbi } from "../abi/MarketsAbi.js";
|
|
3
|
+
import { OPEN_DISPUTE } from "../constants/contractmethods.js";
|
|
4
|
+
import { getDisputeAppealFee } from "../markets/getDisputeFee.js";
|
|
5
|
+
import { getMarketBaseToken } from "../markets/getResolverBondAmount.js";
|
|
6
|
+
import { buildApproveRawTx } from "./buildApprovalRawTx.js";
|
|
7
|
+
/**
|
|
8
|
+
* Build open dispute transactions.
|
|
9
|
+
* Reads the dispute fee from the contract, builds approval + openDispute.
|
|
10
|
+
*/
|
|
11
|
+
export async function buildOpenDisputeRawTx(params) {
|
|
12
|
+
const { marketContractAddress, option, rpcUrl } = params;
|
|
13
|
+
if (!marketContractAddress)
|
|
14
|
+
throw new Error("marketContractAddress is required");
|
|
15
|
+
if (option === undefined || option === null)
|
|
16
|
+
throw new Error("option is required");
|
|
17
|
+
const [disputeFee, baseToken] = await Promise.all([
|
|
18
|
+
getDisputeAppealFee({ marketContractAddress, option, rpcUrl }),
|
|
19
|
+
getMarketBaseToken({ marketContractAddress, rpcUrl }),
|
|
20
|
+
]);
|
|
21
|
+
const txs = [];
|
|
22
|
+
if (disputeFee > 0n) {
|
|
23
|
+
txs.push(buildApproveRawTx({
|
|
24
|
+
tokenAddress: baseToken,
|
|
25
|
+
spender: marketContractAddress,
|
|
26
|
+
amount: disputeFee,
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
txs.push({
|
|
30
|
+
to: marketContractAddress,
|
|
31
|
+
data: encodeFunctionData({
|
|
32
|
+
abi: MarketsAbi,
|
|
33
|
+
functionName: OPEN_DISPUTE,
|
|
34
|
+
args: [option],
|
|
35
|
+
}),
|
|
36
|
+
value: 0n,
|
|
37
|
+
});
|
|
38
|
+
return txs;
|
|
39
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { PlaceBuyOrderTxParams, PlaceSellOrderTxParams, RawTransaction } from "./types.js";
|
|
2
|
+
export declare function buildPlaceBuyOrderRawTx(params: PlaceBuyOrderTxParams): RawTransaction;
|
|
3
|
+
export declare function buildPlaceSellOrderRawTx(params: PlaceSellOrderTxParams): RawTransaction;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { encodeFunctionData } from "viem";
|
|
2
|
+
import { MarketsAbi } from "../abi/MarketsAbi.js";
|
|
3
|
+
import { PLACE_BUY_ORDER, PLACE_SELL_ORDER } from "../constants/contractmethods.js";
|
|
4
|
+
export function buildPlaceBuyOrderRawTx(params) {
|
|
5
|
+
const { marketContractAddress, option, optionSide, price, amount } = params;
|
|
6
|
+
if (!marketContractAddress)
|
|
7
|
+
throw new Error("marketContractAddress is required");
|
|
8
|
+
if (option === undefined || option === null)
|
|
9
|
+
throw new Error("option is required");
|
|
10
|
+
if (optionSide === undefined || optionSide === null)
|
|
11
|
+
throw new Error("optionSide is required");
|
|
12
|
+
if (!price || price <= 0n)
|
|
13
|
+
throw new Error("price must be greater than 0");
|
|
14
|
+
if (!amount || amount <= 0n)
|
|
15
|
+
throw new Error("amount must be greater than 0");
|
|
16
|
+
return {
|
|
17
|
+
to: marketContractAddress,
|
|
18
|
+
data: encodeFunctionData({
|
|
19
|
+
abi: MarketsAbi,
|
|
20
|
+
functionName: PLACE_BUY_ORDER,
|
|
21
|
+
args: [option, optionSide, price, amount],
|
|
22
|
+
}),
|
|
23
|
+
value: 0n,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function buildPlaceSellOrderRawTx(params) {
|
|
27
|
+
const { marketContractAddress, option, optionSide, price, shares } = params;
|
|
28
|
+
if (!marketContractAddress)
|
|
29
|
+
throw new Error("marketContractAddress is required");
|
|
30
|
+
if (option === undefined || option === null)
|
|
31
|
+
throw new Error("option is required");
|
|
32
|
+
if (optionSide === undefined || optionSide === null)
|
|
33
|
+
throw new Error("optionSide is required");
|
|
34
|
+
if (!price || price <= 0n)
|
|
35
|
+
throw new Error("price must be greater than 0");
|
|
36
|
+
if (!shares || shares <= 0n)
|
|
37
|
+
throw new Error("shares must be greater than 0");
|
|
38
|
+
return {
|
|
39
|
+
to: marketContractAddress,
|
|
40
|
+
data: encodeFunctionData({
|
|
41
|
+
abi: MarketsAbi,
|
|
42
|
+
functionName: PLACE_SELL_ORDER,
|
|
43
|
+
args: [option, optionSide, price, shares],
|
|
44
|
+
}),
|
|
45
|
+
value: 0n,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { encodeFunctionData } from "viem";
|
|
2
|
+
import { MarketsAbi } from "../abi/MarketsAbi.js";
|
|
3
|
+
import { REMOVE_LIQUIDITY } from "../constants/contractmethods.js";
|
|
4
|
+
export function buildRemoveLiquidityRawTx(params) {
|
|
5
|
+
const { marketContractAddress, option, lpShares } = params;
|
|
6
|
+
if (!marketContractAddress)
|
|
7
|
+
throw new Error("marketContractAddress is required");
|
|
8
|
+
if (option === undefined || option === null)
|
|
9
|
+
throw new Error("option is required");
|
|
10
|
+
if (!lpShares)
|
|
11
|
+
throw new Error("lpShares is required");
|
|
12
|
+
if (lpShares <= 0n)
|
|
13
|
+
throw new Error("lpShares must be greater than 0");
|
|
14
|
+
return {
|
|
15
|
+
to: marketContractAddress,
|
|
16
|
+
data: encodeFunctionData({
|
|
17
|
+
abi: MarketsAbi,
|
|
18
|
+
functionName: REMOVE_LIQUIDITY,
|
|
19
|
+
args: [option, lpShares],
|
|
20
|
+
}),
|
|
21
|
+
value: 0n,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { encodeFunctionData } from "viem";
|
|
2
|
+
import { MarketsAbi } from "../abi/MarketsAbi.js";
|
|
3
|
+
import { SPLIT } from "../constants/contractmethods.js";
|
|
4
|
+
export function buildSplitRawTx(params) {
|
|
5
|
+
const { marketContractAddress, option, amount } = params;
|
|
6
|
+
if (!marketContractAddress)
|
|
7
|
+
throw new Error("marketContractAddress is required");
|
|
8
|
+
if (option === undefined || option === null)
|
|
9
|
+
throw new Error("option is required");
|
|
10
|
+
if (!amount || amount <= 0n)
|
|
11
|
+
throw new Error("amount must be greater than 0");
|
|
12
|
+
return {
|
|
13
|
+
to: marketContractAddress,
|
|
14
|
+
data: encodeFunctionData({
|
|
15
|
+
abi: MarketsAbi,
|
|
16
|
+
functionName: SPLIT,
|
|
17
|
+
args: [option, amount],
|
|
18
|
+
}),
|
|
19
|
+
value: 0n,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
export interface RawTransaction {
|
|
2
|
+
to: `0x${string}`;
|
|
3
|
+
data: `0x${string}`;
|
|
4
|
+
value?: bigint;
|
|
5
|
+
}
|
|
6
|
+
export type ApproveTxParams = {
|
|
7
|
+
tokenAddress: `0x${string}`;
|
|
8
|
+
spender: `0x${string}`;
|
|
9
|
+
amount: bigint;
|
|
10
|
+
};
|
|
11
|
+
export declare enum TradingModel {
|
|
12
|
+
AMM = 0,
|
|
13
|
+
OrderBook = 1
|
|
14
|
+
}
|
|
15
|
+
export declare enum OptionSide {
|
|
16
|
+
Yes = 1,
|
|
17
|
+
No = 2
|
|
18
|
+
}
|
|
19
|
+
export interface EnterOptionTxParams {
|
|
20
|
+
marketContractAddress: `0x${string}`;
|
|
21
|
+
selectedOption: bigint;
|
|
22
|
+
optionSide: OptionSide;
|
|
23
|
+
buyAmountInWei: bigint;
|
|
24
|
+
}
|
|
25
|
+
export interface PlaceBuyOrderTxParams {
|
|
26
|
+
marketContractAddress: `0x${string}`;
|
|
27
|
+
option: bigint;
|
|
28
|
+
optionSide: OptionSide;
|
|
29
|
+
price: bigint;
|
|
30
|
+
amount: bigint;
|
|
31
|
+
}
|
|
32
|
+
export interface PlaceSellOrderTxParams {
|
|
33
|
+
marketContractAddress: `0x${string}`;
|
|
34
|
+
option: bigint;
|
|
35
|
+
optionSide: OptionSide;
|
|
36
|
+
price: bigint;
|
|
37
|
+
shares: bigint;
|
|
38
|
+
}
|
|
39
|
+
export interface CancelBuyOrdersTxParams {
|
|
40
|
+
marketContractAddress: `0x${string}`;
|
|
41
|
+
option: bigint;
|
|
42
|
+
optionSides: number[];
|
|
43
|
+
prices: bigint[];
|
|
44
|
+
orderIDs: bigint[];
|
|
45
|
+
}
|
|
46
|
+
export interface CancelSellOrdersTxParams {
|
|
47
|
+
marketContractAddress: `0x${string}`;
|
|
48
|
+
option: bigint;
|
|
49
|
+
optionSides: number[];
|
|
50
|
+
prices: bigint[];
|
|
51
|
+
orderIDs: bigint[];
|
|
52
|
+
}
|
|
53
|
+
export interface ClaimTxParams {
|
|
54
|
+
marketContractAddress: `0x${string}`;
|
|
55
|
+
option: bigint;
|
|
56
|
+
}
|
|
57
|
+
export interface OpenDisputeTxParams {
|
|
58
|
+
marketContractAddress: `0x${string}`;
|
|
59
|
+
option: bigint;
|
|
60
|
+
}
|
|
61
|
+
export interface ClosePoolAITxParams {
|
|
62
|
+
marketContractAddress: `0x${string}`;
|
|
63
|
+
option: bigint;
|
|
64
|
+
}
|
|
65
|
+
export interface ClosePoolManualTxParams {
|
|
66
|
+
marketContractAddress: `0x${string}`;
|
|
67
|
+
option: bigint;
|
|
68
|
+
proposedWinner: number;
|
|
69
|
+
}
|
|
70
|
+
export interface ChooseWinnerTxParams {
|
|
71
|
+
marketContractAddress: `0x${string}`;
|
|
72
|
+
option: bigint;
|
|
73
|
+
optionSide: number;
|
|
74
|
+
}
|
|
75
|
+
export interface SplitTxParams {
|
|
76
|
+
marketContractAddress: `0x${string}`;
|
|
77
|
+
option: bigint;
|
|
78
|
+
amount: bigint;
|
|
79
|
+
}
|
|
80
|
+
export interface MergeTxParams {
|
|
81
|
+
marketContractAddress: `0x${string}`;
|
|
82
|
+
option: bigint;
|
|
83
|
+
amount: bigint;
|
|
84
|
+
}
|
|
85
|
+
export interface AddLiquidityTxParams {
|
|
86
|
+
marketContractAddress: `0x${string}`;
|
|
87
|
+
option: bigint;
|
|
88
|
+
totalAmountInWei: bigint;
|
|
89
|
+
}
|
|
90
|
+
export interface RemoveLiquidityTxParams {
|
|
91
|
+
marketContractAddress: `0x${string}`;
|
|
92
|
+
option: bigint;
|
|
93
|
+
lpShares: bigint;
|
|
94
|
+
}
|
|
95
|
+
export interface CreateMarketTxParams {
|
|
96
|
+
marketQuestion: string;
|
|
97
|
+
marketOptions: string[];
|
|
98
|
+
marketTags: string[];
|
|
99
|
+
marketDescription: string;
|
|
100
|
+
isPublic: boolean;
|
|
101
|
+
isPublicPoolResolverAi: boolean;
|
|
102
|
+
creator: `0x${string}`;
|
|
103
|
+
startTime: bigint;
|
|
104
|
+
endTime: bigint;
|
|
105
|
+
no_of_options: bigint;
|
|
106
|
+
disputeTimer: number;
|
|
107
|
+
inputAmountWei: bigint;
|
|
108
|
+
barValues: number[];
|
|
109
|
+
baseToken: `0x${string}`;
|
|
110
|
+
tradingModel?: TradingModel;
|
|
111
|
+
questionImage?: string;
|
|
112
|
+
tokenDecimals?: number;
|
|
113
|
+
factoryContractAddress?: `0x${string}`;
|
|
114
|
+
oracleFixedFeePerOption?: bigint;
|
|
115
|
+
apiUrl?: string;
|
|
116
|
+
rpcUrl?: string;
|
|
117
|
+
}
|
package/dist/tx/types.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export var TradingModel;
|
|
2
|
+
(function (TradingModel) {
|
|
3
|
+
TradingModel[TradingModel["AMM"] = 0] = "AMM";
|
|
4
|
+
TradingModel[TradingModel["OrderBook"] = 1] = "OrderBook";
|
|
5
|
+
})(TradingModel || (TradingModel = {}));
|
|
6
|
+
export var OptionSide;
|
|
7
|
+
(function (OptionSide) {
|
|
8
|
+
OptionSide[OptionSide["Yes"] = 1] = "Yes";
|
|
9
|
+
OptionSide[OptionSide["No"] = 2] = "No";
|
|
10
|
+
})(OptionSide || (OptionSide = {}));
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { WalletClient } from 'viem';
|
|
2
|
+
import { Chain } from 'viem/chains';
|
|
3
|
+
export interface RainConfig {
|
|
4
|
+
walletClient: WalletClient;
|
|
5
|
+
alchemyApiKey?: string;
|
|
6
|
+
paymasterPolicyId?: string;
|
|
7
|
+
chain: Chain;
|
|
8
|
+
rpcUrl?: string;
|
|
9
|
+
}
|
|
10
|
+
export type RainEnvironment = "development";
|
|
11
|
+
export interface RainCoreConfig {
|
|
12
|
+
environment?: RainEnvironment;
|
|
13
|
+
rpcUrl?: string;
|
|
14
|
+
apiUrl?: string;
|
|
15
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CreateMarketTxParams } from "../tx/types.js";
|
|
2
|
+
export declare const convertToWeiEthers: (value: string | bigint, decimals: number) => bigint;
|
|
3
|
+
export declare function isRpcValid(rpcUrl: string | undefined): Promise<boolean>;
|
|
4
|
+
export declare function getUserAllowance(params: CreateMarketTxParams): Promise<number>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ethers, JsonRpcProvider, Contract } from "ethers";
|
|
2
|
+
import { ERC20Abi } from "../abi/ERC20Abi.js";
|
|
3
|
+
export const convertToWeiEthers = (value, decimals) => {
|
|
4
|
+
return ethers.parseUnits(value.toString(), decimals);
|
|
5
|
+
};
|
|
6
|
+
export async function isRpcValid(rpcUrl) {
|
|
7
|
+
if (!rpcUrl)
|
|
8
|
+
return false;
|
|
9
|
+
const provider = new JsonRpcProvider(rpcUrl);
|
|
10
|
+
try {
|
|
11
|
+
await provider.getNetwork();
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export async function getUserAllowance(params) {
|
|
19
|
+
const { factoryContractAddress, baseToken, creator, rpcUrl } = params;
|
|
20
|
+
const isRpcWorking = await isRpcValid(rpcUrl);
|
|
21
|
+
if (!rpcUrl || !isRpcWorking) {
|
|
22
|
+
throw new Error("Provided RPC URL is not valid or not working");
|
|
23
|
+
}
|
|
24
|
+
const provider = new JsonRpcProvider(rpcUrl);
|
|
25
|
+
const ERC20ApprovalContract = new Contract(baseToken, ERC20Abi, provider);
|
|
26
|
+
const userAllowance = await ERC20ApprovalContract.allowance(creator, factoryContractAddress);
|
|
27
|
+
return userAllowance;
|
|
28
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rain-sdk-v2",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
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
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"dev": "tsc -w",
|
|
21
|
+
"prepublishOnly": "npm run build"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/UsamaShafique/rain-sdk-v2.git"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"web3",
|
|
29
|
+
"account-abstraction",
|
|
30
|
+
"smart-account",
|
|
31
|
+
"rain",
|
|
32
|
+
"viem",
|
|
33
|
+
"alchemy"
|
|
34
|
+
],
|
|
35
|
+
"author": "Rain Protocol",
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@account-kit/infra": "^4.48.0",
|
|
39
|
+
"@account-kit/wallet-client": "^0.1.0-alpha.10",
|
|
40
|
+
"@alchemy/aa-alchemy": "^3.0.0",
|
|
41
|
+
"@alchemy/aa-core": "^3.0.0",
|
|
42
|
+
"viem": "^2.0.0"
|
|
43
|
+
},
|
|
44
|
+
"peerDependenciesMeta": {
|
|
45
|
+
"@account-kit/infra": {
|
|
46
|
+
"optional": true
|
|
47
|
+
},
|
|
48
|
+
"@account-kit/wallet-client": {
|
|
49
|
+
"optional": true
|
|
50
|
+
},
|
|
51
|
+
"@alchemy/aa-alchemy": {
|
|
52
|
+
"optional": true
|
|
53
|
+
},
|
|
54
|
+
"@alchemy/aa-core": {
|
|
55
|
+
"optional": true
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"ethers": "^6.16.0",
|
|
60
|
+
"socket.io-client": "^4.8.3"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"typescript": "^5.9.3",
|
|
64
|
+
"viem": "^2.48.8"
|
|
65
|
+
}
|
|
66
|
+
}
|