@kamino-finance/klend-sdk 7.1.4-beta.0 → 7.1.5
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/@codegen/klend/accounts/LendingMarket.d.ts +3 -144
- package/dist/@codegen/klend/accounts/LendingMarket.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/LendingMarket.js +3 -105
- package/dist/@codegen/klend/accounts/LendingMarket.js.map +1 -1
- package/dist/@codegen/klend/accounts/Obligation.d.ts +15 -30
- package/dist/@codegen/klend/accounts/Obligation.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/Obligation.js +21 -31
- package/dist/@codegen/klend/accounts/Obligation.js.map +1 -1
- package/dist/@codegen/klend/accounts/Reserve.d.ts +0 -6
- package/dist/@codegen/klend/accounts/Reserve.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/Reserve.js +2 -9
- package/dist/@codegen/klend/accounts/Reserve.js.map +1 -1
- package/dist/@codegen/klend/accounts/UserState.d.ts +75 -0
- package/dist/@codegen/klend/accounts/UserState.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/UserState.js +25 -0
- package/dist/@codegen/klend/accounts/UserState.js.map +1 -1
- package/dist/@codegen/klend/accounts/index.d.ts +0 -6
- package/dist/@codegen/klend/accounts/index.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/index.js +1 -7
- package/dist/@codegen/klend/accounts/index.js.map +1 -1
- package/dist/@codegen/klend/errors/custom.d.ts +2 -226
- package/dist/@codegen/klend/errors/custom.d.ts.map +1 -1
- package/dist/@codegen/klend/errors/custom.js +3 -396
- package/dist/@codegen/klend/errors/custom.js.map +1 -1
- package/dist/@codegen/klend/instructions/idlMissingTypes.d.ts +2 -1
- package/dist/@codegen/klend/instructions/idlMissingTypes.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/idlMissingTypes.js +2 -6
- package/dist/@codegen/klend/instructions/idlMissingTypes.js.map +1 -1
- package/dist/@codegen/klend/instructions/index.d.ts +0 -16
- package/dist/@codegen/klend/instructions/index.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/index.js +1 -18
- package/dist/@codegen/klend/instructions/index.js.map +1 -1
- package/dist/@codegen/klend/instructions/initReserve.d.ts +1 -1
- package/dist/@codegen/klend/instructions/initReserve.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/initReserve.js +5 -1
- package/dist/@codegen/klend/instructions/initReserve.js.map +1 -1
- package/dist/@codegen/klend/instructions/liquidateObligationAndRedeemReserveCollateral.js +1 -1
- package/dist/@codegen/klend/instructions/updateGlobalConfig.d.ts +1 -1
- package/dist/@codegen/klend/instructions/updateGlobalConfig.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/updateGlobalConfig.js +0 -1
- package/dist/@codegen/klend/instructions/updateGlobalConfig.js.map +1 -1
- package/dist/@codegen/klend/instructions/updateReserveConfig.d.ts +1 -1
- package/dist/@codegen/klend/instructions/updateReserveConfig.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/updateReserveConfig.js +0 -1
- package/dist/@codegen/klend/instructions/updateReserveConfig.js.map +1 -1
- package/dist/@codegen/klend/instructions/withdrawObligationCollateral.js +1 -1
- package/dist/@codegen/klend/instructions/withdrawObligationCollateralV2.js +1 -1
- package/dist/@codegen/klend/types/AssetTier.d.ts +45 -0
- package/dist/@codegen/klend/types/AssetTier.d.ts.map +1 -0
- package/dist/@codegen/klend/types/AssetTier.js +132 -0
- package/dist/@codegen/klend/types/AssetTier.js.map +1 -0
- package/dist/@codegen/klend/types/ObligationLiquidity.d.ts +5 -35
- package/dist/@codegen/klend/types/ObligationLiquidity.d.ts.map +1 -1
- package/dist/@codegen/klend/types/ObligationLiquidity.js +7 -17
- package/dist/@codegen/klend/types/ObligationLiquidity.js.map +1 -1
- package/dist/@codegen/klend/types/ObligationOrder.d.ts +4 -4
- package/dist/@codegen/klend/types/ObligationOrder.js +2 -2
- package/dist/@codegen/klend/types/ReserveConfig.d.ts +29 -141
- package/dist/@codegen/klend/types/ReserveConfig.d.ts.map +1 -1
- package/dist/@codegen/klend/types/ReserveConfig.js +25 -89
- package/dist/@codegen/klend/types/ReserveConfig.js.map +1 -1
- package/dist/@codegen/klend/types/ReserveFees.d.ts +8 -8
- package/dist/@codegen/klend/types/ReserveFees.d.ts.map +1 -1
- package/dist/@codegen/klend/types/ReserveFees.js +8 -8
- package/dist/@codegen/klend/types/ReserveFees.js.map +1 -1
- package/dist/@codegen/klend/types/ReserveLiquidity.d.ts +8 -26
- package/dist/@codegen/klend/types/ReserveLiquidity.d.ts.map +1 -1
- package/dist/@codegen/klend/types/ReserveLiquidity.js +8 -14
- package/dist/@codegen/klend/types/ReserveLiquidity.js.map +1 -1
- package/dist/@codegen/klend/types/UpdateConfigMode.d.ts +14 -92
- package/dist/@codegen/klend/types/UpdateConfigMode.d.ts.map +1 -1
- package/dist/@codegen/klend/types/UpdateConfigMode.js +23 -168
- package/dist/@codegen/klend/types/UpdateConfigMode.js.map +1 -1
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts +0 -130
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts.map +1 -1
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.js +1 -241
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.js.map +1 -1
- package/dist/@codegen/klend/types/index.d.ts +8 -10
- package/dist/@codegen/klend/types/index.d.ts.map +1 -1
- package/dist/@codegen/klend/types/index.js +3 -7
- package/dist/@codegen/klend/types/index.js.map +1 -1
- package/dist/@codegen/klend/zero_padding/ObligationZP.d.ts +4 -9
- package/dist/@codegen/klend/zero_padding/ObligationZP.d.ts.map +1 -1
- package/dist/@codegen/klend/zero_padding/ObligationZP.js +13 -22
- package/dist/@codegen/klend/zero_padding/ObligationZP.js.map +1 -1
- package/dist/classes/action.d.ts +3 -30
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +10 -364
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts +3 -2
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +3 -12
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/market.d.ts +2 -6
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +6 -26
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.js +1 -1
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +7 -13
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/unstakingPool.d.ts +3 -20
- package/dist/classes/unstakingPool.d.ts.map +1 -1
- package/dist/classes/unstakingPool.js +8 -62
- package/dist/classes/unstakingPool.js.map +1 -1
- package/dist/classes/vault.d.ts +2 -1
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +59 -38
- package/dist/classes/vault.js.map +1 -1
- package/dist/idl/klend.json +293 -2186
- package/dist/lending_operations/index.d.ts +0 -1
- package/dist/lending_operations/index.d.ts.map +1 -1
- package/dist/lending_operations/index.js +0 -1
- package/dist/lending_operations/index.js.map +1 -1
- package/dist/manager/client_kamino_manager.js +9 -12
- package/dist/manager/client_kamino_manager.js.map +1 -1
- package/dist/utils/ata.d.ts +10 -1
- package/dist/utils/ata.d.ts.map +1 -1
- package/dist/utils/ata.js +47 -0
- package/dist/utils/ata.js.map +1 -1
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js +4 -9
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/seeds.d.ts +14 -10
- package/dist/utils/seeds.d.ts.map +1 -1
- package/dist/utils/seeds.js +22 -25
- package/dist/utils/seeds.js.map +1 -1
- package/package.json +1 -1
- package/src/@codegen/klend/accounts/LendingMarket.ts +5 -210
- package/src/@codegen/klend/accounts/Obligation.ts +31 -53
- package/src/@codegen/klend/accounts/Reserve.ts +2 -13
- package/src/@codegen/klend/accounts/UserState.ts +75 -0
- package/src/@codegen/klend/accounts/index.ts +0 -6
- package/src/@codegen/klend/errors/custom.ts +2 -427
- package/src/@codegen/klend/instructions/idlMissingTypes.ts +4 -7
- package/src/@codegen/klend/instructions/index.ts +0 -34
- package/src/@codegen/klend/instructions/initReserve.ts +6 -2
- package/src/@codegen/klend/instructions/liquidateObligationAndRedeemReserveCollateral.ts +1 -1
- package/src/@codegen/klend/instructions/updateGlobalConfig.ts +1 -2
- package/src/@codegen/klend/instructions/updateReserveConfig.ts +1 -2
- package/src/@codegen/klend/instructions/withdrawObligationCollateral.ts +1 -1
- package/src/@codegen/klend/instructions/withdrawObligationCollateralV2.ts +1 -1
- package/src/@codegen/klend/types/AssetTier.ts +119 -0
- package/src/@codegen/klend/types/ObligationLiquidity.ts +9 -39
- package/src/@codegen/klend/types/ObligationOrder.ts +4 -4
- package/src/@codegen/klend/types/ReserveConfig.ts +39 -171
- package/src/@codegen/klend/types/ReserveFees.ts +12 -12
- package/src/@codegen/klend/types/ReserveLiquidity.ts +12 -30
- package/src/@codegen/klend/types/UpdateConfigMode.ts +26 -206
- package/src/@codegen/klend/types/UpdateLendingMarketMode.ts +0 -300
- package/src/@codegen/klend/types/index.ts +16 -45
- package/src/@codegen/klend/zero_padding/ObligationZP.ts +13 -22
- package/src/classes/action.ts +8 -577
- package/src/classes/manager.ts +7 -13
- package/src/classes/market.ts +5 -36
- package/src/classes/obligation.ts +1 -1
- package/src/classes/reserve.ts +8 -13
- package/src/classes/unstakingPool.ts +6 -83
- package/src/classes/vault.ts +75 -54
- package/src/idl/klend.json +294 -2187
- package/src/lending_operations/index.ts +0 -1
- package/src/manager/client_kamino_manager.ts +9 -13
- package/src/utils/ata.ts +79 -0
- package/src/utils/managerTypes.ts +4 -9
- package/src/utils/seeds.ts +26 -28
- package/dist/@codegen/klend/accounts/PoolState.d.ts +0 -53
- package/dist/@codegen/klend/accounts/PoolState.d.ts.map +0 -1
- package/dist/@codegen/klend/accounts/PoolState.js +0 -167
- package/dist/@codegen/klend/accounts/PoolState.js.map +0 -1
- package/dist/@codegen/klend/accounts/UnstakeTicket.d.ts +0 -41
- package/dist/@codegen/klend/accounts/UnstakeTicket.d.ts.map +0 -1
- package/dist/@codegen/klend/accounts/UnstakeTicket.js +0 -143
- package/dist/@codegen/klend/accounts/UnstakeTicket.js.map +0 -1
- package/dist/@codegen/klend/accounts/WithdrawTicket.d.ts +0 -132
- package/dist/@codegen/klend/accounts/WithdrawTicket.d.ts.map +0 -1
- package/dist/@codegen/klend/accounts/WithdrawTicket.js +0 -191
- package/dist/@codegen/klend/accounts/WithdrawTicket.js.map +0 -1
- package/dist/@codegen/klend/instructions/enqueueToWithdraw.d.ts +0 -39
- package/dist/@codegen/klend/instructions/enqueueToWithdraw.d.ts.map +0 -1
- package/dist/@codegen/klend/instructions/enqueueToWithdraw.js +0 -67
- package/dist/@codegen/klend/instructions/enqueueToWithdraw.js.map +0 -1
- package/dist/@codegen/klend/instructions/fillBorrowOrder.d.ts +0 -36
- package/dist/@codegen/klend/instructions/fillBorrowOrder.d.ts.map +0 -1
- package/dist/@codegen/klend/instructions/fillBorrowOrder.js +0 -49
- package/dist/@codegen/klend/instructions/fillBorrowOrder.js.map +0 -1
- package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.d.ts +0 -47
- package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.d.ts.map +0 -1
- package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.js +0 -66
- package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.js.map +0 -1
- package/dist/@codegen/klend/instructions/setBorrowOrder.d.ts +0 -31
- package/dist/@codegen/klend/instructions/setBorrowOrder.d.ts.map +0 -1
- package/dist/@codegen/klend/instructions/setBorrowOrder.js +0 -64
- package/dist/@codegen/klend/instructions/setBorrowOrder.js.map +0 -1
- package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.d.ts +0 -53
- package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.d.ts.map +0 -1
- package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.js +0 -190
- package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.js.map +0 -1
- package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.d.ts +0 -70
- package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.d.ts.map +0 -1
- package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.js +0 -261
- package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.js.map +0 -1
- package/dist/@codegen/klend/instructions/withdrawObligationUsol.d.ts +0 -41
- package/dist/@codegen/klend/instructions/withdrawObligationUsol.d.ts.map +0 -1
- package/dist/@codegen/klend/instructions/withdrawObligationUsol.js +0 -135
- package/dist/@codegen/klend/instructions/withdrawObligationUsol.js.map +0 -1
- package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.d.ts +0 -51
- package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.d.ts.map +0 -1
- package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.js +0 -28
- package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.js.map +0 -1
- package/dist/@codegen/klend/types/BorrowOrder.d.ts +0 -192
- package/dist/@codegen/klend/types/BorrowOrder.d.ts.map +0 -1
- package/dist/@codegen/klend/types/BorrowOrder.js +0 -194
- package/dist/@codegen/klend/types/BorrowOrder.js.map +0 -1
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.d.ts +0 -39
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.d.ts.map +0 -1
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.js +0 -100
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.js.map +0 -1
- package/dist/@codegen/klend/types/WithdrawQueue.d.ts +0 -64
- package/dist/@codegen/klend/types/WithdrawQueue.d.ts.map +0 -1
- package/dist/@codegen/klend/types/WithdrawQueue.js +0 -104
- package/dist/@codegen/klend/types/WithdrawQueue.js.map +0 -1
- package/dist/lending_operations/unstake_lst_collateral.d.ts +0 -12
- package/dist/lending_operations/unstake_lst_collateral.d.ts.map +0 -1
- package/dist/lending_operations/unstake_lst_collateral.js +0 -104
- package/dist/lending_operations/unstake_lst_collateral.js.map +0 -1
- package/src/@codegen/klend/accounts/PoolState.ts +0 -192
- package/src/@codegen/klend/accounts/UnstakeTicket.ts +0 -160
- package/src/@codegen/klend/accounts/WithdrawTicket.ts +0 -256
- package/src/@codegen/klend/instructions/enqueueToWithdraw.ts +0 -89
- package/src/@codegen/klend/instructions/fillBorrowOrder.ts +0 -96
- package/src/@codegen/klend/instructions/recoverInvalidTicketCollateral.ts +0 -96
- package/src/@codegen/klend/instructions/setBorrowOrder.ts +0 -77
- package/src/@codegen/klend/instructions/unstakeLstCollateralEnd.ts +0 -251
- package/src/@codegen/klend/instructions/unstakeLstCollateralStart.ts +0 -353
- package/src/@codegen/klend/instructions/withdrawObligationUsol.ts +0 -168
- package/src/@codegen/klend/instructions/withdrawQueuedLiquidity.ts +0 -92
- package/src/@codegen/klend/types/BorrowOrder.ts +0 -267
- package/src/@codegen/klend/types/BorrowOrderConfigArgs.ts +0 -87
- package/src/@codegen/klend/types/WithdrawQueue.ts +0 -117
- package/src/lending_operations/unstake_lst_collateral.ts +0 -174
package/src/classes/manager.ts
CHANGED
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
} from './vault';
|
|
34
34
|
import {
|
|
35
35
|
AddAssetToMarketParams,
|
|
36
|
+
AllOracleAccounts,
|
|
36
37
|
CreateKaminoMarketParams,
|
|
37
38
|
createReserveIxs,
|
|
38
39
|
DEFAULT_PUBLIC_KEY,
|
|
@@ -1278,10 +1279,14 @@ export class KaminoManager {
|
|
|
1278
1279
|
/**
|
|
1279
1280
|
* This will load the onchain state for all the reserves that the vaults have allocations for, deduplicating the reserves
|
|
1280
1281
|
* @param vaults - the vault states to load reserves for
|
|
1282
|
+
* @param oracleAccounts (optional) all reserve oracle accounts, if not supplied will make an additional rpc call to fetch these accounts
|
|
1281
1283
|
* @returns a hashmap from each reserve pubkey to the reserve state
|
|
1282
1284
|
*/
|
|
1283
|
-
async loadVaultsReserves(
|
|
1284
|
-
|
|
1285
|
+
async loadVaultsReserves(
|
|
1286
|
+
vaults: VaultState[],
|
|
1287
|
+
oracleAccounts?: AllOracleAccounts
|
|
1288
|
+
): Promise<Map<Address, KaminoReserve>> {
|
|
1289
|
+
return this._vaultClient.loadVaultsReserves(vaults, oracleAccounts);
|
|
1285
1290
|
}
|
|
1286
1291
|
|
|
1287
1292
|
/**
|
|
@@ -1566,17 +1571,6 @@ export const MARKET_UPDATER = new ConfigUpdater(UpdateLendingMarketMode.fromDeco
|
|
|
1566
1571
|
[UpdateLendingMarketMode.UpdateInitialDepositAmount.kind]: config.minInitialDepositAmount,
|
|
1567
1572
|
[UpdateLendingMarketMode.UpdateObligationOrderCreationEnabled.kind]: config.obligationOrderCreationEnabled,
|
|
1568
1573
|
[UpdateLendingMarketMode.UpdateObligationOrderExecutionEnabled.kind]: config.obligationOrderExecutionEnabled,
|
|
1569
|
-
[UpdateLendingMarketMode.UpdateMatureReserveDebtLiquidationEnabled.kind]: config.matureReserveDebtLiquidationEnabled,
|
|
1570
|
-
[UpdateLendingMarketMode.UpdateObligationBorrowDebtTermLiquidationEnabled.kind]:
|
|
1571
|
-
config.obligationBorrowDebtTermLiquidationEnabled,
|
|
1572
|
-
[UpdateLendingMarketMode.UpdateProposerAuthority.kind]: config.proposerAuthority,
|
|
1573
|
-
[UpdateLendingMarketMode.UpdateBorrowOrderCreationEnabled.kind]: config.borrowOrderCreationEnabled,
|
|
1574
|
-
[UpdateLendingMarketMode.UpdateBorrowOrderExecutionEnabled.kind]: config.borrowOrderExecutionEnabled,
|
|
1575
|
-
[UpdateLendingMarketMode.UpdatePriceTriggeredLiquidationDisabled.kind]: config.priceTriggeredLiquidationDisabled,
|
|
1576
|
-
[UpdateLendingMarketMode.UpdateUnstakingPoolState.kind]: config.unstakingPoolState,
|
|
1577
|
-
[UpdateLendingMarketMode.UpdateWithdrawTicketIssuanceEnabled.kind]: config.withdrawTicketIssuanceEnabled,
|
|
1578
|
-
[UpdateLendingMarketMode.UpdateWithdrawTicketRedemptionEnabled.kind]: config.withdrawTicketRedemptionEnabled,
|
|
1579
|
-
[UpdateLendingMarketMode.UpdateMinWithdrawQueuedLiquidityValue.kind]: config.minWithdrawQueuedLiquidityValue,
|
|
1580
1574
|
}));
|
|
1581
1575
|
|
|
1582
1576
|
function parseForChangesMarketConfigAndGetIxs(
|
package/src/classes/market.ts
CHANGED
|
@@ -54,8 +54,6 @@ import { parseTokenSymbol, parseZeroPaddedUtf8 } from './utils';
|
|
|
54
54
|
import { ObligationZP } from '../@codegen/klend/zero_padding';
|
|
55
55
|
import { checkDefined } from '../utils/validations';
|
|
56
56
|
import { Buffer } from 'buffer';
|
|
57
|
-
import { UNSTAKING_POOL_STAGING_ID, unstakingPoolMintPda } from './unstakingPool';
|
|
58
|
-
import { PROGRAM_ID as UNSTAKING_POOL_ID } from '../@codegen/unstaking_pool/programId';
|
|
59
57
|
|
|
60
58
|
export type KaminoMarketRpcApi = GetAccountInfoApi &
|
|
61
59
|
GetMultipleAccountsApi &
|
|
@@ -66,9 +64,6 @@ export type KaminoMarketRpcApi = GetAccountInfoApi &
|
|
|
66
64
|
GetBalanceApi;
|
|
67
65
|
|
|
68
66
|
const base58Decoder = getBase58Decoder();
|
|
69
|
-
// This is a list of reserves (for STAGING only) that were incorrectly initialized and mess up with the mapping from mint -> reserve
|
|
70
|
-
// This can be removed once we migrate all ixs to act upon reserve pubkey instead of mints
|
|
71
|
-
export const INCORRECT_RESERVES_STAGING: Address[] = [address('5JPmNb5oxRZF4yp3kQL44HWmZnbyjguRVZbo2ew6FoxV')];
|
|
72
67
|
|
|
73
68
|
export interface ReserveRewardInfo {
|
|
74
69
|
rewardsPerSecond: Decimal; // not lamport
|
|
@@ -235,15 +230,8 @@ export class KaminoMarket {
|
|
|
235
230
|
this.reservesActive = getReservesActive(this.reserves);
|
|
236
231
|
}
|
|
237
232
|
|
|
238
|
-
async reloadSingleReserve(reservePk: Address, reserveData?: Reserve
|
|
239
|
-
const reserve = await getSingleReserve(
|
|
240
|
-
reservePk,
|
|
241
|
-
this.rpc,
|
|
242
|
-
this.recentSlotDurationMs,
|
|
243
|
-
reserveData,
|
|
244
|
-
undefined,
|
|
245
|
-
programId
|
|
246
|
-
);
|
|
233
|
+
async reloadSingleReserve(reservePk: Address, reserveData?: Reserve): Promise<void> {
|
|
234
|
+
const reserve = await getSingleReserve(reservePk, this.rpc, this.recentSlotDurationMs, reserveData);
|
|
247
235
|
this.reserves.set(reservePk, reserve);
|
|
248
236
|
this.reservesActive.set(reservePk, reserve);
|
|
249
237
|
}
|
|
@@ -256,20 +244,6 @@ export class KaminoMarket {
|
|
|
256
244
|
return this.address;
|
|
257
245
|
}
|
|
258
246
|
|
|
259
|
-
getUsolPoolAddress(): Address {
|
|
260
|
-
return this.state.unstakingPoolState;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
getUsolPoolProgramId(): Address {
|
|
264
|
-
return this.programId == PROGRAM_ID ? UNSTAKING_POOL_ID : UNSTAKING_POOL_STAGING_ID;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
async getUsolPoolMint(): Promise<Address> {
|
|
268
|
-
const usolPoolPk = this.getUsolPoolAddress();
|
|
269
|
-
const usolPoolProgram = this.getUsolPoolProgramId();
|
|
270
|
-
return (await unstakingPoolMintPda(usolPoolPk, usolPoolProgram))[0];
|
|
271
|
-
}
|
|
272
|
-
|
|
273
247
|
/**
|
|
274
248
|
* Get a list of reserves for this market
|
|
275
249
|
*/
|
|
@@ -1610,7 +1584,7 @@ export async function getReservesForMarket(
|
|
|
1610
1584
|
recentSlotDurationMs: number,
|
|
1611
1585
|
oracleAccounts?: AllOracleAccounts
|
|
1612
1586
|
): Promise<Map<Address, KaminoReserve>> {
|
|
1613
|
-
|
|
1587
|
+
const reserves = await rpc
|
|
1614
1588
|
.getProgramAccounts(programId, {
|
|
1615
1589
|
filters: [
|
|
1616
1590
|
{
|
|
@@ -1627,10 +1601,6 @@ export async function getReservesForMarket(
|
|
|
1627
1601
|
encoding: 'base64',
|
|
1628
1602
|
})
|
|
1629
1603
|
.send();
|
|
1630
|
-
// If staging env always filter the incorrect reserves
|
|
1631
|
-
if (programId !== PROGRAM_ID) {
|
|
1632
|
-
reserves = reserves.filter((reserve) => INCORRECT_RESERVES_STAGING.includes(reserve.pubkey) === false);
|
|
1633
|
-
}
|
|
1634
1604
|
const deserializedReserves: ReserveWithAddress[] = reserves.map((reserve) => {
|
|
1635
1605
|
if (reserve.account === null) {
|
|
1636
1606
|
throw new Error(`Reserve account ${reserve.pubkey} does not exist`);
|
|
@@ -1667,10 +1637,9 @@ export async function getSingleReserve(
|
|
|
1667
1637
|
rpc: Rpc<KaminoReserveRpcApi>,
|
|
1668
1638
|
recentSlotDurationMs: number,
|
|
1669
1639
|
reserveData?: Reserve,
|
|
1670
|
-
oracleAccounts?: AllOracleAccounts
|
|
1671
|
-
programId: Address = PROGRAM_ID
|
|
1640
|
+
oracleAccounts?: AllOracleAccounts
|
|
1672
1641
|
): Promise<KaminoReserve> {
|
|
1673
|
-
const reserve = reserveData ?? (await Reserve.fetch(rpc, reservePk
|
|
1642
|
+
const reserve = reserveData ?? (await Reserve.fetch(rpc, reservePk));
|
|
1674
1643
|
|
|
1675
1644
|
if (reserve === null) {
|
|
1676
1645
|
throw new Error(`Reserve account ${reservePk} does not exist`);
|
|
@@ -270,7 +270,7 @@ export class KaminoObligation {
|
|
|
270
270
|
* Returns obligation orders (including the null ones, i.e. non-active positions in the orders' array).
|
|
271
271
|
*/
|
|
272
272
|
getOrders(): Array<KaminoObligationOrder | null> {
|
|
273
|
-
return this.state.
|
|
273
|
+
return this.state.orders.map((order) => KaminoObligationOrder.fromState(order));
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
/**
|
package/src/classes/reserve.ts
CHANGED
|
@@ -144,7 +144,7 @@ export class KaminoReserve {
|
|
|
144
144
|
* @returns the available liquidity amount of the reserve in lamports
|
|
145
145
|
*/
|
|
146
146
|
getLiquidityAvailableAmount(): Decimal {
|
|
147
|
-
return new Decimal(this.state.liquidity.
|
|
147
|
+
return new Decimal(this.state.liquidity.availableAmount.toString());
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
/**
|
|
@@ -199,7 +199,7 @@ export class KaminoReserve {
|
|
|
199
199
|
* @returns the origination fee percentage of the reserve
|
|
200
200
|
*/
|
|
201
201
|
getBorrowFee = (): Decimal => {
|
|
202
|
-
return new Fraction(this.state.config.fees.
|
|
202
|
+
return new Fraction(this.state.config.fees.borrowFeeSf).toDecimal();
|
|
203
203
|
};
|
|
204
204
|
|
|
205
205
|
/**
|
|
@@ -1163,12 +1163,13 @@ export async function createReserveIxs(
|
|
|
1163
1163
|
|
|
1164
1164
|
const { liquiditySupplyVault, collateralMint, collateralSupplyVault, feeVault } = await reservePdas(
|
|
1165
1165
|
programId,
|
|
1166
|
-
|
|
1166
|
+
lendingMarket,
|
|
1167
|
+
liquidityMint
|
|
1167
1168
|
);
|
|
1168
1169
|
const [lendingMarketAuthority] = await lendingMarketAuthPda(lendingMarket, programId);
|
|
1169
1170
|
|
|
1170
1171
|
const accounts: InitReserveAccounts = {
|
|
1171
|
-
|
|
1172
|
+
lendingMarketOwner: owner,
|
|
1172
1173
|
lendingMarket: lendingMarket,
|
|
1173
1174
|
lendingMarketAuthority: lendingMarketAuthority,
|
|
1174
1175
|
reserve: reserveAddress.address,
|
|
@@ -1221,7 +1222,7 @@ export const RESERVE_CONFIG_UPDATER = new ConfigUpdater(UpdateConfigMode.fromDec
|
|
|
1221
1222
|
[UpdateConfigMode.UpdateLiquidationThresholdPct.kind]: config.liquidationThresholdPct,
|
|
1222
1223
|
[UpdateConfigMode.UpdateProtocolLiquidationFee.kind]: config.protocolLiquidationFeePct,
|
|
1223
1224
|
[UpdateConfigMode.UpdateProtocolTakeRate.kind]: config.protocolTakeRatePct,
|
|
1224
|
-
[UpdateConfigMode.
|
|
1225
|
+
[UpdateConfigMode.UpdateFeesBorrowFee.kind]: config.fees.borrowFeeSf,
|
|
1225
1226
|
[UpdateConfigMode.UpdateFeesFlashLoanFee.kind]: config.fees.flashLoanFeeSf,
|
|
1226
1227
|
[UpdateConfigMode.DeprecatedUpdateFeesReferralFeeBps.kind]: [], // deprecated
|
|
1227
1228
|
[UpdateConfigMode.UpdateDepositLimit.kind]: config.depositLimit,
|
|
@@ -1255,7 +1256,7 @@ export const RESERVE_CONFIG_UPDATER = new ConfigUpdater(UpdateConfigMode.fromDec
|
|
|
1255
1256
|
[UpdateConfigMode.UpdateMinLiquidationBonusBps.kind]: config.minLiquidationBonusBps,
|
|
1256
1257
|
[UpdateConfigMode.UpdateDeleveragingMarginCallPeriod.kind]: config.deleveragingMarginCallPeriodSecs,
|
|
1257
1258
|
[UpdateConfigMode.UpdateBorrowFactor.kind]: config.borrowFactorPct,
|
|
1258
|
-
[UpdateConfigMode.
|
|
1259
|
+
[UpdateConfigMode.UpdateAssetTier.kind]: config.assetTier,
|
|
1259
1260
|
[UpdateConfigMode.UpdateElevationGroup.kind]: config.elevationGroups,
|
|
1260
1261
|
[UpdateConfigMode.UpdateDeleveragingThresholdDecreaseBpsPerDay.kind]: config.deleveragingThresholdDecreaseBpsPerDay,
|
|
1261
1262
|
[UpdateConfigMode.DeprecatedUpdateMultiplierSideBoost.kind]: [], // deprecated
|
|
@@ -1273,12 +1274,6 @@ export const RESERVE_CONFIG_UPDATER = new ConfigUpdater(UpdateConfigMode.fromDec
|
|
|
1273
1274
|
[UpdateConfigMode.UpdateAutodeleverageEnabled.kind]: config.autodeleverageEnabled,
|
|
1274
1275
|
[UpdateConfigMode.UpdateDeleveragingBonusIncreaseBpsPerDay.kind]: config.deleveragingBonusIncreaseBpsPerDay,
|
|
1275
1276
|
[UpdateConfigMode.UpdateProtocolOrderExecutionFee.kind]: config.protocolOrderExecutionFeePct,
|
|
1276
|
-
[UpdateConfigMode.UpdateDebtMaturityTimestamp.kind]: config.debtMaturityTimestamp,
|
|
1277
|
-
[UpdateConfigMode.UpdateDebtTermSeconds.kind]: config.debtTermSeconds,
|
|
1278
|
-
[UpdateConfigMode.UpdateProposerAuthorityLock.kind]: config.proposerAuthorityLocked,
|
|
1279
|
-
[UpdateConfigMode.UpdateMinDeleveragingBonusBps.kind]: config.minDeleveragingBonusBps,
|
|
1280
|
-
[UpdateConfigMode.UpdateCanUnstakeLstCollateral.kind]: config.canUnstakeLstCollateral,
|
|
1281
|
-
[UpdateConfigMode.UpdateLtvLamportsMargin.kind]: config.ltvLamportsMargin,
|
|
1282
1277
|
}));
|
|
1283
1278
|
|
|
1284
1279
|
export async function updateEntireReserveConfigIx(
|
|
@@ -1350,7 +1345,7 @@ const NON_VALIDATED_DISCRIMINATORS = [
|
|
|
1350
1345
|
function shouldSkipValidation(mode: UpdateConfigModeKind, reserve: Reserve | undefined): boolean {
|
|
1351
1346
|
return (
|
|
1352
1347
|
NON_VALIDATED_DISCRIMINATORS.includes(mode.discriminator) &&
|
|
1353
|
-
!reserve?.liquidity.
|
|
1348
|
+
!reserve?.liquidity.availableAmount.gten(MIN_INITIAL_DEPOSIT)
|
|
1354
1349
|
);
|
|
1355
1350
|
}
|
|
1356
1351
|
|
|
@@ -17,7 +17,6 @@ import { TOKEN_2022_PROGRAM_ADDRESS } from '@solana-program/token-2022';
|
|
|
17
17
|
import { getAssociatedTokenAddress } from '../lib';
|
|
18
18
|
import { PoolState, UnstakeTicket } from '../@codegen/unstaking_pool/accounts';
|
|
19
19
|
import {
|
|
20
|
-
createAssociatedTokenAccountIdempotentInstruction,
|
|
21
20
|
createLookupTableIx,
|
|
22
21
|
DEFAULT_PUBLIC_KEY,
|
|
23
22
|
extendLookupTableIxs,
|
|
@@ -50,7 +49,6 @@ import {
|
|
|
50
49
|
Rpc,
|
|
51
50
|
SolanaRpcApi,
|
|
52
51
|
TransactionSigner,
|
|
53
|
-
getBase58Decoder,
|
|
54
52
|
} from '@solana/kit';
|
|
55
53
|
import { getCreateAccountInstruction, SYSTEM_PROGRAM_ADDRESS } from '@solana-program/system';
|
|
56
54
|
import { SYSVAR_CLOCK_ADDRESS, SYSVAR_INSTRUCTIONS_ADDRESS, SYSVAR_RENT_ADDRESS } from '@solana/sysvars';
|
|
@@ -64,29 +62,16 @@ const STAKE_HISTORY_PROGRAM_ID: Address = address('SysvarStakeHistory11111111111
|
|
|
64
62
|
const STAKE_ACCOUNT_SIZE: number = 200;
|
|
65
63
|
export const STAKE_POOL_SIZE: number = 611;
|
|
66
64
|
const addressEncoder = getAddressEncoder();
|
|
67
|
-
const base58Decoder = getBase58Decoder();
|
|
68
65
|
|
|
69
66
|
/**
|
|
70
67
|
* Unstaking sol mint seed
|
|
71
68
|
*/
|
|
72
69
|
export const UNSTAKING_SOL_MINT_SEED = Buffer.from('unstaking_sol_mint');
|
|
73
70
|
|
|
74
|
-
/**
|
|
75
|
-
* Unstaking sol mint seed
|
|
76
|
-
*/
|
|
77
|
-
export const UNSTAKING_SOL_WSOL_VAULT_SEED = Buffer.from('wsol_vault');
|
|
78
|
-
|
|
79
71
|
/**
|
|
80
72
|
* Unstaking sol pool base authority seed
|
|
81
73
|
*/
|
|
82
|
-
export const BASE_POOL_AUTHORITY_SEED = Buffer.from('
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Unstaking sol pool lending market authority seed
|
|
86
|
-
*/
|
|
87
|
-
export const UNSTAKING_POOL_AUTHORITY_SEED = Buffer.from('upa');
|
|
88
|
-
|
|
89
|
-
/**
|
|
74
|
+
export const BASE_POOL_AUTHORITY_SEED = Buffer.from('authority');
|
|
90
75
|
|
|
91
76
|
/**
|
|
92
77
|
* KaminoPoolClient is a class that provides a high-level interface to interact with the Kamino Pool program.
|
|
@@ -127,8 +112,8 @@ export class UnstakingPoolClient {
|
|
|
127
112
|
});
|
|
128
113
|
|
|
129
114
|
const unstakingSolMint = (await unstakingPoolMintPda(poolState.address))[0];
|
|
130
|
-
const basePoolAuthority = (await
|
|
131
|
-
const wsolVault =
|
|
115
|
+
const basePoolAuthority = (await unstakingPoolAuthorityPda(poolState.address))[0];
|
|
116
|
+
const wsolVault = await getAssociatedTokenAddress(WRAPPED_SOL_MINT, basePoolAuthority);
|
|
132
117
|
|
|
133
118
|
const initPoolAccounts: InitializePoolAccounts = {
|
|
134
119
|
admin: poolConfig.admin,
|
|
@@ -291,7 +276,6 @@ export class UnstakingPoolClient {
|
|
|
291
276
|
* @param stakedSolMint - staked sol mint
|
|
292
277
|
* @param stakedSolToDeposit - staked sol to convert to USOL (at the pool ratio)
|
|
293
278
|
* @param minSharesToReceive - parameter to control slippage
|
|
294
|
-
* @param initUsolAta - pass if you want the usol ata initialized
|
|
295
279
|
* @returns burn instruction
|
|
296
280
|
*/
|
|
297
281
|
async mintIx(
|
|
@@ -301,8 +285,7 @@ export class UnstakingPoolClient {
|
|
|
301
285
|
unstakeTicket: TransactionSigner,
|
|
302
286
|
stakedSolMint: Address,
|
|
303
287
|
stakedSolToDeposit: BN,
|
|
304
|
-
minSharesToReceive: BN
|
|
305
|
-
initUsolAta: boolean
|
|
288
|
+
minSharesToReceive: BN
|
|
306
289
|
): Promise<MintIxs> {
|
|
307
290
|
const pool = await poolState.getState(this.getConnection());
|
|
308
291
|
// Create unstake ticket ix
|
|
@@ -357,17 +340,7 @@ export class UnstakingPoolClient {
|
|
|
357
340
|
accounts: ixAccounts.concat(remainingAccounts),
|
|
358
341
|
data: ix.data,
|
|
359
342
|
};
|
|
360
|
-
|
|
361
|
-
if (initUsolAta) {
|
|
362
|
-
const [_, createAtaIx] = await createAssociatedTokenAccountIdempotentInstruction(
|
|
363
|
-
user,
|
|
364
|
-
pool.unstakingSolMint,
|
|
365
|
-
user.address,
|
|
366
|
-
TOKEN_PROGRAM_ADDRESS
|
|
367
|
-
);
|
|
368
|
-
ixs.splice(1, 0, createAtaIx);
|
|
369
|
-
}
|
|
370
|
-
return { mintIxs: ixs, additionalSigners: remainingSigners };
|
|
343
|
+
return { mintIxs: [createUnstakeTicketIx, mintIx], additionalSigners: remainingSigners };
|
|
371
344
|
}
|
|
372
345
|
|
|
373
346
|
/**
|
|
@@ -494,46 +467,6 @@ export class UnstakingPool {
|
|
|
494
467
|
}
|
|
495
468
|
}
|
|
496
469
|
|
|
497
|
-
export async function getAllTicketsForUser(
|
|
498
|
-
rpc: Rpc<GetProgramAccountsApi>,
|
|
499
|
-
user: Address,
|
|
500
|
-
programId: Address = UNSTAKING_POOL_ID
|
|
501
|
-
): Promise<Array<UnstakeTicketInfo>> {
|
|
502
|
-
const results = await rpc
|
|
503
|
-
.getProgramAccounts(programId, {
|
|
504
|
-
filters: [
|
|
505
|
-
{
|
|
506
|
-
dataSize: BigInt(UnstakeTicket.layout.span + 8),
|
|
507
|
-
},
|
|
508
|
-
{
|
|
509
|
-
memcmp: {
|
|
510
|
-
offset: 0n,
|
|
511
|
-
bytes: base58Decoder.decode(UnstakeTicket.discriminator) as Base58EncodedBytes,
|
|
512
|
-
encoding: 'base58',
|
|
513
|
-
},
|
|
514
|
-
},
|
|
515
|
-
{
|
|
516
|
-
memcmp: {
|
|
517
|
-
offset: 8n,
|
|
518
|
-
bytes: user.toString() as Base58EncodedBytes,
|
|
519
|
-
encoding: 'base58',
|
|
520
|
-
},
|
|
521
|
-
},
|
|
522
|
-
],
|
|
523
|
-
encoding: 'base64',
|
|
524
|
-
})
|
|
525
|
-
.send();
|
|
526
|
-
|
|
527
|
-
return results.map((result) => {
|
|
528
|
-
return { state: UnstakeTicket.decode(Buffer.from(result.account.data[0], 'base64')), pk: result.pubkey };
|
|
529
|
-
});
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
export type UnstakeTicketInfo = {
|
|
533
|
-
pk: Address;
|
|
534
|
-
state: UnstakeTicket;
|
|
535
|
-
};
|
|
536
|
-
|
|
537
470
|
export type StakeAccountInfo = {
|
|
538
471
|
pk: Address;
|
|
539
472
|
stakeAccount: StakeAccount;
|
|
@@ -560,17 +493,7 @@ export function unstakingPoolMintPda(
|
|
|
560
493
|
});
|
|
561
494
|
}
|
|
562
495
|
|
|
563
|
-
export function
|
|
564
|
-
pool: Address,
|
|
565
|
-
programId: Address = UNSTAKING_POOL_ID
|
|
566
|
-
): Promise<ProgramDerivedAddress> {
|
|
567
|
-
return getProgramDerivedAddress({
|
|
568
|
-
seeds: [UNSTAKING_SOL_WSOL_VAULT_SEED, addressEncoder.encode(pool)],
|
|
569
|
-
programAddress: programId,
|
|
570
|
-
});
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
export function unstakingPoolBaseAuthorityPda(
|
|
496
|
+
export function unstakingPoolAuthorityPda(
|
|
574
497
|
pool: Address,
|
|
575
498
|
programId: Address = UNSTAKING_POOL_ID
|
|
576
499
|
): Promise<ProgramDerivedAddress> {
|
package/src/classes/vault.ts
CHANGED
|
@@ -21,6 +21,9 @@ import {
|
|
|
21
21
|
Slot,
|
|
22
22
|
SolanaRpcApi,
|
|
23
23
|
TransactionSigner,
|
|
24
|
+
AccountInfoWithPubkey,
|
|
25
|
+
AccountInfoBase,
|
|
26
|
+
AccountInfoWithJsonData,
|
|
24
27
|
} from '@solana/kit';
|
|
25
28
|
import {
|
|
26
29
|
AllOracleAccounts,
|
|
@@ -77,7 +80,10 @@ import { Fraction } from './fraction';
|
|
|
77
80
|
import {
|
|
78
81
|
createAtasIdempotent,
|
|
79
82
|
createWsolAtaIfMissing,
|
|
83
|
+
getAllStandardTokenProgramTokenAccounts,
|
|
80
84
|
getKVaultSharesMetadataPda,
|
|
85
|
+
getTokenAccountAmount,
|
|
86
|
+
getTokenAccountMint,
|
|
81
87
|
lendingMarketAuthPda,
|
|
82
88
|
SECONDS_PER_YEAR,
|
|
83
89
|
U64_MAX,
|
|
@@ -112,12 +118,7 @@ import {
|
|
|
112
118
|
import { getCreateAccountInstruction, SYSTEM_PROGRAM_ADDRESS } from '@solana-program/system';
|
|
113
119
|
import { getInitializeKVaultSharesMetadataIx, getUpdateSharesMetadataIx, resolveMetadata } from '../utils/metadata';
|
|
114
120
|
import { decodeVaultState } from '../utils/vault';
|
|
115
|
-
import {
|
|
116
|
-
fetchAllMaybeToken,
|
|
117
|
-
fetchMaybeToken,
|
|
118
|
-
findAssociatedTokenPda,
|
|
119
|
-
getCloseAccountInstruction,
|
|
120
|
-
} from '@solana-program/token-2022';
|
|
121
|
+
import { fetchMaybeToken, findAssociatedTokenPda, getCloseAccountInstruction } from '@solana-program/token-2022';
|
|
121
122
|
import { TOKEN_PROGRAM_ADDRESS } from '@solana-program/token';
|
|
122
123
|
import { SYSVAR_INSTRUCTIONS_ADDRESS, SYSVAR_RENT_ADDRESS } from '@solana/sysvars';
|
|
123
124
|
import { noopSigner } from '../utils/signer';
|
|
@@ -1937,15 +1938,22 @@ export class KaminoVaultClient {
|
|
|
1937
1938
|
stakedShares: new Decimal(0),
|
|
1938
1939
|
totalShares: new Decimal(0),
|
|
1939
1940
|
};
|
|
1940
|
-
const userSharesAta = await getAssociatedTokenAddress(vaultState.sharesMint, user);
|
|
1941
|
-
const userSharesAccountInfo = await fetchMaybeToken(this.getConnection(), userSharesAta);
|
|
1942
|
-
if (userSharesAccountInfo.exists) {
|
|
1943
|
-
const userSharesAccount = userSharesAccountInfo.data;
|
|
1944
1941
|
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1942
|
+
const userSharesTokenAccounts = await getAllStandardTokenProgramTokenAccounts(this.getConnection(), user);
|
|
1943
|
+
|
|
1944
|
+
const userSharesTokenAccount = userSharesTokenAccounts.filter((tokenAccount) => {
|
|
1945
|
+
const accountData = tokenAccount.account.data;
|
|
1946
|
+
const mint = getTokenAccountMint(accountData);
|
|
1947
|
+
return mint === vaultState.sharesMint;
|
|
1948
|
+
});
|
|
1949
|
+
userShares.unstakedShares = userSharesTokenAccount.reduce((acc, tokenAccount) => {
|
|
1950
|
+
const accountData = tokenAccount.account.data;
|
|
1951
|
+
const amount = getTokenAccountAmount(accountData);
|
|
1952
|
+
if (amount !== null) {
|
|
1953
|
+
return acc.add(new Decimal(amount));
|
|
1954
|
+
}
|
|
1955
|
+
return acc;
|
|
1956
|
+
}, new Decimal(0));
|
|
1949
1957
|
|
|
1950
1958
|
if (await vault.hasFarm(this.getConnection())) {
|
|
1951
1959
|
const userSharesInFarm = await getUserSharesInTokensStakedInFarm(
|
|
@@ -1984,14 +1992,23 @@ export class KaminoVaultClient {
|
|
|
1984
1992
|
// stores vault address for each userSharesAta
|
|
1985
1993
|
const vaultUserShareBalance = new Map<Address, UserSharesForVault>();
|
|
1986
1994
|
|
|
1987
|
-
const
|
|
1995
|
+
const allUserTokenAccounts = await getAllStandardTokenProgramTokenAccounts(this.getConnection(), user);
|
|
1996
|
+
const userSharesTokenAccountsPerVault = new Map<
|
|
1997
|
+
Address,
|
|
1998
|
+
AccountInfoWithPubkey<AccountInfoBase & AccountInfoWithJsonData>[]
|
|
1999
|
+
>();
|
|
1988
2000
|
vaults.forEach(async (vault) => {
|
|
1989
2001
|
const state = vault.state;
|
|
1990
2002
|
if (!state) {
|
|
1991
2003
|
throw new Error(`Vault ${vault.address} not fetched`);
|
|
1992
2004
|
}
|
|
1993
|
-
|
|
1994
|
-
|
|
2005
|
+
|
|
2006
|
+
const userSharesTokenAccounts = allUserTokenAccounts.filter((tokenAccount) => {
|
|
2007
|
+
const accountData = tokenAccount.account.data;
|
|
2008
|
+
const mint = getTokenAccountMint(accountData);
|
|
2009
|
+
return mint === state.sharesMint;
|
|
2010
|
+
});
|
|
2011
|
+
userSharesTokenAccountsPerVault.set(vault.address, userSharesTokenAccounts);
|
|
1995
2012
|
|
|
1996
2013
|
if (await vault.hasFarm(this.getConnection())) {
|
|
1997
2014
|
const userFarmState = allUserFarmStatesMap.get(state.vaultFarm);
|
|
@@ -2015,27 +2032,29 @@ export class KaminoVaultClient {
|
|
|
2015
2032
|
}
|
|
2016
2033
|
});
|
|
2017
2034
|
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
}
|
|
2028
|
-
}
|
|
2035
|
+
userSharesTokenAccountsPerVault.forEach((userSharesTokenAccounts, vaultAddress) => {
|
|
2036
|
+
userSharesTokenAccounts.forEach((userSharesTokenAccount) => {
|
|
2037
|
+
let userSharesForVault = vaultUserShareBalance.get(vaultAddress);
|
|
2038
|
+
if (!userSharesForVault) {
|
|
2039
|
+
userSharesForVault = {
|
|
2040
|
+
unstakedShares: new Decimal(0),
|
|
2041
|
+
stakedShares: new Decimal(0),
|
|
2042
|
+
totalShares: new Decimal(0),
|
|
2043
|
+
};
|
|
2044
|
+
}
|
|
2029
2045
|
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2046
|
+
if (!userSharesTokenAccount) {
|
|
2047
|
+
vaultUserShareBalance.set(vaultAddress, userSharesForVault);
|
|
2048
|
+
} else {
|
|
2049
|
+
const accountData = userSharesTokenAccount.account.data;
|
|
2050
|
+
const amount = getTokenAccountAmount(accountData);
|
|
2051
|
+
if (amount !== null) {
|
|
2052
|
+
userSharesForVault.unstakedShares = new Decimal(amount);
|
|
2053
|
+
userSharesForVault.totalShares = userSharesForVault.unstakedShares.add(userSharesForVault.stakedShares);
|
|
2054
|
+
vaultUserShareBalance.set(vaultAddress, userSharesForVault);
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
});
|
|
2039
2058
|
});
|
|
2040
2059
|
|
|
2041
2060
|
return vaultUserShareBalance;
|
|
@@ -2351,23 +2370,11 @@ export class KaminoVaultClient {
|
|
|
2351
2370
|
return this.loadVaultsReserves([vaultState]);
|
|
2352
2371
|
}
|
|
2353
2372
|
|
|
2354
|
-
|
|
2355
|
-
* This will load the onchain state for all the reserves that the vaults have allocations for, deduplicating the reserves
|
|
2356
|
-
* @param vaults - the vault states to load reserves for
|
|
2357
|
-
* @param oracleAccounts (optional) all reserve oracle accounts, if not supplied will make an additional rpc call to fetch these accounts
|
|
2358
|
-
* @returns a hashmap from each reserve pubkey to the reserve state
|
|
2359
|
-
*/
|
|
2360
|
-
async loadVaultsReserves(
|
|
2361
|
-
vaults: VaultState[],
|
|
2362
|
-
oracleAccounts?: AllOracleAccounts
|
|
2363
|
-
): Promise<Map<Address, KaminoReserve>> {
|
|
2364
|
-
const vaultReservesAddressesSet = new Set<Address>(vaults.flatMap((vault) => this.getVaultReserves(vault)));
|
|
2365
|
-
const vaultReservesAddresses = [...vaultReservesAddressesSet];
|
|
2373
|
+
private async loadReserializedReserves(vaultReservesAddresses: Address[]) {
|
|
2366
2374
|
const reserveAccounts = await this.getConnection()
|
|
2367
2375
|
.getMultipleAccounts(vaultReservesAddresses, { commitment: 'processed' })
|
|
2368
2376
|
.send();
|
|
2369
|
-
|
|
2370
|
-
const deserializedReserves = reserveAccounts.value.map((reserve, i) => {
|
|
2377
|
+
return reserveAccounts.value.map((reserve, i) => {
|
|
2371
2378
|
if (reserve === null) {
|
|
2372
2379
|
// maybe reuse old here
|
|
2373
2380
|
throw new Error(`Reserve account ${vaultReservesAddresses[i]} was not found`);
|
|
@@ -2381,11 +2388,25 @@ export class KaminoVaultClient {
|
|
|
2381
2388
|
state: reserveAccount,
|
|
2382
2389
|
};
|
|
2383
2390
|
});
|
|
2391
|
+
}
|
|
2384
2392
|
|
|
2393
|
+
/**
|
|
2394
|
+
* This will load the onchain state for all the reserves that the vaults have allocations for, deduplicating the reserves
|
|
2395
|
+
* @param vaults - the vault states to load reserves for
|
|
2396
|
+
* @param oracleAccounts (optional) all reserve oracle accounts, if not supplied will make an additional rpc call to fetch these accounts
|
|
2397
|
+
* @returns a hashmap from each reserve pubkey to the reserve state
|
|
2398
|
+
*/
|
|
2399
|
+
async loadVaultsReserves(
|
|
2400
|
+
vaults: VaultState[],
|
|
2401
|
+
oracleAccounts?: AllOracleAccounts
|
|
2402
|
+
): Promise<Map<Address, KaminoReserve>> {
|
|
2403
|
+
const vaultReservesAddressesSet = new Set<Address>(vaults.flatMap((vault) => this.getVaultReserves(vault)));
|
|
2404
|
+
const vaultReservesAddresses = [...vaultReservesAddressesSet];
|
|
2405
|
+
const deserializedReserves = await batchFetch(vaultReservesAddresses, (chunk) =>
|
|
2406
|
+
this.loadReserializedReserves(chunk)
|
|
2407
|
+
);
|
|
2385
2408
|
const reservesAndOracles = await getTokenOracleData(this.getConnection(), deserializedReserves, oracleAccounts);
|
|
2386
|
-
|
|
2387
2409
|
const kaminoReserves = new Map<Address, KaminoReserve>();
|
|
2388
|
-
|
|
2389
2410
|
reservesAndOracles.forEach(([reserve, oracle], index) => {
|
|
2390
2411
|
if (!oracle) {
|
|
2391
2412
|
throw Error(
|
|
@@ -2849,7 +2870,7 @@ export class KaminoVaultClient {
|
|
|
2849
2870
|
}
|
|
2850
2871
|
|
|
2851
2872
|
/**
|
|
2852
|
-
* This will return the APY of the vault under the assumption that all the available tokens in the vault are all the time invested in the reserves as
|
|
2873
|
+
* This will return the APY of the vault under the assumption that all the available tokens in the vault are all the time invested in the reserves as requested by the weights; for percentage it needs multiplication by 100
|
|
2853
2874
|
* @param vault - the kamino vault to get APY for
|
|
2854
2875
|
* @param slot - current slot
|
|
2855
2876
|
* @param [vaultReservesMap] - 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
|