@kamino-finance/klend-sdk 7.1.10 → 7.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53,6 +53,7 @@ const ManagerEnv_1 = require("./tx/ManagerEnv");
53
53
  const processor_1 = require("./tx/processor");
54
54
  const priorityFee_1 = require("../client/tx/priorityFee");
55
55
  const address_lookup_table_1 = require("@solana-program/address-lookup-table");
56
+ const signer_1 = require("../utils/signer");
56
57
  dotenv_1.default.config({
57
58
  path: `.env${process.env.ENV ? '.' + process.env.ENV : ''}`,
58
59
  });
@@ -258,9 +259,9 @@ async function main() {
258
259
  .option(`--staging`, 'If true, will use the staging programs')
259
260
  .action(async ({ vault, mode, symbol, extraName, staging }) => {
260
261
  const env = await (0, ManagerEnv_1.initEnv)(undefined, staging);
261
- const kVault = new lib_1.KaminoVault((0, kit_1.address)(vault));
262
+ const kVault = new lib_1.KaminoVault(env.c.rpc, (0, kit_1.address)(vault));
262
263
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, lib_1.DEFAULT_RECENT_SLOT_DURATION_MS, env.klendProgramId, env.kvaultProgramId);
263
- const vaultState = await kVault.getState(env.c.rpc);
264
+ const vaultState = await kVault.getState();
264
265
  const signer = await env.getSigner({ vaultState });
265
266
  const ix = await kaminoManager.getSetSharesMetadataIx(signer, kVault, symbol, extraName);
266
267
  await (0, processor_1.processTx)(env.c, signer, [
@@ -280,8 +281,8 @@ async function main() {
280
281
  const env = await (0, ManagerEnv_1.initEnv)(staging);
281
282
  const vaultAddress = (0, kit_1.address)(vault);
282
283
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, lib_1.DEFAULT_RECENT_SLOT_DURATION_MS, env.klendProgramId, env.kvaultProgramId);
283
- const kaminoVault = new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
284
- const vaultState = await kaminoVault.getState(env.c.rpc);
284
+ const kaminoVault = new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
285
+ const vaultState = await kaminoVault.getState();
285
286
  const signer = await env.getSigner({ vaultState });
286
287
  const instructions = await kaminoManager.updateVaultConfigIxs(kaminoVault, new VaultConfigField_1.PendingVaultAdmin(), newAdmin, signer);
287
288
  await (0, processor_1.processTx)(env.c, signer, [
@@ -304,8 +305,8 @@ async function main() {
304
305
  const env = await (0, ManagerEnv_1.initEnv)(staging);
305
306
  const vaultAddress = (0, kit_1.address)(vault);
306
307
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, lib_1.DEFAULT_RECENT_SLOT_DURATION_MS, env.klendProgramId, env.kvaultProgramId);
307
- const kaminoVault = new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
308
- const vaultState = await kaminoVault.getState(env.c.rpc);
308
+ const kaminoVault = new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
309
+ const vaultState = await kaminoVault.getState();
309
310
  const signer = await env.getSigner({ vaultState });
310
311
  const instructions = await kaminoManager.updateVaultConfigIxs(kaminoVault, field, value, signer);
311
312
  await (0, processor_1.processTx)(env.c, signer, [
@@ -327,8 +328,8 @@ async function main() {
327
328
  const env = await (0, ManagerEnv_1.initEnv)(staging);
328
329
  const vaultAddress = (0, kit_1.address)(vault);
329
330
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, lib_1.DEFAULT_RECENT_SLOT_DURATION_MS, env.klendProgramId, env.kvaultProgramId);
330
- const kaminoVault = new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
331
- const vaultState = await kaminoVault.getState(env.c.rpc);
331
+ const kaminoVault = new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
332
+ const vaultState = await kaminoVault.getState();
332
333
  const signer = await env.getSigner({ vaultState });
333
334
  const instructions = await kaminoManager.updateVaultConfigIxs(kaminoVault, new VaultConfigField_1.ManagementFeeBps(), feeBps, signer);
334
335
  await (0, processor_1.processTx)(env.c, signer, [
@@ -386,8 +387,8 @@ async function main() {
386
387
  const env = await (0, ManagerEnv_1.initEnv)(staging);
387
388
  const vaultAddress = (0, kit_1.address)(vault);
388
389
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, lib_1.DEFAULT_RECENT_SLOT_DURATION_MS, env.klendProgramId, env.kvaultProgramId);
389
- const kaminoVault = new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
390
- const vaultState = await kaminoVault.getState(env.c.rpc);
390
+ const kaminoVault = new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
391
+ const vaultState = await kaminoVault.getState();
391
392
  const signer = await env.getSigner({ vaultState });
392
393
  const syncLUTIxs = await kaminoManager.syncVaultLUTIxs(signer, kaminoVault);
393
394
  // if we need to create the LUT we have to do that in a separate tx and wait a little bit after
@@ -422,8 +423,8 @@ async function main() {
422
423
  const env = await (0, ManagerEnv_1.initEnv)(staging);
423
424
  const vaultAddress = (0, kit_1.address)(vault);
424
425
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, lib_1.DEFAULT_RECENT_SLOT_DURATION_MS, env.klendProgramId, env.kvaultProgramId);
425
- const kaminoVault = new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
426
- const vaultState = await kaminoVault.getState(env.c.rpc);
426
+ const kaminoVault = new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
427
+ const vaultState = await kaminoVault.getState();
427
428
  const signer = await env.getSigner({ vaultState });
428
429
  const instructions = await kaminoManager.updateVaultConfigIxs(kaminoVault, new VaultConfigField_1.PerformanceFeeBps(), feeBps, signer);
429
430
  await (0, processor_1.processTx)(env.c, signer, [
@@ -444,8 +445,8 @@ async function main() {
444
445
  const env = await (0, ManagerEnv_1.initEnv)(staging);
445
446
  const vaultAddress = (0, kit_1.address)(vault);
446
447
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, lib_1.DEFAULT_RECENT_SLOT_DURATION_MS, env.klendProgramId, env.kvaultProgramId);
447
- const kaminoVault = new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
448
- const vaultState = await kaminoVault.getState(env.c.rpc);
448
+ const kaminoVault = new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
449
+ const vaultState = await kaminoVault.getState();
449
450
  const pendingAdmin = await env.getSigner({
450
451
  vaultState,
451
452
  useVaultPendingAdmin: true,
@@ -488,8 +489,8 @@ async function main() {
488
489
  const env = await (0, ManagerEnv_1.initEnv)(multisig, staging);
489
490
  const vaultAddress = (0, kit_1.address)(vault);
490
491
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, lib_1.DEFAULT_RECENT_SLOT_DURATION_MS, env.klendProgramId, env.kvaultProgramId);
491
- const kaminoVault = new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
492
- const vaultState = await kaminoVault.getState(env.c.rpc);
492
+ const kaminoVault = new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
493
+ const vaultState = await kaminoVault.getState();
493
494
  const signer = await env.getSigner({ vaultState });
494
495
  const instruction = await kaminoManager.giveUpPendingFeesIx(kaminoVault, new decimal_js_1.default(maxAmountToGiveUp), signer);
495
496
  await (0, processor_1.processTx)(env.c, signer, [
@@ -509,8 +510,8 @@ async function main() {
509
510
  const env = await (0, ManagerEnv_1.initEnv)(staging);
510
511
  const vaultAddress = (0, kit_1.address)(vault);
511
512
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, lib_1.DEFAULT_RECENT_SLOT_DURATION_MS, env.klendProgramId, env.kvaultProgramId);
512
- const kaminoVault = new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
513
- const vaultState = await kaminoVault.getState(env.c.rpc);
513
+ const kaminoVault = new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
514
+ const vaultState = await kaminoVault.getState();
514
515
  const signer = await env.getSigner({ vaultState });
515
516
  const instructions = await kaminoManager.withdrawPendingFeesIxs(kaminoVault, await env.c.rpc.getSlot({ commitment: 'confirmed' }).send(), signer);
516
517
  await (0, processor_1.processTx)(env.c, signer, [
@@ -532,8 +533,8 @@ async function main() {
532
533
  const reserveAddress = (0, kit_1.address)(reserve);
533
534
  const vaultAddress = (0, kit_1.address)(vault);
534
535
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, lib_1.DEFAULT_RECENT_SLOT_DURATION_MS, env.klendProgramId, env.kvaultProgramId);
535
- const kaminoVault = new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
536
- const vaultState = await kaminoVault.getState(env.c.rpc);
536
+ const kaminoVault = new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
537
+ const vaultState = await kaminoVault.getState();
537
538
  const signer = await env.getSigner({ vaultState });
538
539
  const ixs = await kaminoManager.fullRemoveReserveFromVaultIxs(signer, kaminoVault, reserveAddress);
539
540
  const transactionIxs = [
@@ -565,7 +566,7 @@ async function main() {
565
566
  const env = await (0, ManagerEnv_1.initEnv)(staging, ms);
566
567
  const user = await env.getSigner();
567
568
  const vaultAddress = (0, kit_1.address)(vault);
568
- const kaminoVault = new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
569
+ const kaminoVault = new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
569
570
  const stakeIxs = await new lib_1.KaminoManager(env.c.rpc, lib_1.DEFAULT_RECENT_SLOT_DURATION_MS, env.klendProgramId, env.kvaultProgramId).stakeSharesIxs(user, kaminoVault);
570
571
  await (0, processor_1.processTx)(env.c, user, [
571
572
  ...stakeIxs,
@@ -579,12 +580,13 @@ async function main() {
579
580
  .command('update-vault-reserve-allocation')
580
581
  .requiredOption('--vault <string>', 'Vault address')
581
582
  .requiredOption('--reserve <string>', 'Reserve address')
582
- .requiredOption('--allocation-weight <number>', 'Allocation weight')
583
- .requiredOption('--allocation-cap <string>', 'Allocation cap decimal value')
584
583
  .requiredOption(`--mode <string>`, 'simulate|multisig|execute - simulate - to print txn simulation and to get tx simulation link in explorer, execute - execute tx, multisig - to get bs58 tx for multisig usage')
584
+ .option('--allocation-weight <number>', 'Allocation weight')
585
+ .option('--allocation-cap <string>', 'Allocation cap decimal value')
585
586
  .option(`--staging`, 'If true, will use the staging programs')
586
587
  .option(`--multisig <string>`, 'If using multisig mode this is required, otherwise will be ignored')
587
- .action(async ({ vault, reserve, allocationWeight, allocationCap, mode, staging, multisig }) => {
588
+ .option(`--skip-lut-update`, 'If set, it will skip the LUT update')
589
+ .action(async ({ vault, reserve, mode, allocationWeight, allocationCap, staging, multisig, skipLutUpdate }) => {
588
590
  if (mode === 'multisig' && !multisig) {
589
591
  throw new Error('If using multisig mode, multisig is required');
590
592
  }
@@ -592,29 +594,55 @@ async function main() {
592
594
  const env = await (0, ManagerEnv_1.initEnv)(staging, ms);
593
595
  const reserveAddress = (0, kit_1.address)(reserve);
594
596
  const vaultAddress = (0, kit_1.address)(vault);
595
- const kaminoVault = new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
596
- const vaultState = await kaminoVault.getState(env.c.rpc);
597
+ const kaminoVault = new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
598
+ const vaultState = await kaminoVault.getState();
597
599
  const signer = await env.getSigner({ vaultState });
598
- const allocationWeightValue = Number(allocationWeight);
599
- const allocationCapDecimal = new decimal_js_1.default(allocationCap);
600
+ const shouldUpdateLut = skipLutUpdate ? false : true;
601
+ let allocationWeightValue;
602
+ let allocationCapDecimal;
600
603
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, lib_1.DEFAULT_RECENT_SLOT_DURATION_MS, env.klendProgramId, env.kvaultProgramId);
601
604
  const reserveState = await lib_1.Reserve.fetch(env.c.rpc, reserveAddress, env.klendProgramId);
602
605
  if (!reserveState) {
603
606
  throw new Error('Reserve not found');
604
607
  }
608
+ const existentAllocation = kaminoManager.getVaultAllocations(vaultState).get(reserveAddress);
609
+ if (allocationWeight) {
610
+ allocationWeightValue = Number(allocationWeight);
611
+ }
612
+ else if (existentAllocation) {
613
+ allocationWeightValue = existentAllocation.targetWeight.toNumber();
614
+ }
615
+ else {
616
+ throw new Error('Allocation weight is required');
617
+ }
618
+ if (allocationCap) {
619
+ allocationCapDecimal = new decimal_js_1.default(allocationCap);
620
+ }
621
+ else if (existentAllocation) {
622
+ allocationCapDecimal = existentAllocation.tokenAllocationCap.div(new decimal_js_1.default(10).pow(Number(vaultState.tokenMintDecimals.toString())));
623
+ }
624
+ else {
625
+ throw new Error('Allocation cap is required');
626
+ }
627
+ console.log('allocationWeightValue', allocationWeightValue);
628
+ console.log('allocationCapDecimal', allocationCapDecimal.toString());
605
629
  const reserveWithAddress = {
606
630
  address: reserveAddress,
607
631
  state: reserveState,
608
632
  };
609
633
  const firstReserveAllocationConfig = new lib_1.ReserveAllocationConfig(reserveWithAddress, allocationWeightValue, allocationCapDecimal);
610
634
  const instructions = await kaminoManager.updateVaultReserveAllocationIxs(kaminoVault, firstReserveAllocationConfig, signer);
611
- await (0, processor_1.processTx)(env.c, signer, [
635
+ const txInstructions = [
612
636
  instructions.updateReserveAllocationIx,
613
637
  ...instructions.updateLUTIxs,
614
638
  ...(0, priorityFee_1.getPriorityFeeAndCuIxs)({
615
639
  priorityFeeMultiplier: 2500,
616
640
  }),
617
- ], mode, []);
641
+ ];
642
+ if (shouldUpdateLut) {
643
+ txInstructions.push(...instructions.updateLUTIxs);
644
+ }
645
+ await (0, processor_1.processTx)(env.c, signer, txInstructions, mode, []);
618
646
  mode === 'execute' && console.log('Vault allocation updated');
619
647
  });
620
648
  commands
@@ -631,7 +659,7 @@ async function main() {
631
659
  const env = await (0, ManagerEnv_1.initEnv)(staging, multisig);
632
660
  const vaultAddress = (0, kit_1.address)(vault);
633
661
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, lib_1.DEFAULT_RECENT_SLOT_DURATION_MS, env.klendProgramId, env.kvaultProgramId);
634
- const kaminoVault = new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
662
+ const kaminoVault = new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
635
663
  const payer = await env.getSigner();
636
664
  const depositInstructions = await kaminoManager.depositToVaultIxs(payer, kaminoVault, amount);
637
665
  const instructions = [...depositInstructions.depositIxs, ...depositInstructions.stakeInFarmIfNeededIxs];
@@ -659,8 +687,8 @@ async function main() {
659
687
  const signer = await env.getSigner();
660
688
  const vaultAddress = (0, kit_1.address)(vault);
661
689
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, lib_1.DEFAULT_RECENT_SLOT_DURATION_MS, env.klendProgramId, env.kvaultProgramId);
662
- const kaminoVault = new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
663
- const vaultState = await kaminoVault.getState(env.c.rpc);
690
+ const kaminoVault = new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
691
+ const vaultState = await kaminoVault.getState();
664
692
  const lookupTableAddresses = [];
665
693
  if (vaultState.vaultLookupTable !== lib_1.DEFAULT_PUBLIC_KEY) {
666
694
  lookupTableAddresses.push(vaultState.vaultLookupTable);
@@ -693,7 +721,7 @@ async function main() {
693
721
  const payer = await env.getSigner();
694
722
  const vaultAddress = (0, kit_1.address)(vault);
695
723
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, lib_1.DEFAULT_RECENT_SLOT_DURATION_MS, env.klendProgramId, env.kvaultProgramId);
696
- const kaminoVault = new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
724
+ const kaminoVault = new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
697
725
  const instructions = await kaminoManager.investAllReservesIxs(payer, kaminoVault);
698
726
  for (let i = 0; i < instructions.length; i++) {
699
727
  const txInstructions = [];
@@ -723,7 +751,7 @@ async function main() {
723
751
  const env = await (0, ManagerEnv_1.initEnv)(staging, ms);
724
752
  const vaultAddress = (0, kit_1.address)(vault);
725
753
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, lib_1.DEFAULT_RECENT_SLOT_DURATION_MS, env.klendProgramId, env.kvaultProgramId);
726
- const kaminoVault = new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
754
+ const kaminoVault = new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
727
755
  const reserveAddress = (0, kit_1.address)(reserve);
728
756
  const reserveState = await lib_1.Reserve.fetch(env.c.rpc, reserveAddress, env.klendProgramId);
729
757
  if (!reserveState) {
@@ -766,7 +794,7 @@ async function main() {
766
794
  const slotDuration = await (0, lib_1.getMedianSlotDurationInMsFromLastEpochs)();
767
795
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, slotDuration, env.klendProgramId, env.kvaultProgramId);
768
796
  const vaultAddress = (0, kit_1.address)(vault);
769
- const vaultState = await new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId).getState(env.c.rpc);
797
+ const vaultState = await new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId).getState();
770
798
  const vaultCollaterals = await kaminoManager.getVaultCollaterals(vaultState, await env.c.rpc.getSlot({ commitment: 'confirmed' }).send());
771
799
  vaultCollaterals.forEach((collateral) => {
772
800
  console.log('reserve ', collateral.address);
@@ -785,8 +813,8 @@ async function main() {
785
813
  const slotDuration = await (0, lib_1.getMedianSlotDurationInMsFromLastEpochs)();
786
814
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, slotDuration, env.klendProgramId, env.kvaultProgramId);
787
815
  const vaultAddress = (0, kit_1.address)(vault);
788
- const vaultState = await new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId).getState(env.c.rpc);
789
- const vaultOverview = await kaminoManager.getVaultOverview(vaultState, new decimal_js_1.default(tokenPrice), await env.c.rpc.getSlot({ commitment: 'confirmed' }).send());
816
+ const kaminoVault = new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
817
+ const vaultOverview = await kaminoManager.getVaultOverview(kaminoVault, new decimal_js_1.default(tokenPrice), await env.c.rpc.getSlot({ commitment: 'confirmed' }).send());
790
818
  console.log('vaultOverview', vaultOverview);
791
819
  vaultOverview.reservesFarmsIncentives.reserveFarmsIncentives.forEach((incentive, reserveAddress) => {
792
820
  console.log('reserve ', reserveAddress);
@@ -802,7 +830,7 @@ async function main() {
802
830
  const env = await (0, ManagerEnv_1.initEnv)(staging);
803
831
  const slotDuration = await (0, lib_1.getMedianSlotDurationInMsFromLastEpochs)();
804
832
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, slotDuration, env.klendProgramId, env.kvaultProgramId);
805
- const kaminoVault = new lib_1.KaminoVault((0, kit_1.address)(vault));
833
+ const kaminoVault = new lib_1.KaminoVault(env.c.rpc, (0, kit_1.address)(vault), undefined, env.kvaultProgramId, slotDuration);
806
834
  const farmAPY = await kaminoManager.getVaultFarmRewardsAPY(kaminoVault, new decimal_js_1.default(tokenPrice));
807
835
  console.log('farmAPY', farmAPY);
808
836
  });
@@ -827,7 +855,7 @@ async function main() {
827
855
  const slotDuration = await (0, lib_1.getMedianSlotDurationInMsFromLastEpochs)();
828
856
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, slotDuration, env.klendProgramId, env.kvaultProgramId);
829
857
  const vaultAddress = (0, kit_1.address)(vault);
830
- const kaminoVault = new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
858
+ const kaminoVault = new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId, slotDuration);
831
859
  const allVaultsTokenMints = await kaminoManager.getAllVaultsTokenMintsIncludingRewards([kaminoVault]);
832
860
  console.log('allVaultsTokenMints', allVaultsTokenMints);
833
861
  });
@@ -840,7 +868,7 @@ async function main() {
840
868
  const slotDuration = await (0, lib_1.getMedianSlotDurationInMsFromLastEpochs)();
841
869
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, slotDuration, env.klendProgramId, env.kvaultProgramId);
842
870
  const vaultAddress = (0, kit_1.address)(vault);
843
- const vaultState = await new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId).getState(env.c.rpc);
871
+ const vaultState = await new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId, slotDuration).getState();
844
872
  const allocationDistribution = kaminoManager.getAllocationsDistribuionPct(vaultState);
845
873
  allocationDistribution.forEach((allocation, reserveAddress) => {
846
874
  console.log('reserve ', reserveAddress);
@@ -858,7 +886,7 @@ async function main() {
858
886
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, slotDuration, env.klendProgramId, env.kvaultProgramId);
859
887
  const vaultAddress = (0, kit_1.address)(vault);
860
888
  const walletAddress = (0, kit_1.address)(wallet);
861
- const kaminoVault = new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
889
+ const kaminoVault = new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId, slotDuration);
862
890
  const userShares = await kaminoManager.getUserSharesBalanceSingleVault(walletAddress, kaminoVault);
863
891
  console.log(`User shares for vault ${vaultAddress}: unstaked shares: ${userShares.unstakedShares} staked shares: ${userShares.stakedShares} total shares: ${userShares.totalShares}`);
864
892
  });
@@ -886,7 +914,7 @@ async function main() {
886
914
  const slotDuration = await (0, lib_1.getMedianSlotDurationInMsFromLastEpochs)();
887
915
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, slotDuration, env.klendProgramId, env.kvaultProgramId);
888
916
  const vaultAddress = (0, kit_1.address)(vault);
889
- const kaminoVault = new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
917
+ const kaminoVault = new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId, slotDuration);
890
918
  const tokensPerShare = await kaminoManager.getTokensPerShareSingleVault(kaminoVault, await env.c.rpc.getSlot({ commitment: 'confirmed' }).send());
891
919
  console.log(`Tokens per share for vault ${vaultAddress.toBase58()}: ${tokensPerShare}`);
892
920
  });
@@ -899,19 +927,18 @@ async function main() {
899
927
  const slotDuration = await (0, lib_1.getMedianSlotDurationInMsFromLastEpochs)();
900
928
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, slotDuration, env.klendProgramId, env.kvaultProgramId);
901
929
  const vaultAddress = (0, kit_1.address)(vault);
902
- const kaminoVault = new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
903
- await kaminoVault.getState(env.c.rpc);
930
+ const kaminoVault = new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId, slotDuration);
931
+ const vaultState = await kaminoVault.getState();
904
932
  const slot = await env.c.rpc.getSlot({ commitment: 'confirmed' }).send();
905
933
  const tokensPerShare = await kaminoManager.getTokensPerShareSingleVault(kaminoVault, slot);
906
934
  const holdings = await kaminoManager.getVaultHoldings(kaminoVault.state, slot);
907
- const vaultState = kaminoVault.state;
908
935
  const sharesIssued = (0, lib_1.lamportsToDecimal)(vaultState.sharesIssued.toString(), vaultState.sharesMintDecimals.toString());
909
- const vaultOverview = await kaminoManager.getVaultOverview(vaultState, new decimal_js_1.default(1.0), slot);
936
+ const vaultOverview = await kaminoManager.getVaultOverview(kaminoVault, new decimal_js_1.default(1.0), slot);
910
937
  console.log('farm', vaultState.vaultFarm.toString());
911
938
  console.log('vault token mint', vaultState.tokenMint);
912
939
  console.log('Name: ', kaminoManager.getDecodedVaultName(kaminoVault.state));
913
940
  console.log('Shares issued: ', sharesIssued);
914
- (0, lib_1.printHoldings)(holdings);
941
+ holdings.print();
915
942
  console.log(`Tokens per share for vault ${vaultAddress}: ${tokensPerShare}`);
916
943
  console.log('vaultOverview', vaultOverview);
917
944
  for (const [reserveAddress, reserveOverview] of vaultOverview.reservesOverview) {
@@ -995,7 +1022,7 @@ async function main() {
995
1022
  const vaultAddress = (0, kit_1.address)(vault);
996
1023
  const slotDuration = await (0, lib_1.getMedianSlotDurationInMsFromLastEpochs)();
997
1024
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, slotDuration, env.klendProgramId, env.kvaultProgramId);
998
- const vaultState = await new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId).getState(env.c.rpc);
1025
+ const vaultState = await new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId, slotDuration).getState();
999
1026
  const simulatedHoldings = await kaminoManager.calculateSimulatedHoldingsWithInterest(vaultState);
1000
1027
  console.log('Simulated holdings with interest', simulatedHoldings);
1001
1028
  const simulatedFees = await kaminoManager.calculateSimulatedFees(vaultState, simulatedHoldings);
@@ -1025,7 +1052,7 @@ async function main() {
1025
1052
  const vaultAddress = (0, kit_1.address)(vault);
1026
1053
  const slotDuration = await (0, lib_1.getMedianSlotDurationInMsFromLastEpochs)();
1027
1054
  const kaminoManager = new lib_1.KaminoManager(env.c.rpc, slotDuration, env.klendProgramId, env.kvaultProgramId);
1028
- const vaultState = await new lib_1.KaminoVault(vaultAddress, undefined, env.kvaultProgramId).getState(env.c.rpc);
1055
+ const vaultState = await new lib_1.KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId, slotDuration).getState();
1029
1056
  const computedAllocation = await kaminoManager.getVaultComputedReservesAllocation(vaultState);
1030
1057
  console.log('computedAllocation', computedAllocation);
1031
1058
  });
@@ -1207,6 +1234,32 @@ async function main() {
1207
1234
  const adminInfo = await lib_1.KaminoManager.getMarketOrVaultAdminInfo(env.c.rpc, (0, kit_1.address)(addr));
1208
1235
  console.log(adminInfo);
1209
1236
  });
1237
+ commands
1238
+ .command('claim-rewards-for-vault')
1239
+ .requiredOption('--vault <string>', 'Vault address')
1240
+ .requiredOption(`--mode <string>`, 'simulate|multisig|execute - simulate - to print txn simulation and to get tx simulation link in explorer, execute - execute tx, multisig - to get bs58 tx for multisig usage')
1241
+ .option(`--staging`, 'If true, will use the staging programs')
1242
+ .option(`--user <string>`, 'User address')
1243
+ .action(async ({ vault, mode, staging, user }) => {
1244
+ const env = await (0, ManagerEnv_1.initEnv)(staging);
1245
+ const vaultAddress = (0, kit_1.address)(vault);
1246
+ const kaminoVault = new lib_1.KaminoVault(env.c.rpc, vaultAddress);
1247
+ const kaminoManager = new lib_1.KaminoManager(env.c.rpc, lib_1.DEFAULT_RECENT_SLOT_DURATION_MS, env.klendProgramId, env.kvaultProgramId);
1248
+ const userWallet = user ? (0, signer_1.noopSigner)((0, kit_1.address)(user)) : await env.getSigner();
1249
+ const rewardsIxs = await kaminoManager.getClaimAllRewardsForVaultIxs(userWallet, kaminoVault);
1250
+ if (rewardsIxs.length > 0) {
1251
+ await (0, processor_1.processTx)(env.c, userWallet, [
1252
+ ...rewardsIxs,
1253
+ ...(0, priorityFee_1.getPriorityFeeAndCuIxs)({
1254
+ priorityFeeMultiplier: 2500,
1255
+ computeUnits: 400_000,
1256
+ }),
1257
+ ], mode, []);
1258
+ }
1259
+ else {
1260
+ console.log('No rewards to claim');
1261
+ }
1262
+ });
1210
1263
  await commands.parseAsync();
1211
1264
  }
1212
1265
  main()