@rainprotocolsdk/sdk 2.1.2 → 2.3.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 +633 -613
- package/dist/Rain.d.ts +2 -1
- package/dist/Rain.js +8 -0
- package/dist/config/environments.d.ts +6 -0
- package/dist/config/environments.js +6 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/socket/RainSocket.d.ts +59 -0
- package/dist/socket/RainSocket.js +193 -0
- package/dist/socket/types.d.ts +65 -0
- package/dist/socket/types.js +1 -0
- package/dist/tx/AddLiquidity/buildAddLiquidityRawTx.d.ts +8 -0
- package/dist/tx/AddLiquidity/buildAddLiquidityRawTx.js +51 -0
- package/dist/tx/types.d.ts +6 -0
- package/package.json +13 -6
package/dist/Rain.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GetMarketByIdParams, GetMarketsParams, GetUserInvestmentsParams, Market, UserInvestment } from './markets/types.js';
|
|
2
|
-
import { ApproveTxParams, CancelAllOpenOrdersTxParams, CancelOrdersTxParams, ClaimTxParams, CloseMarketTxParams, CreateDisputeTxParams, CreateAppealTxParams, CreateMarketTxParams, EnterLimitOptionTxParams, EnterOptionTxParams, ExtendTimeTxParams, LimitSellOptionTxParams, RawTransaction } from './tx/types.js';
|
|
2
|
+
import { AddLiquidityTxParams, ApproveTxParams, CancelAllOpenOrdersTxParams, CancelOrdersTxParams, ClaimTxParams, CloseMarketTxParams, CreateDisputeTxParams, CreateAppealTxParams, CreateMarketTxParams, EnterLimitOptionTxParams, EnterOptionTxParams, ExtendTimeTxParams, LimitSellOptionTxParams, RawTransaction } from './tx/types.js';
|
|
3
3
|
import { RainCoreConfig, RainEnvironment } from './types.js';
|
|
4
4
|
import { LoginParams, LoginResult } from './auth/types.js';
|
|
5
5
|
export declare class Rain {
|
|
@@ -25,5 +25,6 @@ export declare class Rain {
|
|
|
25
25
|
buildCreateDisputeTx(params: CreateDisputeTxParams): Promise<RawTransaction[]>;
|
|
26
26
|
buildCreateAppealTx(params: CreateAppealTxParams): Promise<RawTransaction[]>;
|
|
27
27
|
buildExtendTimeTx(params: ExtendTimeTxParams): Promise<RawTransaction>;
|
|
28
|
+
buildAddLiquidityTx(params: AddLiquidityTxParams): Promise<RawTransaction[]>;
|
|
28
29
|
login(params: LoginParams): Promise<LoginResult>;
|
|
29
30
|
}
|
package/dist/Rain.js
CHANGED
|
@@ -11,6 +11,7 @@ import { buildCreateMarketRawTx } from './tx/CreateMarket/buildCreateMarketRawTx
|
|
|
11
11
|
import { ALLOWED_ENVIRONMENTS, ENV_CONFIG, getRandomRpc } from './config/environments.js';
|
|
12
12
|
import { buildClaimRawTx } from './tx/ClaimFunds/buildClaimFundsRawTx.js';
|
|
13
13
|
import { buildExtendTimeRawTx } from './tx/ExtendTime/buildExtendTimeRawTx.js';
|
|
14
|
+
import { buildAddLiquidityRawTx } from './tx/AddLiquidity/buildAddLiquidityRawTx.js';
|
|
14
15
|
import { loginUser } from './auth/login.js';
|
|
15
16
|
export class Rain {
|
|
16
17
|
environment;
|
|
@@ -80,6 +81,13 @@ export class Rain {
|
|
|
80
81
|
async buildExtendTimeTx(params) {
|
|
81
82
|
return buildExtendTimeRawTx({ ...params, apiUrl: this.apiUrl, rpcUrl: this.rpcUrl });
|
|
82
83
|
}
|
|
84
|
+
async buildAddLiquidityTx(params) {
|
|
85
|
+
return buildAddLiquidityRawTx({
|
|
86
|
+
...params,
|
|
87
|
+
environment: this.environment,
|
|
88
|
+
rpcUrl: params.rpcUrl ?? this.rpcUrl,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
83
91
|
async login(params) {
|
|
84
92
|
return loginUser({ ...params, apiUrl: this.apiUrl });
|
|
85
93
|
}
|
|
@@ -9,17 +9,23 @@ export declare const ENV_CONFIG: {
|
|
|
9
9
|
readonly market_factory_address: "0x148DA7F2039B2B00633AC2ab566f59C8a4C86313";
|
|
10
10
|
readonly dispute_initial_timer: number;
|
|
11
11
|
readonly usdt_symbol: "USDTm";
|
|
12
|
+
readonly usdt_token: `0x${string}`;
|
|
13
|
+
readonly rain_token: `0x${string}`;
|
|
12
14
|
};
|
|
13
15
|
readonly stage: {
|
|
14
16
|
readonly apiUrl: "https://stg-api.rain.one";
|
|
15
17
|
readonly market_factory_address: "0x6109c9f28FE3Ad84c51368f7Ef2d487ca020c561";
|
|
16
18
|
readonly dispute_initial_timer: number;
|
|
17
19
|
readonly usdt_symbol: "USD₮0";
|
|
20
|
+
readonly usdt_token: `0x${string}`;
|
|
21
|
+
readonly rain_token: `0x${string}`;
|
|
18
22
|
};
|
|
19
23
|
readonly production: {
|
|
20
24
|
readonly apiUrl: "https://prod-api.rain.one";
|
|
21
25
|
readonly market_factory_address: "0xccCB3C03D9355B01883779EF15C1Be09cf3623F1";
|
|
22
26
|
readonly dispute_initial_timer: number;
|
|
23
27
|
readonly usdt_symbol: "USD₮0";
|
|
28
|
+
readonly usdt_token: `0x${string}`;
|
|
29
|
+
readonly rain_token: `0x${string}`;
|
|
24
30
|
};
|
|
25
31
|
};
|
|
@@ -16,17 +16,23 @@ export const ENV_CONFIG = {
|
|
|
16
16
|
market_factory_address: "0x148DA7F2039B2B00633AC2ab566f59C8a4C86313",
|
|
17
17
|
dispute_initial_timer: 1 * 60,
|
|
18
18
|
usdt_symbol: USDT_SYMBOL_DEV,
|
|
19
|
+
usdt_token: "0xCa4f77A38d8552Dd1D5E44e890173921B67725F4",
|
|
20
|
+
rain_token: "0x25118290e6A5f4139381D072181157035864099d",
|
|
19
21
|
},
|
|
20
22
|
stage: {
|
|
21
23
|
apiUrl: "https://stg-api.rain.one",
|
|
22
24
|
market_factory_address: "0x6109c9f28FE3Ad84c51368f7Ef2d487ca020c561",
|
|
23
25
|
dispute_initial_timer: 1 * 60,
|
|
24
26
|
usdt_symbol: USDT_SYMBOL_PROD,
|
|
27
|
+
usdt_token: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
|
|
28
|
+
rain_token: "0x43976a124e6834b541840Ce741243dAD3dd538DA",
|
|
25
29
|
},
|
|
26
30
|
production: {
|
|
27
31
|
apiUrl: "https://prod-api.rain.one",
|
|
28
32
|
market_factory_address: "0xccCB3C03D9355B01883779EF15C1Be09cf3623F1",
|
|
29
33
|
dispute_initial_timer: 120 * 60,
|
|
30
34
|
usdt_symbol: USDT_SYMBOL_PROD,
|
|
35
|
+
usdt_token: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
|
|
36
|
+
rain_token: "0x43976a124e6834b541840Ce741243dAD3dd538DA",
|
|
31
37
|
},
|
|
32
38
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { Rain } from './Rain.js';
|
|
2
2
|
export { RainAA } from './RainAA.js';
|
|
3
|
+
export { RainSocket } from './socket/RainSocket.js';
|
|
3
4
|
export * from './types.js';
|
|
4
5
|
export type { LoginParams, LoginResult } from './auth/types.js';
|
|
6
|
+
export type { EnterOptionEventData, OrderEventData, OrderFilledEventData, DisputeOpenedEventData, AppealOpenedEventData, DisputeTimeExtendedEventData, DisputeWinnerEventData, AppealWinnerEventData, ClaimRewardEventData } from './socket/types.js';
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { RainCoreConfig } from '../types.js';
|
|
2
|
+
import { EnterOptionEventData, OrderEventData, OrderFilledEventData, DisputeOpenedEventData, AppealOpenedEventData, DisputeTimeExtendedEventData, DisputeWinnerEventData, AppealWinnerEventData, ClaimRewardEventData } from './types.js';
|
|
3
|
+
export declare class RainSocket {
|
|
4
|
+
private socket;
|
|
5
|
+
constructor(config?: RainCoreConfig);
|
|
6
|
+
get connected(): boolean;
|
|
7
|
+
onConnect(callback: () => void): void;
|
|
8
|
+
onDisconnect(callback: () => void): void;
|
|
9
|
+
/**
|
|
10
|
+
* Subscribe to the enter-option event for a specific market.
|
|
11
|
+
* Fires when a user buys into a market option.
|
|
12
|
+
* Returns an unsubscribe function — call it to stop listening.
|
|
13
|
+
*/
|
|
14
|
+
onEnterOption(marketId: string, callback: (data: EnterOptionEventData) => void): () => void;
|
|
15
|
+
/**
|
|
16
|
+
* Subscribe to the order-created event for a specific market.
|
|
17
|
+
* Fires when a new limit order is placed.
|
|
18
|
+
*/
|
|
19
|
+
onOrderCreated(marketId: string, callback: (data: OrderEventData) => void): () => void;
|
|
20
|
+
/**
|
|
21
|
+
* Subscribe to the order-cancelled event for a specific market.
|
|
22
|
+
* Fires when an open order is cancelled.
|
|
23
|
+
*/
|
|
24
|
+
onOrderCancelled(marketId: string, callback: (data: OrderEventData) => void): () => void;
|
|
25
|
+
/**
|
|
26
|
+
* Subscribe to the order-filled event for a specific market.
|
|
27
|
+
* Fires when an order is partially or fully filled.
|
|
28
|
+
*/
|
|
29
|
+
onOrderFilled(marketId: string, callback: (data: OrderFilledEventData) => void): () => void;
|
|
30
|
+
/**
|
|
31
|
+
* Subscribe to the dispute-opened event for a specific market.
|
|
32
|
+
*/
|
|
33
|
+
onDisputeOpened(marketId: string, callback: (data: DisputeOpenedEventData) => void): () => void;
|
|
34
|
+
/**
|
|
35
|
+
* Subscribe to the appeal-opened event for a specific market.
|
|
36
|
+
*/
|
|
37
|
+
onAppealOpened(marketId: string, callback: (data: AppealOpenedEventData) => void): () => void;
|
|
38
|
+
/**
|
|
39
|
+
* Subscribe to the dispute-time-extented event for a specific market.
|
|
40
|
+
* Note: event name matches the backend spelling ("extented").
|
|
41
|
+
*/
|
|
42
|
+
onDisputeTimeExtended(marketId: string, callback: (data: DisputeTimeExtendedEventData) => void): () => void;
|
|
43
|
+
/**
|
|
44
|
+
* Subscribe to the dispute-winner event for a specific market.
|
|
45
|
+
* Fires when a dispute winner is decided.
|
|
46
|
+
*/
|
|
47
|
+
onDisputeWinner(marketId: string, callback: (data: DisputeWinnerEventData) => void): () => void;
|
|
48
|
+
/**
|
|
49
|
+
* Subscribe to the appeal-winner event for a specific market.
|
|
50
|
+
* Fires when an appeal winner is finalized.
|
|
51
|
+
*/
|
|
52
|
+
onAppealWinner(marketId: string, callback: (data: AppealWinnerEventData) => void): () => void;
|
|
53
|
+
/**
|
|
54
|
+
* Subscribe to the claim-reward event for a specific market and user.
|
|
55
|
+
* Fires when a user's reward claim is confirmed.
|
|
56
|
+
*/
|
|
57
|
+
onClaimReward(marketId: string, userId: string, callback: (data: ClaimRewardEventData) => void): () => void;
|
|
58
|
+
disconnect(): void;
|
|
59
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { io } from 'socket.io-client';
|
|
2
|
+
import { ALLOWED_ENVIRONMENTS, ENV_CONFIG } from '../config/environments.js';
|
|
3
|
+
export class RainSocket {
|
|
4
|
+
socket;
|
|
5
|
+
constructor(config = {}) {
|
|
6
|
+
const { environment = 'development' } = config;
|
|
7
|
+
function isValidEnvironment(env) {
|
|
8
|
+
return ALLOWED_ENVIRONMENTS.includes(env);
|
|
9
|
+
}
|
|
10
|
+
if (!isValidEnvironment(environment)) {
|
|
11
|
+
throw new Error(`Invalid environment "${environment}". Allowed values: ${ALLOWED_ENVIRONMENTS.join(', ')}`);
|
|
12
|
+
}
|
|
13
|
+
const { apiUrl } = ENV_CONFIG[environment];
|
|
14
|
+
this.socket = io(apiUrl, { transports: ['websocket', 'polling'] });
|
|
15
|
+
}
|
|
16
|
+
get connected() {
|
|
17
|
+
return this.socket.connected;
|
|
18
|
+
}
|
|
19
|
+
onConnect(callback) {
|
|
20
|
+
this.socket.on('connect', callback);
|
|
21
|
+
}
|
|
22
|
+
onDisconnect(callback) {
|
|
23
|
+
this.socket.on('disconnect', callback);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Subscribe to the enter-option event for a specific market.
|
|
27
|
+
* Fires when a user buys into a market option.
|
|
28
|
+
* Returns an unsubscribe function — call it to stop listening.
|
|
29
|
+
*/
|
|
30
|
+
onEnterOption(marketId, callback) {
|
|
31
|
+
const event = `enter-option/${marketId}`;
|
|
32
|
+
const handler = (raw) => {
|
|
33
|
+
const investments = (raw?.enterOption?.investment ?? []).map((inv) => ({
|
|
34
|
+
choiceIndex: inv?.choiceIndex ?? inv?.option ?? 0,
|
|
35
|
+
amount: String(inv?.amount ?? inv?.investment ?? '0'),
|
|
36
|
+
optionName: inv?.optionName,
|
|
37
|
+
}));
|
|
38
|
+
callback({
|
|
39
|
+
poolId: raw?.pool?._id ?? marketId,
|
|
40
|
+
investments,
|
|
41
|
+
totalInvestmentWei: String(raw?.enterOption?.totalInvestment ?? '0'),
|
|
42
|
+
tokenDecimals: raw?.pool?.token?.tokenDecimals ?? 6,
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
this.socket.on(event, handler);
|
|
46
|
+
return () => this.socket.off(event, handler);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Subscribe to the order-created event for a specific market.
|
|
50
|
+
* Fires when a new limit order is placed.
|
|
51
|
+
*/
|
|
52
|
+
onOrderCreated(marketId, callback) {
|
|
53
|
+
const event = `order-created/${marketId}`;
|
|
54
|
+
const handler = (raw) => {
|
|
55
|
+
callback({
|
|
56
|
+
poolId: raw?.pool?._id ?? marketId,
|
|
57
|
+
order: raw?.order ?? {},
|
|
58
|
+
tokenDecimals: raw?.pool?.token?.tokenDecimals ?? 6,
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
this.socket.on(event, handler);
|
|
62
|
+
return () => this.socket.off(event, handler);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Subscribe to the order-cancelled event for a specific market.
|
|
66
|
+
* Fires when an open order is cancelled.
|
|
67
|
+
*/
|
|
68
|
+
onOrderCancelled(marketId, callback) {
|
|
69
|
+
const event = `order-cancelled/${marketId}`;
|
|
70
|
+
const handler = (raw) => {
|
|
71
|
+
callback({
|
|
72
|
+
poolId: raw?.pool?._id ?? marketId,
|
|
73
|
+
order: raw?.order ?? {},
|
|
74
|
+
tokenDecimals: raw?.pool?.token?.tokenDecimals ?? 6,
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
this.socket.on(event, handler);
|
|
78
|
+
return () => this.socket.off(event, handler);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Subscribe to the order-filled event for a specific market.
|
|
82
|
+
* Fires when an order is partially or fully filled.
|
|
83
|
+
*/
|
|
84
|
+
onOrderFilled(marketId, callback) {
|
|
85
|
+
const event = `order-filled/${marketId}`;
|
|
86
|
+
const handler = (raw) => {
|
|
87
|
+
callback({ poolId: raw?.pool?._id ?? marketId, raw });
|
|
88
|
+
};
|
|
89
|
+
this.socket.on(event, handler);
|
|
90
|
+
return () => this.socket.off(event, handler);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Subscribe to the dispute-opened event for a specific market.
|
|
94
|
+
*/
|
|
95
|
+
onDisputeOpened(marketId, callback) {
|
|
96
|
+
const event = `dispute-opened/${marketId}`;
|
|
97
|
+
const handler = (raw) => {
|
|
98
|
+
callback({
|
|
99
|
+
poolId: raw?.pool?._id ?? marketId,
|
|
100
|
+
isDisputed: raw?.pool?.isDisputed ?? false,
|
|
101
|
+
isAiResolver: raw?.pool?.isAiResolver ?? false,
|
|
102
|
+
status: raw?.pool?.status ?? '',
|
|
103
|
+
disputeData: raw?.pool?.disputeData ?? null,
|
|
104
|
+
winnerDecidedBy: raw?.pool?.winnerOption?.decidedBy ?? '',
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
this.socket.on(event, handler);
|
|
108
|
+
return () => this.socket.off(event, handler);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Subscribe to the appeal-opened event for a specific market.
|
|
112
|
+
*/
|
|
113
|
+
onAppealOpened(marketId, callback) {
|
|
114
|
+
const event = `appeal-opened/${marketId}`;
|
|
115
|
+
const handler = (raw) => {
|
|
116
|
+
callback({
|
|
117
|
+
poolId: raw?.pool?._id ?? marketId,
|
|
118
|
+
eventType: raw?.eventType ?? '',
|
|
119
|
+
isAppealed: raw?.pool?.isAppealed ?? false,
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
this.socket.on(event, handler);
|
|
123
|
+
return () => this.socket.off(event, handler);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Subscribe to the dispute-time-extented event for a specific market.
|
|
127
|
+
* Note: event name matches the backend spelling ("extented").
|
|
128
|
+
*/
|
|
129
|
+
onDisputeTimeExtended(marketId, callback) {
|
|
130
|
+
const event = `dispute-time-extented/${marketId}`;
|
|
131
|
+
const handler = (raw) => {
|
|
132
|
+
callback({
|
|
133
|
+
poolId: raw?.pool?._id ?? marketId,
|
|
134
|
+
eventType: raw?.eventType ?? '',
|
|
135
|
+
newEndTime: raw?.newEndTime ?? '',
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
this.socket.on(event, handler);
|
|
139
|
+
return () => this.socket.off(event, handler);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Subscribe to the dispute-winner event for a specific market.
|
|
143
|
+
* Fires when a dispute winner is decided.
|
|
144
|
+
*/
|
|
145
|
+
onDisputeWinner(marketId, callback) {
|
|
146
|
+
const event = `dispute-winner/${marketId}`;
|
|
147
|
+
const handler = (raw) => {
|
|
148
|
+
callback({
|
|
149
|
+
poolId: raw?.pool?._id ?? marketId,
|
|
150
|
+
status: raw?.pool?.status ?? '',
|
|
151
|
+
winnerOption: {
|
|
152
|
+
decidedBy: raw?.pool?.winnerOption?.decidedBy ?? '',
|
|
153
|
+
choiceIndex: raw?.pool?.winnerOption?.choiceIndex ?? 0,
|
|
154
|
+
createdAt: raw?.pool?.winnerOption?.createdAt ?? '',
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
this.socket.on(event, handler);
|
|
159
|
+
return () => this.socket.off(event, handler);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Subscribe to the appeal-winner event for a specific market.
|
|
163
|
+
* Fires when an appeal winner is finalized.
|
|
164
|
+
*/
|
|
165
|
+
onAppealWinner(marketId, callback) {
|
|
166
|
+
const event = `appeal-winner/${marketId}`;
|
|
167
|
+
const handler = (raw) => {
|
|
168
|
+
callback({
|
|
169
|
+
poolId: raw?.pool?._id ?? marketId,
|
|
170
|
+
eventType: raw?.eventType ?? '',
|
|
171
|
+
winnerFinalized: raw?.winnerFinalized ?? null,
|
|
172
|
+
winnerOption: raw?.pool?.winnerOption ?? null,
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
this.socket.on(event, handler);
|
|
176
|
+
return () => this.socket.off(event, handler);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Subscribe to the claim-reward event for a specific market and user.
|
|
180
|
+
* Fires when a user's reward claim is confirmed.
|
|
181
|
+
*/
|
|
182
|
+
onClaimReward(marketId, userId, callback) {
|
|
183
|
+
const event = `claim-reward/${marketId}/${userId}`;
|
|
184
|
+
const handler = (_raw) => {
|
|
185
|
+
callback({ poolId: marketId, userId });
|
|
186
|
+
};
|
|
187
|
+
this.socket.on(event, handler);
|
|
188
|
+
return () => this.socket.off(event, handler);
|
|
189
|
+
}
|
|
190
|
+
disconnect() {
|
|
191
|
+
this.socket.disconnect();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export interface EnterOptionEventData {
|
|
2
|
+
poolId: string;
|
|
3
|
+
investments: {
|
|
4
|
+
choiceIndex: number;
|
|
5
|
+
amount: string;
|
|
6
|
+
optionName?: string;
|
|
7
|
+
}[];
|
|
8
|
+
totalInvestmentWei: string;
|
|
9
|
+
tokenDecimals: number;
|
|
10
|
+
}
|
|
11
|
+
export interface OrderEventData {
|
|
12
|
+
poolId: string;
|
|
13
|
+
order: {
|
|
14
|
+
_id: string;
|
|
15
|
+
orderType: 'buy' | 'sell';
|
|
16
|
+
option: number;
|
|
17
|
+
optionName?: string;
|
|
18
|
+
pricePerShare: string;
|
|
19
|
+
quantity: string;
|
|
20
|
+
createdAt: string;
|
|
21
|
+
[key: string]: any;
|
|
22
|
+
};
|
|
23
|
+
tokenDecimals: number;
|
|
24
|
+
}
|
|
25
|
+
export interface OrderFilledEventData {
|
|
26
|
+
poolId: string;
|
|
27
|
+
raw: any;
|
|
28
|
+
}
|
|
29
|
+
export interface DisputeOpenedEventData {
|
|
30
|
+
poolId: string;
|
|
31
|
+
isDisputed: boolean;
|
|
32
|
+
isAiResolver: boolean;
|
|
33
|
+
status: string;
|
|
34
|
+
disputeData: any;
|
|
35
|
+
winnerDecidedBy: string;
|
|
36
|
+
}
|
|
37
|
+
export interface AppealOpenedEventData {
|
|
38
|
+
poolId: string;
|
|
39
|
+
eventType: string;
|
|
40
|
+
isAppealed: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface DisputeTimeExtendedEventData {
|
|
43
|
+
poolId: string;
|
|
44
|
+
eventType: string;
|
|
45
|
+
newEndTime: string | number;
|
|
46
|
+
}
|
|
47
|
+
export interface DisputeWinnerEventData {
|
|
48
|
+
poolId: string;
|
|
49
|
+
status: string;
|
|
50
|
+
winnerOption: {
|
|
51
|
+
decidedBy: string;
|
|
52
|
+
choiceIndex: number;
|
|
53
|
+
createdAt: string;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export interface AppealWinnerEventData {
|
|
57
|
+
poolId: string;
|
|
58
|
+
eventType: string;
|
|
59
|
+
winnerFinalized: any;
|
|
60
|
+
winnerOption: any;
|
|
61
|
+
}
|
|
62
|
+
export interface ClaimRewardEventData {
|
|
63
|
+
poolId: string;
|
|
64
|
+
userId: string;
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AddLiquidityTxParams, RawTransaction } from "../types.js";
|
|
2
|
+
import { RainEnvironment } from "../../types.js";
|
|
3
|
+
interface AddLiquidityRawTxInternalParams extends AddLiquidityTxParams {
|
|
4
|
+
environment: RainEnvironment;
|
|
5
|
+
rpcUrl: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function buildAddLiquidityRawTx(params: AddLiquidityRawTxInternalParams): Promise<RawTransaction[]>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { encodeFunctionData } from "viem";
|
|
2
|
+
import { Contract, JsonRpcProvider, ethers } from "ethers";
|
|
3
|
+
import { TradePoolAbi } from "../../abi/TradeMarketsAbi.js";
|
|
4
|
+
import { buildApproveRawTx } from "../buildApprovalRawTx.js";
|
|
5
|
+
import { getTokenAllowance } from "../CloseMarket/helpers.js";
|
|
6
|
+
import { isRpcValid } from "../ClaimFunds/helpers.js";
|
|
7
|
+
import { ENV_CONFIG, ALLOWED_ENVIRONMENTS } from "../../config/environments.js";
|
|
8
|
+
async function getMarketBaseToken(marketContractAddress, rpcUrl) {
|
|
9
|
+
const provider = new JsonRpcProvider(rpcUrl);
|
|
10
|
+
const contract = new Contract(marketContractAddress, TradePoolAbi, provider);
|
|
11
|
+
return (await contract.baseToken()).toLowerCase();
|
|
12
|
+
}
|
|
13
|
+
export async function buildAddLiquidityRawTx(params) {
|
|
14
|
+
const { marketContractAddress, walletAddress, amount, environment, rpcUrl } = params;
|
|
15
|
+
if (!marketContractAddress)
|
|
16
|
+
throw new Error("marketContractAddress is required");
|
|
17
|
+
if (!walletAddress)
|
|
18
|
+
throw new Error("walletAddress is required");
|
|
19
|
+
if (!amount)
|
|
20
|
+
throw new Error("amount is required");
|
|
21
|
+
if (!ALLOWED_ENVIRONMENTS.includes(environment))
|
|
22
|
+
throw new Error(`Invalid environment: ${environment}`);
|
|
23
|
+
const isRpcWorking = await isRpcValid(rpcUrl);
|
|
24
|
+
if (!isRpcWorking)
|
|
25
|
+
throw new Error("Provided RPC URL is not valid or not working");
|
|
26
|
+
const { usdt_token, rain_token } = ENV_CONFIG[environment];
|
|
27
|
+
// Read base token from the market contract
|
|
28
|
+
const baseToken = await getMarketBaseToken(marketContractAddress, rpcUrl);
|
|
29
|
+
const isUsdtMarket = baseToken === usdt_token.toLowerCase();
|
|
30
|
+
const tokenAddress = isUsdtMarket ? usdt_token : rain_token;
|
|
31
|
+
// USDT uses 6 decimals, RAIN uses 18
|
|
32
|
+
const decimals = isUsdtMarket ? 6 : 18;
|
|
33
|
+
const amountInWei = ethers.parseUnits(amount.toString(), decimals);
|
|
34
|
+
const txs = [];
|
|
35
|
+
// Check allowance for the correct token only
|
|
36
|
+
const allowance = await getTokenAllowance(tokenAddress, walletAddress, marketContractAddress, rpcUrl);
|
|
37
|
+
if (BigInt(allowance) < amountInWei) {
|
|
38
|
+
txs.push(buildApproveRawTx({ tokenAddress, spender: marketContractAddress }));
|
|
39
|
+
}
|
|
40
|
+
// enterLiquidity tx on the market contract
|
|
41
|
+
txs.push({
|
|
42
|
+
to: marketContractAddress,
|
|
43
|
+
data: encodeFunctionData({
|
|
44
|
+
abi: TradePoolAbi,
|
|
45
|
+
functionName: "enterLiquidity",
|
|
46
|
+
args: [amountInWei],
|
|
47
|
+
}),
|
|
48
|
+
value: 0n,
|
|
49
|
+
});
|
|
50
|
+
return txs;
|
|
51
|
+
}
|
package/dist/tx/types.d.ts
CHANGED
|
@@ -99,6 +99,12 @@ export interface CancelAllOpenOrdersTxParams {
|
|
|
99
99
|
accessToken: string;
|
|
100
100
|
apiUrl?: string;
|
|
101
101
|
}
|
|
102
|
+
export interface AddLiquidityTxParams {
|
|
103
|
+
marketContractAddress: `0x${string}`;
|
|
104
|
+
walletAddress: `0x${string}`;
|
|
105
|
+
amount: string | number;
|
|
106
|
+
rpcUrl?: string;
|
|
107
|
+
}
|
|
102
108
|
export interface ExtendTimeTxParams {
|
|
103
109
|
marketContractAddress: `0x${string}`;
|
|
104
110
|
walletAddress: `0x${string}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rainprotocolsdk/sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Rain SDK",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -31,14 +31,21 @@
|
|
|
31
31
|
"author": "Rain Protocol",
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"viem": "^2.0.0"
|
|
35
|
-
},
|
|
36
|
-
"dependencies": {
|
|
34
|
+
"viem": "^2.0.0",
|
|
37
35
|
"@account-kit/infra": "^4.48.0",
|
|
38
36
|
"@account-kit/wallet-client": "^0.1.0-alpha.10",
|
|
39
37
|
"@alchemy/aa-alchemy": "^3.0.0",
|
|
40
|
-
"@alchemy/aa-core": "^3.0.0"
|
|
41
|
-
|
|
38
|
+
"@alchemy/aa-core": "^3.0.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependenciesMeta": {
|
|
41
|
+
"@account-kit/infra": { "optional": true },
|
|
42
|
+
"@account-kit/wallet-client": { "optional": true },
|
|
43
|
+
"@alchemy/aa-alchemy": { "optional": true },
|
|
44
|
+
"@alchemy/aa-core": { "optional": true }
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"ethers": "^6.16.0",
|
|
48
|
+
"socket.io-client": "^4.8.3"
|
|
42
49
|
},
|
|
43
50
|
"devDependencies": {
|
|
44
51
|
"typescript": "^5.9.3"
|