@kamino-finance/kliquidity-sdk 8.0.0 → 8.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kamino-finance/kliquidity-sdk",
3
- "version": "8.0.0",
3
+ "version": "8.0.2",
4
4
  "description": "Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol",
5
5
  "repository": {
6
6
  "type": "git",
@@ -53,7 +53,7 @@
53
53
  "@kamino-finance/scope-sdk": "^9.0.0",
54
54
  "@orca-so/whirlpool-client-sdk": "^0.0.8",
55
55
  "@orca-so/whirlpool-sdk": "^0.4.2",
56
- "@raydium-io/raydium-sdk-v2": "^0.1.111-alpha",
56
+ "@raydium-io/raydium-sdk-v2": "^0.1.126-alpha",
57
57
  "@solana-program/address-lookup-table": "^0.7.0",
58
58
  "@solana-program/compute-budget": "^0.7.0",
59
59
  "@solana-program/system": "^0.7.0",
package/src/Kamino.ts CHANGED
@@ -1379,6 +1379,20 @@ export class Kamino {
1379
1379
  }
1380
1380
  };
1381
1381
 
1382
+ /**
1383
+ * Get the token A and B per share for the specified Kamino whirlpool strategy
1384
+ * @param strategy
1385
+ */
1386
+ getTokenAAndBPerShare = async (strategy: Address | StrategyWithAddress): Promise<TokenAmounts> => {
1387
+ const strategyState = await this.getStrategyStateIfNotFetched(strategy);
1388
+ const sharesIssued = new Decimal(strategyState.strategy.sharesIssued.toString());
1389
+ const balances = await this.getStrategyBalances(strategyState.strategy);
1390
+ if (sharesIssued.isZero()) {
1391
+ return { a: new Decimal(0), b: new Decimal(0) };
1392
+ }
1393
+ return { a: balances.tokenAAmounts.div(sharesIssued), b: balances.tokenBAmounts.div(sharesIssued) };
1394
+ };
1395
+
1382
1396
  /**
1383
1397
  * Batch fetch share data for all or a filtered list of strategies
1384
1398
  * @param strategyFilters strategy filters or a list of strategy public keys
@@ -5985,6 +5999,63 @@ export class Kamino {
5985
5999
  return rebalanceFields;
5986
6000
  }
5987
6001
 
6002
+ /**
6003
+ * Get the current withdrawal caps for a strategy
6004
+ */
6005
+ async getStrategyCurrentWithdrawalCaps(strategy: Address | StrategyWithAddress): Promise<TokenAmounts> {
6006
+ const strategyWithAddress = await this.getStrategyStateIfNotFetched(strategy);
6007
+
6008
+ const tokenAWithdrawalCap = strategyWithAddress.strategy.withdrawalCapA;
6009
+ const tokenBWithdrawalCap = strategyWithAddress.strategy.withdrawalCapB;
6010
+ let tokenAWithdrawalCapTokens = Decimal.max(
6011
+ new Decimal(tokenAWithdrawalCap.configCapacity.toString()).sub(tokenAWithdrawalCap.currentTotal.toString()),
6012
+ ZERO
6013
+ );
6014
+ let tokenBWithdrawalCapTokens = Decimal.max(
6015
+ new Decimal(tokenBWithdrawalCap.configCapacity.toString()).sub(tokenBWithdrawalCap.currentTotal.toString()),
6016
+ ZERO
6017
+ );
6018
+ if (tokenAWithdrawalCap.configIntervalLengthSeconds.toNumber() == 0) {
6019
+ tokenAWithdrawalCapTokens = new Decimal(Number.MAX_VALUE);
6020
+ }
6021
+ if (tokenBWithdrawalCap.configIntervalLengthSeconds.toNumber() == 0) {
6022
+ tokenBWithdrawalCapTokens = new Decimal(Number.MAX_VALUE);
6023
+ }
6024
+ return {
6025
+ a: lamportsToNumberDecimal(tokenAWithdrawalCapTokens, strategyWithAddress.strategy.tokenAMintDecimals.toNumber()),
6026
+ b: lamportsToNumberDecimal(tokenBWithdrawalCapTokens, strategyWithAddress.strategy.tokenBMintDecimals.toNumber()),
6027
+ };
6028
+ }
6029
+
6030
+ /**
6031
+ * Get the max USD value that can be deposited per ix for a strategy
6032
+ */
6033
+ async getStrategyDepositCapInUSDPerIx(strategy: Address | StrategyWithAddress): Promise<Decimal> {
6034
+ const strategyWithAddress = await this.getStrategyStateIfNotFetched(strategy);
6035
+ return lamportsToNumberDecimal(new Decimal(strategyWithAddress.strategy.depositCapUsdPerIxn.toString()), 6);
6036
+ }
6037
+
6038
+ async getStrategyMaxDepositInUSD(strategy: Address | StrategyWithAddress): Promise<Decimal> {
6039
+ const strategyWithAddress = await this.getStrategyStateIfNotFetched(strategy);
6040
+ const depositCapInUSDPerIx = await this.getStrategyDepositCapInUSDPerIx(strategy);
6041
+
6042
+ // return the min between deposit cap per ix and the cap left in the deposit
6043
+ const depositCapInTokens = lamportsToNumberDecimal(
6044
+ new Decimal(strategyWithAddress.strategy.depositCapUsd.toString()),
6045
+ 6
6046
+ );
6047
+
6048
+ // read the tvl from API
6049
+ const url = `https://api.hubbleprotocol.io/strategies/${strategyWithAddress.address.toString()}/metrics?env=mainnet-beta`;
6050
+ const response = await fetch(url);
6051
+ const data = (await response.json()) as { totalValueLocked: number };
6052
+ const tvl = new Decimal(data.totalValueLocked);
6053
+
6054
+ const spaceLeftInDeposit = Decimal.max(depositCapInTokens.sub(tvl), ZERO);
6055
+
6056
+ return Decimal.min(depositCapInUSDPerIx, spaceLeftInDeposit);
6057
+ }
6058
+
5988
6059
  /**
5989
6060
  * Get the prices for rebalancing params (range and reset range, if strategy involves a reset range)
5990
6061
  */