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

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,104 +99,35 @@ 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"),
@@ -211,30 +142,84 @@ class Client {
211
142
  liabilityBorrowCostApy: Number(b.liabilityBorrowCostApy),
212
143
  price: Number(b.price),
213
144
  liquidation,
214
- });
215
- }
216
- // create clend account
217
- const clendAccountAddress = new anchor_1.web3.PublicKey(accountAndSumary.clendAccount.key);
145
+ };
146
+ });
218
147
  const clendAccount = {
219
- key: clendAccountAddress,
220
- group: new anchor_1.web3.PublicKey(ca.group),
148
+ key: new anchor_1.web3.PublicKey(rawClendAccount.key),
149
+ group: new anchor_1.web3.PublicKey(rawClendAccount.group),
221
150
  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),
151
+ netValue: Number(rawClendAccount.netValue),
152
+ netApy: Number(rawClendAccount.netApy),
153
+ pnl: Number(rawClendAccount.pnl),
154
+ totalAssetValue: Number(rawClendAccount.totalAssetValue),
155
+ totalLiabilityValue: Number(rawClendAccount.totalLiabilityValue),
156
+ healthFactorNotional: Number(rawClendAccount.healthFactorNotional),
157
+ healthFactorRiskAdjusted: Number(rawClendAccount.healthFactorRiskAdjusted),
158
+ notionalLeverage: Number(rawClendAccount.notionalLeverage),
159
+ riskAdjustedLeverage: Number(rawClendAccount.riskAdjustedLeverage),
160
+ notionalLtv: Number(rawClendAccount.notionalLtv),
161
+ riskAdjustedLtv: Number(rawClendAccount.riskAdjustedLtv),
233
162
  };
234
- // find corresponding tx summary for account
235
- const summary = summaryByAccount.get(clendAccountAddress.toString()) || [];
236
- clendAccounts.push({ clendAccount, summary });
237
- }
163
+ // B. Parse the associated Summary array for the account
164
+ let summary = [];
165
+ if (getClendAccountSummary && accountData.summary) {
166
+ summary = accountData.summary.map((s) => {
167
+ let input = undefined;
168
+ if (s.input) {
169
+ input = {
170
+ apiPath: s.input.apiPath,
171
+ selectedTokenMint: s.input.selectedTokenMint
172
+ ? new anchor_1.web3.PublicKey(s.input.selectedTokenMint)
173
+ : null,
174
+ amountUi: s.input.amountUi ? Number(s.input.amountUi) : null,
175
+ leverage: s.input.leverage ? Number(s.input.leverage) : null,
176
+ slippageBps: s.input.slippageBps
177
+ ? Number(s.input.slippageBps)
178
+ : null,
179
+ openPosition: s.input.openPosition != null
180
+ ? Boolean(s.input.openPosition)
181
+ : null,
182
+ closePosition: s.input.closePosition != null
183
+ ? Boolean(s.input.closePosition)
184
+ : null,
185
+ };
186
+ }
187
+ const events = (s.events || []).map((event) => {
188
+ let closeBalance = null;
189
+ // Only convert to boolean if the value is not null/undefined to preserve the null state.
190
+ if (event.closeBalance !== null &&
191
+ event.closeBalance !== undefined) {
192
+ closeBalance = Boolean(event.closeBalance);
193
+ }
194
+ return {
195
+ eventIndex: event.eventIndex,
196
+ eventName: event.eventName,
197
+ bank: event.bank ? new anchor_1.web3.PublicKey(event.bank) : null,
198
+ mint: event.mint ? new anchor_1.web3.PublicKey(event.mint) : null,
199
+ amount: event.amount ? new anchor_1.BN(event.amount, "hex") : null,
200
+ amountUi: event.amountUi ? Number(event.amountUi) : null,
201
+ value: event.value ? Number(event.value) : null,
202
+ price: event.price ? Number(event.price) : null,
203
+ closeBalance,
204
+ };
205
+ });
206
+ const txSummary = {
207
+ txSig: s.txSig,
208
+ time: s.time,
209
+ clendAccount: new anchor_1.web3.PublicKey(s.clendAccount),
210
+ clendAccountAuthority: new anchor_1.web3.PublicKey(s.clendAccountAuthority),
211
+ clendGroup: new anchor_1.web3.PublicKey(s.clendGroup),
212
+ action: s.action,
213
+ input,
214
+ events,
215
+ };
216
+ return txSummary;
217
+ });
218
+ }
219
+ // C. Combine the parsed account and its summary
220
+ return { clendAccount, summary };
221
+ });
222
+ // 3. Return the final, correctly structured response object.
238
223
  return {
239
224
  wallet,
240
225
  clendAccounts,
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-54bdd58",
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,168 @@ 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
+ assetYieldBps: Number(b.assetYieldBps),
158
+ assetYieldApy: Number(b.assetYieldApy),
159
+ liabilityBalance: new BN(b.liabilityBalance, "hex"),
160
+ liabilityBalanceUi: Number(b.liabilityBalanceUi),
161
+ liabilityValue: Number(b.liabilityValue),
162
+ liabilityBorrowCostBps: Number(b.liabilityBorrowCostBps),
163
+ liabilityBorrowCostApy: Number(b.liabilityBorrowCostApy),
164
+ price: Number(b.price),
165
+ liquidation,
166
+ };
167
+ });
146
168
 
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: [],
169
+ const clendAccount: ClendAccount = {
170
+ key: new web3.PublicKey(rawClendAccount.key),
171
+ group: new web3.PublicKey(rawClendAccount.group),
172
+ balances: clendAccountBalances,
173
+ netValue: Number(rawClendAccount.netValue),
174
+ netApy: Number(rawClendAccount.netApy),
175
+ pnl: Number(rawClendAccount.pnl),
176
+ totalAssetValue: Number(rawClendAccount.totalAssetValue),
177
+ totalLiabilityValue: Number(rawClendAccount.totalLiabilityValue),
178
+ healthFactorNotional: Number(rawClendAccount.healthFactorNotional),
179
+ healthFactorRiskAdjusted: Number(
180
+ rawClendAccount.healthFactorRiskAdjusted,
181
+ ),
182
+ notionalLeverage: Number(rawClendAccount.notionalLeverage),
183
+ riskAdjustedLeverage: Number(rawClendAccount.riskAdjustedLeverage),
184
+ notionalLtv: Number(rawClendAccount.notionalLtv),
185
+ riskAdjustedLtv: Number(rawClendAccount.riskAdjustedLtv),
156
186
  };
157
187
 
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
- }
188
+ // B. Parse the associated Summary array for the account
189
+ let summary: ClendAccountTxSummary[] = [];
190
+ if (getClendAccountSummary && accountData.summary) {
191
+ summary = accountData.summary.map((s: any) => {
192
+ let input: UserRequest | undefined = undefined;
193
+ if (s.input) {
194
+ input = {
195
+ apiPath: s.input.apiPath,
196
+ selectedTokenMint: s.input.selectedTokenMint
197
+ ? new web3.PublicKey(s.input.selectedTokenMint)
198
+ : null,
199
+ amountUi: s.input.amountUi ? Number(s.input.amountUi) : null,
200
+ leverage: s.input.leverage ? Number(s.input.leverage) : null,
201
+ slippageBps: s.input.slippageBps
202
+ ? Number(s.input.slippageBps)
203
+ : null,
204
+ openPosition:
205
+ s.input.openPosition != null
206
+ ? Boolean(s.input.openPosition)
207
+ : null,
208
+ closePosition:
209
+ s.input.closePosition != null
210
+ ? Boolean(s.input.closePosition)
211
+ : null,
212
+ };
213
+ }
179
214
 
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);
215
+ const events: ClendAccountEvent[] = (s.events || []).map(
216
+ (event: any) => {
217
+ let closeBalance: boolean | null = null;
218
+ // Only convert to boolean if the value is not null/undefined to preserve the null state.
219
+ if (
220
+ event.closeBalance !== null &&
221
+ event.closeBalance !== undefined
222
+ ) {
223
+ closeBalance = Boolean(event.closeBalance);
224
+ }
225
+
226
+ return {
227
+ eventIndex: event.eventIndex,
228
+ eventName: event.eventName,
229
+ bank: event.bank ? new web3.PublicKey(event.bank) : null,
230
+ mint: event.mint ? new web3.PublicKey(event.mint) : null,
231
+ amount: event.amount ? new BN(event.amount, "hex") : null,
232
+ amountUi: event.amountUi ? Number(event.amountUi) : null,
233
+ value: event.value ? Number(event.value) : null,
234
+ price: event.price ? Number(event.price) : null,
235
+ closeBalance,
236
+ };
237
+ },
238
+ );
239
+
240
+ const txSummary: ClendAccountTxSummary = {
241
+ txSig: s.txSig,
242
+ time: s.time,
243
+ clendAccount: new web3.PublicKey(s.clendAccount),
244
+ clendAccountAuthority: new web3.PublicKey(
245
+ s.clendAccountAuthority,
246
+ ),
247
+ clendGroup: new web3.PublicKey(s.clendGroup),
248
+ action: s.action,
249
+ input,
250
+ events,
251
+ };
252
+ return txSummary;
253
+ });
200
254
  }
201
255
 
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
- }
256
+ // C. Combine the parsed account and its summary
257
+ return { clendAccount, summary };
258
+ },
259
+ );
268
260
 
261
+ // 3. Return the final, correctly structured response object.
269
262
  return {
270
263
  wallet,
271
264
  clendAccounts,
272
265
  };
273
266
  }
274
-
275
267
  /**
276
268
  * Get all groups
277
269
  * @param includeBankData Whether to include bank data in the response, if not strictly necessary keep false