-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add preliquidatable class #251
base: main
Are you sure you want to change the base?
feat: add preliquidatable class #251
Conversation
/** | ||
* This position's pre health factor (collateral power over debt, scaled by WAD). | ||
* If the debt is 0, health factor is `MaxUint256`. | ||
* `undefined` iff the market's oracle is undefined or reverts. | ||
*/ | ||
get preHealthFactor() { | ||
return MarketUtils.getHealthFactor(this, this.market, { | ||
lltv: this.preLiquidationParams.preLltv, | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this function is useless and we should just override healthFactor
/** | ||
* Returns the maximum amount of loan assets that can be borrowed given a certain borrow position | ||
* and the reason for the limit. | ||
* Returns `undefined` iff the market's price is undefined. | ||
* @deprecated Use `getBorrowCapacityLimit` instead. | ||
*/ | ||
get borrowCapacityLimit() { | ||
if (this.maxBorrowAssets == null) return; | ||
|
||
// handle edge cases when the user is (pre)liquidatable (maxBorrow < borrow) | ||
const maxBorrowableAssets = MathLib.zeroFloorSub( | ||
this.maxBorrowAssets, | ||
this.market.toBorrowAssets(this.borrowShares), | ||
); | ||
|
||
const liquidity = this.market.liquidity; | ||
|
||
if (maxBorrowableAssets > liquidity) | ||
return { | ||
value: liquidity, | ||
limiter: CapacityLimitReason.liquidity, | ||
}; | ||
|
||
return { | ||
value: maxBorrowableAssets, | ||
limiter: CapacityLimitReason.collateral, | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to implement this function as it is deprecated ?
/** | ||
* Returns the maximum amount of collateral assets that can be withdrawn given a certain borrow position | ||
* and the reason for the limit. | ||
* Returns `undefined` iff the market's price is undefined. | ||
* @deprecated Use `getWithdrawCollateralCapacityLimit` instead. | ||
*/ | ||
get withdrawCollateralCapacityLimit() { | ||
const withdrawableCollateral = this.withdrawableCollateral; | ||
if (withdrawableCollateral == null) return; | ||
|
||
if (this.collateral > withdrawableCollateral) | ||
return { | ||
value: withdrawableCollateral, | ||
limiter: CapacityLimitReason.collateral, | ||
}; | ||
|
||
return { | ||
value: this.collateral, | ||
limiter: CapacityLimitReason.position, | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
Signed-off-by: Jean-Grimal <83286814+Jean-Grimal@users.noreply.github.com>
Given that for the
accrualPosition
class, a significant portion of the logic is actually in theMarket
class (or inMarketUtils
), I had several options for the functions of the new class I need to create/override:Implement them (if they are new functions, otherwise override them) directly in the
preLiquidatablePosition
class without changing eitheraccrualPosition
orMarket
.Implement them (if they are new functions, otherwise override them) directly in the
preLiquidatablePosition
class and move the logic fromMarketUtils
toaccrualPosition
(for better consistency).Implement the new logic in
MarketUtils
and/or in a new utility file.I chose 1 for these first version, but could change.