@kamino-finance/klend-sdk 5.10.19 → 5.10.21
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/manager.d.ts +6 -1
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +85 -60
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/reserve.d.ts +3 -0
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +323 -230
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/utils.d.ts +5 -0
- package/dist/classes/utils.d.ts.map +1 -1
- package/dist/classes/utils.js +13 -0
- package/dist/classes/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/manager.ts +109 -52
- package/src/classes/reserve.ts +442 -279
- package/src/classes/utils.ts +13 -0
package/src/classes/manager.ts
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
} from './vault';
|
|
29
29
|
import {
|
|
30
30
|
AddAssetToMarketParams,
|
|
31
|
+
assertNever,
|
|
31
32
|
CreateKaminoMarketParams,
|
|
32
33
|
createReserveIxs,
|
|
33
34
|
DEFAULT_RECENT_SLOT_DURATION_MS,
|
|
@@ -40,6 +41,7 @@ import {
|
|
|
40
41
|
KaminoReserve,
|
|
41
42
|
LendingMarket,
|
|
42
43
|
lendingMarketAuthPda,
|
|
44
|
+
LendingMarketFields,
|
|
43
45
|
MarketWithAddress,
|
|
44
46
|
parseForChangesReserveConfigAndGetIxs,
|
|
45
47
|
parseOracleType,
|
|
@@ -992,15 +994,32 @@ export class KaminoManager {
|
|
|
992
994
|
}
|
|
993
995
|
} // KaminoManager
|
|
994
996
|
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
997
|
+
export type BaseLendingMarketKey = keyof LendingMarketFields;
|
|
998
|
+
const EXCLUDED_LENDING_MARKET_KEYS = [
|
|
999
|
+
'version',
|
|
1000
|
+
'bumpSeed',
|
|
1001
|
+
'reserved0',
|
|
1002
|
+
'reserved1',
|
|
1003
|
+
'padding1',
|
|
1004
|
+
'elevationGroupPadding',
|
|
1005
|
+
'quoteCurrency',
|
|
1006
|
+
] as const;
|
|
1007
|
+
export type ExcludedLendingMarketKey = (typeof EXCLUDED_LENDING_MARKET_KEYS)[number];
|
|
1008
|
+
|
|
1009
|
+
function isExcludedLendingMarketKey(value: unknown): value is ExcludedLendingMarketKey {
|
|
1010
|
+
return EXCLUDED_LENDING_MARKET_KEYS.includes(value as ExcludedLendingMarketKey);
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
export type LendingMarketKey = Exclude<BaseLendingMarketKey, ExcludedLendingMarketKey>;
|
|
1014
|
+
|
|
1015
|
+
const updateLendingMarketConfig = (
|
|
1016
|
+
key: LendingMarketKey,
|
|
1017
|
+
market: LendingMarket,
|
|
1018
|
+
newMarket: LendingMarket
|
|
1019
|
+
): { mode: number; value: Buffer }[] => {
|
|
1001
1020
|
const updateLendingMarketIxnsArgs: { mode: number; value: Buffer }[] = [];
|
|
1002
|
-
|
|
1003
|
-
|
|
1021
|
+
switch (key) {
|
|
1022
|
+
case 'lendingMarketOwner': {
|
|
1004
1023
|
if (!market.lendingMarketOwner.equals(newMarket.lendingMarketOwner)) {
|
|
1005
1024
|
updateLendingMarketIxnsArgs.push({
|
|
1006
1025
|
mode: UpdateLendingMarketMode.UpdateOwner.discriminator,
|
|
@@ -1010,7 +1029,9 @@ function parseForChangesMarketConfigAndGetIxs(
|
|
|
1010
1029
|
),
|
|
1011
1030
|
});
|
|
1012
1031
|
}
|
|
1013
|
-
|
|
1032
|
+
break;
|
|
1033
|
+
}
|
|
1034
|
+
case 'lendingMarketOwnerCached':
|
|
1014
1035
|
if (!market.lendingMarketOwnerCached.equals(newMarket.lendingMarketOwnerCached)) {
|
|
1015
1036
|
updateLendingMarketIxnsArgs.push({
|
|
1016
1037
|
mode: UpdateLendingMarketMode.UpdateOwner.discriminator,
|
|
@@ -1020,7 +1041,8 @@ function parseForChangesMarketConfigAndGetIxs(
|
|
|
1020
1041
|
),
|
|
1021
1042
|
});
|
|
1022
1043
|
}
|
|
1023
|
-
|
|
1044
|
+
break;
|
|
1045
|
+
case 'referralFeeBps':
|
|
1024
1046
|
if (market.referralFeeBps !== newMarket.referralFeeBps) {
|
|
1025
1047
|
updateLendingMarketIxnsArgs.push({
|
|
1026
1048
|
mode: UpdateLendingMarketMode.UpdateReferralFeeBps.discriminator,
|
|
@@ -1030,7 +1052,8 @@ function parseForChangesMarketConfigAndGetIxs(
|
|
|
1030
1052
|
),
|
|
1031
1053
|
});
|
|
1032
1054
|
}
|
|
1033
|
-
|
|
1055
|
+
break;
|
|
1056
|
+
case 'emergencyMode':
|
|
1034
1057
|
if (market.emergencyMode !== newMarket.emergencyMode) {
|
|
1035
1058
|
updateLendingMarketIxnsArgs.push({
|
|
1036
1059
|
mode: UpdateLendingMarketMode.UpdateEmergencyMode.discriminator,
|
|
@@ -1040,7 +1063,8 @@ function parseForChangesMarketConfigAndGetIxs(
|
|
|
1040
1063
|
),
|
|
1041
1064
|
});
|
|
1042
1065
|
}
|
|
1043
|
-
|
|
1066
|
+
break;
|
|
1067
|
+
case 'autodeleverageEnabled':
|
|
1044
1068
|
if (market.autodeleverageEnabled !== newMarket.autodeleverageEnabled) {
|
|
1045
1069
|
updateLendingMarketIxnsArgs.push({
|
|
1046
1070
|
mode: UpdateLendingMarketMode.UpdateAutodeleverageEnabled.discriminator,
|
|
@@ -1050,7 +1074,8 @@ function parseForChangesMarketConfigAndGetIxs(
|
|
|
1050
1074
|
),
|
|
1051
1075
|
});
|
|
1052
1076
|
}
|
|
1053
|
-
|
|
1077
|
+
break;
|
|
1078
|
+
case 'borrowDisabled':
|
|
1054
1079
|
if (market.borrowDisabled !== newMarket.borrowDisabled) {
|
|
1055
1080
|
updateLendingMarketIxnsArgs.push({
|
|
1056
1081
|
mode: UpdateLendingMarketMode.UpdateBorrowingDisabled.discriminator,
|
|
@@ -1060,7 +1085,8 @@ function parseForChangesMarketConfigAndGetIxs(
|
|
|
1060
1085
|
),
|
|
1061
1086
|
});
|
|
1062
1087
|
}
|
|
1063
|
-
|
|
1088
|
+
break;
|
|
1089
|
+
case 'priceRefreshTriggerToMaxAgePct':
|
|
1064
1090
|
if (market.priceRefreshTriggerToMaxAgePct !== newMarket.priceRefreshTriggerToMaxAgePct) {
|
|
1065
1091
|
updateLendingMarketIxnsArgs.push({
|
|
1066
1092
|
mode: UpdateLendingMarketMode.UpdatePriceRefreshTriggerToMaxAgePct.discriminator,
|
|
@@ -1070,7 +1096,8 @@ function parseForChangesMarketConfigAndGetIxs(
|
|
|
1070
1096
|
),
|
|
1071
1097
|
});
|
|
1072
1098
|
}
|
|
1073
|
-
|
|
1099
|
+
break;
|
|
1100
|
+
case 'liquidationMaxDebtCloseFactorPct':
|
|
1074
1101
|
if (market.liquidationMaxDebtCloseFactorPct !== newMarket.liquidationMaxDebtCloseFactorPct) {
|
|
1075
1102
|
updateLendingMarketIxnsArgs.push({
|
|
1076
1103
|
mode: UpdateLendingMarketMode.UpdateLiquidationCloseFactor.discriminator,
|
|
@@ -1080,7 +1107,8 @@ function parseForChangesMarketConfigAndGetIxs(
|
|
|
1080
1107
|
),
|
|
1081
1108
|
});
|
|
1082
1109
|
}
|
|
1083
|
-
|
|
1110
|
+
break;
|
|
1111
|
+
case 'insolvencyRiskUnhealthyLtvPct':
|
|
1084
1112
|
if (market.insolvencyRiskUnhealthyLtvPct !== newMarket.insolvencyRiskUnhealthyLtvPct) {
|
|
1085
1113
|
updateLendingMarketIxnsArgs.push({
|
|
1086
1114
|
mode: UpdateLendingMarketMode.UpdateInsolvencyRiskLtv.discriminator,
|
|
@@ -1090,7 +1118,8 @@ function parseForChangesMarketConfigAndGetIxs(
|
|
|
1090
1118
|
),
|
|
1091
1119
|
});
|
|
1092
1120
|
}
|
|
1093
|
-
|
|
1121
|
+
break;
|
|
1122
|
+
case 'minFullLiquidationValueThreshold':
|
|
1094
1123
|
if (!market.minFullLiquidationValueThreshold.eq(newMarket.minFullLiquidationValueThreshold)) {
|
|
1095
1124
|
updateLendingMarketIxnsArgs.push({
|
|
1096
1125
|
mode: UpdateLendingMarketMode.UpdateMinFullLiquidationThreshold.discriminator,
|
|
@@ -1100,7 +1129,8 @@ function parseForChangesMarketConfigAndGetIxs(
|
|
|
1100
1129
|
),
|
|
1101
1130
|
});
|
|
1102
1131
|
}
|
|
1103
|
-
|
|
1132
|
+
break;
|
|
1133
|
+
case 'maxLiquidatableDebtMarketValueAtOnce':
|
|
1104
1134
|
if (!market.maxLiquidatableDebtMarketValueAtOnce.eq(newMarket.maxLiquidatableDebtMarketValueAtOnce)) {
|
|
1105
1135
|
updateLendingMarketIxnsArgs.push({
|
|
1106
1136
|
mode: UpdateLendingMarketMode.UpdateLiquidationMaxValue.discriminator,
|
|
@@ -1110,7 +1140,8 @@ function parseForChangesMarketConfigAndGetIxs(
|
|
|
1110
1140
|
),
|
|
1111
1141
|
});
|
|
1112
1142
|
}
|
|
1113
|
-
|
|
1143
|
+
break;
|
|
1144
|
+
case 'globalAllowedBorrowValue':
|
|
1114
1145
|
if (!market.globalAllowedBorrowValue.eq(newMarket.globalAllowedBorrowValue)) {
|
|
1115
1146
|
updateLendingMarketIxnsArgs.push({
|
|
1116
1147
|
mode: UpdateLendingMarketMode.UpdateGlobalAllowedBorrow.discriminator,
|
|
@@ -1120,7 +1151,8 @@ function parseForChangesMarketConfigAndGetIxs(
|
|
|
1120
1151
|
),
|
|
1121
1152
|
});
|
|
1122
1153
|
}
|
|
1123
|
-
|
|
1154
|
+
break;
|
|
1155
|
+
case 'riskCouncil':
|
|
1124
1156
|
if (!market.riskCouncil.equals(newMarket.riskCouncil)) {
|
|
1125
1157
|
updateLendingMarketIxnsArgs.push({
|
|
1126
1158
|
mode: UpdateLendingMarketMode.UpdateRiskCouncil.discriminator,
|
|
@@ -1130,7 +1162,34 @@ function parseForChangesMarketConfigAndGetIxs(
|
|
|
1130
1162
|
),
|
|
1131
1163
|
});
|
|
1132
1164
|
}
|
|
1133
|
-
|
|
1165
|
+
break;
|
|
1166
|
+
case 'elevationGroups':
|
|
1167
|
+
let elevationGroupsDiffs = 0;
|
|
1168
|
+
for (let i = 0; i < market.elevationGroups.length; i++) {
|
|
1169
|
+
if (
|
|
1170
|
+
market.elevationGroups[i].id !== newMarket.elevationGroups[i].id ||
|
|
1171
|
+
market.elevationGroups[i].maxLiquidationBonusBps !== newMarket.elevationGroups[i].maxLiquidationBonusBps ||
|
|
1172
|
+
market.elevationGroups[i].ltvPct !== newMarket.elevationGroups[i].ltvPct ||
|
|
1173
|
+
market.elevationGroups[i].liquidationThresholdPct !== newMarket.elevationGroups[i].liquidationThresholdPct ||
|
|
1174
|
+
market.elevationGroups[i].allowNewLoans !== newMarket.elevationGroups[i].allowNewLoans ||
|
|
1175
|
+
market.elevationGroups[i].maxReservesAsCollateral !== newMarket.elevationGroups[i].maxReservesAsCollateral ||
|
|
1176
|
+
!market.elevationGroups[i].debtReserve.equals(newMarket.elevationGroups[i].debtReserve)
|
|
1177
|
+
) {
|
|
1178
|
+
updateLendingMarketIxnsArgs.push({
|
|
1179
|
+
mode: UpdateLendingMarketMode.UpdateElevationGroup.discriminator,
|
|
1180
|
+
value: updateMarketConfigEncodedValue(
|
|
1181
|
+
UpdateLendingMarketMode.UpdateElevationGroup.discriminator,
|
|
1182
|
+
newMarket.elevationGroups[i]
|
|
1183
|
+
),
|
|
1184
|
+
});
|
|
1185
|
+
elevationGroupsDiffs++;
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
if (elevationGroupsDiffs > 1) {
|
|
1189
|
+
throw new Error('Can only update 1 elevation group at a time');
|
|
1190
|
+
}
|
|
1191
|
+
break;
|
|
1192
|
+
case 'minNetValueInObligationSf':
|
|
1134
1193
|
if (!market.minNetValueInObligationSf.eq(newMarket.minNetValueInObligationSf)) {
|
|
1135
1194
|
updateLendingMarketIxnsArgs.push({
|
|
1136
1195
|
mode: UpdateLendingMarketMode.UpdateMinNetValueObligationPostAction.discriminator,
|
|
@@ -1140,7 +1199,8 @@ function parseForChangesMarketConfigAndGetIxs(
|
|
|
1140
1199
|
),
|
|
1141
1200
|
});
|
|
1142
1201
|
}
|
|
1143
|
-
|
|
1202
|
+
break;
|
|
1203
|
+
case 'minValueSkipLiquidationBfChecks':
|
|
1144
1204
|
if (!market.minValueSkipLiquidationBfChecks.eq(newMarket.minValueSkipLiquidationBfChecks)) {
|
|
1145
1205
|
updateLendingMarketIxnsArgs.push({
|
|
1146
1206
|
mode: UpdateLendingMarketMode.UpdateMinValueBfSkipPriorityLiqCheck.discriminator,
|
|
@@ -1150,7 +1210,8 @@ function parseForChangesMarketConfigAndGetIxs(
|
|
|
1150
1210
|
),
|
|
1151
1211
|
});
|
|
1152
1212
|
}
|
|
1153
|
-
|
|
1213
|
+
break;
|
|
1214
|
+
case 'minValueSkipLiquidationLtvChecks':
|
|
1154
1215
|
if (!market.minValueSkipLiquidationLtvChecks.eq(newMarket.minValueSkipLiquidationLtvChecks)) {
|
|
1155
1216
|
updateLendingMarketIxnsArgs.push({
|
|
1156
1217
|
mode: UpdateLendingMarketMode.UpdateMinValueLtvSkipPriorityLiqCheck.discriminator,
|
|
@@ -1160,9 +1221,10 @@ function parseForChangesMarketConfigAndGetIxs(
|
|
|
1160
1221
|
),
|
|
1161
1222
|
});
|
|
1162
1223
|
}
|
|
1163
|
-
|
|
1224
|
+
break;
|
|
1225
|
+
case 'individualAutodeleverageMarginCallPeriodSecs':
|
|
1164
1226
|
if (
|
|
1165
|
-
|
|
1227
|
+
market.individualAutodeleverageMarginCallPeriodSecs !== newMarket.individualAutodeleverageMarginCallPeriodSecs
|
|
1166
1228
|
) {
|
|
1167
1229
|
updateLendingMarketIxnsArgs.push({
|
|
1168
1230
|
mode: UpdateLendingMarketMode.UpdateIndividualAutodeleverageMarginCallPeriodSecs.discriminator,
|
|
@@ -1172,40 +1234,35 @@ function parseForChangesMarketConfigAndGetIxs(
|
|
|
1172
1234
|
),
|
|
1173
1235
|
});
|
|
1174
1236
|
}
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
for (let i = 0; i < market.elevationGroups.length; i++) {
|
|
1178
|
-
if (
|
|
1179
|
-
market.elevationGroups[i].id !== newMarket.elevationGroups[i].id ||
|
|
1180
|
-
market.elevationGroups[i].maxLiquidationBonusBps !== newMarket.elevationGroups[i].maxLiquidationBonusBps ||
|
|
1181
|
-
market.elevationGroups[i].ltvPct !== newMarket.elevationGroups[i].ltvPct ||
|
|
1182
|
-
market.elevationGroups[i].liquidationThresholdPct !== newMarket.elevationGroups[i].liquidationThresholdPct ||
|
|
1183
|
-
market.elevationGroups[i].allowNewLoans !== newMarket.elevationGroups[i].allowNewLoans ||
|
|
1184
|
-
market.elevationGroups[i].maxReservesAsCollateral !== newMarket.elevationGroups[i].maxReservesAsCollateral ||
|
|
1185
|
-
!market.elevationGroups[i].debtReserve.equals(newMarket.elevationGroups[i].debtReserve)
|
|
1186
|
-
) {
|
|
1187
|
-
updateLendingMarketIxnsArgs.push({
|
|
1188
|
-
mode: UpdateLendingMarketMode.UpdateElevationGroup.discriminator,
|
|
1189
|
-
value: updateMarketConfigEncodedValue(
|
|
1190
|
-
UpdateLendingMarketMode.UpdateElevationGroup.discriminator,
|
|
1191
|
-
newMarket.elevationGroups[i]
|
|
1192
|
-
),
|
|
1193
|
-
});
|
|
1194
|
-
elevationGroupsDiffs++;
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
|
-
if (elevationGroupsDiffs > 1) {
|
|
1198
|
-
throw new Error('Can only update 1 elevation group at a time');
|
|
1199
|
-
}
|
|
1200
|
-
} else if (key === 'name') {
|
|
1237
|
+
break;
|
|
1238
|
+
case 'name':
|
|
1201
1239
|
if (!sameLengthArrayEquals(market.name, newMarket.name)) {
|
|
1202
1240
|
updateLendingMarketIxnsArgs.push({
|
|
1203
1241
|
mode: UpdateLendingMarketMode.UpdateName.discriminator,
|
|
1204
1242
|
value: updateMarketConfigEncodedValue(UpdateLendingMarketMode.UpdateName.discriminator, newMarket.name),
|
|
1205
1243
|
});
|
|
1206
1244
|
}
|
|
1245
|
+
break;
|
|
1246
|
+
default:
|
|
1247
|
+
assertNever(key);
|
|
1248
|
+
}
|
|
1249
|
+
return updateLendingMarketIxnsArgs;
|
|
1250
|
+
};
|
|
1251
|
+
|
|
1252
|
+
function parseForChangesMarketConfigAndGetIxs(
|
|
1253
|
+
marketWithAddress: MarketWithAddress,
|
|
1254
|
+
newMarket: LendingMarket,
|
|
1255
|
+
programId: PublicKey
|
|
1256
|
+
): TransactionInstruction[] {
|
|
1257
|
+
const market = marketWithAddress.state;
|
|
1258
|
+
const updateLendingMarketIxnsArgs: { mode: number; value: Buffer }[] = [];
|
|
1259
|
+
|
|
1260
|
+
for (const key in market.toJSON()) {
|
|
1261
|
+
if (isExcludedLendingMarketKey(key)) {
|
|
1262
|
+
continue;
|
|
1207
1263
|
}
|
|
1208
|
-
|
|
1264
|
+
updateLendingMarketIxnsArgs.push(...updateLendingMarketConfig(key as LendingMarketKey, market, newMarket));
|
|
1265
|
+
}
|
|
1209
1266
|
|
|
1210
1267
|
const ixns: TransactionInstruction[] = [];
|
|
1211
1268
|
|