@everstake/wallet-sdk-hysp-solana 1.1.0 → 1.1.2

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.mts CHANGED
@@ -211,6 +211,13 @@ declare class HyspSolana extends Blockchain {
211
211
  * @returns Returns a promise that resolves with the user's token balance amount.
212
212
  */
213
213
  getUserBalance(userAddress: Address): Promise<ApiResponse<Decimal>>;
214
+ /**
215
+ * Fetches the maximum available liquidity amount in the vaults allocations' reserves.
216
+ *
217
+ * @throws Throws an error if there's an issue loading vault's state or reserves.
218
+ *
219
+ * @returns Returns a promise that resolves with the maximum available liquidity amount as Decimal.
220
+ */
214
221
  getVaultLiquidityAmount(): Promise<ApiResponse<Decimal>>;
215
222
  /**
216
223
  * Creates a deposit transaction to the vault.
package/dist/index.d.ts CHANGED
@@ -211,6 +211,13 @@ declare class HyspSolana extends Blockchain {
211
211
  * @returns Returns a promise that resolves with the user's token balance amount.
212
212
  */
213
213
  getUserBalance(userAddress: Address): Promise<ApiResponse<Decimal>>;
214
+ /**
215
+ * Fetches the maximum available liquidity amount in the vaults allocations' reserves.
216
+ *
217
+ * @throws Throws an error if there's an issue loading vault's state or reserves.
218
+ *
219
+ * @returns Returns a promise that resolves with the maximum available liquidity amount as Decimal.
220
+ */
214
221
  getVaultLiquidityAmount(): Promise<ApiResponse<Decimal>>;
215
222
  /**
216
223
  * Creates a deposit transaction to the vault.
package/dist/index.js CHANGED
@@ -251,12 +251,27 @@ var HyspSolana = class extends Blockchain {
251
251
  throw this.handleError("GET_BALANCE_ERROR", error);
252
252
  }
253
253
  }
254
+ /**
255
+ * Fetches the maximum available liquidity amount in the vaults allocations' reserves.
256
+ *
257
+ * @throws Throws an error if there's an issue loading vault's state or reserves.
258
+ *
259
+ * @returns Returns a promise that resolves with the maximum available liquidity amount as Decimal.
260
+ */
254
261
  async getVaultLiquidityAmount() {
255
262
  try {
256
263
  const state = await this.vault.getState();
257
- const liquidityAmount = state.tokenAvailable / 10 ** state.tokenMintDecimals;
264
+ const reserves = await this.vault.client.loadVaultReserves(state);
265
+ const mintFactor = new import_decimal.Decimal(10).pow(
266
+ new import_decimal.Decimal(state.tokenMintDecimals.toString())
267
+ );
268
+ let totalLiquiditty = new import_decimal.Decimal(state.tokenAvailable.toString());
269
+ for (const [, reserve] of reserves) {
270
+ const reserveLiquidity = reserve.getLiquidityAvailableAmount();
271
+ totalLiquiditty = totalLiquiditty.add(reserveLiquidity);
272
+ }
258
273
  return {
259
- result: this.convertToDecimal(liquidityAmount.toString())
274
+ result: totalLiquiditty.div(mintFactor)
260
275
  };
261
276
  } catch (error) {
262
277
  throw this.handleError("VAULT_LOAD_ERROR", error);
@@ -282,6 +297,7 @@ var HyspSolana = class extends Blockchain {
282
297
  } else {
283
298
  decimalAmount = this.convertToDecimal(amount);
284
299
  }
300
+ const vaultState = await this.vault.getState();
285
301
  const depositIxs = await this.vault.depositIxs(signer, decimalAmount);
286
302
  const mergedDepositIxs = [];
287
303
  depositIxs.depositIxs.forEach((instruction) => {
@@ -293,7 +309,8 @@ var HyspSolana = class extends Blockchain {
293
309
  const transactionMessage = await this.buildTx(
294
310
  userAddress.toString(),
295
311
  mergedDepositIxs,
296
- params
312
+ params,
313
+ [vaultState.vaultLookupTable]
297
314
  );
298
315
  return {
299
316
  result: transactionMessage
@@ -322,6 +339,7 @@ var HyspSolana = class extends Blockchain {
322
339
  } else {
323
340
  sharesDecimal = this.convertToDecimal(sharesAmount);
324
341
  }
342
+ const vaultState = await this.vault.getState();
325
343
  const withdrawIxs = await this.vault.withdrawIxs(signer, sharesDecimal);
326
344
  const mergedWithdrawIxs = [];
327
345
  withdrawIxs.unstakeFromFarmIfNeededIxs.forEach((instruction) => {
@@ -336,7 +354,8 @@ var HyspSolana = class extends Blockchain {
336
354
  const transactionMessage = await this.buildTx(
337
355
  userAddress.toString(),
338
356
  mergedWithdrawIxs,
339
- params
357
+ params,
358
+ [vaultState.vaultLookupTable]
340
359
  );
341
360
  return {
342
361
  result: transactionMessage
@@ -345,7 +364,7 @@ var HyspSolana = class extends Blockchain {
345
364
  throw this.handleError("WITHDRAW_ERROR", error);
346
365
  }
347
366
  }
348
- async buildTx(sender, instructions, params) {
367
+ async buildTx(sender, instructions, params, lookupTableAddresses) {
349
368
  let transactionMessage = (0, import_kit2.pipe)(
350
369
  (0, import_kit2.createTransactionMessage)({ version: 0 }),
351
370
  (tx) => (0, import_kit2.setTransactionMessageFeePayer)((0, import_kit2.address)(sender), tx)
@@ -384,6 +403,16 @@ var HyspSolana = class extends Blockchain {
384
403
  );
385
404
  }
386
405
  }
406
+ if (lookupTableAddresses && lookupTableAddresses.length > 0) {
407
+ const fetchedTables = await (0, import_kit2.fetchAddressesForLookupTables)(
408
+ lookupTableAddresses,
409
+ this.connection
410
+ );
411
+ transactionMessage = (0, import_kit2.compressTransactionMessageUsingAddressLookupTables)(
412
+ transactionMessage,
413
+ fetchedTables
414
+ );
415
+ }
387
416
  const finalLatestBlockhash = params?.finalLatestBlockhash || (await this.connection.getLatestBlockhash().send()).value;
388
417
  const txMessageWithBlockhashLifetime = (0, import_kit2.setTransactionMessageLifetimeUsingBlockhash)(
389
418
  finalLatestBlockhash,
package/dist/index.mjs CHANGED
@@ -8,7 +8,9 @@ import {
8
8
  setTransactionMessageFeePayer,
9
9
  setTransactionMessageLifetimeUsingBlockhash,
10
10
  appendTransactionMessageInstruction,
11
- prependTransactionMessageInstruction
11
+ prependTransactionMessageInstruction,
12
+ compressTransactionMessageUsingAddressLookupTables,
13
+ fetchAddressesForLookupTables
12
14
  } from "@solana/kit";
13
15
  import {
14
16
  getSetComputeUnitLimitInstruction,
@@ -234,12 +236,27 @@ var HyspSolana = class extends Blockchain {
234
236
  throw this.handleError("GET_BALANCE_ERROR", error);
235
237
  }
236
238
  }
239
+ /**
240
+ * Fetches the maximum available liquidity amount in the vaults allocations' reserves.
241
+ *
242
+ * @throws Throws an error if there's an issue loading vault's state or reserves.
243
+ *
244
+ * @returns Returns a promise that resolves with the maximum available liquidity amount as Decimal.
245
+ */
237
246
  async getVaultLiquidityAmount() {
238
247
  try {
239
248
  const state = await this.vault.getState();
240
- const liquidityAmount = state.tokenAvailable / 10 ** state.tokenMintDecimals;
249
+ const reserves = await this.vault.client.loadVaultReserves(state);
250
+ const mintFactor = new Decimal(10).pow(
251
+ new Decimal(state.tokenMintDecimals.toString())
252
+ );
253
+ let totalLiquiditty = new Decimal(state.tokenAvailable.toString());
254
+ for (const [, reserve] of reserves) {
255
+ const reserveLiquidity = reserve.getLiquidityAvailableAmount();
256
+ totalLiquiditty = totalLiquiditty.add(reserveLiquidity);
257
+ }
241
258
  return {
242
- result: this.convertToDecimal(liquidityAmount.toString())
259
+ result: totalLiquiditty.div(mintFactor)
243
260
  };
244
261
  } catch (error) {
245
262
  throw this.handleError("VAULT_LOAD_ERROR", error);
@@ -265,6 +282,7 @@ var HyspSolana = class extends Blockchain {
265
282
  } else {
266
283
  decimalAmount = this.convertToDecimal(amount);
267
284
  }
285
+ const vaultState = await this.vault.getState();
268
286
  const depositIxs = await this.vault.depositIxs(signer, decimalAmount);
269
287
  const mergedDepositIxs = [];
270
288
  depositIxs.depositIxs.forEach((instruction) => {
@@ -276,7 +294,8 @@ var HyspSolana = class extends Blockchain {
276
294
  const transactionMessage = await this.buildTx(
277
295
  userAddress.toString(),
278
296
  mergedDepositIxs,
279
- params
297
+ params,
298
+ [vaultState.vaultLookupTable]
280
299
  );
281
300
  return {
282
301
  result: transactionMessage
@@ -305,6 +324,7 @@ var HyspSolana = class extends Blockchain {
305
324
  } else {
306
325
  sharesDecimal = this.convertToDecimal(sharesAmount);
307
326
  }
327
+ const vaultState = await this.vault.getState();
308
328
  const withdrawIxs = await this.vault.withdrawIxs(signer, sharesDecimal);
309
329
  const mergedWithdrawIxs = [];
310
330
  withdrawIxs.unstakeFromFarmIfNeededIxs.forEach((instruction) => {
@@ -319,7 +339,8 @@ var HyspSolana = class extends Blockchain {
319
339
  const transactionMessage = await this.buildTx(
320
340
  userAddress.toString(),
321
341
  mergedWithdrawIxs,
322
- params
342
+ params,
343
+ [vaultState.vaultLookupTable]
323
344
  );
324
345
  return {
325
346
  result: transactionMessage
@@ -328,7 +349,7 @@ var HyspSolana = class extends Blockchain {
328
349
  throw this.handleError("WITHDRAW_ERROR", error);
329
350
  }
330
351
  }
331
- async buildTx(sender, instructions, params) {
352
+ async buildTx(sender, instructions, params, lookupTableAddresses) {
332
353
  let transactionMessage = pipe(
333
354
  createTransactionMessage({ version: 0 }),
334
355
  (tx) => setTransactionMessageFeePayer(address2(sender), tx)
@@ -367,6 +388,16 @@ var HyspSolana = class extends Blockchain {
367
388
  );
368
389
  }
369
390
  }
391
+ if (lookupTableAddresses && lookupTableAddresses.length > 0) {
392
+ const fetchedTables = await fetchAddressesForLookupTables(
393
+ lookupTableAddresses,
394
+ this.connection
395
+ );
396
+ transactionMessage = compressTransactionMessageUsingAddressLookupTables(
397
+ transactionMessage,
398
+ fetchedTables
399
+ );
400
+ }
370
401
  const finalLatestBlockhash = params?.finalLatestBlockhash || (await this.connection.getLatestBlockhash().send()).value;
371
402
  const txMessageWithBlockhashLifetime = setTransactionMessageLifetimeUsingBlockhash(
372
403
  finalLatestBlockhash,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@everstake/wallet-sdk-hysp-solana",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "HYSP Solana - Everstake Wallet SDK",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "homepage": "https://github.com/everstake/wallet-sdk#readme",
44
44
  "dependencies": {
45
- "@kamino-finance/klend-sdk": "^7.2.4",
45
+ "@kamino-finance/klend-sdk": "^7.3.4",
46
46
  "@solana-program/compute-budget": "^0.7.0",
47
47
  "@solana/kit": "^3.0.3",
48
48
  "decimal.js": "^10.6.0"
package/src/hysp.ts CHANGED
@@ -14,6 +14,8 @@ import {
14
14
  setTransactionMessageLifetimeUsingBlockhash,
15
15
  appendTransactionMessageInstruction,
16
16
  prependTransactionMessageInstruction,
17
+ compressTransactionMessageUsingAddressLookupTables,
18
+ fetchAddressesForLookupTables,
17
19
  TransactionMessage,
18
20
  TransactionMessageWithLifetime,
19
21
  Rpc,
@@ -178,15 +180,29 @@ export class HyspSolana extends Blockchain {
178
180
  throw this.handleError('GET_BALANCE_ERROR', error);
179
181
  }
180
182
  }
181
-
183
+ /**
184
+ * Fetches the maximum available liquidity amount in the vaults allocations' reserves.
185
+ *
186
+ * @throws Throws an error if there's an issue loading vault's state or reserves.
187
+ *
188
+ * @returns Returns a promise that resolves with the maximum available liquidity amount as Decimal.
189
+ */
182
190
  async getVaultLiquidityAmount(): Promise<ApiResponse<Decimal>> {
183
191
  try {
184
192
  const state = await this.vault.getState();
185
- const liquidityAmount =
186
- state.tokenAvailable / 10 ** state.tokenMintDecimals;
193
+ const reserves = await this.vault.client.loadVaultReserves(state);
194
+
195
+ const mintFactor = new Decimal(10).pow(
196
+ new Decimal(state.tokenMintDecimals.toString()),
197
+ );
198
+ let totalLiquiditty = new Decimal(state.tokenAvailable.toString());
199
+ for (const [, reserve] of reserves) {
200
+ const reserveLiquidity = reserve.getLiquidityAvailableAmount();
201
+ totalLiquiditty = totalLiquiditty.add(reserveLiquidity);
202
+ }
187
203
 
188
204
  return {
189
- result: this.convertToDecimal(liquidityAmount.toString()),
205
+ result: totalLiquiditty.div(mintFactor),
190
206
  };
191
207
  } catch (error) {
192
208
  throw this.handleError('VAULT_LOAD_ERROR', error);
@@ -218,6 +234,7 @@ export class HyspSolana extends Blockchain {
218
234
  decimalAmount = this.convertToDecimal(amount);
219
235
  }
220
236
 
237
+ const vaultState = await this.vault.getState();
221
238
  const depositIxs = await this.vault.depositIxs(signer, decimalAmount);
222
239
 
223
240
  const mergedDepositIxs: Instruction[] = [];
@@ -233,6 +250,7 @@ export class HyspSolana extends Blockchain {
233
250
  userAddress.toString(),
234
251
  mergedDepositIxs,
235
252
  params,
253
+ [vaultState.vaultLookupTable],
236
254
  );
237
255
 
238
256
  return {
@@ -268,6 +286,7 @@ export class HyspSolana extends Blockchain {
268
286
  sharesDecimal = this.convertToDecimal(sharesAmount);
269
287
  }
270
288
 
289
+ const vaultState = await this.vault.getState();
271
290
  const withdrawIxs = await this.vault.withdrawIxs(signer, sharesDecimal);
272
291
 
273
292
  const mergedWithdrawIxs: Instruction[] = [];
@@ -286,6 +305,7 @@ export class HyspSolana extends Blockchain {
286
305
  userAddress.toString(),
287
306
  mergedWithdrawIxs,
288
307
  params,
308
+ [vaultState.vaultLookupTable],
289
309
  );
290
310
 
291
311
  return {
@@ -300,6 +320,7 @@ export class HyspSolana extends Blockchain {
300
320
  sender: string,
301
321
  instructions: Instruction[],
302
322
  params?: Params,
323
+ lookupTableAddresses?: Address[],
303
324
  ): Promise<TransactionMessageWithLifetime> {
304
325
  let transactionMessage: TransactionMessage = pipe(
305
326
  createTransactionMessage({ version: 0 }),
@@ -351,6 +372,17 @@ export class HyspSolana extends Blockchain {
351
372
  }
352
373
  }
353
374
 
375
+ if (lookupTableAddresses && lookupTableAddresses.length > 0) {
376
+ const fetchedTables = await fetchAddressesForLookupTables(
377
+ lookupTableAddresses,
378
+ this.connection,
379
+ );
380
+ transactionMessage = compressTransactionMessageUsingAddressLookupTables(
381
+ transactionMessage,
382
+ fetchedTables,
383
+ );
384
+ }
385
+
354
386
  const finalLatestBlockhash =
355
387
  params?.finalLatestBlockhash ||
356
388
  (await this.connection.getLatestBlockhash().send()).value;