Skip to content
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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Jean-Grimal
Copy link
Collaborator

@Jean-Grimal Jean-Grimal commented Jan 23, 2025

Given that for the accrualPosition class, a significant portion of the logic is actually in the Market class (or in MarketUtils), I had several options for the functions of the new class I need to create/override:

  1. Implement them (if they are new functions, otherwise override them) directly in the preLiquidatablePosition class without changing either accrualPosition or Market.

  2. Implement them (if they are new functions, otherwise override them) directly in the preLiquidatablePosition class and move the logic from MarketUtils to accrualPosition (for better consistency).

  3. Implement the new logic in MarketUtils and/or in a new utility file.

I chose 1 for these first version, but could change.

Copy link

linear bot commented Jan 23, 2025

Comment on lines 189 to 198
/**
* 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,
});
}
Copy link
Collaborator Author

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

Comment on lines 210 to 237
/**
* 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,
};
}
Copy link
Collaborator Author

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 ?

Comment on lines 239 to 259
/**
* 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,
};
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant