@kamino-finance/klend-sdk 5.11.10 → 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.
- package/dist/classes/reserve.d.ts +7 -1
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +152 -257
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/utils.d.ts +1 -1
- package/dist/classes/utils.d.ts.map +1 -1
- package/dist/classes/utils.js +8 -2
- package/dist/classes/utils.js.map +1 -1
- package/dist/client_kamino_manager.js +54 -54
- package/dist/client_kamino_manager.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/reserve.ts +184 -321
- package/src/classes/utils.ts +9 -3
- package/src/client_kamino_manager.ts +54 -54
package/src/classes/utils.ts
CHANGED
|
@@ -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<
|
|
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} != ${
|
|
227
|
+
throw new Error(`Not same length: ${left.length} != ${right.length}`);
|
|
228
228
|
}
|
|
229
|
-
return left.every((value, 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(
|
|
1323
|
+
function parseReserveConfigFromFile(reserveConfigFromFile: any): ReserveConfig {
|
|
1324
1324
|
const reserveConfigFields: ReserveConfigFields = {
|
|
1325
|
-
status:
|
|
1326
|
-
loanToValuePct:
|
|
1327
|
-
liquidationThresholdPct:
|
|
1328
|
-
minLiquidationBonusBps:
|
|
1329
|
-
protocolLiquidationFeePct:
|
|
1330
|
-
protocolTakeRatePct:
|
|
1331
|
-
assetTier:
|
|
1332
|
-
maxLiquidationBonusBps:
|
|
1333
|
-
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(
|
|
1336
|
-
flashLoanFeeSf: Fraction.fromDecimal(new Decimal(
|
|
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(
|
|
1340
|
-
borrowLimit: new BN(
|
|
1339
|
+
depositLimit: new BN(reserveConfigFromFile.depositLimit),
|
|
1340
|
+
borrowLimit: new BN(reserveConfigFromFile.borrowLimit),
|
|
1341
1341
|
tokenInfo: {
|
|
1342
|
-
name: encodeTokenName(
|
|
1342
|
+
name: encodeTokenName(reserveConfigFromFile.tokenInfo.name),
|
|
1343
1343
|
heuristic: new PriceHeuristic({
|
|
1344
|
-
lower: new BN(
|
|
1345
|
-
upper: new BN(
|
|
1346
|
-
exp: new BN(
|
|
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(
|
|
1349
|
-
maxAgePriceSeconds: new BN(
|
|
1350
|
-
maxAgeTwapSeconds: new BN(
|
|
1351
|
-
...parseOracleConfiguration(
|
|
1352
|
-
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(
|
|
1356
|
+
borrowRateCurve: parseBorrowRateCurve(reserveConfigFromFile),
|
|
1357
1357
|
depositWithdrawalCap: new WithdrawalCaps({
|
|
1358
|
-
configCapacity: new BN(
|
|
1358
|
+
configCapacity: new BN(reserveConfigFromFile.depositWithdrawalCap.configCapacity),
|
|
1359
1359
|
currentTotal: new BN(0),
|
|
1360
1360
|
lastIntervalStartTimestamp: new BN(0),
|
|
1361
|
-
configIntervalLengthSeconds: new BN(
|
|
1361
|
+
configIntervalLengthSeconds: new BN(reserveConfigFromFile.depositWithdrawalCap.configIntervalLengthSeconds),
|
|
1362
1362
|
}),
|
|
1363
1363
|
debtWithdrawalCap: new WithdrawalCaps({
|
|
1364
|
-
configCapacity: new BN(
|
|
1364
|
+
configCapacity: new BN(reserveConfigFromFile.debtWithdrawalCap.configCapacity),
|
|
1365
1365
|
currentTotal: new BN(0),
|
|
1366
1366
|
lastIntervalStartTimestamp: new BN(0),
|
|
1367
|
-
configIntervalLengthSeconds: new BN(
|
|
1367
|
+
configIntervalLengthSeconds: new BN(reserveConfigFromFile.debtWithdrawalCap.configIntervalLengthSeconds),
|
|
1368
1368
|
}),
|
|
1369
|
-
deleveragingMarginCallPeriodSecs: new BN(
|
|
1370
|
-
borrowFactorPct: new BN(
|
|
1371
|
-
elevationGroups:
|
|
1372
|
-
deleveragingThresholdDecreaseBpsPerDay: new BN(
|
|
1373
|
-
disableUsageAsCollOutsideEmode:
|
|
1374
|
-
utilizationLimitBlockBorrowingAbovePct:
|
|
1375
|
-
hostFixedInterestRateBps:
|
|
1376
|
-
autodeleverageEnabled:
|
|
1377
|
-
borrowLimitOutsideElevationGroup: new BN(
|
|
1378
|
-
borrowLimitAgainstThisCollateralInElevationGroup: parseReserveBorrowLimitAgainstCollInEmode(
|
|
1379
|
-
deleveragingBonusIncreaseBpsPerDay: new BN(
|
|
1380
|
-
reserved1: Array(
|
|
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(
|
|
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(
|
|
1394
|
+
price: new PublicKey(reserveConfigFromFile.tokenInfo.pythConfiguration.price),
|
|
1395
1395
|
});
|
|
1396
1396
|
const switchboardConfiguration = new SwitchboardConfiguration({
|
|
1397
|
-
priceAggregator: new PublicKey(
|
|
1398
|
-
twapAggregator: new PublicKey(
|
|
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[] =
|
|
1404
|
-
const twapChainFromFile: number[] =
|
|
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(
|
|
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(
|
|
1422
|
+
function parseBorrowRateCurve(reserveConfigFromFile: any): BorrowRateCurve {
|
|
1423
1423
|
const curvePoints: CurvePointFields[] = [];
|
|
1424
1424
|
|
|
1425
|
-
|
|
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
|
|
1432
|
+
const finalCurvePoints: CurvePointFields[] = Array(11).fill(curvePoints[curvePoints.length - 1]);
|
|
1433
1433
|
|
|
1434
|
-
curvePoints.forEach((curvePoint, index) => (
|
|
1434
|
+
curvePoints.forEach((curvePoint, index) => (finalCurvePoints[index] = curvePoint));
|
|
1435
1435
|
|
|
1436
|
-
const borrowRateCurve = new BorrowRateCurve({ points:
|
|
1436
|
+
const borrowRateCurve = new BorrowRateCurve({ points: finalCurvePoints });
|
|
1437
1437
|
|
|
1438
1438
|
return borrowRateCurve;
|
|
1439
1439
|
}
|
|
1440
1440
|
|
|
1441
|
-
function parseReserveBorrowLimitAgainstCollInEmode(
|
|
1441
|
+
function parseReserveBorrowLimitAgainstCollInEmode(reserveConfigFromFile: any): BN[] {
|
|
1442
1442
|
const reserveBorrowLimitAgainstCollInEmode: BN[] = Array(32).fill(new BN(0));
|
|
1443
1443
|
|
|
1444
|
-
|
|
1444
|
+
reserveConfigFromFile.borrowLimitAgainstThisCollateralInElevationGroup.forEach(
|
|
1445
1445
|
(limit: any, index: number) => (reserveBorrowLimitAgainstCollInEmode[index] = new BN(limit))
|
|
1446
1446
|
);
|
|
1447
1447
|
|