@carrot-protocol/boost-http-client 0.2.15-group-refactor1-dev-6331a3e → 0.2.15-group-refactor1-dev-6ecf454
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/dist/index.d.ts +7 -1
- package/dist/index.js +29 -3
- package/dist/types.d.ts +7 -0
- package/package.json +1 -1
- package/src/index.ts +37 -3
- package/src/types.ts +9 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnchorProvider, web3 } from "@coral-xyz/anchor";
|
|
2
|
-
import { GetBankResponse, GetUserResponse, GetGroupResponse } from "./types";
|
|
2
|
+
import { GetBankResponse, GetUserResponse, GetGroupResponse, GetGroupsResponse } from "./types";
|
|
3
3
|
export * from "./types";
|
|
4
4
|
export * from "./utils";
|
|
5
5
|
export * as Common from "@carrot-protocol/clend-common";
|
|
@@ -28,6 +28,12 @@ export declare class Client {
|
|
|
28
28
|
* @returns User details
|
|
29
29
|
*/
|
|
30
30
|
getUser(groups: web3.PublicKey[], user: web3.PublicKey, getClendAccountSummary: boolean): Promise<GetUserResponse>;
|
|
31
|
+
/**
|
|
32
|
+
* Get all groups
|
|
33
|
+
* @param includeBankData Whether to include bank data in the response, if not strictly necessary keep false
|
|
34
|
+
* @returns All groups
|
|
35
|
+
*/
|
|
36
|
+
getGroups(includeBankData: boolean): Promise<GetGroupsResponse>;
|
|
31
37
|
/**
|
|
32
38
|
* Get market details
|
|
33
39
|
* @param groupAddress group public key
|
package/dist/index.js
CHANGED
|
@@ -236,6 +236,29 @@ class Client {
|
|
|
236
236
|
clendAccounts,
|
|
237
237
|
};
|
|
238
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* Get all groups
|
|
241
|
+
* @param includeBankData Whether to include bank data in the response, if not strictly necessary keep false
|
|
242
|
+
* @returns All groups
|
|
243
|
+
*/
|
|
244
|
+
async getGroups(includeBankData) {
|
|
245
|
+
const body = await handleApiCall(() => this.http.get(`/groups?includeBankData=${includeBankData}`));
|
|
246
|
+
const marketJson = JSON.parse(body);
|
|
247
|
+
const groups = [];
|
|
248
|
+
for (const groupJson of marketJson.groups) {
|
|
249
|
+
const group = new anchor_1.web3.PublicKey(groupJson.group);
|
|
250
|
+
const banks = [];
|
|
251
|
+
for (const bankJson of groupJson.banks) {
|
|
252
|
+
const bank = parseBank(bankJson);
|
|
253
|
+
banks.push(bank);
|
|
254
|
+
}
|
|
255
|
+
groups.push({ group, banks });
|
|
256
|
+
}
|
|
257
|
+
const response = {
|
|
258
|
+
groups,
|
|
259
|
+
};
|
|
260
|
+
return response;
|
|
261
|
+
}
|
|
239
262
|
/**
|
|
240
263
|
* Get market details
|
|
241
264
|
* @param groupAddress group public key
|
|
@@ -244,13 +267,16 @@ class Client {
|
|
|
244
267
|
async getGroup(groupAddress) {
|
|
245
268
|
const body = await handleApiCall(() => this.http.get(`/group?group=${groupAddress.toString()}`));
|
|
246
269
|
const marketJson = JSON.parse(body);
|
|
247
|
-
const
|
|
270
|
+
const group = {
|
|
271
|
+
group: new anchor_1.web3.PublicKey(marketJson.group),
|
|
272
|
+
banks: [],
|
|
273
|
+
};
|
|
248
274
|
for (const bankJson of marketJson.banks) {
|
|
249
275
|
const bank = parseBank(bankJson);
|
|
250
|
-
banks.push(bank);
|
|
276
|
+
group.banks.push(bank);
|
|
251
277
|
}
|
|
252
278
|
const response = {
|
|
253
|
-
|
|
279
|
+
group,
|
|
254
280
|
};
|
|
255
281
|
return response;
|
|
256
282
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -64,7 +64,14 @@ export interface WithdrawLeverageResponse {
|
|
|
64
64
|
userRequestId: string;
|
|
65
65
|
unsignedBase64Tx: string;
|
|
66
66
|
}
|
|
67
|
+
export interface GetGroupsResponse {
|
|
68
|
+
groups: GroupAndBanks[];
|
|
69
|
+
}
|
|
67
70
|
export interface GetGroupResponse {
|
|
71
|
+
group: GroupAndBanks;
|
|
72
|
+
}
|
|
73
|
+
export interface GroupAndBanks {
|
|
74
|
+
group: web3.PublicKey;
|
|
68
75
|
banks: Bank[];
|
|
69
76
|
}
|
|
70
77
|
export interface GetUserRequest {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -21,6 +21,8 @@ import {
|
|
|
21
21
|
UserRequest,
|
|
22
22
|
UserBalance,
|
|
23
23
|
ClendAccountAssetLiquidation,
|
|
24
|
+
GetGroupsResponse,
|
|
25
|
+
GroupAndBanks,
|
|
24
26
|
} from "./types";
|
|
25
27
|
import encode from "bs58";
|
|
26
28
|
|
|
@@ -266,6 +268,35 @@ export class Client {
|
|
|
266
268
|
};
|
|
267
269
|
}
|
|
268
270
|
|
|
271
|
+
/**
|
|
272
|
+
* Get all groups
|
|
273
|
+
* @param includeBankData Whether to include bank data in the response, if not strictly necessary keep false
|
|
274
|
+
* @returns All groups
|
|
275
|
+
*/
|
|
276
|
+
async getGroups(includeBankData: boolean): Promise<GetGroupsResponse> {
|
|
277
|
+
const body = await handleApiCall(() =>
|
|
278
|
+
this.http.get(`/groups?includeBankData=${includeBankData}`),
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
const marketJson: any = JSON.parse(body);
|
|
282
|
+
const groups: GroupAndBanks[] = [];
|
|
283
|
+
for (const groupJson of marketJson.groups) {
|
|
284
|
+
const group: web3.PublicKey = new web3.PublicKey(groupJson.group);
|
|
285
|
+
const banks: Bank[] = [];
|
|
286
|
+
for (const bankJson of groupJson.banks) {
|
|
287
|
+
const bank = parseBank(bankJson);
|
|
288
|
+
banks.push(bank);
|
|
289
|
+
}
|
|
290
|
+
groups.push({ group, banks });
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const response: GetGroupsResponse = {
|
|
294
|
+
groups,
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
return response;
|
|
298
|
+
}
|
|
299
|
+
|
|
269
300
|
/**
|
|
270
301
|
* Get market details
|
|
271
302
|
* @param groupAddress group public key
|
|
@@ -277,14 +308,17 @@ export class Client {
|
|
|
277
308
|
);
|
|
278
309
|
|
|
279
310
|
const marketJson: any = JSON.parse(body);
|
|
280
|
-
const
|
|
311
|
+
const group: GroupAndBanks = {
|
|
312
|
+
group: new web3.PublicKey(marketJson.group),
|
|
313
|
+
banks: [],
|
|
314
|
+
};
|
|
281
315
|
for (const bankJson of marketJson.banks) {
|
|
282
316
|
const bank = parseBank(bankJson);
|
|
283
|
-
banks.push(bank);
|
|
317
|
+
group.banks.push(bank);
|
|
284
318
|
}
|
|
285
319
|
|
|
286
320
|
const response: GetGroupResponse = {
|
|
287
|
-
|
|
321
|
+
group,
|
|
288
322
|
};
|
|
289
323
|
|
|
290
324
|
return response;
|
package/src/types.ts
CHANGED
|
@@ -73,7 +73,16 @@ export interface WithdrawLeverageResponse {
|
|
|
73
73
|
unsignedBase64Tx: string;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
export interface GetGroupsResponse {
|
|
77
|
+
groups: GroupAndBanks[];
|
|
78
|
+
}
|
|
79
|
+
|
|
76
80
|
export interface GetGroupResponse {
|
|
81
|
+
group: GroupAndBanks;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface GroupAndBanks {
|
|
85
|
+
group: web3.PublicKey;
|
|
77
86
|
banks: Bank[];
|
|
78
87
|
}
|
|
79
88
|
|