@kamino-finance/klend-sdk 5.10.6 → 5.10.8

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 (80) hide show
  1. package/dist/classes/action.d.ts +7 -3
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +28 -13
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/manager.d.ts +20 -18
  6. package/dist/classes/manager.d.ts.map +1 -1
  7. package/dist/classes/manager.js +27 -20
  8. package/dist/classes/manager.js.map +1 -1
  9. package/dist/classes/market.d.ts +11 -0
  10. package/dist/classes/market.d.ts.map +1 -1
  11. package/dist/classes/market.js +26 -0
  12. package/dist/classes/market.js.map +1 -1
  13. package/dist/classes/obligation.d.ts +14 -0
  14. package/dist/classes/obligation.d.ts.map +1 -1
  15. package/dist/classes/obligation.js +25 -0
  16. package/dist/classes/obligation.js.map +1 -1
  17. package/dist/classes/types_utils.d.ts +11 -0
  18. package/dist/classes/types_utils.d.ts.map +1 -0
  19. package/dist/classes/types_utils.js +21 -0
  20. package/dist/classes/types_utils.js.map +1 -0
  21. package/dist/classes/utils.d.ts +7 -0
  22. package/dist/classes/utils.d.ts.map +1 -1
  23. package/dist/classes/utils.js +21 -0
  24. package/dist/classes/utils.js.map +1 -1
  25. package/dist/classes/vault.d.ts +23 -14
  26. package/dist/classes/vault.d.ts.map +1 -1
  27. package/dist/classes/vault.js +65 -33
  28. package/dist/classes/vault.js.map +1 -1
  29. package/dist/client_kamino_manager.d.ts.map +1 -1
  30. package/dist/client_kamino_manager.js +25 -2
  31. package/dist/client_kamino_manager.js.map +1 -1
  32. package/dist/lending_operations/index.d.ts +1 -0
  33. package/dist/lending_operations/index.d.ts.map +1 -1
  34. package/dist/lending_operations/index.js +1 -0
  35. package/dist/lending_operations/index.js.map +1 -1
  36. package/dist/lending_operations/repay_with_collateral_operations.d.ts +5 -5
  37. package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
  38. package/dist/lending_operations/repay_with_collateral_operations.js +3 -2
  39. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  40. package/dist/lending_operations/swap_collateral_operations.d.ts +102 -0
  41. package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -0
  42. package/dist/lending_operations/swap_collateral_operations.js +306 -0
  43. package/dist/lending_operations/swap_collateral_operations.js.map +1 -0
  44. package/dist/leverage/operations.d.ts +2 -2
  45. package/dist/leverage/operations.d.ts.map +1 -1
  46. package/dist/leverage/operations.js +4 -0
  47. package/dist/leverage/operations.js.map +1 -1
  48. package/dist/leverage/types.d.ts +5 -5
  49. package/dist/leverage/types.d.ts.map +1 -1
  50. package/dist/leverage/utils.d.ts +5 -5
  51. package/dist/leverage/utils.d.ts.map +1 -1
  52. package/dist/leverage/utils.js.map +1 -1
  53. package/dist/utils/constants.d.ts +1 -0
  54. package/dist/utils/constants.d.ts.map +1 -1
  55. package/dist/utils/constants.js +2 -1
  56. package/dist/utils/constants.js.map +1 -1
  57. package/dist/utils/pubkey.d.ts +3 -0
  58. package/dist/utils/pubkey.d.ts.map +1 -1
  59. package/dist/utils/pubkey.js +16 -2
  60. package/dist/utils/pubkey.js.map +1 -1
  61. package/dist/utils/seeds.d.ts +1 -1
  62. package/dist/utils/seeds.js +1 -1
  63. package/package.json +4 -4
  64. package/src/classes/action.ts +37 -19
  65. package/src/classes/manager.ts +40 -23
  66. package/src/classes/market.ts +35 -1
  67. package/src/classes/obligation.ts +75 -0
  68. package/src/classes/types_utils.ts +19 -0
  69. package/src/classes/utils.ts +22 -1
  70. package/src/classes/vault.ts +93 -41
  71. package/src/client_kamino_manager.ts +43 -4
  72. package/src/lending_operations/index.ts +1 -0
  73. package/src/lending_operations/repay_with_collateral_operations.ts +10 -9
  74. package/src/lending_operations/swap_collateral_operations.ts +586 -0
  75. package/src/leverage/operations.ts +14 -10
  76. package/src/leverage/types.ts +6 -6
  77. package/src/leverage/utils.ts +8 -8
  78. package/src/utils/constants.ts +2 -0
  79. package/src/utils/pubkey.ts +19 -2
  80. package/src/utils/seeds.ts +1 -1
@@ -53,7 +53,13 @@ import {
53
53
  import { VaultConfigField, VaultConfigFieldKind } from '../idl_codegen_kamino_vault/types';
54
54
  import { VaultState } from '../idl_codegen_kamino_vault/accounts';
55
55
  import Decimal from 'decimal.js';
56
- import { bpsToPct, getTokenBalanceFromAccountInfoLamports, numberToLamportsDecimal, parseTokenSymbol } from './utils';
56
+ import {
57
+ bpsToPct,
58
+ decodeVaultName,
59
+ getTokenBalanceFromAccountInfoLamports,
60
+ numberToLamportsDecimal,
61
+ parseTokenSymbol,
62
+ } from './utils';
57
63
  import { deposit } from '../idl_codegen_kamino_vault/instructions';
58
64
  import { withdraw } from '../idl_codegen_kamino_vault/instructions';
59
65
  import { PROGRAM_ID } from '../idl_codegen/programId';
@@ -83,6 +89,7 @@ import {
83
89
  getSharesInFarmUserPosition,
84
90
  getUserSharesInFarm,
85
91
  } from './farm_utils';
92
+ import { printHoldings } from './types_utils';
86
93
 
87
94
  export const kaminoVaultId = new PublicKey('kvauTFR8qm1dhniz6pYuBZkuene3Hfrs1VQhVRgCNrr');
88
95
  export const kaminoVaultStagingId = new PublicKey('STkvh7ostar39Fwr4uZKASs1RNNuYMFMTsE77FiRsL2');
@@ -125,6 +132,36 @@ export class KaminoVaultClient {
125
132
  return;
126
133
  }
127
134
 
135
+ /**
136
+ * Prints a vault in a human readable form
137
+ * @param vaultPubkey - the address of the vault
138
+ * @param [vaultState] - optional parameter to pass the vault state directly; this will save a network call
139
+ * @returns - void; prints the vault to the console
140
+ */
141
+ async printVault(vaultPubkey: PublicKey, vaultState?: VaultState) {
142
+ const vault = vaultState ? vaultState : await VaultState.fetch(this.getConnection(), vaultPubkey);
143
+
144
+ if (!vault) {
145
+ console.log(`Vault ${vaultPubkey.toString()} not found`);
146
+ return;
147
+ }
148
+
149
+ const kaminoVault = new KaminoVault(vaultPubkey, vault, this._kaminoVaultProgramId);
150
+ const vaultName = this.decodeVaultName(vault.name);
151
+ const slot = await this.getConnection().getSlot('confirmed');
152
+ const tokensPerShare = await this.getTokensPerShareSingleVault(kaminoVault, slot);
153
+ const holdings = await this.getVaultHoldings(vault);
154
+
155
+ const sharesIssued = new Decimal(vault.sharesIssued.toString()!).div(
156
+ new Decimal(vault.sharesMintDecimals.toString())
157
+ );
158
+
159
+ console.log('Name: ', vaultName);
160
+ console.log('Shares issued: ', sharesIssued);
161
+ printHoldings(holdings);
162
+ console.log('Tokens per share: ', tokensPerShare);
163
+ }
164
+
128
165
  /**
129
166
  * This method will create a vault with a given config. The config can be changed later on, but it is recommended to set it up correctly from the start
130
167
  * @param vaultConfig - the config object used to create a vault
@@ -1058,11 +1095,7 @@ export class KaminoVaultClient {
1058
1095
 
1059
1096
  /**Convert an u8 array to a string */
1060
1097
  decodeVaultName(token: number[]): string {
1061
- const maxArray = new Uint8Array(token);
1062
- let s: string = new TextDecoder().decode(maxArray);
1063
- // Remove trailing zeros and spaces
1064
- s = s.replace(/[\0 ]+$/, '');
1065
- return s;
1098
+ return decodeVaultName(token);
1066
1099
  }
1067
1100
 
1068
1101
  private withdrawIxn(
@@ -1491,15 +1524,15 @@ export class KaminoVaultClient {
1491
1524
  }
1492
1525
 
1493
1526
  /**
1494
- * This method calculates the token per shar value. This will always change based on interest earned from the vault, but calculating it requires a bunch of rpc requests. Caching this for a short duration would be optimal
1527
+ * This method calculates the token per share value. This will always change based on interest earned from the vault, but calculating it requires a bunch of rpc requests. Caching this for a short duration would be optimal
1495
1528
  * @param vault - vault to calculate tokensPerShare for
1496
- * @param slot - current slot, used to estimate the interest earned in the different reserves with allocation from the vault
1529
+ * @param [slot] - the slot at which we retrieve the tokens per share. Optional. If not provided, the function will fetch the current slot
1497
1530
  * @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
1498
1531
  * @returns - token per share value
1499
1532
  */
1500
1533
  async getTokensPerShareSingleVault(
1501
1534
  vault: KaminoVault,
1502
- slot: number,
1535
+ slot?: number,
1503
1536
  vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>
1504
1537
  ): Promise<Decimal> {
1505
1538
  const vaultState = await vault.getState(this.getConnection());
@@ -1514,11 +1547,7 @@ export class KaminoVaultClient {
1514
1547
  vaultState.sharesMintDecimals.toString()
1515
1548
  );
1516
1549
 
1517
- const holdings = await this.getVaultHoldings(
1518
- vaultState,
1519
- await this.getConnection().getSlot('confirmed'),
1520
- vaultReservesState
1521
- );
1550
+ const holdings = await this.getVaultHoldings(vaultState, slot, vaultReservesState);
1522
1551
 
1523
1552
  return holdings.total.div(sharesDecimal);
1524
1553
  }
@@ -1759,7 +1788,7 @@ export class KaminoVaultClient {
1759
1788
  /**
1760
1789
  * This will retrieve all the tokens that can be used as collateral by the users who borrow the token in the vault alongside details about the min and max loan to value ratio
1761
1790
  * @param vaultState - the vault state to load reserves for
1762
- * @param slot - current slot
1791
+ * @param [slot] - the slot for which to retrieve the vault collaterals for. Optional. If not provided the function will fetch the current slot
1763
1792
  * @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
1764
1793
  * @param [kaminoMarkets] - a list of all the kamino markets. Optional. If provided the function will be significantly faster as it will not have to fetch the markets
1765
1794
  * @returns a hashmap from each reserve pubkey to the market overview of the collaterals that can be used and the min and max loan to value ratio in that market
@@ -1831,13 +1860,13 @@ export class KaminoVaultClient {
1831
1860
  /**
1832
1861
  * This will return an VaultHoldings object which contains the amount available (uninvested) in vault, total amount invested in reseves and a breakdown of the amount invested in each reserve
1833
1862
  * @param vault - the kamino vault to get available liquidity to withdraw for
1834
- * @param slot - current slot
1835
- * @param vaultReserves - a hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
1863
+ * @param [slot] - the slot for which to calculate the holdings. Optional. If not provided the function will fetch the current slot
1864
+ * @param [vaultReserves] - a hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
1836
1865
  * @returns an VaultHoldings object representing the amount available (uninvested) in vault, total amount invested in reseves and a breakdown of the amount invested in each reserve
1837
1866
  */
1838
1867
  async getVaultHoldings(
1839
1868
  vault: VaultState,
1840
- slot: number,
1869
+ slot?: number,
1841
1870
  vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>
1842
1871
  ): Promise<VaultHoldings> {
1843
1872
  const vaultHoldings: VaultHoldings = {
@@ -1860,7 +1889,12 @@ export class KaminoVaultClient {
1860
1889
  throw new Error(`Reserve ${allocationStrategy.reserve.toBase58()} not found`);
1861
1890
  }
1862
1891
 
1863
- const reserveCollExchangeRate = reserve.getEstimatedCollateralExchangeRate(slot, 0);
1892
+ let reserveCollExchangeRate: Decimal;
1893
+ if (slot) {
1894
+ reserveCollExchangeRate = reserve.getEstimatedCollateralExchangeRate(slot, 0);
1895
+ } else {
1896
+ reserveCollExchangeRate = reserve.getCollateralExchangeRate();
1897
+ }
1864
1898
  const reserveAllocationLiquidityAmount = new Decimal(allocationStrategy.ctokenAllocation.toString()).div(
1865
1899
  reserveCollExchangeRate
1866
1900
  );
@@ -1883,17 +1917,18 @@ export class KaminoVaultClient {
1883
1917
  }
1884
1918
 
1885
1919
  /**
1886
- * This will return an VaultHoldingsWithUSDValue object which contains an holdings field representing the amount available (uninvested) in vault, total amount invested in reseves and a breakdown of the amount invested in each reserve and additional fields for the total USD value of the available and invested amounts
1920
+ * This will return an VaultOverview object that encapsulates all the information about the vault, including the holdings, reserves details, theoretical APY, utilization ratio and total borrowed amount
1887
1921
  * @param vault - the kamino vault to get available liquidity to withdraw for
1888
- * @param slot - current slot
1889
1922
  * @param price - the price of the token in the vault (e.g. USDC)
1923
+ * @param [slot] - the slot for which to retrieve the vault overview for. Optional. If not provided the function will fetch the current slot
1890
1924
  * @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
1891
- * @returns an VaultHoldingsWithUSDValue object with details about the tokens available and invested in the vault, denominated in tokens and USD
1925
+ * @param [kaminoMarkets] - a list of all kamino markets. Optional. If provided the function will be significantly faster as it will not have to fetch the markets
1926
+ * @returns an VaultOverview object with details about the tokens available and invested in the vault, denominated in tokens and USD
1892
1927
  */
1893
1928
  async getVaultHoldingsWithPrice(
1894
1929
  vault: VaultState,
1895
- slot: number,
1896
1930
  price: Decimal,
1931
+ slot?: number,
1897
1932
  vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>
1898
1933
  ): Promise<VaultHoldingsWithUSDValue> {
1899
1934
  const holdings = await this.getVaultHoldings(vault, slot, vaultReservesMap);
@@ -1914,16 +1949,16 @@ export class KaminoVaultClient {
1914
1949
  /**
1915
1950
  * This will return an VaultOverview object that encapsulates all the information about the vault, including the holdings, reserves details, theoretical APY, utilization ratio and total borrowed amount
1916
1951
  * @param vault - the kamino vault to get available liquidity to withdraw for
1917
- * @param slot - current slot
1918
1952
  * @param price - the price of the token in the vault (e.g. USDC)
1953
+ * @param [slot] - the slot for which to retrieve the vault overview for. Optional. If not provided the function will fetch the current slot
1919
1954
  * @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
1920
1955
  * @param [kaminoMarkets] - a list of all kamino markets. Optional. If provided the function will be significantly faster as it will not have to fetch the markets
1921
1956
  * @returns an VaultOverview object with details about the tokens available and invested in the vault, denominated in tokens and USD
1922
1957
  */
1923
1958
  async getVaultOverview(
1924
1959
  vault: VaultState,
1925
- slot: number,
1926
1960
  price: Decimal,
1961
+ slot?: number,
1927
1962
  vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>,
1928
1963
  kaminoMarkets?: KaminoMarket[]
1929
1964
  ): Promise<VaultOverview> {
@@ -1931,14 +1966,26 @@ export class KaminoVaultClient {
1931
1966
 
1932
1967
  const vaultHoldingsWithUSDValuePromise = await this.getVaultHoldingsWithPrice(
1933
1968
  vault,
1934
- slot,
1935
1969
  price,
1970
+ slot,
1971
+ vaultReservesState
1972
+ );
1973
+
1974
+ const currentSlot = slot ? slot : await this.getConnection().getSlot();
1975
+
1976
+ const vaultTheoreticalAPYPromise = await this.getVaultTheoreticalAPY(vault, currentSlot, vaultReservesState);
1977
+ const totalInvestedAndBorrowedPromise = await this.getTotalBorrowedAndInvested(
1978
+ vault,
1979
+ currentSlot,
1936
1980
  vaultReservesState
1937
1981
  );
1938
- const vaultTheoreticalAPYPromise = await this.getVaultTheoreticalAPY(vault, slot, vaultReservesState);
1939
- const totalInvestedAndBorrowedPromise = await this.getTotalBorrowedAndInvested(vault, slot, vaultReservesState);
1940
- const vaultCollateralsPromise = await this.getVaultCollaterals(vault, slot, vaultReservesState, kaminoMarkets);
1941
- const reservesOverviewPromise = await this.getVaultReservesDetails(vault, slot, vaultReservesState);
1982
+ const vaultCollateralsPromise = await this.getVaultCollaterals(
1983
+ vault,
1984
+ currentSlot,
1985
+ vaultReservesState,
1986
+ kaminoMarkets
1987
+ );
1988
+ const reservesOverviewPromise = await this.getVaultReservesDetails(vault, currentSlot, vaultReservesState);
1942
1989
 
1943
1990
  // 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
1944
1991
  const [
@@ -2115,26 +2162,31 @@ export class KaminoVaultClient {
2115
2162
  * @param vaultState the kamino vault state to get simulated holdings and earnings for
2116
2163
  * @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
2117
2164
  * @param [currentSlot] - the current slot. Optional. If not provided it will fetch the current slot
2165
+ * @param [previousTotalAUM] - the previous AUM of the vault to compute the earned interest relative to this value. Optional. If not provided the function will estimate the total AUM at the slot of the last state update on chain
2118
2166
  * @returns a struct of simulated vault holdings and earned interest
2119
2167
  */
2120
2168
  async calculateSimulatedHoldingsWithInterest(
2121
2169
  vaultState: VaultState,
2122
2170
  vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>,
2123
- currentSlot?: number
2171
+ currentSlot?: number,
2172
+ previousTotalAUM?: Decimal
2124
2173
  ): Promise<SimulatedVaultHoldingsWithEarnedInterest> {
2125
- const latestUpdateTs = vaultState.lastFeeChargeTimestamp.toNumber();
2126
- const lastUpdateSlot = latestUpdateTs / this.recentSlotDurationMs;
2174
+ let prevAUM: Decimal;
2127
2175
 
2128
- const slot = currentSlot ? currentSlot : await this.getConnection().getSlot('confirmed');
2176
+ if (previousTotalAUM) {
2177
+ prevAUM = previousTotalAUM;
2178
+ } else {
2179
+ const latestUpdateTs = vaultState.lastFeeChargeTimestamp.toNumber();
2180
+ const lastUpdateSlot = latestUpdateTs / this.recentSlotDurationMs;
2129
2181
 
2130
- const lastUpdateHoldingsPromise = this.getVaultHoldings(vaultState, lastUpdateSlot, vaultReservesMap);
2131
- const currentHoldingsPromise = this.getVaultHoldings(vaultState, slot, vaultReservesMap);
2132
- const [lastUpdateHoldings, currentHoldings] = await Promise.all([
2133
- lastUpdateHoldingsPromise,
2134
- currentHoldingsPromise,
2135
- ]);
2182
+ const lastUpdateHoldings = await this.getVaultHoldings(vaultState, lastUpdateSlot, vaultReservesMap);
2183
+ prevAUM = lastUpdateHoldings.total;
2184
+ }
2185
+
2186
+ const slot = currentSlot ? currentSlot : await this.getConnection().getSlot('confirmed');
2136
2187
 
2137
- const earnedInterest = currentHoldings.total.sub(lastUpdateHoldings.total);
2188
+ const currentHoldings = await this.getVaultHoldings(vaultState, slot, vaultReservesMap);
2189
+ const earnedInterest = currentHoldings.total.sub(prevAUM);
2138
2190
 
2139
2191
  return {
2140
2192
  holdings: currentHoldings,
@@ -53,6 +53,7 @@ import {
53
53
  PerformanceFeeBps,
54
54
  } from './idl_codegen_kamino_vault/types/VaultConfigField';
55
55
  import { getAccountOwner } from './utils/rpc';
56
+ import { printHoldings } from './classes/types_utils';
56
57
 
57
58
  dotenv.config({
58
59
  path: `.env${process.env.ENV ? '.' + process.env.ENV : ''}`,
@@ -293,6 +294,42 @@ async function main() {
293
294
  mode === 'execute' && console.log('Pending admin updated:', updateVaultPendingAdminSig);
294
295
  });
295
296
 
297
+ commands
298
+ .command('update-vault-config')
299
+ .requiredOption('--vault <string>', 'Vault address')
300
+ .requiredOption('--field <string>', 'The field to update')
301
+ .requiredOption('--value <string>', 'The value to update the field to')
302
+ .requiredOption(
303
+ `--mode <string>`,
304
+ 'simulate - to print txn simulation, inspect - to get txn simulation in explorer, execute - execute txn, multisig - to get bs58 txn for multisig usage'
305
+ )
306
+ .option(`--staging`, 'If true, will use the staging programs')
307
+ .option(`--multisig <string>`, 'If using multisig mode this is required, otherwise will be ignored')
308
+ .action(async ({ vault, field, value, mode, staging, multisig }) => {
309
+ const env = initializeClient(mode === 'multisig', staging);
310
+ const vaultAddress = new PublicKey(vault);
311
+
312
+ if (mode === 'multisig' && !multisig) {
313
+ throw new Error('If using multisig mode, multisig is required');
314
+ }
315
+
316
+ const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
317
+
318
+ const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kVaultProgramId);
319
+ const instructions = await kaminoManager.updateVaultConfigIxs(kaminoVault, field, value);
320
+
321
+ const updateVaultPendingAdminSig = await processTxn(
322
+ env.client,
323
+ env.payer,
324
+ [instructions.updateVaultConfigIx, ...instructions.updateLUTIxs],
325
+ mode,
326
+ 2500,
327
+ []
328
+ );
329
+
330
+ mode === 'execute' && console.log('Pending admin updated:', updateVaultPendingAdminSig);
331
+ });
332
+
296
333
  commands
297
334
  .command('update-vault-mgmt-fee')
298
335
  .requiredOption('--vault <string>', 'Vault address')
@@ -796,8 +833,8 @@ async function main() {
796
833
  const vaultState = await new KaminoVault(vaultAddress, undefined, env.kVaultProgramId).getState(env.connection);
797
834
  const vaultOverview = await kaminoManager.getVaultOverview(
798
835
  vaultState,
799
- await env.connection.getSlot('confirmed'),
800
- new Decimal(1.0)
836
+ new Decimal(1.0),
837
+ await env.connection.getSlot('confirmed')
801
838
  );
802
839
 
803
840
  console.log('vaultOverview', vaultOverview);
@@ -890,8 +927,11 @@ async function main() {
890
927
  const sharesIssued = new Decimal(vaultState.sharesIssued.toString()!).div(
891
928
  new Decimal(vaultState.sharesMintDecimals.toString())
892
929
  );
930
+
931
+ console.log('farm', vaultState.vaultFarm.toString());
932
+ console.log('Name: ', kaminoManager.getDecodedVaultName(kaminoVault.state!));
893
933
  console.log('Shares issued: ', sharesIssued);
894
- console.log('Holdings: ', holdings);
934
+ printHoldings(holdings);
895
935
  console.log(`Tokens per share for vault ${vaultAddress.toBase58()}: ${tokensPerShare}`);
896
936
  });
897
937
 
@@ -937,7 +977,6 @@ async function main() {
937
977
  const simulatedHoldings = await kaminoManager.calculateSimulatedHoldingsWithInterest(vaultState);
938
978
 
939
979
  console.log('Simulated holdings with interest', simulatedHoldings);
940
-
941
980
  const simulatedFees = await kaminoManager.calculateSimulatedFees(vaultState, simulatedHoldings);
942
981
 
943
982
  console.log('Simulated fees', simulatedFees);
@@ -1,2 +1,3 @@
1
1
  export * from './repay_with_collateral_operations';
2
+ export * from './swap_collateral_operations';
2
3
  export * from './repay_with_collateral_calcs';
@@ -3,8 +3,8 @@ import {
3
3
  getFlashLoanInstructions,
4
4
  SwapInputs,
5
5
  SwapQuote,
6
- SwapQuoteIxs,
7
- SwapQuoteIxsProvider,
6
+ SwapIxs,
7
+ SwapIxsProvider,
8
8
  SwapQuoteProvider,
9
9
  } from '../leverage';
10
10
  import {
@@ -23,10 +23,10 @@ export type RepayWithCollIxsResponse<QuoteResponse> = {
23
23
  ixs: TransactionInstruction[];
24
24
  lookupTables: AddressLookupTableAccount[];
25
25
  swapInputs: SwapInputs;
26
- initialInputs: InitialInputs<QuoteResponse>;
26
+ initialInputs: RepayWithCollInitialInputs<QuoteResponse>;
27
27
  };
28
28
 
29
- export type InitialInputs<QuoteResponse> = {
29
+ export type RepayWithCollInitialInputs<QuoteResponse> = {
30
30
  debtRepayAmountLamports: Decimal;
31
31
  flashRepayAmountLamports: Decimal;
32
32
  /**
@@ -69,15 +69,15 @@ export async function getRepayWithCollSwapInputs<QuoteResponse>({
69
69
  scopeRefresh,
70
70
  }: RepayWithCollSwapInputsProps<QuoteResponse>): Promise<{
71
71
  swapInputs: SwapInputs;
72
- initialInputs: InitialInputs<QuoteResponse>;
72
+ initialInputs: RepayWithCollInitialInputs<QuoteResponse>;
73
73
  }> {
74
74
  const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
75
75
  const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
76
76
  if (!collReserve) {
77
- throw new Error(`Collateral reserve with mint ${collReserve} not found in market ${kaminoMarket.getAddress()}`);
77
+ throw new Error(`Collateral reserve with mint ${collTokenMint} not found in market ${kaminoMarket.getAddress()}`);
78
78
  }
79
79
  if (!debtReserve) {
80
- throw new Error(`Debt reserve with mint ${debtReserve} not found in market ${kaminoMarket.getAddress()}`);
80
+ throw new Error(`Debt reserve with mint ${debtTokenMint} not found in market ${kaminoMarket.getAddress()}`);
81
81
  }
82
82
 
83
83
  const {
@@ -172,7 +172,7 @@ export async function getRepayWithCollSwapInputs<QuoteResponse>({
172
172
  }
173
173
 
174
174
  interface RepayWithCollIxsProps<QuoteResponse> extends RepayWithCollSwapInputsProps<QuoteResponse> {
175
- swapper: SwapQuoteIxsProvider<QuoteResponse>;
175
+ swapper: SwapIxsProvider<QuoteResponse>;
176
176
  logger?: (msg: string, ...extra: any[]) => void;
177
177
  }
178
178
 
@@ -263,7 +263,7 @@ async function buildRepayWithCollateralIxs(
263
263
  currentSlot: number,
264
264
  budgetAndPriorityFeeIxs: TransactionInstruction[] | undefined,
265
265
  scopeRefresh: ScopeRefresh | undefined,
266
- swapQuoteIxs: SwapQuoteIxs,
266
+ swapQuoteIxs: SwapIxs,
267
267
  isClosingPosition: boolean,
268
268
  debtRepayAmountLamports: Decimal,
269
269
  collWithdrawLamports: Decimal
@@ -288,6 +288,7 @@ async function buildRepayWithCollateralIxs(
288
288
  reserve: debtReserve,
289
289
  amountLamports: debtRepayAmountLamports,
290
290
  destinationAta: debtTokenAta,
291
+ // TODO(referrals): once we support referrals, we will have to replace the placeholder args below:
291
292
  referrerAccount: market.programId,
292
293
  referrerTokenState: market.programId,
293
294
  programId: market.programId,