@carrot-protocol/boost-http-client 0.2.3-withdraw-jlp-dev-e591dae → 0.2.3-withdraw-jlp-dev-6a31381

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, GetUserRequest } from "./types";
3
3
  export * from "./types";
4
4
  export * from "./utils";
5
5
  /**
@@ -26,7 +26,7 @@ export declare class Client {
26
26
  * @param user wallet public key
27
27
  * @returns User details
28
28
  */
29
- getUser(user?: web3.PublicKey): Promise<GetUserResponse>;
29
+ getUser(request: GetUserRequest): Promise<GetUserResponse>;
30
30
  /**
31
31
  * Get market details
32
32
  * @returns Group Details
package/dist/index.js CHANGED
@@ -21,6 +21,7 @@ exports.Client = void 0;
21
21
  const axios_1 = __importDefault(require("axios"));
22
22
  const anchor_1 = require("@coral-xyz/anchor");
23
23
  const bs58_1 = __importDefault(require("bs58"));
24
+ const utils_1 = require("./utils");
24
25
  // Re-export types
25
26
  __exportStar(require("./types"), exports);
26
27
  __exportStar(require("./utils"), exports);
@@ -79,12 +80,13 @@ class Client {
79
80
  * @param user wallet public key
80
81
  * @returns User details
81
82
  */
82
- async getUser(user) {
83
+ async getUser(request) {
83
84
  // use loaded wallet if not provided
85
+ let user = request.user;
84
86
  if (!user) {
85
87
  user = this.address();
86
88
  }
87
- const body = await handleApiCall(() => this.http.get(`/user?user=${user.toString()}`));
89
+ const body = await handleApiCall(() => this.http.get(`/user?user=${user.toString()}&getClendEvents=${request.getClendEvents}`));
88
90
  const jsonRawResponse = JSON.parse(body);
89
91
  // get tokens still in user wallet
90
92
  const wallet = {
@@ -140,6 +142,9 @@ class Client {
140
142
  if (event.closeBalance !== null) {
141
143
  closeBalance = Boolean(event.closeBalance);
142
144
  }
145
+ // parse amount
146
+ const amount = event.amount ? new anchor_1.BN(event.amount, "hex") : null;
147
+ const amountUi = amount !== null ? (0, utils_1.amountToUi)(amount, 6) : null;
143
148
  const clendAccountEvent = {
144
149
  txSig: event.txSig,
145
150
  eventIndex: event.eventIndex,
@@ -151,7 +156,8 @@ class Client {
151
156
  clendGroup: new anchor_1.web3.PublicKey(event.clendGroup),
152
157
  bank: event.bank ? new anchor_1.web3.PublicKey(event.bank) : null,
153
158
  mint: event.mint ? new anchor_1.web3.PublicKey(event.mint) : null,
154
- amount: event.amount ? new anchor_1.BN(event.amount, "hex") : null,
159
+ amount,
160
+ amountUi,
155
161
  closeBalance,
156
162
  };
157
163
  events.push(clendAccountEvent);
package/dist/types.d.ts CHANGED
@@ -51,6 +51,10 @@ export interface WithdrawLeverageResponse {
51
51
  export interface GetGroupResponse {
52
52
  banks: Bank[];
53
53
  }
54
+ export interface GetUserRequest {
55
+ user?: web3.PublicKey;
56
+ getClendEvents?: boolean;
57
+ }
54
58
  export interface GetUserResponse {
55
59
  wallet: UserWallet;
56
60
  clendAccount: ClendAccount | undefined;
@@ -121,5 +125,6 @@ export interface ClendAccountEvent {
121
125
  bank: web3.PublicKey | null;
122
126
  mint: web3.PublicKey | null;
123
127
  amount: BN | null;
128
+ amountUi: number | null;
124
129
  closeBalance: boolean | null;
125
130
  }
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- import { web3 } from "@coral-xyz/anchor";
1
+ import { BN, web3 } from "@coral-xyz/anchor";
2
2
  import { ClendAccount } from "./types";
3
+ export declare function amountToUi(amount: BN | number, decimals: number): number;
3
4
  export declare function netValueInToken(clendAccount: ClendAccount, tokenMint: web3.PublicKey): number;
package/dist/utils.js CHANGED
@@ -1,6 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.amountToUi = amountToUi;
3
4
  exports.netValueInToken = netValueInToken;
5
+ const anchor_1 = require("@coral-xyz/anchor");
6
+ function amountToUi(amount, decimals) {
7
+ if (amount instanceof anchor_1.BN) {
8
+ return Number(amount.toNumber() / 10 ** decimals);
9
+ }
10
+ else {
11
+ return Number(amount / 10 ** decimals);
12
+ }
13
+ }
4
14
  // returns the net value of the clend account in a given tokens price
5
15
  function netValueInToken(clendAccount, tokenMint) {
6
16
  const clendAccountTokenBalance = clendAccount.balances.find((balance) => balance.mint.equals(tokenMint));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carrot-protocol/boost-http-client",
3
- "version": "0.2.3-withdraw-jlp-dev-e591dae",
3
+ "version": "0.2.3-withdraw-jlp-dev-6a31381",
4
4
  "description": "HTTP client for Carrot Boost API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -16,8 +16,10 @@ import {
16
16
  Bank,
17
17
  GetGroupResponse,
18
18
  ClendAccountEvent,
19
+ GetUserRequest,
19
20
  } from "./types";
20
21
  import encode from "bs58";
22
+ import { amountToUi } from "./utils";
21
23
 
22
24
  // Re-export types
23
25
  export * from "./types";
@@ -93,14 +95,17 @@ export class Client {
93
95
  * @param user wallet public key
94
96
  * @returns User details
95
97
  */
96
- async getUser(user?: web3.PublicKey): Promise<GetUserResponse> {
98
+ async getUser(request: GetUserRequest): Promise<GetUserResponse> {
97
99
  // use loaded wallet if not provided
100
+ let user = request.user;
98
101
  if (!user) {
99
102
  user = this.address();
100
103
  }
101
104
 
102
105
  const body = await handleApiCall(() =>
103
- this.http.get(`/user?user=${user.toString()}`),
106
+ this.http.get(
107
+ `/user?user=${user.toString()}&getClendEvents=${request.getClendEvents}`,
108
+ ),
104
109
  );
105
110
 
106
111
  const jsonRawResponse: any = JSON.parse(body);
@@ -172,6 +177,10 @@ export class Client {
172
177
  closeBalance = Boolean(event.closeBalance);
173
178
  }
174
179
 
180
+ // parse amount
181
+ const amount = event.amount ? new BN(event.amount, "hex") : null;
182
+ const amountUi = amount !== null ? amountToUi(amount, 6) : null;
183
+
175
184
  const clendAccountEvent: ClendAccountEvent = {
176
185
  txSig: event.txSig,
177
186
  eventIndex: event.eventIndex,
@@ -183,7 +192,8 @@ export class Client {
183
192
  clendGroup: new web3.PublicKey(event.clendGroup),
184
193
  bank: event.bank ? new web3.PublicKey(event.bank) : null,
185
194
  mint: event.mint ? new web3.PublicKey(event.mint) : null,
186
- amount: event.amount ? new BN(event.amount, "hex") : null,
195
+ amount,
196
+ amountUi,
187
197
  closeBalance,
188
198
  };
189
199
  events.push(clendAccountEvent);
package/src/types.ts CHANGED
@@ -62,6 +62,11 @@ export interface GetGroupResponse {
62
62
  banks: Bank[];
63
63
  }
64
64
 
65
+ export interface GetUserRequest {
66
+ user?: web3.PublicKey;
67
+ getClendEvents?: boolean;
68
+ }
69
+
65
70
  export interface GetUserResponse {
66
71
  wallet: UserWallet;
67
72
  clendAccount: ClendAccount | undefined;
@@ -138,5 +143,6 @@ export interface ClendAccountEvent {
138
143
  bank: web3.PublicKey | null;
139
144
  mint: web3.PublicKey | null;
140
145
  amount: BN | null;
146
+ amountUi: number | null;
141
147
  closeBalance: boolean | null;
142
148
  }
package/src/utils.ts CHANGED
@@ -1,6 +1,14 @@
1
- import { web3 } from "@coral-xyz/anchor";
1
+ import { BN, web3 } from "@coral-xyz/anchor";
2
2
  import { ClendAccount } from "./types";
3
3
 
4
+ export function amountToUi(amount: BN | number, decimals: number): number {
5
+ if (amount instanceof BN) {
6
+ return Number(amount.toNumber() / 10 ** decimals);
7
+ } else {
8
+ return Number(amount / 10 ** decimals);
9
+ }
10
+ }
11
+
4
12
  // returns the net value of the clend account in a given tokens price
5
13
  export function netValueInToken(
6
14
  clendAccount: ClendAccount,