@kamino-finance/klend-sdk 5.11.5-beta.0 → 5.11.6-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/dist/classes/action.d.ts +25 -35
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +225 -350
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/index.d.ts +0 -1
  6. package/dist/classes/index.d.ts.map +1 -1
  7. package/dist/classes/index.js +0 -1
  8. package/dist/classes/index.js.map +1 -1
  9. package/dist/classes/lut_utils.d.ts +29 -0
  10. package/dist/classes/lut_utils.d.ts.map +1 -0
  11. package/dist/classes/lut_utils.js +62 -0
  12. package/dist/classes/lut_utils.js.map +1 -0
  13. package/dist/classes/manager.d.ts +1 -6
  14. package/dist/classes/manager.d.ts.map +1 -1
  15. package/dist/classes/manager.js +1 -17
  16. package/dist/classes/manager.js.map +1 -1
  17. package/dist/classes/market.d.ts +3 -3
  18. package/dist/classes/market.d.ts.map +1 -1
  19. package/dist/classes/market.js +16 -30
  20. package/dist/classes/market.js.map +1 -1
  21. package/dist/classes/obligation.d.ts +1 -3
  22. package/dist/classes/obligation.d.ts.map +1 -1
  23. package/dist/classes/obligation.js +1 -6
  24. package/dist/classes/obligation.js.map +1 -1
  25. package/dist/classes/vault.d.ts +0 -1
  26. package/dist/classes/vault.d.ts.map +1 -1
  27. package/dist/classes/vault.js +22 -25
  28. package/dist/classes/vault.js.map +1 -1
  29. package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts +3 -6
  30. package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts.map +1 -1
  31. package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +7 -13
  32. package/dist/idl_codegen_kamino_vault/accounts/VaultState.js.map +1 -1
  33. package/dist/idl_codegen_kamino_vault/errors/custom.d.ts +1 -25
  34. package/dist/idl_codegen_kamino_vault/errors/custom.d.ts.map +1 -1
  35. package/dist/idl_codegen_kamino_vault/errors/custom.js +1 -43
  36. package/dist/idl_codegen_kamino_vault/errors/custom.js.map +1 -1
  37. package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.d.ts +1 -1
  38. package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.d.ts.map +1 -1
  39. package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.js +1 -1
  40. package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.js.map +1 -1
  41. package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts +0 -1
  42. package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts.map +1 -1
  43. package/dist/idl_codegen_kamino_vault/instructions/initVault.js +0 -1
  44. package/dist/idl_codegen_kamino_vault/instructions/initVault.js.map +1 -1
  45. package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.d.ts +1 -1
  46. package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.d.ts.map +1 -1
  47. package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.js +1 -1
  48. package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.js.map +1 -1
  49. package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts +1 -1
  50. package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts.map +1 -1
  51. package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js +1 -1
  52. package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js.map +1 -1
  53. package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.d.ts +1 -1
  54. package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.d.ts.map +1 -1
  55. package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.js +1 -1
  56. package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.js.map +1 -1
  57. package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.d.ts +1 -1
  58. package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.d.ts.map +1 -1
  59. package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.js +1 -1
  60. package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.js.map +1 -1
  61. package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.d.ts +1 -1
  62. package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.d.ts.map +1 -1
  63. package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.js +1 -1
  64. package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.js.map +1 -1
  65. package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts +0 -13
  66. package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts.map +1 -1
  67. package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js +1 -25
  68. package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js.map +1 -1
  69. package/dist/idl_codegen_kamino_vault/types/index.d.ts +2 -2
  70. package/dist/idl_codegen_kamino_vault/types/index.d.ts.map +1 -1
  71. package/dist/idl_codegen_kamino_vault/types/index.js.map +1 -1
  72. package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
  73. package/dist/lending_operations/repay_with_collateral_calcs.js +5 -9
  74. package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
  75. package/dist/lending_operations/repay_with_collateral_operations.d.ts +4 -9
  76. package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
  77. package/dist/lending_operations/repay_with_collateral_operations.js +8 -35
  78. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  79. package/dist/lending_operations/swap_collateral_operations.d.ts +2 -2
  80. package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
  81. package/dist/lending_operations/swap_collateral_operations.js +6 -11
  82. package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
  83. package/dist/leverage/operations.d.ts +7 -9
  84. package/dist/leverage/operations.d.ts.map +1 -1
  85. package/dist/leverage/operations.js +66 -78
  86. package/dist/leverage/operations.js.map +1 -1
  87. package/dist/leverage/types.d.ts +4 -4
  88. package/dist/leverage/types.d.ts.map +1 -1
  89. package/dist/utils/ObligationType.d.ts +1 -1
  90. package/dist/utils/ObligationType.d.ts.map +1 -1
  91. package/dist/utils/constants.d.ts +0 -1
  92. package/dist/utils/constants.d.ts.map +1 -1
  93. package/dist/utils/constants.js +1 -2
  94. package/dist/utils/constants.js.map +1 -1
  95. package/dist/utils/lookupTable.d.ts +0 -27
  96. package/dist/utils/lookupTable.d.ts.map +1 -1
  97. package/dist/utils/lookupTable.js +0 -58
  98. package/dist/utils/lookupTable.js.map +1 -1
  99. package/dist/utils/managerTypes.d.ts.map +1 -1
  100. package/dist/utils/managerTypes.js +52 -7
  101. package/dist/utils/managerTypes.js.map +1 -1
  102. package/dist/utils/oracle.d.ts +3 -3
  103. package/dist/utils/oracle.d.ts.map +1 -1
  104. package/dist/utils/oracle.js +3 -4
  105. package/dist/utils/oracle.js.map +1 -1
  106. package/dist/utils/seeds.d.ts +1 -11
  107. package/dist/utils/seeds.d.ts.map +1 -1
  108. package/dist/utils/seeds.js +3 -13
  109. package/dist/utils/seeds.js.map +1 -1
  110. package/dist/utils/userMetadata.d.ts.map +1 -1
  111. package/dist/utils/userMetadata.js +7 -8
  112. package/dist/utils/userMetadata.js.map +1 -1
  113. package/package.json +2 -2
  114. package/src/classes/action.ts +261 -504
  115. package/src/classes/index.ts +0 -1
  116. package/src/classes/lut_utils.ts +63 -0
  117. package/src/classes/manager.ts +1 -30
  118. package/src/classes/market.ts +25 -34
  119. package/src/classes/obligation.ts +1 -7
  120. package/src/classes/vault.ts +23 -24
  121. package/src/client.ts +3 -8
  122. package/src/idl_codegen_kamino_vault/accounts/VaultState.ts +9 -17
  123. package/src/idl_codegen_kamino_vault/errors/custom.ts +0 -42
  124. package/src/idl_codegen_kamino_vault/instructions/giveUpPendingFees.ts +2 -2
  125. package/src/idl_codegen_kamino_vault/instructions/initVault.ts +0 -2
  126. package/src/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.ts +2 -2
  127. package/src/idl_codegen_kamino_vault/instructions/updateReserveAllocation.ts +2 -2
  128. package/src/idl_codegen_kamino_vault/instructions/updateSharesMetadata.ts +2 -2
  129. package/src/idl_codegen_kamino_vault/instructions/updateVaultConfig.ts +2 -2
  130. package/src/idl_codegen_kamino_vault/instructions/withdrawPendingFees.ts +2 -2
  131. package/src/idl_codegen_kamino_vault/types/VaultConfigField.ts +0 -30
  132. package/src/idl_codegen_kamino_vault/types/index.ts +0 -2
  133. package/src/idl_kamino_vault.json +8 -35
  134. package/src/lending_operations/repay_with_collateral_calcs.ts +5 -14
  135. package/src/lending_operations/repay_with_collateral_operations.ts +29 -76
  136. package/src/lending_operations/swap_collateral_operations.ts +7 -19
  137. package/src/leverage/operations.ts +66 -114
  138. package/src/leverage/types.ts +4 -4
  139. package/src/utils/ObligationType.ts +1 -1
  140. package/src/utils/constants.ts +0 -1
  141. package/src/utils/lookupTable.ts +0 -62
  142. package/src/utils/managerTypes.ts +52 -10
  143. package/src/utils/oracle.ts +6 -7
  144. package/src/utils/seeds.ts +4 -14
  145. package/src/utils/userMetadata.ts +15 -16
@@ -9,4 +9,3 @@ export * from './jupiterPerps';
9
9
  export * from './manager';
10
10
  export * from './vault';
11
11
  export * from './fraction';
12
- export * from './types';
@@ -0,0 +1,63 @@
1
+ import { AddressLookupTableProgram, Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
2
+
3
+ /**
4
+ * This method retuns an instruction that creates a lookup table, alongside the pubkey of the lookup table
5
+ * @param payer - the owner of the lookup table
6
+ * @param slot - the current slot
7
+ * @returns - the instruction to create the lookup table and its address
8
+ */
9
+ export function initLookupTableIx(payer: PublicKey, slot: number): [TransactionInstruction, PublicKey] {
10
+ const [ixn, address] = AddressLookupTableProgram.createLookupTable({
11
+ authority: payer,
12
+ payer,
13
+ recentSlot: slot,
14
+ });
15
+
16
+ return [ixn, address];
17
+ }
18
+
19
+ /**
20
+ * This method retuns an instruction that deactivates a lookup table, which is needed to close it
21
+ * @param payer - the owner of the lookup table
22
+ * @param lookupTable - the lookup table to deactivate
23
+ * @returns - the instruction to deactivate the lookup table
24
+ */
25
+ export function deactivateLookupTableIx(payer: PublicKey, lookupTable: PublicKey): TransactionInstruction {
26
+ const ixn = AddressLookupTableProgram.deactivateLookupTable({
27
+ authority: payer,
28
+ lookupTable: lookupTable,
29
+ });
30
+
31
+ return ixn;
32
+ }
33
+
34
+ /**
35
+ * This method returns an instruction that closes a lookup table. That lookup table needs to be disabled at least 500 blocks before closing it.
36
+ * @param payer - the owner of the lookup table
37
+ * @param lookupTable - the lookup table to close
38
+ * @returns - the instruction to close the lookup table
39
+ */
40
+ /// this require the LUT to be deactivated at least 500 blocks before
41
+ export function closeLookupTableIx(payer: PublicKey, lookupTable: PublicKey): TransactionInstruction {
42
+ const ixn = AddressLookupTableProgram.closeLookupTable({
43
+ authority: payer,
44
+ recipient: payer,
45
+ lookupTable: lookupTable,
46
+ });
47
+
48
+ return ixn;
49
+ }
50
+
51
+ /**
52
+ * Returns the accounts in a lookup table
53
+ * @param lookupTable - lookup table to get the accounts from
54
+ * @returns - an array of accounts in the lookup table
55
+ */
56
+ export async function getAccountsInLUT(connection: Connection, lookupTable: PublicKey): Promise<PublicKey[]> {
57
+ const lutState = await connection.getAddressLookupTable(lookupTable);
58
+ if (!lutState || !lutState.value) {
59
+ throw new Error(`Lookup table ${lookupTable} not found`);
60
+ }
61
+
62
+ return lutState.value.state.addresses;
63
+ }
@@ -50,7 +50,6 @@ import {
50
50
  ReserveWithAddress,
51
51
  sameLengthArrayEquals,
52
52
  ScopeOracleConfig,
53
- sleep,
54
53
  updateEntireReserveConfigIx,
55
54
  updateLendingMarket,
56
55
  UpdateLendingMarketAccounts,
@@ -576,34 +575,6 @@ export class KaminoManager {
576
575
  return this._vaultClient.getAllVaults();
577
576
  }
578
577
 
579
- /**
580
- * Get all lending markets
581
- * @returns an array of all lending markets
582
- */
583
- async getAllMarkets(): Promise<KaminoMarket[]> {
584
- const lendingMarketsAccounts = await getProgramAccounts(
585
- this.getConnection(),
586
- this._kaminoLendProgramId,
587
- LendingMarket.layout.span + 8,
588
- {
589
- commitment: this.getConnection().commitment ?? 'processed',
590
- filters: [
591
- { dataSize: LendingMarket.layout.span + 8 },
592
- { memcmp: { offset: 0, bytes: bs58.encode(LendingMarket.discriminator) } },
593
- ],
594
- }
595
- );
596
-
597
- await sleep(500);
598
-
599
- const markets = await Promise.all(
600
- lendingMarketsAccounts.map((account) =>
601
- KaminoMarket.load(this._connection, account.pubkey, this.recentSlotDurationMs, this._kaminoLendProgramId)
602
- )
603
- );
604
- return markets.filter((market): market is KaminoMarket => market !== null);
605
- }
606
-
607
578
  /**
608
579
  * Get all vaults for owner
609
580
  * @param owner the pubkey of the vaults owner
@@ -978,7 +949,7 @@ export class KaminoManager {
978
949
  }
979
950
 
980
951
  /**
981
- * This returns an array of scope oracle configs to be used to set the scope price and twap oracles for a reserve
952
+ * This retruns an array of scope oracle configs to be used to set the scope price and twap oracles for a reserve
982
953
  * @param feed - scope feed to fetch prices from
983
954
  * @param cluster - cluster to fetch from, this should be left unchanged unless working on devnet or locally
984
955
  * @returns - an array of scope oracle configs
@@ -29,7 +29,7 @@ import Decimal from 'decimal.js';
29
29
  import { FarmState } from '@kamino-finance/farms-sdk';
30
30
  import { PROGRAM_ID } from '../idl_codegen/programId';
31
31
  import bs58 from 'bs58';
32
- import { OraclePrices, Scope, U16_MAX } from '@kamino-finance/scope-sdk';
32
+ import { OraclePrices, Scope } from '@kamino-finance/scope-sdk';
33
33
  import { Fraction } from './fraction';
34
34
  import { chunks, KaminoPrices, MintToPriceMap } from '@kamino-finance/kliquidity-sdk';
35
35
  import { parseTokenSymbol, parseZeroPaddedUtf8 } from './utils';
@@ -59,6 +59,8 @@ export class KaminoMarket {
59
59
 
60
60
  readonly programId: PublicKey;
61
61
 
62
+ scope: Scope;
63
+
62
64
  private readonly recentSlotDurationMs: number;
63
65
 
64
66
  private constructor(
@@ -66,6 +68,7 @@ export class KaminoMarket {
66
68
  state: LendingMarket,
67
69
  marketAddress: string,
68
70
  reserves: Map<PublicKey, KaminoReserve>,
71
+ scope: Scope,
69
72
  recentSlotDurationMs: number,
70
73
  programId: PublicKey = PROGRAM_ID
71
74
  ) {
@@ -75,6 +78,7 @@ export class KaminoMarket {
75
78
  this.reserves = reserves;
76
79
  this.reservesActive = getReservesActive(this.reserves);
77
80
  this.programId = programId;
81
+ this.scope = scope;
78
82
  this.recentSlotDurationMs = recentSlotDurationMs;
79
83
  }
80
84
 
@@ -93,6 +97,7 @@ export class KaminoMarket {
93
97
  marketAddress: PublicKey,
94
98
  recentSlotDurationMs: number,
95
99
  programId: PublicKey = PROGRAM_ID,
100
+ setupLocalTest: boolean = false,
96
101
  withReserves: boolean = true
97
102
  ) {
98
103
  const market = await LendingMarket.fetch(connection, marketAddress, programId);
@@ -100,12 +105,26 @@ export class KaminoMarket {
100
105
  if (market === null) {
101
106
  return null;
102
107
  }
108
+ let scope: Scope;
109
+ if (!setupLocalTest) {
110
+ scope = new Scope('mainnet-beta', connection);
111
+ } else {
112
+ scope = new Scope('localnet', connection);
113
+ }
103
114
 
104
115
  const reserves = withReserves
105
116
  ? await getReservesForMarket(marketAddress, connection, programId, recentSlotDurationMs)
106
117
  : new Map<PublicKey, KaminoReserve>();
107
118
 
108
- return new KaminoMarket(connection, market, marketAddress.toString(), reserves, recentSlotDurationMs, programId);
119
+ return new KaminoMarket(
120
+ connection,
121
+ market,
122
+ marketAddress.toString(),
123
+ reserves,
124
+ scope,
125
+ recentSlotDurationMs,
126
+ programId
127
+ );
109
128
  }
110
129
 
111
130
  async reload(): Promise<void> {
@@ -1167,9 +1186,9 @@ export class KaminoMarket {
1167
1186
  /**
1168
1187
  * Get all Scope prices used by all the market reserves
1169
1188
  */
1170
- async getAllScopePrices(scope: Scope, oraclePrices?: OraclePrices): Promise<KaminoPrices> {
1189
+ async getAllScopePrices(oraclePrices?: OraclePrices): Promise<KaminoPrices> {
1171
1190
  if (!oraclePrices) {
1172
- oraclePrices = await scope.getOraclePrices();
1191
+ oraclePrices = await this.scope.getOraclePrices();
1173
1192
  }
1174
1193
  const spot: MintToPriceMap = {};
1175
1194
  const twaps: MintToPriceMap = {};
@@ -1180,11 +1199,11 @@ export class KaminoMarket {
1180
1199
  const chain = reserve.state.config.tokenInfo.scopeConfiguration.priceChain;
1181
1200
  const twapChain = reserve.state.config.tokenInfo.scopeConfiguration.twapChain.filter((x) => x > 0);
1182
1201
  if (oracle && isNotNullPubkey(oracle) && chain && Scope.isScopeChainValid(chain)) {
1183
- const spotPrice = await scope.getPriceFromChain(chain, oraclePrices);
1202
+ const spotPrice = await this.scope.getPriceFromChain(chain, oraclePrices);
1184
1203
  spot[tokenMint] = { price: spotPrice.price, name: tokenName };
1185
1204
  }
1186
1205
  if (oracle && isNotNullPubkey(oracle) && twapChain && Scope.isScopeChainValid(twapChain)) {
1187
- const twap = await scope.getPriceFromChain(twapChain, oraclePrices);
1206
+ const twap = await this.scope.getPriceFromChain(twapChain, oraclePrices);
1188
1207
  twaps[tokenMint] = { price: twap.price, name: tokenName };
1189
1208
  }
1190
1209
  }
@@ -1508,34 +1527,6 @@ export function getReservesActive(reserves: Map<PublicKey, KaminoReserve>): Map<
1508
1527
  return reservesActive;
1509
1528
  }
1510
1529
 
1511
- export function getTokenIdsForScopeRefresh(kaminoMarket: KaminoMarket, reserves: PublicKey[]): number[] {
1512
- const tokenIds: number[] = [];
1513
-
1514
- for (const reserveAddress of reserves) {
1515
- const reserve = kaminoMarket.getReserveByAddress(reserveAddress);
1516
- if (!reserve) {
1517
- throw new Error(`Reserve not found for reserve ${reserveAddress.toBase58()}`);
1518
- }
1519
-
1520
- if (!reserve.state.config.tokenInfo.scopeConfiguration.priceFeed.equals(PublicKey.default)) {
1521
- let x = 0;
1522
-
1523
- while (reserve.state.config.tokenInfo.scopeConfiguration.priceChain[x] !== U16_MAX) {
1524
- tokenIds.push(reserve.state.config.tokenInfo.scopeConfiguration.priceChain[x]);
1525
- x++;
1526
- }
1527
-
1528
- x = 0;
1529
- while (reserve.state.config.tokenInfo.scopeConfiguration.twapChain[x] !== U16_MAX) {
1530
- tokenIds.push(reserve.state.config.tokenInfo.scopeConfiguration.twapChain[x]);
1531
- x++;
1532
- }
1533
- }
1534
- }
1535
-
1536
- return tokenIds;
1537
- }
1538
-
1539
1530
  export async function getReserveFromMintAndMarket(
1540
1531
  connection: Connection,
1541
1532
  market: KaminoMarket,
@@ -17,7 +17,6 @@ import {
17
17
  getObligationPdaWithArgs,
18
18
  getObligationType,
19
19
  isNotNullPubkey,
20
- ObligationType,
21
20
  PubkeyHashMap,
22
21
  TOTAL_NUMBER_OF_IDS_TO_CHECK,
23
22
  U64_MAX,
@@ -267,7 +266,7 @@ export class KaminoObligation {
267
266
  /**
268
267
  * @returns total borrow power of the obligation, relative to max LTV of each asset's reserve
269
268
  */
270
- getMaxAllowedBorrowValue(): Decimal {
269
+ getAllowedBorrowValue(): Decimal {
271
270
  return new Fraction(this.state.allowedBorrowValueSf).toDecimal();
272
271
  }
273
272
 
@@ -1594,8 +1593,3 @@ export class KaminoObligation {
1594
1593
  }
1595
1594
  }
1596
1595
  }
1597
-
1598
- // Create a function that checks if an obligation is of type obligation or obligationType
1599
- export function isKaminoObligation(obligation: KaminoObligation | ObligationType): obligation is KaminoObligation {
1600
- return 'obligationAddress' in obligation;
1601
- }
@@ -11,7 +11,7 @@ import {
11
11
  SYSVAR_RENT_PUBKEY,
12
12
  TransactionInstruction,
13
13
  } from '@solana/web3.js';
14
- import { getAssociatedTokenAddressSync, NATIVE_MINT, 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
17
  getTransferWsolIxns,
@@ -82,7 +82,7 @@ import {
82
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
- import { getAccountsInLUT, initLookupTableIx } from '../utils/lookupTable';
85
+ import { getAccountsInLUT, initLookupTableIx } from './lut_utils';
86
86
  import {
87
87
  getFarmStakeIxs,
88
88
  getFarmUnstakeAndWithdrawIxs,
@@ -100,8 +100,6 @@ const CTOKEN_VAULT_SEED = 'ctoken_vault';
100
100
  const BASE_VAULT_AUTHORITY_SEED = 'authority';
101
101
  const SHARES_SEED = 'shares';
102
102
 
103
- export const INITIAL_DEPOSIT_LAMPORTS = 1000;
104
-
105
103
  /**
106
104
  * KaminoVaultClient is a class that provides a high-level interface to interact with the Kamino Vault program.
107
105
  */
@@ -197,8 +195,6 @@ export class KaminoVaultClient {
197
195
  this._kaminoVaultProgramId
198
196
  )[0];
199
197
 
200
- const adminTokenAccount = getAssociatedTokenAddressSync(vaultConfig.tokenMint, vaultConfig.admin, false);
201
-
202
198
  const initVaultAccounts: InitVaultAccounts = {
203
199
  adminAuthority: vaultConfig.admin,
204
200
  vaultState: vaultState.publicKey,
@@ -210,7 +206,6 @@ export class KaminoVaultClient {
210
206
  rent: SYSVAR_RENT_PUBKEY,
211
207
  tokenProgram: vaultConfig.tokenMintProgramId,
212
208
  sharesTokenProgram: TOKEN_PROGRAM_ID,
213
- adminTokenAccount,
214
209
  };
215
210
  const initVaultIx = initVault(initVaultAccounts, this._kaminoVaultProgramId);
216
211
 
@@ -293,7 +288,7 @@ export class KaminoVaultClient {
293
288
  );
294
289
 
295
290
  const updateReserveAllocationAccounts: UpdateReserveAllocationAccounts = {
296
- signer: vaultState.vaultAdminAuthority,
291
+ adminAuthority: vaultState.adminAuthority,
297
292
  vaultState: vault.address,
298
293
  baseVaultAuthority: vaultState.baseVaultAuthority,
299
294
  reserveCollateralMint: reserveState.collateral.mintPubkey,
@@ -301,7 +296,7 @@ export class KaminoVaultClient {
301
296
  ctokenVault: cTokenVault,
302
297
  systemProgram: SystemProgram.programId,
303
298
  rent: SYSVAR_RENT_PUBKEY,
304
- reserveCollateralTokenProgram: TOKEN_PROGRAM_ID,
299
+ reserveCollateralTokenProgram: vaultState.tokenProgram,
305
300
  };
306
301
 
307
302
  const updateReserveAllocationArgs: UpdateReserveAllocationArgs = {
@@ -325,7 +320,7 @@ export class KaminoVaultClient {
325
320
  accountsToAddToLUT.push(lendingMarketAuth);
326
321
 
327
322
  const insertIntoLUTIxs = await this.insertIntoLookupTableIxs(
328
- vaultState.vaultAdminAuthority,
323
+ vaultState.adminAuthority,
329
324
  vaultState.vaultLookupTable,
330
325
  accountsToAddToLUT
331
326
  );
@@ -355,12 +350,12 @@ export class KaminoVaultClient {
355
350
  const vaultState: VaultState = await vault.getState(this.getConnection());
356
351
 
357
352
  const updateVaultConfigAccs: UpdateVaultConfigAccounts = {
358
- vaultAdminAuthority: vaultState.vaultAdminAuthority,
353
+ adminAuthority: vaultState.adminAuthority,
359
354
  vaultState: vault.address,
360
355
  klendProgram: this._kaminoLendProgramId,
361
356
  };
362
357
  if (signer) {
363
- updateVaultConfigAccs.vaultAdminAuthority = signer;
358
+ updateVaultConfigAccs.adminAuthority = signer;
364
359
  }
365
360
 
366
361
  const updateVaultConfigArgs: UpdateVaultConfigArgs = {
@@ -414,7 +409,7 @@ export class KaminoVaultClient {
414
409
  if (mode.kind === new VaultConfigField.PendingVaultAdmin().kind) {
415
410
  const newPubkey = new PublicKey(value);
416
411
  const insertIntoLutIxs = await this.insertIntoLookupTableIxs(
417
- vaultState.vaultAdminAuthority,
412
+ vaultState.adminAuthority,
418
413
  vaultState.vaultLookupTable,
419
414
  [newPubkey]
420
415
  );
@@ -432,7 +427,7 @@ export class KaminoVaultClient {
432
427
  farmState!.globalConfig
433
428
  );
434
429
  const insertIntoLutIxs = await this.insertIntoLookupTableIxs(
435
- vaultState.vaultAdminAuthority,
430
+ vaultState.adminAuthority,
436
431
  vaultState.vaultLookupTable,
437
432
  keysToAddToLUT
438
433
  );
@@ -481,7 +476,7 @@ export class KaminoVaultClient {
481
476
  value: string
482
477
  ): TransactionInstruction {
483
478
  const updateVaultConfigAccs: UpdateVaultConfigAccounts = {
484
- vaultAdminAuthority: admin,
479
+ adminAuthority: admin,
485
480
  vaultState: vault,
486
481
  klendProgram: this._kaminoLendProgramId,
487
482
  };
@@ -531,7 +526,7 @@ export class KaminoVaultClient {
531
526
 
532
527
  // read the current LUT and create a new one for the new admin and backfill it
533
528
  const accountsInExistentLUT = (await getAccountsInLUT(this.getConnection(), vaultState.vaultLookupTable)).filter(
534
- (account) => !account.equals(vaultState.vaultAdminAuthority)
529
+ (account) => !account.equals(vaultState.adminAuthority)
535
530
  );
536
531
 
537
532
  const LUTIxs: TransactionInstruction[] = [];
@@ -574,7 +569,7 @@ export class KaminoVaultClient {
574
569
  const vaultState: VaultState = await vault.getState(this.getConnection());
575
570
 
576
571
  const giveUpPendingFeesAccounts: GiveUpPendingFeesAccounts = {
577
- vaultAdminAuthority: vaultState.vaultAdminAuthority,
572
+ adminAuthority: vaultState.adminAuthority,
578
573
  vaultState: vault.address,
579
574
  klendProgram: this._kaminoLendProgramId,
580
575
  };
@@ -604,7 +599,7 @@ export class KaminoVaultClient {
604
599
  ): Promise<TransactionInstruction[]> {
605
600
  const vaultState: VaultState = await vault.getState(this.getConnection());
606
601
  const vaultReservesState = vaultReservesMap ? vaultReservesMap : await this.loadVaultReserves(vaultState);
607
- const [{ ata: adminTokenAta, createAtaIx }] = createAtasIdempotent(vaultState.vaultAdminAuthority, [
602
+ const [{ ata: adminTokenAta, createAtaIx }] = createAtasIdempotent(vaultState.adminAuthority, [
608
603
  {
609
604
  mint: vaultState.tokenMint,
610
605
  tokenProgram: TOKEN_PROGRAM_ID,
@@ -1015,16 +1010,20 @@ export class KaminoVaultClient {
1015
1010
  if (allReserves.length === 0) {
1016
1011
  throw new Error('No reserves found for the vault, please select at least one reserve for the vault');
1017
1012
  }
1013
+
1018
1014
  const [allReservesStateMap, computedReservesAllocation] = await Promise.all([
1019
1015
  this.loadVaultReserves(vaultState),
1020
1016
  this.getVaultComputedReservesAllocation(vaultState),
1021
1017
  ]);
1018
+
1022
1019
  const tokenProgram = await getAccountOwner(this.getConnection(), vaultState.tokenMint);
1023
1020
  const [{ ata: _payerTokenAta, createAtaIx }] = createAtasIdempotent(payer, [
1024
1021
  { mint: vaultState.tokenMint, tokenProgram },
1025
1022
  ]);
1023
+
1026
1024
  // compute total vault holdings and expected distribution based on weights
1027
1025
  const curentVaultAllocations = this.getVaultAllocations(vaultState);
1026
+
1028
1027
  const reservesToDisinvestFrom: PublicKey[] = [];
1029
1028
  const reservesToInvestInto: PublicKey[] = [];
1030
1029
 
@@ -1295,7 +1294,7 @@ export class KaminoVaultClient {
1295
1294
  const lendingMarketAuth = lendingMarketAuthPda(marketAddress, this._kaminoLendProgramId)[0];
1296
1295
 
1297
1296
  const withdrawPendingFeesAccounts: WithdrawPendingFeesAccounts = {
1298
- vaultAdminAuthority: vaultState.vaultAdminAuthority,
1297
+ adminAuthority: vaultState.adminAuthority,
1299
1298
  vaultState: vault.address,
1300
1299
  reserve: reserve.address,
1301
1300
  tokenVault: vaultState.tokenVault,
@@ -1355,7 +1354,7 @@ export class KaminoVaultClient {
1355
1354
  const vaultState = await vault.getState(this.getConnection());
1356
1355
  const allAccountsToBeInserted = [
1357
1356
  vault.address,
1358
- vaultState.vaultAdminAuthority,
1357
+ vaultState.adminAuthority,
1359
1358
  vaultState.baseVaultAuthority,
1360
1359
  vaultState.tokenMint,
1361
1360
  vaultState.tokenVault,
@@ -1400,7 +1399,7 @@ export class KaminoVaultClient {
1400
1399
  let lut = vaultState.vaultLookupTable;
1401
1400
  if (lut.equals(PublicKey.default)) {
1402
1401
  const recentSlot = await this.getConnection().getSlot();
1403
- const [ixn, address] = initLookupTableIx(vaultState.vaultAdminAuthority, recentSlot);
1402
+ const [ixn, address] = initLookupTableIx(vaultState.adminAuthority, recentSlot);
1404
1403
  setupLUTIfNeededIxs.push(ixn);
1405
1404
  lut = address;
1406
1405
 
@@ -1420,7 +1419,7 @@ export class KaminoVaultClient {
1420
1419
  }
1421
1420
  ixns.push(
1422
1421
  ...(await this.insertIntoLookupTableIxs(
1423
- vaultState.vaultAdminAuthority,
1422
+ vaultState.adminAuthority,
1424
1423
  lut,
1425
1424
  allAccountsToBeInserted,
1426
1425
  overridenExistentAccounts
@@ -1529,8 +1528,8 @@ export class KaminoVaultClient {
1529
1528
 
1530
1529
  let totalLeftToInvest = holdings.totalAUMIncludingFees.sub(holdings.pendingFees);
1531
1530
  let currentAllocationSum = totalAllocation;
1532
- const ONE = new Decimal(1);
1533
- while (totalLeftToInvest.gt(ONE)) {
1531
+ const ZERO = new Decimal(0);
1532
+ while (totalLeftToInvest.gt(ZERO)) {
1534
1533
  const totalLeftover = totalLeftToInvest;
1535
1534
  for (const reserve of allReserves) {
1536
1535
  const reserveWithWeight = initialVaultAllocations.get(reserve);
package/src/client.ts CHANGED
@@ -22,7 +22,6 @@ import { VanillaObligation } from './utils/ObligationType';
22
22
  import { parseTokenSymbol } from './classes/utils';
23
23
  import { Env, initEnv } from '../tests/runner/setup_utils';
24
24
  import { initializeFarmsForReserve } from '../tests/runner/farms/farms_operations';
25
- import { Scope } from '@kamino-finance/scope-sdk';
26
25
 
27
26
  const STAGING_LENDING_MARKET = new PublicKey('6WVSwDQXrBZeQVnu6hpnsRZhodaJTZBUaC334SiiBKdb');
28
27
  const MAINNET_LENDING_MARKET = new PublicKey('7u3HeHxYDLhnCoErrtycNokbQYbWGzLs6JSDqGAv5PfF');
@@ -310,8 +309,7 @@ async function deposit(connection: Connection, wallet: Keypair, token: string, d
310
309
  kaminoMarket.getReserveBySymbol(token)!.getLiquidityMint(),
311
310
  wallet.publicKey,
312
311
  new VanillaObligation(STAGING_LENDING_MARKET),
313
- true,
314
- { scope: new Scope('mainnet-beta', connection), scopeFeed: 'hubble' }
312
+ true
315
313
  );
316
314
  console.log('User obligation', kaminoAction.obligation!.obligationAddress.toString());
317
315
 
@@ -332,8 +330,7 @@ async function withdraw(connection: Connection, wallet: Keypair, token: string,
332
330
  kaminoMarket.getReserveBySymbol(token)!.getLiquidityMint(),
333
331
  wallet.publicKey,
334
332
  new VanillaObligation(new PublicKey(STAGING_LENDING_MARKET)),
335
- true,
336
- { scope: new Scope('mainnet-beta', connection), scopeFeed: 'hubble' }
333
+ true
337
334
  );
338
335
  console.log('User obligation', kaminoAction.obligation!.obligationAddress.toString());
339
336
 
@@ -354,8 +351,7 @@ async function borrow(connection: Connection, wallet: Keypair, token: string, bo
354
351
  kaminoMarket.getReserveBySymbol(token)!.getLiquidityMint(),
355
352
  wallet.publicKey,
356
353
  new VanillaObligation(new PublicKey(STAGING_LENDING_MARKET)),
357
- true,
358
- { scope: new Scope('mainnet-beta', connection), scopeFeed: 'hubble' }
354
+ true
359
355
  );
360
356
  console.log('User obligation', kaminoAction.obligation!.obligationAddress.toString());
361
357
 
@@ -377,7 +373,6 @@ async function repay(connection: Connection, wallet: Keypair, token: string, bor
377
373
  wallet.publicKey,
378
374
  new VanillaObligation(new PublicKey(STAGING_LENDING_MARKET)),
379
375
  true,
380
- { scope: new Scope('mainnet-beta', connection), scopeFeed: 'hubble' },
381
376
  await connection.getSlot()
382
377
  );
383
378
  console.log('User obligation', kaminoAction.obligation!.obligationAddress.toString());
@@ -5,7 +5,7 @@ import * as types from "../types" // eslint-disable-line @typescript-eslint/no-u
5
5
  import { PROGRAM_ID } from "../programId"
6
6
 
7
7
  export interface VaultStateFields {
8
- vaultAdminAuthority: PublicKey
8
+ adminAuthority: PublicKey
9
9
  baseVaultAuthority: PublicKey
10
10
  baseVaultAuthorityBump: BN
11
11
  tokenMint: PublicKey
@@ -38,12 +38,11 @@ export interface VaultStateFields {
38
38
  vaultFarm: PublicKey
39
39
  creationTimestamp: BN
40
40
  padding1: BN
41
- allocationAdmin: PublicKey
42
41
  padding2: Array<BN>
43
42
  }
44
43
 
45
44
  export interface VaultStateJSON {
46
- vaultAdminAuthority: string
45
+ adminAuthority: string
47
46
  baseVaultAuthority: string
48
47
  baseVaultAuthorityBump: string
49
48
  tokenMint: string
@@ -76,12 +75,11 @@ export interface VaultStateJSON {
76
75
  vaultFarm: string
77
76
  creationTimestamp: string
78
77
  padding1: string
79
- allocationAdmin: string
80
78
  padding2: Array<string>
81
79
  }
82
80
 
83
81
  export class VaultState {
84
- readonly vaultAdminAuthority: PublicKey
82
+ readonly adminAuthority: PublicKey
85
83
  readonly baseVaultAuthority: PublicKey
86
84
  readonly baseVaultAuthorityBump: BN
87
85
  readonly tokenMint: PublicKey
@@ -114,7 +112,6 @@ export class VaultState {
114
112
  readonly vaultFarm: PublicKey
115
113
  readonly creationTimestamp: BN
116
114
  readonly padding1: BN
117
- readonly allocationAdmin: PublicKey
118
115
  readonly padding2: Array<BN>
119
116
 
120
117
  static readonly discriminator = Buffer.from([
@@ -122,7 +119,7 @@ export class VaultState {
122
119
  ])
123
120
 
124
121
  static readonly layout = borsh.struct([
125
- borsh.publicKey("vaultAdminAuthority"),
122
+ borsh.publicKey("adminAuthority"),
126
123
  borsh.publicKey("baseVaultAuthority"),
127
124
  borsh.u64("baseVaultAuthorityBump"),
128
125
  borsh.publicKey("tokenMint"),
@@ -155,12 +152,11 @@ export class VaultState {
155
152
  borsh.publicKey("vaultFarm"),
156
153
  borsh.u64("creationTimestamp"),
157
154
  borsh.u64("padding1"),
158
- borsh.publicKey("allocationAdmin"),
159
- borsh.array(borsh.u128(), 242, "padding2"),
155
+ borsh.array(borsh.u128(), 244, "padding2"),
160
156
  ])
161
157
 
162
158
  constructor(fields: VaultStateFields) {
163
- this.vaultAdminAuthority = fields.vaultAdminAuthority
159
+ this.adminAuthority = fields.adminAuthority
164
160
  this.baseVaultAuthority = fields.baseVaultAuthority
165
161
  this.baseVaultAuthorityBump = fields.baseVaultAuthorityBump
166
162
  this.tokenMint = fields.tokenMint
@@ -195,7 +191,6 @@ export class VaultState {
195
191
  this.vaultFarm = fields.vaultFarm
196
192
  this.creationTimestamp = fields.creationTimestamp
197
193
  this.padding1 = fields.padding1
198
- this.allocationAdmin = fields.allocationAdmin
199
194
  this.padding2 = fields.padding2
200
195
  }
201
196
 
@@ -243,7 +238,7 @@ export class VaultState {
243
238
  const dec = VaultState.layout.decode(data.slice(8))
244
239
 
245
240
  return new VaultState({
246
- vaultAdminAuthority: dec.vaultAdminAuthority,
241
+ adminAuthority: dec.adminAuthority,
247
242
  baseVaultAuthority: dec.baseVaultAuthority,
248
243
  baseVaultAuthorityBump: dec.baseVaultAuthorityBump,
249
244
  tokenMint: dec.tokenMint,
@@ -280,14 +275,13 @@ export class VaultState {
280
275
  vaultFarm: dec.vaultFarm,
281
276
  creationTimestamp: dec.creationTimestamp,
282
277
  padding1: dec.padding1,
283
- allocationAdmin: dec.allocationAdmin,
284
278
  padding2: dec.padding2,
285
279
  })
286
280
  }
287
281
 
288
282
  toJSON(): VaultStateJSON {
289
283
  return {
290
- vaultAdminAuthority: this.vaultAdminAuthority.toString(),
284
+ adminAuthority: this.adminAuthority.toString(),
291
285
  baseVaultAuthority: this.baseVaultAuthority.toString(),
292
286
  baseVaultAuthorityBump: this.baseVaultAuthorityBump.toString(),
293
287
  tokenMint: this.tokenMint.toString(),
@@ -322,14 +316,13 @@ export class VaultState {
322
316
  vaultFarm: this.vaultFarm.toString(),
323
317
  creationTimestamp: this.creationTimestamp.toString(),
324
318
  padding1: this.padding1.toString(),
325
- allocationAdmin: this.allocationAdmin.toString(),
326
319
  padding2: this.padding2.map((item) => item.toString()),
327
320
  }
328
321
  }
329
322
 
330
323
  static fromJSON(obj: VaultStateJSON): VaultState {
331
324
  return new VaultState({
332
- vaultAdminAuthority: new PublicKey(obj.vaultAdminAuthority),
325
+ adminAuthority: new PublicKey(obj.adminAuthority),
333
326
  baseVaultAuthority: new PublicKey(obj.baseVaultAuthority),
334
327
  baseVaultAuthorityBump: new BN(obj.baseVaultAuthorityBump),
335
328
  tokenMint: new PublicKey(obj.tokenMint),
@@ -364,7 +357,6 @@ export class VaultState {
364
357
  vaultFarm: new PublicKey(obj.vaultFarm),
365
358
  creationTimestamp: new BN(obj.creationTimestamp),
366
359
  padding1: new BN(obj.padding1),
367
- allocationAdmin: new PublicKey(obj.allocationAdmin),
368
360
  padding2: obj.padding2.map((item) => new BN(item)),
369
361
  })
370
362
  }