@kamino-finance/klend-sdk 5.14.0-beta.0 → 5.14.1-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/configItems.d.ts +32 -3
- package/dist/classes/configItems.d.ts.map +1 -1
- package/dist/classes/configItems.js +70 -11
- package/dist/classes/configItems.js.map +1 -1
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +4 -4
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/obligation.d.ts +1 -3
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +2 -4
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/obligationOrder.d.ts +2 -1
- package/dist/classes/obligationOrder.d.ts.map +1 -1
- package/dist/classes/obligationOrder.js +16 -3
- package/dist/classes/obligationOrder.js.map +1 -1
- package/dist/classes/reserve.js +8 -8
- package/dist/classes/reserve.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.js +2 -2
- package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/configItems.ts +82 -16
- package/src/classes/manager.ts +5 -5
- package/src/classes/obligation.ts +9 -4
- package/src/classes/obligationOrder.ts +22 -3
- package/src/classes/reserve.ts +8 -8
- package/src/lending_operations/repay_with_collateral_calcs.ts +2 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repay_with_collateral_calcs.js","sourceRoot":"","sources":["../../src/lending_operations/repay_with_collateral_calcs.ts"],"names":[],"mappings":";;;;;;AAUA,kEAiDC;AAuBD,
|
|
1
|
+
{"version":3,"file":"repay_with_collateral_calcs.js","sourceRoot":"","sources":["../../src/lending_operations/repay_with_collateral_calcs.ts"],"names":[],"mappings":";;;;;;AAUA,kEAiDC;AAuBD,8DAsFC;AAED,sEA2CC;AAED,gFAqBC;AA5OD,4DAAiC;AAC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SAAS,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,oBAAO,CAAC,UAAU,CAAC,CAAC;IAE5F,uHAAuH;IACvH,MAAM,cAAc,GAAG,uBAAuB;SAC3C,GAAG,CAAC,mBAAmB,CAAC,GAAG,CAAC,IAAI,oBAAO,CAAC,MAAM,CAAC,CAAC,CAAC;SACjD,eAAe,CAAC,WAAW,CAAC,KAAK,CAAC,SAAS,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,oBAAO,CAAC,UAAU,CAAC,CAAC;IAE5F,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,SAAgB,kCAAkC,CAAC,KAKlD;IACC,MAAM,EACJ,UAAU,EAAE,cAAc;IAC1B,eAAe,EACf,WAAW,EACX,eAAe,GAChB,GAAG,KAAK,CAAC;IACV,MAAM,aAAa,GAAG,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC7C,MAAM,iBAAiB,GAAG,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACrD,MAAM,kBAAkB,GAAG,IAAI,oBAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAC/D,MAAM,sBAAsB,GAAG,IAAI,oBAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAEvE,MAAM,kBAAkB,GAAG,UAAU,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;IAClE,MAAM,UAAU,GAAG,kBAAkB,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAEnF,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { struct, Layout } from '@coral-xyz/borsh';
|
|
2
|
-
import { blobEquals, orThrow } from './utils';
|
|
2
|
+
import { blobEquals, orThrow, toJson } from './utils';
|
|
3
3
|
import { Buffer } from 'buffer';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -18,7 +18,12 @@ import { Buffer } from 'buffer';
|
|
|
18
18
|
* }));
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
|
-
export type ConfigItemMap<M extends BorshEnum, C> = BorshEnumMap<M, ConfigItem<C, any
|
|
21
|
+
export type ConfigItemMap<M extends BorshEnum, C> = BorshEnumMap<M, SingleOrArray<ConfigItem<C, any>>>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* As advertised.
|
|
25
|
+
*/
|
|
26
|
+
export type SingleOrArray<T> = T | T[];
|
|
22
27
|
|
|
23
28
|
/**
|
|
24
29
|
* A set of everything required to create an update ix for a single config item of type {@code A} belonging to a
|
|
@@ -34,7 +39,7 @@ export type ConfigItem<C, A> = {
|
|
|
34
39
|
*
|
|
35
40
|
* Such structure may be used:
|
|
36
41
|
* - either directly (i.e. a borsh-serialized "fat" config item, e.g. `ReserveConfig.borrowRateCurve`),
|
|
37
|
-
* - or just to its fields (e.g. `ReserveConfig.tokenInfo.pythConfiguration.price`).
|
|
42
|
+
* - or just to access its fields (e.g. `ReserveConfig.tokenInfo.pythConfiguration.price`).
|
|
38
43
|
*/
|
|
39
44
|
export type StructConfigItem<C, A extends Record<string, any>> = ConfigItem<C, A> & {
|
|
40
45
|
[K in keyof A]: A[K] extends object ? StructConfigItem<C, A[K]> : ConfigItem<C, A>;
|
|
@@ -69,6 +74,32 @@ export class CompositeConfigItem<C> implements ConfigItem<C, Record<string, any>
|
|
|
69
74
|
}
|
|
70
75
|
}
|
|
71
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Creates an array of config items - one per each element of the given array.
|
|
79
|
+
*
|
|
80
|
+
* An example use-case is `LendingMarket.elevationGroups[]`: to update all of them, we need N ixs:
|
|
81
|
+
* - `updateLendingMarket(mode = ElevationGroup, value = elevationGroups[0])`
|
|
82
|
+
* - `updateLendingMarket(mode = ElevationGroup, value = elevationGroups[1])`
|
|
83
|
+
* - `updateLendingMarket(mode = ElevationGroup, value = elevationGroups[2])`
|
|
84
|
+
* ...
|
|
85
|
+
*
|
|
86
|
+
* So: conceptually, the *array* is not "a config item". Each *slot* in that array is its own config item.
|
|
87
|
+
*/
|
|
88
|
+
export function arrayElementConfigItems<C, A>(arrayConfigItem: ConfigItem<C, A[]>): ConfigItem<C, A>[] {
|
|
89
|
+
const arrayGetter = arrayConfigItem.__getter;
|
|
90
|
+
const wrappedSequenceLayout = arrayConfigItem.__layout as any;
|
|
91
|
+
const sequenceLayout = wrappedSequenceLayout.layout?.fields?.[0];
|
|
92
|
+
if (sequenceLayout === undefined) {
|
|
93
|
+
throw new Error(`unexpected layout of the input array config item: ${toJson(wrappedSequenceLayout, true)}`);
|
|
94
|
+
}
|
|
95
|
+
return new Array(sequenceLayout.count)
|
|
96
|
+
.fill(sequenceLayout.elementLayout as Layout<A>)
|
|
97
|
+
.map((elementLayout, index) => ({
|
|
98
|
+
__layout: elementLayout,
|
|
99
|
+
__getter: (config) => arrayGetter(config)[index],
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
|
|
72
103
|
/**
|
|
73
104
|
* A constructor reference of a borsh structure.
|
|
74
105
|
*/
|
|
@@ -120,7 +151,7 @@ export class ConfigItemUpdater<C, A> {
|
|
|
120
151
|
* A resolver of config item changes.
|
|
121
152
|
*/
|
|
122
153
|
export class ConfigUpdater<M extends BorshEnum, C> {
|
|
123
|
-
private readonly itemUpdaters: Map<M['kind'], [M, ConfigItemUpdater<C, any>]>;
|
|
154
|
+
private readonly itemUpdaters: Map<M['kind'], [M, ConfigItemUpdater<C, any>[]]>;
|
|
124
155
|
|
|
125
156
|
/**
|
|
126
157
|
* A resolving constructor.
|
|
@@ -141,35 +172,66 @@ export class ConfigUpdater<M extends BorshEnum, C> {
|
|
|
141
172
|
itemMapBuilder: (config: AnyConfigItem<C, C>) => ConfigItemMap<M, C>
|
|
142
173
|
) {
|
|
143
174
|
this.itemUpdaters = new Map(
|
|
144
|
-
Object.entries(itemMapBuilder(wrap(configClass)))
|
|
145
|
-
|
|
146
|
-
|
|
175
|
+
Object.entries(itemMapBuilder(wrap(configClass))).map(([kind, itemOrArray]) => [
|
|
176
|
+
kind,
|
|
177
|
+
[
|
|
178
|
+
fromDecoded({ [kind]: {} }),
|
|
179
|
+
toArray(itemOrArray as SingleOrArray<ConfigItem<C, any>>).map((item) => new ConfigItemUpdater(item)),
|
|
180
|
+
],
|
|
181
|
+
])
|
|
147
182
|
);
|
|
148
183
|
}
|
|
149
184
|
|
|
150
185
|
/**
|
|
151
186
|
* Returns all changes between the given current and new configs - in particular, this will be *all* supported fields'
|
|
152
187
|
* changes if the previous config does not exist.
|
|
188
|
+
*
|
|
189
|
+
* Please note that more than one {@link EncodedConfigUpdate}s can be associated with a single `M` enum value (in
|
|
190
|
+
* cases where e.g. an array property is updated by individual updates of its elements).
|
|
153
191
|
*/
|
|
154
192
|
encodeAllUpdates(currentConfig: C | undefined, newConfig: C): EncodedConfigUpdate<M>[] {
|
|
155
193
|
const updates: EncodedConfigUpdate<M>[] = [];
|
|
156
|
-
for (const [mode,
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
194
|
+
for (const [mode, itemUpdaters] of this.itemUpdaters.values()) {
|
|
195
|
+
for (const itemUpdater of itemUpdaters) {
|
|
196
|
+
const value = itemUpdater.encodeUpdatedItemFrom(currentConfig, newConfig);
|
|
197
|
+
if (value === undefined) {
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
updates.push({ mode, value });
|
|
160
201
|
}
|
|
161
|
-
updates.push({ mode, value });
|
|
162
202
|
}
|
|
163
203
|
return updates;
|
|
164
204
|
}
|
|
165
205
|
|
|
166
206
|
/**
|
|
167
|
-
* Gets
|
|
207
|
+
* Gets the single updater of the given config item.
|
|
208
|
+
*
|
|
209
|
+
* Throws an error if the updates are not supported (e.g. for deprecated modes) or if the given item is handled by
|
|
210
|
+
* multiple updaters (e.g. for an array property) - to handle these cases, use {@link allForMode()}.
|
|
168
211
|
*/
|
|
169
212
|
forMode(mode: M): ConfigItemUpdater<C, any> {
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
213
|
+
const itemUpdaters = this.allForMode(mode);
|
|
214
|
+
switch (itemUpdaters.length) {
|
|
215
|
+
case 0:
|
|
216
|
+
throw new Error(`updates not supported (updaters for ${mode.kind} were explicitly set to [])`);
|
|
217
|
+
case 1:
|
|
218
|
+
return itemUpdaters[0];
|
|
219
|
+
default:
|
|
220
|
+
throw new Error(`${mode.kind} defines multiple (${itemUpdaters.length}) updaters`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Gets all the updaters of the given config item.
|
|
226
|
+
*
|
|
227
|
+
* This may be an empty array (e.g. for deprecated modes), or multiple elements (e.g. if an array property is updated
|
|
228
|
+
* by individual updates of its elements). If you expect a single updater, use {@link forMode()}.
|
|
229
|
+
*/
|
|
230
|
+
allForMode(mode: M): ConfigItemUpdater<C, any>[] {
|
|
231
|
+
const [_mode, itemUpdaters] =
|
|
232
|
+
this.itemUpdaters.get(mode.kind) ??
|
|
233
|
+
orThrow(`updaters for ${mode.kind} were not set (should not be possible, due to type-safety)`);
|
|
234
|
+
return itemUpdaters;
|
|
173
235
|
}
|
|
174
236
|
}
|
|
175
237
|
|
|
@@ -227,3 +289,7 @@ type BorshEnumMap<M extends BorshEnum, T> = {
|
|
|
227
289
|
};
|
|
228
290
|
|
|
229
291
|
type Getter<C, A> = (config: C) => A;
|
|
292
|
+
|
|
293
|
+
function toArray<T>(singleOrArray: SingleOrArray<T>): T[] {
|
|
294
|
+
return Array.isArray(singleOrArray) ? singleOrArray : [singleOrArray];
|
|
295
|
+
}
|
package/src/classes/manager.ts
CHANGED
|
@@ -88,7 +88,7 @@ import { FarmState } from '@kamino-finance/farms-sdk/dist';
|
|
|
88
88
|
import SwitchboardProgram from '@switchboard-xyz/sbv2-lite';
|
|
89
89
|
import { getSquadsMultisigAdminsAndThreshold, walletIsSquadsMultisig, WalletType } from '../utils/multisig';
|
|
90
90
|
import { decodeVaultState } from '../utils/vault';
|
|
91
|
-
import { ConfigUpdater } from './configItems';
|
|
91
|
+
import { arrayElementConfigItems, ConfigUpdater } from './configItems';
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
94
|
* KaminoManager is a class that provides a high-level interface to interact with the Kamino Lend and Kamino Vault programs, in order to create and manage a market, as well as vaults
|
|
@@ -1255,21 +1255,21 @@ export const MARKET_UPDATER = new ConfigUpdater(UpdateLendingMarketMode.fromDeco
|
|
|
1255
1255
|
[UpdateLendingMarketMode.UpdateEmergencyMode.kind]: config.emergencyMode,
|
|
1256
1256
|
[UpdateLendingMarketMode.UpdateLiquidationCloseFactor.kind]: config.liquidationMaxDebtCloseFactorPct,
|
|
1257
1257
|
[UpdateLendingMarketMode.UpdateLiquidationMaxValue.kind]: config.maxLiquidatableDebtMarketValueAtOnce,
|
|
1258
|
-
[UpdateLendingMarketMode.DeprecatedUpdateGlobalUnhealthyBorrow.kind]:
|
|
1258
|
+
[UpdateLendingMarketMode.DeprecatedUpdateGlobalUnhealthyBorrow.kind]: [], // deprecated
|
|
1259
1259
|
[UpdateLendingMarketMode.UpdateGlobalAllowedBorrow.kind]: config.globalAllowedBorrowValue,
|
|
1260
1260
|
[UpdateLendingMarketMode.UpdateRiskCouncil.kind]: config.riskCouncil,
|
|
1261
1261
|
[UpdateLendingMarketMode.UpdateMinFullLiquidationThreshold.kind]: config.minFullLiquidationValueThreshold,
|
|
1262
1262
|
[UpdateLendingMarketMode.UpdateInsolvencyRiskLtv.kind]: config.insolvencyRiskUnhealthyLtvPct,
|
|
1263
|
-
[UpdateLendingMarketMode.UpdateElevationGroup.kind]: config.elevationGroups,
|
|
1263
|
+
[UpdateLendingMarketMode.UpdateElevationGroup.kind]: arrayElementConfigItems(config.elevationGroups),
|
|
1264
1264
|
[UpdateLendingMarketMode.UpdateReferralFeeBps.kind]: config.referralFeeBps,
|
|
1265
|
-
[UpdateLendingMarketMode.DeprecatedUpdateMultiplierPoints.kind]:
|
|
1265
|
+
[UpdateLendingMarketMode.DeprecatedUpdateMultiplierPoints.kind]: [], // deprecated
|
|
1266
1266
|
[UpdateLendingMarketMode.UpdatePriceRefreshTriggerToMaxAgePct.kind]: config.priceRefreshTriggerToMaxAgePct,
|
|
1267
1267
|
[UpdateLendingMarketMode.UpdateAutodeleverageEnabled.kind]: config.autodeleverageEnabled,
|
|
1268
1268
|
[UpdateLendingMarketMode.UpdateBorrowingDisabled.kind]: config.borrowDisabled,
|
|
1269
1269
|
[UpdateLendingMarketMode.UpdateMinNetValueObligationPostAction.kind]: config.minNetValueInObligationSf,
|
|
1270
1270
|
[UpdateLendingMarketMode.UpdateMinValueLtvSkipPriorityLiqCheck.kind]: config.minValueSkipLiquidationLtvChecks,
|
|
1271
1271
|
[UpdateLendingMarketMode.UpdateMinValueBfSkipPriorityLiqCheck.kind]: config.minValueSkipLiquidationBfChecks,
|
|
1272
|
-
[UpdateLendingMarketMode.UpdatePaddingFields.kind]:
|
|
1272
|
+
[UpdateLendingMarketMode.UpdatePaddingFields.kind]: [], // we do not update padding this way
|
|
1273
1273
|
[UpdateLendingMarketMode.UpdateName.kind]: config.name,
|
|
1274
1274
|
[UpdateLendingMarketMode.UpdateIndividualAutodeleverageMarginCallPeriodSecs.kind]:
|
|
1275
1275
|
config.individualAutodeleverageMarginCallPeriodSecs,
|
|
@@ -436,11 +436,16 @@ export class KaminoObligation {
|
|
|
436
436
|
|
|
437
437
|
/**
|
|
438
438
|
* Get the loan to value and liquidation loan to value for a collateral token reserve as ratios, accounting for the obligation elevation group if it is active
|
|
439
|
-
* @param market
|
|
440
|
-
* @param reserve
|
|
441
439
|
*/
|
|
442
|
-
public getLtvForReserve(
|
|
443
|
-
|
|
440
|
+
public getLtvForReserve(
|
|
441
|
+
market: KaminoMarket,
|
|
442
|
+
reserveAddress: PublicKey
|
|
443
|
+
): { maxLtv: Decimal; liquidationLtv: Decimal } {
|
|
444
|
+
return KaminoObligation.getLtvForReserve(
|
|
445
|
+
market,
|
|
446
|
+
market.getExistingReserveByAddress(reserveAddress),
|
|
447
|
+
this.state.elevationGroup
|
|
448
|
+
);
|
|
444
449
|
}
|
|
445
450
|
|
|
446
451
|
/**
|
|
@@ -8,6 +8,7 @@ import { KaminoObligation, Position } from './obligation';
|
|
|
8
8
|
import { TokenAmount } from './shared';
|
|
9
9
|
import { ONE_HUNDRED_PCT_IN_BPS } from '../utils';
|
|
10
10
|
import { getSingleElement } from '../utils/validations';
|
|
11
|
+
import { KaminoMarket } from './market';
|
|
11
12
|
|
|
12
13
|
// Polymorphic parts of an order:
|
|
13
14
|
|
|
@@ -300,7 +301,10 @@ export class KaminoObligationOrder {
|
|
|
300
301
|
*
|
|
301
302
|
* May return `undefined` when the order's condition is not met.
|
|
302
303
|
*/
|
|
303
|
-
findMaxAvailableExecution(
|
|
304
|
+
findMaxAvailableExecution(
|
|
305
|
+
kaminoMarket: KaminoMarket,
|
|
306
|
+
obligation: KaminoObligation
|
|
307
|
+
): AvailableOrderExecution | undefined {
|
|
304
308
|
const conditionHit = this.condition.evaluate(obligation);
|
|
305
309
|
if (conditionHit === null) {
|
|
306
310
|
return undefined; // condition not met - cannot execute
|
|
@@ -311,9 +315,24 @@ export class KaminoObligationOrder {
|
|
|
311
315
|
const executionBonusRate = this.calculateExecutionBonusRate(conditionHit, obligation);
|
|
312
316
|
const executionBonusFactor = new Decimal(1).add(executionBonusRate);
|
|
313
317
|
const maxWithdrawValue = maxRepayValue.mul(executionBonusFactor);
|
|
314
|
-
|
|
318
|
+
|
|
319
|
+
// The order execution only allows us to pick the lowest-liquidation-LTV deposit for withdrawal (excluding 0-LTV
|
|
320
|
+
// assets, which are never liquidatable), hence we pre-filter the candidate deposits:
|
|
321
|
+
const liquidationLtvsOfDeposits = obligation
|
|
315
322
|
.getDeposits()
|
|
316
|
-
.map((deposit): [Decimal, Position] =>
|
|
323
|
+
.map((deposit): [Decimal, Position] => [
|
|
324
|
+
obligation.getLtvForReserve(kaminoMarket, deposit.reserveAddress).liquidationLtv,
|
|
325
|
+
deposit,
|
|
326
|
+
]);
|
|
327
|
+
const liquidatableDeposits = liquidationLtvsOfDeposits.filter(([liquidationLtv, _deposit]) => liquidationLtv.gt(0));
|
|
328
|
+
// Note: in theory, we could use the Obligation's `lowestReserveDepositLiquidationLtv` (cached by SC) here, but it
|
|
329
|
+
// is equally easy to just find the minimum (and avoid any issues related to stale `KaminoObligation` state or
|
|
330
|
+
// `Decimal` rounding/comparison).
|
|
331
|
+
const minLiquidationLtv = Decimal.min(...liquidatableDeposits.map(([liquidationLtv, _deposit]) => liquidationLtv));
|
|
332
|
+
|
|
333
|
+
const [actualWithdrawValue, withdrawDeposit] = liquidatableDeposits
|
|
334
|
+
.filter(([liquidationLtv, _deposit]) => liquidationLtv.eq(minLiquidationLtv))
|
|
335
|
+
.map(([_liquidationLtv, deposit]): [Decimal, Position] => {
|
|
317
336
|
const availableWithdrawValue = Decimal.min(deposit.marketValueRefreshed, maxWithdrawValue);
|
|
318
337
|
return [availableWithdrawValue, deposit];
|
|
319
338
|
})
|
package/src/classes/reserve.ts
CHANGED
|
@@ -1207,7 +1207,7 @@ export const RESERVE_CONFIG_UPDATER = new ConfigUpdater(UpdateConfigMode.fromDec
|
|
|
1207
1207
|
[UpdateConfigMode.UpdateProtocolTakeRate.kind]: config.protocolTakeRatePct,
|
|
1208
1208
|
[UpdateConfigMode.UpdateFeesBorrowFee.kind]: config.fees.borrowFeeSf,
|
|
1209
1209
|
[UpdateConfigMode.UpdateFeesFlashLoanFee.kind]: config.fees.flashLoanFeeSf,
|
|
1210
|
-
[UpdateConfigMode.DeprecatedUpdateFeesReferralFeeBps.kind]:
|
|
1210
|
+
[UpdateConfigMode.DeprecatedUpdateFeesReferralFeeBps.kind]: [], // deprecated
|
|
1211
1211
|
[UpdateConfigMode.UpdateDepositLimit.kind]: config.depositLimit,
|
|
1212
1212
|
[UpdateConfigMode.UpdateBorrowLimit.kind]: config.borrowLimit,
|
|
1213
1213
|
[UpdateConfigMode.UpdateTokenInfoLowerHeuristic.kind]: config.tokenInfo.heuristic.lower,
|
|
@@ -1224,7 +1224,7 @@ export const RESERVE_CONFIG_UPDATER = new ConfigUpdater(UpdateConfigMode.fromDec
|
|
|
1224
1224
|
[UpdateConfigMode.UpdateSwitchboardFeed.kind]: config.tokenInfo.switchboardConfiguration.priceAggregator,
|
|
1225
1225
|
[UpdateConfigMode.UpdateSwitchboardTwapFeed.kind]: config.tokenInfo.switchboardConfiguration.twapAggregator,
|
|
1226
1226
|
[UpdateConfigMode.UpdateBorrowRateCurve.kind]: config.borrowRateCurve,
|
|
1227
|
-
[UpdateConfigMode.UpdateEntireReserveConfig.kind]:
|
|
1227
|
+
[UpdateConfigMode.UpdateEntireReserveConfig.kind]: [], // technically `config` would be a valid thing here, but we actually do NOT want entire config update among ixs produced for field-by-field updates
|
|
1228
1228
|
[UpdateConfigMode.UpdateDebtWithdrawalCap.kind]: new CompositeConfigItem(
|
|
1229
1229
|
config.debtWithdrawalCap.configCapacity,
|
|
1230
1230
|
config.debtWithdrawalCap.configIntervalLengthSeconds
|
|
@@ -1233,8 +1233,8 @@ export const RESERVE_CONFIG_UPDATER = new ConfigUpdater(UpdateConfigMode.fromDec
|
|
|
1233
1233
|
config.depositWithdrawalCap.configCapacity,
|
|
1234
1234
|
config.depositWithdrawalCap.configIntervalLengthSeconds
|
|
1235
1235
|
),
|
|
1236
|
-
[UpdateConfigMode.DeprecatedUpdateDebtWithdrawalCapCurrentTotal.kind]:
|
|
1237
|
-
[UpdateConfigMode.DeprecatedUpdateDepositWithdrawalCapCurrentTotal.kind]:
|
|
1236
|
+
[UpdateConfigMode.DeprecatedUpdateDebtWithdrawalCapCurrentTotal.kind]: [], // deprecated
|
|
1237
|
+
[UpdateConfigMode.DeprecatedUpdateDepositWithdrawalCapCurrentTotal.kind]: [], // deprecated
|
|
1238
1238
|
[UpdateConfigMode.UpdateBadDebtLiquidationBonusBps.kind]: config.badDebtLiquidationBonusBps,
|
|
1239
1239
|
[UpdateConfigMode.UpdateMinLiquidationBonusBps.kind]: config.minLiquidationBonusBps,
|
|
1240
1240
|
[UpdateConfigMode.UpdateDeleveragingMarginCallPeriod.kind]: config.deleveragingMarginCallPeriodSecs,
|
|
@@ -1242,11 +1242,11 @@ export const RESERVE_CONFIG_UPDATER = new ConfigUpdater(UpdateConfigMode.fromDec
|
|
|
1242
1242
|
[UpdateConfigMode.UpdateAssetTier.kind]: config.assetTier,
|
|
1243
1243
|
[UpdateConfigMode.UpdateElevationGroup.kind]: config.elevationGroups,
|
|
1244
1244
|
[UpdateConfigMode.UpdateDeleveragingThresholdDecreaseBpsPerDay.kind]: config.deleveragingThresholdDecreaseBpsPerDay,
|
|
1245
|
-
[UpdateConfigMode.DeprecatedUpdateMultiplierSideBoost.kind]:
|
|
1246
|
-
[UpdateConfigMode.DeprecatedUpdateMultiplierTagBoost.kind]:
|
|
1245
|
+
[UpdateConfigMode.DeprecatedUpdateMultiplierSideBoost.kind]: [], // deprecated
|
|
1246
|
+
[UpdateConfigMode.DeprecatedUpdateMultiplierTagBoost.kind]: [], // deprecated
|
|
1247
1247
|
[UpdateConfigMode.UpdateReserveStatus.kind]: config.status,
|
|
1248
|
-
[UpdateConfigMode.UpdateFarmCollateral.kind]:
|
|
1249
|
-
[UpdateConfigMode.UpdateFarmDebt.kind]:
|
|
1248
|
+
[UpdateConfigMode.UpdateFarmCollateral.kind]: [], // the farm fields live on the `Reserve` level...
|
|
1249
|
+
[UpdateConfigMode.UpdateFarmDebt.kind]: [], // ...so we are not concerned with them in the `ReserveConfig`'s field-by-field update tx
|
|
1250
1250
|
[UpdateConfigMode.UpdateDisableUsageAsCollateralOutsideEmode.kind]: config.disableUsageAsCollOutsideEmode,
|
|
1251
1251
|
[UpdateConfigMode.UpdateBlockBorrowingAboveUtilizationPct.kind]: config.utilizationLimitBlockBorrowingAbovePct,
|
|
1252
1252
|
[UpdateConfigMode.UpdateBlockPriceUsage.kind]: config.tokenInfo.blockPriceUsage,
|
|
@@ -129,10 +129,7 @@ export function calcMaxWithdrawCollateral(
|
|
|
129
129
|
.getDeposits()
|
|
130
130
|
.filter((p) => !p.reserveAddress.equals(deposit.reserveAddress))
|
|
131
131
|
.reduce((acc, d) => {
|
|
132
|
-
const { maxLtv, liquidationLtv } = obligation.getLtvForReserve(
|
|
133
|
-
market,
|
|
134
|
-
market.getExistingReserveByAddress(d.reserveAddress)
|
|
135
|
-
);
|
|
132
|
+
const { maxLtv, liquidationLtv } = obligation.getLtvForReserve(market, d.reserveAddress);
|
|
136
133
|
const maxWithdrawLtv =
|
|
137
134
|
maxWithdrawLtvCheck === MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD ? liquidationLtv : maxLtv;
|
|
138
135
|
return acc.add(d.marketValueRefreshed.mul(maxWithdrawLtv));
|
|
@@ -150,7 +147,7 @@ export function calcMaxWithdrawCollateral(
|
|
|
150
147
|
} else {
|
|
151
148
|
const { maxLtv: collMaxLtv, liquidationLtv: collLiquidationLtv } = obligation.getLtvForReserve(
|
|
152
149
|
market,
|
|
153
|
-
|
|
150
|
+
depositReserve.address
|
|
154
151
|
);
|
|
155
152
|
const maxWithdrawLtv =
|
|
156
153
|
maxWithdrawLtvCheck === MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD ? collLiquidationLtv : collMaxLtv;
|