@carrot-protocol/boost-http-client 0.2.15-group-refactor1-dev-94d77e6 → 0.2.15-group-refactor1-dev-fcc481c

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 } from "./types";
2
+ import { GetBankResponse, GetGroupResponse, GetGroupsResponse } from "./types";
3
3
  export * from "./types";
4
4
  export * from "./utils";
5
5
  export * as Common from "@carrot-protocol/clend-common";
@@ -22,12 +22,7 @@ export declare class Client {
22
22
  * @returns Index details
23
23
  */
24
24
  index(): Promise<any>;
25
- /**
26
- * Get user details for a wallet
27
- * @param user wallet public key
28
- * @returns User details
29
- */
30
- getUser(groups: web3.PublicKey[], user: web3.PublicKey, getClendAccountSummary: boolean): Promise<GetUserResponse>;
25
+ getUser(user: web3.PublicKey, groups: web3.PublicKey[], getClendAccountSummary: boolean): Promise<any>;
31
26
  /**
32
27
  * Get all groups
33
28
  * @param includeBankData Whether to include bank data in the response, if not strictly necessary keep false
package/dist/index.js CHANGED
@@ -99,142 +99,125 @@ class Client {
99
99
  async index() {
100
100
  return handleApiCall(() => this.http.get(""));
101
101
  }
102
- /**
103
- * Get user details for a wallet
104
- * @param user wallet public key
105
- * @returns User details
106
- */
107
- async getUser(groups, user, getClendAccountSummary) {
102
+ async getUser(user, groups, getClendAccountSummary) {
103
+ // Make the API call to fetch the raw user data as a string.
108
104
  const body = await handleApiCall(() => this.http.get(`/user?user=${user.toString()}&groups=${groups.map((g) => g.toString()).join(",")}&getClendAccountSummary=${getClendAccountSummary}`));
105
+ // Parse the raw string body into a JSON object.
109
106
  const jsonRawResponse = JSON.parse(body);
110
- // parse balances
111
- const walletBalances = [];
112
- for (const b of jsonRawResponse.wallet.balances) {
113
- walletBalances.push({
114
- mint: new anchor_1.web3.PublicKey(b.mint),
115
- balance: new anchor_1.BN(b.balance, "hex"),
116
- balanceUi: Number(b.balanceUi),
117
- });
118
- }
119
- // get tokens still in user wallet
107
+ // 1. Parse Wallet Balances
108
+ // This section correctly iterates through the wallet balances and creates typed objects.
109
+ const walletBalances = (jsonRawResponse.wallet.balances || []).map((b) => ({
110
+ mint: new anchor_1.web3.PublicKey(b.mint),
111
+ balance: new anchor_1.BN(b.balance, "hex"),
112
+ balanceUi: Number(b.balanceUi),
113
+ }));
120
114
  const wallet = {
121
115
  balances: walletBalances,
122
116
  };
123
- // get tx summary for each account and group them
124
- const summaryByAccount = new Map();
125
- if (getClendAccountSummary && jsonRawResponse.summary) {
126
- for (const s of jsonRawResponse.summary) {
127
- const accountAddress = new anchor_1.web3.PublicKey(s.clendAccount).toBase58();
128
- if (!summaryByAccount.has(accountAddress)) {
129
- summaryByAccount.set(accountAddress, []);
130
- }
131
- const txSummary = {
132
- txSig: s.txSig,
133
- time: s.time,
134
- clendAccount: new anchor_1.web3.PublicKey(s.clendAccount),
135
- clendAccountAuthority: new anchor_1.web3.PublicKey(s.clendAccountAuthority),
136
- clendGroup: new anchor_1.web3.PublicKey(s.clendGroup),
137
- action: s.action,
138
- input: undefined,
139
- events: [],
140
- };
141
- // parse inputs if they exist
142
- if (s.input) {
143
- const input = {
144
- apiPath: s.input.apiPath,
145
- selectedTokenMint: s.input.selectedTokenMint
146
- ? new anchor_1.web3.PublicKey(s.input.selectedTokenMint)
147
- : null,
148
- amountUi: s.input.amountUi ? Number(s.input.amountUi) : null,
149
- leverage: s.input.leverage ? Number(s.input.leverage) : null,
150
- slippageBps: s.input.slippageBps
151
- ? Number(s.input.slippageBps)
152
- : null,
153
- openPosition: s.input.openPosition
154
- ? Boolean(s.input.openPosition)
155
- : null,
156
- closePosition: s.input.closePosition
157
- ? Boolean(s.input.closePosition)
158
- : null,
159
- };
160
- txSummary.input = input;
161
- }
162
- // get events for each summary
163
- for (const event of s.events) {
164
- let closeBalance = null;
165
- if (event.closeBalance !== null) {
166
- closeBalance = Boolean(event.closeBalance);
167
- }
168
- // parse amount
169
- const clendAccountEvent = {
170
- eventIndex: event.eventIndex,
171
- eventName: event.eventName,
172
- bank: event.bank ? new anchor_1.web3.PublicKey(event.bank) : null,
173
- mint: event.mint ? new anchor_1.web3.PublicKey(event.mint) : null,
174
- amount: event.amount ? new anchor_1.BN(event.amount, "hex") : null,
175
- amountUi: event.amountUi ? Number(event.amountUi) : null,
176
- value: event.value ? Number(event.value) : null,
177
- price: event.price ? Number(event.price) : null,
178
- closeBalance,
179
- };
180
- txSummary.events.push(clendAccountEvent);
181
- }
182
- summaryByAccount.get(accountAddress).push(txSummary);
183
- }
184
- }
185
- // if no clend accounts, return empty array
186
- const clendAccounts = [];
187
- for (const accountAndSumary of jsonRawResponse.clendAccounts) {
188
- const clendAccountBalances = [];
189
- const ca = accountAndSumary.clendAccount;
190
- for (const b of ca.balances) {
191
- // parse liquidation data if exists
117
+ // 2. Parse Clend Accounts and their Summaries
118
+ // This is the main refactored section. It iterates through the clendAccounts array
119
+ // from the response, which contains both the account data and its summary.
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) => {
192
124
  const liquidation = b.liquidation
193
125
  ? {
194
126
  price: Number(b.liquidation.price),
195
127
  changePercentage: Number(b.liquidation.changePercentage),
196
128
  }
197
129
  : null;
198
- // create clend account balance
199
- clendAccountBalances.push({
130
+ return {
200
131
  mint: new anchor_1.web3.PublicKey(b.mint),
201
132
  bank: new anchor_1.web3.PublicKey(b.bank),
202
133
  assetBalance: new anchor_1.BN(b.assetBalance, "hex"),
203
134
  assetBalanceUi: Number(b.assetBalanceUi),
204
135
  assetValue: Number(b.assetValue),
205
- assetYieldBps: Number(b.assetYieldBps),
206
136
  assetYieldApy: Number(b.assetYieldApy),
207
137
  liabilityBalance: new anchor_1.BN(b.liabilityBalance, "hex"),
208
138
  liabilityBalanceUi: Number(b.liabilityBalanceUi),
209
139
  liabilityValue: Number(b.liabilityValue),
210
- liabilityBorrowCostBps: Number(b.liabilityBorrowCostBps),
211
140
  liabilityBorrowCostApy: Number(b.liabilityBorrowCostApy),
212
141
  price: Number(b.price),
213
142
  liquidation,
214
- });
215
- }
216
- // create clend account
217
- const clendAccountAddress = new anchor_1.web3.PublicKey(accountAndSumary.clendAccount.key);
143
+ };
144
+ });
218
145
  const clendAccount = {
219
- key: clendAccountAddress,
220
- group: new anchor_1.web3.PublicKey(ca.group),
146
+ key: new anchor_1.web3.PublicKey(rawClendAccount.key),
147
+ group: new anchor_1.web3.PublicKey(rawClendAccount.group),
221
148
  balances: clendAccountBalances,
222
- netValue: Number(ca.netValue),
223
- netApy: Number(ca.netApy),
224
- pnl: Number(ca.pnl),
225
- totalAssetValue: Number(ca.totalAssetValue),
226
- totalLiabilityValue: Number(ca.totalLiabilityValue),
227
- healthFactorNotional: Number(ca.healthFactorNotional),
228
- healthFactorRiskAdjusted: Number(ca.healthFactorRiskAdjusted),
229
- notionalLeverage: Number(ca.notionalLeverage),
230
- riskAdjustedLeverage: Number(ca.riskAdjustedLeverage),
231
- notionalLtv: Number(ca.notionalLtv),
232
- riskAdjustedLtv: Number(ca.riskAdjustedLtv),
149
+ netValue: Number(rawClendAccount.netValue),
150
+ netApy: Number(rawClendAccount.netApy),
151
+ pnl: Number(rawClendAccount.pnl),
152
+ totalAssetValue: Number(rawClendAccount.totalAssetValue),
153
+ totalLiabilityValue: Number(rawClendAccount.totalLiabilityValue),
154
+ healthFactorNotional: Number(rawClendAccount.healthFactorNotional),
155
+ healthFactorRiskAdjusted: Number(rawClendAccount.healthFactorRiskAdjusted),
156
+ notionalLeverage: Number(rawClendAccount.notionalLeverage),
157
+ riskAdjustedLeverage: Number(rawClendAccount.riskAdjustedLeverage),
158
+ notionalLtv: Number(rawClendAccount.notionalLtv),
159
+ riskAdjustedLtv: Number(rawClendAccount.riskAdjustedLtv),
233
160
  };
234
- // find corresponding tx summary for account
235
- const summary = summaryByAccount.get(clendAccountAddress.toString()) || [];
236
- clendAccounts.push({ clendAccount, summary });
237
- }
161
+ // B. Parse the associated Summary array for the account
162
+ let summary = [];
163
+ if (getClendAccountSummary && accountData.summary) {
164
+ summary = accountData.summary.map((s) => {
165
+ let input = undefined;
166
+ if (s.input) {
167
+ input = {
168
+ apiPath: s.input.apiPath,
169
+ selectedTokenMint: s.input.selectedTokenMint
170
+ ? new anchor_1.web3.PublicKey(s.input.selectedTokenMint)
171
+ : null,
172
+ amountUi: s.input.amountUi ? Number(s.input.amountUi) : null,
173
+ leverage: s.input.leverage ? Number(s.input.leverage) : null,
174
+ slippageBps: s.input.slippageBps
175
+ ? Number(s.input.slippageBps)
176
+ : null,
177
+ openPosition: s.input.openPosition != null
178
+ ? Boolean(s.input.openPosition)
179
+ : null,
180
+ closePosition: s.input.closePosition != null
181
+ ? Boolean(s.input.closePosition)
182
+ : null,
183
+ };
184
+ }
185
+ const events = (s.events || []).map((event) => {
186
+ let closeBalance = null;
187
+ // Only convert to boolean if the value is not null/undefined to preserve the null state.
188
+ if (event.closeBalance !== null &&
189
+ event.closeBalance !== undefined) {
190
+ closeBalance = Boolean(event.closeBalance);
191
+ }
192
+ return {
193
+ eventIndex: event.eventIndex,
194
+ eventName: event.eventName,
195
+ bank: event.bank ? new anchor_1.web3.PublicKey(event.bank) : null,
196
+ mint: event.mint ? new anchor_1.web3.PublicKey(event.mint) : null,
197
+ amount: event.amount ? new anchor_1.BN(event.amount, "hex") : null,
198
+ amountUi: event.amountUi ? Number(event.amountUi) : null,
199
+ value: event.value ? Number(event.value) : null,
200
+ price: event.price ? Number(event.price) : null,
201
+ closeBalance,
202
+ };
203
+ });
204
+ const txSummary = {
205
+ txSig: s.txSig,
206
+ time: s.time,
207
+ clendAccount: new anchor_1.web3.PublicKey(s.clendAccount),
208
+ clendAccountAuthority: new anchor_1.web3.PublicKey(s.clendAccountAuthority),
209
+ clendGroup: new anchor_1.web3.PublicKey(s.clendGroup),
210
+ action: s.action,
211
+ input,
212
+ events,
213
+ };
214
+ return txSummary;
215
+ });
216
+ }
217
+ // C. Combine the parsed account and its summary
218
+ return { clendAccount, summary };
219
+ });
220
+ // 3. Return the final, correctly structured response object.
238
221
  return {
239
222
  wallet,
240
223
  clendAccounts,
package/dist/types.d.ts CHANGED
@@ -117,12 +117,10 @@ export interface ClendAccountBalance {
117
117
  assetBalance: BN;
118
118
  assetBalanceUi: number;
119
119
  assetValue: number;
120
- assetYieldBps: number;
121
120
  assetYieldApy: number;
122
121
  liabilityBalance: BN;
123
122
  liabilityBalanceUi: number;
124
123
  liabilityValue: number;
125
- liabilityBorrowCostBps: number;
126
124
  liabilityBorrowCostApy: number;
127
125
  price: number;
128
126
  liquidation: ClendAccountAssetLiquidation | null;
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-94d77e6",
3
+ "version": "0.2.15-group-refactor1-dev-fcc481c",
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
@@ -102,176 +102,166 @@ export class Client {
102
102
  return handleApiCall(() => this.http.get(""));
103
103
  }
104
104
 
105
- /**
106
- * Get user details for a wallet
107
- * @param user wallet public key
108
- * @returns User details
109
- */
110
105
  async getUser(
111
- groups: web3.PublicKey[],
112
106
  user: web3.PublicKey,
107
+ groups: web3.PublicKey[],
113
108
  getClendAccountSummary: boolean,
114
- ): Promise<GetUserResponse> {
109
+ ): Promise<any> {
110
+ // Make the API call to fetch the raw user data as a string.
115
111
  const body = await handleApiCall(() =>
116
112
  this.http.get(
117
113
  `/user?user=${user.toString()}&groups=${groups.map((g) => g.toString()).join(",")}&getClendAccountSummary=${getClendAccountSummary}`,
118
114
  ),
119
115
  );
120
116
 
117
+ // Parse the raw string body into a JSON object.
121
118
  const jsonRawResponse: any = JSON.parse(body);
122
119
 
123
- // parse balances
124
- const walletBalances: UserBalance[] = [];
125
- for (const b of jsonRawResponse.wallet.balances) {
126
- walletBalances.push({
127
- mint: new web3.PublicKey(b.mint),
128
- balance: new BN(b.balance, "hex"),
129
- balanceUi: Number(b.balanceUi),
130
- });
131
- }
120
+ // 1. Parse Wallet Balances
121
+ // This section correctly iterates through the wallet balances and creates typed objects.
122
+ const walletBalances: UserBalance[] = (
123
+ jsonRawResponse.wallet.balances || []
124
+ ).map((b: any) => ({
125
+ mint: new web3.PublicKey(b.mint),
126
+ balance: new BN(b.balance, "hex"),
127
+ balanceUi: Number(b.balanceUi),
128
+ }));
132
129
 
133
- // get tokens still in user wallet
134
130
  const wallet: UserWallet = {
135
131
  balances: walletBalances,
136
132
  };
137
133
 
138
- // get tx summary for each account and group them
139
- const summaryByAccount = new Map<string, ClendAccountTxSummary[]>();
140
- if (getClendAccountSummary && jsonRawResponse.summary) {
141
- for (const s of jsonRawResponse.summary) {
142
- const accountAddress = new web3.PublicKey(s.clendAccount).toBase58();
143
- if (!summaryByAccount.has(accountAddress)) {
144
- summaryByAccount.set(accountAddress, []);
145
- }
134
+ // 2. Parse Clend Accounts and their Summaries
135
+ // This is the main refactored section. It iterates through the clendAccounts array
136
+ // from the response, which contains both the account data and its summary.
137
+ const clendAccounts = (jsonRawResponse.clendAccounts || []).map(
138
+ (accountData: any) => {
139
+ // A. Parse the main ClendAccount object
140
+ const rawClendAccount = accountData.clendAccount;
141
+ const clendAccountBalances: ClendAccountBalance[] = (
142
+ rawClendAccount.balances || []
143
+ ).map((b: any) => {
144
+ const liquidation: ClendAccountAssetLiquidation | null = b.liquidation
145
+ ? {
146
+ price: Number(b.liquidation.price),
147
+ changePercentage: Number(b.liquidation.changePercentage),
148
+ }
149
+ : null;
150
+
151
+ return {
152
+ mint: new web3.PublicKey(b.mint),
153
+ bank: new web3.PublicKey(b.bank),
154
+ assetBalance: new BN(b.assetBalance, "hex"),
155
+ assetBalanceUi: Number(b.assetBalanceUi),
156
+ assetValue: Number(b.assetValue),
157
+ assetYieldApy: Number(b.assetYieldApy),
158
+ liabilityBalance: new BN(b.liabilityBalance, "hex"),
159
+ liabilityBalanceUi: Number(b.liabilityBalanceUi),
160
+ liabilityValue: Number(b.liabilityValue),
161
+ liabilityBorrowCostApy: Number(b.liabilityBorrowCostApy),
162
+ price: Number(b.price),
163
+ liquidation,
164
+ };
165
+ });
146
166
 
147
- const txSummary: ClendAccountTxSummary = {
148
- txSig: s.txSig,
149
- time: s.time,
150
- clendAccount: new web3.PublicKey(s.clendAccount),
151
- clendAccountAuthority: new web3.PublicKey(s.clendAccountAuthority),
152
- clendGroup: new web3.PublicKey(s.clendGroup),
153
- action: s.action,
154
- input: undefined,
155
- events: [],
167
+ const clendAccount: ClendAccount = {
168
+ key: new web3.PublicKey(rawClendAccount.key),
169
+ group: new web3.PublicKey(rawClendAccount.group),
170
+ balances: clendAccountBalances,
171
+ netValue: Number(rawClendAccount.netValue),
172
+ netApy: Number(rawClendAccount.netApy),
173
+ pnl: Number(rawClendAccount.pnl),
174
+ totalAssetValue: Number(rawClendAccount.totalAssetValue),
175
+ totalLiabilityValue: Number(rawClendAccount.totalLiabilityValue),
176
+ healthFactorNotional: Number(rawClendAccount.healthFactorNotional),
177
+ healthFactorRiskAdjusted: Number(
178
+ rawClendAccount.healthFactorRiskAdjusted,
179
+ ),
180
+ notionalLeverage: Number(rawClendAccount.notionalLeverage),
181
+ riskAdjustedLeverage: Number(rawClendAccount.riskAdjustedLeverage),
182
+ notionalLtv: Number(rawClendAccount.notionalLtv),
183
+ riskAdjustedLtv: Number(rawClendAccount.riskAdjustedLtv),
156
184
  };
157
185
 
158
- // parse inputs if they exist
159
- if (s.input) {
160
- const input: UserRequest = {
161
- apiPath: s.input.apiPath,
162
- selectedTokenMint: s.input.selectedTokenMint
163
- ? new web3.PublicKey(s.input.selectedTokenMint)
164
- : null,
165
- amountUi: s.input.amountUi ? Number(s.input.amountUi) : null,
166
- leverage: s.input.leverage ? Number(s.input.leverage) : null,
167
- slippageBps: s.input.slippageBps
168
- ? Number(s.input.slippageBps)
169
- : null,
170
- openPosition: s.input.openPosition
171
- ? Boolean(s.input.openPosition)
172
- : null,
173
- closePosition: s.input.closePosition
174
- ? Boolean(s.input.closePosition)
175
- : null,
176
- };
177
- txSummary.input = input;
178
- }
186
+ // B. Parse the associated Summary array for the account
187
+ let summary: ClendAccountTxSummary[] = [];
188
+ if (getClendAccountSummary && accountData.summary) {
189
+ summary = accountData.summary.map((s: any) => {
190
+ let input: UserRequest | undefined = undefined;
191
+ if (s.input) {
192
+ input = {
193
+ apiPath: s.input.apiPath,
194
+ selectedTokenMint: s.input.selectedTokenMint
195
+ ? new web3.PublicKey(s.input.selectedTokenMint)
196
+ : null,
197
+ amountUi: s.input.amountUi ? Number(s.input.amountUi) : null,
198
+ leverage: s.input.leverage ? Number(s.input.leverage) : null,
199
+ slippageBps: s.input.slippageBps
200
+ ? Number(s.input.slippageBps)
201
+ : null,
202
+ openPosition:
203
+ s.input.openPosition != null
204
+ ? Boolean(s.input.openPosition)
205
+ : null,
206
+ closePosition:
207
+ s.input.closePosition != null
208
+ ? Boolean(s.input.closePosition)
209
+ : null,
210
+ };
211
+ }
179
212
 
180
- // get events for each summary
181
- for (const event of s.events) {
182
- let closeBalance: boolean | null = null;
183
- if (event.closeBalance !== null) {
184
- closeBalance = Boolean(event.closeBalance);
185
- }
186
-
187
- // parse amount
188
- const clendAccountEvent: ClendAccountEvent = {
189
- eventIndex: event.eventIndex,
190
- eventName: event.eventName,
191
- bank: event.bank ? new web3.PublicKey(event.bank) : null,
192
- mint: event.mint ? new web3.PublicKey(event.mint) : null,
193
- amount: event.amount ? new BN(event.amount, "hex") : null,
194
- amountUi: event.amountUi ? Number(event.amountUi) : null,
195
- value: event.value ? Number(event.value) : null,
196
- price: event.price ? Number(event.price) : null,
197
- closeBalance,
198
- };
199
- txSummary.events.push(clendAccountEvent);
213
+ const events: ClendAccountEvent[] = (s.events || []).map(
214
+ (event: any) => {
215
+ let closeBalance: boolean | null = null;
216
+ // Only convert to boolean if the value is not null/undefined to preserve the null state.
217
+ if (
218
+ event.closeBalance !== null &&
219
+ event.closeBalance !== undefined
220
+ ) {
221
+ closeBalance = Boolean(event.closeBalance);
222
+ }
223
+
224
+ return {
225
+ eventIndex: event.eventIndex,
226
+ eventName: event.eventName,
227
+ bank: event.bank ? new web3.PublicKey(event.bank) : null,
228
+ mint: event.mint ? new web3.PublicKey(event.mint) : null,
229
+ amount: event.amount ? new BN(event.amount, "hex") : null,
230
+ amountUi: event.amountUi ? Number(event.amountUi) : null,
231
+ value: event.value ? Number(event.value) : null,
232
+ price: event.price ? Number(event.price) : null,
233
+ closeBalance,
234
+ };
235
+ },
236
+ );
237
+
238
+ const txSummary: ClendAccountTxSummary = {
239
+ txSig: s.txSig,
240
+ time: s.time,
241
+ clendAccount: new web3.PublicKey(s.clendAccount),
242
+ clendAccountAuthority: new web3.PublicKey(
243
+ s.clendAccountAuthority,
244
+ ),
245
+ clendGroup: new web3.PublicKey(s.clendGroup),
246
+ action: s.action,
247
+ input,
248
+ events,
249
+ };
250
+ return txSummary;
251
+ });
200
252
  }
201
253
 
202
- summaryByAccount.get(accountAddress)!.push(txSummary);
203
- }
204
- }
205
-
206
- // if no clend accounts, return empty array
207
- const clendAccounts: {
208
- clendAccount: ClendAccount;
209
- summary: ClendAccountTxSummary[];
210
- }[] = [];
211
- for (const accountAndSumary of jsonRawResponse.clendAccounts) {
212
- const clendAccountBalances: ClendAccountBalance[] = [];
213
- const ca = accountAndSumary.clendAccount;
214
- for (const b of ca.balances) {
215
- // parse liquidation data if exists
216
- const liquidation: ClendAccountAssetLiquidation | null = b.liquidation
217
- ? {
218
- price: Number(b.liquidation.price),
219
- changePercentage: Number(b.liquidation.changePercentage),
220
- }
221
- : null;
222
-
223
- // create clend account balance
224
- clendAccountBalances.push({
225
- mint: new web3.PublicKey(b.mint),
226
- bank: new web3.PublicKey(b.bank),
227
- assetBalance: new BN(b.assetBalance, "hex"),
228
- assetBalanceUi: Number(b.assetBalanceUi),
229
- assetValue: Number(b.assetValue),
230
- assetYieldBps: Number(b.assetYieldBps),
231
- assetYieldApy: Number(b.assetYieldApy),
232
- liabilityBalance: new BN(b.liabilityBalance, "hex"),
233
- liabilityBalanceUi: Number(b.liabilityBalanceUi),
234
- liabilityValue: Number(b.liabilityValue),
235
- liabilityBorrowCostBps: Number(b.liabilityBorrowCostBps),
236
- liabilityBorrowCostApy: Number(b.liabilityBorrowCostApy),
237
- price: Number(b.price),
238
- liquidation,
239
- });
240
- }
241
-
242
- // create clend account
243
- const clendAccountAddress = new web3.PublicKey(
244
- accountAndSumary.clendAccount.key,
245
- );
246
- const clendAccount: ClendAccount = {
247
- key: clendAccountAddress,
248
- group: new web3.PublicKey(ca.group),
249
- balances: clendAccountBalances,
250
- netValue: Number(ca.netValue),
251
- netApy: Number(ca.netApy),
252
- pnl: Number(ca.pnl),
253
- totalAssetValue: Number(ca.totalAssetValue),
254
- totalLiabilityValue: Number(ca.totalLiabilityValue),
255
- healthFactorNotional: Number(ca.healthFactorNotional),
256
- healthFactorRiskAdjusted: Number(ca.healthFactorRiskAdjusted),
257
- notionalLeverage: Number(ca.notionalLeverage),
258
- riskAdjustedLeverage: Number(ca.riskAdjustedLeverage),
259
- notionalLtv: Number(ca.notionalLtv),
260
- riskAdjustedLtv: Number(ca.riskAdjustedLtv),
261
- };
262
-
263
- // find corresponding tx summary for account
264
- const summary =
265
- summaryByAccount.get(clendAccountAddress.toString()) || [];
266
- clendAccounts.push({ clendAccount, summary });
267
- }
254
+ // C. Combine the parsed account and its summary
255
+ return { clendAccount, summary };
256
+ },
257
+ );
268
258
 
259
+ // 3. Return the final, correctly structured response object.
269
260
  return {
270
261
  wallet,
271
262
  clendAccounts,
272
263
  };
273
264
  }
274
-
275
265
  /**
276
266
  * Get all groups
277
267
  * @param includeBankData Whether to include bank data in the response, if not strictly necessary keep false
package/src/types.ts CHANGED
@@ -134,12 +134,10 @@ export interface ClendAccountBalance {
134
134
  assetBalance: BN;
135
135
  assetBalanceUi: number;
136
136
  assetValue: number;
137
- assetYieldBps: number;
138
137
  assetYieldApy: number;
139
138
  liabilityBalance: BN;
140
139
  liabilityBalanceUi: number;
141
140
  liabilityValue: number;
142
- liabilityBorrowCostBps: number;
143
141
  liabilityBorrowCostApy: number;
144
142
  price: number;
145
143
  liquidation: ClendAccountAssetLiquidation | null;