@carrot-protocol/boost-http-client 0.3.0-feat-get-account-endpoint-dev-6a0523c → 0.3.1-feat-get-ohlc-endpoint-dev-43df047

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, GetGroupsResponse, GetAccountResponse } from "./types";
2
+ import { GetBankResponse, GetUserResponse, GetGroupResponse, GetGroupsResponse, GetVaultOHLCResponse, GetVaultOHLCRequest } from "./types";
3
3
  export * from "./types";
4
4
  export * from "./utils";
5
5
  export * as Common from "@carrot-protocol/clend-common";
@@ -22,15 +22,6 @@ export declare class Client {
22
22
  * @returns Index details
23
23
  */
24
24
  index(): Promise<any>;
25
- /**
26
- * Fetch and parse a single clend account by pubkey
27
- */
28
- getAccount(account: web3.PublicKey, getClendAccountSummary: boolean): Promise<GetAccountResponse>;
29
- /**
30
- * Helper to parse a clend account summary array from API response
31
- */
32
- private parseClendAccountSummary;
33
- private parseClendAccountWithSummary;
34
25
  getUser(user: web3.PublicKey, groups: web3.PublicKey[], getClendAccountSummary: boolean): Promise<GetUserResponse>;
35
26
  /**
36
27
  * Get all groups
@@ -50,6 +41,12 @@ export declare class Client {
50
41
  * @returns Bank details
51
42
  */
52
43
  getBank(bankAddress: web3.PublicKey): Promise<GetBankResponse>;
44
+ /**
45
+ * Get vault OHLC graph data
46
+ * @param vaultAddress vault public key
47
+ * @returns OHLC graph data
48
+ */
49
+ getVaultOHLC(vaultAddress: GetVaultOHLCRequest["vault"]): Promise<GetVaultOHLCResponse>;
53
50
  /**
54
51
  * Deposit collateral and create a leveraged position
55
52
  * @param request Deposit leverage request parameters
package/dist/index.js CHANGED
@@ -99,120 +99,6 @@ class Client {
99
99
  async index() {
100
100
  return handleApiCall(() => this.http.get(""));
101
101
  }
102
- /**
103
- * Fetch and parse a single clend account by pubkey
104
- */
105
- async getAccount(account, getClendAccountSummary) {
106
- const body = await handleApiCall(() => this.http.get(`/account?account=${account.toString()}&getClendAccountSummary=${getClendAccountSummary}`));
107
- const jsonRawResponse = JSON.parse(body);
108
- return this.parseClendAccountWithSummary(jsonRawResponse, getClendAccountSummary);
109
- }
110
- /**
111
- * Helper to parse a clend account summary array from API response
112
- */
113
- parseClendAccountSummary(summaryArr) {
114
- return summaryArr.map((s) => {
115
- let input = undefined;
116
- if (s.input) {
117
- input = {
118
- apiPath: s.input.apiPath,
119
- selectedTokenMint: s.input.selectedTokenMint
120
- ? new anchor_1.web3.PublicKey(s.input.selectedTokenMint)
121
- : null,
122
- amountUi: s.input.amountUi ? Number(s.input.amountUi) : null,
123
- leverage: s.input.leverage ? Number(s.input.leverage) : null,
124
- slippageBps: s.input.slippageBps ? Number(s.input.slippageBps) : null,
125
- openPosition: s.input.openPosition != null ? Boolean(s.input.openPosition) : null,
126
- closePosition: s.input.closePosition != null
127
- ? Boolean(s.input.closePosition)
128
- : null,
129
- };
130
- }
131
- const events = (s.events || []).map((event) => {
132
- let closeBalance = null;
133
- if (event.closeBalance !== null && event.closeBalance !== undefined) {
134
- closeBalance = Boolean(event.closeBalance);
135
- }
136
- return {
137
- eventIndex: event.eventIndex,
138
- eventName: event.eventName,
139
- bank: event.bank ? new anchor_1.web3.PublicKey(event.bank) : null,
140
- mint: event.mint ? new anchor_1.web3.PublicKey(event.mint) : null,
141
- amount: event.amount ? new anchor_1.BN(event.amount, "hex") : null,
142
- amountUi: event.amountUi ? Number(event.amountUi) : null,
143
- value: event.value ? Number(event.value) : null,
144
- price: event.price ? Number(event.price) : null,
145
- closeBalance,
146
- };
147
- });
148
- const txSummary = {
149
- txSig: s.txSig,
150
- time: s.time,
151
- clendAccount: new anchor_1.web3.PublicKey(s.clendAccount),
152
- clendAccountAuthority: new anchor_1.web3.PublicKey(s.clendAccountAuthority),
153
- clendGroup: new anchor_1.web3.PublicKey(s.clendGroup),
154
- action: s.action,
155
- input,
156
- events,
157
- };
158
- return txSummary;
159
- });
160
- }
161
- parseClendAccountWithSummary(accountData, getClendAccountSummary) {
162
- // A. Parse the main ClendAccount object
163
- const rawClendAccount = accountData.clendAccount;
164
- const clendAccountBalances = (rawClendAccount.balances || []).map((b) => {
165
- const liquidation = b.liquidation
166
- ? {
167
- price: Number(b.liquidation.price),
168
- changePercentage: Number(b.liquidation.changePercentage),
169
- }
170
- : null;
171
- const emissionsOutstandingAndUnclaimed = new anchor_1.BN(b.emissionsOutstandingAndUnclaimed, "hex");
172
- return {
173
- mint: new anchor_1.web3.PublicKey(b.mint),
174
- bank: new anchor_1.web3.PublicKey(b.bank),
175
- tokenYieldApy: Number(b.tokenYieldApy),
176
- assetBalance: new anchor_1.BN(b.assetBalance, "hex"),
177
- assetBalanceUi: Number(b.assetBalanceUi),
178
- assetValue: Number(b.assetValue),
179
- assetEmissionsApy: Number(b.assetEmissionsApy),
180
- liabilityBalance: new anchor_1.BN(b.liabilityBalance, "hex"),
181
- liabilityBalanceUi: Number(b.liabilityBalanceUi),
182
- liabilityValue: Number(b.liabilityValue),
183
- liabilityBorrowCostApy: Number(b.liabilityBorrowCostApy),
184
- liabilityEmissionsApy: Number(b.liabilityEmissionsApy),
185
- emissionsOutstandingAndUnclaimed,
186
- emissionsOutstandingAndUnclaimedUi: Number(b.emissionsOutstandingAndUnclaimedUi),
187
- price: Number(b.price),
188
- liquidation,
189
- };
190
- });
191
- const clendAccount = {
192
- key: new anchor_1.web3.PublicKey(rawClendAccount.key),
193
- group: new anchor_1.web3.PublicKey(rawClendAccount.group),
194
- balances: clendAccountBalances,
195
- netValue: Number(rawClendAccount.netValue),
196
- netApy: Number(rawClendAccount.netApy),
197
- pnl: Number(rawClendAccount.pnl),
198
- totalEmissionsApy: Number(rawClendAccount.totalEmissionsApy),
199
- totalAssetValue: Number(rawClendAccount.totalAssetValue),
200
- totalLiabilityValue: Number(rawClendAccount.totalLiabilityValue),
201
- healthFactorNotional: Number(rawClendAccount.healthFactorNotional),
202
- healthFactorRiskAdjusted: Number(rawClendAccount.healthFactorRiskAdjusted),
203
- notionalLeverage: Number(rawClendAccount.notionalLeverage),
204
- riskAdjustedLeverage: Number(rawClendAccount.riskAdjustedLeverage),
205
- notionalLtv: Number(rawClendAccount.notionalLtv),
206
- riskAdjustedLtv: Number(rawClendAccount.riskAdjustedLtv),
207
- };
208
- // B. Parse the associated Summary array for the account
209
- let summary = [];
210
- if (getClendAccountSummary && accountData.summary) {
211
- summary = this.parseClendAccountSummary(accountData.summary);
212
- }
213
- // C. Combine the parsed account and its summary
214
- return { clendAccount, summary };
215
- }
216
102
  async getUser(user, groups, getClendAccountSummary) {
217
103
  // Make the API call to fetch the raw user data as a string.
218
104
  const body = await handleApiCall(() => this.http.get(`/user?user=${user.toString()}&groups=${groups.map((g) => g.toString()).join(",")}&getClendAccountSummary=${getClendAccountSummary}`));
@@ -231,7 +117,112 @@ class Client {
231
117
  // 2. Parse Clend Accounts and their Summaries
232
118
  // This is the main refactored section. It iterates through the clendAccounts array
233
119
  // from the response, which contains both the account data and its summary.
234
- const clendAccounts = (jsonRawResponse.clendAccounts || []).map((accountData) => this.parseClendAccountWithSummary(accountData, getClendAccountSummary));
120
+ const clendAccounts = (jsonRawResponse.clendAccounts || []).map((accountData) => {
121
+ // A. Parse the main ClendAccount object
122
+ const rawClendAccount = accountData.clendAccount;
123
+ const clendAccountBalances = (rawClendAccount.balances || []).map((b) => {
124
+ const liquidation = b.liquidation
125
+ ? {
126
+ price: Number(b.liquidation.price),
127
+ changePercentage: Number(b.liquidation.changePercentage),
128
+ }
129
+ : null;
130
+ const emissionsOutstandingAndUnclaimed = new anchor_1.BN(b.emissionsOutstandingAndUnclaimed, "hex");
131
+ return {
132
+ mint: new anchor_1.web3.PublicKey(b.mint),
133
+ bank: new anchor_1.web3.PublicKey(b.bank),
134
+ tokenYieldApy: Number(b.tokenYieldApy),
135
+ assetBalance: new anchor_1.BN(b.assetBalance, "hex"),
136
+ assetBalanceUi: Number(b.assetBalanceUi),
137
+ assetValue: Number(b.assetValue),
138
+ assetEmissionsApy: Number(b.assetEmissionsApy),
139
+ liabilityBalance: new anchor_1.BN(b.liabilityBalance, "hex"),
140
+ liabilityBalanceUi: Number(b.liabilityBalanceUi),
141
+ liabilityValue: Number(b.liabilityValue),
142
+ liabilityBorrowCostApy: Number(b.liabilityBorrowCostApy),
143
+ liabilityEmissionsApy: Number(b.liabilityEmissionsApy),
144
+ emissionsOutstandingAndUnclaimed,
145
+ emissionsOutstandingAndUnclaimedUi: Number(b.emissionsOutstandingAndUnclaimedUi),
146
+ price: Number(b.price),
147
+ liquidation,
148
+ };
149
+ });
150
+ const clendAccount = {
151
+ key: new anchor_1.web3.PublicKey(rawClendAccount.key),
152
+ group: new anchor_1.web3.PublicKey(rawClendAccount.group),
153
+ balances: clendAccountBalances,
154
+ netValue: Number(rawClendAccount.netValue),
155
+ netApy: Number(rawClendAccount.netApy),
156
+ pnl: Number(rawClendAccount.pnl),
157
+ totalEmissionsApy: Number(rawClendAccount.totalEmissionsApy),
158
+ totalAssetValue: Number(rawClendAccount.totalAssetValue),
159
+ totalLiabilityValue: Number(rawClendAccount.totalLiabilityValue),
160
+ healthFactorNotional: Number(rawClendAccount.healthFactorNotional),
161
+ healthFactorRiskAdjusted: Number(rawClendAccount.healthFactorRiskAdjusted),
162
+ notionalLeverage: Number(rawClendAccount.notionalLeverage),
163
+ riskAdjustedLeverage: Number(rawClendAccount.riskAdjustedLeverage),
164
+ notionalLtv: Number(rawClendAccount.notionalLtv),
165
+ riskAdjustedLtv: Number(rawClendAccount.riskAdjustedLtv),
166
+ };
167
+ // B. Parse the associated Summary array for the account
168
+ let summary = [];
169
+ if (getClendAccountSummary && accountData.summary) {
170
+ summary = accountData.summary.map((s) => {
171
+ let input = undefined;
172
+ if (s.input) {
173
+ input = {
174
+ apiPath: s.input.apiPath,
175
+ selectedTokenMint: s.input.selectedTokenMint
176
+ ? new anchor_1.web3.PublicKey(s.input.selectedTokenMint)
177
+ : null,
178
+ amountUi: s.input.amountUi ? Number(s.input.amountUi) : null,
179
+ leverage: s.input.leverage ? Number(s.input.leverage) : null,
180
+ slippageBps: s.input.slippageBps
181
+ ? Number(s.input.slippageBps)
182
+ : null,
183
+ openPosition: s.input.openPosition != null
184
+ ? Boolean(s.input.openPosition)
185
+ : null,
186
+ closePosition: s.input.closePosition != null
187
+ ? Boolean(s.input.closePosition)
188
+ : null,
189
+ };
190
+ }
191
+ const events = (s.events || []).map((event) => {
192
+ let closeBalance = null;
193
+ // Only convert to boolean if the value is not null/undefined to preserve the null state.
194
+ if (event.closeBalance !== null &&
195
+ event.closeBalance !== undefined) {
196
+ closeBalance = Boolean(event.closeBalance);
197
+ }
198
+ return {
199
+ eventIndex: event.eventIndex,
200
+ eventName: event.eventName,
201
+ bank: event.bank ? new anchor_1.web3.PublicKey(event.bank) : null,
202
+ mint: event.mint ? new anchor_1.web3.PublicKey(event.mint) : null,
203
+ amount: event.amount ? new anchor_1.BN(event.amount, "hex") : null,
204
+ amountUi: event.amountUi ? Number(event.amountUi) : null,
205
+ value: event.value ? Number(event.value) : null,
206
+ price: event.price ? Number(event.price) : null,
207
+ closeBalance,
208
+ };
209
+ });
210
+ const txSummary = {
211
+ txSig: s.txSig,
212
+ time: s.time,
213
+ clendAccount: new anchor_1.web3.PublicKey(s.clendAccount),
214
+ clendAccountAuthority: new anchor_1.web3.PublicKey(s.clendAccountAuthority),
215
+ clendGroup: new anchor_1.web3.PublicKey(s.clendGroup),
216
+ action: s.action,
217
+ input,
218
+ events,
219
+ };
220
+ return txSummary;
221
+ });
222
+ }
223
+ // C. Combine the parsed account and its summary
224
+ return { clendAccount, summary };
225
+ });
235
226
  // 3. Return the final, correctly structured response object.
236
227
  return {
237
228
  wallet,
@@ -298,6 +289,18 @@ class Client {
298
289
  };
299
290
  return response;
300
291
  }
292
+ /**
293
+ * Get vault OHLC graph data
294
+ * @param vaultAddress vault public key
295
+ * @returns OHLC graph data
296
+ */
297
+ async getVaultOHLC(vaultAddress) {
298
+ const body = await handleApiCall(() => this.http.get(`/vaultOhlc?vault=${vaultAddress.toString()}`));
299
+ const response = {
300
+ data: JSON.parse(body),
301
+ };
302
+ return response;
303
+ }
301
304
  /**
302
305
  * Deposit collateral and create a leveraged position
303
306
  * @param request Deposit leverage request parameters
package/dist/types.d.ts CHANGED
@@ -84,14 +84,6 @@ export interface GroupAndBanks {
84
84
  groupName: string;
85
85
  banks: Bank[];
86
86
  }
87
- export interface GetAccountRequest {
88
- account: web3.PublicKey;
89
- getClendAccountSummary: boolean;
90
- }
91
- export interface GetAccountResponse {
92
- clendAccount: ClendAccount;
93
- summary: ClendAccountTxSummary[];
94
- }
95
87
  export interface GetUserRequest {
96
88
  groups: web3.PublicKey[];
97
89
  user: web3.PublicKey;
@@ -104,6 +96,19 @@ export interface GetUserResponse {
104
96
  summary: ClendAccountTxSummary[];
105
97
  }[];
106
98
  }
99
+ export interface GetVaultOHLCRequest {
100
+ vault: web3.PublicKey;
101
+ }
102
+ export interface VaultOHLCDataPoint {
103
+ time: number;
104
+ open: number;
105
+ high: number;
106
+ low: number;
107
+ close: number;
108
+ }
109
+ export interface GetVaultOHLCResponse {
110
+ data: VaultOHLCDataPoint[];
111
+ }
107
112
  export interface UserWallet {
108
113
  balances: UserBalance[];
109
114
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carrot-protocol/boost-http-client",
3
- "version": "0.3.0-feat-get-account-endpoint-dev-6a0523c",
3
+ "version": "0.3.1-feat-get-ohlc-endpoint-dev-43df047",
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
@@ -27,7 +27,8 @@ import {
27
27
  BankEmissionsMode,
28
28
  WithdrawEmissionsRequest,
29
29
  WithdrawEmissionsResponse,
30
- GetAccountResponse,
30
+ GetVaultOHLCResponse,
31
+ GetVaultOHLCRequest,
31
32
  } from "./types";
32
33
  import encode from "bs58";
33
34
 
@@ -107,155 +108,6 @@ export class Client {
107
108
  return handleApiCall(() => this.http.get(""));
108
109
  }
109
110
 
110
- /**
111
- * Fetch and parse a single clend account by pubkey
112
- */
113
- async getAccount(
114
- account: web3.PublicKey,
115
- getClendAccountSummary: boolean,
116
- ): Promise<GetAccountResponse> {
117
- const body = await handleApiCall(() =>
118
- this.http.get(
119
- `/account?account=${account.toString()}&getClendAccountSummary=${getClendAccountSummary}`,
120
- ),
121
- );
122
- const jsonRawResponse: any = JSON.parse(body);
123
- return this.parseClendAccountWithSummary(
124
- jsonRawResponse,
125
- getClendAccountSummary,
126
- );
127
- }
128
-
129
- /**
130
- * Helper to parse a clend account summary array from API response
131
- */
132
- private parseClendAccountSummary(summaryArr: any[]): ClendAccountTxSummary[] {
133
- return summaryArr.map((s: any) => {
134
- let input: UserRequest | undefined = undefined;
135
- if (s.input) {
136
- input = {
137
- apiPath: s.input.apiPath,
138
- selectedTokenMint: s.input.selectedTokenMint
139
- ? new web3.PublicKey(s.input.selectedTokenMint)
140
- : null,
141
- amountUi: s.input.amountUi ? Number(s.input.amountUi) : null,
142
- leverage: s.input.leverage ? Number(s.input.leverage) : null,
143
- slippageBps: s.input.slippageBps ? Number(s.input.slippageBps) : null,
144
- openPosition:
145
- s.input.openPosition != null ? Boolean(s.input.openPosition) : null,
146
- closePosition:
147
- s.input.closePosition != null
148
- ? Boolean(s.input.closePosition)
149
- : null,
150
- };
151
- }
152
-
153
- const events: ClendAccountEvent[] = (s.events || []).map((event: any) => {
154
- let closeBalance: boolean | null = null;
155
- if (event.closeBalance !== null && event.closeBalance !== undefined) {
156
- closeBalance = Boolean(event.closeBalance);
157
- }
158
-
159
- return {
160
- eventIndex: event.eventIndex,
161
- eventName: event.eventName,
162
- bank: event.bank ? new web3.PublicKey(event.bank) : null,
163
- mint: event.mint ? new web3.PublicKey(event.mint) : null,
164
- amount: event.amount ? new BN(event.amount, "hex") : null,
165
- amountUi: event.amountUi ? Number(event.amountUi) : null,
166
- value: event.value ? Number(event.value) : null,
167
- price: event.price ? Number(event.price) : null,
168
- closeBalance,
169
- };
170
- });
171
-
172
- const txSummary: ClendAccountTxSummary = {
173
- txSig: s.txSig,
174
- time: s.time,
175
- clendAccount: new web3.PublicKey(s.clendAccount),
176
- clendAccountAuthority: new web3.PublicKey(s.clendAccountAuthority),
177
- clendGroup: new web3.PublicKey(s.clendGroup),
178
- action: s.action,
179
- input,
180
- events,
181
- };
182
- return txSummary;
183
- });
184
- }
185
-
186
- private parseClendAccountWithSummary(
187
- accountData: any,
188
- getClendAccountSummary: boolean,
189
- ): GetAccountResponse {
190
- // A. Parse the main ClendAccount object
191
- const rawClendAccount = accountData.clendAccount;
192
- const clendAccountBalances: ClendAccountBalance[] = (
193
- rawClendAccount.balances || []
194
- ).map((b: any) => {
195
- const liquidation: ClendAccountAssetLiquidation | null = b.liquidation
196
- ? {
197
- price: Number(b.liquidation.price),
198
- changePercentage: Number(b.liquidation.changePercentage),
199
- }
200
- : null;
201
-
202
- const emissionsOutstandingAndUnclaimed = new BN(
203
- b.emissionsOutstandingAndUnclaimed,
204
- "hex",
205
- );
206
-
207
- return {
208
- mint: new web3.PublicKey(b.mint),
209
- bank: new web3.PublicKey(b.bank),
210
- tokenYieldApy: Number(b.tokenYieldApy),
211
- assetBalance: new BN(b.assetBalance, "hex"),
212
- assetBalanceUi: Number(b.assetBalanceUi),
213
- assetValue: Number(b.assetValue),
214
- assetEmissionsApy: Number(b.assetEmissionsApy),
215
- liabilityBalance: new BN(b.liabilityBalance, "hex"),
216
- liabilityBalanceUi: Number(b.liabilityBalanceUi),
217
- liabilityValue: Number(b.liabilityValue),
218
- liabilityBorrowCostApy: Number(b.liabilityBorrowCostApy),
219
- liabilityEmissionsApy: Number(b.liabilityEmissionsApy),
220
- emissionsOutstandingAndUnclaimed,
221
- emissionsOutstandingAndUnclaimedUi: Number(
222
- b.emissionsOutstandingAndUnclaimedUi,
223
- ),
224
- price: Number(b.price),
225
- liquidation,
226
- };
227
- });
228
-
229
- const clendAccount: ClendAccount = {
230
- key: new web3.PublicKey(rawClendAccount.key),
231
- group: new web3.PublicKey(rawClendAccount.group),
232
- balances: clendAccountBalances,
233
- netValue: Number(rawClendAccount.netValue),
234
- netApy: Number(rawClendAccount.netApy),
235
- pnl: Number(rawClendAccount.pnl),
236
- totalEmissionsApy: Number(rawClendAccount.totalEmissionsApy),
237
- totalAssetValue: Number(rawClendAccount.totalAssetValue),
238
- totalLiabilityValue: Number(rawClendAccount.totalLiabilityValue),
239
- healthFactorNotional: Number(rawClendAccount.healthFactorNotional),
240
- healthFactorRiskAdjusted: Number(
241
- rawClendAccount.healthFactorRiskAdjusted,
242
- ),
243
- notionalLeverage: Number(rawClendAccount.notionalLeverage),
244
- riskAdjustedLeverage: Number(rawClendAccount.riskAdjustedLeverage),
245
- notionalLtv: Number(rawClendAccount.notionalLtv),
246
- riskAdjustedLtv: Number(rawClendAccount.riskAdjustedLtv),
247
- };
248
-
249
- // B. Parse the associated Summary array for the account
250
- let summary: ClendAccountTxSummary[] = [];
251
- if (getClendAccountSummary && accountData.summary) {
252
- summary = this.parseClendAccountSummary(accountData.summary);
253
- }
254
-
255
- // C. Combine the parsed account and its summary
256
- return { clendAccount, summary };
257
- }
258
-
259
111
  async getUser(
260
112
  user: web3.PublicKey,
261
113
  groups: web3.PublicKey[],
@@ -289,8 +141,137 @@ export class Client {
289
141
  // This is the main refactored section. It iterates through the clendAccounts array
290
142
  // from the response, which contains both the account data and its summary.
291
143
  const clendAccounts = (jsonRawResponse.clendAccounts || []).map(
292
- (accountData: any) =>
293
- this.parseClendAccountWithSummary(accountData, getClendAccountSummary),
144
+ (accountData: any) => {
145
+ // A. Parse the main ClendAccount object
146
+ const rawClendAccount = accountData.clendAccount;
147
+ const clendAccountBalances: ClendAccountBalance[] = (
148
+ rawClendAccount.balances || []
149
+ ).map((b: any) => {
150
+ const liquidation: ClendAccountAssetLiquidation | null = b.liquidation
151
+ ? {
152
+ price: Number(b.liquidation.price),
153
+ changePercentage: Number(b.liquidation.changePercentage),
154
+ }
155
+ : null;
156
+
157
+ const emissionsOutstandingAndUnclaimed = new BN(
158
+ b.emissionsOutstandingAndUnclaimed,
159
+ "hex",
160
+ );
161
+
162
+ return {
163
+ mint: new web3.PublicKey(b.mint),
164
+ bank: new web3.PublicKey(b.bank),
165
+ tokenYieldApy: Number(b.tokenYieldApy),
166
+ assetBalance: new BN(b.assetBalance, "hex"),
167
+ assetBalanceUi: Number(b.assetBalanceUi),
168
+ assetValue: Number(b.assetValue),
169
+ assetEmissionsApy: Number(b.assetEmissionsApy),
170
+ liabilityBalance: new BN(b.liabilityBalance, "hex"),
171
+ liabilityBalanceUi: Number(b.liabilityBalanceUi),
172
+ liabilityValue: Number(b.liabilityValue),
173
+ liabilityBorrowCostApy: Number(b.liabilityBorrowCostApy),
174
+ liabilityEmissionsApy: Number(b.liabilityEmissionsApy),
175
+ emissionsOutstandingAndUnclaimed,
176
+ emissionsOutstandingAndUnclaimedUi: Number(
177
+ b.emissionsOutstandingAndUnclaimedUi,
178
+ ),
179
+ price: Number(b.price),
180
+ liquidation,
181
+ };
182
+ });
183
+
184
+ const clendAccount: ClendAccount = {
185
+ key: new web3.PublicKey(rawClendAccount.key),
186
+ group: new web3.PublicKey(rawClendAccount.group),
187
+ balances: clendAccountBalances,
188
+ netValue: Number(rawClendAccount.netValue),
189
+ netApy: Number(rawClendAccount.netApy),
190
+ pnl: Number(rawClendAccount.pnl),
191
+ totalEmissionsApy: Number(rawClendAccount.totalEmissionsApy),
192
+ totalAssetValue: Number(rawClendAccount.totalAssetValue),
193
+ totalLiabilityValue: Number(rawClendAccount.totalLiabilityValue),
194
+ healthFactorNotional: Number(rawClendAccount.healthFactorNotional),
195
+ healthFactorRiskAdjusted: Number(
196
+ rawClendAccount.healthFactorRiskAdjusted,
197
+ ),
198
+ notionalLeverage: Number(rawClendAccount.notionalLeverage),
199
+ riskAdjustedLeverage: Number(rawClendAccount.riskAdjustedLeverage),
200
+ notionalLtv: Number(rawClendAccount.notionalLtv),
201
+ riskAdjustedLtv: Number(rawClendAccount.riskAdjustedLtv),
202
+ };
203
+
204
+ // B. Parse the associated Summary array for the account
205
+ let summary: ClendAccountTxSummary[] = [];
206
+ if (getClendAccountSummary && accountData.summary) {
207
+ summary = accountData.summary.map((s: any) => {
208
+ let input: UserRequest | undefined = undefined;
209
+ if (s.input) {
210
+ input = {
211
+ apiPath: s.input.apiPath,
212
+ selectedTokenMint: s.input.selectedTokenMint
213
+ ? new web3.PublicKey(s.input.selectedTokenMint)
214
+ : null,
215
+ amountUi: s.input.amountUi ? Number(s.input.amountUi) : null,
216
+ leverage: s.input.leverage ? Number(s.input.leverage) : null,
217
+ slippageBps: s.input.slippageBps
218
+ ? Number(s.input.slippageBps)
219
+ : null,
220
+ openPosition:
221
+ s.input.openPosition != null
222
+ ? Boolean(s.input.openPosition)
223
+ : null,
224
+ closePosition:
225
+ s.input.closePosition != null
226
+ ? Boolean(s.input.closePosition)
227
+ : null,
228
+ };
229
+ }
230
+
231
+ const events: ClendAccountEvent[] = (s.events || []).map(
232
+ (event: any) => {
233
+ let closeBalance: boolean | null = null;
234
+ // Only convert to boolean if the value is not null/undefined to preserve the null state.
235
+ if (
236
+ event.closeBalance !== null &&
237
+ event.closeBalance !== undefined
238
+ ) {
239
+ closeBalance = Boolean(event.closeBalance);
240
+ }
241
+
242
+ return {
243
+ eventIndex: event.eventIndex,
244
+ eventName: event.eventName,
245
+ bank: event.bank ? new web3.PublicKey(event.bank) : null,
246
+ mint: event.mint ? new web3.PublicKey(event.mint) : null,
247
+ amount: event.amount ? new BN(event.amount, "hex") : null,
248
+ amountUi: event.amountUi ? Number(event.amountUi) : null,
249
+ value: event.value ? Number(event.value) : null,
250
+ price: event.price ? Number(event.price) : null,
251
+ closeBalance,
252
+ };
253
+ },
254
+ );
255
+
256
+ const txSummary: ClendAccountTxSummary = {
257
+ txSig: s.txSig,
258
+ time: s.time,
259
+ clendAccount: new web3.PublicKey(s.clendAccount),
260
+ clendAccountAuthority: new web3.PublicKey(
261
+ s.clendAccountAuthority,
262
+ ),
263
+ clendGroup: new web3.PublicKey(s.clendGroup),
264
+ action: s.action,
265
+ input,
266
+ events,
267
+ };
268
+ return txSummary;
269
+ });
270
+ }
271
+
272
+ // C. Combine the parsed account and its summary
273
+ return { clendAccount, summary };
274
+ },
294
275
  );
295
276
 
296
277
  // 3. Return the final, correctly structured response object.
@@ -377,6 +358,25 @@ export class Client {
377
358
  return response;
378
359
  }
379
360
 
361
+ /**
362
+ * Get vault OHLC graph data
363
+ * @param vaultAddress vault public key
364
+ * @returns OHLC graph data
365
+ */
366
+ async getVaultOHLC(
367
+ vaultAddress: GetVaultOHLCRequest["vault"],
368
+ ): Promise<GetVaultOHLCResponse> {
369
+ const body = await handleApiCall(() =>
370
+ this.http.get(`/vaultOhlc?vault=${vaultAddress.toString()}`),
371
+ );
372
+
373
+ const response: GetVaultOHLCResponse = {
374
+ data: JSON.parse(body),
375
+ };
376
+
377
+ return response;
378
+ }
379
+
380
380
  /**
381
381
  * Deposit collateral and create a leveraged position
382
382
  * @param request Deposit leverage request parameters
package/src/types.ts CHANGED
@@ -98,16 +98,6 @@ export interface GroupAndBanks {
98
98
  banks: Bank[];
99
99
  }
100
100
 
101
- export interface GetAccountRequest {
102
- account: web3.PublicKey;
103
- getClendAccountSummary: boolean;
104
- }
105
-
106
- export interface GetAccountResponse {
107
- clendAccount: ClendAccount;
108
- summary: ClendAccountTxSummary[];
109
- }
110
-
111
101
  export interface GetUserRequest {
112
102
  groups: web3.PublicKey[];
113
103
  user: web3.PublicKey;
@@ -122,6 +112,22 @@ export interface GetUserResponse {
122
112
  }[];
123
113
  }
124
114
 
115
+ export interface GetVaultOHLCRequest {
116
+ vault: web3.PublicKey;
117
+ }
118
+
119
+ export interface VaultOHLCDataPoint {
120
+ time: number;
121
+ open: number;
122
+ high: number;
123
+ low: number;
124
+ close: number;
125
+ }
126
+
127
+ export interface GetVaultOHLCResponse {
128
+ data: VaultOHLCDataPoint[];
129
+ }
130
+
125
131
  export interface UserWallet {
126
132
  balances: UserBalance[];
127
133
  }