@carrot-protocol/boost-http-client 0.2.15-group-refactor1-dev-e792f4d → 0.2.15-group-refactor1-dev-ef145c2

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, GetUserRequest } from "./types";
2
+ import { GetBankResponse, GetUserResponse, GetGroupResponse } from "./types";
3
3
  export * from "./types";
4
4
  export * from "./utils";
5
5
  export * as Common from "@carrot-protocol/clend-common";
@@ -27,7 +27,7 @@ export declare class Client {
27
27
  * @param user wallet public key
28
28
  * @returns User details
29
29
  */
30
- getUser(request: GetUserRequest): Promise<GetUserResponse>;
30
+ getUser(group: web3.PublicKey, user: web3.PublicKey, getClendAccountSummary: boolean): Promise<GetUserResponse>;
31
31
  /**
32
32
  * Get market details
33
33
  * @param groupAddress group public key
package/dist/index.js CHANGED
@@ -104,121 +104,127 @@ class Client {
104
104
  * @param user wallet public key
105
105
  * @returns User details
106
106
  */
107
- async getUser(request) {
108
- // use loaded wallet if not provided
109
- let user = request.user;
110
- if (!user) {
111
- user = this.address();
112
- }
113
- const body = await handleApiCall(() => this.http.get(`/user?user=${user.toString()}&getClendAccountSummary=${request.getClendAccountSummary}`));
107
+ async getUser(group, user, getClendAccountSummary) {
108
+ const body = await handleApiCall(() => this.http.get(`/user?user=${user.toString()}&group=${group.toString()}&getClendAccountSummary=${getClendAccountSummary}`));
114
109
  const jsonRawResponse = JSON.parse(body);
115
- // get tokens still in user wallet
116
- const wallet = {
117
- usdcBalance: new anchor_1.BN(jsonRawResponse.wallet.usdcBalance, "hex"),
118
- usdcBalanceUi: Number(jsonRawResponse.wallet.usdcBalanceUi),
119
- jlpBalance: new anchor_1.BN(jsonRawResponse.wallet.jlpBalance, "hex"),
120
- jlpBalanceUi: Number(jsonRawResponse.wallet.jlpBalanceUi),
121
- solBalance: new anchor_1.BN(jsonRawResponse.wallet.solBalance, "hex"),
122
- solBalanceUi: Number(jsonRawResponse.wallet.solBalanceUi),
123
- };
124
- // if no clend account, return undefined for clend
125
- if (!jsonRawResponse.clendAccount) {
126
- return {
127
- wallet,
128
- clendAccount: undefined,
129
- summary: [],
130
- };
131
- }
132
- // parse lending account balances
133
- const balances = [];
134
- for (const b of jsonRawResponse.clendAccount.balances) {
135
- balances.push({
110
+ // parse balances
111
+ const walletBalances = [];
112
+ for (const b of jsonRawResponse.wallet.balances) {
113
+ walletBalances.push({
136
114
  mint: new anchor_1.web3.PublicKey(b.mint),
137
- bank: new anchor_1.web3.PublicKey(b.bank),
138
- assetBalance: new anchor_1.BN(b.assetBalance, "hex"),
139
- assetBalanceUi: Number(b.assetBalanceUi),
140
- assetValue: Number(b.assetValue),
141
- liabilityBalance: new anchor_1.BN(b.liabilityBalance, "hex"),
142
- liabilityBalanceUi: Number(b.liabilityBalanceUi),
143
- liabilityValue: Number(b.liabilityValue),
144
- price: Number(b.price),
115
+ balance: new anchor_1.BN(b.balance, "hex"),
116
+ balanceUi: Number(b.balanceUi),
145
117
  });
146
118
  }
147
- // create clend account
148
- const clendAccount = {
149
- balances,
150
- netValue: Number(jsonRawResponse.clendAccount.netValue),
151
- netApy: Number(jsonRawResponse.clendAccount.netApy),
152
- pnl: Number(jsonRawResponse.clendAccount.pnl),
153
- totalAssetValue: Number(jsonRawResponse.clendAccount.totalAssetValue),
154
- totalLiabilityValue: Number(jsonRawResponse.clendAccount.totalLiabilityValue),
155
- healthFactorNotional: Number(jsonRawResponse.clendAccount.healthFactorNotional),
156
- healthFactorRiskAdjusted: Number(jsonRawResponse.clendAccount.healthFactorRiskAdjusted),
157
- notionalLeverage: Number(jsonRawResponse.clendAccount.notionalLeverage),
158
- riskAdjustedLeverage: Number(jsonRawResponse.clendAccount.riskAdjustedLeverage),
159
- liquidationPrice: Number(jsonRawResponse.clendAccount.liquidationPrice),
160
- liquidationPriceChangePercentage: Number(jsonRawResponse.clendAccount.liquidationPriceChangePercentage),
161
- notionalLtv: Number(jsonRawResponse.clendAccount.notionalLtv),
162
- riskAdjustedLtv: Number(jsonRawResponse.clendAccount.riskAdjustedLtv),
119
+ // get tokens still in user wallet
120
+ const wallet = {
121
+ balances: walletBalances,
163
122
  };
164
- // get tx summary for each account
165
- const summary = [];
166
- for (const s of jsonRawResponse.summary) {
167
- const txSummary = {
168
- txSig: s.txSig,
169
- time: s.time,
170
- clendAccount: new anchor_1.web3.PublicKey(s.clendAccount),
171
- clendAccountAuthority: new anchor_1.web3.PublicKey(s.clendAccountAuthority),
172
- clendGroup: new anchor_1.web3.PublicKey(s.clendGroup),
173
- action: s.action,
174
- input: undefined,
175
- events: [],
176
- };
177
- // parse inputs if they exist
178
- if (s.input) {
179
- const input = {
180
- apiPath: s.input.apiPath,
181
- selectedTokenMint: s.input.selectedTokenMint
182
- ? new anchor_1.web3.PublicKey(s.input.selectedTokenMint)
183
- : null,
184
- amountUi: s.input.amountUi ? Number(s.input.amountUi) : null,
185
- leverage: s.input.leverage ? Number(s.input.leverage) : null,
186
- slippageBps: s.input.slippageBps ? Number(s.input.slippageBps) : null,
187
- openPosition: s.input.openPosition
188
- ? Boolean(s.input.openPosition)
189
- : null,
190
- closePosition: s.input.closePosition
191
- ? Boolean(s.input.closePosition)
192
- : null,
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: [],
193
140
  };
194
- txSummary.input = input;
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);
195
183
  }
196
- // get events for each summary
197
- for (const event of s.events) {
198
- let closeBalance = null;
199
- if (event.closeBalance !== null) {
200
- closeBalance = Boolean(event.closeBalance);
184
+ }
185
+ // if no clend account, return undefined for clend
186
+ const clendAccounts = [];
187
+ if (jsonRawResponse.clendAccounts) {
188
+ for (const [address, ca] of Object.entries(jsonRawResponse.clendAccounts)) {
189
+ // parse lending account balances
190
+ const clendAccountBalances = [];
191
+ for (const b of ca.balances) {
192
+ clendAccountBalances.push({
193
+ mint: new anchor_1.web3.PublicKey(b.mint),
194
+ bank: new anchor_1.web3.PublicKey(b.bank),
195
+ assetBalance: new anchor_1.BN(b.assetBalance, "hex"),
196
+ assetBalanceUi: Number(b.assetBalanceUi),
197
+ assetValue: Number(b.assetValue),
198
+ liabilityBalance: new anchor_1.BN(b.liabilityBalance, "hex"),
199
+ liabilityBalanceUi: Number(b.liabilityBalanceUi),
200
+ liabilityValue: Number(b.liabilityValue),
201
+ price: Number(b.price),
202
+ });
201
203
  }
202
- // parse amount
203
- const clendAccountEvent = {
204
- eventIndex: event.eventIndex,
205
- eventName: event.eventName,
206
- bank: event.bank ? new anchor_1.web3.PublicKey(event.bank) : null,
207
- mint: event.mint ? new anchor_1.web3.PublicKey(event.mint) : null,
208
- amount: event.amount ? new anchor_1.BN(event.amount, "hex") : null,
209
- amountUi: event.amountUi ? Number(event.amountUi) : null,
210
- value: event.value ? Number(event.value) : null,
211
- price: event.price ? Number(event.price) : null,
212
- closeBalance,
204
+ // create clend account
205
+ const clendAccount = {
206
+ balances: clendAccountBalances,
207
+ netValue: Number(ca.netValue),
208
+ netApy: Number(ca.netApy),
209
+ pnl: Number(ca.pnl),
210
+ totalAssetValue: Number(ca.totalAssetValue),
211
+ totalLiabilityValue: Number(ca.totalLiabilityValue),
212
+ healthFactorNotional: Number(ca.healthFactorNotional),
213
+ healthFactorRiskAdjusted: Number(ca.healthFactorRiskAdjusted),
214
+ notionalLeverage: Number(ca.notionalLeverage),
215
+ riskAdjustedLeverage: Number(ca.riskAdjustedLeverage),
216
+ liquidationPrice: Number(ca.liquidationPrice),
217
+ liquidationPriceChangePercentage: Number(ca.liquidationPriceChangePercentage),
218
+ notionalLtv: Number(ca.notionalLtv),
219
+ riskAdjustedLtv: Number(ca.riskAdjustedLtv),
213
220
  };
214
- txSummary.events.push(clendAccountEvent);
221
+ const summary = summaryByAccount.get(address) || [];
222
+ clendAccounts.push({ clendAccount, summary });
215
223
  }
216
- summary.push(txSummary);
217
224
  }
218
225
  return {
219
226
  wallet,
220
- clendAccount,
221
- summary,
227
+ clendAccounts,
222
228
  };
223
229
  }
224
230
  /**
package/dist/types.d.ts CHANGED
@@ -65,24 +65,27 @@ export interface GetGroupResponse {
65
65
  banks: Bank[];
66
66
  }
67
67
  export interface GetUserRequest {
68
- user?: web3.PublicKey;
69
- getClendAccountSummary?: boolean;
68
+ group: web3.PublicKey;
69
+ user: web3.PublicKey;
70
+ getClendAccountSummary: boolean;
70
71
  }
71
72
  export interface GetUserResponse {
72
73
  wallet: UserWallet;
73
- clendAccount: ClendAccount | undefined;
74
- summary: ClendAccountTxSummary[];
74
+ clendAccounts: {
75
+ clendAccount: ClendAccount;
76
+ summary: ClendAccountTxSummary[];
77
+ }[];
75
78
  }
76
79
  export interface UserWallet {
77
- usdcBalance: BN;
78
- usdcBalanceUi: number;
79
- jlpBalance: BN;
80
- jlpBalanceUi: number;
81
- solBalance: BN;
82
- solBalanceUi: number;
80
+ balances: UserBalance[];
81
+ }
82
+ export interface UserBalance {
83
+ mint: web3.PublicKey;
84
+ balance: BN;
85
+ balanceUi: number;
83
86
  }
84
87
  export interface ClendAccount {
85
- balances: Balance[];
88
+ balances: ClendAccountBalance[];
86
89
  netValue: number;
87
90
  netApy: number;
88
91
  pnl: number;
@@ -97,7 +100,7 @@ export interface ClendAccount {
97
100
  notionalLtv: number;
98
101
  riskAdjustedLtv: number;
99
102
  }
100
- export interface Balance {
103
+ export interface ClendAccountBalance {
101
104
  mint: web3.PublicKey;
102
105
  bank: web3.PublicKey;
103
106
  assetBalance: BN;
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-e792f4d",
3
+ "version": "0.2.15-group-refactor1-dev-ef145c2",
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
@@ -12,13 +12,14 @@ import {
12
12
  WithdrawLeverageResponse,
13
13
  UserWallet,
14
14
  ClendAccount,
15
- Balance,
15
+ ClendAccountBalance,
16
16
  Bank,
17
17
  GetGroupResponse,
18
18
  ClendAccountEvent,
19
19
  GetUserRequest,
20
20
  ClendAccountTxSummary,
21
21
  UserRequest,
22
+ UserBalance,
22
23
  } from "./types";
23
24
  import encode from "bs58";
24
25
 
@@ -103,146 +104,157 @@ export class Client {
103
104
  * @param user wallet public key
104
105
  * @returns User details
105
106
  */
106
- async getUser(request: GetUserRequest): Promise<GetUserResponse> {
107
- // use loaded wallet if not provided
108
- let user = request.user;
109
- if (!user) {
110
- user = this.address();
111
- }
112
-
107
+ async getUser(
108
+ group: web3.PublicKey,
109
+ user: web3.PublicKey,
110
+ getClendAccountSummary: boolean,
111
+ ): Promise<GetUserResponse> {
113
112
  const body = await handleApiCall(() =>
114
113
  this.http.get(
115
- `/user?user=${user.toString()}&getClendAccountSummary=${request.getClendAccountSummary}`,
114
+ `/user?user=${user.toString()}&group=${group.toString()}&getClendAccountSummary=${getClendAccountSummary}`,
116
115
  ),
117
116
  );
118
117
 
119
118
  const jsonRawResponse: any = JSON.parse(body);
120
119
 
121
- // get tokens still in user wallet
122
- const wallet: UserWallet = {
123
- usdcBalance: new BN(jsonRawResponse.wallet.usdcBalance, "hex"),
124
- usdcBalanceUi: Number(jsonRawResponse.wallet.usdcBalanceUi),
125
- jlpBalance: new BN(jsonRawResponse.wallet.jlpBalance, "hex"),
126
- jlpBalanceUi: Number(jsonRawResponse.wallet.jlpBalanceUi),
127
- solBalance: new BN(jsonRawResponse.wallet.solBalance, "hex"),
128
- solBalanceUi: Number(jsonRawResponse.wallet.solBalanceUi),
129
- };
130
-
131
- // if no clend account, return undefined for clend
132
- if (!jsonRawResponse.clendAccount) {
133
- return {
134
- wallet,
135
- clendAccount: undefined,
136
- summary: [],
137
- };
138
- }
139
-
140
- // parse lending account balances
141
- const balances: Balance[] = [];
142
- for (const b of jsonRawResponse.clendAccount.balances) {
143
- balances.push({
120
+ // parse balances
121
+ const walletBalances: UserBalance[] = [];
122
+ for (const b of jsonRawResponse.wallet.balances) {
123
+ walletBalances.push({
144
124
  mint: new web3.PublicKey(b.mint),
145
- bank: new web3.PublicKey(b.bank),
146
- assetBalance: new BN(b.assetBalance, "hex"),
147
- assetBalanceUi: Number(b.assetBalanceUi),
148
- assetValue: Number(b.assetValue),
149
- liabilityBalance: new BN(b.liabilityBalance, "hex"),
150
- liabilityBalanceUi: Number(b.liabilityBalanceUi),
151
- liabilityValue: Number(b.liabilityValue),
152
- price: Number(b.price),
125
+ balance: new BN(b.balance, "hex"),
126
+ balanceUi: Number(b.balanceUi),
153
127
  });
154
128
  }
155
129
 
156
- // create clend account
157
- const clendAccount: ClendAccount = {
158
- balances,
159
- netValue: Number(jsonRawResponse.clendAccount.netValue),
160
- netApy: Number(jsonRawResponse.clendAccount.netApy),
161
- pnl: Number(jsonRawResponse.clendAccount.pnl),
162
- totalAssetValue: Number(jsonRawResponse.clendAccount.totalAssetValue),
163
- totalLiabilityValue: Number(
164
- jsonRawResponse.clendAccount.totalLiabilityValue,
165
- ),
166
- healthFactorNotional: Number(
167
- jsonRawResponse.clendAccount.healthFactorNotional,
168
- ),
169
- healthFactorRiskAdjusted: Number(
170
- jsonRawResponse.clendAccount.healthFactorRiskAdjusted,
171
- ),
172
- notionalLeverage: Number(jsonRawResponse.clendAccount.notionalLeverage),
173
- riskAdjustedLeverage: Number(
174
- jsonRawResponse.clendAccount.riskAdjustedLeverage,
175
- ),
176
- liquidationPrice: Number(jsonRawResponse.clendAccount.liquidationPrice),
177
- liquidationPriceChangePercentage: Number(
178
- jsonRawResponse.clendAccount.liquidationPriceChangePercentage,
179
- ),
180
- notionalLtv: Number(jsonRawResponse.clendAccount.notionalLtv),
181
- riskAdjustedLtv: Number(jsonRawResponse.clendAccount.riskAdjustedLtv),
130
+ // get tokens still in user wallet
131
+ const wallet: UserWallet = {
132
+ balances: walletBalances,
182
133
  };
183
134
 
184
- // get tx summary for each account
185
- const summary: ClendAccountTxSummary[] = [];
186
- for (const s of jsonRawResponse.summary) {
187
- const txSummary: ClendAccountTxSummary = {
188
- txSig: s.txSig,
189
- time: s.time,
190
- clendAccount: new web3.PublicKey(s.clendAccount),
191
- clendAccountAuthority: new web3.PublicKey(s.clendAccountAuthority),
192
- clendGroup: new web3.PublicKey(s.clendGroup),
193
- action: s.action,
194
- input: undefined,
195
- events: [],
196
- };
197
-
198
- // parse inputs if they exist
199
- if (s.input) {
200
- const input: UserRequest = {
201
- apiPath: s.input.apiPath,
202
- selectedTokenMint: s.input.selectedTokenMint
203
- ? new web3.PublicKey(s.input.selectedTokenMint)
204
- : null,
205
- amountUi: s.input.amountUi ? Number(s.input.amountUi) : null,
206
- leverage: s.input.leverage ? Number(s.input.leverage) : null,
207
- slippageBps: s.input.slippageBps ? Number(s.input.slippageBps) : null,
208
- openPosition: s.input.openPosition
209
- ? Boolean(s.input.openPosition)
210
- : null,
211
- closePosition: s.input.closePosition
212
- ? Boolean(s.input.closePosition)
213
- : null,
135
+ // get tx summary for each account and group them
136
+ const summaryByAccount = new Map<string, ClendAccountTxSummary[]>();
137
+ if (getClendAccountSummary && jsonRawResponse.summary) {
138
+ for (const s of jsonRawResponse.summary) {
139
+ const accountAddress = new web3.PublicKey(s.clendAccount).toBase58();
140
+ if (!summaryByAccount.has(accountAddress)) {
141
+ summaryByAccount.set(accountAddress, []);
142
+ }
143
+
144
+ const txSummary: ClendAccountTxSummary = {
145
+ txSig: s.txSig,
146
+ time: s.time,
147
+ clendAccount: new web3.PublicKey(s.clendAccount),
148
+ clendAccountAuthority: new web3.PublicKey(s.clendAccountAuthority),
149
+ clendGroup: new web3.PublicKey(s.clendGroup),
150
+ action: s.action,
151
+ input: undefined,
152
+ events: [],
214
153
  };
215
- txSummary.input = input;
154
+
155
+ // parse inputs if they exist
156
+ if (s.input) {
157
+ const input: UserRequest = {
158
+ apiPath: s.input.apiPath,
159
+ selectedTokenMint: s.input.selectedTokenMint
160
+ ? new web3.PublicKey(s.input.selectedTokenMint)
161
+ : null,
162
+ amountUi: s.input.amountUi ? Number(s.input.amountUi) : null,
163
+ leverage: s.input.leverage ? Number(s.input.leverage) : null,
164
+ slippageBps: s.input.slippageBps
165
+ ? Number(s.input.slippageBps)
166
+ : null,
167
+ openPosition: s.input.openPosition
168
+ ? Boolean(s.input.openPosition)
169
+ : null,
170
+ closePosition: s.input.closePosition
171
+ ? Boolean(s.input.closePosition)
172
+ : null,
173
+ };
174
+ txSummary.input = input;
175
+ }
176
+
177
+ // get events for each summary
178
+ for (const event of s.events) {
179
+ let closeBalance: boolean | null = null;
180
+ if (event.closeBalance !== null) {
181
+ closeBalance = Boolean(event.closeBalance);
182
+ }
183
+
184
+ // parse amount
185
+ const clendAccountEvent: ClendAccountEvent = {
186
+ eventIndex: event.eventIndex,
187
+ eventName: event.eventName,
188
+ bank: event.bank ? new web3.PublicKey(event.bank) : null,
189
+ mint: event.mint ? new web3.PublicKey(event.mint) : null,
190
+ amount: event.amount ? new BN(event.amount, "hex") : null,
191
+ amountUi: event.amountUi ? Number(event.amountUi) : null,
192
+ value: event.value ? Number(event.value) : null,
193
+ price: event.price ? Number(event.price) : null,
194
+ closeBalance,
195
+ };
196
+ txSummary.events.push(clendAccountEvent);
197
+ }
198
+
199
+ summaryByAccount.get(accountAddress)!.push(txSummary);
216
200
  }
201
+ }
217
202
 
218
- // get events for each summary
219
- for (const event of s.events) {
220
- let closeBalance: boolean | null = null;
221
- if (event.closeBalance !== null) {
222
- closeBalance = Boolean(event.closeBalance);
203
+ // if no clend account, return undefined for clend
204
+ const clendAccounts: {
205
+ clendAccount: ClendAccount;
206
+ summary: ClendAccountTxSummary[];
207
+ }[] = [];
208
+ if (jsonRawResponse.clendAccounts) {
209
+ for (const [address, ca] of Object.entries(
210
+ jsonRawResponse.clendAccounts,
211
+ )) {
212
+ // parse lending account balances
213
+ const clendAccountBalances: ClendAccountBalance[] = [];
214
+ for (const b of (ca as any).balances) {
215
+ clendAccountBalances.push({
216
+ mint: new web3.PublicKey(b.mint),
217
+ bank: new web3.PublicKey(b.bank),
218
+ assetBalance: new BN(b.assetBalance, "hex"),
219
+ assetBalanceUi: Number(b.assetBalanceUi),
220
+ assetValue: Number(b.assetValue),
221
+ liabilityBalance: new BN(b.liabilityBalance, "hex"),
222
+ liabilityBalanceUi: Number(b.liabilityBalanceUi),
223
+ liabilityValue: Number(b.liabilityValue),
224
+ price: Number(b.price),
225
+ });
223
226
  }
224
227
 
225
- // parse amount
226
- const clendAccountEvent: ClendAccountEvent = {
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,
228
+ // create clend account
229
+ const clendAccount: ClendAccount = {
230
+ balances: clendAccountBalances,
231
+ netValue: Number((ca as any).netValue),
232
+ netApy: Number((ca as any).netApy),
233
+ pnl: Number((ca as any).pnl),
234
+ totalAssetValue: Number((ca as any).totalAssetValue),
235
+ totalLiabilityValue: Number((ca as any).totalLiabilityValue),
236
+ healthFactorNotional: Number((ca as any).healthFactorNotional),
237
+ healthFactorRiskAdjusted: Number(
238
+ (ca as any).healthFactorRiskAdjusted,
239
+ ),
240
+ notionalLeverage: Number((ca as any).notionalLeverage),
241
+ riskAdjustedLeverage: Number((ca as any).riskAdjustedLeverage),
242
+ liquidationPrice: Number((ca as any).liquidationPrice),
243
+ liquidationPriceChangePercentage: Number(
244
+ (ca as any).liquidationPriceChangePercentage,
245
+ ),
246
+ notionalLtv: Number((ca as any).notionalLtv),
247
+ riskAdjustedLtv: Number((ca as any).riskAdjustedLtv),
236
248
  };
237
- txSummary.events.push(clendAccountEvent);
249
+
250
+ const summary = summaryByAccount.get(address) || [];
251
+ clendAccounts.push({ clendAccount, summary });
238
252
  }
239
- summary.push(txSummary);
240
253
  }
241
254
 
242
255
  return {
243
256
  wallet,
244
- clendAccount,
245
- summary,
257
+ clendAccounts,
246
258
  };
247
259
  }
248
260
 
package/src/types.ts CHANGED
@@ -75,27 +75,31 @@ export interface GetGroupResponse {
75
75
  }
76
76
 
77
77
  export interface GetUserRequest {
78
- user?: web3.PublicKey;
79
- getClendAccountSummary?: boolean;
78
+ group: web3.PublicKey;
79
+ user: web3.PublicKey;
80
+ getClendAccountSummary: boolean;
80
81
  }
81
82
 
82
83
  export interface GetUserResponse {
83
84
  wallet: UserWallet;
84
- clendAccount: ClendAccount | undefined;
85
- summary: ClendAccountTxSummary[];
85
+ clendAccounts: {
86
+ clendAccount: ClendAccount;
87
+ summary: ClendAccountTxSummary[];
88
+ }[];
86
89
  }
87
90
 
88
91
  export interface UserWallet {
89
- usdcBalance: BN;
90
- usdcBalanceUi: number;
91
- jlpBalance: BN;
92
- jlpBalanceUi: number;
93
- solBalance: BN;
94
- solBalanceUi: number;
92
+ balances: UserBalance[];
93
+ }
94
+
95
+ export interface UserBalance {
96
+ mint: web3.PublicKey;
97
+ balance: BN;
98
+ balanceUi: number;
95
99
  }
96
100
 
97
101
  export interface ClendAccount {
98
- balances: Balance[];
102
+ balances: ClendAccountBalance[];
99
103
  netValue: number;
100
104
  netApy: number;
101
105
  pnl: number;
@@ -111,7 +115,7 @@ export interface ClendAccount {
111
115
  riskAdjustedLtv: number;
112
116
  }
113
117
 
114
- export interface Balance {
118
+ export interface ClendAccountBalance {
115
119
  mint: web3.PublicKey;
116
120
  bank: web3.PublicKey;
117
121
  assetBalance: BN;