@kamino-finance/klend-sdk 5.14.2 → 5.14.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.
Files changed (67) hide show
  1. package/dist/classes/configItems.d.ts +166 -0
  2. package/dist/classes/configItems.d.ts.map +1 -0
  3. package/dist/classes/configItems.js +202 -0
  4. package/dist/classes/configItems.js.map +1 -0
  5. package/dist/classes/manager.d.ts +4 -7
  6. package/dist/classes/manager.d.ts.map +1 -1
  7. package/dist/classes/manager.js +35 -292
  8. package/dist/classes/manager.js.map +1 -1
  9. package/dist/classes/market.d.ts.map +1 -1
  10. package/dist/classes/market.js +1 -1
  11. package/dist/classes/market.js.map +1 -1
  12. package/dist/classes/reserve.d.ts +5 -14
  13. package/dist/classes/reserve.d.ts.map +1 -1
  14. package/dist/classes/reserve.js +88 -463
  15. package/dist/classes/reserve.js.map +1 -1
  16. package/dist/classes/utils.d.ts +1 -0
  17. package/dist/classes/utils.d.ts.map +1 -1
  18. package/dist/classes/utils.js +12 -0
  19. package/dist/classes/utils.js.map +1 -1
  20. package/dist/classes/vault.d.ts.map +1 -1
  21. package/dist/classes/vault.js +7 -0
  22. package/dist/classes/vault.js.map +1 -1
  23. package/dist/classes/vault_types.d.ts +1 -0
  24. package/dist/classes/vault_types.d.ts.map +1 -1
  25. package/dist/client_kamino_manager.d.ts.map +1 -1
  26. package/dist/client_kamino_manager.js +4 -1
  27. package/dist/client_kamino_manager.js.map +1 -1
  28. package/dist/lending_operations/repay_with_collateral_operations.d.ts +2 -1
  29. package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
  30. package/dist/lending_operations/repay_with_collateral_operations.js +13 -9
  31. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  32. package/dist/lending_operations/swap_collateral_operations.d.ts +1 -1
  33. package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
  34. package/dist/lending_operations/swap_collateral_operations.js +34 -30
  35. package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
  36. package/dist/leverage/operations.d.ts +4 -4
  37. package/dist/leverage/operations.d.ts.map +1 -1
  38. package/dist/leverage/operations.js +91 -55
  39. package/dist/leverage/operations.js.map +1 -1
  40. package/dist/leverage/types.d.ts +8 -6
  41. package/dist/leverage/types.d.ts.map +1 -1
  42. package/dist/leverage/utils.d.ts.map +1 -1
  43. package/dist/leverage/utils.js +40 -19
  44. package/dist/leverage/utils.js.map +1 -1
  45. package/dist/utils/instruction.d.ts +3 -1
  46. package/dist/utils/instruction.d.ts.map +1 -1
  47. package/dist/utils/instruction.js +17 -1
  48. package/dist/utils/instruction.js.map +1 -1
  49. package/dist/utils/managerTypes.d.ts.map +1 -1
  50. package/dist/utils/managerTypes.js +9 -3
  51. package/dist/utils/managerTypes.js.map +1 -1
  52. package/package.json +1 -1
  53. package/src/classes/configItems.ts +295 -0
  54. package/src/classes/manager.ts +47 -392
  55. package/src/classes/market.ts +6 -1
  56. package/src/classes/reserve.ts +115 -783
  57. package/src/classes/utils.ts +12 -0
  58. package/src/classes/vault.ts +15 -1
  59. package/src/classes/vault_types.ts +1 -0
  60. package/src/client_kamino_manager.ts +5 -1
  61. package/src/lending_operations/repay_with_collateral_operations.ts +34 -26
  62. package/src/lending_operations/swap_collateral_operations.ts +43 -36
  63. package/src/leverage/operations.ts +175 -147
  64. package/src/leverage/types.ts +8 -6
  65. package/src/leverage/utils.ts +41 -20
  66. package/src/utils/instruction.ts +28 -0
  67. package/src/utils/managerTypes.ts +9 -3
@@ -28,7 +28,6 @@ import {
28
28
  } from './vault';
29
29
  import {
30
30
  AddAssetToMarketParams,
31
- assertNever,
32
31
  CreateKaminoMarketParams,
33
32
  createReserveIxs,
34
33
  ENV,
@@ -45,7 +44,6 @@ import {
45
44
  KaminoReserve,
46
45
  LendingMarket,
47
46
  lendingMarketAuthPda,
48
- LendingMarketFields,
49
47
  MarketWithAddress,
50
48
  parseForChangesReserveConfigAndGetIxs,
51
49
  parseOracleType,
@@ -53,7 +51,6 @@ import {
53
51
  PubkeyHashMap,
54
52
  Reserve,
55
53
  ReserveWithAddress,
56
- sameLengthArrayEquals,
57
54
  ScopeOracleConfig,
58
55
  updateEntireReserveConfigIx,
59
56
  updateLendingMarket,
@@ -65,12 +62,7 @@ import {
65
62
  import { PROGRAM_ID } from '../idl_codegen/programId';
66
63
  import { Scope, TokenMetadatas, U16_MAX } from '@kamino-finance/scope-sdk';
67
64
  import BN from 'bn.js';
68
- import {
69
- ElevationGroup,
70
- ReserveConfig,
71
- UpdateLendingMarketMode,
72
- UpdateLendingMarketModeKind,
73
- } from '../idl_codegen/types';
65
+ import { ReserveConfig, UpdateLendingMarketMode, UpdateLendingMarketModeKind } from '../idl_codegen/types';
74
66
  import Decimal from 'decimal.js';
75
67
  import * as anchor from '@coral-xyz/anchor';
76
68
  import { VaultState } from '../idl_codegen_kamino_vault/accounts';
@@ -96,6 +88,7 @@ import { FarmState } from '@kamino-finance/farms-sdk/dist';
96
88
  import SwitchboardProgram from '@switchboard-xyz/sbv2-lite';
97
89
  import { getSquadsMultisigAdminsAndThreshold, walletIsSquadsMultisig, WalletType } from '../utils/multisig';
98
90
  import { decodeVaultState } from '../utils/vault';
91
+ import { arrayElementConfigItems, ConfigUpdater } from './configItems';
99
92
 
100
93
  /**
101
94
  * KaminoManager is a class that provides a high-level interface to interact with the Kamino Lend and Kamino Vault programs, in order to create and manage a market, as well as vaults
@@ -391,7 +384,15 @@ export class KaminoManager {
391
384
  const ixs: TransactionInstruction[] = [];
392
385
 
393
386
  if (!reserveState || updateEntireConfig) {
394
- ixs.push(updateEntireReserveConfigIx(marketWithAddress, reserve, config, this._kaminoLendProgramId));
387
+ ixs.push(
388
+ updateEntireReserveConfigIx(
389
+ marketWithAddress.state.lendingMarketOwner,
390
+ marketWithAddress.address,
391
+ reserve,
392
+ config,
393
+ this._kaminoLendProgramId
394
+ )
395
+ );
395
396
  } else {
396
397
  ixs.push(
397
398
  ...parseForChangesReserveConfigAndGetIxs(
@@ -1269,383 +1270,49 @@ export class KaminoManager {
1269
1270
  };
1270
1271
  }
1271
1272
  } // KaminoManager
1272
- export type BaseLendingMarketKey = keyof LendingMarketFields;
1273
- const EXCLUDED_LENDING_MARKET_KEYS = [
1274
- 'version',
1275
- 'bumpSeed',
1276
- 'reserved0',
1277
- 'reserved1',
1278
- 'padding1',
1279
- 'padding2',
1280
- 'elevationGroupPadding',
1281
- 'quoteCurrency',
1282
- ] as const;
1283
- export type ExcludedLendingMarketKey = (typeof EXCLUDED_LENDING_MARKET_KEYS)[number];
1284
-
1285
- function isExcludedLendingMarketKey(value: unknown): value is ExcludedLendingMarketKey {
1286
- return EXCLUDED_LENDING_MARKET_KEYS.includes(value as ExcludedLendingMarketKey);
1287
- }
1288
1273
 
1289
- export type LendingMarketKey = Exclude<BaseLendingMarketKey, ExcludedLendingMarketKey>;
1290
-
1291
- const updateLendingMarketConfig = (
1292
- key: LendingMarketKey,
1293
- market: LendingMarket,
1294
- newMarket: LendingMarket
1295
- ): { mode: number; value: Buffer }[] => {
1296
- const updateLendingMarketIxsArgs: { mode: number; value: Buffer }[] = [];
1297
- switch (key) {
1298
- case 'lendingMarketOwner': {
1299
- if (!market.lendingMarketOwner.equals(newMarket.lendingMarketOwner)) {
1300
- updateLendingMarketIxsArgs.push({
1301
- mode: UpdateLendingMarketMode.UpdateOwner.discriminator,
1302
- value: updateMarketConfigEncodedValue(
1303
- UpdateLendingMarketMode.UpdateOwner.discriminator,
1304
- newMarket.lendingMarketOwner
1305
- ),
1306
- });
1307
- }
1308
- break;
1309
- }
1310
- case 'lendingMarketOwnerCached':
1311
- if (!market.lendingMarketOwnerCached.equals(newMarket.lendingMarketOwnerCached)) {
1312
- updateLendingMarketIxsArgs.push({
1313
- mode: UpdateLendingMarketMode.UpdateOwner.discriminator,
1314
- value: updateMarketConfigEncodedValue(
1315
- UpdateLendingMarketMode.UpdateOwner.discriminator,
1316
- newMarket.lendingMarketOwnerCached
1317
- ),
1318
- });
1319
- }
1320
- break;
1321
- case 'referralFeeBps':
1322
- if (market.referralFeeBps !== newMarket.referralFeeBps) {
1323
- updateLendingMarketIxsArgs.push({
1324
- mode: UpdateLendingMarketMode.UpdateReferralFeeBps.discriminator,
1325
- value: updateMarketConfigEncodedValue(
1326
- UpdateLendingMarketMode.UpdateReferralFeeBps.discriminator,
1327
- newMarket.referralFeeBps
1328
- ),
1329
- });
1330
- }
1331
- break;
1332
- case 'emergencyMode':
1333
- if (market.emergencyMode !== newMarket.emergencyMode) {
1334
- updateLendingMarketIxsArgs.push({
1335
- mode: UpdateLendingMarketMode.UpdateEmergencyMode.discriminator,
1336
- value: updateMarketConfigEncodedValue(
1337
- UpdateLendingMarketMode.UpdateEmergencyMode.discriminator,
1338
- newMarket.emergencyMode
1339
- ),
1340
- });
1341
- }
1342
- break;
1343
- case 'autodeleverageEnabled':
1344
- if (market.autodeleverageEnabled !== newMarket.autodeleverageEnabled) {
1345
- updateLendingMarketIxsArgs.push({
1346
- mode: UpdateLendingMarketMode.UpdateAutodeleverageEnabled.discriminator,
1347
- value: updateMarketConfigEncodedValue(
1348
- UpdateLendingMarketMode.UpdateAutodeleverageEnabled.discriminator,
1349
- newMarket.autodeleverageEnabled
1350
- ),
1351
- });
1352
- }
1353
- break;
1354
- case 'borrowDisabled':
1355
- if (market.borrowDisabled !== newMarket.borrowDisabled) {
1356
- updateLendingMarketIxsArgs.push({
1357
- mode: UpdateLendingMarketMode.UpdateBorrowingDisabled.discriminator,
1358
- value: updateMarketConfigEncodedValue(
1359
- UpdateLendingMarketMode.UpdateBorrowingDisabled.discriminator,
1360
- newMarket.borrowDisabled
1361
- ),
1362
- });
1363
- }
1364
- break;
1365
- case 'priceRefreshTriggerToMaxAgePct':
1366
- if (market.priceRefreshTriggerToMaxAgePct !== newMarket.priceRefreshTriggerToMaxAgePct) {
1367
- updateLendingMarketIxsArgs.push({
1368
- mode: UpdateLendingMarketMode.UpdatePriceRefreshTriggerToMaxAgePct.discriminator,
1369
- value: updateMarketConfigEncodedValue(
1370
- UpdateLendingMarketMode.UpdatePriceRefreshTriggerToMaxAgePct.discriminator,
1371
- newMarket.priceRefreshTriggerToMaxAgePct
1372
- ),
1373
- });
1374
- }
1375
- break;
1376
- case 'liquidationMaxDebtCloseFactorPct':
1377
- if (market.liquidationMaxDebtCloseFactorPct !== newMarket.liquidationMaxDebtCloseFactorPct) {
1378
- updateLendingMarketIxsArgs.push({
1379
- mode: UpdateLendingMarketMode.UpdateLiquidationCloseFactor.discriminator,
1380
- value: updateMarketConfigEncodedValue(
1381
- UpdateLendingMarketMode.UpdateLiquidationCloseFactor.discriminator,
1382
- newMarket.liquidationMaxDebtCloseFactorPct
1383
- ),
1384
- });
1385
- }
1386
- break;
1387
- case 'insolvencyRiskUnhealthyLtvPct':
1388
- if (market.insolvencyRiskUnhealthyLtvPct !== newMarket.insolvencyRiskUnhealthyLtvPct) {
1389
- updateLendingMarketIxsArgs.push({
1390
- mode: UpdateLendingMarketMode.UpdateInsolvencyRiskLtv.discriminator,
1391
- value: updateMarketConfigEncodedValue(
1392
- UpdateLendingMarketMode.UpdateInsolvencyRiskLtv.discriminator,
1393
- newMarket.insolvencyRiskUnhealthyLtvPct
1394
- ),
1395
- });
1396
- }
1397
- break;
1398
- case 'minFullLiquidationValueThreshold':
1399
- if (!market.minFullLiquidationValueThreshold.eq(newMarket.minFullLiquidationValueThreshold)) {
1400
- updateLendingMarketIxsArgs.push({
1401
- mode: UpdateLendingMarketMode.UpdateMinFullLiquidationThreshold.discriminator,
1402
- value: updateMarketConfigEncodedValue(
1403
- UpdateLendingMarketMode.UpdateMinFullLiquidationThreshold.discriminator,
1404
- newMarket.minFullLiquidationValueThreshold.toNumber()
1405
- ),
1406
- });
1407
- }
1408
- break;
1409
- case 'maxLiquidatableDebtMarketValueAtOnce':
1410
- if (!market.maxLiquidatableDebtMarketValueAtOnce.eq(newMarket.maxLiquidatableDebtMarketValueAtOnce)) {
1411
- updateLendingMarketIxsArgs.push({
1412
- mode: UpdateLendingMarketMode.UpdateLiquidationMaxValue.discriminator,
1413
- value: updateMarketConfigEncodedValue(
1414
- UpdateLendingMarketMode.UpdateLiquidationMaxValue.discriminator,
1415
- newMarket.maxLiquidatableDebtMarketValueAtOnce.toNumber()
1416
- ),
1417
- });
1418
- }
1419
- break;
1420
- case 'globalAllowedBorrowValue':
1421
- if (!market.globalAllowedBorrowValue.eq(newMarket.globalAllowedBorrowValue)) {
1422
- updateLendingMarketIxsArgs.push({
1423
- mode: UpdateLendingMarketMode.UpdateGlobalAllowedBorrow.discriminator,
1424
- value: updateMarketConfigEncodedValue(
1425
- UpdateLendingMarketMode.UpdateGlobalAllowedBorrow.discriminator,
1426
- newMarket.globalAllowedBorrowValue.toNumber()
1427
- ),
1428
- });
1429
- }
1430
- break;
1431
- case 'riskCouncil':
1432
- if (!market.riskCouncil.equals(newMarket.riskCouncil)) {
1433
- updateLendingMarketIxsArgs.push({
1434
- mode: UpdateLendingMarketMode.UpdateRiskCouncil.discriminator,
1435
- value: updateMarketConfigEncodedValue(
1436
- UpdateLendingMarketMode.UpdateRiskCouncil.discriminator,
1437
- newMarket.riskCouncil
1438
- ),
1439
- });
1440
- }
1441
- break;
1442
- case 'elevationGroups':
1443
- let elevationGroupsDiffs = 0;
1444
- for (let i = 0; i < market.elevationGroups.length; i++) {
1445
- if (
1446
- market.elevationGroups[i].id !== newMarket.elevationGroups[i].id ||
1447
- market.elevationGroups[i].maxLiquidationBonusBps !== newMarket.elevationGroups[i].maxLiquidationBonusBps ||
1448
- market.elevationGroups[i].ltvPct !== newMarket.elevationGroups[i].ltvPct ||
1449
- market.elevationGroups[i].liquidationThresholdPct !== newMarket.elevationGroups[i].liquidationThresholdPct ||
1450
- market.elevationGroups[i].allowNewLoans !== newMarket.elevationGroups[i].allowNewLoans ||
1451
- market.elevationGroups[i].maxReservesAsCollateral !== newMarket.elevationGroups[i].maxReservesAsCollateral ||
1452
- !market.elevationGroups[i].debtReserve.equals(newMarket.elevationGroups[i].debtReserve)
1453
- ) {
1454
- updateLendingMarketIxsArgs.push({
1455
- mode: UpdateLendingMarketMode.UpdateElevationGroup.discriminator,
1456
- value: updateMarketConfigEncodedValue(
1457
- UpdateLendingMarketMode.UpdateElevationGroup.discriminator,
1458
- newMarket.elevationGroups[i]
1459
- ),
1460
- });
1461
- elevationGroupsDiffs++;
1462
- }
1463
- }
1464
- if (elevationGroupsDiffs > 1) {
1465
- throw new Error('Can only update 1 elevation group at a time');
1466
- }
1467
- break;
1468
- case 'minNetValueInObligationSf':
1469
- if (!market.minNetValueInObligationSf.eq(newMarket.minNetValueInObligationSf)) {
1470
- updateLendingMarketIxsArgs.push({
1471
- mode: UpdateLendingMarketMode.UpdateMinNetValueObligationPostAction.discriminator,
1472
- value: updateMarketConfigEncodedValue(
1473
- UpdateLendingMarketMode.UpdateMinNetValueObligationPostAction.discriminator,
1474
- newMarket.minNetValueInObligationSf.toString()
1475
- ),
1476
- });
1477
- }
1478
- break;
1479
- case 'minValueSkipLiquidationBfChecks':
1480
- if (!market.minValueSkipLiquidationBfChecks.eq(newMarket.minValueSkipLiquidationBfChecks)) {
1481
- updateLendingMarketIxsArgs.push({
1482
- mode: UpdateLendingMarketMode.UpdateMinValueBfSkipPriorityLiqCheck.discriminator,
1483
- value: updateMarketConfigEncodedValue(
1484
- UpdateLendingMarketMode.UpdateMinValueBfSkipPriorityLiqCheck.discriminator,
1485
- newMarket.minValueSkipLiquidationBfChecks.toNumber()
1486
- ),
1487
- });
1488
- }
1489
- break;
1490
- case 'minValueSkipLiquidationLtvChecks':
1491
- if (!market.minValueSkipLiquidationLtvChecks.eq(newMarket.minValueSkipLiquidationLtvChecks)) {
1492
- updateLendingMarketIxsArgs.push({
1493
- mode: UpdateLendingMarketMode.UpdateMinValueLtvSkipPriorityLiqCheck.discriminator,
1494
- value: updateMarketConfigEncodedValue(
1495
- UpdateLendingMarketMode.UpdateMinValueLtvSkipPriorityLiqCheck.discriminator,
1496
- newMarket.minValueSkipLiquidationLtvChecks.toNumber()
1497
- ),
1498
- });
1499
- }
1500
- break;
1501
- case 'individualAutodeleverageMarginCallPeriodSecs':
1502
- if (
1503
- market.individualAutodeleverageMarginCallPeriodSecs !== newMarket.individualAutodeleverageMarginCallPeriodSecs
1504
- ) {
1505
- updateLendingMarketIxsArgs.push({
1506
- mode: UpdateLendingMarketMode.UpdateIndividualAutodeleverageMarginCallPeriodSecs.discriminator,
1507
- value: updateMarketConfigEncodedValue(
1508
- UpdateLendingMarketMode.UpdateIndividualAutodeleverageMarginCallPeriodSecs.discriminator,
1509
- newMarket.individualAutodeleverageMarginCallPeriodSecs.toNumber()
1510
- ),
1511
- });
1512
- }
1513
- break;
1514
- case 'name':
1515
- if (!sameLengthArrayEquals(market.name, newMarket.name)) {
1516
- updateLendingMarketIxsArgs.push({
1517
- mode: UpdateLendingMarketMode.UpdateName.discriminator,
1518
- value: updateMarketConfigEncodedValue(UpdateLendingMarketMode.UpdateName.discriminator, newMarket.name),
1519
- });
1520
- }
1521
- break;
1522
- case 'minInitialDepositAmount':
1523
- if (!market.minInitialDepositAmount.eq(newMarket.minInitialDepositAmount)) {
1524
- updateLendingMarketIxsArgs.push({
1525
- mode: UpdateLendingMarketMode.UpdateInitialDepositAmount.discriminator,
1526
- value: updateMarketConfigEncodedValue(
1527
- UpdateLendingMarketMode.UpdateInitialDepositAmount.discriminator,
1528
- newMarket.minInitialDepositAmount.toNumber()
1529
- ),
1530
- });
1531
- }
1532
- break;
1533
- case 'obligationOrdersEnabled':
1534
- if (market.obligationOrdersEnabled !== newMarket.obligationOrdersEnabled) {
1535
- updateLendingMarketIxsArgs.push({
1536
- mode: UpdateLendingMarketMode.UpdateObligationOrdersEnabled.discriminator,
1537
- value: updateMarketConfigEncodedValue(
1538
- UpdateLendingMarketMode.UpdateObligationOrdersEnabled.discriminator,
1539
- newMarket.obligationOrdersEnabled
1540
- ),
1541
- });
1542
- }
1543
- break;
1544
- default:
1545
- assertNever(key);
1546
- }
1547
- return updateLendingMarketIxsArgs;
1548
- };
1274
+ export const MARKET_UPDATER = new ConfigUpdater(UpdateLendingMarketMode.fromDecoded, LendingMarket, (config) => ({
1275
+ [UpdateLendingMarketMode.UpdateOwner.kind]: config.lendingMarketOwnerCached,
1276
+ [UpdateLendingMarketMode.UpdateEmergencyMode.kind]: config.emergencyMode,
1277
+ [UpdateLendingMarketMode.UpdateLiquidationCloseFactor.kind]: config.liquidationMaxDebtCloseFactorPct,
1278
+ [UpdateLendingMarketMode.UpdateLiquidationMaxValue.kind]: config.maxLiquidatableDebtMarketValueAtOnce,
1279
+ [UpdateLendingMarketMode.DeprecatedUpdateGlobalUnhealthyBorrow.kind]: [], // deprecated
1280
+ [UpdateLendingMarketMode.UpdateGlobalAllowedBorrow.kind]: config.globalAllowedBorrowValue,
1281
+ [UpdateLendingMarketMode.UpdateRiskCouncil.kind]: config.riskCouncil,
1282
+ [UpdateLendingMarketMode.UpdateMinFullLiquidationThreshold.kind]: config.minFullLiquidationValueThreshold,
1283
+ [UpdateLendingMarketMode.UpdateInsolvencyRiskLtv.kind]: config.insolvencyRiskUnhealthyLtvPct,
1284
+ [UpdateLendingMarketMode.UpdateElevationGroup.kind]: arrayElementConfigItems(config.elevationGroups),
1285
+ [UpdateLendingMarketMode.UpdateReferralFeeBps.kind]: config.referralFeeBps,
1286
+ [UpdateLendingMarketMode.DeprecatedUpdateMultiplierPoints.kind]: [], // deprecated
1287
+ [UpdateLendingMarketMode.UpdatePriceRefreshTriggerToMaxAgePct.kind]: config.priceRefreshTriggerToMaxAgePct,
1288
+ [UpdateLendingMarketMode.UpdateAutodeleverageEnabled.kind]: config.autodeleverageEnabled,
1289
+ [UpdateLendingMarketMode.UpdateBorrowingDisabled.kind]: config.borrowDisabled,
1290
+ [UpdateLendingMarketMode.UpdateMinNetValueObligationPostAction.kind]: config.minNetValueInObligationSf,
1291
+ [UpdateLendingMarketMode.UpdateMinValueLtvSkipPriorityLiqCheck.kind]: config.minValueSkipLiquidationLtvChecks,
1292
+ [UpdateLendingMarketMode.UpdateMinValueBfSkipPriorityLiqCheck.kind]: config.minValueSkipLiquidationBfChecks,
1293
+ [UpdateLendingMarketMode.UpdatePaddingFields.kind]: [], // we do not update padding this way
1294
+ [UpdateLendingMarketMode.UpdateName.kind]: config.name,
1295
+ [UpdateLendingMarketMode.UpdateIndividualAutodeleverageMarginCallPeriodSecs.kind]:
1296
+ config.individualAutodeleverageMarginCallPeriodSecs,
1297
+ [UpdateLendingMarketMode.UpdateInitialDepositAmount.kind]: config.minInitialDepositAmount,
1298
+ [UpdateLendingMarketMode.UpdateObligationOrdersEnabled.kind]: config.obligationOrdersEnabled,
1299
+ }));
1549
1300
 
1550
1301
  function parseForChangesMarketConfigAndGetIxs(
1551
1302
  marketWithAddress: MarketWithAddress,
1552
1303
  newMarket: LendingMarket,
1553
1304
  programId: PublicKey
1554
1305
  ): TransactionInstruction[] {
1555
- const market = marketWithAddress.state;
1556
- const updateLendingMarketIxsArgs: { mode: number; value: Buffer }[] = [];
1557
-
1558
- for (const key in market.toJSON()) {
1559
- if (isExcludedLendingMarketKey(key)) {
1560
- continue;
1561
- }
1562
- updateLendingMarketIxsArgs.push(...updateLendingMarketConfig(key as LendingMarketKey, market, newMarket));
1563
- }
1564
-
1565
- const ixs: TransactionInstruction[] = [];
1566
-
1567
- updateLendingMarketIxsArgs.forEach((updateLendingMarketConfigArgs) => {
1568
- ixs.push(
1569
- updateMarketConfigIx(
1570
- marketWithAddress,
1571
- updateLendingMarketConfigArgs.mode,
1572
- updateLendingMarketConfigArgs.value,
1573
- programId
1574
- )
1575
- );
1576
- });
1577
-
1578
- return ixs;
1579
- }
1580
-
1581
- function updateMarketConfigEncodedValue(
1582
- discriminator: UpdateLendingMarketModeKind['discriminator'],
1583
- value: number | number[] | PublicKey | ElevationGroup | string
1584
- ): Buffer {
1585
- let buffer: Buffer = Buffer.alloc(72);
1586
- let pkBuffer: Buffer;
1587
- let valueBigInt: bigint;
1588
- let valueArray: number[];
1589
-
1590
- switch (discriminator) {
1591
- case UpdateLendingMarketMode.UpdateEmergencyMode.discriminator:
1592
- case UpdateLendingMarketMode.UpdateLiquidationCloseFactor.discriminator:
1593
- case UpdateLendingMarketMode.UpdateInsolvencyRiskLtv.discriminator:
1594
- case UpdateLendingMarketMode.UpdatePriceRefreshTriggerToMaxAgePct.discriminator:
1595
- case UpdateLendingMarketMode.UpdateAutodeleverageEnabled.discriminator:
1596
- case UpdateLendingMarketMode.UpdateObligationOrdersEnabled.discriminator:
1597
- case UpdateLendingMarketMode.UpdateBorrowingDisabled.discriminator:
1598
- buffer.writeUIntLE(value as number, 0, 1);
1599
- break;
1600
- case UpdateLendingMarketMode.UpdateReferralFeeBps.discriminator:
1601
- buffer.writeUInt16LE(value as number, 0);
1602
- break;
1603
- case UpdateLendingMarketMode.UpdateLiquidationMaxValue.discriminator:
1604
- case UpdateLendingMarketMode.UpdateGlobalAllowedBorrow.discriminator:
1605
- case UpdateLendingMarketMode.UpdateMinFullLiquidationThreshold.discriminator:
1606
- case UpdateLendingMarketMode.UpdateMinValueBfSkipPriorityLiqCheck.discriminator:
1607
- case UpdateLendingMarketMode.UpdateMinValueLtvSkipPriorityLiqCheck.discriminator:
1608
- case UpdateLendingMarketMode.UpdateIndividualAutodeleverageMarginCallPeriodSecs.discriminator:
1609
- case UpdateLendingMarketMode.UpdateInitialDepositAmount.discriminator:
1610
- value = value as number;
1611
- buffer.writeBigUint64LE(BigInt(value), 0);
1612
- break;
1613
- case UpdateLendingMarketMode.UpdateOwner.discriminator:
1614
- case UpdateLendingMarketMode.UpdateRiskCouncil.discriminator:
1615
- pkBuffer = (value as PublicKey).toBuffer();
1616
- pkBuffer.copy(buffer, 0);
1617
- break;
1618
- case UpdateLendingMarketMode.UpdateElevationGroup.discriminator:
1619
- buffer = serializeElevationGroup(value as ElevationGroup);
1620
- break;
1621
- case UpdateLendingMarketMode.UpdateMinNetValueObligationPostAction.discriminator:
1622
- valueBigInt = BigInt(value as string);
1623
- for (let i = 0; i < 16; i++) {
1624
- buffer[15 - i] = Number((valueBigInt >> BigInt(i * 8)) & BigInt(0xff));
1625
- }
1626
- break;
1627
- case UpdateLendingMarketMode.UpdateName.discriminator:
1628
- valueArray = value as number[];
1629
- for (let i = 0; i < valueArray.length; i++) {
1630
- buffer.writeUIntLE(valueArray[i], i, 1);
1631
- }
1632
- break;
1633
- case UpdateLendingMarketMode.UpdatePaddingFields.discriminator:
1634
- case UpdateLendingMarketMode.DeprecatedUpdateGlobalUnhealthyBorrow.discriminator:
1635
- case UpdateLendingMarketMode.DeprecatedUpdateMultiplierPoints.discriminator:
1636
- // Deliberately skipped - we are not updating padding or deprecated fields using this method
1637
- break;
1638
- default:
1639
- assertNever(discriminator);
1640
- }
1641
-
1642
- return buffer;
1306
+ const encodedMarketUpdates = MARKET_UPDATER.encodeAllUpdates(marketWithAddress.state, newMarket);
1307
+ return encodedMarketUpdates.map((encodedMarketUpdate) =>
1308
+ updateMarketConfigIx(marketWithAddress, encodedMarketUpdate.mode, encodedMarketUpdate.value, programId)
1309
+ );
1643
1310
  }
1644
1311
 
1645
1312
  function updateMarketConfigIx(
1646
1313
  marketWithAddress: MarketWithAddress,
1647
- modeDiscriminator: number,
1648
- value: Buffer,
1314
+ mode: UpdateLendingMarketModeKind,
1315
+ value: Uint8Array,
1649
1316
  programId: PublicKey
1650
1317
  ): TransactionInstruction {
1651
1318
  const accounts: UpdateLendingMarketAccounts = {
@@ -1654,25 +1321,13 @@ function updateMarketConfigIx(
1654
1321
  };
1655
1322
 
1656
1323
  const args: UpdateLendingMarketArgs = {
1657
- mode: new anchor.BN(modeDiscriminator),
1658
- value: [...value],
1324
+ mode: new anchor.BN(mode.discriminator),
1325
+ // NOTE: the Market's update handler expects a `[u8; 72]` (contrary to e.g. the Reserve's update handler accepting
1326
+ // `Vec<u8>`). Hence, we need to add explicit padding here:
1327
+ value: [...value, ...Array(72 - value.length).fill(0)],
1659
1328
  };
1660
1329
 
1661
1330
  const ix = updateLendingMarket(args, accounts, programId);
1662
1331
 
1663
1332
  return ix;
1664
1333
  }
1665
-
1666
- function serializeElevationGroup(elevationGroup: ElevationGroup): Buffer {
1667
- const buffer = Buffer.alloc(72);
1668
- buffer.writeUInt16LE(elevationGroup.maxLiquidationBonusBps, 0);
1669
- buffer.writeUIntLE(elevationGroup.id, 2, 1);
1670
- buffer.writeUIntLE(elevationGroup.ltvPct, 3, 1);
1671
- buffer.writeUIntLE(elevationGroup.liquidationThresholdPct, 4, 1);
1672
- buffer.writeUIntLE(elevationGroup.allowNewLoans, 5, 1);
1673
- buffer.writeUIntLE(elevationGroup.maxReservesAsCollateral, 6, 1);
1674
- buffer.writeUIntLE(elevationGroup.padding0, 7, 1);
1675
- const debtReserveBuffer = elevationGroup.debtReserve.toBuffer();
1676
- debtReserveBuffer.copy(buffer, 8);
1677
- return buffer;
1678
- }
@@ -524,8 +524,13 @@ export class KaminoMarket {
524
524
  getRewardPrice
525
525
  );
526
526
  }
527
+
527
528
  if (isNotNullPubkey(debtFarmAddress)) {
528
- result.depositingRewards = await this.getRewardInfoForFarm(debtFarmAddress, totalBorrowAmount, getRewardPrice);
529
+ result.borrowingRewards = await this.getRewardInfoForFarm(
530
+ debtFarmAddress,
531
+ totalBorrowAmount,
532
+ getRewardPrice
533
+ );
529
534
  }
530
535
 
531
536
  return result;