@kamino-finance/klend-sdk 5.11.11 → 5.11.12-beta.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.
@@ -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 {
@@ -1320,64 +1320,64 @@ function createAddExtraComputeUnitFeeTransaction(units: number, microLamports: n
1320
1320
  return ixns;
1321
1321
  }
1322
1322
 
1323
- function parseReserveConfigFromFile(farmConfigFromFile: any): ReserveConfig {
1323
+ function parseReserveConfigFromFile(reserveConfigFromFile: any): ReserveConfig {
1324
1324
  const reserveConfigFields: ReserveConfigFields = {
1325
- status: farmConfigFromFile.status,
1326
- loanToValuePct: farmConfigFromFile.loanToValuePct,
1327
- liquidationThresholdPct: farmConfigFromFile.liquidationThresholdPct,
1328
- minLiquidationBonusBps: farmConfigFromFile.minLiquidationBonusBps,
1329
- protocolLiquidationFeePct: farmConfigFromFile.protocolLiquidationFeePct,
1330
- protocolTakeRatePct: farmConfigFromFile.protocolLiquidationFeePct,
1331
- assetTier: farmConfigFromFile.assetTier,
1332
- maxLiquidationBonusBps: farmConfigFromFile.maxLiquidationBonusBps,
1333
- badDebtLiquidationBonusBps: farmConfigFromFile.badDebtLiquidationBonusBps,
1325
+ status: reserveConfigFromFile.status,
1326
+ loanToValuePct: reserveConfigFromFile.loanToValuePct,
1327
+ liquidationThresholdPct: reserveConfigFromFile.liquidationThresholdPct,
1328
+ minLiquidationBonusBps: reserveConfigFromFile.minLiquidationBonusBps,
1329
+ protocolLiquidationFeePct: reserveConfigFromFile.protocolLiquidationFeePct,
1330
+ protocolTakeRatePct: reserveConfigFromFile.protocolLiquidationFeePct,
1331
+ assetTier: reserveConfigFromFile.assetTier,
1332
+ maxLiquidationBonusBps: reserveConfigFromFile.maxLiquidationBonusBps,
1333
+ badDebtLiquidationBonusBps: reserveConfigFromFile.badDebtLiquidationBonusBps,
1334
1334
  fees: {
1335
- borrowFeeSf: Fraction.fromDecimal(new Decimal(farmConfigFromFile.fees.borrowFee)).valueSf,
1336
- flashLoanFeeSf: Fraction.fromDecimal(new Decimal(farmConfigFromFile.fees.flashLoanFee)).valueSf,
1335
+ borrowFeeSf: Fraction.fromDecimal(new Decimal(reserveConfigFromFile.fees.borrowFee)).valueSf,
1336
+ flashLoanFeeSf: Fraction.fromDecimal(new Decimal(reserveConfigFromFile.fees.flashLoanFee)).valueSf,
1337
1337
  padding: Array(8).fill(0),
1338
1338
  },
1339
- depositLimit: new BN(farmConfigFromFile.depositLimit),
1340
- borrowLimit: new BN(farmConfigFromFile.borrowLimit),
1339
+ depositLimit: new BN(reserveConfigFromFile.depositLimit),
1340
+ borrowLimit: new BN(reserveConfigFromFile.borrowLimit),
1341
1341
  tokenInfo: {
1342
- name: encodeTokenName(farmConfigFromFile.tokenInfo.name),
1342
+ name: encodeTokenName(reserveConfigFromFile.tokenInfo.name),
1343
1343
  heuristic: new PriceHeuristic({
1344
- lower: new BN(farmConfigFromFile.tokenInfo.heuristic.lower),
1345
- upper: new BN(farmConfigFromFile.tokenInfo.heuristic.upper),
1346
- exp: new BN(farmConfigFromFile.tokenInfo.heuristic.exp),
1344
+ lower: new BN(reserveConfigFromFile.tokenInfo.heuristic.lower),
1345
+ upper: new BN(reserveConfigFromFile.tokenInfo.heuristic.upper),
1346
+ exp: new BN(reserveConfigFromFile.tokenInfo.heuristic.exp),
1347
1347
  }),
1348
- maxTwapDivergenceBps: new BN(farmConfigFromFile.tokenInfo.maxTwapDivergenceBps),
1349
- maxAgePriceSeconds: new BN(farmConfigFromFile.tokenInfo.maxAgePriceSeconds),
1350
- maxAgeTwapSeconds: new BN(farmConfigFromFile.tokenInfo.maxAgeTwapSeconds),
1351
- ...parseOracleConfiguration(farmConfigFromFile),
1352
- blockPriceUsage: farmConfigFromFile.tokenInfo.blockPriceUsage,
1348
+ maxTwapDivergenceBps: new BN(reserveConfigFromFile.tokenInfo.maxTwapDivergenceBps),
1349
+ maxAgePriceSeconds: new BN(reserveConfigFromFile.tokenInfo.maxAgePriceSeconds),
1350
+ maxAgeTwapSeconds: new BN(reserveConfigFromFile.tokenInfo.maxAgeTwapSeconds),
1351
+ ...parseOracleConfiguration(reserveConfigFromFile),
1352
+ blockPriceUsage: reserveConfigFromFile.tokenInfo.blockPriceUsage,
1353
1353
  reserved: Array(7).fill(0),
1354
1354
  padding: Array(19).fill(new BN(0)),
1355
1355
  } as TokenInfo,
1356
- borrowRateCurve: parseBorrowRateCurve(farmConfigFromFile),
1356
+ borrowRateCurve: parseBorrowRateCurve(reserveConfigFromFile),
1357
1357
  depositWithdrawalCap: new WithdrawalCaps({
1358
- configCapacity: new BN(farmConfigFromFile.depositWithdrawalCap.configCapacity),
1358
+ configCapacity: new BN(reserveConfigFromFile.depositWithdrawalCap.configCapacity),
1359
1359
  currentTotal: new BN(0),
1360
1360
  lastIntervalStartTimestamp: new BN(0),
1361
- configIntervalLengthSeconds: new BN(farmConfigFromFile.depositWithdrawalCap.configIntervalLengthSeconds),
1361
+ configIntervalLengthSeconds: new BN(reserveConfigFromFile.depositWithdrawalCap.configIntervalLengthSeconds),
1362
1362
  }),
1363
1363
  debtWithdrawalCap: new WithdrawalCaps({
1364
- configCapacity: new BN(farmConfigFromFile.debtWithdrawalCap.configCapacity),
1364
+ configCapacity: new BN(reserveConfigFromFile.debtWithdrawalCap.configCapacity),
1365
1365
  currentTotal: new BN(0),
1366
1366
  lastIntervalStartTimestamp: new BN(0),
1367
- configIntervalLengthSeconds: new BN(farmConfigFromFile.debtWithdrawalCap.configIntervalLengthSeconds),
1367
+ configIntervalLengthSeconds: new BN(reserveConfigFromFile.debtWithdrawalCap.configIntervalLengthSeconds),
1368
1368
  }),
1369
- deleveragingMarginCallPeriodSecs: new BN(farmConfigFromFile.deleveragingMarginCallPeriodSecs),
1370
- borrowFactorPct: new BN(farmConfigFromFile.borrowFactorPct),
1371
- elevationGroups: farmConfigFromFile.elevationGroups,
1372
- deleveragingThresholdDecreaseBpsPerDay: new BN(farmConfigFromFile.deleveragingThresholdDecreaseBpsPerDay),
1373
- disableUsageAsCollOutsideEmode: farmConfigFromFile.disableUsageAsCollOutsideEmode,
1374
- utilizationLimitBlockBorrowingAbovePct: farmConfigFromFile.utilizationLimitBlockBorrowingAbovePct,
1375
- hostFixedInterestRateBps: farmConfigFromFile.hostFixedInterestRateBps,
1376
- autodeleverageEnabled: farmConfigFromFile.autodeleverageEnabled,
1377
- borrowLimitOutsideElevationGroup: new BN(farmConfigFromFile.borrowLimitOutsideElevationGroup),
1378
- borrowLimitAgainstThisCollateralInElevationGroup: parseReserveBorrowLimitAgainstCollInEmode(farmConfigFromFile),
1379
- deleveragingBonusIncreaseBpsPerDay: new BN(farmConfigFromFile.deleveragingBonusIncreaseBpsPerDay),
1380
- reserved1: Array(2).fill(0),
1369
+ deleveragingMarginCallPeriodSecs: new BN(reserveConfigFromFile.deleveragingMarginCallPeriodSecs),
1370
+ borrowFactorPct: new BN(reserveConfigFromFile.borrowFactorPct),
1371
+ elevationGroups: reserveConfigFromFile.elevationGroups,
1372
+ deleveragingThresholdDecreaseBpsPerDay: new BN(reserveConfigFromFile.deleveragingThresholdDecreaseBpsPerDay),
1373
+ disableUsageAsCollOutsideEmode: reserveConfigFromFile.disableUsageAsCollOutsideEmode,
1374
+ utilizationLimitBlockBorrowingAbovePct: reserveConfigFromFile.utilizationLimitBlockBorrowingAbovePct,
1375
+ hostFixedInterestRateBps: reserveConfigFromFile.hostFixedInterestRateBps,
1376
+ autodeleverageEnabled: reserveConfigFromFile.autodeleverageEnabled,
1377
+ borrowLimitOutsideElevationGroup: new BN(reserveConfigFromFile.borrowLimitOutsideElevationGroup),
1378
+ borrowLimitAgainstThisCollateralInElevationGroup: parseReserveBorrowLimitAgainstCollInEmode(reserveConfigFromFile),
1379
+ deleveragingBonusIncreaseBpsPerDay: new BN(reserveConfigFromFile.deleveragingBonusIncreaseBpsPerDay),
1380
+ reserved1: Array(1).fill(0),
1381
1381
  reserved2: Array(2).fill(0),
1382
1382
  reserved3: Array(8).fill(0),
1383
1383
  };
@@ -1385,29 +1385,29 @@ function parseReserveConfigFromFile(farmConfigFromFile: any): ReserveConfig {
1385
1385
  return new ReserveConfig(reserveConfigFields);
1386
1386
  }
1387
1387
 
1388
- function parseOracleConfiguration(farmConfigFromFile: any): {
1388
+ function parseOracleConfiguration(reserveConfigFromFile: any): {
1389
1389
  pythConfiguration: PythConfiguration;
1390
1390
  switchboardConfiguration: SwitchboardConfiguration;
1391
1391
  scopeConfiguration: ScopeConfiguration;
1392
1392
  } {
1393
1393
  const pythConfiguration = new PythConfiguration({
1394
- price: new PublicKey(farmConfigFromFile.tokenInfo.pythConfiguration.price),
1394
+ price: new PublicKey(reserveConfigFromFile.tokenInfo.pythConfiguration.price),
1395
1395
  });
1396
1396
  const switchboardConfiguration = new SwitchboardConfiguration({
1397
- priceAggregator: new PublicKey(farmConfigFromFile.tokenInfo.switchboardConfiguration.priceAggregator),
1398
- twapAggregator: new PublicKey(farmConfigFromFile.tokenInfo.switchboardConfiguration.twapAggregator),
1397
+ priceAggregator: new PublicKey(reserveConfigFromFile.tokenInfo.switchboardConfiguration.priceAggregator),
1398
+ twapAggregator: new PublicKey(reserveConfigFromFile.tokenInfo.switchboardConfiguration.twapAggregator),
1399
1399
  });
1400
1400
  const priceChain = [65535, 65535, 65535, 65535];
1401
1401
  const twapChain = [65535, 65535, 65535, 65535];
1402
1402
 
1403
- const priceChainFromFile: number[] = farmConfigFromFile.tokenInfo.scopeConfiguration.priceChain;
1404
- const twapChainFromFile: number[] = farmConfigFromFile.tokenInfo.scopeConfiguration.twapChain;
1403
+ const priceChainFromFile: number[] = reserveConfigFromFile.tokenInfo.scopeConfiguration.priceChain;
1404
+ const twapChainFromFile: number[] = reserveConfigFromFile.tokenInfo.scopeConfiguration.twapChain;
1405
1405
 
1406
1406
  priceChainFromFile.forEach((value, index) => (priceChain[index] = value));
1407
1407
  twapChainFromFile.forEach((value, index) => (twapChain[index] = value));
1408
1408
 
1409
1409
  const scopeConfiguration = new ScopeConfiguration({
1410
- priceFeed: new PublicKey(farmConfigFromFile.tokenInfo.scopeConfiguration.priceFeed),
1410
+ priceFeed: new PublicKey(reserveConfigFromFile.tokenInfo.scopeConfiguration.priceFeed),
1411
1411
  priceChain: priceChain,
1412
1412
  twapChain: twapChain,
1413
1413
  });
@@ -1419,29 +1419,29 @@ function parseOracleConfiguration(farmConfigFromFile: any): {
1419
1419
  };
1420
1420
  }
1421
1421
 
1422
- function parseBorrowRateCurve(farmConfigFromFile: any): BorrowRateCurve {
1422
+ function parseBorrowRateCurve(reserveConfigFromFile: any): BorrowRateCurve {
1423
1423
  const curvePoints: CurvePointFields[] = [];
1424
1424
 
1425
- farmConfigFromFile.borrowRateCurve.points.forEach((curvePoint: { utilizationRateBps: any; borrowRateBps: any }) =>
1425
+ reserveConfigFromFile.borrowRateCurve.points.forEach((curvePoint: { utilizationRateBps: any; borrowRateBps: any }) =>
1426
1426
  curvePoints.push({
1427
1427
  utilizationRateBps: curvePoint.utilizationRateBps,
1428
1428
  borrowRateBps: curvePoint.borrowRateBps,
1429
1429
  })
1430
1430
  );
1431
1431
 
1432
- const finalCruvePoints: CurvePointFields[] = Array(11).fill(curvePoints[curvePoints.length - 1]);
1432
+ const finalCurvePoints: CurvePointFields[] = Array(11).fill(curvePoints[curvePoints.length - 1]);
1433
1433
 
1434
- curvePoints.forEach((curvePoint, index) => (finalCruvePoints[index] = curvePoint));
1434
+ curvePoints.forEach((curvePoint, index) => (finalCurvePoints[index] = curvePoint));
1435
1435
 
1436
- const borrowRateCurve = new BorrowRateCurve({ points: finalCruvePoints });
1436
+ const borrowRateCurve = new BorrowRateCurve({ points: finalCurvePoints });
1437
1437
 
1438
1438
  return borrowRateCurve;
1439
1439
  }
1440
1440
 
1441
- function parseReserveBorrowLimitAgainstCollInEmode(farmConfigFromFile: any): BN[] {
1441
+ function parseReserveBorrowLimitAgainstCollInEmode(reserveConfigFromFile: any): BN[] {
1442
1442
  const reserveBorrowLimitAgainstCollInEmode: BN[] = Array(32).fill(new BN(0));
1443
1443
 
1444
- farmConfigFromFile.borrowLimitAgainstThisCollateralInElevationGroup.forEach(
1444
+ reserveConfigFromFile.borrowLimitAgainstThisCollateralInElevationGroup.forEach(
1445
1445
  (limit: any, index: number) => (reserveBorrowLimitAgainstCollInEmode[index] = new BN(limit))
1446
1446
  );
1447
1447