@kamino-finance/klend-sdk 7.3.9 → 7.3.10-beta.0
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.map +1 -1
- package/dist/classes/action.js +20 -11
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/configItems.d.ts +6 -1
- package/dist/classes/configItems.d.ts.map +1 -1
- package/dist/classes/configItems.js +93 -1
- 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 +1 -3
- package/dist/classes/farm_utils.js.map +1 -1
- package/dist/classes/reserve.d.ts +3 -7
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +43 -31
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/shared.d.ts +2 -2
- package/dist/classes/shared.d.ts.map +1 -1
- package/dist/classes/vault.d.ts +1 -28
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +6 -103
- package/dist/classes/vault.js.map +1 -1
- package/dist/classes/vault_types.d.ts +1 -2
- package/dist/classes/vault_types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/classes/action.ts +25 -25
- package/src/classes/configItems.ts +99 -1
- package/src/classes/farm_utils.ts +1 -5
- package/src/classes/reserve.ts +122 -118
- package/src/classes/shared.ts +2 -2
- package/src/classes/vault.ts +7 -160
- package/src/classes/vault_types.ts +1 -2
package/src/classes/vault.ts
CHANGED
|
@@ -123,13 +123,7 @@ import {
|
|
|
123
123
|
} from './vault_types';
|
|
124
124
|
import { batchFetch, collToLamportsDecimal, ZERO } from '@kamino-finance/kliquidity-sdk';
|
|
125
125
|
import { FullBPSDecimal } from '@kamino-finance/kliquidity-sdk/dist/utils/CreationParameters';
|
|
126
|
-
import {
|
|
127
|
-
FarmConfigOption,
|
|
128
|
-
FarmIncentives,
|
|
129
|
-
FarmState,
|
|
130
|
-
getUserStatePDA,
|
|
131
|
-
scaleDownWads,
|
|
132
|
-
} from '@kamino-finance/farms-sdk/dist';
|
|
126
|
+
import { FarmConfigOption, FarmIncentives, FarmState, getUserStatePDA } from '@kamino-finance/farms-sdk/dist';
|
|
133
127
|
import { getAccountsInLut, initLookupTableIx, insertIntoLookupTableIxs } from '../utils/lookupTable';
|
|
134
128
|
import {
|
|
135
129
|
FARMS_ADMIN_MAINNET,
|
|
@@ -849,8 +843,6 @@ export class KaminoVaultClient {
|
|
|
849
843
|
data: this.getValueForModeAsBuffer(mode, value),
|
|
850
844
|
};
|
|
851
845
|
|
|
852
|
-
await this.updateVaultConfigValidations(mode, value, vaultState);
|
|
853
|
-
|
|
854
846
|
const vaultReserves = this.getVaultReserves(vaultState);
|
|
855
847
|
const vaultReservesState = await this.loadVaultReserves(vaultState);
|
|
856
848
|
|
|
@@ -914,24 +906,6 @@ export class KaminoVaultClient {
|
|
|
914
906
|
return updateVaultConfigIxs;
|
|
915
907
|
}
|
|
916
908
|
|
|
917
|
-
async updateVaultConfigValidations(mode: VaultConfigFieldKind, value: string, vaultState: VaultState) {
|
|
918
|
-
if (
|
|
919
|
-
mode.kind === new VaultConfigField.FirstLossCapitalFarm().kind ||
|
|
920
|
-
mode.kind === new VaultConfigField.Farm().kind
|
|
921
|
-
) {
|
|
922
|
-
const farmAddress = address(value);
|
|
923
|
-
const farmState = await FarmState.fetch(this.getConnection(), farmAddress);
|
|
924
|
-
if (!farmState) {
|
|
925
|
-
throw new Error(`Farm ${farmAddress.toString()} not found for FirstLossCapitalFarm`);
|
|
926
|
-
}
|
|
927
|
-
if (
|
|
928
|
-
mode.kind === new VaultConfigField.FirstLossCapitalFarm().kind &&
|
|
929
|
-
!(await this.isFlcFarmValid(farmState, vaultState))
|
|
930
|
-
) {
|
|
931
|
-
throw new Error(`Farm ${farmAddress.toString()} is not valid for FirstLossCapitalFarm`);
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
909
|
/**
|
|
936
910
|
* Add or update a reserve whitelist entry. This controls whether the reserve is whitelisted for adding/updating
|
|
937
911
|
* allocations or for invest, depending on the mode parameter.
|
|
@@ -1225,7 +1199,7 @@ export class KaminoVaultClient {
|
|
|
1225
1199
|
* @param tokenAmount - token amount to be deposited, in decimals (will be converted in lamports)
|
|
1226
1200
|
* @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
|
|
1227
1201
|
* @param [farmState] - the state of the vault farm, if the vault has a farm. Optional. If not provided, it will be fetched
|
|
1228
|
-
* @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
|
|
1202
|
+
* @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
|
|
1229
1203
|
*/
|
|
1230
1204
|
async depositIxs(
|
|
1231
1205
|
user: TransactionSigner,
|
|
@@ -1339,17 +1313,14 @@ export class KaminoVaultClient {
|
|
|
1339
1313
|
const result: DepositIxs = {
|
|
1340
1314
|
depositIxs: [...createAtasIxs, entryIx, ...closeAtasIxs],
|
|
1341
1315
|
stakeInFarmIfNeededIxs: [],
|
|
1342
|
-
stakeInFlcFarmIfNeededIxs: [],
|
|
1343
1316
|
};
|
|
1344
1317
|
|
|
1345
|
-
if (await vault.hasFarm()) {
|
|
1346
|
-
|
|
1347
|
-
result.stakeInFarmIfNeededIxs = stakeSharesIxs;
|
|
1348
|
-
}
|
|
1349
|
-
if (await vault.hasFlcFarm()) {
|
|
1350
|
-
const stakeSharesInFlcFarmIxs = await this.stakeSharesInFlcFarmIxs(user, vault, undefined, undefined);
|
|
1351
|
-
result.stakeInFlcFarmIfNeededIxs = stakeSharesInFlcFarmIxs;
|
|
1318
|
+
if (!(await vault.hasFarm())) {
|
|
1319
|
+
return result;
|
|
1352
1320
|
}
|
|
1321
|
+
|
|
1322
|
+
const stakeSharesIxs = await this.stakeSharesIxs(user, vault, undefined, farmState);
|
|
1323
|
+
result.stakeInFarmIfNeededIxs = stakeSharesIxs;
|
|
1353
1324
|
return result;
|
|
1354
1325
|
}
|
|
1355
1326
|
|
|
@@ -1383,42 +1354,6 @@ export class KaminoVaultClient {
|
|
|
1383
1354
|
return getFarmStakeIxs(this.getConnection(), user, sharesToStakeLamports, vaultState.vaultFarm, farmState);
|
|
1384
1355
|
}
|
|
1385
1356
|
|
|
1386
|
-
/**
|
|
1387
|
-
* This function creates instructions to stake the shares in the vault firstLossCapital farm if the vault has a farm
|
|
1388
|
-
* @param user - user to stake
|
|
1389
|
-
* @param vault - vault to deposit into its flc farm (if the state is not provided, it will be fetched)
|
|
1390
|
-
* @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
|
|
1391
|
-
* @param [farmState] - the state of the vault flc farm, if the vault has a farm. Optional. If not provided, it will be fetched
|
|
1392
|
-
* @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
|
|
1393
|
-
*/
|
|
1394
|
-
async stakeSharesInFlcFarmIxs(
|
|
1395
|
-
user: TransactionSigner,
|
|
1396
|
-
vault: KaminoVault,
|
|
1397
|
-
sharesAmount?: Decimal,
|
|
1398
|
-
farmState?: FarmState
|
|
1399
|
-
): Promise<Instruction[]> {
|
|
1400
|
-
const vaultState = await vault.getState();
|
|
1401
|
-
|
|
1402
|
-
let sharesToStakeLamports = new Decimal(U64_MAX);
|
|
1403
|
-
if (sharesAmount) {
|
|
1404
|
-
sharesToStakeLamports = numberToLamportsDecimal(sharesAmount, vaultState.sharesMintDecimals.toNumber());
|
|
1405
|
-
}
|
|
1406
|
-
|
|
1407
|
-
// if tokens to be staked are 0 or vault has no farm there is no stake needed
|
|
1408
|
-
if (sharesToStakeLamports.lte(0) || !(await vault.hasFlcFarm())) {
|
|
1409
|
-
return [];
|
|
1410
|
-
}
|
|
1411
|
-
|
|
1412
|
-
// returns the ix to create the farm state account if needed and the ix to stake the shares
|
|
1413
|
-
return getFarmStakeIxs(
|
|
1414
|
-
this.getConnection(),
|
|
1415
|
-
user,
|
|
1416
|
-
sharesToStakeLamports,
|
|
1417
|
-
vaultState.firstLossCapitalFarm,
|
|
1418
|
-
farmState
|
|
1419
|
-
);
|
|
1420
|
-
}
|
|
1421
|
-
|
|
1422
1357
|
/**
|
|
1423
1358
|
* 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
|
|
1424
1359
|
* @param user - user to withdraw
|
|
@@ -3161,7 +3096,6 @@ export class KaminoVaultClient {
|
|
|
3161
3096
|
slotForOverview,
|
|
3162
3097
|
tokensPrices
|
|
3163
3098
|
);
|
|
3164
|
-
const vaultFlcFarmStatsPromise = this.getVaultFlcFarmStats(vault);
|
|
3165
3099
|
|
|
3166
3100
|
// 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
|
|
3167
3101
|
const [
|
|
@@ -3174,7 +3108,6 @@ export class KaminoVaultClient {
|
|
|
3174
3108
|
vaultFarmIncentives,
|
|
3175
3109
|
vaultReservesFarmIncentives,
|
|
3176
3110
|
vaultDelegatedFarmIncentives,
|
|
3177
|
-
vaultFlcFarmStats,
|
|
3178
3111
|
] = await Promise.all([
|
|
3179
3112
|
vaultHoldingsWithUSDValuePromise,
|
|
3180
3113
|
vaultTheoreticalAPYPromise,
|
|
@@ -3185,7 +3118,6 @@ export class KaminoVaultClient {
|
|
|
3185
3118
|
vaultFarmIncentivesPromise,
|
|
3186
3119
|
vaultReservesFarmIncentivesPromise,
|
|
3187
3120
|
vaultDelegatedFarmIncentivesPromise,
|
|
3188
|
-
vaultFlcFarmStatsPromise,
|
|
3189
3121
|
]);
|
|
3190
3122
|
|
|
3191
3123
|
return {
|
|
@@ -3202,7 +3134,6 @@ export class KaminoVaultClient {
|
|
|
3202
3134
|
utilizationRatio: totalInvestedAndBorrowed.utilizationRatio,
|
|
3203
3135
|
totalSupplied: totalInvestedAndBorrowed.totalInvested,
|
|
3204
3136
|
totalSuppliedUSD: totalInvestedAndBorrowed.totalInvested.mul(vaultTokenPrice),
|
|
3205
|
-
flcFarmStats: vaultFlcFarmStats,
|
|
3206
3137
|
};
|
|
3207
3138
|
}
|
|
3208
3139
|
|
|
@@ -3843,69 +3774,6 @@ export class KaminoVaultClient {
|
|
|
3843
3774
|
};
|
|
3844
3775
|
}
|
|
3845
3776
|
|
|
3846
|
-
async getVaultFlcFarmStats(vaultOrState: KaminoVault | VaultState): Promise<FlcFarmStats | undefined> {
|
|
3847
|
-
const vaultState = 'getState' in vaultOrState ? await vaultOrState.getState() : vaultOrState;
|
|
3848
|
-
|
|
3849
|
-
if (vaultState.firstLossCapitalFarm === DEFAULT_PUBLIC_KEY) {
|
|
3850
|
-
return undefined;
|
|
3851
|
-
}
|
|
3852
|
-
|
|
3853
|
-
const kFarmsClient = new Farms(this.getConnection());
|
|
3854
|
-
|
|
3855
|
-
const flcFarmState = await FarmState.fetch(this.getConnection(), vaultState.firstLossCapitalFarm);
|
|
3856
|
-
|
|
3857
|
-
if (!flcFarmState) {
|
|
3858
|
-
return undefined;
|
|
3859
|
-
}
|
|
3860
|
-
|
|
3861
|
-
if (!(await this.isFlcFarmValid(flcFarmState, vaultState))) {
|
|
3862
|
-
return undefined;
|
|
3863
|
-
}
|
|
3864
|
-
|
|
3865
|
-
const userStates = await kFarmsClient.getAllUserStatesForFarm(vaultState.firstLossCapitalFarm);
|
|
3866
|
-
const pendingUnstakes: FarmPendingUnstakeInfo[] = [];
|
|
3867
|
-
|
|
3868
|
-
for (const { userState, key } of userStates) {
|
|
3869
|
-
const pendingWithdrawalUnstake = new Decimal(scaleDownWads(userState.pendingWithdrawalUnstakeScaled));
|
|
3870
|
-
if (pendingWithdrawalUnstake.gt(0)) {
|
|
3871
|
-
pendingUnstakes.push({
|
|
3872
|
-
userStateAddress: key,
|
|
3873
|
-
pendingUnstakeAmountLamports: pendingWithdrawalUnstake,
|
|
3874
|
-
pendingUnstakeAvailableAtTimestamp: userState.pendingWithdrawalUnstakeTs.toNumber(),
|
|
3875
|
-
});
|
|
3876
|
-
}
|
|
3877
|
-
}
|
|
3878
|
-
|
|
3879
|
-
return {
|
|
3880
|
-
address: vaultState.firstLossCapitalFarm,
|
|
3881
|
-
farmState: flcFarmState,
|
|
3882
|
-
totalStakedShares: new Decimal(scaleDownWads(flcFarmState.totalActiveStakeScaled)),
|
|
3883
|
-
withdrawalCooldownDurationSeconds: flcFarmState.withdrawalCooldownPeriod,
|
|
3884
|
-
isPendingUnstake: pendingUnstakes.length > 0,
|
|
3885
|
-
pendingUnstakeInfo: pendingUnstakes,
|
|
3886
|
-
};
|
|
3887
|
-
}
|
|
3888
|
-
|
|
3889
|
-
async isFlcFarmValid(flcFarmState: FarmState, vaultOrState: KaminoVault | VaultState): Promise<boolean> {
|
|
3890
|
-
const vaultState = 'getState' in vaultOrState ? await vaultOrState.getState() : vaultOrState;
|
|
3891
|
-
|
|
3892
|
-
if (flcFarmState.timeUnit !== 0) {
|
|
3893
|
-
// timeUnit = 0 -> seconds
|
|
3894
|
-
return false;
|
|
3895
|
-
}
|
|
3896
|
-
|
|
3897
|
-
if (flcFarmState.withdrawalCooldownPeriod === 0) {
|
|
3898
|
-
// invalid FLC farm, should have > 0 withdrawal cooldown
|
|
3899
|
-
return false;
|
|
3900
|
-
}
|
|
3901
|
-
|
|
3902
|
-
if (flcFarmState.token.mint !== vaultState.sharesMint) {
|
|
3903
|
-
// staked token mint should be the vault shares mint
|
|
3904
|
-
return false;
|
|
3905
|
-
}
|
|
3906
|
-
return true;
|
|
3907
|
-
}
|
|
3908
|
-
|
|
3909
3777
|
/// reads the pending rewards for a user in the vault farm
|
|
3910
3778
|
/// @param user - the user address
|
|
3911
3779
|
/// @param vault - the vault
|
|
@@ -4335,11 +4203,6 @@ export class KaminoVault {
|
|
|
4335
4203
|
return state.vaultFarm !== DEFAULT_PUBLIC_KEY;
|
|
4336
4204
|
}
|
|
4337
4205
|
|
|
4338
|
-
async hasFlcFarm(): Promise<boolean> {
|
|
4339
|
-
const state = await this.getState();
|
|
4340
|
-
return state.firstLossCapitalFarm !== DEFAULT_PUBLIC_KEY;
|
|
4341
|
-
}
|
|
4342
|
-
|
|
4343
4206
|
/**
|
|
4344
4207
|
* 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
|
|
4345
4208
|
* @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
|
|
@@ -4716,7 +4579,6 @@ export type VaultOverview = {
|
|
|
4716
4579
|
totalSupplied: Decimal;
|
|
4717
4580
|
totalSuppliedUSD: Decimal;
|
|
4718
4581
|
utilizationRatio: Decimal;
|
|
4719
|
-
flcFarmStats: FlcFarmStats | undefined;
|
|
4720
4582
|
};
|
|
4721
4583
|
|
|
4722
4584
|
export type VaultReservesFarmsIncentives = {
|
|
@@ -4724,21 +4586,6 @@ export type VaultReservesFarmsIncentives = {
|
|
|
4724
4586
|
totalIncentivesAPY: Decimal;
|
|
4725
4587
|
};
|
|
4726
4588
|
|
|
4727
|
-
export type FlcFarmStats = {
|
|
4728
|
-
address: Address;
|
|
4729
|
-
farmState: FarmState;
|
|
4730
|
-
totalStakedShares: Decimal;
|
|
4731
|
-
withdrawalCooldownDurationSeconds: number;
|
|
4732
|
-
isPendingUnstake: boolean;
|
|
4733
|
-
pendingUnstakeInfo: FarmPendingUnstakeInfo[];
|
|
4734
|
-
};
|
|
4735
|
-
|
|
4736
|
-
export type FarmPendingUnstakeInfo = {
|
|
4737
|
-
userStateAddress: Address;
|
|
4738
|
-
pendingUnstakeAmountLamports: Decimal;
|
|
4739
|
-
pendingUnstakeAvailableAtTimestamp: number;
|
|
4740
|
-
};
|
|
4741
|
-
|
|
4742
4589
|
export type VaultFeesPct = {
|
|
4743
4590
|
managementFeePct: Decimal;
|
|
4744
4591
|
performanceFeePct: Decimal;
|
|
@@ -50,11 +50,10 @@ export type SyncVaultLUTIxs = {
|
|
|
50
50
|
syncLUTIxs: Instruction[];
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
/** If the stakeInFarmIfNeededIxs
|
|
53
|
+
/** If the stakeInFarmIfNeededIxs exist they have to be executed after the deposit so the shares received from the deposit are staked in the vault farm */
|
|
54
54
|
export type DepositIxs = {
|
|
55
55
|
depositIxs: Instruction[];
|
|
56
56
|
stakeInFarmIfNeededIxs: Instruction[];
|
|
57
|
-
stakeInFlcFarmIfNeededIxs: Instruction[]; // if the vault has a firstLossCapital farm, these ixs will stake the shares in the flc farm
|
|
58
57
|
};
|
|
59
58
|
|
|
60
59
|
/** the ixs to unstake shares from farm and withdraw them from the vault. The `unstakeFromFarmIfNeededIxs` should be in the tx before `withdrawIxs`*/
|