@carrot-protocol/boost-http-client 0.2.15 → 0.2.16-group-refactor1-dev-50c976e

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, GetUserResponse, GetGroupResponse, GetUserRequest } from "./types";
3
3
  export * from "./types";
4
4
  export * from "./utils";
5
5
  export * as Common from "@carrot-protocol/clend-common";
@@ -22,13 +22,12 @@ export declare class Client {
22
22
  * @returns Index details
23
23
  */
24
24
  index(): Promise<any>;
25
- getUser(user: web3.PublicKey, groups: web3.PublicKey[], getClendAccountSummary: boolean): Promise<GetUserResponse>;
26
25
  /**
27
- * Get all groups
28
- * @param includeBankData Whether to include bank data in the response, if not strictly necessary keep false
29
- * @returns All groups
26
+ * Get user details for a wallet
27
+ * @param user wallet public key
28
+ * @returns User details
30
29
  */
31
- getGroups(includeBankData: boolean): Promise<GetGroupsResponse>;
30
+ getUser(request: GetUserRequest): Promise<GetUserResponse>;
32
31
  /**
33
32
  * Get market details
34
33
  * @param groupAddress group public key
@@ -46,22 +45,17 @@ export declare class Client {
46
45
  * @param request Deposit leverage request parameters
47
46
  * @returns Deposit leverage operation result
48
47
  */
49
- depositLeverage(clendGroup: web3.PublicKey, clendAccount: web3.PublicKey | null, inputTokenMint: web3.PublicKey, assetTokenMint: web3.PublicKey, liabilityTokenMint: web3.PublicKey, uiAmount: number, leverage: number, slippageBps: number): Promise<string>;
48
+ depositLeverage(inputMint: web3.PublicKey, assetMint: web3.PublicKey, liabilityMint: web3.PublicKey, uiAmount: number, leverage: number, slippageBps: number): Promise<string>;
50
49
  /**
51
50
  * Adjust the leverage of an existing position
52
51
  * @param request Adjust leverage request parameters
53
52
  * @returns Adjust leverage operation result
54
53
  */
55
- adjustLeverage(clendAccount: web3.PublicKey, assetTokenMint: web3.PublicKey, liabilityTokenMint: web3.PublicKey, leverage: number, slippageBps: number): Promise<string>;
54
+ adjustLeverage(leverage: number, slippageBps: number): Promise<any>;
56
55
  /**
57
56
  * Withdraw from or close a leveraged position
58
57
  * @param request Withdraw leverage request parameters
59
58
  * @returns Withdraw leverage operation result
60
59
  */
61
- withdrawLeverage(clendAccount: web3.PublicKey, outputTokenMint: web3.PublicKey, assetTokenMint: web3.PublicKey, liabilityTokenMint: web3.PublicKey, uiAmount: number, slippageBps: number, withdrawAll: boolean): Promise<string>;
62
- /**
63
- * Withdraw emissions from a bank
64
- * @returns Withdraw emissions operation result
65
- */
66
- withdrawEmissions(): Promise<string>;
60
+ withdrawLeverage(selectedTokenMint: web3.PublicKey, uiAmount: number, slippageBps: number, withdrawAll: boolean): Promise<any>;
67
61
  }
package/dist/index.js CHANGED
@@ -99,159 +99,127 @@ class Client {
99
99
  async index() {
100
100
  return handleApiCall(() => this.http.get(""));
101
101
  }
102
- async getUser(user, groups, getClendAccountSummary) {
103
- // Make the API call to fetch the raw user data as a string.
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.
102
+ /**
103
+ * Get user details for a wallet
104
+ * @param user wallet public key
105
+ * @returns User details
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}`));
106
114
  const jsonRawResponse = JSON.parse(body);
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
- }));
115
+ // get tokens still in user wallet
114
116
  const wallet = {
115
- balances: walletBalances,
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),
116
123
  };
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) => {
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
- };
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({
136
+ 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),
149
145
  });
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),
146
+ }
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),
163
+ };
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: [],
166
176
  };
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
- });
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,
193
+ };
194
+ txSummary.input = input;
222
195
  }
223
- // C. Combine the parsed account and its summary
224
- return { clendAccount, summary };
225
- });
226
- // 3. Return the final, correctly structured response object.
227
- return {
228
- wallet,
229
- clendAccounts,
230
- };
231
- }
232
- /**
233
- * Get all groups
234
- * @param includeBankData Whether to include bank data in the response, if not strictly necessary keep false
235
- * @returns All groups
236
- */
237
- async getGroups(includeBankData) {
238
- const body = await handleApiCall(() => this.http.get(`/groups?includeBankData=${includeBankData}`));
239
- const marketJson = JSON.parse(body);
240
- const groups = [];
241
- for (const groupJson of marketJson.groups) {
242
- const group = new anchor_1.web3.PublicKey(groupJson.group);
243
- const groupName = groupJson.groupName;
244
- const banks = [];
245
- for (const bankJson of groupJson.banks) {
246
- const bank = parseBank(bankJson);
247
- banks.push(bank);
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);
201
+ }
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,
213
+ };
214
+ txSummary.events.push(clendAccountEvent);
248
215
  }
249
- groups.push({ group, groupName, banks });
216
+ summary.push(txSummary);
250
217
  }
251
- const response = {
252
- groups,
218
+ return {
219
+ wallet,
220
+ clendAccount,
221
+ summary,
253
222
  };
254
- return response;
255
223
  }
256
224
  /**
257
225
  * Get market details
@@ -261,17 +229,13 @@ class Client {
261
229
  async getGroup(groupAddress) {
262
230
  const body = await handleApiCall(() => this.http.get(`/group?group=${groupAddress.toString()}`));
263
231
  const marketJson = JSON.parse(body);
264
- const group = {
265
- group: new anchor_1.web3.PublicKey(marketJson.group.group),
266
- groupName: marketJson.group.groupName,
267
- banks: [],
268
- };
269
- for (const bankJson of marketJson.group.banks) {
232
+ const banks = [];
233
+ for (const bankJson of marketJson.banks) {
270
234
  const bank = parseBank(bankJson);
271
- group.banks.push(bank);
235
+ banks.push(bank);
272
236
  }
273
237
  const response = {
274
- group,
238
+ banks,
275
239
  };
276
240
  return response;
277
241
  }
@@ -294,18 +258,15 @@ class Client {
294
258
  * @param request Deposit leverage request parameters
295
259
  * @returns Deposit leverage operation result
296
260
  */
297
- async depositLeverage(clendGroup, clendAccount, inputTokenMint, assetTokenMint, liabilityTokenMint, uiAmount, leverage, slippageBps) {
298
- if (!inputTokenMint.equals(assetTokenMint) &&
299
- !inputTokenMint.equals(liabilityTokenMint)) {
261
+ async depositLeverage(inputMint, assetMint, liabilityMint, uiAmount, leverage, slippageBps) {
262
+ if (!inputMint.equals(assetMint) || !inputMint.equals(liabilityMint)) {
300
263
  throw new Error("Input mint must be the same as the asset or liability mint");
301
264
  }
302
265
  const req = {
303
266
  owner: this.address(),
304
- clendGroup,
305
- clendAccount,
306
- inputTokenMint,
307
- assetTokenMint,
308
- liabilityTokenMint,
267
+ inputMint,
268
+ assetMint,
269
+ liabilityMint,
309
270
  depositAmountUi: uiAmount,
310
271
  leverage,
311
272
  slippageBps,
@@ -320,11 +281,9 @@ class Client {
320
281
  * @param request Adjust leverage request parameters
321
282
  * @returns Adjust leverage operation result
322
283
  */
323
- async adjustLeverage(clendAccount, assetTokenMint, liabilityTokenMint, leverage, slippageBps) {
284
+ async adjustLeverage(leverage, slippageBps) {
324
285
  const req = {
325
- clendAccount,
326
- assetTokenMint,
327
- liabilityTokenMint,
286
+ owner: this.address(),
328
287
  leverage,
329
288
  slippageBps,
330
289
  };
@@ -338,12 +297,10 @@ class Client {
338
297
  * @param request Withdraw leverage request parameters
339
298
  * @returns Withdraw leverage operation result
340
299
  */
341
- async withdrawLeverage(clendAccount, outputTokenMint, assetTokenMint, liabilityTokenMint, uiAmount, slippageBps, withdrawAll) {
300
+ async withdrawLeverage(selectedTokenMint, uiAmount, slippageBps, withdrawAll) {
342
301
  const req = {
343
- clendAccount,
344
- outputTokenMint,
345
- assetTokenMint,
346
- liabilityTokenMint,
302
+ owner: this.address(),
303
+ selectedTokenMint,
347
304
  withdrawAmountUi: uiAmount,
348
305
  slippageBps,
349
306
  withdrawAll,
@@ -353,21 +310,16 @@ class Client {
353
310
  const txSig = await this.send(withdrawLeverageResponse.unsignedBase64Tx, withdrawLeverageResponse.userRequestId);
354
311
  return txSig;
355
312
  }
356
- /**
357
- * Withdraw emissions from a bank
358
- * @returns Withdraw emissions operation result
359
- */
360
- async withdrawEmissions() {
361
- const req = {
362
- owner: this.address(),
363
- };
364
- const body = await handleApiCall(() => this.http.post("emissions/withdraw", JSON.stringify(req)));
365
- const withdrawEmissionsResponse = JSON.parse(body);
366
- const txSig = await this.send(withdrawEmissionsResponse.unsignedBase64Tx, withdrawEmissionsResponse.userRequestId);
367
- return txSig;
368
- }
369
313
  }
370
314
  exports.Client = Client;
315
+ function handleStatusCode(statusCode) {
316
+ switch (statusCode) {
317
+ case 200:
318
+ break;
319
+ default:
320
+ throw new Error(`unexpected status code: ${statusCode}`);
321
+ }
322
+ }
371
323
  // Helper function to handle API calls
372
324
  async function handleApiCall(call) {
373
325
  try {
@@ -392,17 +344,6 @@ function getDummyProvider() {
392
344
  });
393
345
  }
394
346
  function parseBank(bankJson) {
395
- let bankEmissions = null;
396
- if (bankJson.emissions) {
397
- bankEmissions = {
398
- emissionsMode: bankJson.emissions.emissionsMode,
399
- emissionsApy: Number(bankJson.emissions.emissionsApy),
400
- emissionsMint: new anchor_1.web3.PublicKey(bankJson.emissions.emissionsMint),
401
- emissionsTokenPrice: Number(bankJson.emissions.emissionsTokenPrice),
402
- emissionsRate: new anchor_1.BN(bankJson.emissions.emissionsRate, "hex"),
403
- emissionsRemainingUi: Number(bankJson.emissions.emissionsRemainingUi),
404
- };
405
- }
406
347
  return {
407
348
  mint: new anchor_1.web3.PublicKey(bankJson.mint),
408
349
  key: new anchor_1.web3.PublicKey(bankJson.key),
@@ -416,7 +357,6 @@ function parseBank(bankJson) {
416
357
  assetMaintWeight: Number(bankJson.assetMaintWeight),
417
358
  totalAssetShares: Number(bankJson.totalAssetShares),
418
359
  assetShareValue: Number(bankJson.assetShareValue),
419
- tokenYieldApy: Number(bankJson.tokenYieldApy),
420
360
  liabilityAmount: new anchor_1.BN(bankJson.liabilityAmount, "hex"),
421
361
  liabilityAmountUi: Number(bankJson.liabilityAmountUi),
422
362
  liabilityInitWeight: Number(bankJson.liabilityInitWeight),
@@ -428,6 +368,5 @@ function parseBank(bankJson) {
428
368
  depositLimitUi: Number(bankJson.depositLimitUi),
429
369
  borrowLimit: new anchor_1.BN(bankJson.borrowLimit, "hex"),
430
370
  borrowLimitUi: Number(bankJson.borrowLimitUi),
431
- emissions: bankEmissions,
432
371
  };
433
372
  }
package/dist/types.d.ts CHANGED
@@ -8,11 +8,9 @@ export interface SendRequest {
8
8
  */
9
9
  export interface DepositLeverageRequest {
10
10
  owner: web3.PublicKey;
11
- clendGroup: web3.PublicKey;
12
- clendAccount: web3.PublicKey | null;
13
- inputTokenMint: web3.PublicKey;
14
- assetTokenMint: web3.PublicKey;
15
- liabilityTokenMint: web3.PublicKey;
11
+ inputMint: web3.PublicKey;
12
+ assetMint: web3.PublicKey;
13
+ liabilityMint: web3.PublicKey;
16
14
  depositAmountUi: number;
17
15
  leverage: number;
18
16
  slippageBps: number;
@@ -28,9 +26,7 @@ export interface DepositLeverageResponse {
28
26
  * Request to adjust the leverage of an existing position
29
27
  */
30
28
  export interface AdjustLeverageRequest {
31
- clendAccount: web3.PublicKey;
32
- assetTokenMint: web3.PublicKey;
33
- liabilityTokenMint: web3.PublicKey;
29
+ owner: web3.PublicKey;
34
30
  leverage: number;
35
31
  slippageBps: number;
36
32
  }
@@ -45,10 +41,8 @@ export interface AdjustLeverageResponse {
45
41
  * Request to withdraw from a leveraged position
46
42
  */
47
43
  export interface WithdrawLeverageRequest {
48
- clendAccount: web3.PublicKey;
49
- outputTokenMint: web3.PublicKey;
50
- assetTokenMint: web3.PublicKey;
51
- liabilityTokenMint: web3.PublicKey;
44
+ owner: web3.PublicKey;
45
+ selectedTokenMint: web3.PublicKey;
52
46
  withdrawAmountUi: number;
53
47
  slippageBps: number;
54
48
  withdrawAll: boolean;
@@ -60,88 +54,52 @@ export interface WithdrawLeverageResponse {
60
54
  userRequestId: string;
61
55
  unsignedBase64Tx: string;
62
56
  }
63
- /**
64
- * Request to withdraw emissions from a bank
65
- */
66
- export interface WithdrawEmissionsRequest {
67
- owner: web3.PublicKey;
68
- }
69
- /**
70
- * Response for withdraw emissions operation
71
- */
72
- export interface WithdrawEmissionsResponse {
73
- userRequestId: string;
74
- unsignedBase64Tx: string;
75
- }
76
- export interface GetGroupsResponse {
77
- groups: GroupAndBanks[];
78
- }
79
57
  export interface GetGroupResponse {
80
- group: GroupAndBanks;
81
- }
82
- export interface GroupAndBanks {
83
- group: web3.PublicKey;
84
- groupName: string;
85
58
  banks: Bank[];
86
59
  }
87
60
  export interface GetUserRequest {
88
- groups: web3.PublicKey[];
89
- user: web3.PublicKey;
90
- getClendAccountSummary: boolean;
61
+ user?: web3.PublicKey;
62
+ getClendAccountSummary?: boolean;
91
63
  }
92
64
  export interface GetUserResponse {
93
65
  wallet: UserWallet;
94
- clendAccounts: {
95
- clendAccount: ClendAccount;
96
- summary: ClendAccountTxSummary[];
97
- }[];
66
+ clendAccount: ClendAccount | undefined;
67
+ summary: ClendAccountTxSummary[];
98
68
  }
99
69
  export interface UserWallet {
100
- balances: UserBalance[];
101
- }
102
- export interface UserBalance {
103
- mint: web3.PublicKey;
104
- balance: BN;
105
- balanceUi: number;
70
+ usdcBalance: BN;
71
+ usdcBalanceUi: number;
72
+ jlpBalance: BN;
73
+ jlpBalanceUi: number;
74
+ solBalance: BN;
75
+ solBalanceUi: number;
106
76
  }
107
77
  export interface ClendAccount {
108
- key: web3.PublicKey;
109
- group: web3.PublicKey;
110
- balances: ClendAccountBalance[];
78
+ balances: Balance[];
111
79
  netValue: number;
112
80
  netApy: number;
113
81
  pnl: number;
114
- totalEmissionsApy: number;
115
82
  totalAssetValue: number;
116
83
  totalLiabilityValue: number;
117
84
  healthFactorNotional: number;
118
85
  healthFactorRiskAdjusted: number;
119
86
  notionalLeverage: number;
120
87
  riskAdjustedLeverage: number;
88
+ liquidationPrice: number;
89
+ liquidationPriceChangePercentage: number;
121
90
  notionalLtv: number;
122
91
  riskAdjustedLtv: number;
123
92
  }
124
- export interface ClendAccountBalance {
93
+ export interface Balance {
125
94
  mint: web3.PublicKey;
126
95
  bank: web3.PublicKey;
127
- tokenYieldApy: number;
128
96
  assetBalance: BN;
129
97
  assetBalanceUi: number;
130
98
  assetValue: number;
131
- assetEmissionsApy: number;
132
99
  liabilityBalance: BN;
133
100
  liabilityBalanceUi: number;
134
101
  liabilityValue: number;
135
- liabilityBorrowCostApy: number;
136
- liabilityEmissionsApy: number;
137
- emissionsOutstandingAndUnclaimed: BN;
138
- emissionsOutstandingAndUnclaimedUi: number;
139
102
  price: number;
140
- liquidation: ClendAccountAssetLiquidation | null;
141
- }
142
- export interface ClendAccountAssetLiquidation {
143
- price: number;
144
- changePercentage: number;
145
103
  }
146
104
  export interface GetBankResponse {
147
105
  bank: Bank;
@@ -150,7 +108,6 @@ export interface Bank {
150
108
  group: web3.PublicKey;
151
109
  key: web3.PublicKey;
152
110
  mint: web3.PublicKey;
153
- tokenYieldApy: number;
154
111
  supplyApy: number;
155
112
  borrowApy: number;
156
113
  utilizationRate: number;
@@ -171,17 +128,7 @@ export interface Bank {
171
128
  depositLimitUi: number;
172
129
  borrowLimit: BN;
173
130
  borrowLimitUi: number;
174
- emissions: BankEmissions | null;
175
- }
176
- export interface BankEmissions {
177
- emissionsMode: BankEmissionsMode;
178
- emissionsApy: number;
179
- emissionsMint: web3.PublicKey;
180
- emissionsTokenPrice: number;
181
- emissionsRate: BN;
182
- emissionsRemainingUi: number;
183
131
  }
184
- export type BankEmissionsMode = "LENDING_ONLY" | "BORROW_ONLY" | "LENDING_AND_BORROWING";
185
132
  export interface ClendAccountTxSummary {
186
133
  txSig: string;
187
134
  time: Date;
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  import { web3 } from "@coral-xyz/anchor";
2
2
  import { ClendAccount } from "./types";
3
3
  export declare function netValueInToken(clendAccount: ClendAccount, tokenMint: web3.PublicKey): number;
4
+ export declare function getProductionGroups(): web3.PublicKey[];
5
+ export declare function getStagingGroups(): web3.PublicKey[];
package/dist/utils.js CHANGED
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.netValueInToken = netValueInToken;
4
+ exports.getProductionGroups = getProductionGroups;
5
+ exports.getStagingGroups = getStagingGroups;
6
+ const anchor_1 = require("@coral-xyz/anchor");
4
7
  // returns the net value of the clend account in a given tokens price
5
8
  function netValueInToken(clendAccount, tokenMint) {
6
9
  const clendAccountTokenBalance = clendAccount.balances.find((balance) => balance.mint.equals(tokenMint));
@@ -9,3 +12,9 @@ function netValueInToken(clendAccount, tokenMint) {
9
12
  }
10
13
  return clendAccount.netValue / clendAccountTokenBalance.price;
11
14
  }
15
+ function getProductionGroups() {
16
+ return [new anchor_1.web3.PublicKey("9bCWxAXFdWQ9GcZTSU3G636T6EyGXYMgaWR74yc7QZz8")];
17
+ }
18
+ function getStagingGroups() {
19
+ return [new anchor_1.web3.PublicKey("HKMDWLBK7yUmorSx9argg2rYcro6KoWf41N57FccKRP5")];
20
+ }