@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.
- package/dist/classes/reserve.d.ts +7 -1
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +145 -255
- 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/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +1 -1
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.js +54 -54
- package/dist/client_kamino_manager.js.map +1 -1
- package/package.json +6 -4
- package/src/classes/reserve.ts +178 -319
- package/src/classes/utils.ts +9 -3
- package/src/classes/vault.ts +6 -1
- 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 {
|
package/src/classes/vault.ts
CHANGED
|
@@ -199,7 +199,12 @@ export class KaminoVaultClient {
|
|
|
199
199
|
this._kaminoVaultProgramId
|
|
200
200
|
)[0];
|
|
201
201
|
|
|
202
|
-
const adminTokenAccount = getAssociatedTokenAddressSync(
|
|
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(
|
|
1430
|
+
function parseReserveConfigFromFile(reserveConfigFromFile: any): ReserveConfig {
|
|
1431
1431
|
const reserveConfigFields: ReserveConfigFields = {
|
|
1432
|
-
status:
|
|
1433
|
-
loanToValuePct:
|
|
1434
|
-
liquidationThresholdPct:
|
|
1435
|
-
minLiquidationBonusBps:
|
|
1436
|
-
protocolLiquidationFeePct:
|
|
1437
|
-
protocolTakeRatePct:
|
|
1438
|
-
assetTier:
|
|
1439
|
-
maxLiquidationBonusBps:
|
|
1440
|
-
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(
|
|
1443
|
-
flashLoanFeeSf: Fraction.fromDecimal(new Decimal(
|
|
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(
|
|
1447
|
-
borrowLimit: new BN(
|
|
1446
|
+
depositLimit: new BN(reserveConfigFromFile.depositLimit),
|
|
1447
|
+
borrowLimit: new BN(reserveConfigFromFile.borrowLimit),
|
|
1448
1448
|
tokenInfo: {
|
|
1449
|
-
name: encodeTokenName(
|
|
1449
|
+
name: encodeTokenName(reserveConfigFromFile.tokenInfo.name),
|
|
1450
1450
|
heuristic: new PriceHeuristic({
|
|
1451
|
-
lower: new BN(
|
|
1452
|
-
upper: new BN(
|
|
1453
|
-
exp: new BN(
|
|
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(
|
|
1456
|
-
maxAgePriceSeconds: new BN(
|
|
1457
|
-
maxAgeTwapSeconds: new BN(
|
|
1458
|
-
...parseOracleConfiguration(
|
|
1459
|
-
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(
|
|
1463
|
+
borrowRateCurve: parseBorrowRateCurve(reserveConfigFromFile),
|
|
1464
1464
|
depositWithdrawalCap: new WithdrawalCaps({
|
|
1465
|
-
configCapacity: new BN(
|
|
1465
|
+
configCapacity: new BN(reserveConfigFromFile.depositWithdrawalCap.configCapacity),
|
|
1466
1466
|
currentTotal: new BN(0),
|
|
1467
1467
|
lastIntervalStartTimestamp: new BN(0),
|
|
1468
|
-
configIntervalLengthSeconds: new BN(
|
|
1468
|
+
configIntervalLengthSeconds: new BN(reserveConfigFromFile.depositWithdrawalCap.configIntervalLengthSeconds),
|
|
1469
1469
|
}),
|
|
1470
1470
|
debtWithdrawalCap: new WithdrawalCaps({
|
|
1471
|
-
configCapacity: new BN(
|
|
1471
|
+
configCapacity: new BN(reserveConfigFromFile.debtWithdrawalCap.configCapacity),
|
|
1472
1472
|
currentTotal: new BN(0),
|
|
1473
1473
|
lastIntervalStartTimestamp: new BN(0),
|
|
1474
|
-
configIntervalLengthSeconds: new BN(
|
|
1474
|
+
configIntervalLengthSeconds: new BN(reserveConfigFromFile.debtWithdrawalCap.configIntervalLengthSeconds),
|
|
1475
1475
|
}),
|
|
1476
|
-
deleveragingMarginCallPeriodSecs: new BN(
|
|
1477
|
-
borrowFactorPct: new BN(
|
|
1478
|
-
elevationGroups:
|
|
1479
|
-
deleveragingThresholdDecreaseBpsPerDay: new BN(
|
|
1480
|
-
disableUsageAsCollOutsideEmode:
|
|
1481
|
-
utilizationLimitBlockBorrowingAbovePct:
|
|
1482
|
-
hostFixedInterestRateBps:
|
|
1483
|
-
autodeleverageEnabled:
|
|
1484
|
-
borrowLimitOutsideElevationGroup: new BN(
|
|
1485
|
-
borrowLimitAgainstThisCollateralInElevationGroup: parseReserveBorrowLimitAgainstCollInEmode(
|
|
1486
|
-
deleveragingBonusIncreaseBpsPerDay: new BN(
|
|
1487
|
-
reserved1: Array(
|
|
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(
|
|
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(
|
|
1501
|
+
price: new PublicKey(reserveConfigFromFile.tokenInfo.pythConfiguration.price),
|
|
1502
1502
|
});
|
|
1503
1503
|
const switchboardConfiguration = new SwitchboardConfiguration({
|
|
1504
|
-
priceAggregator: new PublicKey(
|
|
1505
|
-
twapAggregator: new PublicKey(
|
|
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[] =
|
|
1511
|
-
const twapChainFromFile: number[] =
|
|
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(
|
|
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(
|
|
1529
|
+
function parseBorrowRateCurve(reserveConfigFromFile: any): BorrowRateCurve {
|
|
1530
1530
|
const curvePoints: CurvePointFields[] = [];
|
|
1531
1531
|
|
|
1532
|
-
|
|
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
|
|
1539
|
+
const finalCurvePoints: CurvePointFields[] = Array(11).fill(curvePoints[curvePoints.length - 1]);
|
|
1540
1540
|
|
|
1541
|
-
curvePoints.forEach((curvePoint, index) => (
|
|
1541
|
+
curvePoints.forEach((curvePoint, index) => (finalCurvePoints[index] = curvePoint));
|
|
1542
1542
|
|
|
1543
|
-
const borrowRateCurve = new BorrowRateCurve({ points:
|
|
1543
|
+
const borrowRateCurve = new BorrowRateCurve({ points: finalCurvePoints });
|
|
1544
1544
|
|
|
1545
1545
|
return borrowRateCurve;
|
|
1546
1546
|
}
|
|
1547
1547
|
|
|
1548
|
-
function parseReserveBorrowLimitAgainstCollInEmode(
|
|
1548
|
+
function parseReserveBorrowLimitAgainstCollInEmode(reserveConfigFromFile: any): BN[] {
|
|
1549
1549
|
const reserveBorrowLimitAgainstCollInEmode: BN[] = Array(32).fill(new BN(0));
|
|
1550
1550
|
|
|
1551
|
-
|
|
1551
|
+
reserveConfigFromFile.borrowLimitAgainstThisCollateralInElevationGroup.forEach(
|
|
1552
1552
|
(limit: any, index: number) => (reserveBorrowLimitAgainstCollInEmode[index] = new BN(limit))
|
|
1553
1553
|
);
|
|
1554
1554
|
|