@carrot-protocol/boost-http-client 0.2.15-group-refactor1-dev-6331a3e → 0.2.15-group-refactor1-dev-72c1344

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 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,30 @@ 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 groupName = groupJson.groupName;
251
+ const banks = [];
252
+ for (const bankJson of groupJson.banks) {
253
+ const bank = parseBank(bankJson);
254
+ banks.push(bank);
255
+ }
256
+ groups.push({ group, groupName, banks });
257
+ }
258
+ const response = {
259
+ groups,
260
+ };
261
+ return response;
262
+ }
239
263
  /**
240
264
  * Get market details
241
265
  * @param groupAddress group public key
@@ -244,13 +268,17 @@ class Client {
244
268
  async getGroup(groupAddress) {
245
269
  const body = await handleApiCall(() => this.http.get(`/group?group=${groupAddress.toString()}`));
246
270
  const marketJson = JSON.parse(body);
247
- const banks = [];
271
+ const group = {
272
+ group: new anchor_1.web3.PublicKey(marketJson.group),
273
+ groupName: marketJson.groupName,
274
+ banks: [],
275
+ };
248
276
  for (const bankJson of marketJson.banks) {
249
277
  const bank = parseBank(bankJson);
250
- banks.push(bank);
278
+ group.banks.push(bank);
251
279
  }
252
280
  const response = {
253
- banks,
281
+ group,
254
282
  };
255
283
  return response;
256
284
  }
package/dist/types.d.ts CHANGED
@@ -64,7 +64,15 @@ 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;
75
+ groupName: string;
68
76
  banks: Bank[];
69
77
  }
70
78
  export interface GetUserRequest {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carrot-protocol/boost-http-client",
3
- "version": "0.2.15-group-refactor1-dev-6331a3e",
3
+ "version": "0.2.15-group-refactor1-dev-72c1344",
4
4
  "description": "HTTP client for Carrot Boost",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
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,36 @@ 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 groupName = groupJson.groupName;
286
+ const banks: Bank[] = [];
287
+ for (const bankJson of groupJson.banks) {
288
+ const bank = parseBank(bankJson);
289
+ banks.push(bank);
290
+ }
291
+ groups.push({ group, groupName, banks });
292
+ }
293
+
294
+ const response: GetGroupsResponse = {
295
+ groups,
296
+ };
297
+
298
+ return response;
299
+ }
300
+
269
301
  /**
270
302
  * Get market details
271
303
  * @param groupAddress group public key
@@ -277,14 +309,18 @@ export class Client {
277
309
  );
278
310
 
279
311
  const marketJson: any = JSON.parse(body);
280
- const banks: Bank[] = [];
312
+ const group: GroupAndBanks = {
313
+ group: new web3.PublicKey(marketJson.group),
314
+ groupName: marketJson.groupName,
315
+ banks: [],
316
+ };
281
317
  for (const bankJson of marketJson.banks) {
282
318
  const bank = parseBank(bankJson);
283
- banks.push(bank);
319
+ group.banks.push(bank);
284
320
  }
285
321
 
286
322
  const response: GetGroupResponse = {
287
- banks,
323
+ group,
288
324
  };
289
325
 
290
326
  return response;
package/src/types.ts CHANGED
@@ -73,7 +73,17 @@ 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;
86
+ groupName: string;
77
87
  banks: Bank[];
78
88
  }
79
89