@kamino-finance/klend-sdk 5.1.0 → 5.1.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.
Files changed (31) hide show
  1. package/README_KAMINO_MANAGER.md +24 -3
  2. package/dist/classes/manager.d.ts +45 -2
  3. package/dist/classes/manager.d.ts.map +1 -1
  4. package/dist/classes/manager.js +54 -0
  5. package/dist/classes/manager.js.map +1 -1
  6. package/dist/classes/vault.d.ts +56 -4
  7. package/dist/classes/vault.d.ts.map +1 -1
  8. package/dist/classes/vault.js +107 -3
  9. package/dist/classes/vault.js.map +1 -1
  10. package/dist/client_kamino_manager.d.ts.map +1 -1
  11. package/dist/client_kamino_manager.js +6 -0
  12. package/dist/client_kamino_manager.js.map +1 -1
  13. package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts +9 -3
  14. package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts.map +1 -1
  15. package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +42 -32
  16. package/dist/idl_codegen_kamino_vault/accounts/VaultState.js.map +1 -1
  17. package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts +10 -10
  18. package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts.map +1 -1
  19. package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js +51 -52
  20. package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js.map +1 -1
  21. package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.d.ts +2 -2
  22. package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.d.ts.map +1 -1
  23. package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.js +4 -4
  24. package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.js.map +1 -1
  25. package/package.json +1 -1
  26. package/src/classes/manager.ts +80 -1
  27. package/src/classes/vault.ts +158 -4
  28. package/src/client_kamino_manager.ts +8 -0
  29. package/src/idl_codegen_kamino_vault/accounts/VaultState.ts +178 -175
  30. package/src/idl_codegen_kamino_vault/types/VaultConfigField.ts +117 -116
  31. package/src/idl_codegen_kamino_vault/types/WithdrawalCaps.ts +30 -30
@@ -61,6 +61,7 @@ import bs58 from 'bs58';
61
61
  import { getProgramAccounts } from '../utils/rpc';
62
62
 
63
63
  export const kaminoVaultId = new PublicKey('kvauTFR8qm1dhniz6pYuBZkuene3Hfrs1VQhVRgCNrr');
64
+ export const kaminoVaultStagingId = new PublicKey('STkvh7ostar39Fwr4uZKASs1RNNuYMFMTsE77FiRsL2');
64
65
 
65
66
  const TOKEN_VAULT_SEED = 'token_vault';
66
67
  const CTOKEN_VAULT_SEED = 'ctoken_vault';
@@ -391,7 +392,12 @@ export class KaminoVaultClient {
391
392
  * @param tokenAmount - token amount to be deposited, in decimals (will be converted in lamports)
392
393
  * @returns - an array of instructions to be used to be executed
393
394
  */
394
- async depositIxs(user: PublicKey, vault: KaminoVault, tokenAmount: Decimal): Promise<TransactionInstruction[]> {
395
+ async depositIxs(
396
+ user: PublicKey,
397
+ vault: KaminoVault,
398
+ tokenAmount: Decimal,
399
+ vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>
400
+ ): Promise<TransactionInstruction[]> {
395
401
  const vaultState = await vault.getState(this._connection);
396
402
 
397
403
  const userTokenAta = getAssociatedTokenAddress(vaultState.tokenMint, user);
@@ -450,7 +456,7 @@ export class KaminoVaultClient {
450
456
 
451
457
  const vaultReserves = this.getVaultReserves(vaultState);
452
458
 
453
- const vaultReservesState = await this.loadVaultReserves(vaultState);
459
+ const vaultReservesState = vaultReservesMap ? vaultReservesMap : await this.loadVaultReserves(vaultState);
454
460
 
455
461
  let vaultReservesAccountMetas: AccountMeta[] = [];
456
462
  let vaultReservesLendingMarkets: AccountMeta[] = [];
@@ -983,13 +989,32 @@ export class KaminoVaultClient {
983
989
  return reserveAllocationAvailableLiquidityToWithdraw;
984
990
  }
985
991
 
986
- private getVaultReserves(vault: VaultState): PublicKey[] {
992
+ /**
993
+ * This will get the list of all reserve pubkeys that the vault has allocations for
994
+ * @param vaultState - the vault state to load reserves for
995
+ * @returns a hashmap from each reserve pubkey to the reserve state
996
+ */
997
+ getAllVaultReserves(vault: VaultState): PublicKey[] {
998
+ return vault.vaultAllocationStrategy.map((vaultAllocation) => vaultAllocation.reserve);
999
+ }
1000
+
1001
+ /**
1002
+ * This will get the list of all reserve pubkeys that the vault has allocations for ex
1003
+ * @param vaultState - the vault state to load reserves for
1004
+ * @returns a hashmap from each reserve pubkey to the reserve state
1005
+ */
1006
+ getVaultReserves(vault: VaultState): PublicKey[] {
987
1007
  return vault.vaultAllocationStrategy
988
1008
  .filter((vaultAllocation) => !vaultAllocation.reserve.equals(PublicKey.default))
989
1009
  .map((vaultAllocation) => vaultAllocation.reserve);
990
1010
  }
991
1011
 
992
- private async loadVaultReserves(vaultState: VaultState): Promise<PubkeyHashMap<PublicKey, KaminoReserve>> {
1012
+ /**
1013
+ * This will load the onchain state for all the reserves that the vault has allocations for
1014
+ * @param vaultState - the vault state to load reserves for
1015
+ * @returns a hashmap from each reserve pubkey to the reserve state
1016
+ */
1017
+ async loadVaultReserves(vaultState: VaultState): Promise<PubkeyHashMap<PublicKey, KaminoReserve>> {
993
1018
  const vaultReservesAddresses = this.getVaultReserves(vaultState);
994
1019
  const reserveAccounts = await this._connection.getMultipleAccountsInfo(vaultReservesAddresses, 'processed');
995
1020
 
@@ -1026,6 +1051,122 @@ export class KaminoVaultClient {
1026
1051
 
1027
1052
  return kaminoReserves;
1028
1053
  }
1054
+
1055
+ /**
1056
+ * This will return an Holdings object which contains the amount available (uninvested) in vault, total amount invested in reseves and a breakdown of the amount invested in each reserve
1057
+ * @param vault - the kamino vault to get available liquidity to withdraw for
1058
+ * @param slot - current slot
1059
+ * @param vaultReserves - optional parameter; a hashmap from each reserve pubkey to the reserve state. If provided the function will be significantly faster as it will not have to fetch the reserves
1060
+ * @returns an Holdings object
1061
+ */
1062
+ async getVaultHoldings(
1063
+ vault: VaultState,
1064
+ slot: number,
1065
+ vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>
1066
+ ): Promise<VaultHoldings> {
1067
+ const vaultHoldings: VaultHoldings = {
1068
+ available: new Decimal(vault.tokenAvailable.toString()),
1069
+ invested: new Decimal(0),
1070
+ investedInReserves: new PubkeyHashMap<PublicKey, Decimal>(),
1071
+ };
1072
+
1073
+ const vaultReservesState = vaultReserves ? vaultReserves : await this.loadVaultReserves(vault);
1074
+
1075
+ vault.vaultAllocationStrategy.forEach((allocationStrategy) => {
1076
+ if (allocationStrategy.reserve.equals(PublicKey.default)) {
1077
+ return;
1078
+ }
1079
+
1080
+ const reserve = vaultReservesState.get(allocationStrategy.reserve);
1081
+ if (reserve === undefined) {
1082
+ throw new Error(`Reserve ${allocationStrategy.reserve.toBase58()} not found`);
1083
+ }
1084
+
1085
+ const reserveCollExchangeRate = reserve.getEstimatedCollateralExchangeRate(slot, 0);
1086
+ const reserveAllocationLiquidityAmount = new Decimal(allocationStrategy.cTokenAllocation.toString()).mul(
1087
+ reserveCollExchangeRate
1088
+ );
1089
+
1090
+ vaultHoldings.invested = vaultHoldings.invested.add(reserveAllocationLiquidityAmount);
1091
+ vaultHoldings.investedInReserves.set(allocationStrategy.reserve, reserveAllocationLiquidityAmount);
1092
+ });
1093
+
1094
+ return vaultHoldings;
1095
+ }
1096
+
1097
+ /**
1098
+ * This will return an overview of each reserve that is part of the vault allocation
1099
+ * @param vault - the kamino vault to get available liquidity to withdraw for
1100
+ * @param slot - current slot
1101
+ * @param vaultReserves - optional parameter; a hashmap from each reserve pubkey to the reserve state. If provided the function will be significantly faster as it will not have to fetch the reserves
1102
+ * @returns a hashmap from vault reserve pubkey to ReserveOverview object
1103
+ */
1104
+ async getVaultReservesDetails(
1105
+ vault: VaultState,
1106
+ slot: number,
1107
+ vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>
1108
+ ): Promise<PubkeyHashMap<PublicKey, ReserveOverview>> {
1109
+ const vaultReservesState = vaultReserves ? vaultReserves : await this.loadVaultReserves(vault);
1110
+ const reservesDetails = new PubkeyHashMap<PublicKey, ReserveOverview>();
1111
+
1112
+ vault.vaultAllocationStrategy.forEach((allocationStrategy) => {
1113
+ if (allocationStrategy.reserve.equals(PublicKey.default)) {
1114
+ return;
1115
+ }
1116
+
1117
+ const reserve = vaultReservesState.get(allocationStrategy.reserve);
1118
+ if (reserve === undefined) {
1119
+ throw new Error(`Reserve ${allocationStrategy.reserve.toBase58()} not found`);
1120
+ }
1121
+
1122
+ reserve.getBorrowedAmount();
1123
+ const reserveOverview: ReserveOverview = {
1124
+ supplyAPY: new Decimal(reserve.totalSupplyAPY(slot)),
1125
+ uUtilizationRatio: new Decimal(reserve.getEstimatedUtilizationRatio(slot, 0)),
1126
+ liquidationThresholdPct: new Decimal(reserve.state.config.liquidationThresholdPct),
1127
+ borrowedAmount: reserve.getBorrowedAmount(),
1128
+ };
1129
+ reservesDetails.set(allocationStrategy.reserve, reserveOverview);
1130
+ });
1131
+
1132
+ return reservesDetails;
1133
+ }
1134
+
1135
+ /**
1136
+ * 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
1137
+ * @param vault - the kamino vault to get APY for
1138
+ * @param slot - current slot
1139
+ * @param vaultReserves - optional parameter; a hashmap from each reserve pubkey to the reserve state. If provided the function will be significantly faster as it will not have to fetch the reserves
1140
+ * @returns APY for the vault
1141
+ */
1142
+ async getVaultTheoreticalAPY(
1143
+ vault: VaultState,
1144
+ slot: number,
1145
+ vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>
1146
+ ): Promise<Decimal> {
1147
+ const vaultReservesState = vaultReserves ? vaultReserves : await this.loadVaultReserves(vault);
1148
+
1149
+ let totalWeights = new Decimal(0);
1150
+ let totalAPY = new Decimal(0);
1151
+ vault.vaultAllocationStrategy.forEach((allocationStrategy) => {
1152
+ if (allocationStrategy.reserve.equals(PublicKey.default)) {
1153
+ return;
1154
+ }
1155
+
1156
+ const reserve = vaultReservesState.get(allocationStrategy.reserve);
1157
+ if (reserve === undefined) {
1158
+ throw new Error(`Reserve ${allocationStrategy.reserve.toBase58()} not found`);
1159
+ }
1160
+
1161
+ const reserveAPY = new Decimal(reserve.totalSupplyAPY(slot));
1162
+ const weight = new Decimal(allocationStrategy.targetAllocationWeight.toString());
1163
+ const weightedAPY = reserveAPY.mul(weight);
1164
+ totalAPY = totalAPY.add(weightedAPY);
1165
+ totalWeights = totalWeights.add(weight);
1166
+ });
1167
+
1168
+ return totalAPY.div(totalWeights);
1169
+ }
1029
1170
  } // KaminoVaultClient
1030
1171
 
1031
1172
  export class KaminoVault {
@@ -1134,3 +1275,16 @@ export type VaultHolder = {
1134
1275
  holderPubkey: PublicKey;
1135
1276
  amount: Decimal;
1136
1277
  };
1278
+
1279
+ export type VaultHoldings = {
1280
+ available: Decimal;
1281
+ invested: Decimal;
1282
+ investedInReserves: PubkeyHashMap<PublicKey, Decimal>;
1283
+ };
1284
+
1285
+ export type ReserveOverview = {
1286
+ supplyAPY: Decimal;
1287
+ uUtilizationRatio: Decimal;
1288
+ liquidationThresholdPct: Decimal;
1289
+ borrowedAmount: Decimal;
1290
+ };
@@ -496,6 +496,14 @@ async function main() {
496
496
  console.log('oracleConfigs', JSON.parse(JSON.stringify(oracleConfigs)));
497
497
  });
498
498
 
499
+ commands.command('get-all-vaults').action(async () => {
500
+ const env = initializeClient(false, false);
501
+ const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
502
+
503
+ const allVaults = await kaminoManager.getAllVaults();
504
+ console.log('all vaults', allVaults);
505
+ });
506
+
499
507
  commands
500
508
  .command('download-lending-market-config')
501
509
  .requiredOption('--lending-market <string>', 'Lending Market Address')
@@ -1,179 +1,181 @@
1
- import { PublicKey, Connection } from "@solana/web3.js"
2
- import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
3
- import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
4
- import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
5
- import { PROGRAM_ID } from "../programId"
1
+ import { PublicKey, Connection } from '@solana/web3.js';
2
+ import BN from 'bn.js'; // eslint-disable-line @typescript-eslint/no-unused-vars
3
+ import * as borsh from '@coral-xyz/borsh'; // eslint-disable-line @typescript-eslint/no-unused-vars
4
+ import * as types from '../types'; // eslint-disable-line @typescript-eslint/no-unused-vars
5
+ import { PROGRAM_ID } from '../programId';
6
6
 
7
7
  export interface VaultStateFields {
8
- adminAuthority: PublicKey
9
- baseVaultAuthority: PublicKey
10
- baseVaultAuthorityBump: BN
11
- tokenMint: PublicKey
12
- tokenMintDecimals: BN
13
- tokenVault: PublicKey
14
- tokenProgram: PublicKey
15
- sharesMint: PublicKey
16
- sharesMintDecimals: BN
17
- tokenAvailable: BN
18
- sharesIssued: BN
19
- availableCrankFunds: BN
20
- padding0: BN
21
- performanceFeeBps: BN
22
- managementFeeBps: BN
23
- lastFeeChargeTimestamp: BN
24
- prevAumSf: BN
25
- pendingFeesSf: BN
26
- vaultAllocationStrategy: Array<types.VaultAllocationFields>
27
- minDepositAmount: BN
28
- minWithdrawAmount: BN
29
- minInvestAmount: BN
30
- minInvestDelaySlots: BN
31
- crankFundFeePerReserve: BN
32
- pendingAdmin: PublicKey
33
- padding1: BN
34
- padding2: Array<BN>
8
+ adminAuthority: PublicKey;
9
+ baseVaultAuthority: PublicKey;
10
+ baseVaultAuthorityBump: BN;
11
+ tokenMint: PublicKey;
12
+ tokenMintDecimals: BN;
13
+ tokenVault: PublicKey;
14
+ tokenProgram: PublicKey;
15
+ sharesMint: PublicKey;
16
+ sharesMintDecimals: BN;
17
+ tokenAvailable: BN;
18
+ sharesIssued: BN;
19
+ availableCrankFunds: BN;
20
+ padding0: BN;
21
+ performanceFeeBps: BN;
22
+ managementFeeBps: BN;
23
+ lastFeeChargeTimestamp: BN;
24
+ prevAumSf: BN;
25
+ pendingFeesSf: BN;
26
+ vaultAllocationStrategy: Array<types.VaultAllocationFields>;
27
+ minDepositAmount: BN;
28
+ minWithdrawAmount: BN;
29
+ minInvestAmount: BN;
30
+ minInvestDelaySlots: BN;
31
+ crankFundFeePerReserve: BN;
32
+ pendingAdmin: PublicKey;
33
+ vaultLookupTable: PublicKey;
34
+ cumulativeNetEarnedYield: BN;
35
+ padding1: BN;
36
+ padding2: Array<BN>;
35
37
  }
36
38
 
37
39
  export interface VaultStateJSON {
38
- adminAuthority: string
39
- baseVaultAuthority: string
40
- baseVaultAuthorityBump: string
41
- tokenMint: string
42
- tokenMintDecimals: string
43
- tokenVault: string
44
- tokenProgram: string
45
- sharesMint: string
46
- sharesMintDecimals: string
47
- tokenAvailable: string
48
- sharesIssued: string
49
- availableCrankFunds: string
50
- padding0: string
51
- performanceFeeBps: string
52
- managementFeeBps: string
53
- lastFeeChargeTimestamp: string
54
- prevAumSf: string
55
- pendingFeesSf: string
56
- vaultAllocationStrategy: Array<types.VaultAllocationJSON>
57
- minDepositAmount: string
58
- minWithdrawAmount: string
59
- minInvestAmount: string
60
- minInvestDelaySlots: string
61
- crankFundFeePerReserve: string
62
- pendingAdmin: string
63
- padding1: string
64
- padding2: Array<string>
40
+ adminAuthority: string;
41
+ baseVaultAuthority: string;
42
+ baseVaultAuthorityBump: string;
43
+ tokenMint: string;
44
+ tokenMintDecimals: string;
45
+ tokenVault: string;
46
+ tokenProgram: string;
47
+ sharesMint: string;
48
+ sharesMintDecimals: string;
49
+ tokenAvailable: string;
50
+ sharesIssued: string;
51
+ availableCrankFunds: string;
52
+ padding0: string;
53
+ performanceFeeBps: string;
54
+ managementFeeBps: string;
55
+ lastFeeChargeTimestamp: string;
56
+ prevAumSf: string;
57
+ pendingFeesSf: string;
58
+ vaultAllocationStrategy: Array<types.VaultAllocationJSON>;
59
+ minDepositAmount: string;
60
+ minWithdrawAmount: string;
61
+ minInvestAmount: string;
62
+ minInvestDelaySlots: string;
63
+ crankFundFeePerReserve: string;
64
+ pendingAdmin: string;
65
+ vaultLookupTable: string;
66
+ cumulativeNetEarnedYield: string;
67
+ padding1: string;
68
+ padding2: Array<string>;
65
69
  }
66
70
 
67
71
  export class VaultState {
68
- readonly adminAuthority: PublicKey
69
- readonly baseVaultAuthority: PublicKey
70
- readonly baseVaultAuthorityBump: BN
71
- readonly tokenMint: PublicKey
72
- readonly tokenMintDecimals: BN
73
- readonly tokenVault: PublicKey
74
- readonly tokenProgram: PublicKey
75
- readonly sharesMint: PublicKey
76
- readonly sharesMintDecimals: BN
77
- readonly tokenAvailable: BN
78
- readonly sharesIssued: BN
79
- readonly availableCrankFunds: BN
80
- readonly padding0: BN
81
- readonly performanceFeeBps: BN
82
- readonly managementFeeBps: BN
83
- readonly lastFeeChargeTimestamp: BN
84
- readonly prevAumSf: BN
85
- readonly pendingFeesSf: BN
86
- readonly vaultAllocationStrategy: Array<types.VaultAllocation>
87
- readonly minDepositAmount: BN
88
- readonly minWithdrawAmount: BN
89
- readonly minInvestAmount: BN
90
- readonly minInvestDelaySlots: BN
91
- readonly crankFundFeePerReserve: BN
92
- readonly pendingAdmin: PublicKey
93
- readonly padding1: BN
94
- readonly padding2: Array<BN>
72
+ readonly adminAuthority: PublicKey;
73
+ readonly baseVaultAuthority: PublicKey;
74
+ readonly baseVaultAuthorityBump: BN;
75
+ readonly tokenMint: PublicKey;
76
+ readonly tokenMintDecimals: BN;
77
+ readonly tokenVault: PublicKey;
78
+ readonly tokenProgram: PublicKey;
79
+ readonly sharesMint: PublicKey;
80
+ readonly sharesMintDecimals: BN;
81
+ readonly tokenAvailable: BN;
82
+ readonly sharesIssued: BN;
83
+ readonly availableCrankFunds: BN;
84
+ readonly padding0: BN;
85
+ readonly performanceFeeBps: BN;
86
+ readonly managementFeeBps: BN;
87
+ readonly lastFeeChargeTimestamp: BN;
88
+ readonly prevAumSf: BN;
89
+ readonly pendingFeesSf: BN;
90
+ readonly vaultAllocationStrategy: Array<types.VaultAllocation>;
91
+ readonly minDepositAmount: BN;
92
+ readonly minWithdrawAmount: BN;
93
+ readonly minInvestAmount: BN;
94
+ readonly minInvestDelaySlots: BN;
95
+ readonly crankFundFeePerReserve: BN;
96
+ readonly pendingAdmin: PublicKey;
97
+ readonly vaultLookupTable: PublicKey;
98
+ readonly cumulativeNetEarnedYield: BN;
99
+ readonly padding1: BN;
100
+ readonly padding2: Array<BN>;
95
101
 
96
- static readonly discriminator = Buffer.from([
97
- 228, 196, 82, 165, 98, 210, 235, 152,
98
- ])
102
+ static readonly discriminator = Buffer.from([228, 196, 82, 165, 98, 210, 235, 152]);
99
103
 
100
104
  static readonly layout = borsh.struct([
101
- borsh.publicKey("adminAuthority"),
102
- borsh.publicKey("baseVaultAuthority"),
103
- borsh.u64("baseVaultAuthorityBump"),
104
- borsh.publicKey("tokenMint"),
105
- borsh.u64("tokenMintDecimals"),
106
- borsh.publicKey("tokenVault"),
107
- borsh.publicKey("tokenProgram"),
108
- borsh.publicKey("sharesMint"),
109
- borsh.u64("sharesMintDecimals"),
110
- borsh.u64("tokenAvailable"),
111
- borsh.u64("sharesIssued"),
112
- borsh.u64("availableCrankFunds"),
113
- borsh.u64("padding0"),
114
- borsh.u64("performanceFeeBps"),
115
- borsh.u64("managementFeeBps"),
116
- borsh.u64("lastFeeChargeTimestamp"),
117
- borsh.u128("prevAumSf"),
118
- borsh.u128("pendingFeesSf"),
119
- borsh.array(types.VaultAllocation.layout(), 10, "vaultAllocationStrategy"),
120
- borsh.u64("minDepositAmount"),
121
- borsh.u64("minWithdrawAmount"),
122
- borsh.u64("minInvestAmount"),
123
- borsh.u64("minInvestDelaySlots"),
124
- borsh.u64("crankFundFeePerReserve"),
125
- borsh.publicKey("pendingAdmin"),
126
- borsh.u64("padding1"),
127
- borsh.array(borsh.u128(), 254, "padding2"),
128
- ])
105
+ borsh.publicKey('adminAuthority'),
106
+ borsh.publicKey('baseVaultAuthority'),
107
+ borsh.u64('baseVaultAuthorityBump'),
108
+ borsh.publicKey('tokenMint'),
109
+ borsh.u64('tokenMintDecimals'),
110
+ borsh.publicKey('tokenVault'),
111
+ borsh.publicKey('tokenProgram'),
112
+ borsh.publicKey('sharesMint'),
113
+ borsh.u64('sharesMintDecimals'),
114
+ borsh.u64('tokenAvailable'),
115
+ borsh.u64('sharesIssued'),
116
+ borsh.u64('availableCrankFunds'),
117
+ borsh.u64('padding0'),
118
+ borsh.u64('performanceFeeBps'),
119
+ borsh.u64('managementFeeBps'),
120
+ borsh.u64('lastFeeChargeTimestamp'),
121
+ borsh.u128('prevAumSf'),
122
+ borsh.u128('pendingFeesSf'),
123
+ borsh.array(types.VaultAllocation.layout(), 10, 'vaultAllocationStrategy'),
124
+ borsh.u64('minDepositAmount'),
125
+ borsh.u64('minWithdrawAmount'),
126
+ borsh.u64('minInvestAmount'),
127
+ borsh.u64('minInvestDelaySlots'),
128
+ borsh.u64('crankFundFeePerReserve'),
129
+ borsh.publicKey('pendingAdmin'),
130
+ borsh.publicKey('vaultLookupTable'),
131
+ borsh.i128('cumulativeNetEarnedYield'),
132
+ borsh.u64('padding1'),
133
+ borsh.array(borsh.u128(), 251, 'padding2'),
134
+ ]);
129
135
 
130
136
  constructor(fields: VaultStateFields) {
131
- this.adminAuthority = fields.adminAuthority
132
- this.baseVaultAuthority = fields.baseVaultAuthority
133
- this.baseVaultAuthorityBump = fields.baseVaultAuthorityBump
134
- this.tokenMint = fields.tokenMint
135
- this.tokenMintDecimals = fields.tokenMintDecimals
136
- this.tokenVault = fields.tokenVault
137
- this.tokenProgram = fields.tokenProgram
138
- this.sharesMint = fields.sharesMint
139
- this.sharesMintDecimals = fields.sharesMintDecimals
140
- this.tokenAvailable = fields.tokenAvailable
141
- this.sharesIssued = fields.sharesIssued
142
- this.availableCrankFunds = fields.availableCrankFunds
143
- this.padding0 = fields.padding0
144
- this.performanceFeeBps = fields.performanceFeeBps
145
- this.managementFeeBps = fields.managementFeeBps
146
- this.lastFeeChargeTimestamp = fields.lastFeeChargeTimestamp
147
- this.prevAumSf = fields.prevAumSf
148
- this.pendingFeesSf = fields.pendingFeesSf
149
- this.vaultAllocationStrategy = fields.vaultAllocationStrategy.map(
150
- (item) => new types.VaultAllocation({ ...item })
151
- )
152
- this.minDepositAmount = fields.minDepositAmount
153
- this.minWithdrawAmount = fields.minWithdrawAmount
154
- this.minInvestAmount = fields.minInvestAmount
155
- this.minInvestDelaySlots = fields.minInvestDelaySlots
156
- this.crankFundFeePerReserve = fields.crankFundFeePerReserve
157
- this.pendingAdmin = fields.pendingAdmin
158
- this.padding1 = fields.padding1
159
- this.padding2 = fields.padding2
137
+ this.adminAuthority = fields.adminAuthority;
138
+ this.baseVaultAuthority = fields.baseVaultAuthority;
139
+ this.baseVaultAuthorityBump = fields.baseVaultAuthorityBump;
140
+ this.tokenMint = fields.tokenMint;
141
+ this.tokenMintDecimals = fields.tokenMintDecimals;
142
+ this.tokenVault = fields.tokenVault;
143
+ this.tokenProgram = fields.tokenProgram;
144
+ this.sharesMint = fields.sharesMint;
145
+ this.sharesMintDecimals = fields.sharesMintDecimals;
146
+ this.tokenAvailable = fields.tokenAvailable;
147
+ this.sharesIssued = fields.sharesIssued;
148
+ this.availableCrankFunds = fields.availableCrankFunds;
149
+ this.padding0 = fields.padding0;
150
+ this.performanceFeeBps = fields.performanceFeeBps;
151
+ this.managementFeeBps = fields.managementFeeBps;
152
+ this.lastFeeChargeTimestamp = fields.lastFeeChargeTimestamp;
153
+ this.prevAumSf = fields.prevAumSf;
154
+ this.pendingFeesSf = fields.pendingFeesSf;
155
+ this.vaultAllocationStrategy = fields.vaultAllocationStrategy.map((item) => new types.VaultAllocation({ ...item }));
156
+ this.minDepositAmount = fields.minDepositAmount;
157
+ this.minWithdrawAmount = fields.minWithdrawAmount;
158
+ this.minInvestAmount = fields.minInvestAmount;
159
+ this.minInvestDelaySlots = fields.minInvestDelaySlots;
160
+ this.crankFundFeePerReserve = fields.crankFundFeePerReserve;
161
+ this.pendingAdmin = fields.pendingAdmin;
162
+ this.vaultLookupTable = fields.vaultLookupTable;
163
+ this.cumulativeNetEarnedYield = fields.cumulativeNetEarnedYield;
164
+ this.padding1 = fields.padding1;
165
+ this.padding2 = fields.padding2;
160
166
  }
161
167
 
162
- static async fetch(
163
- c: Connection,
164
- address: PublicKey,
165
- programId: PublicKey = PROGRAM_ID
166
- ): Promise<VaultState | null> {
167
- const info = await c.getAccountInfo(address)
168
+ static async fetch(c: Connection, address: PublicKey, programId: PublicKey = PROGRAM_ID): Promise<VaultState | null> {
169
+ const info = await c.getAccountInfo(address);
168
170
 
169
171
  if (info === null) {
170
- return null
172
+ return null;
171
173
  }
172
174
  if (!info.owner.equals(programId)) {
173
- throw new Error("account doesn't belong to this program")
175
+ throw new Error("account doesn't belong to this program");
174
176
  }
175
177
 
176
- return this.decode(info.data)
178
+ return this.decode(info.data);
177
179
  }
178
180
 
179
181
  static async fetchMultiple(
@@ -181,26 +183,26 @@ export class VaultState {
181
183
  addresses: PublicKey[],
182
184
  programId: PublicKey = PROGRAM_ID
183
185
  ): Promise<Array<VaultState | null>> {
184
- const infos = await c.getMultipleAccountsInfo(addresses)
186
+ const infos = await c.getMultipleAccountsInfo(addresses);
185
187
 
186
188
  return infos.map((info) => {
187
189
  if (info === null) {
188
- return null
190
+ return null;
189
191
  }
190
192
  if (!info.owner.equals(programId)) {
191
- throw new Error("account doesn't belong to this program")
193
+ throw new Error("account doesn't belong to this program");
192
194
  }
193
195
 
194
- return this.decode(info.data)
195
- })
196
+ return this.decode(info.data);
197
+ });
196
198
  }
197
199
 
198
200
  static decode(data: Buffer): VaultState {
199
- if (!data.slice(0, 8).equals(VaultState.discriminator)) {
200
- throw new Error("invalid account discriminator")
201
+ if (!VaultState.discriminator.equals(data.slice(0, 8))) {
202
+ throw new Error('invalid account discriminator');
201
203
  }
202
204
 
203
- const dec = VaultState.layout.decode(data.slice(8))
205
+ const dec = VaultState.layout.decode(data.slice(8));
204
206
 
205
207
  return new VaultState({
206
208
  adminAuthority: dec.adminAuthority,
@@ -222,9 +224,8 @@ export class VaultState {
222
224
  prevAumSf: dec.prevAumSf,
223
225
  pendingFeesSf: dec.pendingFeesSf,
224
226
  vaultAllocationStrategy: dec.vaultAllocationStrategy.map(
225
- (
226
- item: any /* eslint-disable-line @typescript-eslint/no-explicit-any */
227
- ) => types.VaultAllocation.fromDecoded(item)
227
+ (item: any /* eslint-disable-line @typescript-eslint/no-explicit-any */) =>
228
+ types.VaultAllocation.fromDecoded(item)
228
229
  ),
229
230
  minDepositAmount: dec.minDepositAmount,
230
231
  minWithdrawAmount: dec.minWithdrawAmount,
@@ -232,9 +233,11 @@ export class VaultState {
232
233
  minInvestDelaySlots: dec.minInvestDelaySlots,
233
234
  crankFundFeePerReserve: dec.crankFundFeePerReserve,
234
235
  pendingAdmin: dec.pendingAdmin,
236
+ vaultLookupTable: dec.vaultLookupTable,
237
+ cumulativeNetEarnedYield: dec.cumulativeNetEarnedYield,
235
238
  padding1: dec.padding1,
236
239
  padding2: dec.padding2,
237
- })
240
+ });
238
241
  }
239
242
 
240
243
  toJSON(): VaultStateJSON {
@@ -257,18 +260,18 @@ export class VaultState {
257
260
  lastFeeChargeTimestamp: this.lastFeeChargeTimestamp.toString(),
258
261
  prevAumSf: this.prevAumSf.toString(),
259
262
  pendingFeesSf: this.pendingFeesSf.toString(),
260
- vaultAllocationStrategy: this.vaultAllocationStrategy.map((item) =>
261
- item.toJSON()
262
- ),
263
+ vaultAllocationStrategy: this.vaultAllocationStrategy.map((item) => item.toJSON()),
263
264
  minDepositAmount: this.minDepositAmount.toString(),
264
265
  minWithdrawAmount: this.minWithdrawAmount.toString(),
265
266
  minInvestAmount: this.minInvestAmount.toString(),
266
267
  minInvestDelaySlots: this.minInvestDelaySlots.toString(),
267
268
  crankFundFeePerReserve: this.crankFundFeePerReserve.toString(),
268
269
  pendingAdmin: this.pendingAdmin.toString(),
270
+ vaultLookupTable: this.vaultLookupTable.toString(),
271
+ cumulativeNetEarnedYield: this.cumulativeNetEarnedYield.toString(),
269
272
  padding1: this.padding1.toString(),
270
273
  padding2: this.padding2.map((item) => item.toString()),
271
- }
274
+ };
272
275
  }
273
276
 
274
277
  static fromJSON(obj: VaultStateJSON): VaultState {
@@ -291,17 +294,17 @@ export class VaultState {
291
294
  lastFeeChargeTimestamp: new BN(obj.lastFeeChargeTimestamp),
292
295
  prevAumSf: new BN(obj.prevAumSf),
293
296
  pendingFeesSf: new BN(obj.pendingFeesSf),
294
- vaultAllocationStrategy: obj.vaultAllocationStrategy.map((item) =>
295
- types.VaultAllocation.fromJSON(item)
296
- ),
297
+ vaultAllocationStrategy: obj.vaultAllocationStrategy.map((item) => types.VaultAllocation.fromJSON(item)),
297
298
  minDepositAmount: new BN(obj.minDepositAmount),
298
299
  minWithdrawAmount: new BN(obj.minWithdrawAmount),
299
300
  minInvestAmount: new BN(obj.minInvestAmount),
300
301
  minInvestDelaySlots: new BN(obj.minInvestDelaySlots),
301
302
  crankFundFeePerReserve: new BN(obj.crankFundFeePerReserve),
302
303
  pendingAdmin: new PublicKey(obj.pendingAdmin),
304
+ vaultLookupTable: new PublicKey(obj.vaultLookupTable),
305
+ cumulativeNetEarnedYield: new BN(obj.cumulativeNetEarnedYield),
303
306
  padding1: new BN(obj.padding1),
304
307
  padding2: obj.padding2.map((item) => new BN(item)),
305
- })
308
+ });
306
309
  }
307
310
  }