@carrot-protocol/boost-http-client 0.2.15-group-refactor1-dev-44d9397 → 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 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
@@ -51,11 +57,11 @@ export declare class Client {
51
57
  * @param request Adjust leverage request parameters
52
58
  * @returns Adjust leverage operation result
53
59
  */
54
- adjustLeverage(clendGroup: web3.PublicKey, assetTokenMint: web3.PublicKey, liabilityTokenMint: web3.PublicKey, leverage: number, slippageBps: number): Promise<any>;
60
+ adjustLeverage(clendGroup: web3.PublicKey, clendAccount: web3.PublicKey, assetTokenMint: web3.PublicKey, liabilityTokenMint: web3.PublicKey, leverage: number, slippageBps: number): Promise<any>;
55
61
  /**
56
62
  * Withdraw from or close a leveraged position
57
63
  * @param request Withdraw leverage request parameters
58
64
  * @returns Withdraw leverage operation result
59
65
  */
60
- withdrawLeverage(clendGroup: web3.PublicKey, outputTokenMint: web3.PublicKey, assetTokenMint: web3.PublicKey, liabilityTokenMint: web3.PublicKey, uiAmount: number, slippageBps: number, withdrawAll: boolean): Promise<any>;
66
+ withdrawLeverage(clendGroup: web3.PublicKey, clendAccount: web3.PublicKey, outputTokenMint: web3.PublicKey, assetTokenMint: web3.PublicKey, liabilityTokenMint: web3.PublicKey, uiAmount: number, slippageBps: number, withdrawAll: boolean): Promise<any>;
61
67
  }
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 banks = [];
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
- banks,
279
+ group,
254
280
  };
255
281
  return response;
256
282
  }
@@ -299,10 +325,11 @@ class Client {
299
325
  * @param request Adjust leverage request parameters
300
326
  * @returns Adjust leverage operation result
301
327
  */
302
- async adjustLeverage(clendGroup, assetTokenMint, liabilityTokenMint, leverage, slippageBps) {
328
+ async adjustLeverage(clendGroup, clendAccount, assetTokenMint, liabilityTokenMint, leverage, slippageBps) {
303
329
  const req = {
304
330
  owner: this.address(),
305
331
  clendGroup,
332
+ clendAccount,
306
333
  assetTokenMint,
307
334
  liabilityTokenMint,
308
335
  leverage,
@@ -318,10 +345,11 @@ class Client {
318
345
  * @param request Withdraw leverage request parameters
319
346
  * @returns Withdraw leverage operation result
320
347
  */
321
- async withdrawLeverage(clendGroup, outputTokenMint, assetTokenMint, liabilityTokenMint, uiAmount, slippageBps, withdrawAll) {
348
+ async withdrawLeverage(clendGroup, clendAccount, outputTokenMint, assetTokenMint, liabilityTokenMint, uiAmount, slippageBps, withdrawAll) {
322
349
  const req = {
323
350
  owner: this.address(),
324
351
  clendGroup,
352
+ clendAccount,
325
353
  outputTokenMint,
326
354
  assetTokenMint,
327
355
  liabilityTokenMint,
package/dist/types.d.ts CHANGED
@@ -30,6 +30,7 @@ export interface DepositLeverageResponse {
30
30
  export interface AdjustLeverageRequest {
31
31
  owner: web3.PublicKey;
32
32
  clendGroup: web3.PublicKey;
33
+ clendAccount: web3.PublicKey;
33
34
  assetTokenMint: web3.PublicKey;
34
35
  liabilityTokenMint: web3.PublicKey;
35
36
  leverage: number;
@@ -48,6 +49,7 @@ export interface AdjustLeverageResponse {
48
49
  export interface WithdrawLeverageRequest {
49
50
  owner: web3.PublicKey;
50
51
  clendGroup: web3.PublicKey;
52
+ clendAccount: web3.PublicKey;
51
53
  outputTokenMint: web3.PublicKey;
52
54
  assetTokenMint: web3.PublicKey;
53
55
  liabilityTokenMint: web3.PublicKey;
@@ -62,7 +64,14 @@ export interface WithdrawLeverageResponse {
62
64
  userRequestId: string;
63
65
  unsignedBase64Tx: string;
64
66
  }
67
+ export interface GetGroupsResponse {
68
+ groups: GroupAndBanks[];
69
+ }
65
70
  export interface GetGroupResponse {
71
+ group: GroupAndBanks;
72
+ }
73
+ export interface GroupAndBanks {
74
+ group: web3.PublicKey;
66
75
  banks: Bank[];
67
76
  }
68
77
  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-44d9397",
3
+ "version": "0.2.15-group-refactor1-dev-6ecf454",
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,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 banks: Bank[] = [];
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
- banks,
321
+ group,
288
322
  };
289
323
 
290
324
  return response;
@@ -366,6 +400,7 @@ export class Client {
366
400
  */
367
401
  async adjustLeverage(
368
402
  clendGroup: web3.PublicKey,
403
+ clendAccount: web3.PublicKey,
369
404
  assetTokenMint: web3.PublicKey,
370
405
  liabilityTokenMint: web3.PublicKey,
371
406
  leverage: number,
@@ -374,6 +409,7 @@ export class Client {
374
409
  const req: AdjustLeverageRequest = {
375
410
  owner: this.address(),
376
411
  clendGroup,
412
+ clendAccount,
377
413
  assetTokenMint,
378
414
  liabilityTokenMint,
379
415
  leverage,
@@ -400,6 +436,7 @@ export class Client {
400
436
  */
401
437
  async withdrawLeverage(
402
438
  clendGroup: web3.PublicKey,
439
+ clendAccount: web3.PublicKey,
403
440
  outputTokenMint: web3.PublicKey,
404
441
  assetTokenMint: web3.PublicKey,
405
442
  liabilityTokenMint: web3.PublicKey,
@@ -410,6 +447,7 @@ export class Client {
410
447
  const req: WithdrawLeverageRequest = {
411
448
  owner: this.address(),
412
449
  clendGroup,
450
+ clendAccount,
413
451
  outputTokenMint,
414
452
  assetTokenMint,
415
453
  liabilityTokenMint,
package/src/types.ts CHANGED
@@ -35,6 +35,7 @@ export interface DepositLeverageResponse {
35
35
  export interface AdjustLeverageRequest {
36
36
  owner: web3.PublicKey;
37
37
  clendGroup: web3.PublicKey;
38
+ clendAccount: web3.PublicKey;
38
39
  assetTokenMint: web3.PublicKey;
39
40
  liabilityTokenMint: web3.PublicKey;
40
41
  leverage: number;
@@ -55,6 +56,7 @@ export interface AdjustLeverageResponse {
55
56
  export interface WithdrawLeverageRequest {
56
57
  owner: web3.PublicKey;
57
58
  clendGroup: web3.PublicKey;
59
+ clendAccount: web3.PublicKey;
58
60
  outputTokenMint: web3.PublicKey;
59
61
  assetTokenMint: web3.PublicKey;
60
62
  liabilityTokenMint: web3.PublicKey;
@@ -71,7 +73,16 @@ export interface WithdrawLeverageResponse {
71
73
  unsignedBase64Tx: string;
72
74
  }
73
75
 
76
+ export interface GetGroupsResponse {
77
+ groups: GroupAndBanks[];
78
+ }
79
+
74
80
  export interface GetGroupResponse {
81
+ group: GroupAndBanks;
82
+ }
83
+
84
+ export interface GroupAndBanks {
85
+ group: web3.PublicKey;
75
86
  banks: Bank[];
76
87
  }
77
88