@everstake/wallet-sdk-hysp-solana 1.0.1 → 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,14 @@ 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
+ */
221
+ getVaultLiquidityAmount(): Promise<ApiResponse<Decimal>>;
214
222
  /**
215
223
  * Creates a deposit transaction to the vault.
216
224
  *
package/dist/index.d.ts CHANGED
@@ -211,6 +211,14 @@ 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
+ */
221
+ getVaultLiquidityAmount(): Promise<ApiResponse<Decimal>>;
214
222
  /**
215
223
  * Creates a deposit transaction to the vault.
216
224
  *
package/dist/index.js CHANGED
@@ -251,6 +251,32 @@ 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
+ */
261
+ async getVaultLiquidityAmount() {
262
+ try {
263
+ const state = await this.vault.getState();
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
+ }
273
+ return {
274
+ result: totalLiquiditty.div(mintFactor)
275
+ };
276
+ } catch (error) {
277
+ throw this.handleError("VAULT_LOAD_ERROR", error);
278
+ }
279
+ }
254
280
  /**
255
281
  * Creates a deposit transaction to the vault.
256
282
  *
@@ -271,6 +297,7 @@ var HyspSolana = class extends Blockchain {
271
297
  } else {
272
298
  decimalAmount = this.convertToDecimal(amount);
273
299
  }
300
+ const vaultState = await this.vault.getState();
274
301
  const depositIxs = await this.vault.depositIxs(signer, decimalAmount);
275
302
  const mergedDepositIxs = [];
276
303
  depositIxs.depositIxs.forEach((instruction) => {
@@ -282,7 +309,8 @@ var HyspSolana = class extends Blockchain {
282
309
  const transactionMessage = await this.buildTx(
283
310
  userAddress.toString(),
284
311
  mergedDepositIxs,
285
- params
312
+ params,
313
+ [vaultState.vaultLookupTable]
286
314
  );
287
315
  return {
288
316
  result: transactionMessage
@@ -311,6 +339,7 @@ var HyspSolana = class extends Blockchain {
311
339
  } else {
312
340
  sharesDecimal = this.convertToDecimal(sharesAmount);
313
341
  }
342
+ const vaultState = await this.vault.getState();
314
343
  const withdrawIxs = await this.vault.withdrawIxs(signer, sharesDecimal);
315
344
  const mergedWithdrawIxs = [];
316
345
  withdrawIxs.unstakeFromFarmIfNeededIxs.forEach((instruction) => {
@@ -325,7 +354,8 @@ var HyspSolana = class extends Blockchain {
325
354
  const transactionMessage = await this.buildTx(
326
355
  userAddress.toString(),
327
356
  mergedWithdrawIxs,
328
- params
357
+ params,
358
+ [vaultState.vaultLookupTable]
329
359
  );
330
360
  return {
331
361
  result: transactionMessage
@@ -334,7 +364,7 @@ var HyspSolana = class extends Blockchain {
334
364
  throw this.handleError("WITHDRAW_ERROR", error);
335
365
  }
336
366
  }
337
- async buildTx(sender, instructions, params) {
367
+ async buildTx(sender, instructions, params, lookupTableAddresses) {
338
368
  let transactionMessage = (0, import_kit2.pipe)(
339
369
  (0, import_kit2.createTransactionMessage)({ version: 0 }),
340
370
  (tx) => (0, import_kit2.setTransactionMessageFeePayer)((0, import_kit2.address)(sender), tx)
@@ -373,6 +403,16 @@ var HyspSolana = class extends Blockchain {
373
403
  );
374
404
  }
375
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
+ }
376
416
  const finalLatestBlockhash = params?.finalLatestBlockhash || (await this.connection.getLatestBlockhash().send()).value;
377
417
  const txMessageWithBlockhashLifetime = (0, import_kit2.setTransactionMessageLifetimeUsingBlockhash)(
378
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,6 +236,32 @@ 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
+ */
246
+ async getVaultLiquidityAmount() {
247
+ try {
248
+ const state = await this.vault.getState();
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
+ }
258
+ return {
259
+ result: totalLiquiditty.div(mintFactor)
260
+ };
261
+ } catch (error) {
262
+ throw this.handleError("VAULT_LOAD_ERROR", error);
263
+ }
264
+ }
237
265
  /**
238
266
  * Creates a deposit transaction to the vault.
239
267
  *
@@ -254,6 +282,7 @@ var HyspSolana = class extends Blockchain {
254
282
  } else {
255
283
  decimalAmount = this.convertToDecimal(amount);
256
284
  }
285
+ const vaultState = await this.vault.getState();
257
286
  const depositIxs = await this.vault.depositIxs(signer, decimalAmount);
258
287
  const mergedDepositIxs = [];
259
288
  depositIxs.depositIxs.forEach((instruction) => {
@@ -265,7 +294,8 @@ var HyspSolana = class extends Blockchain {
265
294
  const transactionMessage = await this.buildTx(
266
295
  userAddress.toString(),
267
296
  mergedDepositIxs,
268
- params
297
+ params,
298
+ [vaultState.vaultLookupTable]
269
299
  );
270
300
  return {
271
301
  result: transactionMessage
@@ -294,6 +324,7 @@ var HyspSolana = class extends Blockchain {
294
324
  } else {
295
325
  sharesDecimal = this.convertToDecimal(sharesAmount);
296
326
  }
327
+ const vaultState = await this.vault.getState();
297
328
  const withdrawIxs = await this.vault.withdrawIxs(signer, sharesDecimal);
298
329
  const mergedWithdrawIxs = [];
299
330
  withdrawIxs.unstakeFromFarmIfNeededIxs.forEach((instruction) => {
@@ -308,7 +339,8 @@ var HyspSolana = class extends Blockchain {
308
339
  const transactionMessage = await this.buildTx(
309
340
  userAddress.toString(),
310
341
  mergedWithdrawIxs,
311
- params
342
+ params,
343
+ [vaultState.vaultLookupTable]
312
344
  );
313
345
  return {
314
346
  result: transactionMessage
@@ -317,7 +349,7 @@ var HyspSolana = class extends Blockchain {
317
349
  throw this.handleError("WITHDRAW_ERROR", error);
318
350
  }
319
351
  }
320
- async buildTx(sender, instructions, params) {
352
+ async buildTx(sender, instructions, params, lookupTableAddresses) {
321
353
  let transactionMessage = pipe(
322
354
  createTransactionMessage({ version: 0 }),
323
355
  (tx) => setTransactionMessageFeePayer(address2(sender), tx)
@@ -356,6 +388,16 @@ var HyspSolana = class extends Blockchain {
356
388
  );
357
389
  }
358
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
+ }
359
401
  const finalLatestBlockhash = params?.finalLatestBlockhash || (await this.connection.getLatestBlockhash().send()).value;
360
402
  const txMessageWithBlockhashLifetime = setTransactionMessageLifetimeUsingBlockhash(
361
403
  finalLatestBlockhash,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@everstake/wallet-sdk-hysp-solana",
3
- "version": "1.0.1",
3
+ "version": "1.1.2",
4
4
  "description": "HYSP Solana - Everstake Wallet SDK",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "sideEffects": false,
18
18
  "scripts": {
19
- "build": "pnpm run prebuild && tsup src/index.ts --format cjs,esm --dts",
19
+ "build": "tsup src/index.ts --format cjs,esm --dts",
20
20
  "type-check": "tsc",
21
21
  "lint": "eslint 'src/**/*.{ts,tsx}'",
22
22
  "prettier": "prettier --write 'src/**/*.{ts,tsx}'",
@@ -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,6 +180,34 @@ export class HyspSolana extends Blockchain {
178
180
  throw this.handleError('GET_BALANCE_ERROR', error);
179
181
  }
180
182
  }
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
+ */
190
+ async getVaultLiquidityAmount(): Promise<ApiResponse<Decimal>> {
191
+ try {
192
+ const state = await this.vault.getState();
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
+ }
203
+
204
+ return {
205
+ result: totalLiquiditty.div(mintFactor),
206
+ };
207
+ } catch (error) {
208
+ throw this.handleError('VAULT_LOAD_ERROR', error);
209
+ }
210
+ }
181
211
 
182
212
  /**
183
213
  * Creates a deposit transaction to the vault.
@@ -204,6 +234,7 @@ export class HyspSolana extends Blockchain {
204
234
  decimalAmount = this.convertToDecimal(amount);
205
235
  }
206
236
 
237
+ const vaultState = await this.vault.getState();
207
238
  const depositIxs = await this.vault.depositIxs(signer, decimalAmount);
208
239
 
209
240
  const mergedDepositIxs: Instruction[] = [];
@@ -219,6 +250,7 @@ export class HyspSolana extends Blockchain {
219
250
  userAddress.toString(),
220
251
  mergedDepositIxs,
221
252
  params,
253
+ [vaultState.vaultLookupTable],
222
254
  );
223
255
 
224
256
  return {
@@ -254,6 +286,7 @@ export class HyspSolana extends Blockchain {
254
286
  sharesDecimal = this.convertToDecimal(sharesAmount);
255
287
  }
256
288
 
289
+ const vaultState = await this.vault.getState();
257
290
  const withdrawIxs = await this.vault.withdrawIxs(signer, sharesDecimal);
258
291
 
259
292
  const mergedWithdrawIxs: Instruction[] = [];
@@ -272,6 +305,7 @@ export class HyspSolana extends Blockchain {
272
305
  userAddress.toString(),
273
306
  mergedWithdrawIxs,
274
307
  params,
308
+ [vaultState.vaultLookupTable],
275
309
  );
276
310
 
277
311
  return {
@@ -286,6 +320,7 @@ export class HyspSolana extends Blockchain {
286
320
  sender: string,
287
321
  instructions: Instruction[],
288
322
  params?: Params,
323
+ lookupTableAddresses?: Address[],
289
324
  ): Promise<TransactionMessageWithLifetime> {
290
325
  let transactionMessage: TransactionMessage = pipe(
291
326
  createTransactionMessage({ version: 0 }),
@@ -337,6 +372,17 @@ export class HyspSolana extends Blockchain {
337
372
  }
338
373
  }
339
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
+
340
386
  const finalLatestBlockhash =
341
387
  params?.finalLatestBlockhash ||
342
388
  (await this.connection.getLatestBlockhash().send()).value;