@kamino-finance/klend-sdk 6.0.2 → 6.0.4

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.
@@ -3,7 +3,9 @@ import { Command } from 'commander';
3
3
  import { Address, address, IInstruction } from '@solana/kit';
4
4
  import {
5
5
  AssetReserveConfigCli,
6
+ calculateAPYFromAPR,
6
7
  createLookupTableIx,
8
+ DEFAULT_PUBLIC_KEY,
7
9
  DEFAULT_RECENT_SLOT_DURATION_MS,
8
10
  encodeTokenName,
9
11
  extendLookupTableIxs,
@@ -12,6 +14,7 @@ import {
12
14
  initLookupTableIx,
13
15
  KaminoManager,
14
16
  KaminoMarket,
17
+ KaminoReserve,
15
18
  KaminoVault,
16
19
  KaminoVaultConfig,
17
20
  lamportsToDecimal,
@@ -45,7 +48,7 @@ import { fetchMint, findAssociatedTokenPda } from '@solana-program/token-2022';
45
48
  import { initEnv, ManagerEnv } from './tx/ManagerEnv';
46
49
  import { processTx } from './tx/processor';
47
50
  import { getPriorityFeeAndCuIxs } from '../client/tx/priorityFee';
48
- import { fetchAddressLookupTable } from '@solana-program/address-lookup-table';
51
+ import { fetchAddressLookupTable, fetchAllAddressLookupTable } from '@solana-program/address-lookup-table';
49
52
 
50
53
  dotenv.config({
51
54
  path: `.env${process.env.ENV ? '.' + process.env.ENV : ''}`,
@@ -317,7 +320,7 @@ async function main() {
317
320
  throw new Error('If using multisig mode, multisig is required');
318
321
  }
319
322
  const ms = multisig ? address(multisig) : undefined;
320
- const env = await initEnv(ms, staging);
323
+ const env = await initEnv(staging, ms);
321
324
  const tokenMint = address(mint);
322
325
 
323
326
  const kaminoManager = new KaminoManager(
@@ -406,7 +409,7 @@ async function main() {
406
409
  env.klendProgramId,
407
410
  env.kvaultProgramId
408
411
  );
409
- const vaultState = await vault.getState(env.c.rpc);
412
+ const vaultState = await kVault.getState(env.c.rpc);
410
413
  const signer = await env.getSigner({ vaultState });
411
414
  const ix = await kaminoManager.getSetSharesMetadataIx(signer, kVault, symbol, extraName);
412
415
 
@@ -494,7 +497,7 @@ async function main() {
494
497
  );
495
498
 
496
499
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
497
- const vaultState = await vault.getState(env.c.rpc);
500
+ const vaultState = await kaminoVault.getState(env.c.rpc);
498
501
  const signer = await env.getSigner({ vaultState });
499
502
 
500
503
  const instructions = await kaminoManager.updateVaultConfigIxs(kaminoVault, field, value, signer);
@@ -537,7 +540,7 @@ async function main() {
537
540
  );
538
541
 
539
542
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
540
- const vaultState = await vault.getState(env.c.rpc);
543
+ const vaultState = await kaminoVault.getState(env.c.rpc);
541
544
  const signer = await env.getSigner({ vaultState });
542
545
  const instructions = await kaminoManager.updateVaultConfigIxs(
543
546
  kaminoVault,
@@ -649,7 +652,7 @@ async function main() {
649
652
  );
650
653
 
651
654
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
652
- const vaultState = await vault.getState(env.c.rpc);
655
+ const vaultState = await kaminoVault.getState(env.c.rpc);
653
656
  const signer = await env.getSigner({ vaultState });
654
657
  const syncLUTIxs = await kaminoManager.syncVaultLUTIxs(signer, kaminoVault);
655
658
 
@@ -709,7 +712,7 @@ async function main() {
709
712
  );
710
713
 
711
714
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
712
- const vaultState = await vault.getState(env.c.rpc);
715
+ const vaultState = await kaminoVault.getState(env.c.rpc);
713
716
  const signer = await env.getSigner({ vaultState });
714
717
  const instructions = await kaminoManager.updateVaultConfigIxs(
715
718
  kaminoVault,
@@ -755,7 +758,7 @@ async function main() {
755
758
  );
756
759
 
757
760
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
758
- const vaultState = await vault.getState(env.c.rpc);
761
+ const vaultState = await kaminoVault.getState(env.c.rpc);
759
762
  const pendingAdmin = await env.getSigner({
760
763
  vaultState,
761
764
  useVaultPendingAdmin: true,
@@ -833,7 +836,7 @@ async function main() {
833
836
  );
834
837
 
835
838
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
836
- const vaultState = await vault.getState(env.c.rpc);
839
+ const vaultState = await kaminoVault.getState(env.c.rpc);
837
840
  const signer = await env.getSigner({ vaultState });
838
841
  const instruction = await kaminoManager.giveUpPendingFeesIx(kaminoVault, new Decimal(maxAmountToGiveUp), signer);
839
842
 
@@ -873,7 +876,7 @@ async function main() {
873
876
  );
874
877
 
875
878
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
876
- const vaultState = await vault.getState(env.c.rpc);
879
+ const vaultState = await kaminoVault.getState(env.c.rpc);
877
880
  const signer = await env.getSigner({ vaultState });
878
881
 
879
882
  const instructions = await kaminoManager.withdrawPendingFeesIxs(
@@ -920,27 +923,27 @@ async function main() {
920
923
  );
921
924
 
922
925
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
923
- const vaultState = await vault.getState(env.c.rpc);
926
+ const vaultState = await kaminoVault.getState(env.c.rpc);
924
927
  const signer = await env.getSigner({ vaultState });
925
- const instruction = await kaminoManager.removeReserveFromAllocationIx(kaminoVault, reserveAddress, signer);
926
928
 
927
- if (instruction) {
928
- await processTx(
929
- env.c,
930
- signer,
931
- [
932
- instruction,
933
- ...getPriorityFeeAndCuIxs({
934
- priorityFeeMultiplier: 2500,
935
- }),
936
- ],
937
- mode,
938
- []
939
- );
940
- mode === 'execute' && console.log('Vault allocation updated');
941
- } else {
942
- console.log('No updates to vault allocation to perform');
929
+ const ixs = await kaminoManager.fullRemoveReserveFromVaultIxs(signer, kaminoVault, reserveAddress);
930
+
931
+ const transactionIxs = [
932
+ ...ixs,
933
+ ...getPriorityFeeAndCuIxs({
934
+ priorityFeeMultiplier: 2500,
935
+ computeUnits: 1_000_000,
936
+ }),
937
+ ];
938
+
939
+ const lookupTableAddresses = [];
940
+ if (vaultState.vaultLookupTable !== DEFAULT_PUBLIC_KEY) {
941
+ lookupTableAddresses.push(vaultState.vaultLookupTable);
943
942
  }
943
+ const lookupTables = await fetchAllAddressLookupTable(env.c.rpc, lookupTableAddresses);
944
+
945
+ await processTx(env.c, signer, transactionIxs, mode, lookupTables);
946
+ mode === 'execute' && console.log('Vault allocation removed');
944
947
  });
945
948
 
946
949
  commands
@@ -1342,12 +1345,7 @@ async function main() {
1342
1345
  const env = await initEnv(staging);
1343
1346
  const slotDuration = await getMedianSlotDurationInMsFromLastEpochs();
1344
1347
 
1345
- const kaminoManager = new KaminoManager(
1346
- env.c.rpc,
1347
- slotDuration,
1348
- address('KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD'),
1349
- env.kvaultProgramId
1350
- );
1348
+ const kaminoManager = new KaminoManager(env.c.rpc, slotDuration, env.klendProgramId, env.kvaultProgramId);
1351
1349
 
1352
1350
  const farmAPY = await kaminoManager.getReserveFarmRewardsAPY(address(reserve), new Decimal(tokenPrice));
1353
1351
  console.log('farmAPY', farmAPY);
@@ -1471,6 +1469,37 @@ async function main() {
1471
1469
  }
1472
1470
  });
1473
1471
 
1472
+ commands
1473
+ .command('simulate-reserve-apy')
1474
+ .requiredOption('--reserve <string>', 'Reserve address')
1475
+ .action(async ({ reserve }) => {
1476
+ const env = await initEnv();
1477
+
1478
+ const reserveState = await Reserve.fetch(env.c.rpc, address(reserve), env.klendProgramId);
1479
+ if (!reserveState) {
1480
+ throw new Error('Reserve not found');
1481
+ }
1482
+
1483
+ const kaminoReserve = await KaminoReserve.initializeFromAddress(
1484
+ address(reserve),
1485
+ env.c.rpc,
1486
+ DEFAULT_RECENT_SLOT_DURATION_MS,
1487
+ reserveState
1488
+ );
1489
+
1490
+ const slot = await env.c.rpc.getSlot({ commitment: 'confirmed' }).send();
1491
+ const amount = new Decimal(0);
1492
+ const simulatedApr = kaminoReserve.calcSimulatedSupplyAPR(amount, 'deposit', slot, 0);
1493
+ console.log('simulated apr', simulatedApr);
1494
+ const apy = calculateAPYFromAPR(simulatedApr);
1495
+ console.log('simulated apy', apy);
1496
+
1497
+ const computedAPR = kaminoReserve.calculateSupplyAPR(slot, 0);
1498
+ console.log('computed apr', computedAPR);
1499
+ const computedAPY = kaminoReserve.totalSupplyAPY(slot);
1500
+ console.log('computed apy', computedAPY);
1501
+ });
1502
+
1474
1503
  commands
1475
1504
  .command('get-oracle-mappings')
1476
1505
  .option(`--staging`, 'If true, will use the staging programs')