@kamino-finance/klend-sdk 7.1.9 → 7.2.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.
@@ -20,7 +20,6 @@ import {
20
20
  lamportsToDecimal,
21
21
  LendingMarket,
22
22
  parseZeroPaddedUtf8,
23
- printHoldings,
24
23
  Reserve,
25
24
  ReserveAllocationConfig,
26
25
  ReserveWithAddress,
@@ -49,6 +48,7 @@ import { initEnv, ManagerEnv } from './tx/ManagerEnv';
49
48
  import { processTx } from './tx/processor';
50
49
  import { getPriorityFeeAndCuIxs } from '../client/tx/priorityFee';
51
50
  import { fetchAddressLookupTable, fetchAllAddressLookupTable } from '@solana-program/address-lookup-table';
51
+ import { noopSigner } from '../utils/signer';
52
52
 
53
53
  dotenv.config({
54
54
  path: `.env${process.env.ENV ? '.' + process.env.ENV : ''}`,
@@ -401,7 +401,7 @@ async function main() {
401
401
  .option(`--staging`, 'If true, will use the staging programs')
402
402
  .action(async ({ vault, mode, symbol, extraName, staging }) => {
403
403
  const env = await initEnv(undefined, staging);
404
- const kVault = new KaminoVault(address(vault));
404
+ const kVault = new KaminoVault(env.c.rpc, address(vault));
405
405
 
406
406
  const kaminoManager = new KaminoManager(
407
407
  env.c.rpc,
@@ -409,7 +409,7 @@ async function main() {
409
409
  env.klendProgramId,
410
410
  env.kvaultProgramId
411
411
  );
412
- const vaultState = await kVault.getState(env.c.rpc);
412
+ const vaultState = await kVault.getState();
413
413
  const signer = await env.getSigner({ vaultState });
414
414
  const ix = await kaminoManager.getSetSharesMetadataIx(signer, kVault, symbol, extraName);
415
415
 
@@ -447,8 +447,8 @@ async function main() {
447
447
  env.kvaultProgramId
448
448
  );
449
449
 
450
- const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
451
- const vaultState = await kaminoVault.getState(env.c.rpc);
450
+ const kaminoVault = new KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
451
+ const vaultState = await kaminoVault.getState();
452
452
  const signer = await env.getSigner({ vaultState });
453
453
 
454
454
  const instructions = await kaminoManager.updateVaultConfigIxs(
@@ -496,8 +496,8 @@ async function main() {
496
496
  env.kvaultProgramId
497
497
  );
498
498
 
499
- const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
500
- const vaultState = await kaminoVault.getState(env.c.rpc);
499
+ const kaminoVault = new KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
500
+ const vaultState = await kaminoVault.getState();
501
501
  const signer = await env.getSigner({ vaultState });
502
502
 
503
503
  const instructions = await kaminoManager.updateVaultConfigIxs(kaminoVault, field, value, signer);
@@ -539,8 +539,8 @@ async function main() {
539
539
  env.kvaultProgramId
540
540
  );
541
541
 
542
- const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
543
- const vaultState = await kaminoVault.getState(env.c.rpc);
542
+ const kaminoVault = new KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
543
+ const vaultState = await kaminoVault.getState();
544
544
  const signer = await env.getSigner({ vaultState });
545
545
  const instructions = await kaminoManager.updateVaultConfigIxs(
546
546
  kaminoVault,
@@ -651,8 +651,8 @@ async function main() {
651
651
  env.kvaultProgramId
652
652
  );
653
653
 
654
- const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
655
- const vaultState = await kaminoVault.getState(env.c.rpc);
654
+ const kaminoVault = new KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
655
+ const vaultState = await kaminoVault.getState();
656
656
  const signer = await env.getSigner({ vaultState });
657
657
  const syncLUTIxs = await kaminoManager.syncVaultLUTIxs(signer, kaminoVault);
658
658
 
@@ -711,8 +711,8 @@ async function main() {
711
711
  env.kvaultProgramId
712
712
  );
713
713
 
714
- const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
715
- const vaultState = await kaminoVault.getState(env.c.rpc);
714
+ const kaminoVault = new KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
715
+ const vaultState = await kaminoVault.getState();
716
716
  const signer = await env.getSigner({ vaultState });
717
717
  const instructions = await kaminoManager.updateVaultConfigIxs(
718
718
  kaminoVault,
@@ -757,8 +757,8 @@ async function main() {
757
757
  env.kvaultProgramId
758
758
  );
759
759
 
760
- const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
761
- const vaultState = await kaminoVault.getState(env.c.rpc);
760
+ const kaminoVault = new KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
761
+ const vaultState = await kaminoVault.getState();
762
762
  const pendingAdmin = await env.getSigner({
763
763
  vaultState,
764
764
  useVaultPendingAdmin: true,
@@ -835,8 +835,8 @@ async function main() {
835
835
  env.kvaultProgramId
836
836
  );
837
837
 
838
- const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
839
- const vaultState = await kaminoVault.getState(env.c.rpc);
838
+ const kaminoVault = new KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
839
+ const vaultState = await kaminoVault.getState();
840
840
  const signer = await env.getSigner({ vaultState });
841
841
  const instruction = await kaminoManager.giveUpPendingFeesIx(kaminoVault, new Decimal(maxAmountToGiveUp), signer);
842
842
 
@@ -875,8 +875,8 @@ async function main() {
875
875
  env.kvaultProgramId
876
876
  );
877
877
 
878
- const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
879
- const vaultState = await kaminoVault.getState(env.c.rpc);
878
+ const kaminoVault = new KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
879
+ const vaultState = await kaminoVault.getState();
880
880
  const signer = await env.getSigner({ vaultState });
881
881
 
882
882
  const instructions = await kaminoManager.withdrawPendingFeesIxs(
@@ -922,8 +922,8 @@ async function main() {
922
922
  env.kvaultProgramId
923
923
  );
924
924
 
925
- const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
926
- const vaultState = await kaminoVault.getState(env.c.rpc);
925
+ const kaminoVault = new KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
926
+ const vaultState = await kaminoVault.getState();
927
927
  const signer = await env.getSigner({ vaultState });
928
928
 
929
929
  const ixs = await kaminoManager.fullRemoveReserveFromVaultIxs(signer, kaminoVault, reserveAddress);
@@ -964,7 +964,7 @@ async function main() {
964
964
  const user = await env.getSigner();
965
965
  const vaultAddress = address(vault);
966
966
 
967
- const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
967
+ const kaminoVault = new KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
968
968
 
969
969
  const stakeIxs = await new KaminoManager(
970
970
  env.c.rpc,
@@ -1008,8 +1008,8 @@ async function main() {
1008
1008
  const env = await initEnv(staging, ms);
1009
1009
  const reserveAddress = address(reserve);
1010
1010
  const vaultAddress = address(vault);
1011
- const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
1012
- const vaultState = await kaminoVault.getState(env.c.rpc);
1011
+ const kaminoVault = new KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
1012
+ const vaultState = await kaminoVault.getState();
1013
1013
  const signer = await env.getSigner({ vaultState });
1014
1014
  const allocationWeightValue = Number(allocationWeight);
1015
1015
  const allocationCapDecimal = new Decimal(allocationCap);
@@ -1081,7 +1081,7 @@ async function main() {
1081
1081
  env.kvaultProgramId
1082
1082
  );
1083
1083
 
1084
- const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
1084
+ const kaminoVault = new KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
1085
1085
  const payer = await env.getSigner();
1086
1086
  const depositInstructions = await kaminoManager.depositToVaultIxs(payer, kaminoVault, amount);
1087
1087
  const instructions = [...depositInstructions.depositIxs, ...depositInstructions.stakeInFarmIfNeededIxs];
@@ -1128,7 +1128,13 @@ async function main() {
1128
1128
  env.kvaultProgramId
1129
1129
  );
1130
1130
 
1131
- const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
1131
+ const kaminoVault = new KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
1132
+ const vaultState = await kaminoVault.getState();
1133
+ const lookupTableAddresses = [];
1134
+ if (vaultState.vaultLookupTable !== DEFAULT_PUBLIC_KEY) {
1135
+ lookupTableAddresses.push(vaultState.vaultLookupTable);
1136
+ }
1137
+ const lookupTables = await fetchAllAddressLookupTable(env.c.rpc, lookupTableAddresses);
1132
1138
  const withdrawIxs = await kaminoManager.withdrawFromVaultIxs(
1133
1139
  signer,
1134
1140
  kaminoVault,
@@ -1149,7 +1155,7 @@ async function main() {
1149
1155
  }),
1150
1156
  ],
1151
1157
  mode,
1152
- []
1158
+ lookupTables
1153
1159
  );
1154
1160
 
1155
1161
  mode === 'execute' && console.log('User withdrew');
@@ -1180,7 +1186,7 @@ async function main() {
1180
1186
  env.kvaultProgramId
1181
1187
  );
1182
1188
 
1183
- const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
1189
+ const kaminoVault = new KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
1184
1190
  const instructions = await kaminoManager.investAllReservesIxs(payer, kaminoVault);
1185
1191
 
1186
1192
  for (let i = 0; i < instructions.length; i++) {
@@ -1228,7 +1234,8 @@ async function main() {
1228
1234
  env.kvaultProgramId
1229
1235
  );
1230
1236
 
1231
- const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
1237
+ const kaminoVault = new KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
1238
+
1232
1239
  const reserveAddress = address(reserve);
1233
1240
  const reserveState = await Reserve.fetch(env.c.rpc, reserveAddress, env.klendProgramId);
1234
1241
  if (!reserveState) {
@@ -1286,7 +1293,7 @@ async function main() {
1286
1293
  const kaminoManager = new KaminoManager(env.c.rpc, slotDuration, env.klendProgramId, env.kvaultProgramId);
1287
1294
 
1288
1295
  const vaultAddress = address(vault);
1289
- const vaultState = await new KaminoVault(vaultAddress, undefined, env.kvaultProgramId).getState(env.c.rpc);
1296
+ const vaultState = await new KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId).getState();
1290
1297
  const vaultCollaterals = await kaminoManager.getVaultCollaterals(
1291
1298
  vaultState,
1292
1299
  await env.c.rpc.getSlot({ commitment: 'confirmed' }).send()
@@ -1311,9 +1318,9 @@ async function main() {
1311
1318
  const kaminoManager = new KaminoManager(env.c.rpc, slotDuration, env.klendProgramId, env.kvaultProgramId);
1312
1319
 
1313
1320
  const vaultAddress = address(vault);
1314
- const vaultState = await new KaminoVault(vaultAddress, undefined, env.kvaultProgramId).getState(env.c.rpc);
1321
+ const kaminoVault = new KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId);
1315
1322
  const vaultOverview = await kaminoManager.getVaultOverview(
1316
- vaultState,
1323
+ kaminoVault,
1317
1324
  new Decimal(tokenPrice),
1318
1325
  await env.c.rpc.getSlot({ commitment: 'confirmed' }).send()
1319
1326
  );
@@ -1336,7 +1343,7 @@ async function main() {
1336
1343
 
1337
1344
  const kaminoManager = new KaminoManager(env.c.rpc, slotDuration, env.klendProgramId, env.kvaultProgramId);
1338
1345
 
1339
- const kaminoVault = new KaminoVault(address(vault));
1346
+ const kaminoVault = new KaminoVault(env.c.rpc, address(vault), undefined, env.kvaultProgramId, slotDuration);
1340
1347
  const farmAPY = await kaminoManager.getVaultFarmRewardsAPY(kaminoVault, new Decimal(tokenPrice));
1341
1348
  console.log('farmAPY', farmAPY);
1342
1349
  });
@@ -1367,7 +1374,7 @@ async function main() {
1367
1374
  const kaminoManager = new KaminoManager(env.c.rpc, slotDuration, env.klendProgramId, env.kvaultProgramId);
1368
1375
 
1369
1376
  const vaultAddress = address(vault);
1370
- const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
1377
+ const kaminoVault = new KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId, slotDuration);
1371
1378
 
1372
1379
  const allVaultsTokenMints = await kaminoManager.getAllVaultsTokenMintsIncludingRewards([kaminoVault]);
1373
1380
  console.log('allVaultsTokenMints', allVaultsTokenMints);
@@ -1384,7 +1391,13 @@ async function main() {
1384
1391
  const kaminoManager = new KaminoManager(env.c.rpc, slotDuration, env.klendProgramId, env.kvaultProgramId);
1385
1392
 
1386
1393
  const vaultAddress = address(vault);
1387
- const vaultState = await new KaminoVault(vaultAddress, undefined, env.kvaultProgramId).getState(env.c.rpc);
1394
+ const vaultState = await new KaminoVault(
1395
+ env.c.rpc,
1396
+ vaultAddress,
1397
+ undefined,
1398
+ env.kvaultProgramId,
1399
+ slotDuration
1400
+ ).getState();
1388
1401
  const allocationDistribution = kaminoManager.getAllocationsDistribuionPct(vaultState);
1389
1402
 
1390
1403
  allocationDistribution.forEach((allocation, reserveAddress) => {
@@ -1406,7 +1419,7 @@ async function main() {
1406
1419
 
1407
1420
  const vaultAddress = address(vault);
1408
1421
  const walletAddress = address(wallet);
1409
- const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
1422
+ const kaminoVault = new KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId, slotDuration);
1410
1423
  const userShares = await kaminoManager.getUserSharesBalanceSingleVault(walletAddress, kaminoVault);
1411
1424
  console.log(
1412
1425
  `User shares for vault ${vaultAddress}: unstaked shares: ${userShares.unstakedShares} staked shares: ${userShares.stakedShares} total shares: ${userShares.totalShares}`
@@ -1445,7 +1458,7 @@ async function main() {
1445
1458
  const kaminoManager = new KaminoManager(env.c.rpc, slotDuration, env.klendProgramId, env.kvaultProgramId);
1446
1459
 
1447
1460
  const vaultAddress = address(vault);
1448
- const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
1461
+ const kaminoVault = new KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId, slotDuration);
1449
1462
  const tokensPerShare = await kaminoManager.getTokensPerShareSingleVault(
1450
1463
  kaminoVault,
1451
1464
  await env.c.rpc.getSlot({ commitment: 'confirmed' }).send()
@@ -1464,26 +1477,25 @@ async function main() {
1464
1477
  const kaminoManager = new KaminoManager(env.c.rpc, slotDuration, env.klendProgramId, env.kvaultProgramId);
1465
1478
 
1466
1479
  const vaultAddress = address(vault);
1467
- const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kvaultProgramId);
1468
- await kaminoVault.getState(env.c.rpc);
1480
+ const kaminoVault = new KaminoVault(env.c.rpc, vaultAddress, undefined, env.kvaultProgramId, slotDuration);
1481
+ const vaultState = await kaminoVault.getState();
1469
1482
 
1470
1483
  const slot = await env.c.rpc.getSlot({ commitment: 'confirmed' }).send();
1471
1484
  const tokensPerShare = await kaminoManager.getTokensPerShareSingleVault(kaminoVault, slot);
1472
1485
  const holdings = await kaminoManager.getVaultHoldings(kaminoVault.state!, slot);
1473
- const vaultState = kaminoVault.state!;
1474
1486
 
1475
1487
  const sharesIssued = lamportsToDecimal(
1476
1488
  vaultState.sharesIssued.toString(),
1477
1489
  vaultState.sharesMintDecimals.toString()
1478
1490
  );
1479
1491
 
1480
- const vaultOverview = await kaminoManager.getVaultOverview(vaultState, new Decimal(1.0), slot);
1492
+ const vaultOverview = await kaminoManager.getVaultOverview(kaminoVault, new Decimal(1.0), slot);
1481
1493
 
1482
1494
  console.log('farm', vaultState.vaultFarm.toString());
1483
1495
  console.log('vault token mint', vaultState.tokenMint);
1484
1496
  console.log('Name: ', kaminoManager.getDecodedVaultName(kaminoVault.state!));
1485
1497
  console.log('Shares issued: ', sharesIssued);
1486
- printHoldings(holdings);
1498
+ holdings.print();
1487
1499
  console.log(`Tokens per share for vault ${vaultAddress}: ${tokensPerShare}`);
1488
1500
  console.log('vaultOverview', vaultOverview);
1489
1501
 
@@ -1607,7 +1619,13 @@ async function main() {
1607
1619
  const slotDuration = await getMedianSlotDurationInMsFromLastEpochs();
1608
1620
 
1609
1621
  const kaminoManager = new KaminoManager(env.c.rpc, slotDuration, env.klendProgramId, env.kvaultProgramId);
1610
- const vaultState = await new KaminoVault(vaultAddress, undefined, env.kvaultProgramId).getState(env.c.rpc);
1622
+ const vaultState = await new KaminoVault(
1623
+ env.c.rpc,
1624
+ vaultAddress,
1625
+ undefined,
1626
+ env.kvaultProgramId,
1627
+ slotDuration
1628
+ ).getState();
1611
1629
 
1612
1630
  const simulatedHoldings = await kaminoManager.calculateSimulatedHoldingsWithInterest(vaultState);
1613
1631
 
@@ -1651,7 +1669,13 @@ async function main() {
1651
1669
  const slotDuration = await getMedianSlotDurationInMsFromLastEpochs();
1652
1670
 
1653
1671
  const kaminoManager = new KaminoManager(env.c.rpc, slotDuration, env.klendProgramId, env.kvaultProgramId);
1654
- const vaultState = await new KaminoVault(vaultAddress, undefined, env.kvaultProgramId).getState(env.c.rpc);
1672
+ const vaultState = await new KaminoVault(
1673
+ env.c.rpc,
1674
+ vaultAddress,
1675
+ undefined,
1676
+ env.kvaultProgramId,
1677
+ slotDuration
1678
+ ).getState();
1655
1679
 
1656
1680
  const computedAllocation = await kaminoManager.getVaultComputedReservesAllocation(vaultState);
1657
1681
  console.log('computedAllocation', computedAllocation);
@@ -1969,6 +1993,47 @@ async function main() {
1969
1993
  console.log(adminInfo);
1970
1994
  });
1971
1995
 
1996
+ commands
1997
+ .command('claim-rewards-for-vault')
1998
+ .requiredOption('--vault <string>', 'Vault address')
1999
+ .requiredOption(
2000
+ `--mode <string>`,
2001
+ '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'
2002
+ )
2003
+ .option(`--staging`, 'If true, will use the staging programs')
2004
+ .option(`--user <string>`, 'User address')
2005
+ .action(async ({ vault, mode, staging, user }) => {
2006
+ const env = await initEnv(staging);
2007
+ const vaultAddress = address(vault);
2008
+ const kaminoVault = new KaminoVault(env.c.rpc, vaultAddress);
2009
+ const kaminoManager = new KaminoManager(
2010
+ env.c.rpc,
2011
+ DEFAULT_RECENT_SLOT_DURATION_MS,
2012
+ env.klendProgramId,
2013
+ env.kvaultProgramId
2014
+ );
2015
+ const userWallet = user ? noopSigner(address(user)) : await env.getSigner();
2016
+ const rewardsIxs = await kaminoManager.getClaimAllRewardsForVaultIxs(userWallet, kaminoVault);
2017
+
2018
+ if (rewardsIxs.length > 0) {
2019
+ await processTx(
2020
+ env.c,
2021
+ userWallet,
2022
+ [
2023
+ ...rewardsIxs,
2024
+ ...getPriorityFeeAndCuIxs({
2025
+ priorityFeeMultiplier: 2500,
2026
+ computeUnits: 400_000,
2027
+ }),
2028
+ ],
2029
+ mode,
2030
+ []
2031
+ );
2032
+ } else {
2033
+ console.log('No rewards to claim');
2034
+ }
2035
+ });
2036
+
1972
2037
  await commands.parseAsync();
1973
2038
  }
1974
2039
 
@@ -20,7 +20,6 @@ export async function getReserveFarmRewardsAPY(
20
20
  farmsClient: Farms,
21
21
  slot: Slot,
22
22
  reserveState?: Reserve,
23
- cTokenMintDecimals?: number,
24
23
  tokensPrices?: Map<Address, Decimal>
25
24
  ): Promise<ReserveIncentives> {
26
25
  const reserveIncentives: ReserveIncentives = {