@carrot-protocol/boost-http-client 0.2.15-group-refactor1-dev-875d3f7 → 0.2.15-group-refactor1-dev-966c84f

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
@@ -45,7 +45,7 @@ export declare class Client {
45
45
  * @param request Deposit leverage request parameters
46
46
  * @returns Deposit leverage operation result
47
47
  */
48
- depositLeverage(clendGroup: web3.PublicKey, inputTokenMint: web3.PublicKey, assetTokenMint: web3.PublicKey, liabilityTokenMint: web3.PublicKey, uiAmount: number, leverage: number, slippageBps: number): Promise<string>;
48
+ depositLeverage(clendGroup: web3.PublicKey, inputTokenMint: web3.PublicKey, assetTokenMint: web3.PublicKey, liabilityTokenMint: web3.PublicKey, uiAmount: number, leverage: number, slippageBps: number, clendAccount: web3.PublicKey | null): Promise<string>;
49
49
  /**
50
50
  * Adjust the leverage of an existing position
51
51
  * @param request Adjust leverage request parameters
package/dist/index.js CHANGED
@@ -184,50 +184,51 @@ class Client {
184
184
  }
185
185
  // if no clend accounts, return empty array
186
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
- // parse liquidation data if exists
193
- const liquidation = b.liquidation
194
- ? {
195
- price: Number(b.liquidation.price),
196
- changePercentage: Number(b.liquidation.changePercentage),
197
- }
198
- : null;
199
- // create clend account balance
200
- clendAccountBalances.push({
201
- mint: new anchor_1.web3.PublicKey(b.mint),
202
- bank: new anchor_1.web3.PublicKey(b.bank),
203
- assetBalance: new anchor_1.BN(b.assetBalance, "hex"),
204
- assetBalanceUi: Number(b.assetBalanceUi),
205
- assetValue: Number(b.assetValue),
206
- liabilityBalance: new anchor_1.BN(b.liabilityBalance, "hex"),
207
- liabilityBalanceUi: Number(b.liabilityBalanceUi),
208
- liabilityValue: Number(b.liabilityValue),
209
- price: Number(b.price),
210
- liquidation,
211
- });
212
- }
213
- // create clend account
214
- const clendAccount = {
215
- balances: clendAccountBalances,
216
- netValue: Number(ca.netValue),
217
- netApy: Number(ca.netApy),
218
- pnl: Number(ca.pnl),
219
- totalAssetValue: Number(ca.totalAssetValue),
220
- totalLiabilityValue: Number(ca.totalLiabilityValue),
221
- healthFactorNotional: Number(ca.healthFactorNotional),
222
- healthFactorRiskAdjusted: Number(ca.healthFactorRiskAdjusted),
223
- notionalLeverage: Number(ca.notionalLeverage),
224
- riskAdjustedLeverage: Number(ca.riskAdjustedLeverage),
225
- notionalLtv: Number(ca.notionalLtv),
226
- riskAdjustedLtv: Number(ca.riskAdjustedLtv),
227
- };
228
- const summary = summaryByAccount.get(address) || [];
229
- clendAccounts.push({ clendAccount, summary });
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
192
+ const liquidation = b.liquidation
193
+ ? {
194
+ price: Number(b.liquidation.price),
195
+ changePercentage: Number(b.liquidation.changePercentage),
196
+ }
197
+ : null;
198
+ // create clend account balance
199
+ clendAccountBalances.push({
200
+ mint: new anchor_1.web3.PublicKey(b.mint),
201
+ bank: new anchor_1.web3.PublicKey(b.bank),
202
+ assetBalance: new anchor_1.BN(b.assetBalance, "hex"),
203
+ assetBalanceUi: Number(b.assetBalanceUi),
204
+ assetValue: Number(b.assetValue),
205
+ liabilityBalance: new anchor_1.BN(b.liabilityBalance, "hex"),
206
+ liabilityBalanceUi: Number(b.liabilityBalanceUi),
207
+ liabilityValue: Number(b.liabilityValue),
208
+ price: Number(b.price),
209
+ liquidation,
210
+ });
230
211
  }
212
+ // create clend account
213
+ const clendAccountAddress = new anchor_1.web3.PublicKey(accountAndSumary.clendAccount.key);
214
+ const clendAccount = {
215
+ key: clendAccountAddress,
216
+ balances: clendAccountBalances,
217
+ netValue: Number(ca.netValue),
218
+ netApy: Number(ca.netApy),
219
+ pnl: Number(ca.pnl),
220
+ totalAssetValue: Number(ca.totalAssetValue),
221
+ totalLiabilityValue: Number(ca.totalLiabilityValue),
222
+ healthFactorNotional: Number(ca.healthFactorNotional),
223
+ healthFactorRiskAdjusted: Number(ca.healthFactorRiskAdjusted),
224
+ notionalLeverage: Number(ca.notionalLeverage),
225
+ riskAdjustedLeverage: Number(ca.riskAdjustedLeverage),
226
+ notionalLtv: Number(ca.notionalLtv),
227
+ riskAdjustedLtv: Number(ca.riskAdjustedLtv),
228
+ };
229
+ // find corresponding tx summary for account
230
+ const summary = summaryByAccount.get(clendAccountAddress.toString()) || [];
231
+ clendAccounts.push({ clendAccount, summary });
231
232
  }
232
233
  return {
233
234
  wallet,
@@ -271,14 +272,15 @@ class Client {
271
272
  * @param request Deposit leverage request parameters
272
273
  * @returns Deposit leverage operation result
273
274
  */
274
- async depositLeverage(clendGroup, inputTokenMint, assetTokenMint, liabilityTokenMint, uiAmount, leverage, slippageBps) {
275
- if (!inputTokenMint.equals(assetTokenMint) ||
275
+ async depositLeverage(clendGroup, inputTokenMint, assetTokenMint, liabilityTokenMint, uiAmount, leverage, slippageBps, clendAccount) {
276
+ if (!inputTokenMint.equals(assetTokenMint) &&
276
277
  !inputTokenMint.equals(liabilityTokenMint)) {
277
278
  throw new Error("Input mint must be the same as the asset or liability mint");
278
279
  }
279
280
  const req = {
280
281
  owner: this.address(),
281
282
  clendGroup,
283
+ clendAccount,
282
284
  inputTokenMint,
283
285
  assetTokenMint,
284
286
  liabilityTokenMint,
package/dist/types.d.ts CHANGED
@@ -9,6 +9,7 @@ export interface SendRequest {
9
9
  export interface DepositLeverageRequest {
10
10
  owner: web3.PublicKey;
11
11
  clendGroup: web3.PublicKey;
12
+ clendAccount: web3.PublicKey | null;
12
13
  inputTokenMint: web3.PublicKey;
13
14
  assetTokenMint: web3.PublicKey;
14
15
  liabilityTokenMint: web3.PublicKey;
@@ -85,6 +86,7 @@ export interface UserBalance {
85
86
  balanceUi: number;
86
87
  }
87
88
  export interface ClendAccount {
89
+ key: web3.PublicKey;
88
90
  balances: ClendAccountBalance[];
89
91
  netValue: number;
90
92
  netApy: number;
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-875d3f7",
3
+ "version": "0.2.15-group-refactor1-dev-966c84f",
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
@@ -206,57 +206,57 @@ export class Client {
206
206
  clendAccount: ClendAccount;
207
207
  summary: ClendAccountTxSummary[];
208
208
  }[] = [];
209
- if (jsonRawResponse.clendAccounts) {
210
- for (const [address, ca] of Object.entries(
211
- jsonRawResponse.clendAccounts,
212
- )) {
213
- // parse lending account balances
214
- const clendAccountBalances: ClendAccountBalance[] = [];
215
- for (const b of (ca as any).balances) {
216
- // parse liquidation data if exists
217
- const liquidation: ClendAccountAssetLiquidation | null = b.liquidation
218
- ? {
219
- price: Number(b.liquidation.price),
220
- changePercentage: Number(b.liquidation.changePercentage),
221
- }
222
- : null;
223
-
224
- // create clend account balance
225
- clendAccountBalances.push({
226
- mint: new web3.PublicKey(b.mint),
227
- bank: new web3.PublicKey(b.bank),
228
- assetBalance: new BN(b.assetBalance, "hex"),
229
- assetBalanceUi: Number(b.assetBalanceUi),
230
- assetValue: Number(b.assetValue),
231
- liabilityBalance: new BN(b.liabilityBalance, "hex"),
232
- liabilityBalanceUi: Number(b.liabilityBalanceUi),
233
- liabilityValue: Number(b.liabilityValue),
234
- price: Number(b.price),
235
- liquidation,
236
- });
237
- }
238
-
239
- // create clend account
240
- const clendAccount: ClendAccount = {
241
- balances: clendAccountBalances,
242
- netValue: Number((ca as any).netValue),
243
- netApy: Number((ca as any).netApy),
244
- pnl: Number((ca as any).pnl),
245
- totalAssetValue: Number((ca as any).totalAssetValue),
246
- totalLiabilityValue: Number((ca as any).totalLiabilityValue),
247
- healthFactorNotional: Number((ca as any).healthFactorNotional),
248
- healthFactorRiskAdjusted: Number(
249
- (ca as any).healthFactorRiskAdjusted,
250
- ),
251
- notionalLeverage: Number((ca as any).notionalLeverage),
252
- riskAdjustedLeverage: Number((ca as any).riskAdjustedLeverage),
253
- notionalLtv: Number((ca as any).notionalLtv),
254
- riskAdjustedLtv: Number((ca as any).riskAdjustedLtv),
255
- };
256
-
257
- const summary = summaryByAccount.get(address) || [];
258
- clendAccounts.push({ clendAccount, summary });
209
+ for (const accountAndSumary of jsonRawResponse.clendAccounts) {
210
+ const clendAccountBalances: ClendAccountBalance[] = [];
211
+ const ca = accountAndSumary.clendAccount;
212
+ for (const b of ca.balances) {
213
+ // parse liquidation data if exists
214
+ const liquidation: ClendAccountAssetLiquidation | null = b.liquidation
215
+ ? {
216
+ price: Number(b.liquidation.price),
217
+ changePercentage: Number(b.liquidation.changePercentage),
218
+ }
219
+ : null;
220
+
221
+ // create clend account balance
222
+ clendAccountBalances.push({
223
+ mint: new web3.PublicKey(b.mint),
224
+ bank: new web3.PublicKey(b.bank),
225
+ assetBalance: new BN(b.assetBalance, "hex"),
226
+ assetBalanceUi: Number(b.assetBalanceUi),
227
+ assetValue: Number(b.assetValue),
228
+ liabilityBalance: new BN(b.liabilityBalance, "hex"),
229
+ liabilityBalanceUi: Number(b.liabilityBalanceUi),
230
+ liabilityValue: Number(b.liabilityValue),
231
+ price: Number(b.price),
232
+ liquidation,
233
+ });
259
234
  }
235
+
236
+ // create clend account
237
+ const clendAccountAddress = new web3.PublicKey(
238
+ accountAndSumary.clendAccount.key,
239
+ );
240
+ const clendAccount: ClendAccount = {
241
+ key: clendAccountAddress,
242
+ balances: clendAccountBalances,
243
+ netValue: Number(ca.netValue),
244
+ netApy: Number(ca.netApy),
245
+ pnl: Number(ca.pnl),
246
+ totalAssetValue: Number(ca.totalAssetValue),
247
+ totalLiabilityValue: Number(ca.totalLiabilityValue),
248
+ healthFactorNotional: Number(ca.healthFactorNotional),
249
+ healthFactorRiskAdjusted: Number(ca.healthFactorRiskAdjusted),
250
+ notionalLeverage: Number(ca.notionalLeverage),
251
+ riskAdjustedLeverage: Number(ca.riskAdjustedLeverage),
252
+ notionalLtv: Number(ca.notionalLtv),
253
+ riskAdjustedLtv: Number(ca.riskAdjustedLtv),
254
+ };
255
+
256
+ // find corresponding tx summary for account
257
+ const summary =
258
+ summaryByAccount.get(clendAccountAddress.toString()) || [];
259
+ clendAccounts.push({ clendAccount, summary });
260
260
  }
261
261
 
262
262
  return {
@@ -322,9 +322,10 @@ export class Client {
322
322
  uiAmount: number,
323
323
  leverage: number,
324
324
  slippageBps: number,
325
+ clendAccount: web3.PublicKey | null,
325
326
  ): Promise<string> {
326
327
  if (
327
- !inputTokenMint.equals(assetTokenMint) ||
328
+ !inputTokenMint.equals(assetTokenMint) &&
328
329
  !inputTokenMint.equals(liabilityTokenMint)
329
330
  ) {
330
331
  throw new Error(
@@ -335,6 +336,7 @@ export class Client {
335
336
  const req: DepositLeverageRequest = {
336
337
  owner: this.address(),
337
338
  clendGroup,
339
+ clendAccount,
338
340
  inputTokenMint,
339
341
  assetTokenMint,
340
342
  liabilityTokenMint,
package/src/types.ts CHANGED
@@ -12,6 +12,7 @@ export interface SendRequest {
12
12
  export interface DepositLeverageRequest {
13
13
  owner: web3.PublicKey;
14
14
  clendGroup: web3.PublicKey;
15
+ clendAccount: web3.PublicKey | null;
15
16
  inputTokenMint: web3.PublicKey;
16
17
  assetTokenMint: web3.PublicKey;
17
18
  liabilityTokenMint: web3.PublicKey;
@@ -99,6 +100,7 @@ export interface UserBalance {
99
100
  }
100
101
 
101
102
  export interface ClendAccount {
103
+ key: web3.PublicKey;
102
104
  balances: ClendAccountBalance[];
103
105
  netValue: number;
104
106
  netApy: number;