riskmarket-sdk 1.0.21 → 1.0.22
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.
Potentially problematic release.
This version of riskmarket-sdk might be problematic. Click here for more details.
- package/README.md +79 -77
- package/dist/Game.d.ts +49 -1
- package/dist/Game.js +28 -5
- package/dist/Games/read/getMaxBet.d.ts +1 -1
- package/dist/Games/read/getMaxBet.js +3 -4
- package/dist/Games/read/getMinBet.d.ts +1 -1
- package/dist/Games/read/getMinBet.js +2 -2
- package/dist/Games/read/getPositionData.d.ts +1 -0
- package/dist/Games/read/getPositionData.js +23 -0
- package/dist/Games/read/getPositionProgress.d.ts +1 -0
- package/dist/Games/read/getPositionProgress.js +25 -0
- package/dist/Games/read/getTotalLiquidity.d.ts +1 -1
- package/dist/Games/read/getTotalLiquidity.js +2 -3
- package/dist/Games/write/cashout.js +6 -5
- package/dist/Games/write/placeBet.js +10 -10
- package/dist/Liquidity/read/UserPrviewUnreserve.js +6 -4
- package/dist/Liquidity/read/currentLiquidityYouProvide.js +6 -4
- package/dist/Liquidity/read/estimateCloseGasFee.d.ts +1 -0
- package/dist/Liquidity/read/estimateCloseGasFee.js +67 -0
- package/dist/Liquidity/read/estimateCrashGasFee.d.ts +1 -1
- package/dist/Liquidity/read/estimateCrashGasFee.js +9 -8
- package/dist/Liquidity/read/getCrashGameIndex.js +1 -1
- package/dist/Liquidity/read/getCrashPlatformFee.d.ts +1 -1
- package/dist/Liquidity/read/getCrashPlatformFee.js +6 -3
- package/dist/Liquidity/read/getGameRoundByIndex.js +4 -4
- package/dist/Liquidity/read/getMarketIndexTermination.d.ts +1 -0
- package/dist/Liquidity/read/getMarketIndexTermination.js +14 -0
- package/dist/Liquidity/read/getMarketRoundByIndex.d.ts +1 -0
- package/dist/Liquidity/read/getMarketRoundByIndex.js +17 -0
- package/dist/Liquidity/read/getMaxTrade.js +2 -2
- package/dist/Liquidity/read/getPlatformFee.d.ts +1 -0
- package/dist/Liquidity/read/getPlatformFee.js +18 -0
- package/dist/Liquidity/read/isUserBetAlready.d.ts +1 -4
- package/dist/Liquidity/read/isUserBetAlready.js +9 -12
- package/dist/Liquidity/read/isUserPositionOpen.d.ts +4 -0
- package/dist/Liquidity/read/isUserPositionOpen.js +31 -0
- package/dist/Liquidity/read/userReserved.js +6 -4
- package/dist/Liquidity/write/addLiquidity.js +2 -2
- package/dist/Liquidity/write/removeLiquidity.js +2 -2
- package/dist/Liquidity/write/unReserve.js +2 -2
- package/dist/Liquidity.d.ts +6 -6
- package/dist/Liquidity.js +17 -17
- package/dist/abi/MarketLiquidityAbi.d.ts +1256 -0
- package/dist/abi/MarketLiquidityAbi.js +918 -0
- package/dist/abi/{TradeMarketsAbi.d.ts → riskGameAbi.d.ts} +1275 -1420
- package/dist/abi/riskGameAbi.js +2193 -0
- package/dist/abi/riskMarketAbi.d.ts +1704 -0
- package/dist/abi/riskMarketAbi.js +2193 -0
- package/dist/constants/index.d.ts +4 -4
- package/dist/constants/index.js +4 -4
- package/dist/types.d.ts +2 -2
- package/dist/utils/AxiosGraphInstance.js +1 -1
- package/dist/web3/contractHelpers.d.ts +3 -3
- package/dist/web3/contractHelpers.js +11 -11
- package/package.json +38 -38
- package/dist/RiskMarketSDK.d.ts +0 -81
- package/dist/RiskMarketSDK.js +0 -141
- package/dist/abi/ERC20Abi.d.ts +0 -1
- package/dist/abi/ERC20Abi.js +0 -76
- package/dist/abi/TradeMarketsAbi.js +0 -2371
- package/dist/abi/crashGame.abi.json +0 -15
- package/dist/abi/gameLiquidity.abi.json +0 -70
- package/dist/api/APIClient.d.ts +0 -105
- package/dist/api/APIClient.js +0 -204
- package/dist/config/api.d.ts +0 -1
- package/dist/config/api.js +0 -1
- package/dist/constants/contractmethods.d.ts +0 -3
- package/dist/constants/contractmethods.js +0 -3
- package/dist/markets/constants.d.ts +0 -17
- package/dist/markets/constants.js +0 -17
- package/dist/markets/getMarkets.d.ts +0 -2
- package/dist/markets/getMarkets.js +0 -19
- package/dist/markets/types.d.ts +0 -14
- package/dist/markets/types.js +0 -1
- package/dist/transactions/TransactionBuilder.d.ts +0 -88
- package/dist/transactions/TransactionBuilder.js +0 -114
- package/dist/transactions/liquidity/liquidity.d.ts +0 -20
- package/dist/transactions/liquidity/liquidity.js +0 -35
- package/dist/transactions/liquidity/read/getCrashGameIndex.d.ts +0 -1
- package/dist/transactions/liquidity/read/getCrashGameIndex.js +0 -15
- package/dist/transactions/liquidity/read/getMaxTrade.d.ts +0 -1
- package/dist/transactions/liquidity/read/getMaxTrade.js +0 -18
- package/dist/transactions/liquidity/read/getTotalRewards.d.ts +0 -1
- package/dist/transactions/liquidity/read/getTotalRewards.js +0 -17
- package/dist/transactions/liquidity/read/getTotalVolume.d.ts +0 -1
- package/dist/transactions/liquidity/read/getTotalVolume.js +0 -17
- package/dist/transactions/liquidity/write/addLiquidity.d.ts +0 -4
- package/dist/transactions/liquidity/write/addLiquidity.js +0 -26
- package/dist/tx/buildApprovalRawTx.d.ts +0 -2
- package/dist/tx/buildApprovalRawTx.js +0 -21
- package/dist/tx/buildRawTransactions.d.ts +0 -3
- package/dist/tx/buildRawTransactions.js +0 -57
- package/dist/tx/types.d.ts +0 -22
- package/dist/tx/types.js +0 -1
- package/dist/utils/constants.d.ts +0 -59
- package/dist/utils/constants.js +0 -67
- package/dist/utils/contractHelpers.d.ts +0 -2
- package/dist/utils/contractHelpers.js +0 -11
- package/dist/utils/converters/getGameRoundByIndex.converters.d.ts +0 -1
- package/dist/utils/converters/getGameRoundByIndex.converters.js +0 -34
- package/dist/utils/environments.d.ts +0 -7
- package/dist/utils/environments.js +0 -11
- package/dist/utils/getGameRoundByIndex.converters.d.ts +0 -1
- package/dist/utils/getGameRoundByIndex.converters.js +0 -34
- package/dist/utils/helpers2.d.ts +0 -62
- package/dist/utils/helpers2.js +0 -139
package/README.md
CHANGED
|
@@ -6,8 +6,8 @@ RiskMarket SDK is designed as a **clean, modular, and extensible TypeScript SDK*
|
|
|
6
6
|
|
|
7
7
|
The SDK provides a single entry point through the `Liquidity` class, which offers:
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
- **Read Methods** → Fetching on-chain data (market state, liquidity info, allowances, gas estimates)
|
|
10
|
+
- **Write Methods** → Building encoded transaction calldata (add/remove liquidity, unreserve)
|
|
11
11
|
|
|
12
12
|
---
|
|
13
13
|
|
|
@@ -35,7 +35,6 @@ const liquidity = new Liquidity();
|
|
|
35
35
|
|
|
36
36
|
---
|
|
37
37
|
|
|
38
|
-
|
|
39
38
|
## Read Methods
|
|
40
39
|
|
|
41
40
|
### getMaxTradeAmount
|
|
@@ -61,79 +60,79 @@ console.log(maxTrade); // "326901.222201"
|
|
|
61
60
|
|
|
62
61
|
---
|
|
63
62
|
|
|
64
|
-
###
|
|
63
|
+
### getMarketIndexTermination
|
|
65
64
|
|
|
66
|
-
Fetches the current
|
|
65
|
+
Fetches the current market market round index.
|
|
67
66
|
|
|
68
67
|
#### Method Signature
|
|
69
68
|
|
|
70
69
|
```ts
|
|
71
|
-
|
|
70
|
+
getMarketIndexTermination(): Promise<bigint>
|
|
72
71
|
```
|
|
73
72
|
|
|
74
73
|
#### Returns
|
|
75
74
|
|
|
76
|
-
`bigint` — The current
|
|
75
|
+
`bigint` — The current market round index.
|
|
77
76
|
|
|
78
77
|
#### Example
|
|
79
78
|
|
|
80
79
|
```ts
|
|
81
|
-
const currentIndex = await liquidity.
|
|
80
|
+
const currentIndex = await liquidity.getMarketIndexTermination();
|
|
82
81
|
console.log(currentIndex); // 1363n
|
|
83
82
|
```
|
|
84
83
|
|
|
85
84
|
---
|
|
86
85
|
|
|
87
|
-
###
|
|
86
|
+
### getMarketRoundByIndex
|
|
88
87
|
|
|
89
|
-
Fetches
|
|
88
|
+
Fetches market round data for a specific index.
|
|
90
89
|
|
|
91
90
|
#### Method Signature
|
|
92
91
|
|
|
93
92
|
```ts
|
|
94
|
-
|
|
93
|
+
getMarketRoundByIndex(index: number): Promise<MarketRound>
|
|
95
94
|
```
|
|
96
95
|
|
|
97
96
|
#### Parameters
|
|
98
97
|
|
|
99
|
-
| Parameter | Type | Required | Description
|
|
100
|
-
| --------- | -------- | -------- |
|
|
101
|
-
| `index` | `number` | ✅
|
|
98
|
+
| Parameter | Type | Required | Description |
|
|
99
|
+
| --------- | -------- | -------- | ---------------------- |
|
|
100
|
+
| `index` | `number` | ✅ | The market round index |
|
|
102
101
|
|
|
103
102
|
#### Returns
|
|
104
103
|
|
|
105
|
-
`
|
|
104
|
+
`marketRound` — Market round data with all values as strings.
|
|
106
105
|
|
|
107
|
-
| Field
|
|
108
|
-
|
|
|
109
|
-
| `index`
|
|
110
|
-
| `marketState`
|
|
111
|
-
| `startTime`
|
|
112
|
-
| `totalAssets`
|
|
113
|
-
| `requestId`
|
|
114
|
-
| `encryptedMarketDuration`
|
|
115
|
-
| `extraData`
|
|
106
|
+
| Field | Type | Description |
|
|
107
|
+
| ------------------------- | -------- | ------------------------------ |
|
|
108
|
+
| `index` | `string` | Market round index |
|
|
109
|
+
| `marketState` | `string` | Current state of the market |
|
|
110
|
+
| `startTime` | `string` | Unix timestamp of round start |
|
|
111
|
+
| `totalAssets` | `string` | Total assets in the round |
|
|
112
|
+
| `requestId` | `string` | VRF request ID |
|
|
113
|
+
| `encryptedMarketDuration` | `string` | Encrypted market duration hash |
|
|
114
|
+
| `extraData` | `string` | Additional encoded data |
|
|
116
115
|
|
|
117
116
|
#### Example
|
|
118
117
|
|
|
119
118
|
```ts
|
|
120
|
-
const round = await liquidity.
|
|
121
|
-
console.log(round.index);
|
|
119
|
+
const round = await liquidity.getMarketRoundByIndex(3);
|
|
120
|
+
console.log(round.index); // "3"
|
|
122
121
|
console.log(round.marketState); // "3"
|
|
123
|
-
console.log(round.startTime);
|
|
122
|
+
console.log(round.startTime); // "1767267308"
|
|
124
123
|
console.log(round.totalAssets); // "9500000"
|
|
125
124
|
```
|
|
126
125
|
|
|
127
126
|
---
|
|
128
127
|
|
|
129
|
-
###
|
|
128
|
+
### getPlatformFee
|
|
130
129
|
|
|
131
130
|
Fetches the total platform fees collected.
|
|
132
131
|
|
|
133
132
|
#### Method Signature
|
|
134
133
|
|
|
135
134
|
```ts
|
|
136
|
-
|
|
135
|
+
getPlatformFee(): Promise<string>
|
|
137
136
|
```
|
|
138
137
|
|
|
139
138
|
#### Returns
|
|
@@ -143,48 +142,48 @@ getCrashPlatformFee(): Promise<string>
|
|
|
143
142
|
#### Example
|
|
144
143
|
|
|
145
144
|
```ts
|
|
146
|
-
const fees = await liquidity.
|
|
145
|
+
const fees = await liquidity.getPlatformFee();
|
|
147
146
|
console.log(fees); // "1788.410256"
|
|
148
147
|
```
|
|
149
148
|
|
|
150
149
|
---
|
|
151
150
|
|
|
152
|
-
###
|
|
151
|
+
### isUserPositionOpen
|
|
153
152
|
|
|
154
|
-
Checks whether a user has already
|
|
153
|
+
Checks whether a user has already open a position in a specific market round.
|
|
155
154
|
|
|
156
155
|
#### Method Signature
|
|
157
156
|
|
|
158
157
|
```ts
|
|
159
|
-
|
|
158
|
+
isUserPositionOpen(
|
|
160
159
|
user_address: `0x${string}`,
|
|
161
160
|
index: number
|
|
162
|
-
): Promise<
|
|
161
|
+
): Promise<UserPositionInfo>
|
|
163
162
|
```
|
|
164
163
|
|
|
165
164
|
#### Parameters
|
|
166
165
|
|
|
167
|
-
| Parameter | Type
|
|
168
|
-
| -------------- |
|
|
169
|
-
| `user_address` | `` `0x${string}` `` | ✅
|
|
170
|
-
| `index` | `number`
|
|
166
|
+
| Parameter | Type | Required | Description |
|
|
167
|
+
| -------------- | ------------------- | -------- | ----------------------- |
|
|
168
|
+
| `user_address` | `` `0x${string}` `` | ✅ | User's Ethereum address |
|
|
169
|
+
| `index` | `number` | ✅ | Market round index |
|
|
171
170
|
|
|
172
171
|
#### Returns
|
|
173
172
|
|
|
174
173
|
| Field | Type | Description |
|
|
175
174
|
| -------- | -------- | ----------------------------------- |
|
|
176
|
-
| `amount` | `string` |
|
|
175
|
+
| `amount` | `string` | Position amount placed by the user |
|
|
177
176
|
| `status` | `string` | Confirmation status of the position |
|
|
178
177
|
|
|
179
178
|
#### Example
|
|
180
179
|
|
|
181
180
|
```ts
|
|
182
|
-
const
|
|
181
|
+
const position = await liquidity.isUserPositionOpen(
|
|
183
182
|
"0xa682C9022871881b3257A72E103B50fC75013245",
|
|
184
183
|
3
|
|
185
184
|
);
|
|
186
|
-
console.log(
|
|
187
|
-
console.log(
|
|
185
|
+
console.log(position.amount); // "9500000"
|
|
186
|
+
console.log(position.status); // "1"
|
|
188
187
|
```
|
|
189
188
|
|
|
190
189
|
---
|
|
@@ -201,9 +200,9 @@ checkAllowance(smartAccount: `0x${string}`): Promise<string>
|
|
|
201
200
|
|
|
202
201
|
#### Parameters
|
|
203
202
|
|
|
204
|
-
| Parameter | Type
|
|
205
|
-
| -------------- |
|
|
206
|
-
| `smartAccount` | `` `0x${string}` `` | ✅
|
|
203
|
+
| Parameter | Type | Required | Description |
|
|
204
|
+
| -------------- | ------------------- | -------- | --------------------- |
|
|
205
|
+
| `smartAccount` | `` `0x${string}` `` | ✅ | Smart account address |
|
|
207
206
|
|
|
208
207
|
#### Returns
|
|
209
208
|
|
|
@@ -235,10 +234,10 @@ getAllowanceByAddress(
|
|
|
235
234
|
|
|
236
235
|
#### Parameters
|
|
237
236
|
|
|
238
|
-
| Parameter | Type
|
|
239
|
-
| ----------------- |
|
|
240
|
-
| `smartAccount` | `` `0x${string}` `` | ✅
|
|
241
|
-
| `contractAddress` | `` `0x${string}` `` | ✅
|
|
237
|
+
| Parameter | Type | Required | Description |
|
|
238
|
+
| ----------------- | ------------------- | -------- | --------------------------------------- |
|
|
239
|
+
| `smartAccount` | `` `0x${string}` `` | ✅ | Smart account address |
|
|
240
|
+
| `contractAddress` | `` `0x${string}` `` | ✅ | Contract address to check allowance for |
|
|
242
241
|
|
|
243
242
|
#### Returns
|
|
244
243
|
|
|
@@ -270,9 +269,9 @@ CurrentLiquidityYouProvide(
|
|
|
270
269
|
|
|
271
270
|
#### Parameters
|
|
272
271
|
|
|
273
|
-
| Parameter | Type
|
|
274
|
-
| ----------------- |
|
|
275
|
-
| `internalAccount` | `` `0x${string}` `` | ✅
|
|
272
|
+
| Parameter | Type | Required | Description |
|
|
273
|
+
| ----------------- | ------------------- | -------- | ------------------------------- |
|
|
274
|
+
| `internalAccount` | `` `0x${string}` `` | ✅ | User's internal account address |
|
|
276
275
|
|
|
277
276
|
#### Returns
|
|
278
277
|
|
|
@@ -289,14 +288,14 @@ console.log(myLiquidity); // "3.412555239"
|
|
|
289
288
|
|
|
290
289
|
---
|
|
291
290
|
|
|
292
|
-
###
|
|
291
|
+
### estimateCloseGasFee
|
|
293
292
|
|
|
294
|
-
Estimates the gas fee in USD for a
|
|
293
|
+
Estimates the gas fee in USD for a close market transaction, including optional approval transactions.
|
|
295
294
|
|
|
296
295
|
#### Method Signature
|
|
297
296
|
|
|
298
297
|
```ts
|
|
299
|
-
|
|
298
|
+
estimateCloseGasFee(
|
|
300
299
|
amount: any,
|
|
301
300
|
smartAccount: any,
|
|
302
301
|
smartAccountClient: any,
|
|
@@ -310,12 +309,12 @@ estimateCrashGasFee(
|
|
|
310
309
|
|
|
311
310
|
| Parameter | Type | Required | Description |
|
|
312
311
|
| ---------------------- | --------- | -------- | -------------------------------------- |
|
|
313
|
-
| `amount` | `any` | ✅
|
|
314
|
-
| `smartAccount` | `any` | ✅
|
|
315
|
-
| `smartAccountClient` | `any` | ✅
|
|
316
|
-
| `isUSDTApprovalNeeded` | `boolean` | ✅
|
|
317
|
-
| `isRNGApprovalNeeded` | `boolean` | ✅
|
|
318
|
-
| `openPositionData` | `any` | ✅
|
|
312
|
+
| `amount` | `any` | ✅ | Transaction amount |
|
|
313
|
+
| `smartAccount` | `any` | ✅ | Smart account instance |
|
|
314
|
+
| `smartAccountClient` | `any` | ✅ | Smart account client instance |
|
|
315
|
+
| `isUSDTApprovalNeeded` | `boolean` | ✅ | Whether USDT approval is required |
|
|
316
|
+
| `isRNGApprovalNeeded` | `boolean` | ✅ | Whether RNG token approval is required |
|
|
317
|
+
| `openPositionData` | `any` | ✅ | Encoded open position transaction data |
|
|
319
318
|
|
|
320
319
|
#### Returns
|
|
321
320
|
|
|
@@ -324,7 +323,7 @@ estimateCrashGasFee(
|
|
|
324
323
|
#### Example
|
|
325
324
|
|
|
326
325
|
```ts
|
|
327
|
-
const gasFee = await liquidity.
|
|
326
|
+
const gasFee = await liquidity.estimateCloseGasFee(
|
|
328
327
|
1000000n,
|
|
329
328
|
smartAccount,
|
|
330
329
|
smartAccountClient,
|
|
@@ -371,8 +370,8 @@ addLiquidityMethod(params: {
|
|
|
371
370
|
|
|
372
371
|
| Parameter | Type | Required | Description |
|
|
373
372
|
| -------------- | -------- | -------- | ------------------------------ |
|
|
374
|
-
| `amount` | `string` | ✅
|
|
375
|
-
| `smartAccount` | `string` | ✅
|
|
373
|
+
| `amount` | `string` | ✅ | Amount of liquidity to deposit |
|
|
374
|
+
| `smartAccount` | `string` | ✅ | Smart account address |
|
|
376
375
|
|
|
377
376
|
#### Example
|
|
378
377
|
|
|
@@ -402,9 +401,9 @@ addUnReserveMethod(params: {
|
|
|
402
401
|
|
|
403
402
|
#### Parameters
|
|
404
403
|
|
|
405
|
-
| Parameter | Type
|
|
406
|
-
| --------- |
|
|
407
|
-
| `address` | `` `0x${string}` `` | ✅
|
|
404
|
+
| Parameter | Type | Required | Description |
|
|
405
|
+
| --------- | ------------------- | -------- | -------------- |
|
|
406
|
+
| `address` | `` `0x${string}` `` | ✅ | User's address |
|
|
408
407
|
|
|
409
408
|
#### Example
|
|
410
409
|
|
|
@@ -435,11 +434,11 @@ removeLiquidity(params: {
|
|
|
435
434
|
|
|
436
435
|
#### Parameters
|
|
437
436
|
|
|
438
|
-
| Parameter | Type
|
|
439
|
-
| -------------- |
|
|
440
|
-
| `address` | `` `0x${string}` `` | ✅
|
|
441
|
-
| `amount` | `string`
|
|
442
|
-
| `smartAccount` | `` `0x${string}` `` | ✅
|
|
437
|
+
| Parameter | Type | Required | Description |
|
|
438
|
+
| -------------- | ------------------- | -------- | ------------------------------- |
|
|
439
|
+
| `address` | `` `0x${string}` `` | ✅ | Liquidity provider address |
|
|
440
|
+
| `amount` | `string` | ✅ | Amount of liquidity to withdraw |
|
|
441
|
+
| `smartAccount` | `` `0x${string}` `` | ✅ | Smart account address |
|
|
443
442
|
|
|
444
443
|
#### Example
|
|
445
444
|
|
|
@@ -465,8 +464,8 @@ const liquidity = new Liquidity();
|
|
|
465
464
|
|
|
466
465
|
// 1. Read on-chain data
|
|
467
466
|
const maxTrade = await liquidity.getMaxTradeAmount();
|
|
468
|
-
const
|
|
469
|
-
const round = await liquidity.
|
|
467
|
+
const marketIndex = await liquidity.getMarketIndexTermination();
|
|
468
|
+
const round = await liquidity.getMarketRoundByIndex(Number(marketIndex));
|
|
470
469
|
|
|
471
470
|
// 2. Check allowances before writing
|
|
472
471
|
const allowance = await liquidity.checkAllowance("0xYourSmartAccount...");
|
|
@@ -488,6 +487,7 @@ await smartAccountClient.sendTransaction({ calls });
|
|
|
488
487
|
To use this SDK locally during development:
|
|
489
488
|
|
|
490
489
|
1. Navigate to the SDK directory and link it:
|
|
490
|
+
|
|
491
491
|
```bash
|
|
492
492
|
cd riskmarket-sdks
|
|
493
493
|
yarn build
|
|
@@ -495,12 +495,14 @@ To use this SDK locally during development:
|
|
|
495
495
|
```
|
|
496
496
|
|
|
497
497
|
2. In your consumer application directory, link to the local SDK:
|
|
498
|
+
|
|
498
499
|
```bash
|
|
499
500
|
cd /path/to/your/consumer/app
|
|
500
501
|
yarn link "riskmarket-sdk"
|
|
501
502
|
```
|
|
502
503
|
|
|
503
504
|
3. After making changes to the SDK, rebuild it:
|
|
505
|
+
|
|
504
506
|
```bash
|
|
505
507
|
yarn build
|
|
506
508
|
```
|
|
@@ -513,9 +515,9 @@ To use this SDK locally during development:
|
|
|
513
515
|
|
|
514
516
|
RiskMarket SDK follows **Semantic Versioning**:
|
|
515
517
|
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
518
|
+
- **Patch** (`1.0.x`) → Bug fixes
|
|
519
|
+
- **Minor** (`1.x.0`) → New features, backward compatible
|
|
520
|
+
- **Major** (`x.0.0`) → Breaking API changes
|
|
519
521
|
|
|
520
522
|
---
|
|
521
523
|
|
package/dist/Game.d.ts
CHANGED
|
@@ -1,9 +1,57 @@
|
|
|
1
|
+
import { type Environment } from "./constants/index.js";
|
|
2
|
+
export interface GameOptions {
|
|
3
|
+
environment?: Environment;
|
|
4
|
+
}
|
|
1
5
|
export declare class Game {
|
|
2
6
|
private client;
|
|
3
|
-
|
|
7
|
+
private config;
|
|
8
|
+
constructor(options?: GameOptions);
|
|
9
|
+
getEnvironment(): Environment;
|
|
10
|
+
getConfig(): {
|
|
11
|
+
readonly apiUrl: "https://dev-api.riskmarkets.fun";
|
|
12
|
+
readonly rpcUrl: "https://arb-mainnet.g.alchemy.com/v2/m1ZDZF0NDLbqkK-we12g0";
|
|
13
|
+
readonly contracts: {
|
|
14
|
+
readonly usdtToken: `0x${string}`;
|
|
15
|
+
readonly liquidityContract: `0x${string}`;
|
|
16
|
+
readonly closeGame: `0x${string}`;
|
|
17
|
+
readonly rng: `0x${string}`;
|
|
18
|
+
readonly paymaster: `0x${string}`;
|
|
19
|
+
};
|
|
20
|
+
readonly graphQl: {
|
|
21
|
+
readonly closeGame: "https://api.studio.thegraph.com/query/25822/rain-decision-development/version/latest";
|
|
22
|
+
};
|
|
23
|
+
} | {
|
|
24
|
+
readonly apiUrl: "https://stg-api.riskmarkets.fun";
|
|
25
|
+
readonly rpcUrl: "https://arb-mainnet.g.alchemy.com/v2/m1ZDZF0NDLbqkK-we12g0";
|
|
26
|
+
readonly contracts: {
|
|
27
|
+
readonly usdtToken: `0x${string}`;
|
|
28
|
+
readonly liquidityContract: `0x${string}`;
|
|
29
|
+
readonly closeGame: `0x${string}`;
|
|
30
|
+
readonly rng: `0x${string}`;
|
|
31
|
+
readonly paymaster: `0x${string}`;
|
|
32
|
+
};
|
|
33
|
+
readonly graphQl: {
|
|
34
|
+
readonly closeGame: "https://api.studio.thegraph.com/query/25822/rain-decision-staging/version/latest";
|
|
35
|
+
};
|
|
36
|
+
} | {
|
|
37
|
+
readonly apiUrl: "https://api.riskmarkets.fun";
|
|
38
|
+
readonly rpcUrl: "https://arb-mainnet.g.alchemy.com/v2/YOUR_PROD_KEY";
|
|
39
|
+
readonly contracts: {
|
|
40
|
+
readonly usdtToken: `0x${string}`;
|
|
41
|
+
readonly liquidityContract: `0x${string}`;
|
|
42
|
+
readonly closeGame: `0x${string}`;
|
|
43
|
+
readonly rng: `0x${string}`;
|
|
44
|
+
readonly paymaster: `0x${string}`;
|
|
45
|
+
};
|
|
46
|
+
readonly graphQl: {
|
|
47
|
+
readonly closeGame: "https://api.studio.thegraph.com/query/25822/rain-decision-production/version/latest";
|
|
48
|
+
};
|
|
49
|
+
};
|
|
4
50
|
getTotalLiquidity(): Promise<any>;
|
|
5
51
|
getMinBet(): Promise<any>;
|
|
6
52
|
getMaxBet(): Promise<any>;
|
|
53
|
+
getPositionData(userAddress: `0x${string}`, index: number): Promise<any>;
|
|
54
|
+
getPositionProgress(userAddress: `0x${string}`, index: number): Promise<any>;
|
|
7
55
|
cashOutMethod(params: {
|
|
8
56
|
smartAccount: string;
|
|
9
57
|
}): Promise<any>;
|
package/dist/Game.js
CHANGED
|
@@ -1,24 +1,47 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getCurrentConfig, sdkConfig, } from "./constants/index.js";
|
|
2
2
|
import { getViemClient } from "./web3/web3.js";
|
|
3
3
|
import { cashOutMethod } from "./Games/write/cashout.js";
|
|
4
4
|
import { placeBetMethod } from "./Games/write/placeBet.js";
|
|
5
5
|
import { getTotalLiquidity } from "./Games/read/getTotalLiquidity.js";
|
|
6
6
|
import { getMinBet } from "./Games/read/getMinBet.js";
|
|
7
7
|
import { getMaxBet } from "./Games/read/getMaxBet.js";
|
|
8
|
+
import { getPositionData } from "./Games/read/getPositionData.js";
|
|
9
|
+
import { getPositionProgress } from "./Games/read/getPositionProgress.js";
|
|
8
10
|
export class Game {
|
|
9
11
|
client;
|
|
10
|
-
|
|
12
|
+
config;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
// Set environment if provided
|
|
15
|
+
if (options?.environment) {
|
|
16
|
+
sdkConfig.setEnvironment(options.environment);
|
|
17
|
+
}
|
|
18
|
+
// Get current config
|
|
19
|
+
this.config = getCurrentConfig();
|
|
11
20
|
this.client = getViemClient();
|
|
12
21
|
}
|
|
22
|
+
// Getter for current environment
|
|
23
|
+
getEnvironment() {
|
|
24
|
+
return sdkConfig.getEnvironment();
|
|
25
|
+
}
|
|
26
|
+
// Getter for current config (useful for debugging)
|
|
27
|
+
getConfig() {
|
|
28
|
+
return this.config;
|
|
29
|
+
}
|
|
13
30
|
// Read functions
|
|
14
31
|
async getTotalLiquidity() {
|
|
15
|
-
return await getTotalLiquidity(
|
|
32
|
+
return await getTotalLiquidity(this.config.contracts.liquidityContract, this.config.contracts.usdtToken);
|
|
16
33
|
}
|
|
17
34
|
async getMinBet() {
|
|
18
|
-
return await getMinBet(
|
|
35
|
+
return await getMinBet(this.config.contracts.closeGame);
|
|
19
36
|
}
|
|
20
37
|
async getMaxBet() {
|
|
21
|
-
return await getMaxBet(
|
|
38
|
+
return await getMaxBet(this.config.contracts.liquidityContract, this.config.contracts.usdtToken);
|
|
39
|
+
}
|
|
40
|
+
async getPositionData(userAddress, index) {
|
|
41
|
+
return await getPositionData(this.config.contracts.closeGame, userAddress, index);
|
|
42
|
+
}
|
|
43
|
+
async getPositionProgress(userAddress, index) {
|
|
44
|
+
return await getPositionProgress(this.config.contracts.closeGame, userAddress, index);
|
|
22
45
|
}
|
|
23
46
|
// Write functions
|
|
24
47
|
async cashOutMethod(params) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const getMaxBet: (liquidityAddress: `0x${string}`) => Promise<number>;
|
|
1
|
+
export declare const getMaxBet: (liquidityAddress: `0x${string}`, usdtTokenAddress: `0x${string}`) => Promise<number>;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { Enviroments } from "../../constants/index.js";
|
|
2
1
|
import { UtilitiyFunctions } from "../../utils/helpers.js";
|
|
3
2
|
import { getViemClient } from "../../web3/web3.js";
|
|
4
3
|
import { getGameLiquidityContract } from "../../web3/contractHelpers.js";
|
|
5
4
|
const MAX_BET_DIVISOR = 520;
|
|
6
|
-
export const getMaxBet = async (liquidityAddress) => {
|
|
5
|
+
export const getMaxBet = async (liquidityAddress, usdtTokenAddress) => {
|
|
7
6
|
try {
|
|
8
7
|
const client = getViemClient();
|
|
9
8
|
const contract = getGameLiquidityContract(liquidityAddress, client);
|
|
10
9
|
const [totalAssets, totalFees] = await Promise.all([
|
|
11
|
-
contract.read.totalAssets([
|
|
12
|
-
contract.read.totalFees([
|
|
10
|
+
contract.read.totalAssets([usdtTokenAddress]),
|
|
11
|
+
contract.read.totalFees([usdtTokenAddress]),
|
|
13
12
|
]);
|
|
14
13
|
const formattedLiquidity = UtilitiyFunctions.convertFromWei(totalAssets, "mwei");
|
|
15
14
|
const formattedFees = UtilitiyFunctions.convertFromWei(totalFees, "mwei");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const getMinBet: (address: `0x${string}`) => Promise<
|
|
1
|
+
export declare const getMinBet: (address: `0x${string}`) => Promise<string>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { UtilitiyFunctions } from "../../utils/helpers.js";
|
|
2
2
|
import { getViemClient } from "../../web3/web3.js";
|
|
3
|
-
import {
|
|
3
|
+
import { getGameContract } from "../../web3/contractHelpers.js";
|
|
4
4
|
export const getMinBet = async (address) => {
|
|
5
5
|
try {
|
|
6
6
|
const client = getViemClient();
|
|
7
|
-
const contract =
|
|
7
|
+
const contract = getGameContract(address, client);
|
|
8
8
|
const minPosition = await contract.read.minPosition();
|
|
9
9
|
const formatted = UtilitiyFunctions.convertFromWei(minPosition, "mwei");
|
|
10
10
|
return formatted;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getPositionData: (address: `0x${string}`, user_address: `0x${string}`, index: number) => Promise<any>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getViemClient } from "../../web3/web3.js";
|
|
2
|
+
import { getGameContract } from "../../web3/contractHelpers.js";
|
|
3
|
+
import { GameState } from "../../constants/index.js";
|
|
4
|
+
import { formatToWeb3Style } from "../../utils/formatToWeb3Response.js";
|
|
5
|
+
import { riskGameAbi } from "../../abi/riskGameAbi.js";
|
|
6
|
+
export const getPositionData = async (address, user_address, index) => {
|
|
7
|
+
try {
|
|
8
|
+
const client = getViemClient();
|
|
9
|
+
const contract = getGameContract(address, client);
|
|
10
|
+
const generatingId = await client.readContract({
|
|
11
|
+
address: address,
|
|
12
|
+
abi: riskGameAbi,
|
|
13
|
+
functionName: "generatePositionId",
|
|
14
|
+
args: [parseInt(GameState?.closeGame), user_address, BigInt(index)],
|
|
15
|
+
});
|
|
16
|
+
const betData = await contract.read.positionData([generatingId]);
|
|
17
|
+
return formatToWeb3Style(betData, "positionData", riskGameAbi);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
console.error("Error fetching getPositionData:", error);
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getPositionProgress: (address: `0x${string}`, user_address: `0x${string}`, index: number) => Promise<any>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getViemClient } from "../../web3/web3.js";
|
|
2
|
+
import { getGameContract } from "../../web3/contractHelpers.js";
|
|
3
|
+
import { GameState } from "../../constants/index.js";
|
|
4
|
+
import { formatToWeb3Style } from "../../utils/formatToWeb3Response.js";
|
|
5
|
+
import { riskGameAbi } from "../../abi/riskGameAbi.js";
|
|
6
|
+
export const getPositionProgress = async (address, user_address, index) => {
|
|
7
|
+
try {
|
|
8
|
+
const client = getViemClient();
|
|
9
|
+
const contract = getGameContract(address, client);
|
|
10
|
+
const generatingId = await client.readContract({
|
|
11
|
+
address: address,
|
|
12
|
+
abi: riskGameAbi,
|
|
13
|
+
functionName: "generatePositionId",
|
|
14
|
+
args: [parseInt(GameState?.closeGame), user_address, BigInt(index)],
|
|
15
|
+
});
|
|
16
|
+
const positionProgress = await contract.read.positionProgress([
|
|
17
|
+
generatingId,
|
|
18
|
+
]);
|
|
19
|
+
return formatToWeb3Style(positionProgress, "positionProgress", riskGameAbi);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.error("Error fetching getPositionProgress:", error);
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const getTotalLiquidity: (address: `0x${string}`) => Promise<
|
|
1
|
+
export declare const getTotalLiquidity: (address: `0x${string}`, usdtTokenAddress: `0x${string}`) => Promise<string>;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { Enviroments } from "../../constants/index.js";
|
|
2
1
|
import { UtilitiyFunctions } from "../../utils/helpers.js";
|
|
3
2
|
import { getViemClient } from "../../web3/web3.js";
|
|
4
3
|
import { getGameLiquidityContract } from "../../web3/contractHelpers.js";
|
|
5
|
-
export const getTotalLiquidity = async (address) => {
|
|
4
|
+
export const getTotalLiquidity = async (address, usdtTokenAddress) => {
|
|
6
5
|
try {
|
|
7
6
|
const client = getViemClient();
|
|
8
7
|
const contract = getGameLiquidityContract(address, client);
|
|
9
|
-
const balance = await contract.read.totalAssets([
|
|
8
|
+
const balance = await contract.read.totalAssets([usdtTokenAddress]);
|
|
10
9
|
const formattedBalance = UtilitiyFunctions.convertFromWei(balance, "mwei");
|
|
11
10
|
return formattedBalance;
|
|
12
11
|
}
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import { encodeFunctionData } from "viem";
|
|
2
2
|
import axios from "axios";
|
|
3
|
-
import {
|
|
3
|
+
import { riskGameAbi } from "../../abi/riskGameAbi.js";
|
|
4
4
|
import { UtilitiyFunctions } from "../../utils/helpers.js";
|
|
5
|
-
import {
|
|
5
|
+
import { getCurrentConfig } from "../../constants/index.js";
|
|
6
6
|
export const cashOutMethod = async (params) => {
|
|
7
7
|
const validSmartAccount = UtilitiyFunctions.validateEthereumAddress(params.smartAccount);
|
|
8
|
+
const config = getCurrentConfig();
|
|
8
9
|
if (!validSmartAccount) {
|
|
9
10
|
throw new Error("Invalid Ethereum address provided for smartAccount.");
|
|
10
11
|
}
|
|
11
12
|
try {
|
|
12
|
-
const response = await axios.post(`${
|
|
13
|
+
const response = await axios.post(`${config.apiUrl}/crash-game/cashout`, {
|
|
13
14
|
walletAddress: params.smartAccount,
|
|
14
15
|
time: Date.now(),
|
|
15
16
|
});
|
|
16
17
|
console.log(response, response.data.data.signedKey, response.data.data.signedKey, "cashout app call completed");
|
|
17
18
|
const calls = [
|
|
18
19
|
{
|
|
19
|
-
to:
|
|
20
|
+
to: config.contracts.closeGame,
|
|
20
21
|
data: encodeFunctionData({
|
|
21
|
-
abi:
|
|
22
|
+
abi: riskGameAbi,
|
|
22
23
|
functionName: "closePositionTermination",
|
|
23
24
|
args: [response.data.data.signedKey, response.data.data.signedKey],
|
|
24
25
|
}),
|