@kamino-finance/klend-sdk 7.3.10-beta.0 → 7.4.0-beta.1
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/classes/action.d.ts +21 -91
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +152 -139
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/actionTypes.d.ts +310 -0
- package/dist/classes/actionTypes.d.ts.map +1 -0
- package/dist/classes/actionTypes.js +3 -0
- package/dist/classes/actionTypes.js.map +1 -0
- package/dist/classes/configItems.d.ts +1 -6
- package/dist/classes/configItems.d.ts.map +1 -1
- package/dist/classes/configItems.js +1 -93
- package/dist/classes/configItems.js.map +1 -1
- package/dist/classes/farm_utils.d.ts +1 -1
- package/dist/classes/farm_utils.d.ts.map +1 -1
- package/dist/classes/farm_utils.js +3 -1
- package/dist/classes/farm_utils.js.map +1 -1
- package/dist/classes/market.d.ts +5 -5
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +29 -13
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.d.ts +9 -9
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +48 -50
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/obligationOrder.d.ts.map +1 -1
- package/dist/classes/obligationOrder.js +6 -3
- package/dist/classes/obligationOrder.js.map +1 -1
- package/dist/classes/reserve.d.ts +7 -3
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +31 -43
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/shared.d.ts +3 -2
- package/dist/classes/shared.d.ts.map +1 -1
- package/dist/classes/vault.d.ts +28 -1
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +103 -6
- package/dist/classes/vault.js.map +1 -1
- package/dist/classes/vault_types.d.ts +2 -1
- package/dist/classes/vault_types.d.ts.map +1 -1
- package/dist/client/commands/borrow.d.ts +1 -1
- package/dist/client/commands/borrow.d.ts.map +1 -1
- package/dist/client/commands/borrow.js +11 -2
- package/dist/client/commands/borrow.js.map +1 -1
- package/dist/client/commands/deposit.d.ts +1 -1
- package/dist/client/commands/deposit.d.ts.map +1 -1
- package/dist/client/commands/deposit.js +11 -2
- package/dist/client/commands/deposit.js.map +1 -1
- package/dist/client/commands/printReserve.d.ts +1 -1
- package/dist/client/commands/printReserve.d.ts.map +1 -1
- package/dist/client/commands/printReserve.js +2 -4
- package/dist/client/commands/printReserve.js.map +1 -1
- package/dist/client/commands/repay.d.ts +1 -1
- package/dist/client/commands/repay.d.ts.map +1 -1
- package/dist/client/commands/repay.js +12 -2
- package/dist/client/commands/repay.js.map +1 -1
- package/dist/client/commands/withdraw.d.ts +1 -1
- package/dist/client/commands/withdraw.d.ts.map +1 -1
- package/dist/client/commands/withdraw.js +11 -2
- package/dist/client/commands/withdraw.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.js +2 -2
- package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +4 -4
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +43 -10
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts +4 -4
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +40 -21
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/operations.d.ts +6 -6
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +167 -52
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +2 -2
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/obligation_orders/price_based.js +1 -0
- package/dist/obligation_orders/price_based.js.map +1 -1
- package/dist/utils/Logger.d.ts +14 -0
- package/dist/utils/Logger.d.ts.map +1 -0
- package/dist/utils/Logger.js +12 -0
- package/dist/utils/Logger.js.map +1 -0
- package/dist/utils/ObligationType.d.ts +33 -1
- package/dist/utils/ObligationType.d.ts.map +1 -1
- package/dist/utils/ObligationType.js +81 -2
- package/dist/utils/ObligationType.js.map +1 -1
- package/dist/utils/api.d.ts +13 -4
- package/dist/utils/api.d.ts.map +1 -1
- package/dist/utils/api.js +33 -31
- package/dist/utils/api.js.map +1 -1
- package/dist/utils/userMetadata.d.ts +2 -2
- package/dist/utils/userMetadata.d.ts.map +1 -1
- package/dist/utils/userMetadata.js +49 -25
- package/dist/utils/userMetadata.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/action.ts +346 -372
- package/src/classes/actionTypes.ts +295 -0
- package/src/classes/configItems.ts +1 -99
- package/src/classes/farm_utils.ts +5 -1
- package/src/classes/market.ts +42 -16
- package/src/classes/obligation.ts +54 -53
- package/src/classes/obligationOrder.ts +6 -3
- package/src/classes/reserve.ts +118 -122
- package/src/classes/shared.ts +4 -2
- package/src/classes/vault.ts +160 -7
- package/src/classes/vault_types.ts +2 -1
- package/src/client/client.ts +17 -18
- package/src/client/commands/borrow.ts +10 -9
- package/src/client/commands/deposit.ts +10 -9
- package/src/client/commands/printReserve.ts +2 -4
- package/src/client/commands/repay.ts +11 -10
- package/src/client/commands/withdraw.ts +15 -9
- package/src/lending_operations/repay_with_collateral_calcs.ts +3 -4
- package/src/lending_operations/repay_with_collateral_operations.ts +40 -38
- package/src/lending_operations/swap_collateral_operations.ts +47 -41
- package/src/leverage/operations.ts +168 -129
- package/src/leverage/types.ts +2 -2
- package/src/obligation_orders/price_based.ts +1 -0
- package/src/utils/Logger.ts +14 -0
- package/src/utils/ObligationType.ts +92 -1
- package/src/utils/api.ts +56 -33
- package/src/utils/userMetadata.ts +64 -30
package/dist/classes/vault.js
CHANGED
|
@@ -487,6 +487,7 @@ class KaminoVaultClient {
|
|
|
487
487
|
entry: mode,
|
|
488
488
|
data: this.getValueForModeAsBuffer(mode, value),
|
|
489
489
|
};
|
|
490
|
+
await this.updateVaultConfigValidations(mode, value, vaultState);
|
|
490
491
|
const vaultReserves = this.getVaultReserves(vaultState);
|
|
491
492
|
const vaultReservesState = await this.loadVaultReserves(vaultState);
|
|
492
493
|
let updateVaultConfigIx = (0, instructions_1.updateVaultConfig)(updateVaultConfigArgs, updateVaultConfigAccs, undefined, this._kaminoVaultProgramId);
|
|
@@ -519,6 +520,20 @@ class KaminoVaultClient {
|
|
|
519
520
|
};
|
|
520
521
|
return updateVaultConfigIxs;
|
|
521
522
|
}
|
|
523
|
+
async updateVaultConfigValidations(mode, value, vaultState) {
|
|
524
|
+
if (mode.kind === new types_1.VaultConfigField.FirstLossCapitalFarm().kind ||
|
|
525
|
+
mode.kind === new types_1.VaultConfigField.Farm().kind) {
|
|
526
|
+
const farmAddress = (0, kit_1.address)(value);
|
|
527
|
+
const farmState = await dist_1.FarmState.fetch(this.getConnection(), farmAddress);
|
|
528
|
+
if (!farmState) {
|
|
529
|
+
throw new Error(`Farm ${farmAddress.toString()} not found for FirstLossCapitalFarm`);
|
|
530
|
+
}
|
|
531
|
+
if (mode.kind === new types_1.VaultConfigField.FirstLossCapitalFarm().kind &&
|
|
532
|
+
!(await this.isFlcFarmValid(farmState, vaultState))) {
|
|
533
|
+
throw new Error(`Farm ${farmAddress.toString()} is not valid for FirstLossCapitalFarm`);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
522
537
|
/**
|
|
523
538
|
* Add or update a reserve whitelist entry. This controls whether the reserve is whitelisted for adding/updating
|
|
524
539
|
* allocations or for invest, depending on the mode parameter.
|
|
@@ -701,7 +716,7 @@ class KaminoVaultClient {
|
|
|
701
716
|
* @param tokenAmount - token amount to be deposited, in decimals (will be converted in lamports)
|
|
702
717
|
* @param [vaultReservesMap] - optional parameter; a hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
|
|
703
718
|
* @param [farmState] - the state of the vault farm, if the vault has a farm. Optional. If not provided, it will be fetched
|
|
704
|
-
* @returns - an instance of DepositIxs which contains the instructions to deposit in vault and the instructions to stake the shares in the farm if the vault has a farm
|
|
719
|
+
* @returns - an instance of DepositIxs which contains the instructions to deposit in vault and the instructions to stake the shares in the farm if the vault has a farm as well as ixs to stake in the first loss capital farm if the vault has one - only one set on ixs so stake in a farm can be used -> staking can be either done in the farm or in the first loss capital farm
|
|
705
720
|
*/
|
|
706
721
|
async depositIxs(user, vault, tokenAmount, vaultReservesMap, farmState) {
|
|
707
722
|
return this.buildShareEntryIxs('deposit', user, vault, tokenAmount, vaultReservesMap, farmState);
|
|
@@ -784,12 +799,16 @@ class KaminoVaultClient {
|
|
|
784
799
|
const result = {
|
|
785
800
|
depositIxs: [...createAtasIxs, entryIx, ...closeAtasIxs],
|
|
786
801
|
stakeInFarmIfNeededIxs: [],
|
|
802
|
+
stakeInFlcFarmIfNeededIxs: [],
|
|
787
803
|
};
|
|
788
|
-
if (
|
|
789
|
-
|
|
804
|
+
if (await vault.hasFarm()) {
|
|
805
|
+
const stakeSharesIxs = await this.stakeSharesIxs(user, vault, undefined, farmState);
|
|
806
|
+
result.stakeInFarmIfNeededIxs = stakeSharesIxs;
|
|
807
|
+
}
|
|
808
|
+
if (await vault.hasFlcFarm()) {
|
|
809
|
+
const stakeSharesInFlcFarmIxs = await this.stakeSharesInFlcFarmIxs(user, vault, undefined, undefined);
|
|
810
|
+
result.stakeInFlcFarmIfNeededIxs = stakeSharesInFlcFarmIxs;
|
|
790
811
|
}
|
|
791
|
-
const stakeSharesIxs = await this.stakeSharesIxs(user, vault, undefined, farmState);
|
|
792
|
-
result.stakeInFarmIfNeededIxs = stakeSharesIxs;
|
|
793
812
|
return result;
|
|
794
813
|
}
|
|
795
814
|
/**
|
|
@@ -813,6 +832,27 @@ class KaminoVaultClient {
|
|
|
813
832
|
// returns the ix to create the farm state account if needed and the ix to stake the shares
|
|
814
833
|
return (0, farm_utils_1.getFarmStakeIxs)(this.getConnection(), user, sharesToStakeLamports, vaultState.vaultFarm, farmState);
|
|
815
834
|
}
|
|
835
|
+
/**
|
|
836
|
+
* This function creates instructions to stake the shares in the vault firstLossCapital farm if the vault has a farm
|
|
837
|
+
* @param user - user to stake
|
|
838
|
+
* @param vault - vault to deposit into its flc farm (if the state is not provided, it will be fetched)
|
|
839
|
+
* @param [sharesAmount] - token amount to be deposited, in decimals (will be converted in lamports). Optional. If not provided, the user's share balance will be used
|
|
840
|
+
* @param [farmState] - the state of the vault flc farm, if the vault has a farm. Optional. If not provided, it will be fetched
|
|
841
|
+
* @returns - a list of instructions for the user to stake shares into the vault's firstLossCapital farm, including the creation of prerequisite accounts if needed
|
|
842
|
+
*/
|
|
843
|
+
async stakeSharesInFlcFarmIxs(user, vault, sharesAmount, farmState) {
|
|
844
|
+
const vaultState = await vault.getState();
|
|
845
|
+
let sharesToStakeLamports = new decimal_js_1.default(utils_2.U64_MAX);
|
|
846
|
+
if (sharesAmount) {
|
|
847
|
+
sharesToStakeLamports = (0, utils_1.numberToLamportsDecimal)(sharesAmount, vaultState.sharesMintDecimals.toNumber());
|
|
848
|
+
}
|
|
849
|
+
// if tokens to be staked are 0 or vault has no farm there is no stake needed
|
|
850
|
+
if (sharesToStakeLamports.lte(0) || !(await vault.hasFlcFarm())) {
|
|
851
|
+
return [];
|
|
852
|
+
}
|
|
853
|
+
// returns the ix to create the farm state account if needed and the ix to stake the shares
|
|
854
|
+
return (0, farm_utils_1.getFarmStakeIxs)(this.getConnection(), user, sharesToStakeLamports, vaultState.firstLossCapitalFarm, farmState);
|
|
855
|
+
}
|
|
816
856
|
/**
|
|
817
857
|
* This function will return a struct with the instructions to unstake from the farm if necessary and the instructions for the missing ATA creation instructions, as well as one or multiple withdraw instructions, based on how many reserves it's needed to withdraw from. This might have to be split in multiple transactions
|
|
818
858
|
* @param user - user to withdraw
|
|
@@ -2044,8 +2084,9 @@ class KaminoVaultClient {
|
|
|
2044
2084
|
const vaultFarmIncentivesPromise = this.getVaultRewardsAPY(vault, vaultTokenPrice, farmsClient, slotForOverview, tokensPrices);
|
|
2045
2085
|
const vaultReservesFarmIncentivesPromise = this.getVaultReservesFarmsIncentives(vault, vaultTokenPrice, farmsClient, slotForOverview, vaultReservesState, tokensPrices);
|
|
2046
2086
|
const vaultDelegatedFarmIncentivesPromise = this.getVaultDelegatedFarmRewardsAPY(vault, vaultTokenPrice, farmsClient, slotForOverview, tokensPrices);
|
|
2087
|
+
const vaultFlcFarmStatsPromise = this.getVaultFlcFarmStats(vault);
|
|
2047
2088
|
// all the async part of the functions above just read the vaultReservesState which is read beforehand, so excepting vaultCollateralsPromise they should do no additional network calls
|
|
2048
|
-
const [vaultHoldingsWithUSDValue, vaultTheoreticalAPYs, vaultActualAPYs, totalInvestedAndBorrowed, vaultCollaterals, reservesOverview, vaultFarmIncentives, vaultReservesFarmIncentives, vaultDelegatedFarmIncentives,] = await Promise.all([
|
|
2089
|
+
const [vaultHoldingsWithUSDValue, vaultTheoreticalAPYs, vaultActualAPYs, totalInvestedAndBorrowed, vaultCollaterals, reservesOverview, vaultFarmIncentives, vaultReservesFarmIncentives, vaultDelegatedFarmIncentives, vaultFlcFarmStats,] = await Promise.all([
|
|
2049
2090
|
vaultHoldingsWithUSDValuePromise,
|
|
2050
2091
|
vaultTheoreticalAPYPromise,
|
|
2051
2092
|
vaultActualAPYPromise,
|
|
@@ -2055,6 +2096,7 @@ class KaminoVaultClient {
|
|
|
2055
2096
|
vaultFarmIncentivesPromise,
|
|
2056
2097
|
vaultReservesFarmIncentivesPromise,
|
|
2057
2098
|
vaultDelegatedFarmIncentivesPromise,
|
|
2099
|
+
vaultFlcFarmStatsPromise,
|
|
2058
2100
|
]);
|
|
2059
2101
|
return {
|
|
2060
2102
|
holdingsUSD: vaultHoldingsWithUSDValue,
|
|
@@ -2070,6 +2112,7 @@ class KaminoVaultClient {
|
|
|
2070
2112
|
utilizationRatio: totalInvestedAndBorrowed.utilizationRatio,
|
|
2071
2113
|
totalSupplied: totalInvestedAndBorrowed.totalInvested,
|
|
2072
2114
|
totalSuppliedUSD: totalInvestedAndBorrowed.totalInvested.mul(vaultTokenPrice),
|
|
2115
|
+
flcFarmStats: vaultFlcFarmStats,
|
|
2073
2116
|
};
|
|
2074
2117
|
}
|
|
2075
2118
|
/**
|
|
@@ -2544,6 +2587,56 @@ class KaminoVaultClient {
|
|
|
2544
2587
|
totalIncentivesAPY: totalIncentivesApy,
|
|
2545
2588
|
};
|
|
2546
2589
|
}
|
|
2590
|
+
async getVaultFlcFarmStats(vaultOrState) {
|
|
2591
|
+
const vaultState = 'getState' in vaultOrState ? await vaultOrState.getState() : vaultOrState;
|
|
2592
|
+
if (vaultState.firstLossCapitalFarm === lib_1.DEFAULT_PUBLIC_KEY) {
|
|
2593
|
+
return undefined;
|
|
2594
|
+
}
|
|
2595
|
+
const kFarmsClient = new farms_sdk_1.Farms(this.getConnection());
|
|
2596
|
+
const flcFarmState = await dist_1.FarmState.fetch(this.getConnection(), vaultState.firstLossCapitalFarm);
|
|
2597
|
+
if (!flcFarmState) {
|
|
2598
|
+
return undefined;
|
|
2599
|
+
}
|
|
2600
|
+
if (!(await this.isFlcFarmValid(flcFarmState, vaultState))) {
|
|
2601
|
+
return undefined;
|
|
2602
|
+
}
|
|
2603
|
+
const userStates = await kFarmsClient.getAllUserStatesForFarm(vaultState.firstLossCapitalFarm);
|
|
2604
|
+
const pendingUnstakes = [];
|
|
2605
|
+
for (const { userState, key } of userStates) {
|
|
2606
|
+
const pendingWithdrawalUnstake = new decimal_js_1.default((0, dist_1.scaleDownWads)(userState.pendingWithdrawalUnstakeScaled));
|
|
2607
|
+
if (pendingWithdrawalUnstake.gt(0)) {
|
|
2608
|
+
pendingUnstakes.push({
|
|
2609
|
+
userStateAddress: key,
|
|
2610
|
+
pendingUnstakeAmountLamports: pendingWithdrawalUnstake,
|
|
2611
|
+
pendingUnstakeAvailableAtTimestamp: userState.pendingWithdrawalUnstakeTs.toNumber(),
|
|
2612
|
+
});
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
return {
|
|
2616
|
+
address: vaultState.firstLossCapitalFarm,
|
|
2617
|
+
farmState: flcFarmState,
|
|
2618
|
+
totalStakedShares: new decimal_js_1.default((0, dist_1.scaleDownWads)(flcFarmState.totalActiveStakeScaled)),
|
|
2619
|
+
withdrawalCooldownDurationSeconds: flcFarmState.withdrawalCooldownPeriod,
|
|
2620
|
+
isPendingUnstake: pendingUnstakes.length > 0,
|
|
2621
|
+
pendingUnstakeInfo: pendingUnstakes,
|
|
2622
|
+
};
|
|
2623
|
+
}
|
|
2624
|
+
async isFlcFarmValid(flcFarmState, vaultOrState) {
|
|
2625
|
+
const vaultState = 'getState' in vaultOrState ? await vaultOrState.getState() : vaultOrState;
|
|
2626
|
+
if (flcFarmState.timeUnit !== 0) {
|
|
2627
|
+
// timeUnit = 0 -> seconds
|
|
2628
|
+
return false;
|
|
2629
|
+
}
|
|
2630
|
+
if (flcFarmState.withdrawalCooldownPeriod === 0) {
|
|
2631
|
+
// invalid FLC farm, should have > 0 withdrawal cooldown
|
|
2632
|
+
return false;
|
|
2633
|
+
}
|
|
2634
|
+
if (flcFarmState.token.mint !== vaultState.sharesMint) {
|
|
2635
|
+
// staked token mint should be the vault shares mint
|
|
2636
|
+
return false;
|
|
2637
|
+
}
|
|
2638
|
+
return true;
|
|
2639
|
+
}
|
|
2547
2640
|
/// reads the pending rewards for a user in the vault farm
|
|
2548
2641
|
/// @param user - the user address
|
|
2549
2642
|
/// @param vault - the vault
|
|
@@ -2856,6 +2949,10 @@ class KaminoVault {
|
|
|
2856
2949
|
const state = await this.getState();
|
|
2857
2950
|
return state.vaultFarm !== lib_1.DEFAULT_PUBLIC_KEY;
|
|
2858
2951
|
}
|
|
2952
|
+
async hasFlcFarm() {
|
|
2953
|
+
const state = await this.getState();
|
|
2954
|
+
return state.firstLossCapitalFarm !== lib_1.DEFAULT_PUBLIC_KEY;
|
|
2955
|
+
}
|
|
2859
2956
|
/**
|
|
2860
2957
|
* This will return an VaultHoldings object which contains the amount available (uninvested) in vault, total amount invested in reseves and a breakdown of the amount invested in each reserve
|
|
2861
2958
|
* @returns an VaultHoldings object representing the amount available (uninvested) in vault, total amount invested in reseves and a breakdown of the amount invested in each reserve
|