@kamino-finance/klend-sdk 4.0.0 → 4.0.2
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/action.js +2 -2
- package/dist/classes/manager.js +1 -1
- package/dist/classes/market.d.ts +6 -6
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +16 -16
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.d.ts +1 -1
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +40 -28
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +8 -6
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/shared.d.ts +1 -1
- package/dist/utils/managerTypes.js +1 -1
- package/dist/utils/oracle.d.ts +1 -1
- package/dist/utils/oracle.d.ts.map +1 -1
- package/dist/utils/oracle.js +1 -2
- package/dist/utils/oracle.js.map +1 -1
- package/dist/utils/userMetadata.js +1 -1
- package/package.json +6 -6
- package/src/classes/action.ts +2 -2
- package/src/classes/manager.ts +1 -1
- package/src/classes/market.ts +21 -22
- package/src/classes/obligation.ts +65 -32
- package/src/classes/reserve.ts +9 -8
- package/src/classes/shared.ts +1 -1
- package/src/utils/managerTypes.ts +1 -1
- package/src/utils/oracle.ts +1 -2
- package/src/utils/userMetadata.ts +1 -1
|
@@ -4,7 +4,7 @@ exports.getUserLutAddressAndSetupIxns = void 0;
|
|
|
4
4
|
exports.getAllUserMetadatasWithFilter = getAllUserMetadatasWithFilter;
|
|
5
5
|
const web3_js_1 = require("@solana/web3.js");
|
|
6
6
|
const lib_1 = require("../lib");
|
|
7
|
-
const farms_sdk_1 = require("@
|
|
7
|
+
const farms_sdk_1 = require("@kamino-finance/farms-sdk");
|
|
8
8
|
const getUserLutAddressAndSetupIxns = async (kaminoMarket, user, referrer = web3_js_1.PublicKey.default, withExtendLut = true, multiplyMints = [], leverageMints = [], repayWithCollObligation = undefined, payer = web3_js_1.PublicKey.default) => {
|
|
9
9
|
const [userMetadataAddress, userMetadataState] = await kaminoMarket.getUserMetadata(user);
|
|
10
10
|
const initUserMetadataIxs = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kamino-finance/klend-sdk",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Typescript SDK for interacting with the Kamino Lending (klend) protocol",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"@bokuweb/zstd-wasm": "^0.0.20",
|
|
51
51
|
"@coral-xyz/anchor": "^0.28.0",
|
|
52
52
|
"@coral-xyz/borsh": "^0.28.0",
|
|
53
|
-
"@
|
|
54
|
-
"@
|
|
55
|
-
"@kamino-finance/
|
|
53
|
+
"@kamino-finance/farms-sdk": "^2.0.3",
|
|
54
|
+
"@kamino-finance/kliquidity-sdk": "^6.2.1",
|
|
55
|
+
"@kamino-finance/scope-sdk": "^8.0.2",
|
|
56
56
|
"@pythnetwork/client": "^2.5.1",
|
|
57
57
|
"@solana/buffer-layout": "^4.0.0",
|
|
58
58
|
"@solana/spl-token": "^0.4.8",
|
|
@@ -101,8 +101,8 @@
|
|
|
101
101
|
"typescript-eslint": "^0.0.1-alpha.0"
|
|
102
102
|
},
|
|
103
103
|
"resolutions": {
|
|
104
|
-
"@kamino-finance/
|
|
105
|
-
"@
|
|
104
|
+
"@kamino-finance/farms-sdk": "^2.0.3",
|
|
105
|
+
"@kamino-finance/kliquidity-sdk": "^6.2.1"
|
|
106
106
|
},
|
|
107
107
|
"packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
|
|
108
108
|
}
|
package/src/classes/action.ts
CHANGED
|
@@ -64,11 +64,11 @@ import { KaminoMarket } from './market';
|
|
|
64
64
|
import { KaminoObligation } from './obligation';
|
|
65
65
|
import { KaminoReserve } from './reserve';
|
|
66
66
|
import { ReserveFarmKind } from '../idl_codegen/types';
|
|
67
|
-
import { farmsId } from '@
|
|
67
|
+
import { farmsId } from '@kamino-finance/farms-sdk';
|
|
68
68
|
import { Reserve } from '../idl_codegen/accounts';
|
|
69
69
|
import { VanillaObligation } from '../utils/ObligationType';
|
|
70
70
|
import { PROGRAM_ID } from '../lib';
|
|
71
|
-
import { U16_MAX } from '@
|
|
71
|
+
import { U16_MAX } from '@kamino-finance/scope-sdk';
|
|
72
72
|
|
|
73
73
|
export const POSITION_LIMIT = 10;
|
|
74
74
|
export const BORROWS_LIMIT = 5;
|
package/src/classes/manager.ts
CHANGED
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
UpdateLendingMarketOwnerAccounts,
|
|
35
35
|
} from '../lib';
|
|
36
36
|
import { PROGRAM_ID } from '../idl_codegen/programId';
|
|
37
|
-
import { Scope, TokenMetadatas, U16_MAX } from '@
|
|
37
|
+
import { Scope, TokenMetadatas, U16_MAX } from '@kamino-finance/scope-sdk';
|
|
38
38
|
import BN from 'bn.js';
|
|
39
39
|
import { ElevationGroup, ReserveConfig, UpdateLendingMarketMode } from '../idl_codegen/types';
|
|
40
40
|
import Decimal from 'decimal.js';
|
package/src/classes/market.ts
CHANGED
|
@@ -20,14 +20,15 @@ import {
|
|
|
20
20
|
cacheOrGetSwitchboardPrice,
|
|
21
21
|
PubkeyHashMap,
|
|
22
22
|
CandidatePrice,
|
|
23
|
+
PublicKeySet,
|
|
23
24
|
} from '../utils';
|
|
24
25
|
import base58 from 'bs58';
|
|
25
26
|
import { BN } from '@coral-xyz/anchor';
|
|
26
27
|
import Decimal from 'decimal.js';
|
|
27
|
-
import { FarmState } from '@
|
|
28
|
+
import { FarmState } from '@kamino-finance/farms-sdk';
|
|
28
29
|
import { PROGRAM_ID } from '../idl_codegen/programId';
|
|
29
30
|
import bs58 from 'bs58';
|
|
30
|
-
import { OraclePrices, Scope } from '@
|
|
31
|
+
import { OraclePrices, Scope } from '@kamino-finance/scope-sdk';
|
|
31
32
|
import { Fraction } from './fraction';
|
|
32
33
|
import { chunks, KaminoPrices, MintToPriceMap } from '@kamino-finance/kliquidity-sdk';
|
|
33
34
|
import { parseTokenSymbol } from './utils';
|
|
@@ -1208,10 +1209,10 @@ export class KaminoMarket {
|
|
|
1208
1209
|
continue;
|
|
1209
1210
|
}
|
|
1210
1211
|
elevationGroups.push({
|
|
1211
|
-
collateralReserves: [],
|
|
1212
|
-
collateralLiquidityMints: [],
|
|
1213
|
-
debtReserve: elevationGroup.debtReserve
|
|
1214
|
-
debtLiquidityMint:
|
|
1212
|
+
collateralReserves: new PublicKeySet<PublicKey>([]),
|
|
1213
|
+
collateralLiquidityMints: new PublicKeySet<PublicKey>([]),
|
|
1214
|
+
debtReserve: elevationGroup.debtReserve,
|
|
1215
|
+
debtLiquidityMint: PublicKey.default,
|
|
1215
1216
|
elevationGroup: elevationGroup.id,
|
|
1216
1217
|
});
|
|
1217
1218
|
}
|
|
@@ -1219,7 +1220,7 @@ export class KaminoMarket {
|
|
|
1219
1220
|
// Fill the remaining
|
|
1220
1221
|
for (const reserve of this.reserves.values()) {
|
|
1221
1222
|
const reserveLiquidityMint = reserve.getLiquidityMint();
|
|
1222
|
-
const reserveAddress = reserve.address
|
|
1223
|
+
const reserveAddress = reserve.address;
|
|
1223
1224
|
const reserveElevationGroups = reserve.state.config.elevationGroups;
|
|
1224
1225
|
for (const elevationGroupId of reserveElevationGroups) {
|
|
1225
1226
|
if (elevationGroupId === 0) {
|
|
@@ -1228,14 +1229,14 @@ export class KaminoMarket {
|
|
|
1228
1229
|
|
|
1229
1230
|
const elevationGroupDescription = elevationGroups[elevationGroupId - 1];
|
|
1230
1231
|
if (elevationGroupDescription) {
|
|
1231
|
-
if (reserveAddress
|
|
1232
|
-
elevationGroups[elevationGroupId - 1].debtLiquidityMint = reserveLiquidityMint
|
|
1232
|
+
if (reserveAddress.equals(elevationGroupDescription.debtReserve)) {
|
|
1233
|
+
elevationGroups[elevationGroupId - 1].debtLiquidityMint = reserveLiquidityMint;
|
|
1233
1234
|
} else {
|
|
1234
|
-
elevationGroups[elevationGroupId - 1].collateralReserves.
|
|
1235
|
-
elevationGroups[elevationGroupId - 1].collateralLiquidityMints.
|
|
1235
|
+
elevationGroups[elevationGroupId - 1].collateralReserves.add(reserveAddress);
|
|
1236
|
+
elevationGroups[elevationGroupId - 1].collateralLiquidityMints.add(reserveLiquidityMint);
|
|
1236
1237
|
}
|
|
1237
1238
|
} else {
|
|
1238
|
-
throw new Error(`Invalid elevation group id ${elevationGroupId} at reserve ${reserveAddress}`);
|
|
1239
|
+
throw new Error(`Invalid elevation group id ${elevationGroupId} at reserve ${reserveAddress.toString()}`);
|
|
1239
1240
|
}
|
|
1240
1241
|
}
|
|
1241
1242
|
}
|
|
@@ -1252,10 +1253,8 @@ export class KaminoMarket {
|
|
|
1252
1253
|
|
|
1253
1254
|
return allElevationGroups.filter((elevationGroupDescription) => {
|
|
1254
1255
|
return (
|
|
1255
|
-
collLiquidityMints.every((mint) =>
|
|
1256
|
-
|
|
1257
|
-
) &&
|
|
1258
|
-
(debtLiquidityMint == undefined || debtLiquidityMint.toString() === elevationGroupDescription.debtLiquidityMint)
|
|
1256
|
+
collLiquidityMints.every((mint) => elevationGroupDescription.collateralLiquidityMints.contains(mint)) &&
|
|
1257
|
+
(debtLiquidityMint == undefined || debtLiquidityMint.equals(elevationGroupDescription.debtLiquidityMint))
|
|
1259
1258
|
);
|
|
1260
1259
|
});
|
|
1261
1260
|
}
|
|
@@ -1269,8 +1268,8 @@ export class KaminoMarket {
|
|
|
1269
1268
|
|
|
1270
1269
|
return allElevationGroups.filter((elevationGroupDescription) => {
|
|
1271
1270
|
return (
|
|
1272
|
-
collReserves.every((mint) => elevationGroupDescription.collateralReserves.
|
|
1273
|
-
(debtReserve == undefined || debtReserve.
|
|
1271
|
+
collReserves.every((mint) => elevationGroupDescription.collateralReserves.contains(mint)) &&
|
|
1272
|
+
(debtReserve == undefined || debtReserve.equals(elevationGroupDescription.debtReserve))
|
|
1274
1273
|
);
|
|
1275
1274
|
});
|
|
1276
1275
|
}
|
|
@@ -1305,10 +1304,10 @@ export type BorrowCapsAndCounters = {
|
|
|
1305
1304
|
};
|
|
1306
1305
|
|
|
1307
1306
|
export type ElevationGroupDescription = {
|
|
1308
|
-
collateralReserves:
|
|
1309
|
-
collateralLiquidityMints:
|
|
1310
|
-
debtReserve:
|
|
1311
|
-
debtLiquidityMint:
|
|
1307
|
+
collateralReserves: PublicKeySet<PublicKey>;
|
|
1308
|
+
collateralLiquidityMints: PublicKeySet<PublicKey>;
|
|
1309
|
+
debtReserve: PublicKey;
|
|
1310
|
+
debtLiquidityMint: PublicKey;
|
|
1312
1311
|
elevationGroup: number;
|
|
1313
1312
|
};
|
|
1314
1313
|
|
|
@@ -372,19 +372,31 @@ export class KaminoObligation {
|
|
|
372
372
|
simulateBorrowChange(
|
|
373
373
|
obligationBorrows: ObligationLiquidity[],
|
|
374
374
|
changeInLamports: number,
|
|
375
|
-
changeReserve: PublicKey
|
|
375
|
+
changeReserve: PublicKey,
|
|
376
|
+
cumulativeBorrowRate: Decimal
|
|
376
377
|
): ObligationLiquidity[] {
|
|
377
378
|
const newBorrows: ObligationLiquidity[] = [];
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
379
|
+
const borrowIndex = obligationBorrows.findIndex((borrow) => borrow.borrowReserve.equals(changeReserve));
|
|
380
|
+
|
|
381
|
+
if (borrowIndex !== -1) {
|
|
382
|
+
const borrow: ObligationLiquidityFields = { ...obligationBorrows[borrowIndex] };
|
|
383
|
+
const newBorrowedAmount: Decimal = new Fraction(borrow.borrowedAmountSf).toDecimal().add(changeInLamports);
|
|
384
|
+
const newBorrowedAmountSf = Fraction.fromDecimal(positiveOrZero(newBorrowedAmount)).getValue();
|
|
385
|
+
borrow.borrowedAmountSf = newBorrowedAmountSf;
|
|
386
|
+
newBorrows.push(new ObligationLiquidity(borrow));
|
|
387
|
+
} else {
|
|
388
|
+
const firstBorrowIndexAvailable = obligationBorrows.findIndex((borrow) =>
|
|
389
|
+
borrow.borrowReserve.equals(PublicKey.default)
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
const borrow: ObligationLiquidityFields = { ...obligationBorrows[firstBorrowIndexAvailable] };
|
|
393
|
+
borrow.borrowedAmountSf = Fraction.fromDecimal(new Decimal(changeInLamports)).getValue();
|
|
394
|
+
borrow.borrowReserve = changeReserve;
|
|
395
|
+
borrow.cumulativeBorrowRateBsf = {
|
|
396
|
+
padding: [],
|
|
397
|
+
value: [Fraction.fromDecimal(cumulativeBorrowRate).getValue(), new BN(0), new BN(0), new BN(0)],
|
|
398
|
+
};
|
|
399
|
+
newBorrows.push(new ObligationLiquidity(borrow));
|
|
388
400
|
}
|
|
389
401
|
|
|
390
402
|
return newBorrows;
|
|
@@ -412,11 +424,7 @@ export class KaminoObligation {
|
|
|
412
424
|
const { amountCollateral, amountDebt, action, mintCollateral, mintDebt, market } = params;
|
|
413
425
|
let newStats = { ...this.refreshedStats };
|
|
414
426
|
|
|
415
|
-
const { collateralExchangeRates
|
|
416
|
-
market,
|
|
417
|
-
this.state,
|
|
418
|
-
params.slot
|
|
419
|
-
);
|
|
427
|
+
const { collateralExchangeRates } = KaminoObligation.getRatesForObligation(market, this.state, params.slot);
|
|
420
428
|
|
|
421
429
|
const elevationGroup = params.elevationGroupOverride ?? this.state.elevationGroup;
|
|
422
430
|
|
|
@@ -427,8 +435,11 @@ export class KaminoObligation {
|
|
|
427
435
|
// so we have to recalculate the entire position, not just an updated deposit or borrow
|
|
428
436
|
// as both LTVs and borrow factors can change, affecting all calcs
|
|
429
437
|
|
|
430
|
-
const
|
|
431
|
-
const
|
|
438
|
+
const collateralReservePk = mintCollateral ? market.getReserveByMint(mintCollateral)!.address : undefined;
|
|
439
|
+
const debtReservePk = mintDebt ? market.getReserveByMint(mintDebt)!.address : undefined;
|
|
440
|
+
const debtReserveCumulativeBorrowRate = mintDebt
|
|
441
|
+
? market.getReserveByMint(mintDebt)!.getCumulativeBorrowRate()
|
|
442
|
+
: undefined;
|
|
432
443
|
|
|
433
444
|
let newObligationDeposits = this.state.deposits;
|
|
434
445
|
let newObligationBorrows = this.state.borrows;
|
|
@@ -441,7 +452,7 @@ export class KaminoObligation {
|
|
|
441
452
|
newObligationDeposits = this.simulateDepositChange(
|
|
442
453
|
this.state.deposits,
|
|
443
454
|
amountCollateral.toNumber(),
|
|
444
|
-
|
|
455
|
+
collateralReservePk!,
|
|
445
456
|
collateralExchangeRates
|
|
446
457
|
);
|
|
447
458
|
break;
|
|
@@ -451,14 +462,25 @@ export class KaminoObligation {
|
|
|
451
462
|
throw Error('amountDebt & mintDebt are required for borrow action');
|
|
452
463
|
}
|
|
453
464
|
|
|
454
|
-
newObligationBorrows = this.simulateBorrowChange(
|
|
465
|
+
newObligationBorrows = this.simulateBorrowChange(
|
|
466
|
+
this.state.borrows,
|
|
467
|
+
amountDebt.toNumber(),
|
|
468
|
+
debtReservePk!,
|
|
469
|
+
debtReserveCumulativeBorrowRate!
|
|
470
|
+
);
|
|
455
471
|
break;
|
|
456
472
|
}
|
|
457
473
|
case 'repay': {
|
|
458
474
|
if (amountDebt === undefined || mintDebt === undefined) {
|
|
459
475
|
throw Error('amountDebt & mintDebt are required for repay action');
|
|
460
476
|
}
|
|
461
|
-
|
|
477
|
+
|
|
478
|
+
newObligationBorrows = this.simulateBorrowChange(
|
|
479
|
+
this.state.borrows,
|
|
480
|
+
amountDebt.neg().toNumber(),
|
|
481
|
+
debtReservePk!,
|
|
482
|
+
debtReserveCumulativeBorrowRate!
|
|
483
|
+
);
|
|
462
484
|
|
|
463
485
|
break;
|
|
464
486
|
}
|
|
@@ -470,7 +492,7 @@ export class KaminoObligation {
|
|
|
470
492
|
newObligationDeposits = this.simulateDepositChange(
|
|
471
493
|
this.state.deposits,
|
|
472
494
|
amountCollateral.neg().toNumber(),
|
|
473
|
-
|
|
495
|
+
collateralReservePk!,
|
|
474
496
|
collateralExchangeRates
|
|
475
497
|
);
|
|
476
498
|
break;
|
|
@@ -487,10 +509,16 @@ export class KaminoObligation {
|
|
|
487
509
|
newObligationDeposits = this.simulateDepositChange(
|
|
488
510
|
this.state.deposits,
|
|
489
511
|
amountCollateral.toNumber(),
|
|
490
|
-
|
|
512
|
+
collateralReservePk!,
|
|
491
513
|
collateralExchangeRates
|
|
492
514
|
);
|
|
493
|
-
|
|
515
|
+
|
|
516
|
+
newObligationBorrows = this.simulateBorrowChange(
|
|
517
|
+
this.state.borrows,
|
|
518
|
+
amountDebt.toNumber(),
|
|
519
|
+
debtReservePk!,
|
|
520
|
+
debtReserveCumulativeBorrowRate!
|
|
521
|
+
);
|
|
494
522
|
break;
|
|
495
523
|
}
|
|
496
524
|
case 'repayAndWithdraw': {
|
|
@@ -505,10 +533,15 @@ export class KaminoObligation {
|
|
|
505
533
|
newObligationDeposits = this.simulateDepositChange(
|
|
506
534
|
this.state.deposits,
|
|
507
535
|
amountCollateral.neg().toNumber(),
|
|
508
|
-
|
|
536
|
+
collateralReservePk!,
|
|
509
537
|
collateralExchangeRates
|
|
510
538
|
);
|
|
511
|
-
newObligationBorrows = this.simulateBorrowChange(
|
|
539
|
+
newObligationBorrows = this.simulateBorrowChange(
|
|
540
|
+
this.state.borrows,
|
|
541
|
+
amountDebt.neg().toNumber(),
|
|
542
|
+
debtReservePk!,
|
|
543
|
+
debtReserveCumulativeBorrowRate!
|
|
544
|
+
);
|
|
512
545
|
break;
|
|
513
546
|
}
|
|
514
547
|
default: {
|
|
@@ -522,7 +555,7 @@ export class KaminoObligation {
|
|
|
522
555
|
newObligationBorrows,
|
|
523
556
|
elevationGroup,
|
|
524
557
|
collateralExchangeRates,
|
|
525
|
-
|
|
558
|
+
null
|
|
526
559
|
);
|
|
527
560
|
|
|
528
561
|
newStats = refreshedStats;
|
|
@@ -568,7 +601,7 @@ export class KaminoObligation {
|
|
|
568
601
|
obligationBorrows: ObligationLiquidity[],
|
|
569
602
|
elevationGroup: number,
|
|
570
603
|
collateralExchangeRates: Map<PublicKey, Decimal>,
|
|
571
|
-
cumulativeBorrowRates: Map<PublicKey, Decimal>
|
|
604
|
+
cumulativeBorrowRates: Map<PublicKey, Decimal> | null
|
|
572
605
|
): {
|
|
573
606
|
borrows: Map<PublicKey, Position>;
|
|
574
607
|
deposits: Map<PublicKey, Position>;
|
|
@@ -904,8 +937,8 @@ export class KaminoObligation {
|
|
|
904
937
|
// - [x] due to collateral / debt reserves combination
|
|
905
938
|
// - [x] due to LTV, etc
|
|
906
939
|
|
|
907
|
-
const reserveDeposits:
|
|
908
|
-
const reserveBorrows:
|
|
940
|
+
const reserveDeposits: PublicKey[] = Array.from(this.deposits.keys());
|
|
941
|
+
const reserveBorrows: PublicKey[] = Array.from(this.borrows.keys());
|
|
909
942
|
|
|
910
943
|
if (reserveBorrows.length > 1) {
|
|
911
944
|
return false;
|
|
@@ -918,11 +951,11 @@ export class KaminoObligation {
|
|
|
918
951
|
|
|
919
952
|
// Has to be a subset
|
|
920
953
|
const allCollsIncluded = reserveDeposits.every((reserve) =>
|
|
921
|
-
elevationGroupDescription.collateralReserves.
|
|
954
|
+
elevationGroupDescription.collateralReserves.contains(reserve)
|
|
922
955
|
);
|
|
923
956
|
const allDebtsIncluded =
|
|
924
957
|
reserveBorrows.length === 0 ||
|
|
925
|
-
(reserveBorrows.length === 1 && elevationGroupDescription.debtReserve
|
|
958
|
+
(reserveBorrows.length === 1 && elevationGroupDescription.debtReserve.equals(reserveBorrows[0]));
|
|
926
959
|
|
|
927
960
|
if (!allCollsIncluded || !allDebtsIncluded) {
|
|
928
961
|
return false;
|
package/src/classes/reserve.ts
CHANGED
|
@@ -39,7 +39,7 @@ import * as anchor from '@coral-xyz/anchor';
|
|
|
39
39
|
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
40
40
|
import { UpdateBorrowRateCurve } from '../idl_codegen/types/UpdateConfigMode';
|
|
41
41
|
import { aprToApy, KaminoPrices } from '@kamino-finance/kliquidity-sdk';
|
|
42
|
-
import { FarmState, RewardInfo } from '@
|
|
42
|
+
import { FarmState, RewardInfo } from '@kamino-finance/farms-sdk';
|
|
43
43
|
|
|
44
44
|
export const DEFAULT_RECENT_SLOT_DURATION_MS = 450;
|
|
45
45
|
|
|
@@ -935,9 +935,9 @@ export class KaminoReserve {
|
|
|
935
935
|
currentValue: Decimal;
|
|
936
936
|
}[] = market
|
|
937
937
|
.getMarketElevationGroupDescriptions()
|
|
938
|
-
.filter((x) => x.debtReserve
|
|
938
|
+
.filter((x) => x.debtReserve.equals(this.address))
|
|
939
939
|
.map((elevationGroupDescription: ElevationGroupDescription) =>
|
|
940
|
-
elevationGroupDescription.collateralReserves.map((collateralReserveAddress) => {
|
|
940
|
+
elevationGroupDescription.collateralReserves.toArray().map((collateralReserveAddress) => {
|
|
941
941
|
const collRes = market.reserves.get(new PublicKey(collateralReserveAddress))!;
|
|
942
942
|
|
|
943
943
|
const debtLimitAgainstThisCollInGroup =
|
|
@@ -1015,14 +1015,15 @@ export class KaminoReserve {
|
|
|
1015
1015
|
positiveOrZero(remainingGlobalCap),
|
|
1016
1016
|
positiveOrZero(liquidityGivenUtilizationCap)
|
|
1017
1017
|
);
|
|
1018
|
-
|
|
1019
1018
|
return availableInCrossMode;
|
|
1020
1019
|
} else {
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
.map((x) => x.maxDebt.minus(x.currentValue))
|
|
1020
|
+
let remainingInsideEmodeCaps = new Decimal(0);
|
|
1021
|
+
const capsGivenEgroup = caps.debtAgainstCollateralReserveCaps.filter(
|
|
1022
|
+
(x) => x.elevationGroup === elevationGroup
|
|
1025
1023
|
);
|
|
1024
|
+
if (capsGivenEgroup.length > 0) {
|
|
1025
|
+
remainingInsideEmodeCaps = Decimal.min(...capsGivenEgroup.map((x) => x.maxDebt.minus(x.currentValue)));
|
|
1026
|
+
}
|
|
1026
1027
|
return Decimal.min(
|
|
1027
1028
|
positiveOrZero(liquidityAvailable),
|
|
1028
1029
|
positiveOrZero(remainingInsideEmodeCaps),
|
package/src/classes/shared.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PublicKey } from '@solana/web3.js';
|
|
2
2
|
import Decimal from 'decimal.js';
|
|
3
|
-
import { FarmState, RewardInfo } from '@
|
|
3
|
+
import { FarmState, RewardInfo } from '@kamino-finance/farms-sdk';
|
|
4
4
|
|
|
5
5
|
export type ConfigType = Array<MarketConfigType>;
|
|
6
6
|
|
|
@@ -17,7 +17,7 @@ import { Fraction, ZERO_FRACTION } from '../classes/fraction';
|
|
|
17
17
|
import BN from 'bn.js';
|
|
18
18
|
import { numberToLamportsDecimal } from '../classes';
|
|
19
19
|
import { NULL_PUBKEY } from './pubkey';
|
|
20
|
-
import { OracleType, U16_MAX } from '@
|
|
20
|
+
import { OracleType, U16_MAX } from '@kamino-finance/scope-sdk';
|
|
21
21
|
import { LendingMarket } from '../lib';
|
|
22
22
|
|
|
23
23
|
export type ScopeOracleConfig = {
|
package/src/utils/oracle.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { parsePriceData } from '@pythnetwork/client';
|
|
2
2
|
import { AccountInfo, Connection, PublicKey } from '@solana/web3.js';
|
|
3
3
|
import Decimal from 'decimal.js';
|
|
4
|
-
|
|
5
|
-
import { OraclePrices, Scope } from '@hubbleprotocol/scope-sdk';
|
|
4
|
+
import { OraclePrices, Scope } from '@kamino-finance/scope-sdk';
|
|
6
5
|
import { isNotNullPubkey, PubkeyHashMap, PublicKeySet } from './pubkey';
|
|
7
6
|
import { parseTokenSymbol } from '../classes';
|
|
8
7
|
import SwitchboardProgram from '@switchboard-xyz/sbv2-lite';
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
UserMetadata,
|
|
22
22
|
PublicKeySet,
|
|
23
23
|
} from '../lib';
|
|
24
|
-
import { farmsId } from '@
|
|
24
|
+
import { farmsId } from '@kamino-finance/farms-sdk';
|
|
25
25
|
import { KaminoReserve } from '../classes/reserve';
|
|
26
26
|
|
|
27
27
|
export type KaminoUserMetadata = {
|