@kamino-finance/klend-sdk 5.11.0-beta.0 → 5.11.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.
Files changed (178) hide show
  1. package/dist/classes/action.d.ts +16 -17
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +61 -102
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/manager.d.ts +16 -4
  6. package/dist/classes/manager.d.ts.map +1 -1
  7. package/dist/classes/manager.js +28 -3
  8. package/dist/classes/manager.js.map +1 -1
  9. package/dist/classes/obligation.d.ts +6 -1
  10. package/dist/classes/obligation.d.ts.map +1 -1
  11. package/dist/classes/obligation.js +4 -2
  12. package/dist/classes/obligation.js.map +1 -1
  13. package/dist/classes/reserve.d.ts +2 -2
  14. package/dist/classes/reserve.d.ts.map +1 -1
  15. package/dist/classes/reserve.js +15 -11
  16. package/dist/classes/reserve.js.map +1 -1
  17. package/dist/classes/types.d.ts +4 -0
  18. package/dist/classes/types.d.ts.map +1 -1
  19. package/dist/classes/utils.d.ts.map +1 -1
  20. package/dist/classes/utils.js +1 -2
  21. package/dist/classes/utils.js.map +1 -1
  22. package/dist/classes/vault.d.ts +17 -4
  23. package/dist/classes/vault.d.ts.map +1 -1
  24. package/dist/classes/vault.js +80 -26
  25. package/dist/classes/vault.js.map +1 -1
  26. package/dist/client_kamino_manager.d.ts.map +1 -1
  27. package/dist/client_kamino_manager.js +8 -3
  28. package/dist/client_kamino_manager.js.map +1 -1
  29. package/dist/idl.json +199 -152
  30. package/dist/idl_codegen/accounts/LendingMarket.d.ts +15 -0
  31. package/dist/idl_codegen/accounts/LendingMarket.d.ts.map +1 -1
  32. package/dist/idl_codegen/accounts/LendingMarket.js +11 -1
  33. package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
  34. package/dist/idl_codegen/errors/custom.d.ts +18 -2
  35. package/dist/idl_codegen/errors/custom.d.ts.map +1 -1
  36. package/dist/idl_codegen/errors/custom.js +31 -3
  37. package/dist/idl_codegen/errors/custom.js.map +1 -1
  38. package/dist/idl_codegen/instructions/borrowObligationLiquidity.js +1 -1
  39. package/dist/idl_codegen/instructions/borrowObligationLiquidity.js.map +1 -1
  40. package/dist/idl_codegen/instructions/borrowObligationLiquidityV2.js +1 -1
  41. package/dist/idl_codegen/instructions/borrowObligationLiquidityV2.js.map +1 -1
  42. package/dist/idl_codegen/instructions/depositAndWithdraw.d.ts +52 -0
  43. package/dist/idl_codegen/instructions/depositAndWithdraw.d.ts.map +1 -0
  44. package/dist/idl_codegen/instructions/depositAndWithdraw.js +219 -0
  45. package/dist/idl_codegen/instructions/depositAndWithdraw.js.map +1 -0
  46. package/dist/idl_codegen/instructions/depositReserveLiquidity.js +1 -1
  47. package/dist/idl_codegen/instructions/depositReserveLiquidity.js.map +1 -1
  48. package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js +1 -1
  49. package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js.map +1 -1
  50. package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.js +1 -1
  51. package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.js.map +1 -1
  52. package/dist/idl_codegen/instructions/index.d.ts +2 -2
  53. package/dist/idl_codegen/instructions/index.d.ts.map +1 -1
  54. package/dist/idl_codegen/instructions/index.js +3 -3
  55. package/dist/idl_codegen/instructions/index.js.map +1 -1
  56. package/dist/idl_codegen/instructions/initFarmsForReserve.js +1 -1
  57. package/dist/idl_codegen/instructions/initFarmsForReserve.js.map +1 -1
  58. package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js +1 -1
  59. package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js.map +1 -1
  60. package/dist/idl_codegen/instructions/initReserve.d.ts +1 -0
  61. package/dist/idl_codegen/instructions/initReserve.d.ts.map +1 -1
  62. package/dist/idl_codegen/instructions/initReserve.js +5 -0
  63. package/dist/idl_codegen/instructions/initReserve.js.map +1 -1
  64. package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js +2 -2
  65. package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js.map +1 -1
  66. package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.js +2 -2
  67. package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.js.map +1 -1
  68. package/dist/idl_codegen/instructions/redeemFees.js +1 -1
  69. package/dist/idl_codegen/instructions/redeemFees.js.map +1 -1
  70. package/dist/idl_codegen/instructions/redeemReserveCollateral.js +1 -1
  71. package/dist/idl_codegen/instructions/redeemReserveCollateral.js.map +1 -1
  72. package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js +1 -1
  73. package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js.map +1 -1
  74. package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js +2 -2
  75. package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js.map +1 -1
  76. package/dist/idl_codegen/instructions/repayObligationLiquidity.js +1 -1
  77. package/dist/idl_codegen/instructions/repayObligationLiquidity.js.map +1 -1
  78. package/dist/idl_codegen/instructions/repayObligationLiquidityV2.js +1 -1
  79. package/dist/idl_codegen/instructions/repayObligationLiquidityV2.js.map +1 -1
  80. package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js +1 -1
  81. package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js.map +1 -1
  82. package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.js +1 -1
  83. package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.js.map +1 -1
  84. package/dist/idl_codegen/instructions/withdrawProtocolFee.js +1 -1
  85. package/dist/idl_codegen/instructions/withdrawProtocolFee.js.map +1 -1
  86. package/dist/idl_codegen/instructions/withdrawReferrerFees.js +1 -1
  87. package/dist/idl_codegen/instructions/withdrawReferrerFees.js.map +1 -1
  88. package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +13 -0
  89. package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts.map +1 -1
  90. package/dist/idl_codegen/types/UpdateLendingMarketMode.js +25 -1
  91. package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
  92. package/dist/idl_codegen/types/index.d.ts +2 -2
  93. package/dist/idl_codegen/types/index.d.ts.map +1 -1
  94. package/dist/idl_codegen/types/index.js.map +1 -1
  95. package/dist/idl_codegen/zero_padding/ObligationZP.d.ts +10 -4
  96. package/dist/idl_codegen/zero_padding/ObligationZP.d.ts.map +1 -1
  97. package/dist/idl_codegen/zero_padding/ObligationZP.js +9 -7
  98. package/dist/idl_codegen/zero_padding/ObligationZP.js.map +1 -1
  99. package/dist/lending_operations/repay_with_collateral_operations.js +1 -1
  100. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  101. package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
  102. package/dist/lending_operations/swap_collateral_operations.js +5 -3
  103. package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
  104. package/dist/leverage/calcs.d.ts +1 -1
  105. package/dist/leverage/calcs.d.ts.map +1 -1
  106. package/dist/leverage/calcs.js +12 -10
  107. package/dist/leverage/calcs.js.map +1 -1
  108. package/dist/leverage/instructions.d.ts +1 -2
  109. package/dist/leverage/instructions.d.ts.map +1 -1
  110. package/dist/leverage/instructions.js +2 -6
  111. package/dist/leverage/instructions.js.map +1 -1
  112. package/dist/leverage/operations.d.ts.map +1 -1
  113. package/dist/leverage/operations.js +19 -13
  114. package/dist/leverage/operations.js.map +1 -1
  115. package/dist/utils/ata.d.ts +1 -1
  116. package/dist/utils/ata.d.ts.map +1 -1
  117. package/dist/utils/ata.js +2 -2
  118. package/dist/utils/ata.js.map +1 -1
  119. package/dist/utils/constants.d.ts +4 -9
  120. package/dist/utils/constants.d.ts.map +1 -1
  121. package/dist/utils/constants.js +5 -10
  122. package/dist/utils/constants.js.map +1 -1
  123. package/dist/utils/instruction.d.ts.map +1 -1
  124. package/dist/utils/instruction.js +1 -3
  125. package/dist/utils/instruction.js.map +1 -1
  126. package/dist/utils/managerTypes.d.ts +1 -0
  127. package/dist/utils/managerTypes.d.ts.map +1 -1
  128. package/dist/utils/managerTypes.js.map +1 -1
  129. package/dist/utils/userMetadata.d.ts.map +1 -1
  130. package/dist/utils/userMetadata.js +2 -1
  131. package/dist/utils/userMetadata.js.map +1 -1
  132. package/package.json +7 -7
  133. package/src/classes/action.ts +77 -105
  134. package/src/classes/manager.ts +35 -3
  135. package/src/classes/obligation.ts +8 -4
  136. package/src/classes/reserve.ts +16 -13
  137. package/src/classes/types.ts +5 -0
  138. package/src/classes/utils.ts +3 -3
  139. package/src/classes/vault.ts +95 -38
  140. package/src/client_kamino_manager.ts +10 -3
  141. package/src/idl.json +199 -152
  142. package/src/idl_codegen/accounts/LendingMarket.ts +21 -1
  143. package/src/idl_codegen/errors/custom.ts +39 -2
  144. package/src/idl_codegen/instructions/borrowObligationLiquidity.ts +1 -1
  145. package/src/idl_codegen/instructions/borrowObligationLiquidityV2.ts +1 -1
  146. package/src/idl_codegen/instructions/depositAndWithdraw.ts +241 -0
  147. package/src/idl_codegen/instructions/depositReserveLiquidity.ts +1 -1
  148. package/src/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.ts +1 -1
  149. package/src/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.ts +1 -1
  150. package/src/idl_codegen/instructions/index.ts +4 -4
  151. package/src/idl_codegen/instructions/initFarmsForReserve.ts +1 -1
  152. package/src/idl_codegen/instructions/initObligationFarmsForReserve.ts +1 -1
  153. package/src/idl_codegen/instructions/initReserve.ts +6 -0
  154. package/src/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.ts +2 -2
  155. package/src/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.ts +2 -2
  156. package/src/idl_codegen/instructions/redeemFees.ts +1 -1
  157. package/src/idl_codegen/instructions/redeemReserveCollateral.ts +1 -1
  158. package/src/idl_codegen/instructions/refreshObligationFarmsForReserve.ts +1 -1
  159. package/src/idl_codegen/instructions/repayAndWithdrawAndRedeem.ts +2 -2
  160. package/src/idl_codegen/instructions/repayObligationLiquidity.ts +1 -1
  161. package/src/idl_codegen/instructions/repayObligationLiquidityV2.ts +1 -1
  162. package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.ts +1 -1
  163. package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.ts +1 -1
  164. package/src/idl_codegen/instructions/withdrawProtocolFee.ts +1 -1
  165. package/src/idl_codegen/instructions/withdrawReferrerFees.ts +1 -1
  166. package/src/idl_codegen/types/UpdateLendingMarketMode.ts +30 -0
  167. package/src/idl_codegen/types/index.ts +2 -0
  168. package/src/idl_codegen/zero_padding/ObligationZP.ts +12 -6
  169. package/src/lending_operations/repay_with_collateral_operations.ts +1 -0
  170. package/src/lending_operations/swap_collateral_operations.ts +6 -5
  171. package/src/leverage/calcs.ts +16 -13
  172. package/src/leverage/instructions.ts +1 -6
  173. package/src/leverage/operations.ts +28 -18
  174. package/src/utils/ata.ts +1 -1
  175. package/src/utils/constants.ts +5 -11
  176. package/src/utils/instruction.ts +1 -3
  177. package/src/utils/managerTypes.ts +1 -0
  178. package/src/utils/userMetadata.ts +2 -2
@@ -1134,6 +1134,7 @@ const truncateBorrowCurve = (points: CurvePointFields[]): [number, number][] =>
1134
1134
  export async function createReserveIxs(
1135
1135
  connection: Connection,
1136
1136
  owner: PublicKey,
1137
+ ownerLiquiditySource: PublicKey,
1137
1138
  lendingMarket: PublicKey,
1138
1139
  liquidityMint: PublicKey,
1139
1140
  reserveAddress: PublicKey,
@@ -1166,6 +1167,7 @@ export async function createReserveIxs(
1166
1167
  feeReceiver: feeVault,
1167
1168
  reserveCollateralMint: collateralMint,
1168
1169
  reserveCollateralSupply: collateralSupplyVault,
1170
+ initialLiquiditySource: ownerLiquiditySource,
1169
1171
  liquidityTokenProgram: TOKEN_PROGRAM_ID,
1170
1172
  collateralTokenProgram: TOKEN_PROGRAM_ID,
1171
1173
  systemProgram: SystemProgram.programId,
@@ -1537,7 +1539,7 @@ function handleConfigUpdate(
1537
1539
  mode: UpdateConfigMode.UpdateDepositLimit.discriminator,
1538
1540
  value: updateReserveConfigEncodedValue(
1539
1541
  UpdateConfigMode.UpdateDepositLimit.discriminator,
1540
- reserveConfig.depositLimit.toNumber()
1542
+ BigInt(reserveConfig.depositLimit.toString())
1541
1543
  ),
1542
1544
  });
1543
1545
  } else if (!reserve.config.depositLimit.eq(reserveConfig.depositLimit)) {
@@ -1545,7 +1547,7 @@ function handleConfigUpdate(
1545
1547
  mode: UpdateConfigMode.UpdateDepositLimit.discriminator,
1546
1548
  value: updateReserveConfigEncodedValue(
1547
1549
  UpdateConfigMode.UpdateDepositLimit.discriminator,
1548
- reserveConfig.depositLimit.toNumber()
1550
+ BigInt(reserveConfig.depositLimit.toString())
1549
1551
  ),
1550
1552
  });
1551
1553
  }
@@ -1556,7 +1558,7 @@ function handleConfigUpdate(
1556
1558
  mode: UpdateConfigMode.UpdateBorrowLimit.discriminator,
1557
1559
  value: updateReserveConfigEncodedValue(
1558
1560
  UpdateConfigMode.UpdateBorrowLimit.discriminator,
1559
- reserveConfig.borrowLimit.toNumber()
1561
+ BigInt(reserveConfig.borrowLimit.toString())
1560
1562
  ),
1561
1563
  });
1562
1564
  } else if (!reserve.config.borrowLimit.eq(reserveConfig.borrowLimit)) {
@@ -1564,7 +1566,7 @@ function handleConfigUpdate(
1564
1566
  mode: UpdateConfigMode.UpdateBorrowLimit.discriminator,
1565
1567
  value: updateReserveConfigEncodedValue(
1566
1568
  UpdateConfigMode.UpdateBorrowLimit.discriminator,
1567
- reserveConfig.borrowLimit.toNumber()
1569
+ BigInt(reserveConfig.borrowLimit.toString())
1568
1570
  ),
1569
1571
  });
1570
1572
  }
@@ -1976,15 +1978,12 @@ function handleConfigUpdate(
1976
1978
  reserveConfig.borrowLimitOutsideElevationGroup.toNumber()
1977
1979
  ),
1978
1980
  });
1979
- } else if (
1980
- reserve.config.borrowLimitOutsideElevationGroup.toNumber() !==
1981
- reserveConfig.borrowLimitOutsideElevationGroup.toNumber()
1982
- ) {
1981
+ } else if (!reserve.config.borrowLimitOutsideElevationGroup.eq(reserveConfig.borrowLimitOutsideElevationGroup)) {
1983
1982
  updateReserveIxnsArgs.push({
1984
1983
  mode: UpdateConfigMode.UpdateBorrowLimitOutsideElevationGroup.discriminator,
1985
1984
  value: updateReserveConfigEncodedValue(
1986
1985
  UpdateConfigMode.UpdateBorrowLimitOutsideElevationGroup.discriminator,
1987
- reserveConfig.borrowLimitOutsideElevationGroup.toNumber()
1986
+ BigInt(reserveConfig.borrowLimitOutsideElevationGroup.toString())
1988
1987
  ),
1989
1988
  });
1990
1989
  }
@@ -2106,7 +2105,7 @@ export function parseForChangesReserveConfigAndGetIxs(
2106
2105
 
2107
2106
  export function updateReserveConfigEncodedValue(
2108
2107
  discriminator: number,
2109
- value: number | number[] | BorrowRateCurve | PublicKey
2108
+ value: number | number[] | bigint | BorrowRateCurve | PublicKey
2110
2109
  ): Uint8Array {
2111
2110
  let buffer: Buffer;
2112
2111
  let valueArray: number[] = [];
@@ -2133,8 +2132,6 @@ export function updateReserveConfigEncodedValue(
2133
2132
  break;
2134
2133
  case UpdateConfigMode.UpdateFeesBorrowFee.discriminator:
2135
2134
  case UpdateConfigMode.UpdateFeesFlashLoanFee.discriminator:
2136
- case UpdateConfigMode.UpdateDepositLimit.discriminator:
2137
- case UpdateConfigMode.UpdateBorrowLimit.discriminator:
2138
2135
  case UpdateConfigMode.UpdateTokenInfoLowerHeuristic.discriminator:
2139
2136
  case UpdateConfigMode.UpdateTokenInfoUpperHeuristic.discriminator:
2140
2137
  case UpdateConfigMode.UpdateTokenInfoExpHeuristic.discriminator:
@@ -2147,11 +2144,17 @@ export function updateReserveConfigEncodedValue(
2147
2144
  case UpdateConfigMode.UpdateBorrowFactor.discriminator:
2148
2145
  case UpdateConfigMode.UpdateDeleveragingThresholdDecreaseBpsPerDay.discriminator:
2149
2146
  case UpdateConfigMode.UpdateDeleveragingBonusIncreaseBpsPerDay.discriminator:
2150
- case UpdateConfigMode.UpdateBorrowLimitOutsideElevationGroup.discriminator:
2151
2147
  value = value as number;
2152
2148
  buffer = Buffer.alloc(8);
2153
2149
  buffer.writeBigUint64LE(BigInt(value), 0);
2154
2150
  break;
2151
+ case UpdateConfigMode.UpdateDepositLimit.discriminator:
2152
+ case UpdateConfigMode.UpdateBorrowLimit.discriminator:
2153
+ case UpdateConfigMode.UpdateBorrowLimitOutsideElevationGroup.discriminator:
2154
+ value = value as bigint;
2155
+ buffer = Buffer.alloc(8);
2156
+ buffer.writeBigUint64LE(value, 0);
2157
+ break;
2155
2158
  case UpdateConfigMode.UpdateTokenInfoScopeChain.discriminator:
2156
2159
  case UpdateConfigMode.UpdateTokenInfoScopeTwap.discriminator:
2157
2160
  valueArray = value as number[];
@@ -54,3 +54,8 @@ export type ReserveAllocationOverview = {
54
54
  tokenAllocationCap: Decimal;
55
55
  ctokenAllocation: Decimal;
56
56
  };
57
+
58
+ export type APYs = {
59
+ grossAPY: Decimal;
60
+ netAPY: Decimal;
61
+ }
@@ -1,8 +1,8 @@
1
1
  import { PubkeyHashMap, SLOTS_PER_SECOND, SLOTS_PER_YEAR } from '../utils';
2
2
  import Decimal from 'decimal.js';
3
3
  import { AccountInfo, PublicKey } from '@solana/web3.js';
4
- import { MarketOverview, ReserveOverview, SOL_MINTS } from '../lib';
5
- import { AccountLayout } from '@solana/spl-token';
4
+ import { MarketOverview, ReserveOverview } from '../lib';
5
+ import { AccountLayout, NATIVE_MINT } from '@solana/spl-token';
6
6
  import { ReserveAllocationOverview } from './types';
7
7
  import axios from 'axios';
8
8
 
@@ -188,7 +188,7 @@ export function lamportsToDecimal(amount: Decimal.Value, decimals: Decimal.Value
188
188
  }
189
189
 
190
190
  export const isSolMint = (mint: PublicKey): boolean => {
191
- return SOL_MINTS.filter((m) => m.equals(mint)).length > 0;
191
+ return NATIVE_MINT.equals(mint);
192
192
  };
193
193
 
194
194
  export const valueOrZero = (value: Decimal): Decimal => {
@@ -11,10 +11,10 @@ import {
11
11
  SYSVAR_RENT_PUBKEY,
12
12
  TransactionInstruction,
13
13
  } from '@solana/web3.js';
14
- import { TOKEN_PROGRAM_ID, unpackAccount } from '@solana/spl-token';
14
+ import { NATIVE_MINT, TOKEN_PROGRAM_ID, unpackAccount } from '@solana/spl-token';
15
15
  import {
16
16
  getAssociatedTokenAddress,
17
- getDepositWsolIxns,
17
+ getTransferWsolIxns,
18
18
  getTokenOracleData,
19
19
  KaminoMarket,
20
20
  KaminoReserve,
@@ -22,7 +22,6 @@ import {
22
22
  PubkeyHashMap,
23
23
  Reserve,
24
24
  UserState,
25
- WRAPPED_SOL_MINT,
26
25
  } from '../lib';
27
26
  import {
28
27
  DepositAccounts,
@@ -70,6 +69,7 @@ import bs58 from 'bs58';
70
69
  import { getAccountOwner, getProgramAccounts } from '../utils/rpc';
71
70
  import {
72
71
  AcceptVaultOwnershipIxs,
72
+ APYs,
73
73
  DepositIxs,
74
74
  InitVaultIxs,
75
75
  ReserveAllocationOverview,
@@ -79,7 +79,7 @@ import {
79
79
  UserSharesForVault,
80
80
  WithdrawIxs,
81
81
  } from './types';
82
- import { collToLamportsDecimal, ZERO } from '@kamino-finance/kliquidity-sdk';
82
+ import { batchFetch, collToLamportsDecimal, ZERO } from '@kamino-finance/kliquidity-sdk';
83
83
  import { FullBPSDecimal } from '@kamino-finance/kliquidity-sdk/dist/utils/CreationParameters';
84
84
  import { FarmState } from '@kamino-finance/farms-sdk/dist';
85
85
  import { getAccountsInLUT, initLookupTableIx } from './lut_utils';
@@ -98,7 +98,7 @@ export const kaminoVaultStagingId = new PublicKey('STkvh7ostar39Fwr4uZKASs1RNNuY
98
98
  const TOKEN_VAULT_SEED = 'token_vault';
99
99
  const CTOKEN_VAULT_SEED = 'ctoken_vault';
100
100
  const BASE_VAULT_AUTHORITY_SEED = 'authority';
101
- const SHARES_SEEDS = 'shares';
101
+ const SHARES_SEED = 'shares';
102
102
 
103
103
  /**
104
104
  * KaminoVaultClient is a class that provides a high-level interface to interact with the Kamino Vault program.
@@ -191,7 +191,7 @@ export class KaminoVaultClient {
191
191
  )[0];
192
192
 
193
193
  const sharesMint = PublicKey.findProgramAddressSync(
194
- [Buffer.from(SHARES_SEEDS), vaultState.publicKey.toBytes()],
194
+ [Buffer.from(SHARES_SEED), vaultState.publicKey.toBytes()],
195
195
  this._kaminoVaultProgramId
196
196
  )[0];
197
197
 
@@ -694,20 +694,20 @@ export class KaminoVaultClient {
694
694
  const userTokenAta = getAssociatedTokenAddress(vaultState.tokenMint, user, true, tokenProgramID);
695
695
  const createAtasIxns: TransactionInstruction[] = [];
696
696
  const closeAtasIxns: TransactionInstruction[] = [];
697
- if (vaultState.tokenMint.equals(WRAPPED_SOL_MINT)) {
697
+ if (vaultState.tokenMint.equals(NATIVE_MINT)) {
698
698
  const [{ ata: wsolAta, createAtaIx: createWsolAtaIxn }] = createAtasIdempotent(user, [
699
699
  {
700
- mint: WRAPPED_SOL_MINT,
700
+ mint: NATIVE_MINT,
701
701
  tokenProgram: TOKEN_PROGRAM_ID,
702
702
  },
703
703
  ]);
704
704
  createAtasIxns.push(createWsolAtaIxn);
705
- const depositWsolIxn = getDepositWsolIxns(
705
+ const transferWsolIxns = getTransferWsolIxns(
706
706
  user,
707
707
  wsolAta,
708
708
  numberToLamportsDecimal(tokenAmount, vaultState.tokenMintDecimals.toNumber()).ceil()
709
709
  );
710
- createAtasIxns.push(...depositWsolIxn);
710
+ createAtasIxns.push(...transferWsolIxns);
711
711
  }
712
712
 
713
713
  const [{ ata: userSharesAta, createAtaIx: createSharesAtaIxns }] = createAtasIdempotent(user, [
@@ -1005,6 +1005,7 @@ export class KaminoVaultClient {
1005
1005
  */
1006
1006
  async investAllReservesIxs(payer: PublicKey, vault: KaminoVault): Promise<TransactionInstruction[]> {
1007
1007
  const vaultState = await vault.getState(this.getConnection());
1008
+ const minInvestAmount = vaultState.minInvestAmount;
1008
1009
  const allReserves = this.getVaultReserves(vaultState);
1009
1010
  if (allReserves.length === 0) {
1010
1011
  throw new Error('No reserves found for the vault, please select at least one reserve for the vault');
@@ -1024,6 +1025,7 @@ export class KaminoVaultClient {
1024
1025
  const curentVaultAllocations = this.getVaultAllocations(vaultState);
1025
1026
 
1026
1027
  const reservesToDisinvestFrom: PublicKey[] = [];
1028
+ const reservesToInvestInto: PublicKey[] = [];
1027
1029
 
1028
1030
  for (let index = 0; index < allReserves.length; index++) {
1029
1031
  const reservePubkey = allReserves[index];
@@ -1037,8 +1039,15 @@ export class KaminoVaultClient {
1037
1039
  vaultState.tokenMintDecimals.toNumber()
1038
1040
  );
1039
1041
 
1040
- if (computedAllocation.lt(reserveAllocationLiquidityAmount)) {
1041
- reservesToDisinvestFrom.push(reservePubkey);
1042
+ const diffInReserveTokens = computedAllocation.sub(reserveAllocationLiquidityAmount);
1043
+ const diffInReserveLamports = collToLamportsDecimal(diffInReserveTokens, vaultState.tokenMintDecimals.toNumber());
1044
+ // if the diff for the reserve is smaller than the min invest amount, we do not need to invest or disinvest
1045
+ if (diffInReserveLamports.abs().gte(new Decimal(minInvestAmount.toString()))) {
1046
+ if (computedAllocation.lt(reserveAllocationLiquidityAmount)) {
1047
+ reservesToDisinvestFrom.push(reservePubkey);
1048
+ } else {
1049
+ reservesToInvestInto.push(reservePubkey);
1050
+ }
1042
1051
  }
1043
1052
  }
1044
1053
 
@@ -1062,24 +1071,22 @@ export class KaminoVaultClient {
1062
1071
  investIxnsPromises.push(investIxsPromise);
1063
1072
  }
1064
1073
 
1065
- for (const reserve of allReserves) {
1066
- if (!reservesToDisinvestFrom.includes(reserve)) {
1067
- const reserveState = allReservesStateMap.get(reserve);
1068
- if (reserveState === null) {
1069
- throw new Error(`Reserve ${reserve.toBase58()} not found`);
1070
- }
1071
- const investIxsPromise = this.investSingleReserveIxs(
1072
- payer,
1073
- vault,
1074
- {
1075
- address: reserve,
1076
- state: reserveState!.state,
1077
- },
1078
- allReservesStateMap,
1079
- false
1080
- );
1081
- investIxnsPromises.push(investIxsPromise);
1074
+ for (const reserve of reservesToInvestInto) {
1075
+ const reserveState = allReservesStateMap.get(reserve);
1076
+ if (reserveState === null) {
1077
+ throw new Error(`Reserve ${reserve.toBase58()} not found`);
1082
1078
  }
1079
+ const investIxsPromise = this.investSingleReserveIxs(
1080
+ payer,
1081
+ vault,
1082
+ {
1083
+ address: reserve,
1084
+ state: reserveState!.state,
1085
+ },
1086
+ allReservesStateMap,
1087
+ false
1088
+ );
1089
+ investIxnsPromises.push(investIxsPromise);
1083
1090
  }
1084
1091
 
1085
1092
  let investIxns: TransactionInstruction[] = [];
@@ -1493,6 +1500,21 @@ export class KaminoVaultClient {
1493
1500
  vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>,
1494
1501
  currentSlot?: number
1495
1502
  ): Promise<PubkeyHashMap<PublicKey, Decimal>> {
1503
+ // if there are no vault reserves or all have weight 0 everything has to be in Available
1504
+ const allReservesPubkeys = this.getVaultReserves(vaultState);
1505
+ const reservesAllocations = this.getVaultAllocations(vaultState);
1506
+ const allReservesHaveWeight0 = allReservesPubkeys.every((reserve) => {
1507
+ const allocation = reservesAllocations.get(reserve);
1508
+ return allocation?.targetWeight.isZero();
1509
+ });
1510
+ if (allReservesPubkeys.length === 0 || allReservesHaveWeight0) {
1511
+ const computedHoldings = new PubkeyHashMap<PublicKey, Decimal>();
1512
+ allReservesPubkeys.forEach((reserve) => {
1513
+ computedHoldings.set(reserve, new Decimal(0));
1514
+ });
1515
+ return computedHoldings;
1516
+ }
1517
+
1496
1518
  const holdings = await this.getVaultHoldings(vaultState, slot, vaultReserves, currentSlot);
1497
1519
  const initialVaultAllocations = this.getVaultAllocations(vaultState);
1498
1520
 
@@ -1513,7 +1535,6 @@ export class KaminoVaultClient {
1513
1535
  const reserveWithWeight = initialVaultAllocations.get(reserve);
1514
1536
  const targetAllocation = reserveWithWeight!.targetWeight.mul(totalLeftover).div(currentAllocationSum);
1515
1537
  const reserveCap = reserveWithWeight!.tokenAllocationCap;
1516
- // todo: check if both target and reserveCap
1517
1538
  const amountToInvest = Decimal.min(targetAllocation, reserveCap, totalLeftToInvest);
1518
1539
  totalLeftToInvest = totalLeftToInvest.sub(amountToInvest);
1519
1540
  if (amountToInvest.eq(reserveCap)) {
@@ -1749,6 +1770,26 @@ export class KaminoVaultClient {
1749
1770
  });
1750
1771
  }
1751
1772
 
1773
+ /**
1774
+ * Get a list of kaminoVaults
1775
+ * @param vaults - a list of vaults to get the states for; if not provided, all vaults will be fetched
1776
+ * @returns a list of vaults
1777
+ */
1778
+ async getVaults(vaults?: Array<PublicKey>): Promise<Array<KaminoVault | null>> {
1779
+ if (!vaults) {
1780
+ vaults = (await this.getAllVaults()).map((x) => x.address);
1781
+ }
1782
+ const vaultStates = await batchFetch(vaults, (chunk) => this.getVaultsStates(chunk));
1783
+ return vaults.map((vault, index) => {
1784
+ const state = vaultStates[index];
1785
+ return state ? new KaminoVault(vault, state, this._kaminoVaultProgramId) : null;
1786
+ });
1787
+ }
1788
+
1789
+ private async getVaultsStates(vaults: PublicKey[]): Promise<Array<VaultState | null>> {
1790
+ return await VaultState.fetchMultiple(this.getConnection(), vaults, this._kaminoVaultProgramId);
1791
+ }
1792
+
1752
1793
  /**
1753
1794
  * This will return the amount of token invested from the vault into the given reserve
1754
1795
  * @param vault - the kamino vault to get invested amount in reserve for
@@ -1898,7 +1939,17 @@ export class KaminoVaultClient {
1898
1939
  * @returns a hashmap from each reserve pubkey to the reserve state
1899
1940
  */
1900
1941
  async loadVaultReserves(vaultState: VaultState): Promise<PubkeyHashMap<PublicKey, KaminoReserve>> {
1901
- const vaultReservesAddresses = this.getVaultReserves(vaultState);
1942
+ return this.loadVaultsReserves([vaultState]);
1943
+ }
1944
+
1945
+ /**
1946
+ * This will load the onchain state for all the reserves that the vaults have allocations for, deduplicating the reserves
1947
+ * @param vaults - the vault states to load reserves for
1948
+ * @returns a hashmap from each reserve pubkey to the reserve state
1949
+ */
1950
+ async loadVaultsReserves(vaults: VaultState[]): Promise<PubkeyHashMap<PublicKey, KaminoReserve>> {
1951
+ const vaultReservesAddressesSet = new PublicKeySet(vaults.flatMap((vault) => this.getVaultReserves(vault)));
1952
+ const vaultReservesAddresses = vaultReservesAddressesSet.toArray();
1902
1953
  const reserveAccounts = await this.getConnection().getMultipleAccountsInfo(vaultReservesAddresses, 'processed');
1903
1954
 
1904
1955
  const deserializedReserves = reserveAccounts.map((reserve, i) => {
@@ -2179,7 +2230,7 @@ export class KaminoVaultClient {
2179
2230
  // 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
2180
2231
  const [
2181
2232
  vaultHoldingsWithUSDValue,
2182
- vaultTheoreticalAPY,
2233
+ vaultTheoreticalAPYs,
2183
2234
  totalInvestedAndBorrowed,
2184
2235
  vaultCollaterals,
2185
2236
  reservesOverview,
@@ -2195,7 +2246,7 @@ export class KaminoVaultClient {
2195
2246
  holdingsUSD: vaultHoldingsWithUSDValue,
2196
2247
  reservesOverview: reservesOverview,
2197
2248
  vaultCollaterals: vaultCollaterals,
2198
- theoreticalSupplyAPY: vaultTheoreticalAPY,
2249
+ theoreticalSupplyAPY: vaultTheoreticalAPYs,
2199
2250
  totalBorrowed: totalInvestedAndBorrowed.totalBorrowed,
2200
2251
  utilizationRatio: totalInvestedAndBorrowed.utilizationRatio,
2201
2252
  totalSupplied: totalInvestedAndBorrowed.totalInvested,
@@ -2306,13 +2357,13 @@ export class KaminoVaultClient {
2306
2357
  * @param vault - the kamino vault to get APY for
2307
2358
  * @param slot - current slot
2308
2359
  * @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
2309
- * @returns APY for the vault
2360
+ * @returns a struct containing estimated gross APY and net APY (gross - vault fees) for the vault
2310
2361
  */
2311
2362
  async getVaultTheoreticalAPY(
2312
2363
  vault: VaultState,
2313
2364
  slot: number,
2314
2365
  vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>
2315
- ): Promise<Decimal> {
2366
+ ): Promise<APYs> {
2316
2367
  const vaultReservesState = vaultReservesMap ? vaultReservesMap : await this.loadVaultReserves(vault);
2317
2368
 
2318
2369
  let totalWeights = new Decimal(0);
@@ -2334,14 +2385,20 @@ export class KaminoVaultClient {
2334
2385
  totalWeights = totalWeights.add(weight);
2335
2386
  });
2336
2387
  if (totalWeights.isZero()) {
2337
- return new Decimal(0);
2388
+ return {
2389
+ grossAPY: new Decimal(0),
2390
+ netAPY: new Decimal(0),
2391
+ };
2338
2392
  }
2339
2393
 
2340
2394
  const grossAPY = totalAPY.div(totalWeights);
2341
2395
  const netAPY = grossAPY
2342
2396
  .mul(new Decimal(1).sub(new Decimal(vault.performanceFeeBps.toString()).div(FullBPSDecimal)))
2343
2397
  .mul(new Decimal(1).sub(new Decimal(vault.managementFeeBps.toString()).div(FullBPSDecimal)));
2344
- return netAPY;
2398
+ return {
2399
+ grossAPY,
2400
+ netAPY,
2401
+ };
2345
2402
  }
2346
2403
 
2347
2404
  /**
@@ -2610,7 +2667,7 @@ export type VaultOverview = {
2610
2667
  holdingsUSD: VaultHoldingsWithUSDValue;
2611
2668
  reservesOverview: PubkeyHashMap<PublicKey, ReserveOverview>;
2612
2669
  vaultCollaterals: PubkeyHashMap<PublicKey, MarketOverview>;
2613
- theoreticalSupplyAPY: Decimal;
2670
+ theoreticalSupplyAPY: APYs;
2614
2671
  totalBorrowed: Decimal;
2615
2672
  totalSupplied: Decimal;
2616
2673
  utilizationRatio: Decimal;
@@ -54,6 +54,7 @@ import {
54
54
  } from './idl_codegen_kamino_vault/types/VaultConfigField';
55
55
  import { getAccountOwner } from './utils/rpc';
56
56
  import { printHoldings } from './classes/types_utils';
57
+ import { getAssociatedTokenAddressSync } from '@solana/spl-token';
57
58
 
58
59
  dotenv.config({
59
60
  path: `.env${process.env.ENV ? '.' + process.env.ENV : ''}`,
@@ -87,7 +88,7 @@ async function main() {
87
88
  admin: mode === 'multisig' ? multisigPk : env.payer.publicKey,
88
89
  });
89
90
 
90
- const _createMarketSig = await processTxn(env.client, env.payer, createMarketIxns, mode, 2500, [marketKp]);
91
+ await processTxn(env.client, env.payer, createMarketIxns, mode, 2500, [marketKp]);
91
92
 
92
93
  mode === 'execute' && console.log('Market created:', marketKp.publicKey.toBase58());
93
94
  });
@@ -122,8 +123,14 @@ async function main() {
122
123
  const reserveConfig = parseReserveConfigFromFile(reserveConfigFromFile);
123
124
  const assetConfig = new AssetReserveConfigCli(tokenMint, tokenMintProgramId, reserveConfig);
124
125
 
126
+ const adminAta =
127
+ mode === 'multisig'
128
+ ? getAssociatedTokenAddressSync(tokenMint, multisigPk)
129
+ : getAssociatedTokenAddressSync(tokenMint, env.payer.publicKey);
130
+
125
131
  const { reserve, txnIxns } = await kaminoManager.addAssetToMarketIxs({
126
132
  admin: mode === 'multisig' ? multisigPk : env.payer.publicKey,
133
+ adminLiquiditySource: adminAta,
127
134
  marketAddress: marketAddress,
128
135
  assetConfig: assetConfig,
129
136
  });
@@ -260,7 +267,7 @@ async function main() {
260
267
  2500,
261
268
  [vaultKp]
262
269
  );
263
- await sleep(5000);
270
+ await sleep(2000);
264
271
  const _populateLUTSig = await processTxn(env.client, env.payer, instructions.populateLUTIxs, mode, 2500, []);
265
272
 
266
273
  mode === 'execute' && console.log('Vault created:', vaultKp.publicKey.toBase58());
@@ -426,7 +433,7 @@ async function main() {
426
433
  // if we need to create the LUT we have to do that in a separate tx and wait a little bit after
427
434
  if (syncLUTIxs.setupLUTIfNeededIxs.length > 0) {
428
435
  const setupLUTSig = await processTxn(env.client, env.payer, syncLUTIxs.setupLUTIfNeededIxs, mode, 2500, []);
429
- await sleep(5000);
436
+ await sleep(2000);
430
437
  mode === 'execute' && console.log('LUT created and set to the vault:', setupLUTSig);
431
438
  }
432
439
  // if there are accounts to be added to the LUT we have to do that in a separate tx