@kamino-finance/kliquidity-sdk 8.0.1 → 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/dist/Kamino.d.ts +9 -0
- package/dist/Kamino.d.ts.map +1 -1
- package/dist/Kamino.js +40 -0
- package/dist/Kamino.js.map +1 -1
- package/package.json +2 -2
- package/src/Kamino.ts +57 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kamino-finance/kliquidity-sdk",
|
|
3
|
-
"version": "8.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.
|
|
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
|
@@ -5999,6 +5999,63 @@ export class Kamino {
|
|
|
5999
5999
|
return rebalanceFields;
|
|
6000
6000
|
}
|
|
6001
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
|
+
|
|
6002
6059
|
/**
|
|
6003
6060
|
* Get the prices for rebalancing params (range and reset range, if strategy involves a reset range)
|
|
6004
6061
|
*/
|