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,60 @@
|
|
|
1
|
+
import { buildHeaders, buildQuery, handleResponse } from './helpers.js';
|
|
2
|
+
export async function findUserByWalletAddress(params, config) {
|
|
3
|
+
const qs = buildQuery({ walletAddress: params.walletAddress });
|
|
4
|
+
const res = await fetch(`${config.apiUrl}/users/find-user-by-wallet-address${qs}`, {
|
|
5
|
+
method: 'GET',
|
|
6
|
+
headers: buildHeaders(config),
|
|
7
|
+
});
|
|
8
|
+
return handleResponse(res);
|
|
9
|
+
}
|
|
10
|
+
export async function updateUserProfile(params, config) {
|
|
11
|
+
const res = await fetch(`${config.apiUrl}/users/user-profile-update`, {
|
|
12
|
+
method: 'PATCH',
|
|
13
|
+
headers: buildHeaders(config, 'application/json'),
|
|
14
|
+
body: JSON.stringify(params),
|
|
15
|
+
});
|
|
16
|
+
return handleResponse(res);
|
|
17
|
+
}
|
|
18
|
+
export async function getUserProfile(config) {
|
|
19
|
+
const res = await fetch(`${config.apiUrl}/users/user-profile`, {
|
|
20
|
+
method: 'GET',
|
|
21
|
+
headers: buildHeaders(config),
|
|
22
|
+
});
|
|
23
|
+
return handleResponse(res);
|
|
24
|
+
}
|
|
25
|
+
export async function getUsersTotalCount(config) {
|
|
26
|
+
const res = await fetch(`${config.apiUrl}/users/users-total-count`, {
|
|
27
|
+
method: 'GET',
|
|
28
|
+
headers: buildHeaders(config),
|
|
29
|
+
});
|
|
30
|
+
return handleResponse(res);
|
|
31
|
+
}
|
|
32
|
+
export async function removeUserProfilePic(config) {
|
|
33
|
+
const res = await fetch(`${config.apiUrl}/users/remove-user-profile-pic`, {
|
|
34
|
+
method: 'PATCH',
|
|
35
|
+
headers: buildHeaders(config),
|
|
36
|
+
});
|
|
37
|
+
return handleResponse(res);
|
|
38
|
+
}
|
|
39
|
+
export async function getUserHistory(params, config) {
|
|
40
|
+
const qs = buildQuery({ limit: params.limit, offset: params.offset });
|
|
41
|
+
const res = await fetch(`${config.apiUrl}/users/get-user-history${qs}`, {
|
|
42
|
+
method: 'GET',
|
|
43
|
+
headers: buildHeaders(config),
|
|
44
|
+
});
|
|
45
|
+
return handleResponse(res);
|
|
46
|
+
}
|
|
47
|
+
export async function viewUserProfile(params, config) {
|
|
48
|
+
const res = await fetch(`${config.apiUrl}/users/view-user-profile/${encodeURIComponent(params.userId)}`, {
|
|
49
|
+
method: 'GET',
|
|
50
|
+
headers: buildHeaders(config),
|
|
51
|
+
});
|
|
52
|
+
return handleResponse(res);
|
|
53
|
+
}
|
|
54
|
+
export async function checkTokenExpiration(config) {
|
|
55
|
+
const res = await fetch(`${config.apiUrl}/users/check-token-expiration`, {
|
|
56
|
+
method: 'GET',
|
|
57
|
+
headers: buildHeaders(config),
|
|
58
|
+
});
|
|
59
|
+
return handleResponse(res);
|
|
60
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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: {
|
|
6
|
+
'Content-Type': 'application/json',
|
|
7
|
+
...(apiUrl.includes('ngrok') ? { 'ngrok-skip-browser-warning': 'true' } : {}),
|
|
8
|
+
},
|
|
9
|
+
body: JSON.stringify({
|
|
10
|
+
sign: signature,
|
|
11
|
+
walletAddress,
|
|
12
|
+
userSmartAddress: smartWalletAddress,
|
|
13
|
+
...(referredBy ? { referredBy } : {}),
|
|
14
|
+
}),
|
|
15
|
+
});
|
|
16
|
+
if (!res.ok) {
|
|
17
|
+
const text = await res.text().catch(() => res.statusText);
|
|
18
|
+
throw new Error(`Login failed (${res.status}): ${text}`);
|
|
19
|
+
}
|
|
20
|
+
const data = await res.json();
|
|
21
|
+
const accessToken = data?.token;
|
|
22
|
+
const userId = data?.user?._id;
|
|
23
|
+
if (!accessToken || !userId) {
|
|
24
|
+
throw new Error('Login response missing token or user id');
|
|
25
|
+
}
|
|
26
|
+
return { accessToken, userId };
|
|
27
|
+
}
|
|
@@ -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 {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const ALLOWED_ENVIRONMENTS: readonly ["development"];
|
|
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 ENV_CONFIG: {
|
|
6
|
+
readonly development: {
|
|
7
|
+
readonly apiUrl: "https://dev2-api.rain.one";
|
|
8
|
+
readonly market_factory_address: `0x${string}`;
|
|
9
|
+
readonly dispute_initial_timer: number;
|
|
10
|
+
readonly oracle_fixed_fee_per_option: 1000000n;
|
|
11
|
+
readonly usdt_symbol: "USDTm";
|
|
12
|
+
readonly usdt_token: `0x${string}`;
|
|
13
|
+
readonly rain_token: `0x${string}`;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export const ALLOWED_ENVIRONMENTS = ["development"];
|
|
2
|
+
export const DEFAULT_RPCS = [
|
|
3
|
+
"https://arb1.arbitrum.io/rpc",
|
|
4
|
+
"https://arbitrum-one.publicnode.com",
|
|
5
|
+
"https://rpc.sentio.xyz/arbitrum-one"
|
|
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";
|
|
13
|
+
export const ENV_CONFIG = {
|
|
14
|
+
development: {
|
|
15
|
+
apiUrl: "https://dev2-api.rain.one",
|
|
16
|
+
market_factory_address: "0xBD99441C4116b85dFecA2d6521EC0e2Eb62F0adE",
|
|
17
|
+
dispute_initial_timer: 1 * 60,
|
|
18
|
+
oracle_fixed_fee_per_option: 1000000n, // $1 per option (6 decimals)
|
|
19
|
+
usdt_symbol: USDT_SYMBOL_DEV,
|
|
20
|
+
usdt_token: "0xCa4f77A38d8552Dd1D5E44e890173921B67725F4",
|
|
21
|
+
rain_token: "0x25118290e6A5f4139381D072181157035864099d",
|
|
22
|
+
},
|
|
23
|
+
// stage: {
|
|
24
|
+
// apiUrl: "https://stg-api.rain.one",
|
|
25
|
+
// market_factory_address: "0xD4900CA167228365806FBA4cB21f7EAe8b6d96BE" as `0x${string}`,
|
|
26
|
+
// dispute_initial_timer: 1 * 60,
|
|
27
|
+
// oracle_fixed_fee_per_option: 1_000_000n, // $1 per option (6 decimals)
|
|
28
|
+
// usdt_symbol: USDT_SYMBOL_PROD,
|
|
29
|
+
// usdt_token: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9" as `0x${string}`,
|
|
30
|
+
// rain_token: "0x43976a124e6834b541840Ce741243dAD3dd538DA" as `0x${string}`,
|
|
31
|
+
// },
|
|
32
|
+
// production: {
|
|
33
|
+
// apiUrl: "https://prod-api.rain.one",
|
|
34
|
+
// market_factory_address: "0xA8640B62D755e42C9ed6A86d0fc65CE09e31F264" as `0x${string}`,
|
|
35
|
+
// dispute_initial_timer: 120 * 60,
|
|
36
|
+
// oracle_fixed_fee_per_option: 1_000_000n, // $1 per option (6 decimals)
|
|
37
|
+
// usdt_symbol: USDT_SYMBOL_PROD,
|
|
38
|
+
// usdt_token: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9" as `0x${string}`,
|
|
39
|
+
// rain_token: "0x43976a124e6834b541840Ce741243dAD3dd538DA" as `0x${string}`,
|
|
40
|
+
// },
|
|
41
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const APPROVE_TOKEN = "approve";
|
|
2
|
+
export declare const CREATE_MARKET = "createPool";
|
|
3
|
+
export declare const ENTER_OPTION = "enterOption";
|
|
4
|
+
export declare const ENTER_LIQUIDITY = "enterLiquidity";
|
|
5
|
+
export declare const REMOVE_LIQUIDITY = "removeLiquidity";
|
|
6
|
+
export declare const SPLIT = "split";
|
|
7
|
+
export declare const MERGE = "merge";
|
|
8
|
+
export declare const CLOSE_POOL = "closePool";
|
|
9
|
+
export declare const CHOOSE_WINNER = "chooseWinner";
|
|
10
|
+
export declare const PLACE_BUY_ORDER = "placeBuyOrder";
|
|
11
|
+
export declare const PLACE_SELL_ORDER = "placeSellOrder";
|
|
12
|
+
export declare const OPEN_DISPUTE = "openDispute";
|
|
13
|
+
export declare const CLAIM = "claim";
|
|
14
|
+
export declare const CANCEL_BUY_ORDERS = "cancelBuyOrders";
|
|
15
|
+
export declare const CANCEL_SELL_ORDERS = "cancelSellOrders";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const APPROVE_TOKEN = 'approve';
|
|
2
|
+
export const CREATE_MARKET = 'createPool';
|
|
3
|
+
export const ENTER_OPTION = 'enterOption';
|
|
4
|
+
export const ENTER_LIQUIDITY = 'enterLiquidity';
|
|
5
|
+
export const REMOVE_LIQUIDITY = 'removeLiquidity';
|
|
6
|
+
export const SPLIT = 'split';
|
|
7
|
+
export const MERGE = 'merge';
|
|
8
|
+
export const CLOSE_POOL = 'closePool';
|
|
9
|
+
export const CHOOSE_WINNER = 'chooseWinner';
|
|
10
|
+
export const PLACE_BUY_ORDER = 'placeBuyOrder';
|
|
11
|
+
export const PLACE_SELL_ORDER = 'placeSellOrder';
|
|
12
|
+
export const OPEN_DISPUTE = 'openDispute';
|
|
13
|
+
export const CLAIM = 'claim';
|
|
14
|
+
export const CANCEL_BUY_ORDERS = 'cancelBuyOrders';
|
|
15
|
+
export const CANCEL_SELL_ORDERS = 'cancelSellOrders';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { Rain } from './Rain.js';
|
|
2
|
+
export { RainAA } from './RainAA.js';
|
|
3
|
+
export * from './types.js';
|
|
4
|
+
export { TradingModel, OptionSide } from './tx/types.js';
|
|
5
|
+
export type { CreateMarketTxParams, EnterOptionTxParams, AddLiquidityTxParams, RemoveLiquidityTxParams, SplitTxParams, MergeTxParams, ClosePoolAITxParams, ClosePoolManualTxParams, ChooseWinnerTxParams, PlaceBuyOrderTxParams, PlaceSellOrderTxParams, OpenDisputeTxParams, ClaimTxParams, CancelBuyOrdersTxParams, CancelSellOrdersTxParams, RawTransaction, ApproveTxParams } from './tx/types.js';
|
|
6
|
+
export type { LoginParams, LoginResult } from './auth/types.js';
|
|
7
|
+
export * from './api/index.js';
|
|
8
|
+
export { RainSocket } from './socket/RainSocket.js';
|
|
9
|
+
export type { RainSocketEvent, EnterOptionEventData, ExitOptionEventData, LiquidityEventData, SplitEventData, MergeEventData, RemoveLiquidityEventData, SyncPriceEventData, OrderCreatedEventData, OrderCancelledEventData, OrderFilledEventData, PoolClosedEventData, PoolEventData, WinnerEventData, DisputeOpenedEventData, OracleCreatedEventData, AppealOpenedEventData, DisputeWinnerEventData, AppealWinnerEventData, ClaimRewardEventData, DisputeRefundEventData } from './socket/RainSocket.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createPublicClient, http, parseAbi } from 'viem';
|
|
2
|
+
import { arbitrum } from 'viem/chains';
|
|
3
|
+
const disputeFeeAbi = parseAbi([
|
|
4
|
+
'function getDisputeAppealFee(uint256 option) view returns (uint256 disputeFee)',
|
|
5
|
+
]);
|
|
6
|
+
export async function getDisputeAppealFee(params) {
|
|
7
|
+
const { marketContractAddress, option, rpcUrl } = params;
|
|
8
|
+
const client = createPublicClient({
|
|
9
|
+
chain: arbitrum,
|
|
10
|
+
transport: http(rpcUrl),
|
|
11
|
+
});
|
|
12
|
+
const fee = await client.readContract({
|
|
13
|
+
address: marketContractAddress,
|
|
14
|
+
abi: disputeFeeAbi,
|
|
15
|
+
functionName: 'getDisputeAppealFee',
|
|
16
|
+
args: [option],
|
|
17
|
+
});
|
|
18
|
+
return fee;
|
|
19
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export declare function getUserActiveBuyOrders(params: {
|
|
2
|
+
marketContractAddress: `0x${string}`;
|
|
3
|
+
userAddress: `0x${string}`;
|
|
4
|
+
rpcUrl: string;
|
|
5
|
+
}): Promise<bigint>;
|
|
6
|
+
export declare function getUserActiveSellOrders(params: {
|
|
7
|
+
marketContractAddress: `0x${string}`;
|
|
8
|
+
userAddress: `0x${string}`;
|
|
9
|
+
rpcUrl: string;
|
|
10
|
+
}): Promise<bigint>;
|
|
11
|
+
export declare function getFirstBuyOrderPrice(params: {
|
|
12
|
+
marketContractAddress: `0x${string}`;
|
|
13
|
+
option: bigint;
|
|
14
|
+
optionSide: number;
|
|
15
|
+
rpcUrl: string;
|
|
16
|
+
}): Promise<bigint>;
|
|
17
|
+
export declare function getFirstSellOrderPrice(params: {
|
|
18
|
+
marketContractAddress: `0x${string}`;
|
|
19
|
+
option: bigint;
|
|
20
|
+
optionSide: number;
|
|
21
|
+
rpcUrl: string;
|
|
22
|
+
}): Promise<bigint>;
|
|
23
|
+
export interface OrderLevelInfo {
|
|
24
|
+
headIndex: bigint;
|
|
25
|
+
tailIndex: bigint;
|
|
26
|
+
count: bigint;
|
|
27
|
+
isInitialized: boolean;
|
|
28
|
+
}
|
|
29
|
+
export declare function getBuyOrdersAtPrice(params: {
|
|
30
|
+
marketContractAddress: `0x${string}`;
|
|
31
|
+
option: bigint;
|
|
32
|
+
optionSide: number;
|
|
33
|
+
price: bigint;
|
|
34
|
+
rpcUrl: string;
|
|
35
|
+
}): Promise<OrderLevelInfo>;
|
|
36
|
+
export declare function getSellOrdersAtPrice(params: {
|
|
37
|
+
marketContractAddress: `0x${string}`;
|
|
38
|
+
option: bigint;
|
|
39
|
+
optionSide: number;
|
|
40
|
+
price: bigint;
|
|
41
|
+
rpcUrl: string;
|
|
42
|
+
}): Promise<OrderLevelInfo>;
|
|
43
|
+
export declare function checkOrderExists(params: {
|
|
44
|
+
marketContractAddress: `0x${string}`;
|
|
45
|
+
option: bigint;
|
|
46
|
+
optionSide: number;
|
|
47
|
+
price: bigint;
|
|
48
|
+
orderID: bigint;
|
|
49
|
+
rpcUrl: string;
|
|
50
|
+
}): Promise<{
|
|
51
|
+
exists: boolean;
|
|
52
|
+
index: bigint;
|
|
53
|
+
}>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { createPublicClient, http, parseAbi } from 'viem';
|
|
2
|
+
import { arbitrum } from 'viem/chains';
|
|
3
|
+
const orderInfoAbi = parseAbi([
|
|
4
|
+
'function userActiveBuyOrders(address user) view returns (uint256)',
|
|
5
|
+
'function userActiveSellOrders(address user) view returns (uint256)',
|
|
6
|
+
'function firstBuyOrderPrice(uint256 option, uint8 optionSide) view returns (uint256)',
|
|
7
|
+
'function firstSellOrderPrice(uint256 option, uint8 optionSide) view returns (uint256)',
|
|
8
|
+
'function buyOrders(uint256 option, uint8 optionSide, uint256 price) view returns (int256 headIndex, int256 tailIndex, int256 count, bool isInitialized)',
|
|
9
|
+
'function sellOrders(uint256 option, uint8 optionSide, uint256 price) view returns (int256 headIndex, int256 tailIndex, int256 count, bool isInitialized)',
|
|
10
|
+
'function orderBook(uint256 option, uint8 optionSide, uint256 price, uint256 orderID) view returns (bool exists, int256 index)',
|
|
11
|
+
]);
|
|
12
|
+
function getClient(rpcUrl) {
|
|
13
|
+
return createPublicClient({ chain: arbitrum, transport: http(rpcUrl) });
|
|
14
|
+
}
|
|
15
|
+
export async function getUserActiveBuyOrders(params) {
|
|
16
|
+
const client = getClient(params.rpcUrl);
|
|
17
|
+
return await client.readContract({
|
|
18
|
+
address: params.marketContractAddress,
|
|
19
|
+
abi: orderInfoAbi,
|
|
20
|
+
functionName: 'userActiveBuyOrders',
|
|
21
|
+
args: [params.userAddress],
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export async function getUserActiveSellOrders(params) {
|
|
25
|
+
const client = getClient(params.rpcUrl);
|
|
26
|
+
return await client.readContract({
|
|
27
|
+
address: params.marketContractAddress,
|
|
28
|
+
abi: orderInfoAbi,
|
|
29
|
+
functionName: 'userActiveSellOrders',
|
|
30
|
+
args: [params.userAddress],
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export async function getFirstBuyOrderPrice(params) {
|
|
34
|
+
const client = getClient(params.rpcUrl);
|
|
35
|
+
return await client.readContract({
|
|
36
|
+
address: params.marketContractAddress,
|
|
37
|
+
abi: orderInfoAbi,
|
|
38
|
+
functionName: 'firstBuyOrderPrice',
|
|
39
|
+
args: [params.option, params.optionSide],
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
export async function getFirstSellOrderPrice(params) {
|
|
43
|
+
const client = getClient(params.rpcUrl);
|
|
44
|
+
return await client.readContract({
|
|
45
|
+
address: params.marketContractAddress,
|
|
46
|
+
abi: orderInfoAbi,
|
|
47
|
+
functionName: 'firstSellOrderPrice',
|
|
48
|
+
args: [params.option, params.optionSide],
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export async function getBuyOrdersAtPrice(params) {
|
|
52
|
+
const client = getClient(params.rpcUrl);
|
|
53
|
+
const [headIndex, tailIndex, count, isInitialized] = await client.readContract({
|
|
54
|
+
address: params.marketContractAddress,
|
|
55
|
+
abi: orderInfoAbi,
|
|
56
|
+
functionName: 'buyOrders',
|
|
57
|
+
args: [params.option, params.optionSide, params.price],
|
|
58
|
+
});
|
|
59
|
+
return { headIndex, tailIndex, count, isInitialized };
|
|
60
|
+
}
|
|
61
|
+
export async function getSellOrdersAtPrice(params) {
|
|
62
|
+
const client = getClient(params.rpcUrl);
|
|
63
|
+
const [headIndex, tailIndex, count, isInitialized] = await client.readContract({
|
|
64
|
+
address: params.marketContractAddress,
|
|
65
|
+
abi: orderInfoAbi,
|
|
66
|
+
functionName: 'sellOrders',
|
|
67
|
+
args: [params.option, params.optionSide, params.price],
|
|
68
|
+
});
|
|
69
|
+
return { headIndex, tailIndex, count, isInitialized };
|
|
70
|
+
}
|
|
71
|
+
export async function checkOrderExists(params) {
|
|
72
|
+
const client = getClient(params.rpcUrl);
|
|
73
|
+
const [exists, index] = await client.readContract({
|
|
74
|
+
address: params.marketContractAddress,
|
|
75
|
+
abi: orderInfoAbi,
|
|
76
|
+
functionName: 'orderBook',
|
|
77
|
+
args: [params.option, params.optionSide, params.price, params.orderID],
|
|
78
|
+
});
|
|
79
|
+
return { exists, index };
|
|
80
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function getResolverBondAmount(params: {
|
|
2
|
+
marketContractAddress: `0x${string}`;
|
|
3
|
+
option: bigint;
|
|
4
|
+
rpcUrl: string;
|
|
5
|
+
}): Promise<bigint>;
|
|
6
|
+
export declare function getMarketBaseToken(params: {
|
|
7
|
+
marketContractAddress: `0x${string}`;
|
|
8
|
+
rpcUrl: string;
|
|
9
|
+
}): Promise<`0x${string}`>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createPublicClient, http, parseAbi } from 'viem';
|
|
2
|
+
import { arbitrum } from 'viem/chains';
|
|
3
|
+
const resolverBondAbi = parseAbi([
|
|
4
|
+
'function getResolverBondAmount(uint256 option) view returns (uint256 resolverBondAmount)',
|
|
5
|
+
]);
|
|
6
|
+
const baseTokenAbi = parseAbi([
|
|
7
|
+
'function baseToken() view returns (address)',
|
|
8
|
+
]);
|
|
9
|
+
export async function getResolverBondAmount(params) {
|
|
10
|
+
const { marketContractAddress, option, rpcUrl } = params;
|
|
11
|
+
const client = createPublicClient({
|
|
12
|
+
chain: arbitrum,
|
|
13
|
+
transport: http(rpcUrl),
|
|
14
|
+
});
|
|
15
|
+
const bond = await client.readContract({
|
|
16
|
+
address: marketContractAddress,
|
|
17
|
+
abi: resolverBondAbi,
|
|
18
|
+
functionName: 'getResolverBondAmount',
|
|
19
|
+
args: [option],
|
|
20
|
+
});
|
|
21
|
+
return bond;
|
|
22
|
+
}
|
|
23
|
+
export async function getMarketBaseToken(params) {
|
|
24
|
+
const { marketContractAddress, rpcUrl } = params;
|
|
25
|
+
const client = createPublicClient({
|
|
26
|
+
chain: arbitrum,
|
|
27
|
+
transport: http(rpcUrl),
|
|
28
|
+
});
|
|
29
|
+
const token = await client.readContract({
|
|
30
|
+
address: marketContractAddress,
|
|
31
|
+
abi: baseTokenAbi,
|
|
32
|
+
functionName: 'baseToken',
|
|
33
|
+
});
|
|
34
|
+
return token;
|
|
35
|
+
}
|
|
@@ -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 getUserOptionLPShares(params) {
|
|
5
|
+
const { marketContractAddress, option, 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: 'userOptionLPShares',
|
|
14
|
+
args: [option, userAddress],
|
|
15
|
+
});
|
|
16
|
+
return shares;
|
|
17
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface GetUserOptionSharesParams {
|
|
2
|
+
marketContractAddress: `0x${string}`;
|
|
3
|
+
option: bigint;
|
|
4
|
+
optionSide: number;
|
|
5
|
+
userAddress: `0x${string}`;
|
|
6
|
+
rpcUrl: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function getUserOptionShares(params: GetUserOptionSharesParams): 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 getUserOptionShares(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: 'userOptionPerSideShares',
|
|
14
|
+
args: [option, optionSide, userAddress],
|
|
15
|
+
});
|
|
16
|
+
return shares;
|
|
17
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
export type RainSocketEvent = 'enter-option' | 'exit-option' | 'liquidity' | 'split' | 'merge' | 'remove-liquidity' | 'sync-price' | 'order-created' | 'order-cancelled' | 'order-filled' | 'pool-closed' | 'pool-reverted' | 'pool-token-set' | 'streamingStatusChanged' | 'winner' | 'winner-proposer' | 'reveal-winner-available' | 'dispute-opened' | 'oracle-created' | 'dispute-time-extented' | 'appeal-opened' | 'appeal-winner-calculated' | 'dispute-winner' | 'appeal-winner' | 'claim-reward' | 'dispute-refund' | 'appeal-refund' | 'resolution-refund' | 'resolver-reward' | 'notifications' | 'pool';
|
|
2
|
+
export interface EnterOptionEventData {
|
|
3
|
+
enterOption: Record<string, any>;
|
|
4
|
+
pool: Record<string, any>;
|
|
5
|
+
subPool: Record<string, any>;
|
|
6
|
+
}
|
|
7
|
+
export interface ExitOptionEventData {
|
|
8
|
+
exitOption: Record<string, any>;
|
|
9
|
+
pool: Record<string, any>;
|
|
10
|
+
subPool: Record<string, any>;
|
|
11
|
+
}
|
|
12
|
+
export interface LiquidityEventData {
|
|
13
|
+
enterLiquidity: Record<string, any>;
|
|
14
|
+
pool: Record<string, any>;
|
|
15
|
+
subPool: Record<string, any>;
|
|
16
|
+
}
|
|
17
|
+
export interface SplitEventData {
|
|
18
|
+
split: Record<string, any>;
|
|
19
|
+
pool: Record<string, any>;
|
|
20
|
+
subPool: Record<string, any>;
|
|
21
|
+
}
|
|
22
|
+
export interface MergeEventData {
|
|
23
|
+
merge: Record<string, any>;
|
|
24
|
+
pool: Record<string, any>;
|
|
25
|
+
subPool: Record<string, any>;
|
|
26
|
+
}
|
|
27
|
+
export interface RemoveLiquidityEventData {
|
|
28
|
+
removeLiquidity: Record<string, any>;
|
|
29
|
+
pool: Record<string, any>;
|
|
30
|
+
subPool: Record<string, any>;
|
|
31
|
+
}
|
|
32
|
+
export interface SyncPriceEventData {
|
|
33
|
+
prices: Array<{
|
|
34
|
+
side: number;
|
|
35
|
+
price: number;
|
|
36
|
+
percentage: number;
|
|
37
|
+
subPoolIndex: number;
|
|
38
|
+
}>;
|
|
39
|
+
pool: Record<string, any>;
|
|
40
|
+
subPool: Record<string, any>;
|
|
41
|
+
}
|
|
42
|
+
export interface OrderCreatedEventData {
|
|
43
|
+
order: Record<string, any>;
|
|
44
|
+
pool: Record<string, any>;
|
|
45
|
+
subPool: Record<string, any>;
|
|
46
|
+
}
|
|
47
|
+
export interface OrderCancelledEventData {
|
|
48
|
+
order: Record<string, any>;
|
|
49
|
+
pool: Record<string, any>;
|
|
50
|
+
subPool: Record<string, any>;
|
|
51
|
+
}
|
|
52
|
+
export interface OrderFilledEventData {
|
|
53
|
+
filledOrder: Record<string, any>;
|
|
54
|
+
pendingOrder?: Record<string, any>;
|
|
55
|
+
pool: Record<string, any>;
|
|
56
|
+
subPool: Record<string, any>;
|
|
57
|
+
}
|
|
58
|
+
export interface PoolClosedEventData {
|
|
59
|
+
pool: Record<string, any>;
|
|
60
|
+
subPool?: Record<string, any>;
|
|
61
|
+
}
|
|
62
|
+
export interface PoolEventData {
|
|
63
|
+
pool: Record<string, any>;
|
|
64
|
+
subMarkets?: Record<string, any>[];
|
|
65
|
+
}
|
|
66
|
+
export interface WinnerEventData {
|
|
67
|
+
pool: Record<string, any>;
|
|
68
|
+
subPool: Record<string, any>;
|
|
69
|
+
}
|
|
70
|
+
export interface DisputeOpenedEventData {
|
|
71
|
+
subPool: Record<string, any>;
|
|
72
|
+
eventType: string;
|
|
73
|
+
}
|
|
74
|
+
export interface OracleCreatedEventData {
|
|
75
|
+
pool: Record<string, any>;
|
|
76
|
+
subPool: Record<string, any>;
|
|
77
|
+
}
|
|
78
|
+
export interface AppealOpenedEventData {
|
|
79
|
+
pool: Record<string, any>;
|
|
80
|
+
subPool: Record<string, any>;
|
|
81
|
+
}
|
|
82
|
+
export interface DisputeWinnerEventData {
|
|
83
|
+
subPool: Record<string, any>;
|
|
84
|
+
eventType: string;
|
|
85
|
+
}
|
|
86
|
+
export interface AppealWinnerEventData {
|
|
87
|
+
subPool: Record<string, any>;
|
|
88
|
+
eventType: string;
|
|
89
|
+
winnerFinalized: boolean;
|
|
90
|
+
}
|
|
91
|
+
export interface ClaimRewardEventData {
|
|
92
|
+
claimReward: Record<string, any>;
|
|
93
|
+
pool: Record<string, any>;
|
|
94
|
+
subPool: Record<string, any>;
|
|
95
|
+
}
|
|
96
|
+
export interface DisputeRefundEventData {
|
|
97
|
+
claimReward: Record<string, any>;
|
|
98
|
+
pool: Record<string, any>;
|
|
99
|
+
subPool: Record<string, any>;
|
|
100
|
+
}
|
|
101
|
+
export declare class RainSocket {
|
|
102
|
+
private socket;
|
|
103
|
+
private url;
|
|
104
|
+
private listeners;
|
|
105
|
+
constructor(url: string);
|
|
106
|
+
/**
|
|
107
|
+
* Connect to the Socket.IO server
|
|
108
|
+
*/
|
|
109
|
+
connect(): void;
|
|
110
|
+
/**
|
|
111
|
+
* Disconnect from the server
|
|
112
|
+
*/
|
|
113
|
+
disconnect(): void;
|
|
114
|
+
/**
|
|
115
|
+
* Check if connected
|
|
116
|
+
*/
|
|
117
|
+
get isConnected(): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Subscribe to an event for a specific pool
|
|
120
|
+
* @returns unsubscribe function
|
|
121
|
+
*/
|
|
122
|
+
on(event: RainSocketEvent, poolId: string, callback: (data: any) => void): () => void;
|
|
123
|
+
/**
|
|
124
|
+
* Subscribe to a global event (no poolId)
|
|
125
|
+
* @returns unsubscribe function
|
|
126
|
+
*/
|
|
127
|
+
onGlobal(event: 'pool', callback: (data: PoolEventData) => void): () => void;
|
|
128
|
+
/**
|
|
129
|
+
* Subscribe to a raw channel name
|
|
130
|
+
* @returns unsubscribe function
|
|
131
|
+
*/
|
|
132
|
+
onChannel(channel: string, callback: (data: any) => void): () => void;
|
|
133
|
+
onEnterOption(poolId: string, callback: (data: EnterOptionEventData) => void): () => void;
|
|
134
|
+
onExitOption(poolId: string, callback: (data: ExitOptionEventData) => void): () => void;
|
|
135
|
+
onLiquidity(poolId: string, callback: (data: LiquidityEventData) => void): () => void;
|
|
136
|
+
onSplit(poolId: string, callback: (data: SplitEventData) => void): () => void;
|
|
137
|
+
onMerge(poolId: string, callback: (data: MergeEventData) => void): () => void;
|
|
138
|
+
onRemoveLiquidity(poolId: string, callback: (data: RemoveLiquidityEventData) => void): () => void;
|
|
139
|
+
onSyncPrice(poolId: string, callback: (data: SyncPriceEventData) => void): () => void;
|
|
140
|
+
onOrderCreated(poolId: string, callback: (data: OrderCreatedEventData) => void): () => void;
|
|
141
|
+
onOrderCancelled(poolId: string, callback: (data: OrderCancelledEventData) => void): () => void;
|
|
142
|
+
onOrderFilled(poolId: string, callback: (data: OrderFilledEventData) => void): () => void;
|
|
143
|
+
onPoolClosed(poolId: string, callback: (data: PoolClosedEventData) => void): () => void;
|
|
144
|
+
onPoolReverted(poolId: string, callback: (data: any) => void): () => void;
|
|
145
|
+
onPoolTokenSet(poolId: string, callback: (data: any) => void): () => void;
|
|
146
|
+
onStreamingStatusChanged(poolId: string, callback: (data: any) => void): () => void;
|
|
147
|
+
onNewPool(callback: (data: PoolEventData) => void): () => void;
|
|
148
|
+
onWinner(poolId: string, callback: (data: WinnerEventData) => void): () => void;
|
|
149
|
+
onWinnerProposer(poolId: string, callback: (data: WinnerEventData) => void): () => void;
|
|
150
|
+
onRevealWinnerAvailable(poolId: string, callback: (data: {
|
|
151
|
+
subPoolId: string;
|
|
152
|
+
}) => void): () => void;
|
|
153
|
+
onDisputeOpened(poolId: string, callback: (data: DisputeOpenedEventData) => void): () => void;
|
|
154
|
+
onOracleCreated(poolId: string, callback: (data: OracleCreatedEventData) => void): () => void;
|
|
155
|
+
onDisputeTimeExtended(poolId: string, callback: (data: {
|
|
156
|
+
pool: Record<string, any>;
|
|
157
|
+
subPool: Record<string, any>;
|
|
158
|
+
}) => void): () => void;
|
|
159
|
+
onAppealOpened(poolId: string, callback: (data: AppealOpenedEventData) => void): () => void;
|
|
160
|
+
onAppealWinnerCalculated(poolId: string, callback: (data: {
|
|
161
|
+
subPool: Record<string, any>;
|
|
162
|
+
}) => void): () => void;
|
|
163
|
+
onDisputeWinner(poolId: string, callback: (data: DisputeWinnerEventData) => void): () => void;
|
|
164
|
+
onAppealWinner(poolId: string, callback: (data: AppealWinnerEventData) => void): () => void;
|
|
165
|
+
onClaimReward(poolId: string, callback: (data: ClaimRewardEventData) => void): () => void;
|
|
166
|
+
/**
|
|
167
|
+
* User-scoped claim reward event: claim-reward/{poolId}/{userId}
|
|
168
|
+
*/
|
|
169
|
+
onUserClaimReward(poolId: string, userId: string, callback: (data: ClaimRewardEventData) => void): () => void;
|
|
170
|
+
onDisputeRefund(poolId: string, userId: string, callback: (data: DisputeRefundEventData) => void): () => void;
|
|
171
|
+
onAppealRefund(poolId: string, userId: string, callback: (data: DisputeRefundEventData) => void): () => void;
|
|
172
|
+
onResolutionRefund(poolId: string, userId: string, callback: (data: ClaimRewardEventData) => void): () => void;
|
|
173
|
+
onResolverReward(poolId: string, userId: string, callback: (data: ClaimRewardEventData) => void): () => void;
|
|
174
|
+
onNotifications(userId: string, callback: (data: any) => void): () => void;
|
|
175
|
+
}
|