@carrot-protocol/boost-http-client 0.2.0-mrgn-fork1-dev-958b4f8 → 0.2.0-mrgn-fork1-dev-661dbfd

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 { DepositLeverageRequest, GetBankResponse, GetUserResponse, AdjustLeverageRequest, WithdrawLeverageRequest } from "./types";
2
+ import { DepositLeverageRequest, GetBankResponse, GetUserResponse, AdjustLeverageRequest, WithdrawLeverageRequest, GetGroupResponse } from "./types";
3
3
  export * from "./types";
4
4
  /**
5
5
  * HTTP Client for Carrot Boost API
@@ -26,6 +26,11 @@ export declare class Client {
26
26
  * @returns User details
27
27
  */
28
28
  getUser(user?: web3.PublicKey): Promise<GetUserResponse>;
29
+ /**
30
+ * Get market details
31
+ * @returns Group Details
32
+ */
33
+ getGroup(): Promise<GetGroupResponse>;
29
34
  /**
30
35
  * Get bank details
31
36
  * @param addr token mint or bank public key
package/dist/index.js CHANGED
@@ -106,8 +106,71 @@ class Client {
106
106
  user = this.address();
107
107
  }
108
108
  const body = await handleApiCall(() => this.http.get(`/user?user=${user.toString()}`));
109
- console.log(JSON.stringify(body));
110
- const response = JSON.parse(body);
109
+ const jsonRawResponse = JSON.parse(body);
110
+ // get tokens still in user wallet
111
+ const wallet = {
112
+ usdcBalance: new anchor_1.BN(jsonRawResponse.wallet.usdcBalance, "hex"),
113
+ usdcBalanceUi: Number(jsonRawResponse.wallet.usdcBalanceUi),
114
+ jlpBalance: new anchor_1.BN(jsonRawResponse.wallet.jlpBalance, "hex"),
115
+ jlpBalanceUi: Number(jsonRawResponse.wallet.jlpBalanceUi),
116
+ solBalance: new anchor_1.BN(jsonRawResponse.wallet.solBalance, "hex"),
117
+ solBalanceUi: Number(jsonRawResponse.wallet.solBalanceUi),
118
+ };
119
+ // if no clend account, return undefined for clend
120
+ if (!jsonRawResponse.clendAccount) {
121
+ return {
122
+ wallet,
123
+ clendAccount: undefined,
124
+ };
125
+ }
126
+ // parse lending account balances
127
+ const balances = [];
128
+ for (const b of jsonRawResponse.clendAccount.balances) {
129
+ balances.push({
130
+ mint: new anchor_1.web3.PublicKey(b.mint),
131
+ bank: new anchor_1.web3.PublicKey(b.bank),
132
+ assetBalance: new anchor_1.BN(b.assetBalance, "hex"),
133
+ assetBalanceUi: Number(b.assetBalanceUi),
134
+ assetValue: Number(b.assetValue),
135
+ liabilityBalance: new anchor_1.BN(b.liabilityBalance, "hex"),
136
+ liabilityBalanceUi: Number(b.liabilityBalanceUi),
137
+ liabilityValue: Number(b.liabilityValue),
138
+ price: Number(b.price),
139
+ });
140
+ }
141
+ // create clend account
142
+ const clendAccount = {
143
+ balances,
144
+ netValue: Number(jsonRawResponse.clendAccount.netValue),
145
+ netApy: Number(jsonRawResponse.clendAccount.netApy),
146
+ pnl: Number(jsonRawResponse.clendAccount.pnl),
147
+ totalAssetValue: Number(jsonRawResponse.clendAccount.totalAssetValue),
148
+ totalLiabilityValue: Number(jsonRawResponse.clendAccount.totalLiabilityValue),
149
+ healthFactorNotional: Number(jsonRawResponse.clendAccount.healthFactorNotional),
150
+ healthFactorRiskAdjusted: Number(jsonRawResponse.clendAccount.healthFactorRiskAdjusted),
151
+ notionalLeverage: Number(jsonRawResponse.clendAccount.notionalLeverage),
152
+ riskAdjustedLeverage: Number(jsonRawResponse.clendAccount.riskAdjustedLeverage),
153
+ };
154
+ return {
155
+ wallet,
156
+ clendAccount,
157
+ };
158
+ }
159
+ /**
160
+ * Get market details
161
+ * @returns Group Details
162
+ */
163
+ async getGroup() {
164
+ const body = await handleApiCall(() => this.http.get(`/group`));
165
+ const marketJson = JSON.parse(body);
166
+ const banks = [];
167
+ for (const bankJson of marketJson.banks) {
168
+ const bank = parseBank(bankJson);
169
+ banks.push(bank);
170
+ }
171
+ const response = {
172
+ banks,
173
+ };
111
174
  return response;
112
175
  }
113
176
  /**
@@ -118,7 +181,11 @@ class Client {
118
181
  */
119
182
  async getBank(addr, addrType) {
120
183
  const body = await handleApiCall(() => this.http.get(`/bank?${addrType}=${addr.toString()}`));
121
- const response = JSON.parse(body);
184
+ const bankJson = JSON.parse(body);
185
+ const bank = parseBank(bankJson.bank);
186
+ const response = {
187
+ bank,
188
+ };
122
189
  return response;
123
190
  }
124
191
  /**
@@ -189,3 +256,18 @@ function getDummyProvider() {
189
256
  skipPreflight: true,
190
257
  });
191
258
  }
259
+ function parseBank(bankJson) {
260
+ return {
261
+ mint: new anchor_1.web3.PublicKey(bankJson.mint),
262
+ key: new anchor_1.web3.PublicKey(bankJson.key),
263
+ group: new anchor_1.web3.PublicKey(bankJson.group),
264
+ supplyApy: Number(bankJson.supplyApy),
265
+ borrowApy: Number(bankJson.borrowApy),
266
+ utilizationRate: Number(bankJson.utilizationRate),
267
+ assetAmount: new anchor_1.BN(bankJson.assetAmount, "hex"),
268
+ assetAmountUi: Number(bankJson.assetAmountUi),
269
+ liabilityAmount: new anchor_1.BN(bankJson.liabilityAmount, "hex"),
270
+ liabilityAmountUi: Number(bankJson.liabilityAmountUi),
271
+ price: Number(bankJson.price),
272
+ };
273
+ }
package/dist/types.d.ts CHANGED
@@ -54,15 +54,57 @@ export interface WithdrawLeverageRequest {
54
54
  export interface WithdrawLeverageResponse {
55
55
  unsignedBase64Tx: string;
56
56
  }
57
+ export interface GetGroupResponse {
58
+ banks: Bank[];
59
+ }
57
60
  export interface GetUserResponse {
61
+ wallet: UserWallet;
62
+ clendAccount: ClendAccount | undefined;
63
+ }
64
+ export interface UserWallet {
58
65
  usdcBalance: BN;
59
66
  usdcBalanceUi: number;
60
67
  jlpBalance: BN;
61
68
  jlpBalanceUi: number;
62
69
  solBalance: BN;
63
70
  solBalanceUi: number;
64
- clendAccount: any | undefined;
71
+ }
72
+ export interface ClendAccount {
73
+ balances: Balance[];
74
+ netValue: number;
75
+ netApy: number;
76
+ pnl: number;
77
+ totalAssetValue: number;
78
+ totalLiabilityValue: number;
79
+ healthFactorNotional: number;
80
+ healthFactorRiskAdjusted: number;
81
+ notionalLeverage: number;
82
+ riskAdjustedLeverage: number;
83
+ }
84
+ export interface Balance {
85
+ mint: web3.PublicKey;
86
+ bank: web3.PublicKey;
87
+ assetBalance: BN;
88
+ assetBalanceUi: number;
89
+ assetValue: number;
90
+ liabilityBalance: BN;
91
+ liabilityBalanceUi: number;
92
+ liabilityValue: number;
93
+ price: number;
65
94
  }
66
95
  export interface GetBankResponse {
67
- data: any;
96
+ bank: Bank;
97
+ }
98
+ export interface Bank {
99
+ group: web3.PublicKey;
100
+ key: web3.PublicKey;
101
+ mint: web3.PublicKey;
102
+ supplyApy: number;
103
+ borrowApy: number;
104
+ utilizationRate: number;
105
+ assetAmount: BN;
106
+ assetAmountUi: number;
107
+ liabilityAmount: BN;
108
+ liabilityAmountUi: number;
109
+ price: number;
68
110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carrot-protocol/boost-http-client",
3
- "version": "0.2.0-mrgn-fork1-dev-958b4f8",
3
+ "version": "0.2.0-mrgn-fork1-dev-661dbfd",
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
@@ -1,5 +1,5 @@
1
1
  import axios, { AxiosInstance, AxiosError, AxiosResponse } from "axios";
2
- import { AnchorProvider, Wallet, web3 } from "@coral-xyz/anchor";
2
+ import { AnchorProvider, BN, Wallet, web3 } from "@coral-xyz/anchor";
3
3
  import {
4
4
  DepositLeverageRequest,
5
5
  DepositLeverageResponse,
@@ -10,6 +10,11 @@ import {
10
10
  SendRequest,
11
11
  WithdrawLeverageRequest,
12
12
  WithdrawLeverageResponse,
13
+ UserWallet,
14
+ ClendAccount,
15
+ Balance,
16
+ Bank,
17
+ GetGroupResponse,
13
18
  } from "./types";
14
19
  import encode from "bs58";
15
20
 
@@ -95,9 +100,88 @@ export class Client {
95
100
  const body = await handleApiCall(() =>
96
101
  this.http.get(`/user?user=${user.toString()}`),
97
102
  );
98
- console.log(JSON.stringify(body));
99
103
 
100
- const response: GetUserResponse = JSON.parse(body);
104
+ const jsonRawResponse: any = JSON.parse(body);
105
+
106
+ // get tokens still in user wallet
107
+ const wallet: UserWallet = {
108
+ usdcBalance: new BN(jsonRawResponse.wallet.usdcBalance, "hex"),
109
+ usdcBalanceUi: Number(jsonRawResponse.wallet.usdcBalanceUi),
110
+ jlpBalance: new BN(jsonRawResponse.wallet.jlpBalance, "hex"),
111
+ jlpBalanceUi: Number(jsonRawResponse.wallet.jlpBalanceUi),
112
+ solBalance: new BN(jsonRawResponse.wallet.solBalance, "hex"),
113
+ solBalanceUi: Number(jsonRawResponse.wallet.solBalanceUi),
114
+ };
115
+
116
+ // if no clend account, return undefined for clend
117
+ if (!jsonRawResponse.clendAccount) {
118
+ return {
119
+ wallet,
120
+ clendAccount: undefined,
121
+ };
122
+ }
123
+
124
+ // parse lending account balances
125
+ const balances: Balance[] = [];
126
+ for (const b of jsonRawResponse.clendAccount.balances) {
127
+ balances.push({
128
+ mint: new web3.PublicKey(b.mint),
129
+ bank: new web3.PublicKey(b.bank),
130
+ assetBalance: new BN(b.assetBalance, "hex"),
131
+ assetBalanceUi: Number(b.assetBalanceUi),
132
+ assetValue: Number(b.assetValue),
133
+ liabilityBalance: new BN(b.liabilityBalance, "hex"),
134
+ liabilityBalanceUi: Number(b.liabilityBalanceUi),
135
+ liabilityValue: Number(b.liabilityValue),
136
+ price: Number(b.price),
137
+ });
138
+ }
139
+
140
+ // create clend account
141
+ const clendAccount: ClendAccount = {
142
+ balances,
143
+ netValue: Number(jsonRawResponse.clendAccount.netValue),
144
+ netApy: Number(jsonRawResponse.clendAccount.netApy),
145
+ pnl: Number(jsonRawResponse.clendAccount.pnl),
146
+ totalAssetValue: Number(jsonRawResponse.clendAccount.totalAssetValue),
147
+ totalLiabilityValue: Number(
148
+ jsonRawResponse.clendAccount.totalLiabilityValue,
149
+ ),
150
+ healthFactorNotional: Number(
151
+ jsonRawResponse.clendAccount.healthFactorNotional,
152
+ ),
153
+ healthFactorRiskAdjusted: Number(
154
+ jsonRawResponse.clendAccount.healthFactorRiskAdjusted,
155
+ ),
156
+ notionalLeverage: Number(jsonRawResponse.clendAccount.notionalLeverage),
157
+ riskAdjustedLeverage: Number(
158
+ jsonRawResponse.clendAccount.riskAdjustedLeverage,
159
+ ),
160
+ };
161
+
162
+ return {
163
+ wallet,
164
+ clendAccount,
165
+ };
166
+ }
167
+
168
+ /**
169
+ * Get market details
170
+ * @returns Group Details
171
+ */
172
+ async getGroup(): Promise<GetGroupResponse> {
173
+ const body = await handleApiCall(() => this.http.get(`/group`));
174
+
175
+ const marketJson: any = JSON.parse(body);
176
+ const banks: Bank[] = [];
177
+ for (const bankJson of marketJson.banks) {
178
+ const bank = parseBank(bankJson);
179
+ banks.push(bank);
180
+ }
181
+
182
+ const response: GetGroupResponse = {
183
+ banks,
184
+ };
101
185
 
102
186
  return response;
103
187
  }
@@ -116,7 +200,12 @@ export class Client {
116
200
  this.http.get(`/bank?${addrType}=${addr.toString()}`),
117
201
  );
118
202
 
119
- const response: GetBankResponse = JSON.parse(body);
203
+ const bankJson: any = JSON.parse(body);
204
+ const bank = parseBank(bankJson.bank);
205
+
206
+ const response: GetBankResponse = {
207
+ bank,
208
+ };
120
209
 
121
210
  return response;
122
211
  }
@@ -213,3 +302,19 @@ function getDummyProvider(): AnchorProvider {
213
302
  },
214
303
  );
215
304
  }
305
+
306
+ function parseBank(bankJson: any): Bank {
307
+ return {
308
+ mint: new web3.PublicKey(bankJson.mint),
309
+ key: new web3.PublicKey(bankJson.key),
310
+ group: new web3.PublicKey(bankJson.group),
311
+ supplyApy: Number(bankJson.supplyApy),
312
+ borrowApy: Number(bankJson.borrowApy),
313
+ utilizationRate: Number(bankJson.utilizationRate),
314
+ assetAmount: new BN(bankJson.assetAmount, "hex"),
315
+ assetAmountUi: Number(bankJson.assetAmountUi),
316
+ liabilityAmount: new BN(bankJson.liabilityAmount, "hex"),
317
+ liabilityAmountUi: Number(bankJson.liabilityAmountUi),
318
+ price: Number(bankJson.price),
319
+ };
320
+ }
package/src/types.ts CHANGED
@@ -66,16 +66,63 @@ export interface WithdrawLeverageResponse {
66
66
  unsignedBase64Tx: string;
67
67
  }
68
68
 
69
+ export interface GetGroupResponse {
70
+ banks: Bank[];
71
+ }
72
+
69
73
  export interface GetUserResponse {
74
+ wallet: UserWallet;
75
+ clendAccount: ClendAccount | undefined;
76
+ }
77
+
78
+ export interface UserWallet {
70
79
  usdcBalance: BN;
71
80
  usdcBalanceUi: number;
72
81
  jlpBalance: BN;
73
82
  jlpBalanceUi: number;
74
83
  solBalance: BN;
75
84
  solBalanceUi: number;
76
- clendAccount: any | undefined;
85
+ }
86
+
87
+ export interface ClendAccount {
88
+ balances: Balance[];
89
+ netValue: number;
90
+ netApy: number;
91
+ pnl: number;
92
+ totalAssetValue: number;
93
+ totalLiabilityValue: number;
94
+ healthFactorNotional: number;
95
+ healthFactorRiskAdjusted: number;
96
+ notionalLeverage: number;
97
+ riskAdjustedLeverage: number;
98
+ }
99
+
100
+ export interface Balance {
101
+ mint: web3.PublicKey;
102
+ bank: web3.PublicKey;
103
+ assetBalance: BN;
104
+ assetBalanceUi: number;
105
+ assetValue: number;
106
+ liabilityBalance: BN;
107
+ liabilityBalanceUi: number;
108
+ liabilityValue: number;
109
+ price: number;
77
110
  }
78
111
 
79
112
  export interface GetBankResponse {
80
- data: any;
113
+ bank: Bank;
114
+ }
115
+
116
+ export interface Bank {
117
+ group: web3.PublicKey;
118
+ key: web3.PublicKey;
119
+ mint: web3.PublicKey;
120
+ supplyApy: number;
121
+ borrowApy: number;
122
+ utilizationRate: number;
123
+ assetAmount: BN;
124
+ assetAmountUi: number;
125
+ liabilityAmount: BN;
126
+ liabilityAmountUi: number;
127
+ price: number;
81
128
  }