@kamino-finance/klend-sdk 5.11.13 → 5.11.15

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.
@@ -222,11 +222,17 @@ export function calculateAPRFromAPY(apy: Decimal.Value) {
222
222
  .times(SLOTS_PER_YEAR);
223
223
  }
224
224
 
225
- export function sameLengthArrayEquals(left: Array<number>, right: Array<number>): boolean {
225
+ export function sameLengthArrayEquals<T>(left: Array<T>, right: Array<T>): boolean {
226
226
  if (left.length != right.length) {
227
- throw new Error(`Not same length: ${left.length} != ${left.length}`);
227
+ throw new Error(`Not same length: ${left.length} != ${right.length}`);
228
228
  }
229
- return left.every((value, index) => value === right[index]);
229
+ return left.every((value, index) => {
230
+ const other = right[index];
231
+ if (value != null && typeof (value as any).eq === 'function') {
232
+ return (value as any).eq(other);
233
+ }
234
+ return value === other;
235
+ });
230
236
  }
231
237
 
232
238
  export function getTokenBalanceFromAccountInfoLamports(accountInfo: AccountInfo<Buffer>): Decimal {
@@ -199,7 +199,12 @@ export class KaminoVaultClient {
199
199
  this._kaminoVaultProgramId
200
200
  )[0];
201
201
 
202
- const adminTokenAccount = getAssociatedTokenAddressSync(vaultConfig.tokenMint, vaultConfig.admin, false);
202
+ const adminTokenAccount = getAssociatedTokenAddressSync(
203
+ vaultConfig.tokenMint,
204
+ vaultConfig.admin,
205
+ false,
206
+ vaultConfig.tokenMintProgramId
207
+ );
203
208
 
204
209
  const initVaultAccounts: InitVaultAccounts = {
205
210
  adminAuthority: vaultConfig.admin,
@@ -1427,64 +1427,64 @@ function createAddExtraComputeUnitFeeTransaction(units: number, microLamports: n
1427
1427
  return ixns;
1428
1428
  }
1429
1429
 
1430
- function parseReserveConfigFromFile(farmConfigFromFile: any): ReserveConfig {
1430
+ function parseReserveConfigFromFile(reserveConfigFromFile: any): ReserveConfig {
1431
1431
  const reserveConfigFields: ReserveConfigFields = {
1432
- status: farmConfigFromFile.status,
1433
- loanToValuePct: farmConfigFromFile.loanToValuePct,
1434
- liquidationThresholdPct: farmConfigFromFile.liquidationThresholdPct,
1435
- minLiquidationBonusBps: farmConfigFromFile.minLiquidationBonusBps,
1436
- protocolLiquidationFeePct: farmConfigFromFile.protocolLiquidationFeePct,
1437
- protocolTakeRatePct: farmConfigFromFile.protocolLiquidationFeePct,
1438
- assetTier: farmConfigFromFile.assetTier,
1439
- maxLiquidationBonusBps: farmConfigFromFile.maxLiquidationBonusBps,
1440
- badDebtLiquidationBonusBps: farmConfigFromFile.badDebtLiquidationBonusBps,
1432
+ status: reserveConfigFromFile.status,
1433
+ loanToValuePct: reserveConfigFromFile.loanToValuePct,
1434
+ liquidationThresholdPct: reserveConfigFromFile.liquidationThresholdPct,
1435
+ minLiquidationBonusBps: reserveConfigFromFile.minLiquidationBonusBps,
1436
+ protocolLiquidationFeePct: reserveConfigFromFile.protocolLiquidationFeePct,
1437
+ protocolTakeRatePct: reserveConfigFromFile.protocolLiquidationFeePct,
1438
+ assetTier: reserveConfigFromFile.assetTier,
1439
+ maxLiquidationBonusBps: reserveConfigFromFile.maxLiquidationBonusBps,
1440
+ badDebtLiquidationBonusBps: reserveConfigFromFile.badDebtLiquidationBonusBps,
1441
1441
  fees: {
1442
- borrowFeeSf: Fraction.fromDecimal(new Decimal(farmConfigFromFile.fees.borrowFee)).valueSf,
1443
- flashLoanFeeSf: Fraction.fromDecimal(new Decimal(farmConfigFromFile.fees.flashLoanFee)).valueSf,
1442
+ borrowFeeSf: Fraction.fromDecimal(new Decimal(reserveConfigFromFile.fees.borrowFee)).valueSf,
1443
+ flashLoanFeeSf: Fraction.fromDecimal(new Decimal(reserveConfigFromFile.fees.flashLoanFee)).valueSf,
1444
1444
  padding: Array(8).fill(0),
1445
1445
  },
1446
- depositLimit: new BN(farmConfigFromFile.depositLimit),
1447
- borrowLimit: new BN(farmConfigFromFile.borrowLimit),
1446
+ depositLimit: new BN(reserveConfigFromFile.depositLimit),
1447
+ borrowLimit: new BN(reserveConfigFromFile.borrowLimit),
1448
1448
  tokenInfo: {
1449
- name: encodeTokenName(farmConfigFromFile.tokenInfo.name),
1449
+ name: encodeTokenName(reserveConfigFromFile.tokenInfo.name),
1450
1450
  heuristic: new PriceHeuristic({
1451
- lower: new BN(farmConfigFromFile.tokenInfo.heuristic.lower),
1452
- upper: new BN(farmConfigFromFile.tokenInfo.heuristic.upper),
1453
- exp: new BN(farmConfigFromFile.tokenInfo.heuristic.exp),
1451
+ lower: new BN(reserveConfigFromFile.tokenInfo.heuristic.lower),
1452
+ upper: new BN(reserveConfigFromFile.tokenInfo.heuristic.upper),
1453
+ exp: new BN(reserveConfigFromFile.tokenInfo.heuristic.exp),
1454
1454
  }),
1455
- maxTwapDivergenceBps: new BN(farmConfigFromFile.tokenInfo.maxTwapDivergenceBps),
1456
- maxAgePriceSeconds: new BN(farmConfigFromFile.tokenInfo.maxAgePriceSeconds),
1457
- maxAgeTwapSeconds: new BN(farmConfigFromFile.tokenInfo.maxAgeTwapSeconds),
1458
- ...parseOracleConfiguration(farmConfigFromFile),
1459
- blockPriceUsage: farmConfigFromFile.tokenInfo.blockPriceUsage,
1455
+ maxTwapDivergenceBps: new BN(reserveConfigFromFile.tokenInfo.maxTwapDivergenceBps),
1456
+ maxAgePriceSeconds: new BN(reserveConfigFromFile.tokenInfo.maxAgePriceSeconds),
1457
+ maxAgeTwapSeconds: new BN(reserveConfigFromFile.tokenInfo.maxAgeTwapSeconds),
1458
+ ...parseOracleConfiguration(reserveConfigFromFile),
1459
+ blockPriceUsage: reserveConfigFromFile.tokenInfo.blockPriceUsage,
1460
1460
  reserved: Array(7).fill(0),
1461
1461
  padding: Array(19).fill(new BN(0)),
1462
1462
  } as TokenInfo,
1463
- borrowRateCurve: parseBorrowRateCurve(farmConfigFromFile),
1463
+ borrowRateCurve: parseBorrowRateCurve(reserveConfigFromFile),
1464
1464
  depositWithdrawalCap: new WithdrawalCaps({
1465
- configCapacity: new BN(farmConfigFromFile.depositWithdrawalCap.configCapacity),
1465
+ configCapacity: new BN(reserveConfigFromFile.depositWithdrawalCap.configCapacity),
1466
1466
  currentTotal: new BN(0),
1467
1467
  lastIntervalStartTimestamp: new BN(0),
1468
- configIntervalLengthSeconds: new BN(farmConfigFromFile.depositWithdrawalCap.configIntervalLengthSeconds),
1468
+ configIntervalLengthSeconds: new BN(reserveConfigFromFile.depositWithdrawalCap.configIntervalLengthSeconds),
1469
1469
  }),
1470
1470
  debtWithdrawalCap: new WithdrawalCaps({
1471
- configCapacity: new BN(farmConfigFromFile.debtWithdrawalCap.configCapacity),
1471
+ configCapacity: new BN(reserveConfigFromFile.debtWithdrawalCap.configCapacity),
1472
1472
  currentTotal: new BN(0),
1473
1473
  lastIntervalStartTimestamp: new BN(0),
1474
- configIntervalLengthSeconds: new BN(farmConfigFromFile.debtWithdrawalCap.configIntervalLengthSeconds),
1474
+ configIntervalLengthSeconds: new BN(reserveConfigFromFile.debtWithdrawalCap.configIntervalLengthSeconds),
1475
1475
  }),
1476
- deleveragingMarginCallPeriodSecs: new BN(farmConfigFromFile.deleveragingMarginCallPeriodSecs),
1477
- borrowFactorPct: new BN(farmConfigFromFile.borrowFactorPct),
1478
- elevationGroups: farmConfigFromFile.elevationGroups,
1479
- deleveragingThresholdDecreaseBpsPerDay: new BN(farmConfigFromFile.deleveragingThresholdDecreaseBpsPerDay),
1480
- disableUsageAsCollOutsideEmode: farmConfigFromFile.disableUsageAsCollOutsideEmode,
1481
- utilizationLimitBlockBorrowingAbovePct: farmConfigFromFile.utilizationLimitBlockBorrowingAbovePct,
1482
- hostFixedInterestRateBps: farmConfigFromFile.hostFixedInterestRateBps,
1483
- autodeleverageEnabled: farmConfigFromFile.autodeleverageEnabled,
1484
- borrowLimitOutsideElevationGroup: new BN(farmConfigFromFile.borrowLimitOutsideElevationGroup),
1485
- borrowLimitAgainstThisCollateralInElevationGroup: parseReserveBorrowLimitAgainstCollInEmode(farmConfigFromFile),
1486
- deleveragingBonusIncreaseBpsPerDay: new BN(farmConfigFromFile.deleveragingBonusIncreaseBpsPerDay),
1487
- reserved1: Array(2).fill(0),
1476
+ deleveragingMarginCallPeriodSecs: new BN(reserveConfigFromFile.deleveragingMarginCallPeriodSecs),
1477
+ borrowFactorPct: new BN(reserveConfigFromFile.borrowFactorPct),
1478
+ elevationGroups: reserveConfigFromFile.elevationGroups,
1479
+ deleveragingThresholdDecreaseBpsPerDay: new BN(reserveConfigFromFile.deleveragingThresholdDecreaseBpsPerDay),
1480
+ disableUsageAsCollOutsideEmode: reserveConfigFromFile.disableUsageAsCollOutsideEmode,
1481
+ utilizationLimitBlockBorrowingAbovePct: reserveConfigFromFile.utilizationLimitBlockBorrowingAbovePct,
1482
+ hostFixedInterestRateBps: reserveConfigFromFile.hostFixedInterestRateBps,
1483
+ autodeleverageEnabled: reserveConfigFromFile.autodeleverageEnabled,
1484
+ borrowLimitOutsideElevationGroup: new BN(reserveConfigFromFile.borrowLimitOutsideElevationGroup),
1485
+ borrowLimitAgainstThisCollateralInElevationGroup: parseReserveBorrowLimitAgainstCollInEmode(reserveConfigFromFile),
1486
+ deleveragingBonusIncreaseBpsPerDay: new BN(reserveConfigFromFile.deleveragingBonusIncreaseBpsPerDay),
1487
+ reserved1: Array(1).fill(0),
1488
1488
  reserved2: Array(2).fill(0),
1489
1489
  reserved3: Array(8).fill(0),
1490
1490
  };
@@ -1492,29 +1492,29 @@ function parseReserveConfigFromFile(farmConfigFromFile: any): ReserveConfig {
1492
1492
  return new ReserveConfig(reserveConfigFields);
1493
1493
  }
1494
1494
 
1495
- function parseOracleConfiguration(farmConfigFromFile: any): {
1495
+ function parseOracleConfiguration(reserveConfigFromFile: any): {
1496
1496
  pythConfiguration: PythConfiguration;
1497
1497
  switchboardConfiguration: SwitchboardConfiguration;
1498
1498
  scopeConfiguration: ScopeConfiguration;
1499
1499
  } {
1500
1500
  const pythConfiguration = new PythConfiguration({
1501
- price: new PublicKey(farmConfigFromFile.tokenInfo.pythConfiguration.price),
1501
+ price: new PublicKey(reserveConfigFromFile.tokenInfo.pythConfiguration.price),
1502
1502
  });
1503
1503
  const switchboardConfiguration = new SwitchboardConfiguration({
1504
- priceAggregator: new PublicKey(farmConfigFromFile.tokenInfo.switchboardConfiguration.priceAggregator),
1505
- twapAggregator: new PublicKey(farmConfigFromFile.tokenInfo.switchboardConfiguration.twapAggregator),
1504
+ priceAggregator: new PublicKey(reserveConfigFromFile.tokenInfo.switchboardConfiguration.priceAggregator),
1505
+ twapAggregator: new PublicKey(reserveConfigFromFile.tokenInfo.switchboardConfiguration.twapAggregator),
1506
1506
  });
1507
1507
  const priceChain = [65535, 65535, 65535, 65535];
1508
1508
  const twapChain = [65535, 65535, 65535, 65535];
1509
1509
 
1510
- const priceChainFromFile: number[] = farmConfigFromFile.tokenInfo.scopeConfiguration.priceChain;
1511
- const twapChainFromFile: number[] = farmConfigFromFile.tokenInfo.scopeConfiguration.twapChain;
1510
+ const priceChainFromFile: number[] = reserveConfigFromFile.tokenInfo.scopeConfiguration.priceChain;
1511
+ const twapChainFromFile: number[] = reserveConfigFromFile.tokenInfo.scopeConfiguration.twapChain;
1512
1512
 
1513
1513
  priceChainFromFile.forEach((value, index) => (priceChain[index] = value));
1514
1514
  twapChainFromFile.forEach((value, index) => (twapChain[index] = value));
1515
1515
 
1516
1516
  const scopeConfiguration = new ScopeConfiguration({
1517
- priceFeed: new PublicKey(farmConfigFromFile.tokenInfo.scopeConfiguration.priceFeed),
1517
+ priceFeed: new PublicKey(reserveConfigFromFile.tokenInfo.scopeConfiguration.priceFeed),
1518
1518
  priceChain: priceChain,
1519
1519
  twapChain: twapChain,
1520
1520
  });
@@ -1526,29 +1526,29 @@ function parseOracleConfiguration(farmConfigFromFile: any): {
1526
1526
  };
1527
1527
  }
1528
1528
 
1529
- function parseBorrowRateCurve(farmConfigFromFile: any): BorrowRateCurve {
1529
+ function parseBorrowRateCurve(reserveConfigFromFile: any): BorrowRateCurve {
1530
1530
  const curvePoints: CurvePointFields[] = [];
1531
1531
 
1532
- farmConfigFromFile.borrowRateCurve.points.forEach((curvePoint: { utilizationRateBps: any; borrowRateBps: any }) =>
1532
+ reserveConfigFromFile.borrowRateCurve.points.forEach((curvePoint: { utilizationRateBps: any; borrowRateBps: any }) =>
1533
1533
  curvePoints.push({
1534
1534
  utilizationRateBps: curvePoint.utilizationRateBps,
1535
1535
  borrowRateBps: curvePoint.borrowRateBps,
1536
1536
  })
1537
1537
  );
1538
1538
 
1539
- const finalCruvePoints: CurvePointFields[] = Array(11).fill(curvePoints[curvePoints.length - 1]);
1539
+ const finalCurvePoints: CurvePointFields[] = Array(11).fill(curvePoints[curvePoints.length - 1]);
1540
1540
 
1541
- curvePoints.forEach((curvePoint, index) => (finalCruvePoints[index] = curvePoint));
1541
+ curvePoints.forEach((curvePoint, index) => (finalCurvePoints[index] = curvePoint));
1542
1542
 
1543
- const borrowRateCurve = new BorrowRateCurve({ points: finalCruvePoints });
1543
+ const borrowRateCurve = new BorrowRateCurve({ points: finalCurvePoints });
1544
1544
 
1545
1545
  return borrowRateCurve;
1546
1546
  }
1547
1547
 
1548
- function parseReserveBorrowLimitAgainstCollInEmode(farmConfigFromFile: any): BN[] {
1548
+ function parseReserveBorrowLimitAgainstCollInEmode(reserveConfigFromFile: any): BN[] {
1549
1549
  const reserveBorrowLimitAgainstCollInEmode: BN[] = Array(32).fill(new BN(0));
1550
1550
 
1551
- farmConfigFromFile.borrowLimitAgainstThisCollateralInElevationGroup.forEach(
1551
+ reserveConfigFromFile.borrowLimitAgainstThisCollateralInElevationGroup.forEach(
1552
1552
  (limit: any, index: number) => (reserveBorrowLimitAgainstCollInEmode[index] = new BN(limit))
1553
1553
  );
1554
1554